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

Classes

struct  Config
 

Public Types

using Parameters = art::EDAnalyzer::Table< Config >
 
typedef art::Handle
< std::vector
< recob::PFParticle > > 
PFParticleHandle
 
typedef std::map< size_t,
art::Ptr< recob::PFParticle > > 
PFParticleIdMap
 

Public Member Functions

 CRTHitCosmicIdAna (Parameters const &config)
 
virtual void beginJob () override
 
virtual void analyze (const art::Event &event) override
 
virtual void endJob () override
 

Private Member Functions

void GetPFParticleIdMap (const PFParticleHandle &pfParticleHandle, PFParticleIdMap &pfParticleMap)
 

Private Attributes

art::InputTag fSimModuleLabel
 name of detsim producer More...
 
art::InputTag fCRTHitLabel
 name of CRT producer More...
 
art::InputTag fTPCTrackLabel
 name of CRT producer More...
 
art::InputTag fPandoraLabel
 
bool fVerbose
 print information about what's going on More...
 
CRTT0MatchAlg t0Alg
 
TPCGeoAlg fTpcGeo
 
CRTBackTracker fCrtBackTrack
 
CrtHitCosmicIdAlg chTag
 
std::vector< std::string > types {"NuMuTrack", "CrTrack", "DirtTrack", "NuTrack", "NuMuPfp", "CrPfp", "DirtPfp", "NuPfp"}
 
std::map< std::string, TH1D * > hNumTrueMatches
 
std::map< std::string, TH1D * > hMatchDCA
 
std::map< std::string, TH1D * > hNoMatchDCA
 
std::map< std::string, TH1D * > hDCATotal
 
std::map< std::string, TH1D * > hDCATag
 
std::map< std::string, TH1D * > hLengthTotal
 
std::map< std::string, TH1D * > hLengthTag
 

Detailed Description

Definition at line 56 of file CRTHitCosmicIdAna_module.cc.

Member Typedef Documentation

using sbnd::CRTHitCosmicIdAna::Parameters = art::EDAnalyzer::Table<Config>

Definition at line 104 of file CRTHitCosmicIdAna_module.cc.

typedef art::Handle< std::vector<recob::PFParticle> > sbnd::CRTHitCosmicIdAna::PFParticleHandle

Definition at line 118 of file CRTHitCosmicIdAna_module.cc.

typedef std::map< size_t, art::Ptr<recob::PFParticle> > sbnd::CRTHitCosmicIdAna::PFParticleIdMap

Definition at line 119 of file CRTHitCosmicIdAna_module.cc.

Constructor & Destructor Documentation

sbnd::CRTHitCosmicIdAna::CRTHitCosmicIdAna ( Parameters const &  config)
explicit

Definition at line 153 of file CRTHitCosmicIdAna_module.cc.

154  : EDAnalyzer(config)
155  , fSimModuleLabel (config().SimModuleLabel())
156  , fCRTHitLabel (config().CRTHitLabel())
157  , fTPCTrackLabel (config().TPCTrackLabel())
158  , fPandoraLabel (config().PandoraLabel())
159  , fVerbose (config().Verbose())
160  , t0Alg (config().CRTT0Alg())
161  , fCrtBackTrack (config().CrtBackTrack())
162  , chTag (config().CHTagAlg())
163  {
164 
165  } //CRTHitCosmicIdAna()
BEGIN_PROLOG Verbose
art::InputTag fCRTHitLabel
name of CRT producer
bool fVerbose
print information about what&#39;s going on
art::InputTag fTPCTrackLabel
name of CRT producer
BEGIN_PROLOG don t mess with this TPCTrackLabel
art::InputTag fSimModuleLabel
name of detsim producer

Member Function Documentation

void sbnd::CRTHitCosmicIdAna::analyze ( const art::Event &  event)
overridevirtual

Definition at line 189 of file CRTHitCosmicIdAna_module.cc.

190  {
191 
192  // Fetch basic event info
193  if(fVerbose){
194  std::cout<<"============================================"<<std::endl
195  <<"Run = "<<event.run()<<", SubRun = "<<event.subRun()<<", Event = "<<event.id().event()<<std::endl
196  <<"============================================"<<std::endl;
197  }
198 
199  //----------------------------------------------------------------------------------------------------------
200  // GETTING PRODUCTS
201  //----------------------------------------------------------------------------------------------------------
202 
203  // Get g4 particles
204  art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
205  auto particleHandle = event.getValidHandle<std::vector<simb::MCParticle>>(fSimModuleLabel);
206 
207  // Get CRT hits from the event
208  art::Handle< std::vector<sbn::crt::CRTHit>> crtHitHandle;
209  std::vector<art::Ptr<sbn::crt::CRTHit> > crtHitList;
210  if (event.getByLabel(fCRTHitLabel, crtHitHandle))
211  art::fill_ptr_vector(crtHitList, crtHitHandle);
212 
213  fCrtBackTrack.Initialize(event);
214  std::vector<sbn::crt::CRTHit> crtHits;
215  std::map<int, int> numHitMap;
216  int hit_i = 0;
217  for(auto const& hit : (crtHitList)){
218  crtHits.push_back(*hit);
219  int hitTrueID = fCrtBackTrack.TrueIdFromHitId(event, hit_i);
220  hit_i++;
221  double hitTime = hit->ts1_ns * 1e-3;
222  if(hitTime > 0 && hitTime < 4) continue;
223  numHitMap[hitTrueID]++;
224  }
225 
226  // Get reconstructed tracks from the event
227  auto tpcTrackHandle = event.getValidHandle<std::vector<recob::Track>>(fTPCTrackLabel);
228  art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event, fTPCTrackLabel);
229 
230  // Get PFParticles from pandora
231  PFParticleHandle pfParticleHandle;
232  event.getByLabel(fPandoraLabel, pfParticleHandle);
233  if( !pfParticleHandle.isValid() ){
234  if(fVerbose) std::cout<<"Failed to find the PFParticles."<<std::endl;
235  return;
236  }
237  PFParticleIdMap pfParticleMap;
238  this->GetPFParticleIdMap(pfParticleHandle, pfParticleMap);
239  // Get PFParticle to track associations
240  art::FindManyP< recob::Track > pfPartToTrackAssoc(pfParticleHandle, event, fTPCTrackLabel);
241 
242  //----------------------------------------------------------------------------------------------------------
243  // TRUTH MATCHING
244  //----------------------------------------------------------------------------------------------------------
245 
246  std::map<int, simb::MCParticle> particles;
247  std::vector<int> nuParticleIds;
248  std::vector<int> lepParticleIds;
249  std::vector<int> dirtParticleIds;
250  std::vector<int> crParticleIds;
251  // Loop over the true particles
252  for (auto const& particle: (*particleHandle)){
253 
254  // Make map with ID
255  int partID = particle.TrackId();
256  particles[partID] = particle;
257 
258  // Get MCTruth
259  art::Ptr<simb::MCTruth> truth = pi_serv->TrackIdToMCTruth_P(partID);
260  int pdg = std::abs(particle.PdgCode());
261 
262  // If origin is a neutrino
263  if(truth->Origin() == simb::kBeamNeutrino){
264  geo::Point_t vtx;
265  vtx.SetX(truth->GetNeutrino().Nu().Vx()); vtx.SetY(truth->GetNeutrino().Nu().Vy()); vtx.SetZ(truth->GetNeutrino().Nu().Vz());
266  // If neutrino vertex is not inside the TPC then call it a dirt particle
267  if(!fTpcGeo.InFiducial(vtx, 0, 0)){
268  dirtParticleIds.push_back(partID);
269  }
270  // If it's a primary muon
271  else if(pdg==13 && particle.Mother()==0){
272  lepParticleIds.push_back(partID);
273  }
274  // Other nu particles
275  else{
276  nuParticleIds.push_back(partID);
277  }
278  }
279 
280  // If origin is a cosmic ray
281  else if(truth->Origin() == simb::kCosmicRay){
282  crParticleIds.push_back(partID);
283  }
284 
285  }
286 
287  //----------------------------------------------------------------------------------------------------------
288  // DISTANCE OF CLOSEST APPROACH ANALYSIS
289  //----------------------------------------------------------------------------------------------------------
290  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
291  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
292 
293  // Loop over reconstructed tracks
294  for (auto const& tpcTrack : (*tpcTrackHandle)){
295  // Get the associated hits
296  std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
297  int trackTrueID = RecoUtils::TrueParticleIDFromTotalRecoHits(clockData, hits, false);
298  std::string type = "none";
299  if(std::find(lepParticleIds.begin(), lepParticleIds.end(), trackTrueID) != lepParticleIds.end()) type = "NuMuTrack";
300  if(std::find(nuParticleIds.begin(), nuParticleIds.end(), trackTrueID) != nuParticleIds.end()) type = "NuTrack";
301  if(std::find(crParticleIds.begin(), crParticleIds.end(), trackTrueID) != crParticleIds.end()) type = "CrTrack";
302  if(std::find(dirtParticleIds.begin(), dirtParticleIds.end(), trackTrueID) != dirtParticleIds.end()) type = "DirtTrack";
303  if(type == "none") continue;
304 
305  // Calculate t0 from CRT Hit matching
306  std::pair<sbn::crt::CRTHit, double> closest = t0Alg.ClosestCRTHit(detProp, tpcTrack, crtHits, event);
307 
308  if(closest.second != -99999){
309  int hitTrueID = fCrtBackTrack.TrueIdFromTotalEnergy(event, closest.first);
310  if(hitTrueID == trackTrueID && hitTrueID != -99999){
311  hMatchDCA[type]->Fill(closest.second);
312  }
313  else{
314  hNoMatchDCA[type]->Fill(closest.second);
315  }
316  }
317 
318  if(numHitMap.find(trackTrueID) != numHitMap.end()){
319  hNumTrueMatches[type]->Fill(numHitMap[trackTrueID]);
320  }
321  else{
322  hNumTrueMatches[type]->Fill(0);
323  }
324 
325  int nbins = hDCATotal.begin()->second->GetNbinsX();
326  for(int i = 0; i < nbins; i++){
327  double DCAcut = hDCATotal.begin()->second->GetBinCenter(i);
328 
329  hDCATotal[type]->Fill(DCAcut);
330 
331  // If closest hit is below limit and track matches any hits then fill efficiency
332  if(closest.second < DCAcut && closest.second != -99999){
333  double hitTime = closest.first.ts1_ns * 1e-3;
334  if(hitTime > 0 && hitTime < 4) continue;
335  hDCATag[type]->Fill(DCAcut);
336  }
337 
338  }
339 
340  hLengthTotal[type]->Fill(tpcTrack.Length());
341  if(chTag.CrtHitCosmicId(detProp, tpcTrack, crtHits, event)){
342  hLengthTag[type]->Fill(tpcTrack.Length());
343  }
344  }
345 
346  //Loop over the pfparticle map
347  for (PFParticleIdMap::const_iterator it = pfParticleMap.begin(); it != pfParticleMap.end(); ++it){
348 
349  const art::Ptr<recob::PFParticle> pParticle(it->second);
350  // Only look for primary particles
351  if (!pParticle->IsPrimary()) continue;
352  // Check if this particle is identified as the neutrino
353  const int pdg(pParticle->PdgCode());
354  const bool isNeutrino(std::abs(pdg) == pandora::NU_E || std::abs(pdg) == pandora::NU_MU || std::abs(pdg) == pandora::NU_TAU);
355  //Find neutrino pfparticle
356  if(!isNeutrino) continue;
357 
358  std::string type = "none";
359  std::vector<recob::Track> nuTracks;
360 
361  // Loop over daughters of pfparticle
362  for (const size_t daughterId : pParticle->Daughters()){
363 
364  // Get tracks associated with daughter
365  art::Ptr<recob::PFParticle> pDaughter = pfParticleMap.at(daughterId);
366  const std::vector< art::Ptr<recob::Track> > associatedTracks(pfPartToTrackAssoc.at(pDaughter.key()));
367  if(associatedTracks.size() != 1) continue;
368 
369  // Get the first associated track
370  recob::Track tpcTrack = *associatedTracks.front();
371  nuTracks.push_back(tpcTrack);
372 
373  // Truth match muon tracks and pfps
374  std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
375  int trueId = RecoUtils::TrueParticleIDFromTotalRecoHits(clockData, hits, false);
376  if(std::find(lepParticleIds.begin(), lepParticleIds.end(), trueId) != lepParticleIds.end()){
377  type = "NuMuPfp";
378  }
379  else if(std::find(nuParticleIds.begin(), nuParticleIds.end(), trueId) != nuParticleIds.end()){
380  if(type != "NuMuPfp") type = "NuPfp";
381  }
382  else if(std::find(dirtParticleIds.begin(), dirtParticleIds.end(), trueId) != dirtParticleIds.end()){
383  if(type != "NuMuPfp" && type != "NuPfp") type = "DirtPfp";
384  }
385  else if(std::find(crParticleIds.begin(), crParticleIds.end(), trueId) != crParticleIds.end()){
386  if(type != "NuMuPfp" && type != "NuPfp" && type != "DirtPfp") type = "CrPfp";
387  }
388  }
389 
390  if(nuTracks.size() == 0) continue;
391 
392  std::sort(nuTracks.begin(), nuTracks.end(), [](auto& left, auto& right){
393  return left.Length() > right.Length();});
394 
395  recob::Track tpcTrack = nuTracks[0];
396  std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
397  int trackTrueID = RecoUtils::TrueParticleIDFromTotalRecoHits(clockData, hits, false);
398 
399  if(numHitMap.find(trackTrueID) != numHitMap.end()){
400  hNumTrueMatches[type]->Fill(numHitMap[trackTrueID]);
401  }
402  else{
403  hNumTrueMatches[type]->Fill(0);
404  }
405 
406  // Calculate t0 from CRT Hit matching
407  std::pair<sbn::crt::CRTHit, double> closest = t0Alg.ClosestCRTHit(detProp, tpcTrack, crtHits, event);
408 
409  if(closest.second != -99999){
410  int hitTrueID = fCrtBackTrack.TrueIdFromTotalEnergy(event, closest.first);
411  if(hitTrueID == trackTrueID && hitTrueID != -99999){
412  hMatchDCA[type]->Fill(closest.second);
413  }
414  else{
415  hNoMatchDCA[type]->Fill(closest.second);
416  }
417  }
418 
419 
420  int nbins = hDCATotal.begin()->second->GetNbinsX();
421  for(int i = 0; i < nbins; i++){
422  double DCAcut = hDCATotal.begin()->second->GetBinCenter(i);
423 
424  hDCATotal[type]->Fill(DCAcut);
425 
426  // If closest hit is below limit and track matches any hits then fill efficiency
427  if(closest.second < DCAcut && closest.second != -99999){
428  double hitTime = closest.first.ts1_ns * 1e-3;
429  if(hitTime > 0 && hitTime < 4) continue;
430  hDCATag[type]->Fill(DCAcut);
431  }
432 
433  }
434 
435  hLengthTotal[type]->Fill(tpcTrack.Length());
436  if(chTag.CrtHitCosmicId(detProp, tpcTrack, crtHits, event)){
437  hLengthTag[type]->Fill(tpcTrack.Length());
438  }
439  }
440 
441  } // CRTHitCosmicIdAna::analyze()
std::map< size_t, art::Ptr< recob::PFParticle > > PFParticleIdMap
var pdg
Definition: selectors.fcl:14
art::InputTag fCRTHitLabel
name of CRT producer
walls no right
Definition: selectors.fcl:105
bool fVerbose
print information about what&#39;s going on
void GetPFParticleIdMap(const PFParticleHandle &pfParticleHandle, PFParticleIdMap &pfParticleMap)
process_name hit
Definition: cheaterreco.fcl:51
int TrueIdFromTotalEnergy(const art::Event &event, const sbnd::crt::CRTData &data)
int TrueIdFromHitId(const art::Event &event, int hit_i)
std::map< std::string, TH1D * > hDCATotal
std::map< std::string, TH1D * > hNoMatchDCA
T abs(T value)
std::pair< sbn::crt::CRTHit, double > ClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
std::map< std::string, TH1D * > hLengthTotal
art::InputTag fTPCTrackLabel
name of CRT producer
std::map< std::string, TH1D * > hNumTrueMatches
std::map< std::string, TH1D * > hDCATag
const Cut kCosmicRay
walls no left
Definition: selectors.fcl:105
int TrueParticleIDFromTotalRecoHits(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
bool CrtHitCosmicId(detinfo::DetectorPropertiesData const &detProp, recob::Track track, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
std::map< std::string, TH1D * > hMatchDCA
do i e
art::Handle< std::vector< recob::PFParticle > > PFParticleHandle
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184
BEGIN_PROLOG could also be cout
auto const detProp
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track:
bool InFiducial(geo::Point_t point, double fiducial)
art::InputTag fSimModuleLabel
name of detsim producer
std::map< std::string, TH1D * > hLengthTag
void sbnd::CRTHitCosmicIdAna::beginJob ( )
overridevirtual

Definition at line 168 of file CRTHitCosmicIdAna_module.cc.

169  {
170 
171  // Access tfileservice to handle creating and writing histograms
172  art::ServiceHandle<art::TFileService> tfs;
173  for(auto type : types){
174  hNumTrueMatches[type] = tfs->make<TH1D>(Form("%sNumTrueMatches", type.c_str()), "", 10, 0, 10);
175  hMatchDCA[type] = tfs->make<TH1D>(Form("%sMatchDCA", type.c_str()), "", 60, 0, 100);
176  hNoMatchDCA[type] = tfs->make<TH1D>(Form("%sNoMatchDCA", type.c_str()), "", 60, 0, 100);
177  hDCATotal[type] = tfs->make<TH1D>(Form("%sDCATotal", type.c_str()), "", 20, 0, 80);
178  hDCATag[type] = tfs->make<TH1D>(Form("%sDCATag", type.c_str()), "", 20, 0, 80);
179  hLengthTotal[type] = tfs->make<TH1D>(Form("%sLengthTotal", type.c_str()), "", 20, 0, 400);
180  hLengthTag[type] = tfs->make<TH1D>(Form("%sLengthTag", type.c_str()), "", 20, 0, 400);
181  }
182 
183  // Initial output
184  if(fVerbose) std::cout<<"----------------- CRT T0 Matching Ana Module -------------------"<<std::endl;
185 
186  } // CRTHitCosmicIdAna::beginJob()
std::vector< std::string > types
bool fVerbose
print information about what&#39;s going on
std::map< std::string, TH1D * > hDCATotal
std::map< std::string, TH1D * > hNoMatchDCA
std::map< std::string, TH1D * > hLengthTotal
std::map< std::string, TH1D * > hNumTrueMatches
std::map< std::string, TH1D * > hDCATag
std::map< std::string, TH1D * > hMatchDCA
art::ServiceHandle< art::TFileService > tfs
BEGIN_PROLOG could also be cout
std::map< std::string, TH1D * > hLengthTag
void sbnd::CRTHitCosmicIdAna::endJob ( )
overridevirtual

Definition at line 444 of file CRTHitCosmicIdAna_module.cc.

444  {
445 
446 
447  } // CRTHitCosmicIdAna::endJob()
void sbnd::CRTHitCosmicIdAna::GetPFParticleIdMap ( const PFParticleHandle pfParticleHandle,
PFParticleIdMap pfParticleMap 
)
private

Definition at line 449 of file CRTHitCosmicIdAna_module.cc.

449  {
450  for (unsigned int i = 0; i < pfParticleHandle->size(); ++i){
451  const art::Ptr<recob::PFParticle> pParticle(pfParticleHandle, i);
452  if (!pfParticleMap.insert(PFParticleIdMap::value_type(pParticle->Self(), pParticle)).second){
453  std::cout << " Unable to get PFParticle ID map, the input PFParticle collection has repeat IDs!" <<"\n";
454  }
455  }
456  }
BEGIN_PROLOG could also be cout

Member Data Documentation

CrtHitCosmicIdAlg sbnd::CRTHitCosmicIdAna::chTag
private

Definition at line 137 of file CRTHitCosmicIdAna_module.cc.

CRTBackTracker sbnd::CRTHitCosmicIdAna::fCrtBackTrack
private

Definition at line 136 of file CRTHitCosmicIdAna_module.cc.

art::InputTag sbnd::CRTHitCosmicIdAna::fCRTHitLabel
private

name of CRT producer

Definition at line 127 of file CRTHitCosmicIdAna_module.cc.

art::InputTag sbnd::CRTHitCosmicIdAna::fPandoraLabel
private

Definition at line 129 of file CRTHitCosmicIdAna_module.cc.

art::InputTag sbnd::CRTHitCosmicIdAna::fSimModuleLabel
private

name of detsim producer

Definition at line 126 of file CRTHitCosmicIdAna_module.cc.

TPCGeoAlg sbnd::CRTHitCosmicIdAna::fTpcGeo
private

Definition at line 134 of file CRTHitCosmicIdAna_module.cc.

art::InputTag sbnd::CRTHitCosmicIdAna::fTPCTrackLabel
private

name of CRT producer

Definition at line 128 of file CRTHitCosmicIdAna_module.cc.

bool sbnd::CRTHitCosmicIdAna::fVerbose
private

print information about what's going on

Definition at line 130 of file CRTHitCosmicIdAna_module.cc.

std::map<std::string, TH1D*> sbnd::CRTHitCosmicIdAna::hDCATag
private

Definition at line 145 of file CRTHitCosmicIdAna_module.cc.

std::map<std::string, TH1D*> sbnd::CRTHitCosmicIdAna::hDCATotal
private

Definition at line 144 of file CRTHitCosmicIdAna_module.cc.

std::map<std::string, TH1D*> sbnd::CRTHitCosmicIdAna::hLengthTag
private

Definition at line 147 of file CRTHitCosmicIdAna_module.cc.

std::map<std::string, TH1D*> sbnd::CRTHitCosmicIdAna::hLengthTotal
private

Definition at line 146 of file CRTHitCosmicIdAna_module.cc.

std::map<std::string, TH1D*> sbnd::CRTHitCosmicIdAna::hMatchDCA
private

Definition at line 142 of file CRTHitCosmicIdAna_module.cc.

std::map<std::string, TH1D*> sbnd::CRTHitCosmicIdAna::hNoMatchDCA
private

Definition at line 143 of file CRTHitCosmicIdAna_module.cc.

std::map<std::string, TH1D*> sbnd::CRTHitCosmicIdAna::hNumTrueMatches
private

Definition at line 141 of file CRTHitCosmicIdAna_module.cc.

CRTT0MatchAlg sbnd::CRTHitCosmicIdAna::t0Alg
private

Definition at line 132 of file CRTHitCosmicIdAna_module.cc.

std::vector<std::string> sbnd::CRTHitCosmicIdAna::types {"NuMuTrack", "CrTrack", "DirtTrack", "NuTrack", "NuMuPfp", "CrPfp", "DirtPfp", "NuPfp"}
private

Definition at line 140 of file CRTHitCosmicIdAna_module.cc.


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