DetRespDrift_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: DetRespDrift
3 // Module Type: filter
4 // File: DetRespDrift_module.cc
5 //
6 // Generated at Wed Jul 8 2015 by Luke Vinton
7 ////////////////////////////////////////////////////////////////////////
8 
9 
10 // framework includes....
18 #include "fhiclcpp/ParameterSet.h"
19 #include "art_root_io/TFileService.h"
22 
23 // novasoft stuff
25 #include "RecoBase/Track.h"
26 #include "RecoBase/CellHit.h"
27 #include "Calibrator/Calibrator.h"
29 
30 // C++
31 #include <memory>
32 #include <string>
33 #include <iostream>
34 #include <vector>
35 
36 // ROOT
37 #include "TH2D.h"
38 #include "TFile.h"
39 #include "TVector3.h"
40 #include "TTree.h"
41 
42 namespace caldp {
43  class PCHit;
44 }
45 
46 
47 
48 namespace calib {
49  class DetRespDrift;
50 
51  class DetRespDrift : public art::EDFilter {
52  public:
53  explicit DetRespDrift(fhicl::ParameterSet const & p);
54  virtual ~DetRespDrift();
55 
56  bool filter(art::Event & e) override;
57  void reconfigure(fhicl::ParameterSet const & p);
58  void beginJob() override;
59  void endJob() override;
60  bool beginRun(art::Run & r) override;
61  bool endRun(art::Run & r) override;
62 
63  private:
64  double getPECorr(art::Event & e,caldp::PCHit const &pchit);
65 
66  TTree* fTree;
67  //declare variables for ttree
68  int run;
69  uint32_t EventTimeHigh;
70  double path;
71  double trueE;
72  double PECorr;
73  double pe;
75 
76 
82 
83  };
84 
85 
86  DetRespDrift::DetRespDrift(fhicl::ParameterSet const & p)
87  : EDFilter(p)
88  {
89  this->reconfigure(p);
90 
91  }
92 
94  {
95  // Clean up dynamic memory and other resources here.
96  }
97 
99  {
100  /// Get the reconstructed tracks
102  e.getByLabel(fLabel, tracks);
103  if( tracks->size() == 0 ) return true;
104 
105  run = (int)(e.run());
106  art::Timestamp ts = e.time();
107  EventTimeHigh = ts.timeHigh();
108 
112 
113  if( !PCHitAvgGetter.isValid() && !PCHitXYGetter.isValid() && !PCHitZGetter.isValid()) return false;
114 
115  // loop over stopping tracks in event
116  for( unsigned int i=0; i<tracks->size(); ++i ){
117 
118  // loop over PCHits associated to stopping track
119  std::vector<art::Ptr<caldp::PCHit> > hitsXY = PCHitXYGetter.at(i);
120  std::vector<art::Ptr<caldp::PCHit> > hitsZ = PCHitZGetter.at(i);
121  std::vector<art::Ptr<caldp::PCHit> > hitsAvg = PCHitAvgGetter.at(i);
122 
123  // XY hits
124  for( unsigned int j=0; j<hitsXY.size(); ++j ){
125 
126  path = hitsXY[j]->Path();
127  trueE = hitsXY[j]->TrueMeV();
128  PECorr = this->getPECorr(e,*hitsXY[j]);
129  pe = hitsXY[j]->PE();
130  pathQual = "XY";
131 
132  fTree->Fill(); //fill ttree
133  }
134 
135  // Z hits
136  for( unsigned int j=0; j<hitsZ.size(); ++j ){
137 
138  path = hitsZ[j]->Path();
139  trueE = hitsZ[j]->TrueMeV();
140  PECorr = this->getPECorr(e,*hitsZ[j]);
141  pe = hitsZ[j]->PE();
142  pathQual = "Z";
143 
144  fTree->Fill(); //fill ttree
145  }
146 
147  // Avg hits
148  for( unsigned int j=0; j<hitsAvg.size(); ++j ){
149 
150  path = hitsAvg[j]->Path();
151  trueE = hitsAvg[j]->TrueMeV();
152  PECorr = this->getPECorr(e,*hitsAvg[j]);
153  pe = hitsAvg[j]->PE();
154  pathQual = "Avg";
155 
156  fTree->Fill(); //fill ttree
157  }
158 
159  }
160 
161  return true;
162 
163  }
164 
166 
167  //Calibrator necessary to get Atten information
169 
170  //Make mock cellhit
171  rb::CellHit cellhit;
172  cellhit.SetPlane(pchit.Plane());
173  cellhit.SetCell(pchit.Cell());
174  cellhit.SetView(pchit.View());
175  cellhit.SetTNS(pchit.TNS(),pchit.GoodTime());
176  if(!e.isRealData())cellhit.SetMC(); // assume only filled for MC...
177  cellhit.SetPE(pchit.PE());
178 
179  double pecorr = calibrator->GetPECorr(cellhit, pchit.W());
180  return pecorr;
181  }
182 
184  {
185  fPCHitLabel = pset.get< std::string >("PCHitLabel"); //Label of PCHitList module
186  fQualXYName = pset.get< std::string >("QualXYName"); //Instance label, "XY" quality hits
187  fQualZName = pset.get< std::string >("QualZName"); //Instance label, "Z" quality hits
188  fQualAvgName = pset.get< std::string >("QualAvgName"); //Instance label, "Avg" quality hits
189  fLabel = pset.get<std::string>("Label");
190 
191  }
192 
194  {
195  // histograms for output
197 
198  fTree = tfs->make<TTree>("fTree","tree to hold variables");
199  fTree->Branch("run",&run);
200  fTree->Branch("EventTimeHigh",&EventTimeHigh);
201  fTree->Branch("pe",&pe);
202  fTree->Branch("PECorr",&PECorr);
203  fTree->Branch("trueE",&trueE);
204  fTree->Branch("path",&path);
205  fTree->Branch("pathQual",&pathQual);
206 
207 
208  }
209 
211  return true;
212  }
213 
215 
217 
218  return true;
219  }
220 
222  {
223 
224  }
225 }// end namespace
227 
float TNS() const
Return uncorrected hit time.
Definition: PCHit.h:54
void SetTNS(float tns, bool good)
Definition: CellHit.h:56
const char * p
Definition: xmltok.h:285
bool GoodTime() const
Return quality of timing fit for cell.
Definition: PCHit.h:56
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
int Cell() const
Return cell value.
Definition: PCHit.h:26
bool endRun(art::Run &r) override
DEFINE_ART_MODULE(TestTMapFile)
"Pre-calibration hit". Common input to calibration procedures
Definition: PCHit.h:16
Definition: Run.h:21
Module that kips a configurable number of events between each that it allows through. Note that this module really skips (N-1) events, it uses a simple modular division as its critera. This module will cut down the data sample to 1/N of its original size.
void SetView(geo::View_t view)
Definition: CellHit.h:54
void SetPlane(unsigned short plane)
Definition: CellHit.h:53
float W() const
Return W value.
Definition: PCHit.h:44
void SetCell(unsigned short cell)
Definition: CellHit.h:52
bool isRealData() const
void reconfigure(fhicl::ParameterSet const &p)
CDPStorage service.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
void SetPE(float pe)
Definition: CellHit.h:55
Timestamp time() const
float PE() const
Return PE value.
Definition: PCHit.h:38
void beginJob()
Encapsulate the geometry of one entire detector (near, far, ndos)
T get(std::string const &key) const
Definition: ParameterSet.h:231
const double j
Definition: BetheBloch.cxx:29
RunNumber_t run() const
int Plane() const
Return plane value.
Definition: PCHit.h:24
geo::View_t View() const
Return view.
Definition: PCHit.h:36
Definition: run.py:1
void SetMC(bool isMC=true)
Definition: RawDigit.h:106
double getPECorr(art::Event &e, caldp::PCHit const &pchit)
Histograms used by attenuation calibration.
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
TRandom3 r(0)
double GetPECorr(rb::CellHit const &cellhit, double w)
Float_t e
Definition: plot.C:35
bool beginRun(art::Run &r) override
bool filter(art::Event &e) override
enum BeamMode string