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

Public Member Functions

 ICARUSOpHitTuple (fhicl::ParameterSet const &p)
 
 ICARUSOpHitTuple (ICARUSOpHitTuple const &)=delete
 
 ICARUSOpHitTuple (ICARUSOpHitTuple &&)=delete
 
ICARUSOpHitTupleoperator= (ICARUSOpHitTuple const &)=delete
 
ICARUSOpHitTupleoperator= (ICARUSOpHitTuple &&)=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 _mct_label
 
std::vector< std::string > _hit_label_v
 
int _run
 
int _event
 
int _ch
 
double _event_time
 
double _event_x
 
double _event_y
 
double _event_z
 
double _event_dr
 
double _event_dx
 
double _event_dy
 
double _event_dz
 
int _tpc
 
TTree * _wftree
 
double _tstart
 
std::vector< float > _wf
 
std::vector< std::string > _wf_label_v
 
std::vector< TTree * > _hittree_v
 
double _width
 
double _time
 
double _amp
 
double _area
 
double _pe
 
TTree * _geotree
 

Detailed Description

Definition at line 30 of file ICARUSOpHitTuple_module.cc.

Constructor & Destructor Documentation

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

Definition at line 82 of file ICARUSOpHitTuple_module.cc.

83  : EDAnalyzer{p}, _wftree(nullptr), _geotree(nullptr)
84 {
85  _output_fname = p.get<std::string>("OutputFileName" );
86  _wf_label = p.get<std::string>("OpDetWaveformProducer" );
87  _mct_label = p.get<std::string>("MCTruthProducer","generator");
88  _hit_label_v = p.get<std::vector<std::string> >("OpHitProducerList");
89 }
pdgs p
Definition: selectors.fcl:22
std::vector< std::string > _hit_label_v
ICARUSOpHitTuple::ICARUSOpHitTuple ( ICARUSOpHitTuple const &  )
delete
ICARUSOpHitTuple::ICARUSOpHitTuple ( ICARUSOpHitTuple &&  )
delete

Member Function Documentation

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

Definition at line 179 of file ICARUSOpHitTuple_module.cc.

180 {
181 
182  _event = e.id().event();
183  _run = e.id().run();
184 
185  // Fill waveforms if requested
186  if(!_wf_label.empty()) {
187  art::Handle< std::vector< raw::OpDetWaveform > > wf_h;
188  e.getByLabel(_wf_label,wf_h);
189  if(!wf_h.isValid()){
190  std::cerr << "Invalid producer for raw::OpDetWaveform: " << _wf_label << std::endl;
191  throw std::exception();
192  }
193  for(auto const& wf : (*wf_h)) {
194  _wf.resize(wf.size());
195  for(size_t i=0; i<_wf.size(); ++i) { _wf.at(i) = wf.at(i); }
196  _ch=wf.ChannelNumber();
197  _tstart=wf.TimeStamp();
198  _wftree->Fill();
199  }
200  }
201 
202  // get MCTruth
203  _event_time = std::numeric_limits<double>::max();
204  _event_x = _event_y = _event_z = std::numeric_limits<double>::max();
205  if(!_mct_label.empty()) {
206  art::Handle< std::vector<simb::MCTruth> > mct_h;
207  e.getByLabel(_mct_label,mct_h);
208  if(!mct_h.isValid()) {
209  std::cerr << "Invalid producer for simb::MCTruth: " << _mct_label << std::endl;
210  throw std::exception();
211  }
212  for(size_t mct_index=0; mct_index<mct_h->size(); ++mct_index) {
213 
214  auto const& mct = (*mct_h)[mct_index];
215 
216  for(int i=0; i<mct.NParticles(); ++i) {
217  auto const& mcp = mct.GetParticle(i);
218  if(mcp.StatusCode() != 1) continue;
219 
220  auto const& pos = mcp.Position(0);
221  if(_event_time < pos.T()/1000.) continue;
222  _event_time = pos.T()/1000.;
223  _event_x = pos.X();
224  _event_y = pos.Y();
225  _event_z = pos.Z();
226  }
227  }
228  }
229 
230  // set dr, dx, dy, dz
231  _event_dr = _event_dx = _event_dy = _event_dz =std::numeric_limits<double>::max();
232  _tpc = -1;
233  if(_event_time != std::numeric_limits<double>::max()) {
234  auto const geop = lar::providerFrom<geo::Geometry>();
235  // measure smallest dr to any pmt
236  double PMTxyz[3];
237  for(size_t opch=0; opch<geop->NOpChannels(); ++opch) {
238  geop->OpDetGeoFromOpChannel(opch).GetCenter(PMTxyz);
239  double dx = PMTxyz[0] - _event_x;
240  double dy = PMTxyz[1] - _event_y;
241  double dz = PMTxyz[2] - _event_z;
242  double dr = sqrt(pow(dx,2)+pow(dy,2)+pow(dz,2));
243  if(_event_dr < dr) continue;
244  _event_dr = dr;
245  _event_dx = dx;
246  _event_dy = dy;
247  _event_dz = dz;
248  }
249  }
250 
251  // now fill ophit trees
252  for(size_t label_idx=0; label_idx<_hit_label_v.size(); ++label_idx) {
253  // Get data product handle
254  auto const& label = _hit_label_v[label_idx];
255  auto& hittree = _hittree_v[label_idx];
256  art::Handle< std::vector< recob::OpHit > > hit_h;
257  e.getByLabel(label,hit_h);
258  if(!hit_h.isValid()){
259  std::cerr << "Invalid producer for recob::OpHit: " << label << std::endl;
260  throw std::exception();
261  }
262 
263  // now loop over hit, identify mc hit, fill ttree
264  for(auto const& hit : (*hit_h)) {
265  // fill simple info
266  _ch=hit.OpChannel();
267  _time = hit.PeakTime();
268  _amp = hit.Amplitude();
269  _width = hit.Width();
270  _area = hit.Area();
271  _pe = hit.PE();
272  hittree->Fill();
273  }
274 
275  }
276 
277 }
BEGIN_PROLOG could also be cerr
process_name hit
Definition: cheaterreco.fcl:51
std::vector< float > _wf
std::vector< std::string > _hit_label_v
std::vector< TTree * > _hittree_v
do i e
void ICARUSOpHitTuple::beginJob ( )
override

Definition at line 91 of file ICARUSOpHitTuple_module.cc.

92 {
93  _f = TFile::Open(_output_fname.c_str(),"RECREATE");
94  _wftree = nullptr;
95  if(!_wf_label.empty()) {
96  std::string name = _wf_label + "_wftree";
97  _wftree = new TTree(name.c_str(),name.c_str());
98  _wftree->Branch("run",&_run,"run/I");
99  _wftree->Branch("event",&_event,"event/I");
100  _wftree->Branch("event_time",&_event_time,"event_time/D");
101  _wftree->Branch("event_x",&_event_x,"event_x/D");
102  _wftree->Branch("event_y",&_event_y,"event_y/D");
103  _wftree->Branch("event_z",&_event_z,"event_z/D");
104  _wftree->Branch("event_dr",&_event_dr,"event_dr/D");
105  _wftree->Branch("event_dx",&_event_dx,"event_dx/D");
106  _wftree->Branch("event_dy",&_event_dy,"event_dy/D");
107  _wftree->Branch("event_dz",&_event_dz,"event_dz/D");
108  _wftree->Branch("tpc",&_tpc,"tpc/I");
109  _wftree->Branch("ch",&_ch,"ch/I");
110  _wftree->Branch("wf",&_wf);
111  _wftree->Branch("tstart",&_tstart,"tstart/D");
112  }
113 
114  for(auto const& label : _hit_label_v) {
115  std::string name = label + "_hittree";
116  auto hittree = new TTree(name.c_str(),name.c_str());
117  hittree->Branch("run",&_run,"run/I");
118  hittree->Branch("event",&_event,"event/I");
119  hittree->Branch("event_time",&_event_time,"event_time/D");
120  hittree->Branch("event_x",&_event_x,"event_x/D");
121  hittree->Branch("event_y",&_event_y,"event_y/D");
122  hittree->Branch("event_z",&_event_z,"event_z/D");
123  hittree->Branch("event_dr",&_event_dr,"event_dr/D");
124  hittree->Branch("event_dx",&_event_dx,"event_dx/D");
125  hittree->Branch("event_dy",&_event_dy,"event_dy/D");
126  hittree->Branch("event_dz",&_event_dz,"event_dz/D");
127  hittree->Branch("tpc",&_tpc,"tpc/I");
128  hittree->Branch("ch",&_ch,"ch/I");
129  hittree->Branch("amp",&_amp,"amp/D");
130  hittree->Branch("area",&_area,"area/D");
131  hittree->Branch("width",&_width,"width/D");
132  hittree->Branch("time",&_time,"time/D");
133  hittree->Branch("pe",&_pe,"pe/D");
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< float > _wf
std::vector< std::string > _hit_label_v
std::vector< TTree * > _hittree_v
then echo fcl name
void ICARUSOpHitTuple::endJob ( )
override

Definition at line 170 of file ICARUSOpHitTuple_module.cc.

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

Member Data Documentation

double ICARUSOpHitTuple::_amp
private

Definition at line 72 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_area
private

Definition at line 73 of file ICARUSOpHitTuple_module.cc.

int ICARUSOpHitTuple::_ch
private

Definition at line 57 of file ICARUSOpHitTuple_module.cc.

int ICARUSOpHitTuple::_event
private

Definition at line 57 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_event_dr
private

Definition at line 59 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_event_dx
private

Definition at line 59 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_event_dy
private

Definition at line 59 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_event_dz
private

Definition at line 59 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_event_time
private

Definition at line 58 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_event_x
private

Definition at line 58 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_event_y
private

Definition at line 58 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_event_z
private

Definition at line 58 of file ICARUSOpHitTuple_module.cc.

TFile* ICARUSOpHitTuple::_f
private

Definition at line 49 of file ICARUSOpHitTuple_module.cc.

TTree* ICARUSOpHitTuple::_geotree
private

Definition at line 77 of file ICARUSOpHitTuple_module.cc.

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

Definition at line 54 of file ICARUSOpHitTuple_module.cc.

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

Definition at line 69 of file ICARUSOpHitTuple_module.cc.

std::string ICARUSOpHitTuple::_mct_label
private

Definition at line 53 of file ICARUSOpHitTuple_module.cc.

std::string ICARUSOpHitTuple::_output_fname
private

Definition at line 50 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_pe
private

Definition at line 74 of file ICARUSOpHitTuple_module.cc.

int ICARUSOpHitTuple::_run
private

Definition at line 57 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_time
private

Definition at line 71 of file ICARUSOpHitTuple_module.cc.

int ICARUSOpHitTuple::_tpc
private

Definition at line 60 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_tstart
private

Definition at line 64 of file ICARUSOpHitTuple_module.cc.

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

Definition at line 65 of file ICARUSOpHitTuple_module.cc.

std::string ICARUSOpHitTuple::_wf_label
private

Definition at line 52 of file ICARUSOpHitTuple_module.cc.

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

Definition at line 66 of file ICARUSOpHitTuple_module.cc.

TTree* ICARUSOpHitTuple::_wftree
private

Definition at line 63 of file ICARUSOpHitTuple_module.cc.

double ICARUSOpHitTuple::_width
private

Definition at line 70 of file ICARUSOpHitTuple_module.cc.


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