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

Public Member Functions

 Razzle (fhicl::ParameterSet const &p)
 
 Razzle (Razzle const &)=delete
 
 Razzle (Razzle &&)=delete
 
Razzleoperator= (Razzle const &)=delete
 
Razzleoperator= (Razzle &&)=delete
 
void produce (art::Event &e) override
 
void beginJob () override
 

Private Member Functions

void ClearTreeValues ()
 
void FillTrueParticleMetrics (const detinfo::DetectorClocksData &clockData, const recob::Shower &shower, const std::vector< art::Ptr< recob::Hit >> &hits, std::vector< art::Ptr< sim::SimChannel >> &simChannels)
 
void FillShowerMetrics (const recob::Shower &shower, const std::vector< art::Ptr< recob::Hit >> &hitVec)
 
void FillPFPMetrics (const art::Ptr< recob::PFParticle > &pfp, const std::map< size_t, art::Ptr< recob::PFParticle >> &pfpMap, const recob::Shower &shower, const art::FindManyP< larpandoraobj::PFParticleMetadata > &fmMeta, const art::FindManyP< recob::Vertex > &fmVertex)
 
void FillDensityFitMetrics (const ShowerDensityFit &densityFit)
 
void FillTrackFitMetrics (const ShowerTrackFit &trackFit)
 
MVAPID RunMVA ()
 
std::map< size_t, art::Ptr
< recob::PFParticle > > 
GetPFPMap (std::vector< art::Ptr< recob::PFParticle >> &pfps) const
 
float GetPFPTrackScore (const art::Ptr< recob::PFParticle > &pfp, const art::FindManyP< larpandoraobj::PFParticleMetadata > &fmMeta) const
 
bool InFV (const TVector3 &pos) const
 
std::string PdgString (const int pdg) const
 

Private Attributes

art::ServiceHandle
< art::TFileService > 
tfs
 
art::ServiceHandle
< cheat::ParticleInventoryService
particleInventory
 
art::InputTag fSimChannelLabel
 
art::InputTag fPFPLabel
 
art::InputTag fShowerLabel
 
art::InputTag fShowerSelVarsLabel
 
const float fMinShowerEnergy
 
const bool fMakeTree
 
const bool fRunMVA
 
const std::string fMethodName
 
const std::string fWeightFile
 
const float fXMin
 
const float fXMax
 
const float fYMin
 
const float fYMax
 
const float fZMin
 
const float fZMax
 
float bestdEdx
 
float convGap
 
float openAngle
 
float modHitDensity
 
float sqrtEnergyDensity
 
float electronScore
 
float photonScore
 
float otherScore
 
float bestScore
 
int bestPDG
 
TMVA::Reader * reader
 
TTree * showerTree
 
int trackHits
 
int truePdg
 
int numHits
 
int bestPlane
 
int recoContained
 
int recoPrimary
 
int numDaughters
 
float length
 
float bestEnergy
 
float bestPlaneHits
 
float bestPitch
 
float logEnergyDensity
 
float trackScore
 
float densityFitGrad
 
float densityFitPow
 
float trackLength
 
float trackWidth
 
float startX
 
float startY
 
float startZ
 
float endX
 
float endY
 
float endZ
 
float trueStartX
 
float trueStartY
 
float trueStartZ
 
float trueEndX
 
float trueEndY
 
float trueEndZ
 
float startDist
 
float endDist
 
float trueP
 
float energyComp
 
float energyPurity
 
std::string trueType
 
std::string trueEndProcess
 

Detailed Description

Definition at line 68 of file Razzle_module.cc.

Constructor & Destructor Documentation

sbn::Razzle::Razzle ( fhicl::ParameterSet const &  p)
explicit

Definition at line 141 of file Razzle_module.cc.

142  : EDProducer { p }
143  , fSimChannelLabel(p.get<std::string>("SimChannelLabel"))
144  , fPFPLabel(p.get<std::string>("PFPLabel"))
145  , fShowerLabel(p.get<std::string>("ShowerLabel"))
146  , fShowerSelVarsLabel(p.get<std::string>("ShowerSelVarsLabel"))
147  , fMinShowerEnergy(p.get<float>("MinShowerEnergy"))
148  , fMakeTree(p.get<bool>("MakeTree"))
149  , fRunMVA(p.get<bool>("RunMVA"))
150  , fMethodName(p.get<std::string>("MethodName", ""))
151  , fWeightFile(p.get<std::string>("WeightFile", ""))
152  , fXMin(p.get<float>("XMin"))
153  , fXMax(p.get<float>("XMax"))
154  , fYMin(p.get<float>("YMin"))
155  , fYMax(p.get<float>("YMax"))
156  , fZMin(p.get<float>("ZMin"))
157  , fZMax(p.get<float>("ZMax"))
158 {
159  if (!fMakeTree && !fRunMVA)
160  throw cet::exception("Razzle") << "Configured to do nothing";
161 
162  if (fRunMVA) {
163  if (fMethodName == "" || fWeightFile == "")
164  throw cet::exception("Razzle") << "Trying to run MVA with inputs not set: MethodName: " << fMethodName << " and WeightFile: " << fWeightFile;
165 
166  cet::search_path searchPath("FW_SEARCH_PATH");
167  std::string fWeightFileFullPath;
168  if (!searchPath.find_file(fWeightFile, fWeightFileFullPath))
169  throw cet::exception("Razzle") << "Unable to find weight file: " << fWeightFile << " in FW_SEARCH_PATH: " << searchPath.to_string();
170 
171  reader = new TMVA::Reader("V");
172 
173  // reader->AddVariable("recoLen", &recoLen);
174  reader->AddVariable("bestdEdx", &bestdEdx);
175  reader->AddVariable("convGap", &convGap);
176  reader->AddVariable("openAngle", &openAngle);
177  reader->AddVariable("modHitDensity", &modHitDensity);
178  // reader->AddVariable("logEnergyDensity", &logEnergyDensity);
179  reader->AddVariable("sqrtEnergyDensity", &sqrtEnergyDensity);
180 
181  reader->BookMVA(fMethodName, fWeightFileFullPath);
182  }
183  // Call appropriate produces<>() functions here.
184  produces<std::vector<MVAPID>>();
185  produces<art::Assns<recob::Shower, MVAPID>>();
186 }
float sqrtEnergyDensity
const bool fRunMVA
art::InputTag fSimChannelLabel
const float fZMin
pdgs p
Definition: selectors.fcl:22
const float fYMin
const std::string fWeightFile
const float fXMin
art::InputTag fShowerLabel
art::InputTag fShowerSelVarsLabel
const std::string fMethodName
art::InputTag fPFPLabel
const bool fMakeTree
float modHitDensity
const float fZMax
const float fMinShowerEnergy
const float fYMax
TMVA::Reader * reader
const float fXMax
sbn::Razzle::Razzle ( Razzle const &  )
delete
sbn::Razzle::Razzle ( Razzle &&  )
delete

Member Function Documentation

void sbn::Razzle::beginJob ( )
override

Definition at line 188 of file Razzle_module.cc.

189 {
190  if (fMakeTree) {
191  showerTree = tfs->make<TTree>("showerTree", "Tree filled per Shower with PID variables");
192 
193  if (fRunMVA) {
194  showerTree->Branch("electronScore", &electronScore);
195  showerTree->Branch("photonScore", &photonScore);
196  showerTree->Branch("otherScore", &otherScore);
197  showerTree->Branch("bestScore", &bestScore);
198  showerTree->Branch("bestPDG", &bestPDG);
199  }
200 
201  showerTree->Branch("truePdg", &truePdg);
202  showerTree->Branch("trueP", &trueP);
203  showerTree->Branch("trueType", &trueType);
204  showerTree->Branch("trueEndProcess", &trueEndProcess);
205  showerTree->Branch("energyComp", &energyComp);
206  showerTree->Branch("energyPurity", &energyPurity);
207 
208  showerTree->Branch("startX", &startX);
209  showerTree->Branch("startY", &startY);
210  showerTree->Branch("startZ", &startZ);
211 
212  showerTree->Branch("endX", &endX);
213  showerTree->Branch("endY", &endY);
214  showerTree->Branch("endZ", &endZ);
215 
216  showerTree->Branch("trueStartX", &trueStartX);
217  showerTree->Branch("trueStartY", &trueStartY);
218  showerTree->Branch("trueStartZ", &trueStartZ);
219 
220  showerTree->Branch("trueEndX", &trueEndX);
221  showerTree->Branch("trueEndY", &trueEndY);
222  showerTree->Branch("trueEndZ", &trueEndZ);
223 
224  showerTree->Branch("startDist", &startDist);
225  showerTree->Branch("endDist", &endDist);
226 
227  showerTree->Branch("numHits", &numHits);
228  showerTree->Branch("bestPlane", &bestPlane);
229 
230  showerTree->Branch("recoPrimary", &recoPrimary);
231  showerTree->Branch("numDaughters", &numDaughters);
232  showerTree->Branch("trackScore", &trackScore);
233  showerTree->Branch("convGap", &convGap);
234  showerTree->Branch("recoContained", &recoContained);
235 
236  showerTree->Branch("densityFitGrad", &densityFitGrad);
237  showerTree->Branch("densityFitPow", &densityFitPow);
238 
239  showerTree->Branch("trackLength", &trackLength);
240  showerTree->Branch("trackWidth", &trackWidth);
241  showerTree->Branch("trackHits", &trackHits);
242 
243  showerTree->Branch("length", &length);
244  showerTree->Branch("openAngle", &openAngle);
245  showerTree->Branch("bestdEdx", &bestdEdx);
246  showerTree->Branch("bestEnergy", &bestEnergy);
247  showerTree->Branch("bestPlaneHits", &bestPlaneHits);
248  showerTree->Branch("bestPitch", &bestPitch);
249  showerTree->Branch("modHitDensity", &modHitDensity);
250  showerTree->Branch("sqrtEnergyDensity", &sqrtEnergyDensity);
251  showerTree->Branch("logEnergyDensity", &logEnergyDensity);
252  }
253 }
float energyPurity
float sqrtEnergyDensity
float bestPlaneHits
const bool fRunMVA
std::string trueEndProcess
std::string trueType
const bool fMakeTree
float densityFitGrad
float modHitDensity
float densityFitPow
art::ServiceHandle< art::TFileService > tfs
float electronScore
TTree * showerTree
float logEnergyDensity
void sbn::Razzle::ClearTreeValues ( )
private

Definition at line 332 of file Razzle_module.cc.

333 {
334  truePdg = -5;
335  numHits = -5;
336  bestPlane = -5;
337 
338  recoContained = -5;
339  recoPrimary = -5;
340  numDaughters = -5;
341 
342  trackScore = -5.f;
343  convGap = -5.f;
344 
345  electronScore = -5.f;
346  photonScore = -5.f;
347  otherScore = -5.f;
348  bestScore = -5.f;
349  bestPDG = -5;
350 
351  startX = -999.f;
352  startY = -999.f;
353  startZ = -999.f;
354  endX = -999.f;
355  endY = -999.f;
356  endZ = -999.f;
357  trueStartX = -999.f;
358  trueStartY = -999.f;
359  trueStartZ = -999.f;
360  trueEndX = -999.f;
361  trueEndY = -999.f;
362  trueEndZ = -999.f;
363  startDist = -999.f;
364  endDist = -999.f;
365 
366  trueP = -5.f;
367  energyPurity = -5.f;
368  energyComp = -5.f;
369 
370  densityFitGrad = -5.f;
371  densityFitPow = -5.f;
372 
373  trackWidth = -5.f;
374  trackLength = -5.f;
375  trackHits = -5;
376 
377  length = -5.f;
378  openAngle = -5.f;
379  bestdEdx = -5.f;
380  bestEnergy = -5.f;
381  bestPlaneHits = -5.f;
382  bestPitch = -5.f;
383  modHitDensity = -5.f;
384  logEnergyDensity = -5.f;
385  sqrtEnergyDensity = -5.f;
386 
387  trueType = "";
388  trueEndProcess = "";
389 }
float energyPurity
float sqrtEnergyDensity
float bestPlaneHits
std::string trueEndProcess
std::string trueType
float densityFitGrad
float modHitDensity
float densityFitPow
float electronScore
float logEnergyDensity
void sbn::Razzle::FillDensityFitMetrics ( const ShowerDensityFit densityFit)
private

Definition at line 549 of file Razzle_module.cc.

550 {
551  densityFitGrad = densityFit.mDensityGrad;
552  densityFitPow = densityFit.mDensityPow;
553 }
float densityFitGrad
float densityFitPow
void sbn::Razzle::FillPFPMetrics ( const art::Ptr< recob::PFParticle > &  pfp,
const std::map< size_t, art::Ptr< recob::PFParticle >> &  pfpMap,
const recob::Shower shower,
const art::FindManyP< larpandoraobj::PFParticleMetadata > &  fmMeta,
const art::FindManyP< recob::Vertex > &  fmVertex 
)
private

Definition at line 522 of file Razzle_module.cc.

524 {
525  numDaughters = pfp->Daughters().size();
526  trackScore = this->GetPFPTrackScore(pfp, fmMeta);
527 
528  auto const parentId(pfp->Parent());
529  auto const& parentIter(pfpMap.find(parentId));
530 
531  if (parentIter == pfpMap.end())
532  return;
533 
534  recoPrimary = parentIter->second->IsPrimary();
535 
536  auto const& parentVertexVec = fmVertex.at(parentIter->second.key());
537 
538  if (parentVertexVec.empty())
539  return;
540 
541  // Need to convert vertex to TVector3 for ease of comparison to shower start
542  const auto parentVertexPoint(parentVertexVec.front()->position());
543  const TVector3 parentVertex { parentVertexPoint.X(), parentVertexPoint.Y(), parentVertexPoint.Z() };
544 
545  convGap = (shower.ShowerStart() - parentVertex).Mag();
546  convGap = std::min(convGap, 50.f);
547 }
const TVector3 & ShowerStart() const
Definition: Shower.h:192
float GetPFPTrackScore(const art::Ptr< recob::PFParticle > &pfp, const art::FindManyP< larpandoraobj::PFParticleMetadata > &fmMeta) const
void sbn::Razzle::FillShowerMetrics ( const recob::Shower shower,
const std::vector< art::Ptr< recob::Hit >> &  hitVec 
)
private

Definition at line 456 of file Razzle_module.cc.

457 {
458  const geo::GeometryCore* geom = lar::providerFrom<geo::Geometry>();
459 
460  length = shower.Length();
461  openAngle = shower.OpenAngle();
462 
463  const TVector3 start(shower.ShowerStart());
464  const TVector3 end(start + length * shower.Direction());
465  recoContained = this->InFV(start) && this->InFV(end);
466 
467  numHits = hitVec.size();
468 
469  std::array<int, 3> showerPlaneHits { 0, 0, 0 };
470  for (auto const& hit : hitVec) {
471  showerPlaneHits[hit->WireID().Plane]++;
472  }
473 
474  std::array<float, 3> showerPlanePitches { -1.f, -1.f, -1.f };
475  for (geo::PlaneGeo const& plane : geom->IteratePlanes()) {
476 
477  const float angleToVert(geom->WireAngleToVertical(plane.View(), plane.ID()) - 0.5 * M_PI);
478  const float cosgamma(std::abs(std::sin(angleToVert) * shower.Direction().Y() + std::cos(angleToVert) * shower.Direction().Z()));
479 
480  showerPlanePitches[plane.ID().Plane] = plane.WirePitch() / cosgamma;
481  }
482 
483  // Fill only for the best plane, defined as the one with the most hits
484  // Prefer collection plane > 1st induction > 2nd induction
485  bestPlane = shower.best_plane();
486 
487  if (bestPlane < 0 || bestPlane > 3)
488  throw cet::exception("Razzle") << "Best plane: " << bestPlane;
489 
490  bestdEdx = shower.dEdx()[bestPlane];
491  bestdEdx = std::min(bestdEdx, 20.f);
492  bestdEdx = std::max(bestdEdx, -5.f);
493 
494  bestEnergy = shower.Energy()[bestPlane];
495  bestPlaneHits = showerPlaneHits[bestPlane];
496  bestPitch = showerPlanePitches[bestPlane];
497 
498  logEnergyDensity = (length > 0 && bestEnergy > 0) ? std::log(bestEnergy) / length : -5.f;
499  sqrtEnergyDensity = (length > 0 && bestEnergy > 0) ? std::sqrt(bestEnergy) / length : -5.f;
500 
501  const float wiresHit(bestPitch > std::numeric_limits<float>::epsilon() ? length / bestPitch : -5.f);
502  modHitDensity = wiresHit > 1.f ? bestPlaneHits / wiresHit : -5.f;
503  modHitDensity = std::min(modHitDensity, 40.f);
504 
505  if (!fMakeTree)
506  return;
507 
508  startX = start.X();
509  startY = start.Y();
510  startZ = start.Z();
511 
512  endX = end.X();
513  endY = end.Y();
514  endZ = end.Z();
515 }
float sqrtEnergyDensity
float bestPlaneHits
IteratorBox< plane_iterator,&GeometryCore::begin_plane,&GeometryCore::end_plane > IteratePlanes() const
Enables ranged-for loops on all planes of the detector.
const TVector3 & Direction() const
Definition: Shower.h:189
const std::vector< double > & dEdx() const
Definition: Shower.h:203
bool InFV(const TVector3 &pos) const
int best_plane() const
Definition: Shower.h:200
process_name hit
Definition: cheaterreco.fcl:51
double Length() const
Definition: Shower.h:201
T abs(T value)
double OpenAngle() const
Definition: Shower.h:202
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:82
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
const bool fMakeTree
Description of geometry of one entire detector.
float modHitDensity
const std::vector< double > & Energy() const
Definition: Shower.h:195
const TVector3 & ShowerStart() const
Definition: Shower.h:192
double WireAngleToVertical(geo::View_t view, geo::TPCID const &tpcid) const
Returns the angle of the wires in the specified view from vertical.
float logEnergyDensity
void sbn::Razzle::FillTrackFitMetrics ( const ShowerTrackFit trackFit)
private

Definition at line 554 of file Razzle_module.cc.

555 {
556  trackLength = trackFit.mTrackLength;
557  trackWidth = trackFit.mTrackWidth;
558  trackHits = trackFit.mNumHits;
559 }
void sbn::Razzle::FillTrueParticleMetrics ( const detinfo::DetectorClocksData clockData,
const recob::Shower shower,
const std::vector< art::Ptr< recob::Hit >> &  hits,
std::vector< art::Ptr< sim::SimChannel >> &  simChannels 
)
private

Definition at line 391 of file Razzle_module.cc.

392 {
393  art::ServiceHandle<cheat::BackTrackerService> bt_serv;
394  const int bestMatch(TruthMatchUtils::TrueParticleIDFromTotalTrueEnergy(clockData, hits, true));
395 
396  if (!TruthMatchUtils::Valid(bestMatch))
397  return;
398 
399  float totalHitEnergy(0.f), totalTrueHitEnergy(0.f);
400  for (auto const& hit : hits) {
401  const std::vector<sim::TrackIDE> trackIDEs(bt_serv->HitToTrackIDEs(clockData, hit));
402  totalHitEnergy = std::accumulate(trackIDEs.cbegin(), trackIDEs.cend(), totalHitEnergy,
403  [](float sum, auto const& ide) { return sum + ide.energy; });
404  totalTrueHitEnergy = std::accumulate(trackIDEs.cbegin(), trackIDEs.cend(), totalTrueHitEnergy,
405  [bestMatch](float sum, auto const& ide) { return (std::abs(ide.trackID) == bestMatch) ? sum + ide.energy : sum; });
406  }
407 
408  const std::vector<const sim::IDE*> trackIDEs(bt_serv->TrackIdToSimIDEs_Ps(bestMatch));
409  float totalTrueEnergy(std::accumulate(trackIDEs.cbegin(), trackIDEs.cend(), 0.f,
410  [](float sum, auto const& ide) { return sum + ide->energy; }));
411 
412  energyComp = totalTrueHitEnergy / totalTrueEnergy;
413  energyPurity = totalTrueHitEnergy / totalHitEnergy;
414 
415  const simb::MCParticle* const trueParticle(particleInventory->TrackIdToParticle_P(bestMatch));
416 
417  if (!trueParticle)
418  return;
419 
420  truePdg = trueParticle->PdgCode();
421  trueType = this->PdgString(truePdg);
422  trueEndProcess = trueParticle->EndProcess();
423 
424  trueP = trueParticle->P();
425 
426  const TVector3 showerStart(shower.ShowerStart());
427  const TVector3 showerEnd(showerStart + shower.Length() * shower.Direction());
428 
429  // Select first traj point where the photon loses energy, last be default
430  TVector3 PositionTrajStart(trueParticle->Position(0).Vect());
431 
432  // For phoyons say the shower started when the photon loses 10% of the energy
433  if (trueParticle->PdgCode() == 22) {
434  unsigned int trajPoint(1);
435  while (trueParticle->E(trajPoint) == trueParticle->E()) {
436  trajPoint++;
437  }
438  PositionTrajStart = trueParticle->Position(trajPoint).Vect();
439  }
440 
441  const TVector3 trueStart(PositionTrajStart);
442  const TVector3 trueEnd(trueParticle->EndPosition().Vect());
443 
444  trueStartX = trueStart.X();
445  trueStartY = trueStart.Y();
446  trueStartZ = trueStart.Z();
447 
448  trueEndX = trueEnd.X();
449  trueEndY = trueEnd.Y();
450  trueEndZ = trueEnd.Z();
451 
452  startDist = (trueStart - showerStart).Mag();
453  endDist = (trueEnd - showerEnd).Mag();
454 }
float energyPurity
const TVector3 & Direction() const
Definition: Shower.h:189
process_name hit
Definition: cheaterreco.fcl:51
double Length() const
Definition: Shower.h:201
T abs(T value)
std::string trueEndProcess
art::ServiceHandle< cheat::ParticleInventoryService > particleInventory
std::string trueType
std::string PdgString(const int pdg) const
bool Valid(const G4ID g4ID) noexcept
Test whether a G4ID returned by the TruthMatchUtils functions is valid.
G4ID TrueParticleIDFromTotalTrueEnergy(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit >> &pHits, const bool rollupUnsavedIDs)
The G4 ID of the true particle which deposits the most energy in a vector of recob::Hit.
const TVector3 & ShowerStart() const
Definition: Shower.h:192
std::map< size_t, art::Ptr< recob::PFParticle > > sbn::Razzle::GetPFPMap ( std::vector< art::Ptr< recob::PFParticle >> &  pfps) const
private

Definition at line 584 of file Razzle_module.cc.

585 {
586  std::map<size_t, art::Ptr<recob::PFParticle>> pfpMap;
587  for (auto const& pfp : pfps) {
588  pfpMap[pfp->Self()] = pfp;
589  }
590  return pfpMap;
591 }
float sbn::Razzle::GetPFPTrackScore ( const art::Ptr< recob::PFParticle > &  pfp,
const art::FindManyP< larpandoraobj::PFParticleMetadata > &  fmMeta 
) const
private

Definition at line 593 of file Razzle_module.cc.

594 {
595  auto const pfpMetaVec(fmMeta.at(pfp.key()));
596  if (pfpMetaVec.size() != 1)
597  return -5.f;
598  const larpandoraobj::PFParticleMetadata::PropertiesMap propertiesMap(pfpMetaVec.front()->GetPropertiesMap());
599  auto const& pfpTrackScoreIter = propertiesMap.find("TrackScore");
600  return pfpTrackScoreIter == propertiesMap.end() ? -5.f : pfpTrackScoreIter->second;
601 }
std::map< std::string, float > PropertiesMap
bool sbn::Razzle::InFV ( const TVector3 &  pos) const
private

Definition at line 517 of file Razzle_module.cc.

518 {
519  return (pos.X() > fXMin && pos.X() < fXMax && pos.Y() > fYMin && pos.Y() < fYMax && pos.Z() > fZMin && pos.Z() < fZMax);
520 }
const float fZMin
const float fYMin
const float fXMin
const float fZMax
const float fYMax
const float fXMax
Razzle& sbn::Razzle::operator= ( Razzle const &  )
delete
Razzle& sbn::Razzle::operator= ( Razzle &&  )
delete
std::string sbn::Razzle::PdgString ( const int  pdg) const
private

Definition at line 603 of file Razzle_module.cc.

604 {
605  switch (std::abs(pdg)) {
606  case 11:
607  return "Electron";
608  case 22:
609  return "Photon";
610  default:
611  return "Other";
612  }
613 }
var pdg
Definition: selectors.fcl:14
T abs(T value)
void sbn::Razzle::produce ( art::Event &  e)
override

Definition at line 255 of file Razzle_module.cc.

256 {
257  auto const clockData(art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e));
258 
259  auto const pfpHandle(e.getValidHandle<std::vector<recob::PFParticle>>(fPFPLabel));
260  auto const simChannelHandle(e.getValidHandle<std::vector<sim::SimChannel>>(fSimChannelLabel));
261  auto const showerHandle(e.getValidHandle<std::vector<recob::Shower>>(fShowerLabel));
262 
263  std::vector<art::Ptr<recob::PFParticle>> pfps;
264  art::fill_ptr_vector(pfps, pfpHandle);
265 
266  std::vector<art::Ptr<sim::SimChannel>> simChannels;
267  art::fill_ptr_vector(simChannels, simChannelHandle);
268 
269  art::FindManyP<recob::Vertex> fmPFPVertex(pfpHandle, e, fPFPLabel);
270  art::FindManyP<larpandoraobj::PFParticleMetadata> fmPFPMeta(pfpHandle, e, fPFPLabel);
271 
272  art::FindManyP<recob::Shower> fmPFPShower(pfpHandle, e, fShowerLabel);
273  art::FindManyP<recob::Hit> fmShowerHit(showerHandle, e, fShowerLabel);
274 
275  art::FindManyP<ShowerDensityFit> fmShowerDensityFit(showerHandle, e, fShowerSelVarsLabel);
276  art::FindManyP<ShowerTrackFit> fmShowerTrackFit(showerHandle, e, fShowerSelVarsLabel);
277 
278  auto mvaPIDVec = std::make_unique<std::vector<MVAPID>>();
279  auto showerAssns = std::make_unique<art::Assns<recob::Shower, MVAPID>>();
280 
281  const std::map<size_t, art::Ptr<recob::PFParticle>> pfpMap(this->GetPFPMap(pfps));
282 
283  for (auto const& pfp : pfps) {
284  this->ClearTreeValues();
285 
286  // Get the shower for the PFP
287  std::vector<art::Ptr<recob::Shower>> pfpShowerVec(fmPFPShower.at(pfp.key()));
288 
289  // Skip showers and primaries
290  if (pfpShowerVec.empty())
291  continue;
292 
293  // There should be 1-1 PFP to showers
294  if (pfpShowerVec.size() > 1)
295  throw cet::exception("Razzle") << "Too many showers: " << pfpShowerVec.size();
296 
297  art::Ptr<recob::Shower>& pfpShower(pfpShowerVec.front());
298 
299  if (pfpShower->best_plane() < 0 || pfpShower->Energy().at(pfpShower->best_plane()) < fMinShowerEnergy)
300  continue;
301 
302  std::vector<art::Ptr<recob::Hit>> showerHitVec(fmShowerHit.at(pfpShower.key()));
303 
304  this->FillShowerMetrics(*pfpShower, showerHitVec);
305 
306  this->FillPFPMetrics(pfp, pfpMap, *pfpShower, fmPFPMeta, fmPFPVertex);
307 
308  auto const densityFitVec(fmShowerDensityFit.at(pfpShower.key()));
309  if (densityFitVec.size() == 1)
310  this->FillDensityFitMetrics(*densityFitVec.front());
311 
312  auto const trackFitVec(fmShowerTrackFit.at(pfpShower.key()));
313  if (trackFitVec.size() == 1)
314  this->FillTrackFitMetrics(*trackFitVec.front());
315 
316  if (fRunMVA) {
317  MVAPID mvaPID(this->RunMVA());
318  mvaPIDVec->push_back(mvaPID);
319  util::CreateAssn(*this, e, *mvaPIDVec, pfpShower, *showerAssns);
320  }
321 
322  // Only fill the truth metrics if we are saving a TTree
323  if (fMakeTree) {
324  this->FillTrueParticleMetrics(clockData, *pfpShower, showerHitVec, simChannels);
325  showerTree->Fill();
326  }
327  }
328  e.put(std::move(mvaPIDVec));
329  e.put(std::move(showerAssns));
330 }
const bool fRunMVA
art::InputTag fSimChannelLabel
void FillTrueParticleMetrics(const detinfo::DetectorClocksData &clockData, const recob::Shower &shower, const std::vector< art::Ptr< recob::Hit >> &hits, std::vector< art::Ptr< sim::SimChannel >> &simChannels)
void FillTrackFitMetrics(const ShowerTrackFit &trackFit)
art::InputTag fShowerLabel
art::InputTag fShowerSelVarsLabel
void FillShowerMetrics(const recob::Shower &shower, const std::vector< art::Ptr< recob::Hit >> &hitVec)
art::InputTag fPFPLabel
const bool fMakeTree
void ClearTreeValues()
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
std::map< size_t, art::Ptr< recob::PFParticle > > GetPFPMap(std::vector< art::Ptr< recob::PFParticle >> &pfps) const
void FillDensityFitMetrics(const ShowerDensityFit &densityFit)
const float fMinShowerEnergy
void FillPFPMetrics(const art::Ptr< recob::PFParticle > &pfp, const std::map< size_t, art::Ptr< recob::PFParticle >> &pfpMap, const recob::Shower &shower, const art::FindManyP< larpandoraobj::PFParticleMetadata > &fmMeta, const art::FindManyP< recob::Vertex > &fmVertex)
MVAPID RunMVA()
do i e
TTree * showerTree
MVAPID sbn::Razzle::RunMVA ( )
private

Definition at line 561 of file Razzle_module.cc.

562 {
563  const std::vector<float> mvaScores(reader->EvaluateMulticlass(fMethodName));
564 
565  MVAPID pidResults;
566 
567  pidResults.AddScore(11, mvaScores.at(0));
568  pidResults.AddScore(22, mvaScores.at(1));
569  pidResults.AddScore(0, mvaScores.at(2));
570 
571  if (!fMakeTree)
572  return pidResults;
573 
574  electronScore = mvaScores.at(0);
575  photonScore = mvaScores.at(1);
576  otherScore = mvaScores.at(2);
577 
578  bestScore = pidResults.BestScore();
579  bestPDG = pidResults.BestPDG();
580 
581  return pidResults;
582 }
const std::string fMethodName
const bool fMakeTree
TMVA::Reader * reader
float electronScore

Member Data Documentation

float sbn::Razzle::bestdEdx
private

Definition at line 98 of file Razzle_module.cc.

float sbn::Razzle::bestEnergy
private

Definition at line 117 of file Razzle_module.cc.

int sbn::Razzle::bestPDG
private

Definition at line 108 of file Razzle_module.cc.

float sbn::Razzle::bestPitch
private

Definition at line 117 of file Razzle_module.cc.

int sbn::Razzle::bestPlane
private

Definition at line 115 of file Razzle_module.cc.

float sbn::Razzle::bestPlaneHits
private

Definition at line 117 of file Razzle_module.cc.

float sbn::Razzle::bestScore
private

Definition at line 107 of file Razzle_module.cc.

float sbn::Razzle::convGap
private

Definition at line 99 of file Razzle_module.cc.

float sbn::Razzle::densityFitGrad
private

Definition at line 119 of file Razzle_module.cc.

float sbn::Razzle::densityFitPow
private

Definition at line 119 of file Razzle_module.cc.

float sbn::Razzle::electronScore
private

Definition at line 107 of file Razzle_module.cc.

float sbn::Razzle::endDist
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::endX
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::endY
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::endZ
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::energyComp
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::energyPurity
private

Definition at line 121 of file Razzle_module.cc.

const bool sbn::Razzle::fMakeTree
private

Definition at line 91 of file Razzle_module.cc.

const std::string sbn::Razzle::fMethodName
private

Definition at line 92 of file Razzle_module.cc.

const float sbn::Razzle::fMinShowerEnergy
private

Definition at line 90 of file Razzle_module.cc.

art::InputTag sbn::Razzle::fPFPLabel
private

Definition at line 89 of file Razzle_module.cc.

const bool sbn::Razzle::fRunMVA
private

Definition at line 91 of file Razzle_module.cc.

art::InputTag sbn::Razzle::fShowerLabel
private

Definition at line 89 of file Razzle_module.cc.

art::InputTag sbn::Razzle::fShowerSelVarsLabel
private

Definition at line 89 of file Razzle_module.cc.

art::InputTag sbn::Razzle::fSimChannelLabel
private

Definition at line 89 of file Razzle_module.cc.

const std::string sbn::Razzle::fWeightFile
private

Definition at line 92 of file Razzle_module.cc.

const float sbn::Razzle::fXMax
private

Definition at line 95 of file Razzle_module.cc.

const float sbn::Razzle::fXMin
private

Definition at line 95 of file Razzle_module.cc.

const float sbn::Razzle::fYMax
private

Definition at line 95 of file Razzle_module.cc.

const float sbn::Razzle::fYMin
private

Definition at line 95 of file Razzle_module.cc.

const float sbn::Razzle::fZMax
private

Definition at line 95 of file Razzle_module.cc.

const float sbn::Razzle::fZMin
private

Definition at line 95 of file Razzle_module.cc.

float sbn::Razzle::length
private

Definition at line 117 of file Razzle_module.cc.

float sbn::Razzle::logEnergyDensity
private

Definition at line 117 of file Razzle_module.cc.

float sbn::Razzle::modHitDensity
private

Definition at line 101 of file Razzle_module.cc.

int sbn::Razzle::numDaughters
private

Definition at line 115 of file Razzle_module.cc.

int sbn::Razzle::numHits
private

Definition at line 115 of file Razzle_module.cc.

float sbn::Razzle::openAngle
private

Definition at line 100 of file Razzle_module.cc.

float sbn::Razzle::otherScore
private

Definition at line 107 of file Razzle_module.cc.

art::ServiceHandle<cheat::ParticleInventoryService> sbn::Razzle::particleInventory
private

Definition at line 87 of file Razzle_module.cc.

float sbn::Razzle::photonScore
private

Definition at line 107 of file Razzle_module.cc.

TMVA::Reader* sbn::Razzle::reader
private

Definition at line 111 of file Razzle_module.cc.

int sbn::Razzle::recoContained
private

Definition at line 115 of file Razzle_module.cc.

int sbn::Razzle::recoPrimary
private

Definition at line 115 of file Razzle_module.cc.

TTree* sbn::Razzle::showerTree
private

Definition at line 112 of file Razzle_module.cc.

float sbn::Razzle::sqrtEnergyDensity
private

Definition at line 104 of file Razzle_module.cc.

float sbn::Razzle::startDist
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::startX
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::startY
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::startZ
private

Definition at line 121 of file Razzle_module.cc.

art::ServiceHandle<art::TFileService> sbn::Razzle::tfs
private

Definition at line 86 of file Razzle_module.cc.

int sbn::Razzle::trackHits
private

Definition at line 114 of file Razzle_module.cc.

float sbn::Razzle::trackLength
private

Definition at line 120 of file Razzle_module.cc.

float sbn::Razzle::trackScore
private

Definition at line 118 of file Razzle_module.cc.

float sbn::Razzle::trackWidth
private

Definition at line 120 of file Razzle_module.cc.

std::string sbn::Razzle::trueEndProcess
private

Definition at line 123 of file Razzle_module.cc.

float sbn::Razzle::trueEndX
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::trueEndY
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::trueEndZ
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::trueP
private

Definition at line 121 of file Razzle_module.cc.

int sbn::Razzle::truePdg
private

Definition at line 115 of file Razzle_module.cc.

float sbn::Razzle::trueStartX
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::trueStartY
private

Definition at line 121 of file Razzle_module.cc.

float sbn::Razzle::trueStartZ
private

Definition at line 121 of file Razzle_module.cc.

std::string sbn::Razzle::trueType
private

Definition at line 123 of file Razzle_module.cc.


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