LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
t0::MCTruthT0Matching Class Reference
Inheritance diagram for t0::MCTruthT0Matching:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 MCTruthT0Matching (fhicl::ParameterSet const &p)
 
 MCTruthT0Matching (MCTruthT0Matching const &)=delete
 
 MCTruthT0Matching (MCTruthT0Matching &&)=delete
 
MCTruthT0Matchingoperator= (MCTruthT0Matching const &)=delete
 
MCTruthT0Matchingoperator= (MCTruthT0Matching &&)=delete
 
void produce (art::Event &e) override
 
void beginJob () override
 
void reconfigure (fhicl::ParameterSet const &p)
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > consumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > consumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > mayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > mayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Attributes

art::InputTag fTrackModuleLabel
 
art::InputTag fShowerModuleLabel
 
art::InputTag fPFParticleModuleLabel
 
bool fMakeT0Assns
 
bool fMakePFParticleAssns
 
art::InputTag fHitModuleLabel
 
bool fMakeHitAssns
 
TTree * fTree
 
int TrackID = 0
 
int TrueTrackID = 0
 
int TrueTriggerType = 0
 
double TrueTrackT0 = 0
 
int ShowerID = 0
 
int ShowerMatchID = 0
 
int ShowerTriggerType = 0
 
double ShowerT0 = 0
 

Detailed Description

Definition at line 95 of file MCTruthT0Matching_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

t0::MCTruthT0Matching::MCTruthT0Matching ( fhicl::ParameterSet const &  p)
explicit

Definition at line 141 of file MCTruthT0Matching_module.cc.

References fMakeHitAssns, fMakePFParticleAssns, fMakeT0Assns, and reconfigure().

144 {
145  // Call appropriate produces<>() functions here.
146  reconfigure(p);
147  if (fMakeT0Assns){ // T0 assns are deprecated - this allows one to use deprecated funcionality. Added 2017-08-15. Should not be kept around forever
148  std::cout << "WARNING - You are using deprecated functionality\n";
149  std::cout << "MCTruthT0Matching T0 assns will be removed soon\n";
150  std::cout << "set your fcl parameter makeT0Assns to false and use MCParticle direct associations instead" << std::endl;
151  produces< std::vector<anab::T0> >();
152  produces< art::Assns<recob::Track , anab::T0> >();
153  produces< art::Assns<recob::Shower, anab::T0> > ();
154  if (fMakePFParticleAssns){produces< art::Assns<recob::PFParticle, anab::T0> > ();}// only do PFParticles if desired by the user
155  }
156 
157  produces< art::Assns<recob::Track , simb::MCParticle, anab::BackTrackerMatchingData > > ();
158  produces< art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData > > ();
159  if (fMakePFParticleAssns){ // only do PFParticles if desired by the user
160  produces< art::Assns<recob::PFParticle, simb::MCParticle, anab::BackTrackerMatchingData > > ();
161  }
162 
163  if(fMakeHitAssns)
164  produces< art::Assns<recob::Hit , simb::MCParticle, anab::BackTrackerHitMatchingData > > ();
165 }
void reconfigure(fhicl::ParameterSet const &p)
t0::MCTruthT0Matching::MCTruthT0Matching ( MCTruthT0Matching const &  )
delete
t0::MCTruthT0Matching::MCTruthT0Matching ( MCTruthT0Matching &&  )
delete

Member Function Documentation

void t0::MCTruthT0Matching::beginJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 180 of file MCTruthT0Matching_module.cc.

References fTree, art::TFileDirectory::make(), TrueTrackID, and TrueTrackT0.

181 {
182  // Implementation of optional member function here.
184  fTree = tfs->make<TTree>("MCTruthT0Matching","MCTruthT0");
185  fTree->Branch("TrueTrackT0",&TrueTrackT0,"TrueTrackT0/D");
186  fTree->Branch("TrueTrackID",&TrueTrackID,"TrueTrackID/D");
187  //fTree->Branch("ShowerID" ,&ShowerID ,"ShowerID/I" );
188  //fTree->Branch("ShowerT0" ,&ShowerT0 ,"ShowerT0/D" );
189 }
T * make(ARGS...args) const
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 147 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

148 {
149  if (!moduleContext_)
150  return ProductToken<T>::invalid();
151 
152  consumables_[BT].emplace_back(ConsumableType::Product,
153  TypeID{typeid(T)},
154  it.label(),
155  it.instance(),
156  it.process());
157  return ProductToken<T>{it};
158 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 162 of file Consumer.h.

163 {
164  if (!moduleContext_)
165  return;
166 
167  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
168 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 172 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

173 {
174  if (!moduleContext_)
175  return ViewToken<T>::invalid();
176 
177  consumables_[BT].emplace_back(ConsumableType::ViewElement,
178  TypeID{typeid(T)},
179  it.label(),
180  it.instance(),
181  it.process());
182  return ViewToken<T>{it};
183 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited

Definition at line 32 of file EngineCreator.cc.

References art::EngineCreator::rng().

34 {
35  return rng()->createEngine(
36  placeholder_schedule_id(), seed, kind_of_engine_to_make);
37 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited

Definition at line 40 of file EngineCreator.cc.

References art::EngineCreator::rng().

43 {
44  return rng()->createEngine(
45  placeholder_schedule_id(), seed, kind_of_engine_to_make, engine_label);
46 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
CurrentProcessingContext const * art::EDProducer::currentContext ( ) const
protectedinherited

Definition at line 120 of file EDProducer.cc.

References art::EDProducer::current_context_.

121  {
122  return current_context_.get();
123  }
CPC_exempt_ptr current_context_
Definition: EDProducer.h:116
EngineCreator::seed_t EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited

Definition at line 49 of file EngineCreator.cc.

References fhicl::ParameterSet::get().

Referenced by art::MixFilter< T >::initEngine_().

52 {
53  auto const& explicit_seeds = pset.get<std::vector<int>>(key, {});
54  return explicit_seeds.empty() ? implicit_seed : explicit_seeds.front();
55 }
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References B, and art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
Int_t B
Definition: plot.C:25
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 190 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

191 {
192  if (!moduleContext_)
193  return ProductToken<T>::invalid();
194 
195  consumables_[BT].emplace_back(ConsumableType::Product,
196  TypeID{typeid(T)},
197  it.label(),
198  it.instance(),
199  it.process());
200  return ProductToken<T>{it};
201 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 205 of file Consumer.h.

206 {
207  if (!moduleContext_)
208  return;
209 
210  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
211 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 215 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

216 {
217  if (!moduleContext_)
218  return ViewToken<T>::invalid();
219 
220  consumables_[BT].emplace_back(ConsumableType::ViewElement,
221  TypeID{typeid(T)},
222  it.label(),
223  it.instance(),
224  it.process());
225  return ViewToken<T>{it};
226 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID().

41  {
42  return true;
43  }
MCTruthT0Matching& t0::MCTruthT0Matching::operator= ( MCTruthT0Matching const &  )
delete
MCTruthT0Matching& t0::MCTruthT0Matching::operator= ( MCTruthT0Matching &&  )
delete
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited

Definition at line 89 of file Consumer.cc.

References fhicl::ParameterSet::get_if_present().

Referenced by art::EDProducer::doBeginJob(), art::EDFilter::doBeginJob(), and art::EDAnalyzer::doBeginJob().

90 {
91  if (!moduleContext_)
92  return;
93 
94  pset.get_if_present("errorOnMissingConsumes", requireConsumes_);
95  for (auto& consumablesPerBranch : consumables_) {
96  cet::sort_all(consumablesPerBranch);
97  }
98 }
bool requireConsumes_
Definition: Consumer.h:137
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
void t0::MCTruthT0Matching::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 191 of file MCTruthT0Matching_module.cc.

References anab::BackTrackerMatchingData::cleanliness, util::CreateAssn(), DEFINE_ART_MODULE, E, e, fHitModuleLabel, Fill(), art::fill_ptr_vector(), fMakeHitAssns, fMakePFParticleAssns, fMakeT0Assns, fPFParticleModuleLabel, fShowerModuleLabel, fTrackModuleLabel, fTree, art::DataViewImpl::getByLabel(), art::DataViewImpl::getValidHandle(), hits(), cheat::BackTrackerService::HitToTrackIDEs(), anab::BackTrackerHitMatchingData::ideFraction, anab::BackTrackerHitMatchingData::ideNFraction, anab::BackTrackerHitMatchingData::isMaxIDE, anab::BackTrackerHitMatchingData::isMaxIDEN, art::Event::isRealData(), art::Handle< T >::isValid(), art::Event::put(), ShowerID, ShowerMatchID, ShowerT0, ShowerTriggerType, simb::MCParticle::T(), simb::MCParticle::TrackId(), cheat::ParticleInventoryService::TrackIdToParticle_P(), TrueTrackID, TrueTrackT0, and TrueTriggerType.

192 {
193  if (evt.isRealData()) return;
194 
195  // Access art services...
199 
200  //TrackList handle
201  art::Handle< std::vector<recob::Track> > trackListHandle;
202  std::vector<art::Ptr<recob::Track> > tracklist;
203  if (evt.getByLabel(fTrackModuleLabel,trackListHandle))
204  art::fill_ptr_vector(tracklist, trackListHandle);
205  //if (!trackListHandle.isValid()) trackListHandle.clear();
206 
207  //ShowerList handle
208  art::Handle< std::vector<recob::Shower> > showerListHandle;
209  std::vector<art::Ptr<recob::Shower> > showerlist;
210  if (evt.getByLabel(fShowerModuleLabel,showerListHandle))
211  art::fill_ptr_vector(showerlist, showerListHandle);
212  //if (!showerListHandle.isValid()) showerListHandle.clear();
213 
214  //PFParticleList handle
215  art::Handle< std::vector<recob::PFParticle> > pfparticleListHandle;
216  std::vector<art::Ptr<recob::PFParticle> > pfparticlelist;
217  if (evt.getByLabel(fPFParticleModuleLabel,pfparticleListHandle))
218  art::fill_ptr_vector(pfparticlelist, pfparticleListHandle);
219  //if (!pfparticleListHandle.isValid()) pfparticleListHandle.clear();
220 
221 
222  auto mcpartHandle = evt.getValidHandle< std::vector<simb::MCParticle> >("largeant");
223 // simb::MCParticle const *firstParticle = &mcpartHandle->front();
224  // Create anab::T0 objects and make association with recob::Track, recob::Shower, and recob::PFParticle objects
225  std::unique_ptr< std::vector<anab::T0> > T0col( new std::vector<anab::T0>);
226 // if (fMakeT0Assns){ // T0 assns are deprecated - this allows one to use deprecated funcionality. Added 2017-08-15. Should not be kept around forever
227  std::unique_ptr< art::Assns<recob::Track, anab::T0> > Trackassn( new art::Assns<recob::Track, anab::T0>);
228  std::unique_ptr< art::Assns<recob::Shower, anab::T0> > Showerassn( new art::Assns<recob::Shower, anab::T0>);
229 // if (fMakePFParticleAssns){
230  std::unique_ptr< art::Assns<recob::PFParticle, anab::T0> > PFParticleassn( new art::Assns<recob::PFParticle, anab::T0>);
231 // }
232 // }
233 
234  // Create associations directly between MCParticle and either recob::Track, recob::Shower, or recob::PFParticle
235  // These associations contain metadata summarising the quality of the match
236  std::unique_ptr< art::Assns<recob::Track, simb::MCParticle, anab::BackTrackerMatchingData > > MCPartTrackassn( new art::Assns<recob::Track, simb::MCParticle, anab::BackTrackerMatchingData >);
237  std::unique_ptr< art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData> > MCPartShowerassn( new art::Assns<recob::Shower, simb::MCParticle, anab::BackTrackerMatchingData>);
238 // if (fMakePFParticleAssns){
239  std::unique_ptr< art::Assns<recob::PFParticle, simb::MCParticle,anab::BackTrackerMatchingData> > MCPartPFParticleassn( new art::Assns<recob::PFParticle, simb::MCParticle, anab::BackTrackerMatchingData>);
240 // }
241  // Association block for the hits<-->MCParticles
242  std::unique_ptr< art::Assns<recob::Hit, simb::MCParticle, anab::BackTrackerHitMatchingData > > MCPartHitassn( new art::Assns<recob::Hit, simb::MCParticle, anab::BackTrackerHitMatchingData >);
243 
244 
245  double maxe = -1;
246  double tote = 0;
247  // int trkid = -1;
248  int maxtrkid = -1;
249  double maxn = -1;
250  double totn = 0;
251  int maxntrkid = -1;
253 
254  std::unordered_map<int,int> trkid_lookup; //indexed by geant4trkid, delivers MC particle location
255 
256  //if we want to make per-hit assns
257  if(fMakeHitAssns){
258 
259 
260 
261  art::Handle< std::vector<recob::Hit> > hitListHandle;
262  evt.getByLabel(fHitModuleLabel,hitListHandle);
263 
264  if(hitListHandle.isValid()){
265 
266  auto const& hitList(*hitListHandle);
267  auto const& mcpartList(*mcpartHandle);
268  for(size_t i_h=0; i_h<hitList.size(); ++i_h){
269  art::Ptr<recob::Hit> hitPtr(hitListHandle, i_h);
270  auto trkide_list = bt_serv->HitToTrackIDEs(hitPtr);
271  struct TrackIDEinfo {
272  float E;
273  float NumElectrons;
274  };
275  std::map<int, TrackIDEinfo> trkide_collector;
276  maxe = -1; tote = 0; maxtrkid = -1;
277  maxn = -1; totn = 0; maxntrkid = -1;
278  for(auto const& t : trkide_list){
279  trkide_collector[t.trackID].E += t.energy;
280  tote += t.energy;
281  if(trkide_collector[t.trackID].E>maxe) { maxe = trkide_collector[t.trackID].E; maxtrkid = t.trackID; }
282  trkide_collector[t.trackID].NumElectrons += t.numElectrons;
283  totn += t.numElectrons;
284  if(trkide_collector[t.trackID].NumElectrons > maxn) {
285  maxn = trkide_collector[t.trackID].NumElectrons;
286  maxntrkid = t.trackID;
287  }
288 
289  //if not found, find mc particle...
290  if(trkid_lookup.find(t.trackID)==trkid_lookup.end()){
291  size_t i_p=0;
292  while(i_p<mcpartList.size()){
293  if(mcpartList[i_p].TrackId() == t.trackID) { trkid_lookup[t.trackID] = (int)i_p; break;}
294  ++i_p;
295  }
296  if(i_p==mcpartList.size()) trkid_lookup[t.trackID] = -1;
297  }
298 
299  }//end loop on TrackIDs
300 
301  //now find the mcparticle and loop back through ...
302  for(auto const& t : trkide_collector){
303  int mcpart_i = trkid_lookup[t.first];
304  if(mcpart_i==-1) continue; //no mcparticle here
305  art::Ptr<simb::MCParticle> mcpartPtr(mcpartHandle, mcpart_i);
306  bthmd.ideFraction = t.second.E / tote;
307  bthmd.isMaxIDE = (t.first==maxtrkid);
308  bthmd.ideNFraction = t.second.NumElectrons / totn;
309  bthmd.isMaxIDEN = ( t.first == maxntrkid );
310  MCPartHitassn->addSingle(hitPtr, mcpartPtr, bthmd);
311  }
312 
313 
314  }//end loop on hits
315 
316  }//end if handle valid
317 
318  }//end if make hit/mcpart assns
319 
320 
321  if (trackListHandle.isValid()){
322  //Access tracks and hits
323  art::FindManyP<recob::Hit> fmtht(trackListHandle, evt, fTrackModuleLabel);
324 
325  size_t NTracks = tracklist.size();
326 
327  // Now to access MCTruth for each track...
328  for(size_t iTrk=0; iTrk < NTracks; ++iTrk) {
329  TrueTrackT0 = 0;
330  TrackID = 0;
331  TrueTrackID = 0;
333  std::vector< art::Ptr<recob::Hit> > allHits = fmtht.at(iTrk);
334 
335  std::map<int,double> trkide;
336  for(size_t h = 0; h < allHits.size(); ++h){
337  art::Ptr<recob::Hit> hit = allHits[h];
338  std::vector<sim::IDE> ides;
339  std::vector<sim::TrackIDE> TrackIDs = bt_serv->HitToTrackIDEs(hit);
340 
341  for(size_t e = 0; e < TrackIDs.size(); ++e){
342  trkide[TrackIDs[e].trackID] += TrackIDs[e].energy;
343  }
344 
345  }
346  // Work out which IDE despoited the most charge in the hit if there was more than one.
347  maxe = -1;
348  tote = 0;
349  for (std::map<int,double>::iterator ii = trkide.begin(); ii!=trkide.end(); ++ii){
350  tote += ii->second;
351  if ((ii->second)>maxe){
352  maxe = ii->second;
353  TrackID = ii->first;
354  }
355  }
356  btdata.cleanliness = maxe/tote;
357 
358  // Now have trackID, so get PdG code and T0 etc.
359  const simb::MCParticle *tmpParticle = pi_serv->TrackIdToParticle_P(TrackID);
360  if (!tmpParticle) continue; // Retain this check that the BackTracker can find the right particle
361  // Now, loop through the MCParticle's myself to find the correct match
362  int mcpart_i(-1);
363  for (auto const particle : *mcpartHandle){
364  mcpart_i++;
365  if (TrackID == particle.TrackId()){
366  break;
367  }
368  }
369  const simb::MCParticle particle = mcpartHandle.product()->at(mcpart_i);
370  TrueTrackT0 = particle.T();
371  TrueTrackID = particle.TrackId();
372  TrueTriggerType = 2; // Using MCTruth as trigger, so tigger type is 2.
373  //std::cout << "Got particle, PDG = " << particle.PdgCode() << std::endl;
374 
375  //std::cout << "Filling T0col with " << TrueTrackT0 << " " << TrueTriggerType << " " << TrueTrackID << " " << (*T0col).size() << std::endl;
376 
377  T0col->push_back(anab::T0(TrueTrackT0,
379  TrueTrackID,
380  (*T0col).size()
381  ));
382  //auto diff = particle - firstParticle;
383  auto diff = mcpart_i; // check I have a sensible value for this counter
384  if (diff >= (int)mcpartHandle->size()){
385  std::cout << "Error, the backtracker is doing weird things to your pointers!" << std::endl;
386  throw std::exception();
387  }
388 
389  art::Ptr<simb::MCParticle> mcpartPtr(mcpartHandle, mcpart_i);
390  MCPartTrackassn->addSingle(tracklist[iTrk], mcpartPtr, btdata);
391  if (fMakeT0Assns){
392  util::CreateAssn(*this, evt, *T0col, tracklist[iTrk], *Trackassn);
393  }
394  fTree -> Fill();
395 
396  } // Loop over tracks
397  }
398 
399  if (showerListHandle.isValid()){
400  art::FindManyP<recob::Hit> fmsht(showerListHandle,evt, fShowerModuleLabel);
401  // Now Loop over showers....
402  size_t NShowers = showerlist.size();
403  for (size_t Shower = 0; Shower < NShowers; ++Shower) {
404  ShowerMatchID = 0;
405  ShowerID = 0;
406  ShowerT0 = 0;
407  std::vector< art::Ptr<recob::Hit> > allHits = fmsht.at(Shower);
409 
410  std::map<int,double> showeride;
411  for(size_t h = 0; h < allHits.size(); ++h){
412  art::Ptr<recob::Hit> hit = allHits[h];
413  std::vector<sim::IDE> ides;
414  std::vector<sim::TrackIDE> TrackIDs = bt_serv->HitToTrackIDEs(hit);
415 
416  for(size_t e = 0; e < TrackIDs.size(); ++e){
417  showeride[TrackIDs[e].trackID] += TrackIDs[e].energy;
418  }
419  }
420  // Work out which IDE despoited the most charge in the hit if there was more than one.
421  maxe = -1;
422  tote = 0;
423  for (std::map<int,double>::iterator ii = showeride.begin(); ii!=showeride.end(); ++ii){
424  tote += ii->second;
425  if ((ii->second)>maxe){
426  maxe = ii->second;
427  ShowerID = ii->first;
428  }
429  }
430  btdata.cleanliness = maxe/tote;
431 
432 
433 
434 
435  // Now have MCParticle trackID corresponding to shower, so get PdG code and T0 etc.
436  const simb::MCParticle *tmpParticle = pi_serv->TrackIdToParticle_P(ShowerID);
437  if (!tmpParticle) continue; // Retain this check that the BackTracker can find the right particle
438  // Now, loop through the MCParticle's myself to find the correct match
439  int mcpart_i(-1);
440  for (auto const particle : *mcpartHandle){
441  mcpart_i++;
442  if (ShowerID == particle.TrackId()){
443  break;
444  }
445  }
446  const simb::MCParticle particle = mcpartHandle.product()->at(mcpart_i);
447  ShowerT0 = particle.T();
448  ShowerID = particle.TrackId();
449  ShowerTriggerType = 2; // Using MCTruth as trigger, so tigger type is 2.
450  T0col->push_back(anab::T0(ShowerT0,
452  ShowerID,
453  (*T0col).size()
454  ));
455 
456  auto diff = mcpart_i; // check I have a sensible value for this counter
457  if (diff >= (int)mcpartHandle->size()){
458  std::cout << "Error, the backtracker is doing weird things to your pointers!" << std::endl;
459  throw std::exception();
460  }
461  art::Ptr<simb::MCParticle> mcpartPtr(mcpartHandle, mcpart_i);
462  if (fMakeT0Assns){
463  util::CreateAssn(*this, evt, *T0col, showerlist[Shower], *Showerassn);
464  }
465  MCPartShowerassn->addSingle(showerlist[Shower], mcpartPtr, btdata);
466 
467  }// Loop over showers
468  }
469 
470 
471  if (pfparticleListHandle.isValid()){
472  //Access pfparticles and hits
473  art::FindManyP<recob::Cluster> fmcp(pfparticleListHandle, evt, fPFParticleModuleLabel);
474  //art::FindManyP<recob::Hit> fmtht(pfparticleListHandle, evt, fPfparticleModuleLabel);
475 
476  size_t NPfparticles = pfparticlelist.size();
477 
478  // Now to access MCTruth for each pfparticle...
479  for(size_t iPfp=0; iPfp < NPfparticles; ++iPfp) {
480  TrueTrackT0 = 0;
481  TrackID = 0;
482  TrueTrackID = 0;
484 
485  std::vector< art::Ptr<recob::Hit> > allHits;
486  //Get all hits through associated clusters
487  std::vector< art::Ptr<recob::Cluster>> allClusters = fmcp.at(iPfp);
488  art::FindManyP<recob::Hit> fmhcl(allClusters, evt, fPFParticleModuleLabel);
489  for (size_t iclu = 0; iclu<allClusters.size(); ++iclu){
490  std::vector< art::Ptr<recob::Hit>> hits = fmhcl.at(iclu);
491  allHits.insert(allHits.end(), hits.begin(), hits.end());
492  }
493 
494  std::map<int,double> trkide;
495  for(size_t h = 0; h < allHits.size(); ++h){
496  art::Ptr<recob::Hit> hit = allHits[h];
497  std::vector<sim::IDE> ides;
498  std::vector<sim::TrackIDE> TrackIDs = bt_serv->HitToTrackIDEs(hit);
499 
500  for(size_t e = 0; e < TrackIDs.size(); ++e){
501  trkide[TrackIDs[e].trackID] += TrackIDs[e].energy;
502  }
503  }
504  // Work out which IDE despoited the most charge in the hit if there was more than one.
505  double maxe = -1;
506  double tote = 0;
507  for (std::map<int,double>::iterator ii = trkide.begin(); ii!=trkide.end(); ++ii){
508  tote += ii->second;
509  if ((ii->second)>maxe){
510  maxe = ii->second;
511  TrackID = ii->first;
512  }
513  }
514  btdata.cleanliness = maxe/tote;
515 
516  // Now have trackID, so get PdG code and T0 etc.
517  const simb::MCParticle *tmpParticle = pi_serv->TrackIdToParticle_P(TrackID);
518  if (!tmpParticle) continue; // Retain this check that the BackTracker can find the right particle
519  // Now, loop through the MCParticle's myself to find the correct match
520  int mcpart_i(-1);
521  for (auto const particle : *mcpartHandle){
522  mcpart_i++;
523  if (TrackID == particle.TrackId()){
524  break;
525  }
526  }
527  const simb::MCParticle particle = mcpartHandle.product()->at(mcpart_i);
528  TrueTrackT0 = particle.T();
529  TrueTrackID = particle.TrackId();
530  TrueTriggerType = 2; // Using MCTruth as trigger, so tigger type is 2.
531  //std::cout << "Got particle, PDG = " << particle.PdgCode() << std::endl;
532 
533  //std::cout << "Filling T0col with " << TrueTrackT0 << " " << TrueTriggerType << " " << TrueTrackID << " " << (*T0col).size() << std::endl;
534 
535  T0col->push_back(anab::T0(TrueTrackT0,
537  TrueTrackID,
538  (*T0col).size()
539  ));
540  //auto diff = particle - firstParticle;
541  auto diff = mcpart_i; // check I have a sensible value for this counter
542  if (diff >= (int)mcpartHandle->size()){
543  std::cout << "Error, the backtracker is doing weird things to your pointers!" << std::endl;
544  throw std::exception();
545  }
546 // art::Ptr<simb::MCParticle> mcpartPtr(mcpartHandle, particle - firstParticle);
547  art::Ptr<simb::MCParticle> mcpartPtr(mcpartHandle, mcpart_i);
548  //std::cout << "made MCParticle Ptr" << std::endl;
549 // const std::vertex< std::pair<double, std::string> > cleanlinessCompleteness;
550 // const std::pair<double, double> tmp(0.5, 0.5);
551 // MCPartassn->addSingle(tracklist[iPfp], mcpartPtr, tmp);
553  if (fMakeT0Assns){
554  util::CreateAssn(*this, evt, *T0col, pfparticlelist[iPfp], *PFParticleassn);
555  }
556  MCPartPFParticleassn->addSingle(pfparticlelist[iPfp], mcpartPtr, btdata);
557  }
558  fTree -> Fill();
559  } // Loop over tracks
560  }
561 
562  if (fMakeT0Assns){
563  evt.put(std::move(T0col));
564  evt.put(std::move(Trackassn));
565  evt.put(std::move(Showerassn));
567  evt.put(std::move(PFParticleassn));
568  }
569  }
570  evt.put(std::move(MCPartTrackassn));
571  evt.put(std::move(MCPartShowerassn));
573  evt.put(std::move(MCPartPFParticleassn));
574  }
575  if(fMakeHitAssns)
576  evt.put(std::move(MCPartHitassn));
577 } // Produce
const simb::MCParticle * TrackIdToParticle_P(int const &id)
Float_t E
Definition: plot.C:23
intermediate_table::iterator iterator
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
std::vector< TrackID > TrackIDs
TNtupleSim Fill(f1, f2, f3, f4)
Definition: T0.h:19
int TrackId() const
Definition: MCParticle.h:214
bool isValid() const
Definition: Handle.h:190
void hits()
Definition: readHits.C:15
double T(const int i=0) const
Definition: MCParticle.h:228
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
Detector simulation of raw signals on wires.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Float_t e
Definition: plot.C:34
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void t0::MCTruthT0Matching::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 167 of file MCTruthT0Matching_module.cc.

References fHitModuleLabel, fMakeHitAssns, fMakePFParticleAssns, fMakeT0Assns, fPFParticleModuleLabel, fShowerModuleLabel, fTrackModuleLabel, and fhicl::ParameterSet::get().

Referenced by MCTruthT0Matching().

168 {
169  // Implementation of optional member function here.
170  fTrackModuleLabel = (p.get< art::InputTag > ("TrackModuleLabel" ) );
171  fShowerModuleLabel = (p.get< art::InputTag > ("ShowerModuleLabel") );
172  fPFParticleModuleLabel = (p.get< art::InputTag > ("PFParticleModuleLabel", "pandoraNu") );
173  fMakeT0Assns = (p.get< bool > ("makeT0Assns", true) );
174  fMakePFParticleAssns = (p.get< bool > ("makePFParticleAssns", false) );
175 
176  fMakeHitAssns = p.get<bool>("makeHitAssns",true);
177  if(fMakeHitAssns) fHitModuleLabel = p.get<art::InputTag>("HitModuleLabel");
178 }
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Definition at line 125 of file Consumer.cc.

Referenced by art::EDProducer::doEndJob(), art::EDFilter::doEndJob(), art::EDAnalyzer::doEndJob(), and art::RootOutput::endJob().

126 {
127  if (!moduleContext_)
128  return;
129 
130  // If none of the branches have missing consumes statements, exit early.
131  if (std::all_of(cbegin(missingConsumes_),
132  cend(missingConsumes_),
133  [](auto const& perBranch) { return perBranch.empty(); }))
134  return;
135 
136  constexpr cet::HorizontalRule rule{60};
137  mf::LogPrint log{"MTdiagnostics"};
138  log << '\n'
139  << rule('=') << '\n'
140  << "The following consumes (or mayConsume) statements are missing from\n"
141  << module_context(moduleDescription_) << '\n'
142  << rule('-') << '\n';
143 
144  cet::for_all_with_index(
145  missingConsumes_, [&log](std::size_t const i, auto const& perBranch) {
146  for (auto const& pi : perBranch) {
147  log << " "
148  << assemble_consumes_statement(static_cast<BranchType>(i), pi)
149  << '\n';
150  }
151  });
152  log << rule('=');
153 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139
void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Definition at line 101 of file Consumer.cc.

References art::errors::ProductRegistrationFailure.

103 {
104  // Early exits if consumes tracking has been disabled or if the
105  // consumed product is an allowed consumable.
106  if (!moduleContext_)
107  return;
108 
109  if (cet::binary_search_all(consumables_[bt], pi))
110  return;
111 
112  if (requireConsumes_) {
114  "Consumer: an error occurred during validation of a "
115  "retrieved product\n\n")
116  << "The following consumes (or mayConsume) statement is missing from\n"
117  << module_context(moduleDescription_) << ":\n\n"
118  << " " << assemble_consumes_statement(bt, pi) << "\n\n";
119  }
120 
121  missingConsumes_[bt].insert(pi);
122 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
bool requireConsumes_
Definition: Consumer.h:137
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139

Member Data Documentation

art::InputTag t0::MCTruthT0Matching::fHitModuleLabel
private

Definition at line 124 of file MCTruthT0Matching_module.cc.

Referenced by produce(), and reconfigure().

bool t0::MCTruthT0Matching::fMakeHitAssns
private

Definition at line 125 of file MCTruthT0Matching_module.cc.

Referenced by MCTruthT0Matching(), produce(), and reconfigure().

bool t0::MCTruthT0Matching::fMakePFParticleAssns
private

Definition at line 122 of file MCTruthT0Matching_module.cc.

Referenced by MCTruthT0Matching(), produce(), and reconfigure().

bool t0::MCTruthT0Matching::fMakeT0Assns
private

Definition at line 121 of file MCTruthT0Matching_module.cc.

Referenced by MCTruthT0Matching(), produce(), and reconfigure().

art::InputTag t0::MCTruthT0Matching::fPFParticleModuleLabel
private

Definition at line 120 of file MCTruthT0Matching_module.cc.

Referenced by produce(), and reconfigure().

art::InputTag t0::MCTruthT0Matching::fShowerModuleLabel
private

Definition at line 119 of file MCTruthT0Matching_module.cc.

Referenced by produce(), and reconfigure().

art::InputTag t0::MCTruthT0Matching::fTrackModuleLabel
private

Definition at line 118 of file MCTruthT0Matching_module.cc.

Referenced by produce(), and reconfigure().

TTree* t0::MCTruthT0Matching::fTree
private

Definition at line 128 of file MCTruthT0Matching_module.cc.

Referenced by beginJob(), and produce().

int t0::MCTruthT0Matching::ShowerID = 0
private

Definition at line 134 of file MCTruthT0Matching_module.cc.

Referenced by produce().

int t0::MCTruthT0Matching::ShowerMatchID = 0
private

Definition at line 135 of file MCTruthT0Matching_module.cc.

Referenced by produce().

double t0::MCTruthT0Matching::ShowerT0 = 0
private

Definition at line 137 of file MCTruthT0Matching_module.cc.

Referenced by produce().

int t0::MCTruthT0Matching::ShowerTriggerType = 0
private

Definition at line 136 of file MCTruthT0Matching_module.cc.

Referenced by produce().

int t0::MCTruthT0Matching::TrackID = 0
private

Definition at line 129 of file MCTruthT0Matching_module.cc.

int t0::MCTruthT0Matching::TrueTrackID = 0
private

Definition at line 130 of file MCTruthT0Matching_module.cc.

Referenced by beginJob(), and produce().

double t0::MCTruthT0Matching::TrueTrackT0 = 0
private

Definition at line 132 of file MCTruthT0Matching_module.cc.

Referenced by beginJob(), and produce().

int t0::MCTruthT0Matching::TrueTriggerType = 0
private

Definition at line 131 of file MCTruthT0Matching_module.cc.

Referenced by produce().


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