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

Public Member Functions

 CRTTrackProducer (fhicl::ParameterSet const &p)
 
 CRTTrackProducer (CRTTrackProducer const &)=delete
 
 CRTTrackProducer (CRTTrackProducer &&)=delete
 
CRTTrackProduceroperator= (CRTTrackProducer const &)=delete
 
CRTTrackProduceroperator= (CRTTrackProducer &&)=delete
 
void produce (art::Event &e) override
 
void beginJob () override
 
void endJob () override
 

Private Attributes

std::string fDataLabelHits
 
std::string fDataLabelTZeros
 
int fTrackMethodType
 
int fStoreTrack
 
CRTTrackRecoAlg trackAlg
 

Detailed Description

Definition at line 47 of file sbndcode/sbndcode/CRT/CRTTrackProducer_module.cc.

Constructor & Destructor Documentation

sbnd::CRTTrackProducer::CRTTrackProducer ( fhicl::ParameterSet const &  p)
explicit

Definition at line 119 of file sbndcode/sbndcode/CRT/CRTTrackProducer_module.cc.

120  : EDProducer(p), trackAlg(p.get<fhicl::ParameterSet>("TrackAlg"))
121 {
122 
123  // Initialize member data here.
124  fDataLabelHits = p.get<std::string>("DataLabelHits"); // CRTHit producer module name
125  fDataLabelTZeros = p.get<std::string>("DataLabelTZeros"); // CRTTzero producer module name
126  fStoreTrack = p.get<int> ("StoreTrack"); // method 1 = all, method 2 = ave, method 3 = pure, method 4 = top plane
127  fTrackMethodType = p.get<int> ("TrackMethodType"); // Print stuff
128 
129  // Call appropriate produces<>() functions here.
130  if(fStoreTrack == 1){
131  produces< std::vector<sbn::crt::CRTTrack> >();
132  produces< art::Assns<sbn::crt::CRTTrack , sbn::crt::CRTHit> >();
133  }
134 
135 } // CRTTrackProducer()
pdgs p
Definition: selectors.fcl:22
sbnd::CRTTrackProducer::CRTTrackProducer ( CRTTrackProducer const &  )
delete
sbnd::CRTTrackProducer::CRTTrackProducer ( CRTTrackProducer &&  )
delete

Member Function Documentation

void sbnd::CRTTrackProducer::beginJob ( )
override

Definition at line 361 of file sbndcode/sbndcode/CRT/CRTTrackProducer_module.cc.

362 {
363 
364 } // CRTTrackProducer::beginJob()
void sbnd::CRTTrackProducer::endJob ( )
override

Definition at line 367 of file sbndcode/sbndcode/CRT/CRTTrackProducer_module.cc.

368 {
369 
370 } // CRTTrackProducer::endJob()
CRTTrackProducer& sbnd::CRTTrackProducer::operator= ( CRTTrackProducer const &  )
delete
CRTTrackProducer& sbnd::CRTTrackProducer::operator= ( CRTTrackProducer &&  )
delete
void sbnd::CRTTrackProducer::produce ( art::Event &  e)
override

Definition at line 138 of file sbndcode/sbndcode/CRT/CRTTrackProducer_module.cc.

139 {
140 
141  // For validation
142  int nTrack = 0;
143  int nCompTrack = 0;
144  int nIncTrack = 0;
145 
146  // CRTTrack collection on this event
147  std::unique_ptr<std::vector<sbn::crt::CRTTrack> > CRTTrackCol(new std::vector<sbn::crt::CRTTrack>);
148  std::unique_ptr< art::Assns<sbn::crt::CRTTrack, sbn::crt::CRTHit> > Trackassn( new art::Assns<sbn::crt::CRTTrack, sbn::crt::CRTHit>);
149  art::PtrMaker<sbn::crt::CRTTrack> makeTrackPtr(evt);
150 
151  // Implementation of required member function here.
152  art::Handle< std::vector<sbn::crt::CRTHit> > rawHandle;
153  evt.getByLabel(fDataLabelHits, rawHandle); //what is the product instance name? no BernZMQ
154 
155  // Check to make sure the data we asked for is valid
156  if(!rawHandle.isValid()){
157  mf::LogWarning("CRTTrackProducer")
158  <<"No CRTHits from producer module "<<fDataLabelHits;
159  return;
160  }
161 
162  // Track method 4 = SBND method with top plane (doesn't use CRTTzero)
163  if(fTrackMethodType == 4){
164 
165  //Get the CRT hits from the event
166  std::vector<art::Ptr<sbn::crt::CRTHit> > hitlist;
167  if (evt.getByLabel(fDataLabelHits, rawHandle))
168  art::fill_ptr_vector(hitlist, rawHandle);
169 
170  std::map<art::Ptr<sbn::crt::CRTHit>, int> hitIds;
171  for(size_t i = 0; i<hitlist.size(); i++){
172  hitIds[hitlist[i]] = i;
173  }
174 
175  std::vector<std::vector<art::Ptr<sbn::crt::CRTHit>>> CRTTzeroVect = trackAlg.CreateCRTTzeros(hitlist);
176 
177  // Loop over tzeros
178  for(size_t i = 0; i<CRTTzeroVect.size(); i++){
179 
180  //loop over hits for this tzero, sort by tagger
181  std::map<std::string, std::vector<art::Ptr<sbn::crt::CRTHit>>> hits;
182  for (size_t ah = 0; ah< CRTTzeroVect[i].size(); ++ah){
183  std::string ip = CRTTzeroVect[i][ah]->tagger;
184  hits[ip].push_back(CRTTzeroVect[i][ah]);
185  } // loop over hits
186 
187  //loop over planes and calculate average hits
188  std::vector<std::pair<sbn::crt::CRTHit, std::vector<int>>> allHits;
189  for (auto &keyVal : hits){
190  std::string ip = keyVal.first;
191  std::vector<std::pair<sbn::crt::CRTHit, std::vector<int>>> ahits = trackAlg.AverageHits(hits[ip], hitIds);
192  allHits.insert(allHits.end(), ahits.begin(), ahits.end());
193  }
194 
195  //Create tracks with hits at the same tzero
196  std::vector<std::pair<sbn::crt::CRTTrack, std::vector<int>>> trackCandidates = trackAlg.CreateTracks(allHits);
197  nTrack += trackCandidates.size();
198  for(size_t j = 0; j < trackCandidates.size(); j++){
199  CRTTrackCol->emplace_back(trackCandidates[j].first);
200 
201  art::Ptr<sbn::crt::CRTTrack> trackPtr = makeTrackPtr(CRTTrackCol->size()-1);
202  for (size_t ah = 0; ah< CRTTzeroVect[i].size(); ++ah){
203  Trackassn->addSingle(trackPtr, CRTTzeroVect[i][ah]);
204  }
205  if(trackCandidates[j].first.complete) nCompTrack++;
206  else nIncTrack++;
207  }
208  }
209 
210  //Older track reconstruction methods from MicroBooNE
211  }else{
212  //Get list of tzeros
213  // std::vector<sbn::crt::CRTHit> const& CRTHitCollection(*rawHandle);
214  art::Handle< std::vector<sbn::crt::CRTTzero> > rawHandletzero;
215  evt.getByLabel(fDataLabelTZeros, rawHandletzero); //what is the product instance name? no BernZMQ
216 
217  //check to make sure the data we asked for is valid
218  if(!rawHandletzero.isValid()){
219  mf::LogWarning("CRTTrackProducer")
220  <<"No CRTTzeros from producer module "<<fDataLabelTZeros;
221  return;
222  }
223 
224  std::vector<art::Ptr<sbn::crt::CRTTzero> > tzerolist;
225  if (evt.getByLabel(fDataLabelTZeros,rawHandletzero))
226  art::fill_ptr_vector(tzerolist, rawHandletzero);
227 
228  art::FindManyP<sbn::crt::CRTHit> fmht(rawHandletzero, evt, fDataLabelTZeros);
229 
230  //loop over tzeros
231  for(size_t tzIter = 0; tzIter < tzerolist.size(); ++tzIter){
232 
233  //count planes with hits for this tzero
234  int np =0 ; //int ipflag[7] = {}; // CHANGED FROM 4 TO 7
235  int tothits =0;
236  for (int ip=0;ip<7;++ip) { // CHANGED FROM 4 TO 7
237  if (tzerolist[tzIter]->nhits[ip]>0) { np++; /*ipflag[ip]=1;*/ tothits+=tzerolist[tzIter]->nhits[ip];}
238  }
239 
240  if (np<2) continue;
241  std::vector<art::Ptr<sbn::crt::CRTHit> > hitlist=fmht.at(tzIter);
242  //for(size_t hit_i = 0; hit_i < hitlist.size(); hit
243  if (fTrackMethodType==1) {
244  double time_s_A = hitlist[0]->ts0_s;
245 
246  // find pairs of hits in different planes
247  for (size_t ah = 0; ah< hitlist.size()-1; ++ah){
248  sbn::crt::CRTHit temphit=*hitlist[ah];
249  CRTavehit Ahit = copyme(temphit);
250  int planeA = hitlist[ah]->plane;
251 
252  for (size_t bh = ah+1; bh< hitlist.size(); ++bh){
253  int planeB = hitlist[bh]->plane;
254 
255  if (planeB!=planeA && !((planeA==3&&planeB==4)||(planeA==4&&planeB==3))) { // make a track
256  temphit=*hitlist[bh];
257  CRTavehit Bhit = copyme(temphit);
258  sbn::crt::CRTTrack CRTcanTrack=shcut(Ahit,Bhit,time_s_A,0);
259  CRTTrackCol->emplace_back(CRTcanTrack);
260  }
261 
262  }
263 
264  }
265 
266  }
267 
268  else if ((fTrackMethodType==2) || (fTrackMethodType==3 && np==2 && tothits==2)) {
269 
270  //loop over hits and get average x,y,z,pe for each plane CHANGED FROM 4 TO 7
271  std::vector<float> thittime0[7];
272  std::vector<float> thittime1[7];
273  std::vector<float> tx[7];
274  std::vector<float> ty[7];
275  std::vector<float> tz[7];
276  std::vector<float> pe[7];
277 
278  double time_s_A = hitlist[0]->ts0_s;
279  // double time_s_err = hitlist[0]->ts0_s_err;
280  double time_s_err = 0.;
281  double time1_ns_A = hitlist[0]->ts1_ns;
282  double time0_ns_A = hitlist[0]->ts0_ns;
283 
284  //loop over hits for this tzero, sort by plane
285  for (size_t ah = 0; ah< hitlist.size(); ++ah){
286  int ip = hitlist[ah]->plane;
287  thittime0[ip].push_back(hitlist[ah]->ts0_ns-time0_ns_A);
288  thittime1[ip].push_back(hitlist[ah]->ts1_ns-time1_ns_A);
289  tx[ip].push_back(hitlist[ah]->x_pos);
290  ty[ip].push_back(hitlist[ah]->y_pos);
291  tz[ip].push_back(hitlist[ah]->z_pos);
292  pe[ip].push_back(hitlist[ah]->peshit);
293  } // loop over hits
294 
295  CRTavehit aveHits[7];
296  //loop over planes and calculate average hits
297  for (int ip = 0; ip < 7; ip++){
298  if (tx[ip].size()>0){
299  uint32_t at0; int32_t at1; uint16_t rt0,rt1;
300  float totpe=0.0;
301  float avet1=0.0; float rmst1 =0.0;
302  float avet0=0.0; float rmst0 =0.0;
303  float avex=0.0; float rmsx =0.0;
304  float avey=0.0; float rmsy =0.0;
305  float avez=0.0; float rmsz =0.0;
306  vmanip(thittime0[ip],&avet0,&rmst0);
307  vmanip(thittime1[ip],&avet1,&rmst1);
308  at0 = (uint32_t)(avet0+time0_ns_A); rt0 = (uint16_t)rmst0;
309  at1 = (int32_t)(avet1+time1_ns_A); rt1 = (uint16_t)rmst1;
310  vmanip(tx[ip],&avex,&rmsx);
311  vmanip(ty[ip],&avey,&rmsy);
312  vmanip(tz[ip],&avez,&rmsz);
313  totpe=std::accumulate(pe[ip].begin(), pe[ip].end(), 0.0);
314  CRTavehit aveHit = fillme(at0,rt0,at1,rt1,avex,rmsx,avey,rmsy,avez,rmsz,totpe,ip,"");
315  aveHits[ip] = aveHit;
316  }
317  else {
318  CRTavehit aveHit = fillme(0,0,0,0,-99999,-99999,-99999,-99999,-99999,-99999,-99999,ip,"");
319  aveHits[ip] = aveHit;
320  }
321  }
322 
323  // find pairs of hits in different planes
324  for (size_t ah = 0; ah< 6; ++ah){
325  CRTavehit Ahit = aveHits[ah];
326  if( Ahit.x_pos==-99999 ) continue;
327 
328  for (size_t bh = ah+1; bh< 7; ++bh){
329  if ( aveHits[bh].x_pos==-99999 ) continue;
330 
331  if (ah!=bh && !(ah==3&&bh==4)) { // make a track
332  CRTavehit Bhit = aveHits[bh];
333  sbn::crt::CRTTrack CRTcanTrack=shcut(Ahit,Bhit,time_s_A,time_s_err);
334  CRTTrackCol->emplace_back(CRTcanTrack);
335  nTrack++;
336  }
337 
338  }
339 
340  }
341 
342  }
343 
344  }// loop over tzeros
345  }
346 
347  mf::LogInfo("CRTTrackProducer")
348  <<"Number of tracks = "<<CRTTrackCol->size()<<"\n"
349  <<"Number of complete tracks = "<<CRTTrackCol->size()-nIncTrack<<"\n"
350  <<"Number of incomplete tracks = "<<nIncTrack;
351 
352  //store track collection into event
353  if(fStoreTrack == 1){
354  evt.put(std::move(CRTTrackCol));
355  evt.put(std::move(Trackassn));
356  }
357 
358 } // CRTTrackProducer::produce()
CRTavehit copyme(sbn::crt::CRTHit myhit)
void vmanip(std::vector< float > v, float *ave, float *rms)
std::vector< std::pair< sbn::crt::CRTTrack, std::vector< int > > > CreateTracks(std::vector< std::pair< sbn::crt::CRTHit, std::vector< int >>> hits)
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
std::vector< std::pair< sbn::crt::CRTHit, std::vector< int > > > AverageHits(std::vector< art::Ptr< sbn::crt::CRTHit >> hits, std::map< art::Ptr< sbn::crt::CRTHit >, int > hitIds)
CRTavehit fillme(uint32_t i, uint16_t j, int32_t k, uint16_t l, float a, float b, float c, float d, float e, float f, float g, int p, std::string t)
std::vector< std::vector< art::Ptr< sbn::crt::CRTHit > > > CreateCRTTzeros(std::vector< art::Ptr< sbn::crt::CRTHit >>)
sbn::crt::CRTTrack shcut(CRTavehit ppA, CRTavehit ppb, uint32_t time0s, uint16_t terr)
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
TCEvent evt
Definition: DataStructs.cxx:8

Member Data Documentation

std::string sbnd::CRTTrackProducer::fDataLabelHits
private
std::string sbnd::CRTTrackProducer::fDataLabelTZeros
private
int sbnd::CRTTrackProducer::fStoreTrack
private
int sbnd::CRTTrackProducer::fTrackMethodType
private
CRTTrackRecoAlg sbnd::CRTTrackProducer::trackAlg
private

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