All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
10 #include "art/Framework/Core/EDProducer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art_root_io/TFileService.h"
15 #include "canvas/Utilities/InputTag.h"
16 #include "fhiclcpp/ParameterSet.h"
17 
18 #include <memory>
19 #include <utility>
20 
21 #include "TNtuple.h"
22 
30 
31 namespace spacecharge {
32  class ShiftEdepSCE;
33 }
34 
35 class spacecharge::ShiftEdepSCE : public art::EDProducer {
36 public:
37  explicit ShiftEdepSCE(fhicl::ParameterSet const& p);
38  // The compiler-generated destructor is fine for non-base
39  // classes without bare pointers or other resource use.
40 
41  // Plugins should not be copied or assigned.
42  ShiftEdepSCE(ShiftEdepSCE const&) = delete;
43  ShiftEdepSCE(ShiftEdepSCE&&) = delete;
44  ShiftEdepSCE& operator=(ShiftEdepSCE const&) = delete;
45  ShiftEdepSCE& operator=(ShiftEdepSCE&&) = delete;
46 
47  // Required functions.
48  void produce(art::Event& e) override;
49  void beginJob() override;
50 
51 private:
52  // Declare member data here.
53  art::InputTag fEDepTag;
55  TNtuple* fNtEdepAna;
56 
57  //IS calculationg
59 };
60 
61 spacecharge::ShiftEdepSCE::ShiftEdepSCE(fhicl::ParameterSet const& p)
62  : EDProducer{p}
63  , fEDepTag(p.get<art::InputTag>("EDepTag"))
64  , fMakeAnaTree(p.get<bool>("MakeAnaTree", true))
65 {
66  produces<std::vector<sim::SimEnergyDeposit>>();
67 }
68 
69 void
71 {
72  if (fMakeAnaTree) {
73  art::ServiceHandle<art::TFileService const> tfs;
74  fNtEdepAna = tfs->make<TNtuple>(
75  "nt_edep_ana",
76  "Edep PosDiff Ana Ntuple",
77  "energy:orig_x:orig_y:orig_z:orig_el:orig_ph:shift_x:shift_y:shift_z:shift_el:shift_ph");
78  }
79 }
80 
81 void
83 {
84  auto sce = lar::providerFrom<spacecharge::SpaceChargeService>();
85  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
86 
87  auto const& inEdepVec = *e.getValidHandle<std::vector<sim::SimEnergyDeposit>>(fEDepTag);
88 
89  auto outEdepVecPtr = std::make_unique<std::vector<sim::SimEnergyDeposit>>();
90  auto& outEdepVec = *outEdepVecPtr;
91  outEdepVec.reserve(inEdepVec.size());
92 
93  geo::Vector_t posOffsetsStart{0.0, 0.0, 0.0};
94  geo::Vector_t posOffsetsEnd{0.0, 0.0, 0.0};
95  for (auto const& edep : inEdepVec) {
96  if (sce->EnableSimSpatialSCE()) {
97  posOffsetsStart = sce->GetPosOffsets({edep.StartX(), edep.StartY(), edep.StartZ()});
98  posOffsetsEnd = sce->GetPosOffsets({edep.EndX(), edep.EndY(), edep.EndZ()});
99  if (larsim::Utils::SCE::out_of_bounds(posOffsetsStart) ||
100  larsim::Utils::SCE::out_of_bounds(posOffsetsEnd) ) {
101  continue;
102  }
103  }
104  auto const isData = fISAlg.CalcIonAndScint(detProp, edep);
105  outEdepVec.emplace_back(
106  isData.numPhotons,
107  isData.numElectrons,
108  0.0,
109  edep.Energy(),
110  geo::Point_t{(float)(edep.StartX() - posOffsetsStart.X()), //x should be subtracted
111  (float)(edep.StartY() + posOffsetsStart.Y()),
112  (float)(edep.StartZ() + posOffsetsStart.Z())},
113  geo::Point_t{(float)(edep.EndX() - posOffsetsEnd.X()), //x should be subtracted
114  (float)(edep.EndY() + posOffsetsEnd.Y()),
115  (float)(edep.EndZ() + posOffsetsEnd.Z())},
116  edep.StartT(),
117  edep.EndT(),
118  edep.TrackID(),
119  edep.PdgCode());
120  if (fMakeAnaTree)
121  fNtEdepAna->Fill(edep.Energy(),
122  edep.X(),
123  edep.Y(),
124  edep.Z(),
125  edep.NumElectrons(),
126  edep.NumPhotons(),
127  outEdepVec.back().X(),
128  outEdepVec.back().Y(),
129  outEdepVec.back().Z(),
130  outEdepVec.back().NumElectrons(),
131  outEdepVec.back().NumPhotons());
132  }
133 
134  e.put(std::move(outEdepVecPtr));
135 }
136 
137 DEFINE_ART_MODULE(spacecharge::ShiftEdepSCE)
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
void produce(art::Event &e) override
Utilities related to art service access.
bool out_of_bounds(geo::Vector_t const &offset)
pdgs p
Definition: selectors.fcl:22
ShiftEdepSCE(fhicl::ParameterSet const &p)
ShiftEdepSCE & operator=(ShiftEdepSCE const &)=delete
Utility function for testing if Space Charge offsets are out of bounds.
larg4::ISCalcSeparate fISAlg
contains information for a single step in the detector simulation
do i e
art::ServiceHandle< art::TFileService > tfs
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
auto const detProp