LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
HitFinderAna_module.cc
Go to the documentation of this file.
1 //
3 // HitFinderAna class
4 //
5 // echurch@fnal.gov
6 //
7 // This algorithm is designed to analyze hits on wires after deconvolution
9 // Framework includes
11 
12 #ifndef HITFINDERANA_H
13 #define HITFINDERANA_H
14 
15 // ROOT includes
16 #include <TMath.h>
17 #include <TH1F.h>
18 #include <TGraph.h>
19 #include <TFile.h>
20 
21 // C++ includes
22 #include <algorithm>
23 #include <sstream>
24 #include <fstream>
25 #include <bitset>
26 
27 // Framework includes
29 #include "fhiclcpp/ParameterSet.h"
37 
38 // LArSoft includes
48 
49 #include "TComplex.h"
50 #include "TString.h"
51 #include "TGraph.h"
52 #include "TH2.h"
53 #include "TTree.h"
54 
56 
57 #include <vector>
58 #include <string>
59 
60 namespace geo { class Geometry; }
61 
63 namespace hit {
64 
66  class HitFinderAna : public art::EDAnalyzer {
67 
68  public:
69 
70  explicit HitFinderAna(fhicl::ParameterSet const& pset);
71  virtual ~HitFinderAna();
72 
74  void analyze (const art::Event& evt);
75  void beginJob();
76  void reconfigure(fhicl::ParameterSet const& p);
77 
78  private:
79 
81  std::string fLArG4ModuleLabel;
82 
83  TTree* fHTree;
84  Int_t fRun;
85  Int_t fEvt;
86  Int_t fNp0;
87  Int_t fNp1;
88  Int_t fNp2;
89  Int_t fN3p0;
90  Int_t fN3p1;
91  Int_t fN3p2;
92  Float_t* fTimep0;
93  Float_t* fTimep1;
94  Float_t* fTimep2;
95  Int_t* fWirep0;
96  Int_t* fWirep1;
97  Int_t* fWirep2;
98  Float_t* fChgp0;
99  Float_t* fChgp1;
100  Float_t* fChgp2;
101  Float_t* fXYZp0;
102  Float_t* fXYZp1;
103  Float_t* fXYZp2;
104 
105  Int_t* fMCPdg0;
106  Int_t* fMCTId0;
107  Float_t* fMCE0;
108  Int_t* fMCPdg1;
109  Int_t* fMCTId1;
110  Float_t* fMCE1;
111  Int_t* fMCPdg2;
112  Int_t* fMCTId2;
113  Float_t* fMCE2;
114 
115  }; // class HitFinderAna
116 
117 }
118 
119 namespace hit{
120 
121  //-------------------------------------------------
122  HitFinderAna::HitFinderAna(fhicl::ParameterSet const& pset)
123  : EDAnalyzer(pset)
124  {
125  this->reconfigure(pset);
126  }
127 
128  //-------------------------------------------------
130  {
131  }
132 
134  {
135  fFFTHitFinderModuleLabel = p.get< std::string >("HitsModuleLabel");
136  fLArG4ModuleLabel = p.get< std::string >("LArGeantModuleLabel");
137  return;
138  }
139  //-------------------------------------------------
141  {
142  // get access to the TFile service
144  fNp0 = 9000;
145  fNp1 = 9000;
146  fNp2 = 9000;
147 
148  fHTree = tfs->make<TTree>("HTree","HTree");
149  fTimep0 = new Float_t[fNp0];
150  fTimep1 = new Float_t[fNp1];
151  fTimep2 = new Float_t[fNp2];
152  fWirep0 = new Int_t[fNp0];
153  fWirep1 = new Int_t[fNp1];
154  fWirep2 = new Int_t[fNp2];
155  fChgp0 = new Float_t[fNp0];
156  fChgp1 = new Float_t[fNp1];
157  fChgp2 = new Float_t[fNp2];
158  fXYZp0 = new Float_t[fNp0*3];
159  fXYZp1 = new Float_t[fNp1*3];
160  fXYZp2 = new Float_t[fNp2*3];
161 
162  fMCPdg0 = new Int_t[fNp0];
163  fMCPdg1 = new Int_t[fNp1];
164  fMCPdg2 = new Int_t[fNp2];
165  fMCTId0 = new Int_t[fNp0];
166  fMCTId1 = new Int_t[fNp1];
167  fMCTId2 = new Int_t[fNp2];
168  fMCE0 = new Float_t[fNp0];
169  fMCE1 = new Float_t[fNp1];
170  fMCE2 = new Float_t[fNp2];
171 
172  fHTree->Branch("HEvt", &fEvt, "HEvt/I");
173  fHTree->Branch("HRun", &fRun, "HRun/I");
174  fHTree->Branch("HNp0", &fNp0, "HNp0/I");
175  fHTree->Branch("HNp1", &fNp1, "HNp1/I");
176  fHTree->Branch("HNp2", &fNp2, "HNp2/I");
177  fHTree->Branch("HN3p0", &fN3p0, "HN3p0/I");
178  fHTree->Branch("HN3p1", &fN3p1, "HN3p1/I");
179  fHTree->Branch("HN3p2", &fN3p2, "HN3p2/I");
180  fHTree->Branch("Htp0", fTimep0, "Htp0[HNp0]/F");
181  fHTree->Branch("Htp1", fTimep1, "Htp1[HNp1]/F");
182  fHTree->Branch("Htp2", fTimep2, "Htp2[HNp2]/F");
183  fHTree->Branch("Hwp0", fWirep0, "Hwp0[HNp0]/I");
184  fHTree->Branch("Hwp1", fWirep1, "Hwp1[HNp1]/I");
185  fHTree->Branch("Hwp2", fWirep2, "Hwp2[HNp2]/I");
186  fHTree->Branch("Hchgp0", fChgp0, "Hchgp0[HNp0]/F");
187  fHTree->Branch("Hchgp1", fChgp1, "Hchgp1[HNp1]/F");
188  fHTree->Branch("Hchgp2", fChgp2, "Hchgp2[HNp2]/F");
189  fHTree->Branch("HMCXYZp0", fXYZp0, "HMCXYZp0[HN3p0]/F");
190  fHTree->Branch("HMCXYZp1", fXYZp1, "HMCXYZp1[HN3p1]/F");
191  fHTree->Branch("HMCXYZp2", fXYZp2, "HMCXYZp2[HN3p2]/F");
192  fHTree->Branch("HMCPdgp0", fMCPdg0, "HMCPdgp0[HNp0]/I");
193  fHTree->Branch("HMCPdgp1", fMCPdg1, "HMCPdgp1[HNp1]/I");
194  fHTree->Branch("HMCPdgp2", fMCPdg2, "HMCPdgp2[HNp2]/I");
195  fHTree->Branch("HMCTIdp0", fMCTId0, "HMCTIdp0[HNp0]/I");
196  fHTree->Branch("HMCTIdp1", fMCTId1, "HMCTIdp1[HNp1]/I");
197  fHTree->Branch("HMCTIdp2", fMCTId2, "HMCTIdp2[HNp2]/I");
198  fHTree->Branch("HMCEp0", fMCE0, "HMCEp0[HNp0]/F");
199  fHTree->Branch("HMCEp1", fMCE1, "HMCEp1[HNp1]/F");
200  fHTree->Branch("HMCEp2", fMCE2, "HMCEp2[HNp2]/F");
201 
202 
203  return;
204 
205  }
206 
207  //-------------------------------------------------
209  {
210 
211  if (evt.isRealData()){
212  throw cet::exception("HitFinderAna: ") << "Not for use on Data yet...\n";
213  }
214 
216  evt.getByLabel(fFFTHitFinderModuleLabel,hitHandle);
217 
220 
221  sim::ParticleList const& _particleList = pi_serv->ParticleList();
222 
223  LOG_VERBATIM("HitFinderAna") << _particleList;
224 
226 
227  std::map<geo::PlaneID, std::vector< art::Ptr<recob::Hit> > > planeIDToHits;
228  for(size_t h = 0; h < hitHandle->size(); ++h)
229  planeIDToHits[hitHandle->at(h).WireID().planeID()].push_back(art::Ptr<recob::Hit>(hitHandle, h));
230 
231 
232  for(auto mapitr : planeIDToHits){
233  fNp0=0; fN3p0=0;
234  fNp1=0; fN3p1=0;
235  fNp2=0; fN3p2=0;
236 
237  geo::PlaneID pid = mapitr.first;
238  auto itr = mapitr.second.begin();
239  while(itr != mapitr.second.end()) {
240 
241  fRun = evt.run();
242  fEvt = evt.id().event();
243 
244  std::vector<sim::TrackIDE> trackides = bt_serv->HitToTrackIDEs(*itr);
245  std::vector<sim::TrackIDE>::iterator idesitr = trackides.begin();
246  std::vector<double> xyz = bt_serv->HitToXYZ(*itr);
247 
248  if (pid.Plane == 0 && fNp0 < 9000){
249  fTimep0[fNp0] = (*itr)->PeakTime();
250  fWirep0[fNp0] = (*itr)->WireID().Wire;
251  fChgp0[fNp0] = (*itr)->Integral();
252 
253  for (unsigned int kk = 0; kk < 3; ++kk){
254  fXYZp0[fNp0*3+kk] = xyz[kk];
255  }
256 
257 
258  while( idesitr != trackides.end() ){
259  fMCTId0[fNp0] = (*idesitr).trackID;
260  if (_particleList.find((*idesitr).trackID) != _particleList.end()){
261  const simb::MCParticle* particle = _particleList.at( (*idesitr).trackID);
262  fMCPdg0[fNp0] = particle->PdgCode();
263  fMCE0[fNp0] = particle->E();
264  }
265  idesitr++;
266  }
267 
268  ++fNp0;
269  }
270 
271  else if (pid.Plane == 1 && fNp1 < 9000){
272  fTimep1[fNp1] = (*itr)->PeakTime();
273  fWirep1[fNp1] = (*itr)->WireID().Wire;
274  fChgp1[fNp1] = (*itr)->Integral();
275 
276  for (unsigned int kk = 0; kk < 3; ++kk){
277  fXYZp1[fNp1*3+kk] = xyz[kk];
278  }
279 
280  while( idesitr != trackides.end() ){
281  fMCTId1[fNp1] = (*idesitr).trackID;
282  if (_particleList.find((*idesitr).trackID) != _particleList.end()){
283  const simb::MCParticle* particle = _particleList.at( (*idesitr).trackID);
284  fMCPdg1[fNp1] = particle->PdgCode();
285  fMCE1[fNp1] = particle->E();
286  }
287  idesitr++;
288  }
289  ++fNp1;
290  }
291 
292  else if (pid.Plane == 2 && fNp2 < 9000){
293  fTimep2[fNp2] = (*itr)->PeakTime();
294  fWirep2[fNp2] = (*itr)->WireID().Wire;
295  fChgp2[fNp2] = (*itr)->Integral();
296 
297  for (unsigned int kk = 0; kk < 3; ++kk){
298  fXYZp2[fNp2*3+kk] = xyz[kk];
299  }
300 
301  while( idesitr != trackides.end()){
302  fMCTId2[fNp2] = (*idesitr).trackID;
303  if (_particleList.find((*idesitr).trackID) != _particleList.end() ){
304  const simb::MCParticle* particle = _particleList.at( (*idesitr).trackID);
305  fMCPdg2[fNp2] = particle->PdgCode();
306  fMCE2[fNp2] = particle->E();
307  }
308  idesitr++;
309  }
310  ++fNp2;
311  }
312 
313  fN3p0 = 3* fNp0;
314  fN3p1 = 3* fNp1;
315  fN3p2 = 3* fNp2;
316 
317  fHTree->Fill();
318  itr++;
319  } // loop on Hits
320  } // loop on map
321 
322  return;
323  }//end analyze method
324 
325 }//end namespace
326 
327 namespace hit{
328 
330 
331 } // end of hit namespace
332 
333 #endif // HITFINDERANA_H
334 
double E(const int i=0) const
Definition: MCParticle.h:237
int PdgCode() const
Definition: MCParticle.h:216
Encapsulate the construction of a single cyostat.
const std::vector< double > HitToXYZ(const recob::Hit &hit)
intermediate_table::iterator iterator
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
Declaration of signal hit object.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
mapped_type at(const key_type &key)
Definition: ParticleList.h:330
std::string fFFTHitFinderModuleLabel
bool isRealData() const
Definition: Event.h:83
std::string fLArG4ModuleLabel
Particle class.
Base class for creation of raw signals on wires.
iterator find(const key_type &key)
Definition: ParticleList.h:318
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void beginJob()
Definition: Breakpoints.cc:14
T get(std::string const &key) const
Definition: ParameterSet.h:231
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:258
void reconfigure(fhicl::ParameterSet const &p)
Detector simulation of raw signals on wires.
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void analyze(const art::Event &evt)
read/write access to event
EventNumber_t event() const
Definition: EventID.h:117
#define LOG_VERBATIM(category)
Particle list in DetSim contains Monte Carlo particle information.
RunNumber_t run() const
Definition: Event.h:77
Namespace collecting geometry-related classes utilities.
EventID id() const
Definition: Event.h:56
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
Encapsulate the construction of a single detector plane.