ShiftEdepSCE_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ShiftEdepSCE
3 // Plugin Type: producer (art v2_05_01)
4 // File: ShiftEdepSCE_module.cc
5 //
6 // Generated at Thu Apr 19 00:41:18 2018 by Wesley Ketchum using cetskelgen
7 // from cetlib version v1_21_00.
8 ////////////////////////////////////////////////////////////////////////
9 
14 #include "art_root_io/TFileService.h"
16 #include "fhiclcpp/ParameterSet.h"
17 
18 #include <memory>
19 
20 #include "TNtuple.h"
28 
29 namespace spacecharge {
30  class ShiftEdepSCE;
31 }
32 
34 public:
35  explicit ShiftEdepSCE(fhicl::ParameterSet const& p);
36  // The compiler-generated destructor is fine for non-base
37  // classes without bare pointers or other resource use.
38 
39  // Plugins should not be copied or assigned.
40  ShiftEdepSCE(ShiftEdepSCE const&) = delete;
41  ShiftEdepSCE(ShiftEdepSCE&&) = delete;
42  ShiftEdepSCE& operator=(ShiftEdepSCE const&) = delete;
43  ShiftEdepSCE& operator=(ShiftEdepSCE&&) = delete;
44 
45  // Required functions.
46  void produce(art::Event& e) override;
47  void beginJob() override;
48 
49 private:
50  // Declare member data here.
53  TNtuple* fNtEdepAna;
54 
55  //IS calculationg
57 };
58 
60  : EDProducer{p}
61  , fEDepTag(p.get<art::InputTag>("EDepTag"))
62  , fMakeAnaTree(p.get<bool>("MakeAnaTree", true))
63 {
64  produces<std::vector<sim::SimEnergyDeposit>>();
65 }
66 
67 void
69 {
70  if (fMakeAnaTree) {
72  fNtEdepAna = tfs->make<TNtuple>(
73  "nt_edep_ana",
74  "Edep PosDiff Ana Ntuple",
75  "energy:orig_x:orig_y:orig_z:orig_el:orig_ph:shift_x:shift_y:shift_z:shift_el:shift_ph");
76  }
77 }
78 
79 void
81 {
82  auto sce = lar::providerFrom<spacecharge::SpaceChargeService>();
83  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
84 
85  auto const& inEdepVec = *e.getValidHandle<std::vector<sim::SimEnergyDeposit>>(fEDepTag);
86 
87  auto outEdepVecPtr = std::make_unique<std::vector<sim::SimEnergyDeposit>>();
88  auto& outEdepVec = *outEdepVecPtr;
89  outEdepVec.reserve(inEdepVec.size());
90 
91  geo::Vector_t posOffsetsStart{0.0, 0.0, 0.0};
92  geo::Vector_t posOffsetsEnd{0.0, 0.0, 0.0};
93  for (auto const& edep : inEdepVec) {
94  if (sce->EnableSimSpatialSCE()) {
95  posOffsetsStart = sce->GetPosOffsets({edep.StartX(), edep.StartY(), edep.StartZ()});
96  posOffsetsEnd = sce->GetPosOffsets({edep.EndX(), edep.EndY(), edep.EndZ()});
97  if (larsim::Utils::SCE::out_of_bounds(posOffsetsStart) ||
98  larsim::Utils::SCE::out_of_bounds(posOffsetsEnd) ) {
99  continue;
100  }
101  }
102  auto const isData = fISAlg.CalcIonAndScint(detProp, edep);
103  outEdepVec.emplace_back(
104  isData.numPhotons,
105  isData.numElectrons,
106  0.0,
107  edep.Energy(),
108  geo::Point_t{(float)(edep.StartX() - posOffsetsStart.X()), //x should be subtracted
109  (float)(edep.StartY() + posOffsetsStart.Y()),
110  (float)(edep.StartZ() + posOffsetsStart.Z())},
111  geo::Point_t{(float)(edep.EndX() - posOffsetsEnd.X()), //x should be subtracted
112  (float)(edep.EndY() + posOffsetsEnd.Y()),
113  (float)(edep.EndZ() + posOffsetsEnd.Z())},
114  edep.StartT(),
115  edep.EndT(),
116  edep.TrackID(),
117  edep.PdgCode());
118  if (fMakeAnaTree)
119  fNtEdepAna->Fill(edep.Energy(),
120  edep.X(),
121  edep.Y(),
122  edep.Z(),
123  edep.NumElectrons(),
124  edep.NumPhotons(),
125  outEdepVec.back().X(),
126  outEdepVec.back().Y(),
127  outEdepVec.back().Z(),
128  outEdepVec.back().NumElectrons(),
129  outEdepVec.back().NumPhotons());
130  }
131 
132  e.put(std::move(outEdepVecPtr));
133 }
134 
void produce(art::Event &e) override
bool out_of_bounds(geo::Vector_t const &offset)
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
ShiftEdepSCE(fhicl::ParameterSet const &p)
ISCalcData CalcIonAndScint(detinfo::DetectorPropertiesData const &detProp, sim::SimEnergyDeposit const &edep) override
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
ShiftEdepSCE & operator=(ShiftEdepSCE const &)=delete
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
Utility function for testing if Space Charge offsets are out of bounds.
def move(depos, offset)
Definition: depos.py:107
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
larg4::ISCalcSeparate fISAlg
contains information for a single step in the detector simulation