DEdxdp_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 // Class: DEdxdp
3 // Module Type: analyzer
4 // File: DEdxdp_module.cc
5 //
6 // This is a simple module that makes plot of dE/dx using 3D reconstructed tracks.
7 // It cab be run before each MC production on the sample of generated muon tracks.
8 // DP calibrations, quality control, prompt measure of effective gain
9 //
10 // Author: andrea.scarpelli@cern.ch
11 //
12 ////////////////////////////////////////////////////////////////////////
13 
25 
27 
30 #include "canvas/Persistency/Common/FindManyP.h"
36 #include "art_root_io/TFileService.h"
38 #include "fhiclcpp/ParameterSet.h"
40 
42 
43 #include "TH1.h"
44 #include "TTree.h"
45 
46 namespace pdunedp
47 {
48  class DEdxdp;
49 }
50 
52 public:
53  explicit DEdxdp(fhicl::ParameterSet const & p);
54 
55  //plugins should not be copied or assigned.
56  DEdxdp(DEdxdp const &) = delete;
57  DEdxdp(DEdxdp &&) = delete;
58  DEdxdp & operator = (DEdxdp const &) = delete;
59  DEdxdp & operator = (DEdxdp &&) = delete;
60 
61  // Required functions.
62  void analyze(art::Event const & e) override;
63  void beginJob() override;
64  void endJob() override;
65 
66  void reconfigure(fhicl::ParameterSet const& p) ;
67 
68 private:
69 
70  // Declare member data here.
71 
72  // void CountdEdx(const std::vector < art::Ptr< recob::Hit > > & hits, const std::vector < recob::TrackHitMeta const* > & data); // MeV/cm
73  void CountdEdx(detinfo::DetectorClocksData const& clockData,
74  detinfo::DetectorPropertiesData const& detProp,
75  const std::vector < art::Ptr< recob::Hit > > & hits, const std::vector< recob::TrackHitMeta const* > & data);
76  void ResetVars();
77 
78  TTree *fTree;
79  TTree *fTreere;
80  int fRun;
81  int fSubRun;
82  int fEvent;
83  int fCryo;
84  int fTPC;
85  int fView;
86  int fTrackID;
88 
89  double fdQdx;
90  double fdEdx;
91  double fdQ;
92  double fdx;
93 
94  // Module labels to get data products
100 
101 };
102 
104  :
105  EDAnalyzer(p),
106  fCalorimetryAlg(p.get<fhicl::ParameterSet>("CalorimetryAlg"))
107  // More initializers here.
108 {
109  reconfigure(p);
110 }
111 
113 {
115  fTreere = tfs->make<TTree>("entries","entries tree");
116  fTree = tfs->make<TTree>("DEdx","dedx tree");
117 
118  fTreere->Branch("fRun", &fRun, "fRun/I");
119  fTreere->Branch("fEvent", &fEvent, "fEvent/I");
120  fTreere->Branch("fNumberOfTracks", &fNumberOfTracks, "fNumberOfTracks/I");
121 
122  fTree->Branch("fRun", &fRun, "fRun/I");
123  fTree->Branch("fSubRun", &fSubRun, "fSubRun/I");
124  fTree->Branch("fEvent", &fEvent, "fEvent/I");
125  fTree->Branch("fCryo", &fCryo, "fCryo/I");
126  fTree->Branch("fTPC", &fTPC, "fTPC/I");
127  fTree->Branch("fTrackID", &fTrackID, "fTrackID/I");
128  fTree->Branch("fView", &fView, "fView/I");
129  fTree->Branch("fdQdx", &fdQdx, "fdQdx/D");
130  fTree->Branch("fdEdx", &fdEdx, "fdEdx/D");
131  fTree->Branch("fdQ", &fdQ, "fdQ/D");
132  fTree->Branch("fdx", &fdx, "fdx/D");
133 }
134 
136 {
137 }
138 
140 {
141  fHitModuleLabel = p.get< std::string >("HitModuleLabel");
142  fTrackModuleLabel = p.get< std::string >("TrackModuleLabel");
143  fGainPerView = p.get<int>("GainPerView");
144 }
145 
147 {
148  // Implementation of required member function here.
149  ResetVars();
150  fRun = e.run();
151  fSubRun = e.subRun();
152  fEvent = e.id().event();
153 
154  // tracks
155  auto trkHandle = e.getValidHandle< std::vector<recob::Track> >(fTrackModuleLabel);
156  fNumberOfTracks = trkHandle->size();
157 
158  const art::FindManyP<recob::Hit, recob::TrackHitMeta> fmthm(trkHandle, e, fTrackModuleLabel);
159  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
160  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e, clockData);
161 
162  if (fmthm.isValid())
163  {
164  // loop over tracks
165  for (size_t t = 0; t < trkHandle->size(); ++t)
166  {
167  auto vhit = fmthm.at(t);
168  auto vmeta = fmthm.data(t);
169 
170  fTrackID = t;
171  CountdEdx(clockData, detProp, vhit, vmeta);
172  }
173  }
174  fTreere->Fill();
175 }
176 
178  detinfo::DetectorPropertiesData const& detProp,
179  const std::vector < art::Ptr< recob::Hit > > & hits, const std::vector< recob::TrackHitMeta const* > & data) // MeV/cm
180 {
181  for (size_t h = 0; h < hits.size(); ++h)
182  {
183  fCryo = hits[h]->WireID().Cryostat;
184  fTPC = hits[h]->WireID().TPC;
185  fView = hits[h]->WireID().Plane;
186 
187  unsigned short plane = hits[h]->WireID().Plane;
188  unsigned short time = hits[h]->PeakTime();
189 
190  double dqadc = hits[h]->Integral();
191  if (!std::isnormal(dqadc) || (dqadc < 0)) dqadc = 0.0;
192 
193  double t0 = 0;
194 
195  fdQdx = 0.0;
196 
197  fdQ = dqadc;
198  fdx = data[h]->Dx();
199  if ((fdx > 0) && (fdQ > 0))
200  {
201  fdQdx = fdQ/fdx;
202  fdQdx /= fGainPerView;
203  fdEdx = fCalorimetryAlg.dEdx_AREA(clockData, detProp, fdQdx, time, plane, t0);
204  fdQdx *= fCalorimetryAlg.LifetimeCorrection(clockData, detProp, time, t0);
205  //if (fdEdx > 35) fdEdx = 35;
206  }
207  fTree->Fill();
208  }
209 }
210 
212 {
213  fdQdx = 0.0;
214  fdEdx = 0.0;
215  fdQ = 0.0;
216  fdx = 0.0;
217  fNumberOfTracks = 0;
218 }
219 
220 
code to link reconstructed objects back to the MC truth information
void beginJob() override
calo::CalorimetryAlg fCalorimetryAlg
DEdxdp(fhicl::ParameterSet const &p)
std::string string
Definition: nybbler.cc:12
std::string fHitModuleLabel
struct vector vector
Class to keep data related to recob::Hit associated with recob::Track.
size_t fNumberOfTracks
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::string fTrackModuleLabel
art framework interface to geometry description
DEdxdp & operator=(DEdxdp const &)=delete
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
void reconfigure(fhicl::ParameterSet const &p)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
RunNumber_t run() const
Definition: DataViewImpl.cc:71
Declaration of signal hit object.
Contains all timing reference information for the detector.
Provides recob::Track data product.
double dEdx_AREA(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
EventNumber_t event() const
Definition: EventID.h:116
Access the description of detector geometry.
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
Collection of Physical constants used in LArSoft.
void CountdEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Hit > > &hits, const std::vector< recob::TrackHitMeta const * > &data)
EventID id() const
Definition: Event.cc:34
std::string fCalorimetryModuleLabel
void endJob() override
void analyze(art::Event const &e) override