LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
PhotonBackTracker.tcc
Go to the documentation of this file.
1 namespace cheat{
2 
3 
4  //----------------------------------------------------------------
5  template<typename Evt>
6  const bool PhotonBackTracker::CanRun(Evt const& evt) {
7  return ! ( evt.isRealData() ) ;
8  }
9 
10 
11  //----------------------------------------------------------------
12  template<typename Evt>
13  void PhotonBackTracker::PrepOpDetBTRs(Evt const& evt)
14  {
15  if(this->BTRsReady()){ return;}
16  auto const& btrHandle = evt.template getValidHandle < std::vector < sim::OpDetBacktrackerRecord > > (fG4ModuleLabel);
17  // if(btrHandle.failedToGet()){
18  /* mf::LogWarning("PhotonBackTracker") << "failed to get handle to simb::MCParticle from "
19  * << fG4ModuleLabel
20  * << ", return";*/ //This is now silent as it is expected to happen every generation run. It is also temporary while we wait for
21  /*if( 0 ){ return;} //Insert check for DivRecs here, or don't use validHandle below.
22  auto const& divrecHandle = evt.template getValidHandle <std::vector<sim::OpDetDivRec>>(fWavLabel);
23  if(divrecHandle.failedToGet()){
24  return;
25  }*/
26 
27  art::fill_ptr_vector(priv_OpDetBTRs, btrHandle);
28  //art::fill_ptr_vector(priv_DivRecs, divrecHandle);
29 
30  auto compareBTRlambda = [](art::Ptr<sim::OpDetBacktrackerRecord> a, art::Ptr<sim::OpDetBacktrackerRecord> b) {return(a->OpDetNum()<b->OpDetNum());};
31  if (!std::is_sorted(priv_OpDetBTRs.begin(),priv_OpDetBTRs.end(),compareBTRlambda))
32  std::sort(priv_OpDetBTRs.begin(),priv_OpDetBTRs.end(),compareBTRlambda);
33  //auto compareDivReclambda = [](art::Ptr<sim::OpDetDivRec> a, art::Ptr<sim::OpDetDivRec> b) {return(a->OpDetNum() < b->OpDetNum());};
34  /*if (!std::is_sorted(priv_DivRecs.begin(), priv_DivRecs.end(), compareDivReclambda))
35  std::sort(priv_DivRecs.begin(), priv_DivRecs.end(), compareDivReclambda);*/
36  //art::FindManyP<raw::OpDetWaveform, sim::OpDetDivRec> fp(priv_OpDetBTRs, evt, fWavLabel);// fp;
37  //art::FindOneP<raw::OpDetWaveform, sim::OpDetDivRec> fp(priv_OpDetBTRs, evt, fWavLabel);// fp;
38  //They come in sorted by BTR. Now make an index matched vector of data_t sorted by BTR. No. I need easy, not efficient. Map of DetNum to data_t. data_t is then channel mapped.
39  /*
40  if (fp.isValid()){
41  for( size_t btr_iter=0; btr_iter<priv_OpDetBTRs.size(); ++btr_iter){
42  auto btr=priv_OpDetBTRs.at(btr_iter);
43  auto od = btr->OpDetNum();
44  auto const& dr = fp.data(btr_iter);
45  for(auto& d : dr)
46  {
47  if(!d) continue;
48  priv_od_to_DivRec[od]=*d;//->ref();
49  }
50 
51  }
52  }else{throw cet::exception("PhotonBackTracker")<<"find Waveforms and DivRecs from BTRs failed.";}
53  */
54 
55  return;
56  }
57 
58  //----------------------------------------------------------------
59  //ToDo: Figure out why I get OpHit* out of here instead of art::Ptr.
60  template<typename Evt>
61  void PhotonBackTracker::PrepOpFlashToOpHits( Evt const& evt)
62  {
63  if(this->OpFlashToOpHitsReady()){ return;}
64  std::vector< art::Handle< std::vector < recob::OpFlash >>> flashHandles;
65  evt.getManyByType(flashHandles);
66  for( const auto& handle : flashHandles)
67  {
68  std::vector< art::Ptr < recob::OpFlash > > flash_vec;
69  if(handle.failedToGet())
70  {
71  mf::LogWarning("PhotonBackTracker")<<" failed to get handle to recob::OpFlash. Has reco run yet?";
72  return;
73  }
74  art::fill_ptr_vector(flash_vec, handle);
75  auto tag = art::InputTag( handle.provenance()->moduleLabel() );
76  art::FindManyP<recob::OpHit> flash_hit_assn(flash_vec, evt, tag);
77  // std::cout<<"flash_hit_assn.size: "<<flash_hit_assn.size()<<"\n";
78  for ( size_t i = 0; i < flash_vec.size(); ++i)
79  {
80  art::Ptr< recob::OpFlash > flashp = flash_vec.at(i);
81  std::vector< art::Ptr< recob::OpHit > > ophits = flash_hit_assn.at(i);
82  auto check = priv_OpFlashToOpHits.emplace(flashp, ophits);
83  if ( check.second == false )
84  {
85  // loop ophit_ps
86  // push_back to vector.
87  for ( auto& ophitp : ophits )
88  {
89  check.first->second.push_back(ophitp);
90  }
91  }
92  }
93  }
94  }
95 
96  //----------------------------------------------------------------
97  template<typename Evt>
98  void PhotonBackTracker::PrepEvent( Evt const& evt)
99  {
100  if( !(this->CanRun( evt ) ) ){
101  throw cet::exception("PhotonBackTracker")
102  <<"PhotonBackTracker cannot function."
103  <<"Is this file real data?";
104  }
105  priv_OpDetBTRs.clear();
106  this->PrepOpDetBTRs(evt);
107  this->PrepOpFlashToOpHits(evt);
108  }
109  }
110