LArSoft  v06_85_00
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  return;
22  }
23 
24  art::fill_ptr_vector(priv_OpDetBTRs, btrHandle);
25 
26  auto compareBTRlambda = [](art::Ptr<sim::OpDetBacktrackerRecord> a, art::Ptr<sim::OpDetBacktrackerRecord> b) {return(a->OpDetNum()<b->OpDetNum());};
27  if (!std::is_sorted(priv_OpDetBTRs.begin(),priv_OpDetBTRs.end(),compareBTRlambda)) std::sort(priv_OpDetBTRs.begin(),priv_OpDetBTRs.end(),compareBTRlambda);
28 
29  return;
30  }
31 
32  //----------------------------------------------------------------
33  template<typename Evt>
34  void PhotonBackTracker::PrepOpFlashToOpHits( Evt const& evt)
35  {
36  if(this->OpFlashToOpHitsReady()){ return;}
37  auto const& flashHandle = evt.template getValidHandle < std::vector < recob::OpFlash > > (fOpFlashLabel);
38  std::vector<art::Ptr<recob::OpFlash>> tmpVec;
39  art::fill_ptr_vector(tmpVec, flashHandle);
40 
41  if(flashHandle.failedToGet()){
42  mf::LogWarning("PhotonBackTracker")<<" failed to get handle to recob::OpFlash. Has reco run yet?";
43  return;
44  }
45  auto const& fmp = art::FindManyP<recob::OpHit>(flashHandle, evt, fOpHitLabel.label());
46  for ( size_t i=0; i<flashHandle->size(); i++)
47  fOpFlashToOpHits[tmpVec.at(i)] = fmp.at(i);
48  }
49 
50  //----------------------------------------------------------------
51  template<typename Evt>
52  void PhotonBackTracker::PrepEvent( Evt const& evt)
53  {
54  if( !(this->CanRun( evt ) ) ){
55  throw cet::exception("PhotonBackTracker")
56  <<"PhotonBackTracker cannot function."
57  <<"Is this file real data?";
58  }
59  priv_OpDetBTRs.clear();
60  this->PrepOpDetBTRs(evt);
61  this->PrepOpFlashToOpHits(evt);
62  }
63 
64 
65 
66 }
67