All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
ICARUSOpHitAna Class Reference
Inheritance diagram for ICARUSOpHitAna:

Public Member Functions

 ICARUSOpHitAna (fhicl::ParameterSet const &p)
 
 ICARUSOpHitAna (ICARUSOpHitAna const &)=delete
 
 ICARUSOpHitAna (ICARUSOpHitAna &&)=delete
 
ICARUSOpHitAnaoperator= (ICARUSOpHitAna const &)=delete
 
ICARUSOpHitAnaoperator= (ICARUSOpHitAna &&)=delete
 
void analyze (art::Event const &e) override
 
void beginJob () override
 
void endJob () override
 

Private Attributes

TFile * _f
 
std::string _output_fname
 
std::string _wf_label
 
std::string _mchit_label
 
std::vector< std::string > _hit_label_v
 
TTree * _wftree
 
int _run
 
int _event
 
int _ch
 
double _tstart
 
std::vector< float > _wf
 
std::vector< std::string > _wf_label_v
 
TTree * _mchittree
 
std::vector< TTree * > _hittree_v
 
double _width
 
double _time
 
double _amp
 
double _area
 
double _pe
 
double _time_true
 
double _pe_true
 
int _mc_idx
 
double _match_time_min
 
double _match_time_max
 
double _match_dt
 
TTree * _geotree
 

Detailed Description

Definition at line 29 of file ICARUSOpHitAna_module.cc.

Constructor & Destructor Documentation

ICARUSOpHitAna::ICARUSOpHitAna ( fhicl::ParameterSet const &  p)
explicit

Definition at line 85 of file ICARUSOpHitAna_module.cc.

86  : EDAnalyzer{p}, _wftree(nullptr), _mchittree(nullptr), _geotree(nullptr)
87 {
88  _output_fname = p.get<std::string>("OutputFileName" );
89  _wf_label = p.get<std::string>("OpDetWaveformProducer" );
90  _mchit_label = p.get<std::string>("MCOpHitProducer" );
91  _hit_label_v = p.get<std::vector<std::string> >("OpHitProducerList");
92  _match_time_min = p.get<double>("MatchTimeStart",0.100); // in micro-seconds
93  _match_time_max = p.get<double>("MatchTimeEnd",0.120); // in micro-seconds
95  assert(_match_dt>0);
96 }
pdgs p
Definition: selectors.fcl:22
std::vector< std::string > _hit_label_v
ICARUSOpHitAna::ICARUSOpHitAna ( ICARUSOpHitAna const &  )
delete
ICARUSOpHitAna::ICARUSOpHitAna ( ICARUSOpHitAna &&  )
delete

Member Function Documentation

void ICARUSOpHitAna::analyze ( art::Event const &  e)
override

Definition at line 180 of file ICARUSOpHitAna_module.cc.

181 {
182 
183  _event = e.id().event();
184  _run = e.id().run();
185 
186  // Fill waveforms if requested
187  if(!_wf_label.empty()) {
188  art::Handle< std::vector< raw::OpDetWaveform > > wf_h;
189  e.getByLabel(_wf_label,wf_h);
190  if(!wf_h.isValid()){
191  std::cerr << "Invalid producer for raw::OpDetWaveform: " << _wf_label << std::endl;
192  throw std::exception();
193  }
194  for(auto const& wf : (*wf_h)) {
195  _wf.resize(wf.size());
196  for(size_t i=0; i<_wf.size(); ++i) { _wf.at(i) = wf.at(i); }
197  _ch=wf.ChannelNumber();
198  _tstart=wf.TimeStamp();
199  _wftree->Fill();
200  }
201  }
202 
203  // get MCOpHit
204  art::Handle< std::vector< recob::OpHit > > mchit_h;
205  e.getByLabel(_mchit_label, mchit_h);
206  if(!mchit_h.isValid()) {
207  std::cerr << "Invalid producer for truth recob::OpHit: " << _mchit_label << std::endl;
208  throw std::exception();
209  }
210  // Create a "time-map" of MCOpHit
211  // outer-array = op channel number
212  // inner map ... key = mchit timing
213  // value = mchit location (i.e. array index number)
214  std::vector<std::map<double,int> > mchit_db;
215  // fill the map
216  auto const geop = lar::providerFrom<geo::Geometry>();
217  mchit_db.resize(geop->NOpChannels());
218  for(size_t mchit_index=0; mchit_index < mchit_h->size(); ++mchit_index) {
219  auto const& mchit = (*mchit_h)[mchit_index];
220  _pe_true = mchit.PE();
221  _time_true = mchit.PeakTime();
222  _ch = mchit.OpChannel();
223  _mc_idx = mchit_index;
224  _mchittree->Fill();
225  auto& db = mchit_db.at(mchit.OpChannel());
226  db[mchit.PeakTime() + _match_time_min] = mchit_index;
227  }
228  // now fill ophit trees
229  for(size_t label_idx=0; label_idx<_hit_label_v.size(); ++label_idx) {
230  // Get data product handle
231  auto const& label = _hit_label_v[label_idx];
232  auto& hittree = _hittree_v[label_idx];
233  art::Handle< std::vector< recob::OpHit > > hit_h;
234  e.getByLabel(label,hit_h);
235  if(!hit_h.isValid()){
236  std::cerr << "Invalid producer for recob::OpHit: " << label << std::endl;
237  throw std::exception();
238  }
239 
240  // keep the record of which mchit was used (to store un-tagged mchit at the end)
241  std::vector<bool> mchit_used(mchit_h->size(),false);
242  // now loop over hit, identify mc hit, fill ttree
243  for(auto const& hit : (*hit_h)) {
244  // fill simple info
245  _ch=hit.OpChannel();
246  _time = hit.PeakTime();
247  _amp = hit.Amplitude();
248  _width = hit.Width();
249  _area = hit.Area();
250  _pe = hit.PE();
251  // search for corresponding mchit
252  auto const& db = mchit_db.at(_ch);
253  auto low = db.lower_bound(_time);
254  _pe_true = -1;
255  _time_true = std::numeric_limits<double>::max();
256  if(low != db.begin()) {
257  --low;
258  // get mc ophit
259  auto const& mchit = (*mchit_h).at((*low).second);
260  // Check if this is in the "match" range
261  if( (_time - (*low).first) < _match_dt ) {
262  _pe_true = mchit.PE();
263  _time_true = mchit.PeakTime();
264  _mc_idx = (*low).second;
265  mchit_used[(*low).second] = true;
266  }
267  }
268  hittree->Fill();
269  }
270  // now fill mchit info that was not tagged
271  for(size_t mchit_idx=0; mchit_idx < mchit_used.size(); ++mchit_idx) {
272  if(mchit_used[mchit_idx]) continue;
273  auto const& mchit = (*mchit_h)[mchit_idx];
274  _ch = mchit.OpChannel();
275  _pe_true = mchit.PE();
276  _time_true = mchit.PeakTime();
277  // fill the "reco hit" values with vogus values
278  _time = std::numeric_limits<double>::max();
279  _amp = std::numeric_limits<double>::max();
280  _area = std::numeric_limits<double>::max();
281  _pe = -1;
282  hittree->Fill();
283  }
284 
285  }
286 
287 }
BEGIN_PROLOG could also be cerr
std::vector< std::string > _hit_label_v
process_name hit
Definition: cheaterreco.fcl:51
standard_dbscan3dalg useful for diagnostics hits not in a line will not be clustered on on only for track like only for track like on on the smaller the less shower like tracks low
std::vector< TTree * > _hittree_v
do i e
height to which particles are projected pnfs larsoft persistent physics cosmics Fermilab CORSIKA standard He_showers_ * db
std::vector< float > _wf
void ICARUSOpHitAna::beginJob ( )
override

Definition at line 98 of file ICARUSOpHitAna_module.cc.

99 {
100  _f = TFile::Open(_output_fname.c_str(),"RECREATE");
101  _wftree = nullptr;
102  if(!_wf_label.empty()) {
103  std::string name = _wf_label + "_wftree";
104  _wftree = new TTree(name.c_str(),name.c_str());
105  _wftree->Branch("run",&_run,"run/I");
106  _wftree->Branch("event",&_event,"event/I");
107  _wftree->Branch("ch",&_ch,"ch/I");
108  _wftree->Branch("wf",&_wf);
109  _wftree->Branch("tstart",&_tstart,"tstart/D");
110  }
111 
112  _mchittree = new TTree("mchittree","mchittree");
113  _mchittree->Branch("run",&_run,"run/I");
114  _mchittree->Branch("event",&_event,"event/I");
115  _mchittree->Branch("ch",&_ch,"ch/I");
116  _mchittree->Branch("mc_idx",&_mc_idx,"mc_idx/I");
117  _mchittree->Branch("pe_true",&_pe_true,"pe_true/D");
118  _mchittree->Branch("time_true",&_time_true,"time_true/D");
119 
120  for(auto const& label : _hit_label_v) {
121  std::string name = label + "_hittree";
122  auto hittree = new TTree(name.c_str(),name.c_str());
123  hittree->Branch("run",&_run,"run/I");
124  hittree->Branch("event",&_event,"event/I");
125  hittree->Branch("ch",&_ch,"ch/I");
126  hittree->Branch("amp",&_amp,"amp/D");
127  hittree->Branch("area",&_area,"area/D");
128  hittree->Branch("width",&_width,"width/D");
129  hittree->Branch("time",&_time,"time/D");
130  hittree->Branch("pe",&_pe,"pe/D");
131  hittree->Branch("time_true",&_time_true,"time_true/D");
132  hittree->Branch("pe_true",&_pe_true,"pe_true/D");
133  hittree->Branch("mc_idx",&_mc_idx,"mc_idx/I");
134  _hittree_v.push_back(hittree);
135  }
136 
137  _geotree = new TTree("geotree","geotree");
138  std::vector<double> pmtX, pmtY, pmtZ;
139  std::vector<double> minX, minY, minZ;
140  std::vector<double> maxX, maxY, maxZ;
141  auto const geop = lar::providerFrom<geo::Geometry>();
142  double PMTxyz[3];
143  for(size_t opch=0; opch<geop->NOpChannels(); ++opch) {
144  geop->OpDetGeoFromOpChannel(opch).GetCenter(PMTxyz);
145  pmtX.push_back(PMTxyz[0]);
146  pmtY.push_back(PMTxyz[1]);
147  pmtZ.push_back(PMTxyz[2]);
148  }
149  for(auto iter=geop->begin_TPC(); iter!=geop->end_TPC(); ++iter) {
150  auto const& tpc = (*iter);
151  minX.push_back(tpc.BoundingBox().MinX());
152  minY.push_back(tpc.BoundingBox().MinY());
153  minZ.push_back(tpc.BoundingBox().MinZ());
154  maxX.push_back(tpc.BoundingBox().MaxX());
155  maxY.push_back(tpc.BoundingBox().MaxY());
156  maxZ.push_back(tpc.BoundingBox().MaxZ());
157  }
158  _geotree->Branch("pmtX",&pmtX);
159  _geotree->Branch("pmtY",&pmtY);
160  _geotree->Branch("pmtZ",&pmtZ);
161  _geotree->Branch("minX",&minX);
162  _geotree->Branch("minY",&minY);
163  _geotree->Branch("minZ",&minZ);
164  _geotree->Branch("maxX",&maxX);
165  _geotree->Branch("maxY",&maxY);
166  _geotree->Branch("maxZ",&maxZ);
167  _geotree->Fill();
168 }
std::vector< std::string > _hit_label_v
std::vector< TTree * > _hittree_v
then echo fcl name
std::vector< float > _wf
void ICARUSOpHitAna::endJob ( )
override

Definition at line 170 of file ICARUSOpHitAna_module.cc.

171 {
172  _f->cd();
173  _mchittree->Write();
174  if(_wftree) _wftree->Write();
175  for(auto& ptr : _hittree_v) { _f->cd(); ptr->Write(); }
176  _f->cd(); _geotree->Write();
177  if(_f) _f->Close();
178 }
std::vector< TTree * > _hittree_v
ICARUSOpHitAna& ICARUSOpHitAna::operator= ( ICARUSOpHitAna const &  )
delete
ICARUSOpHitAna& ICARUSOpHitAna::operator= ( ICARUSOpHitAna &&  )
delete

Member Data Documentation

double ICARUSOpHitAna::_amp
private

Definition at line 67 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_area
private

Definition at line 68 of file ICARUSOpHitAna_module.cc.

int ICARUSOpHitAna::_ch
private

Definition at line 57 of file ICARUSOpHitAna_module.cc.

int ICARUSOpHitAna::_event
private

Definition at line 57 of file ICARUSOpHitAna_module.cc.

TFile* ICARUSOpHitAna::_f
private

Definition at line 48 of file ICARUSOpHitAna_module.cc.

TTree* ICARUSOpHitAna::_geotree
private

Definition at line 80 of file ICARUSOpHitAna_module.cc.

std::vector<std::string> ICARUSOpHitAna::_hit_label_v
private

Definition at line 53 of file ICARUSOpHitAna_module.cc.

std::vector<TTree*> ICARUSOpHitAna::_hittree_v
private

Definition at line 64 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_match_dt
private

Definition at line 77 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_match_time_max
private

Definition at line 76 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_match_time_min
private

Definition at line 75 of file ICARUSOpHitAna_module.cc.

int ICARUSOpHitAna::_mc_idx
private

Definition at line 72 of file ICARUSOpHitAna_module.cc.

std::string ICARUSOpHitAna::_mchit_label
private

Definition at line 52 of file ICARUSOpHitAna_module.cc.

TTree* ICARUSOpHitAna::_mchittree
private

Definition at line 63 of file ICARUSOpHitAna_module.cc.

std::string ICARUSOpHitAna::_output_fname
private

Definition at line 49 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_pe
private

Definition at line 69 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_pe_true
private

Definition at line 71 of file ICARUSOpHitAna_module.cc.

int ICARUSOpHitAna::_run
private

Definition at line 57 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_time
private

Definition at line 66 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_time_true
private

Definition at line 70 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_tstart
private

Definition at line 58 of file ICARUSOpHitAna_module.cc.

std::vector<float> ICARUSOpHitAna::_wf
private

Definition at line 59 of file ICARUSOpHitAna_module.cc.

std::string ICARUSOpHitAna::_wf_label
private

Definition at line 51 of file ICARUSOpHitAna_module.cc.

std::vector<std::string> ICARUSOpHitAna::_wf_label_v
private

Definition at line 60 of file ICARUSOpHitAna_module.cc.

TTree* ICARUSOpHitAna::_wftree
private

Definition at line 56 of file ICARUSOpHitAna_module.cc.

double ICARUSOpHitAna::_width
private

Definition at line 65 of file ICARUSOpHitAna_module.cc.


The documentation for this class was generated from the following file: