All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
shower::LArPandoraShowerCheatingAlg Class Reference

#include <LArPandoraShowerCheatingAlg.h>

Public Member Functions

 LArPandoraShowerCheatingAlg (const fhicl::ParameterSet &pset)
 
std::map< int, const
simb::MCParticle * > 
GetTrueParticleMap () const
 
std::map< int, std::vector< int > > GetTrueChain (std::map< int, const simb::MCParticle * > &trueParticles) const
 
void CheatDebugEVD (detinfo::DetectorClocksData const &clockData, const simb::MCParticle *trueParticle, art::Event const &Event, reco::shower::ShowerElementHolder &ShowerEleHolder, const art::Ptr< recob::PFParticle > &pfparticle) const
 
int TrueParticleID (detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &hit) const
 
std::pair< int, double > TrueParticleIDFromTrueChain (detinfo::DetectorClocksData const &clockData, std::map< int, std::vector< int >> const &ShowersMothers, std::vector< art::Ptr< recob::Hit >> const &hits, int planeid) const
 

Private Attributes

shower::LArPandoraShowerAlg fLArPandoraShowerAlg
 
art::InputTag fHitModuleLabel
 
art::InputTag fPFParticleLabel
 
art::ServiceHandle
< cheat::ParticleInventoryService
particleInventory
 
art::ServiceHandle
< art::TFileService > 
tfs
 
std::string fShowerStartPositionInputLabel
 
std::string fShowerDirectionInputLabel
 
std::string fInitialTrackSpacePointsInputLabel
 

Detailed Description

Definition at line 33 of file LArPandoraShowerCheatingAlg.h.

Constructor & Destructor Documentation

shower::LArPandoraShowerCheatingAlg::LArPandoraShowerCheatingAlg ( const fhicl::ParameterSet &  pset)

Definition at line 17 of file LArPandoraShowerCheatingAlg.cxx.

18  : fLArPandoraShowerAlg(pset.get<fhicl::ParameterSet>("LArPandoraShowerAlg"))
19  , fHitModuleLabel(pset.get<art::InputTag>("HitModuleLabel"))
20  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
21  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
22  , fShowerDirectionInputLabel(pset.get<std::string>("ShowerDirectionInputLabel"))
23  , fInitialTrackSpacePointsInputLabel(pset.get<std::string>("InitialTrackSpacePointsInputLabel"))
24 {}
shower::LArPandoraShowerAlg fLArPandoraShowerAlg

Member Function Documentation

void shower::LArPandoraShowerCheatingAlg::CheatDebugEVD ( detinfo::DetectorClocksData const &  clockData,
const simb::MCParticle *  trueParticle,
art::Event const &  Event,
reco::shower::ShowerElementHolder ShowerEleHolder,
const art::Ptr< recob::PFParticle > &  pfparticle 
) const

Definition at line 76 of file LArPandoraShowerCheatingAlg.cxx.

82 {
83 
84  std::cout << "Making Debug Event Display" << std::endl;
85 
86  //Function for drawing reco showers to check direction and initial track selection
87 
88  // Get run info to make unique canvas names
89  int run = Event.run();
90  int subRun = Event.subRun();
91  int event = Event.event();
92  int PFPID = pfparticle->Self();
93 
94  // Create the canvas
95  TString canvasName = Form("canvas_%i_%i_%i_%i", run, subRun, event, PFPID);
96  TCanvas* canvas = tfs->make<TCanvas>(canvasName, canvasName);
97 
98  // Initialise variables
99  double x = 0;
100  double y = 0;
101  double z = 0;
102 
103  std::vector<art::Ptr<recob::SpacePoint>> showerSpacePoints;
104  std::vector<art::Ptr<recob::SpacePoint>> otherSpacePoints;
105 
106  auto const hitHandle = Event.getValidHandle<std::vector<recob::Hit>>(fHitModuleLabel);
107  std::vector<art::Ptr<recob::Hit>> hits;
108  art::fill_ptr_vector(hits, hitHandle);
109 
110  // Get the hits associated with the space points
111  const art::FindManyP<recob::SpacePoint> fmsph(hitHandle, Event, fPFParticleLabel);
112  if (!fmsph.isValid()) {
113  throw cet::exception("LArPandoraShowerCheatingAlg")
114  << "Spacepoint and hit association not valid. Stopping.";
115  }
116 
117  std::map<art::Ptr<recob::SpacePoint>, art::Ptr<recob::Hit>> spacePointHitMap;
118  //Get the hits from the true particle
119  for (auto hit : hits) {
120  int trueParticleID = std::abs(TrueParticleID(clockData, hit));
121  std::vector<art::Ptr<recob::SpacePoint>> sps = fmsph.at(hit.key());
122  if (sps.size() == 1) {
123  art::Ptr<recob::SpacePoint> sp = sps.front();
124  if (trueParticleID == trueParticle->TrackId()) { showerSpacePoints.push_back(sp); }
125  else {
126  otherSpacePoints.push_back(sp);
127  }
128  }
129  }
130 
131  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
132  mf::LogError("LArPandoraShowerCheatingAlg")
133  << "Start position not set, returning " << std::endl;
134  return;
135  }
136  if (!ShowerEleHolder.CheckElement(fShowerDirectionInputLabel)) {
137  mf::LogError("LArPandoraShowerCheatingAlg") << "Direction not set, returning " << std::endl;
138  return;
139  }
140  if (!ShowerEleHolder.CheckElement(fInitialTrackSpacePointsInputLabel)) {
141  mf::LogError("LArPandoraShowerCheatingAlg")
142  << "TrackSpacePoints not set, returning " << std::endl;
143  return;
144  }
145 
146  // Get info from shower property holder
147  TVector3 showerStartPosition = {-999, -999, -999};
148  TVector3 showerDirection = {-999, -999, -999};
149  std::vector<art::Ptr<recob::SpacePoint>> trackSpacePoints;
150 
151  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, showerStartPosition);
152  ShowerEleHolder.GetElement(fShowerDirectionInputLabel, showerDirection);
153  ShowerEleHolder.GetElement(fInitialTrackSpacePointsInputLabel, trackSpacePoints);
154 
155  // Create 3D point at vertex, chosed to be origin for ease of use of display
156  double startXYZ[3] = {0, 0, 0};
157  auto startPoly = std::make_unique<TPolyMarker3D>(1, startXYZ);
158 
159  // Get the min and max projections along the direction to know how long to draw
160  // the direction line
161  double minProj = std::numeric_limits<double>::max();
162  double maxProj = -std::numeric_limits<double>::max();
163 
164  double x_min = std::numeric_limits<double>::max(), x_max = -std::numeric_limits<double>::max();
165  double y_min = std::numeric_limits<double>::max(), y_max = -std::numeric_limits<double>::max();
166  double z_min = std::numeric_limits<double>::max(), z_max = -std::numeric_limits<double>::max();
167 
168  //initialise counter point
169  int point = 0;
170 
171  // Make 3D points for each spacepoint in the shower
172  auto showerPoly = std::make_unique<TPolyMarker3D>(showerSpacePoints.size());
173  for (auto spacePoint : showerSpacePoints) {
174  TVector3 pos = fLArPandoraShowerAlg.SpacePointPosition(spacePoint) - showerStartPosition;
175 
176  x = pos.X();
177  y = pos.Y();
178  z = pos.Z();
179  x_min = std::min(x, x_min);
180  x_max = std::max(x, x_max);
181  y_min = std::min(y, y_min);
182  y_max = std::max(y, y_max);
183  z_min = std::min(z, z_min);
184  z_max = std::max(z, z_max);
185 
186  showerPoly->SetPoint(point, x, y, z);
187  ++point;
188 
189  // Calculate the projection of (point-startpoint) along the direction
190  double proj =
191  fLArPandoraShowerAlg.SpacePointProjection(spacePoint, showerStartPosition, showerDirection);
192 
193  maxProj = std::max(proj, maxProj);
194  minProj = std::min(proj, minProj);
195  } // loop over spacepoints
196 
197  // Create TPolyLine3D arrays
198  double xDirPoints[2] = {minProj * showerDirection.X(), maxProj * showerDirection.X()};
199  double yDirPoints[2] = {minProj * showerDirection.Y(), maxProj * showerDirection.Y()};
200  double zDirPoints[2] = {minProj * showerDirection.Z(), maxProj * showerDirection.Z()};
201 
202  auto dirPoly = std::make_unique<TPolyLine3D>(2, xDirPoints, yDirPoints, zDirPoints);
203 
204  point = 0; // re-initialise counter
205  auto trackPoly = std::make_unique<TPolyMarker3D>(trackSpacePoints.size());
206  for (auto spacePoint : trackSpacePoints) {
207  TVector3 pos = fLArPandoraShowerAlg.SpacePointPosition(spacePoint) - showerStartPosition;
208  x = pos.X();
209  y = pos.Y();
210  z = pos.Z();
211  trackPoly->SetPoint(point, x, y, z);
212  ++point;
213  } // loop over track spacepoints
214 
215  // we want to draw all of the PFParticles in the event
216  //Get the PFParticles
217 
218  auto otherPoly = std::make_unique<TPolyMarker3D>(otherSpacePoints.size());
219 
220  // initialise counters
221  point = 0; // re-initialise counter
222 
223  for (auto const& sp : otherSpacePoints) {
224  TVector3 pos = fLArPandoraShowerAlg.SpacePointPosition(sp) - showerStartPosition;
225  x = pos.X();
226  y = pos.Y();
227  z = pos.Z();
228  x_min = std::min(x, x_min);
229  x_max = std::max(x, x_max);
230  y_min = std::min(y, y_min);
231  y_max = std::max(y, y_max);
232  z_min = std::min(z, z_min);
233  z_max = std::max(z, z_max);
234  otherPoly->SetPoint(point, x, y, z);
235  ++point;
236  }
237 
238  gStyle->SetOptStat(0);
239  TH3F axes("axes", "", 1, x_min, x_max, 1, y_min, y_max, 1, z_min, z_max);
240  axes.SetDirectory(0);
241  axes.GetXaxis()->SetTitle("X");
242  axes.GetYaxis()->SetTitle("Y");
243  axes.GetZaxis()->SetTitle("Z");
244  axes.Draw();
245 
246  otherPoly->SetMarkerStyle(20);
247  otherPoly->SetMarkerColor(4);
248  otherPoly->Draw();
249 
250  // Draw all of the things
251  showerPoly->SetMarkerStyle(20);
252  showerPoly->Draw();
253  trackPoly->SetMarkerStyle(20);
254  trackPoly->SetMarkerColor(2);
255  trackPoly->Draw();
256  startPoly->SetMarkerStyle(21);
257  startPoly->SetMarkerSize(2);
258  startPoly->SetMarkerColor(3);
259  startPoly->Draw();
260  dirPoly->SetLineWidth(1);
261  dirPoly->SetLineColor(6);
262  dirPoly->Draw();
263 
264  // Save the canvas. Don't usually need this when using TFileService but this in the alg
265  // not a module and didn't work without this so im going with it.
266  canvas->Write();
267 }
process_name opflash particleana ie ie ie z
shower::LArPandoraShowerAlg fLArPandoraShowerAlg
process_name opflash particleana ie x
process_name hit
Definition: cheaterreco.fcl:51
T abs(T value)
process_name opflash particleana ie ie y
bool CheckElement(const std::string &Name) const
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
int GetElement(const std::string &Name, T &Element) const
int TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &hit) const
art::ServiceHandle< art::TFileService > tfs
BEGIN_PROLOG could also be cout
TVector3 SpacePointPosition(art::Ptr< recob::SpacePoint > const &sp) const
std::map< int, std::vector< int > > shower::LArPandoraShowerCheatingAlg::GetTrueChain ( std::map< int, const simb::MCParticle * > &  trueParticles) const

Definition at line 45 of file LArPandoraShowerCheatingAlg.cxx.

47 {
48 
49  // Roll up showers if not already done:
50  std::map<int, std::vector<int>> showerMothers;
51 
52  // Loop over daughters and find th`e mothers
53  for (const auto& particleIt : trueParticles) {
54  const simb::MCParticle* particle = particleIt.second;
55  const simb::MCParticle* mother = particle;
56 
57  if (std::abs(particle->PdgCode()) != 11 && std::abs(particle->PdgCode()) != 22) { continue; }
58 
59  // While the grand mother exists and is an electron or photon
60  // Note the true mother will skip this loop and fill itself into the map
61  while (mother->Mother() != 0 && trueParticles.find(mother->Mother()) != trueParticles.end()) {
62 
63  int motherId = mother->Mother();
64  if (std::abs(trueParticles[motherId]->PdgCode()) != 11 &&
65  std::abs(trueParticles[motherId]->PdgCode()) != 22) {
66  break;
67  }
68  mother = trueParticles[motherId];
69  }
70  showerMothers[mother->TrackId()].push_back(particle->TrackId());
71  }
72  return showerMothers;
73 }
T abs(T value)
std::map< int, const simb::MCParticle * > shower::LArPandoraShowerCheatingAlg::GetTrueParticleMap ( ) const

Definition at line 27 of file LArPandoraShowerCheatingAlg.cxx.

28 {
29 
30  const sim::ParticleList& particles = particleInventory->ParticleList();
31 
32  std::map<int, const simb::MCParticle*> trueParticles;
33  // Make a map of track id to particle
34  for (sim::ParticleList::const_iterator particleIt = particles.begin();
35  particleIt != particles.end();
36  ++particleIt) {
37  const simb::MCParticle* particle = particleIt->second;
38  trueParticles[particle->TrackId()] = particle;
39  //std::cout<<"Particle ID: "<<particle->TrackId()<<" and PDG: "<<particle->PdgCode()<<std::endl;
40  }
41  return trueParticles;
42 }
art::ServiceHandle< cheat::ParticleInventoryService > particleInventory
int shower::LArPandoraShowerCheatingAlg::TrueParticleID ( detinfo::DetectorClocksData const &  clockData,
const art::Ptr< recob::Hit > &  hit 
) const

Definition at line 270 of file LArPandoraShowerCheatingAlg.cxx.

272 {
273 
274  double particleEnergy = 0;
275  int likelyTrackID = 0;
276  art::ServiceHandle<cheat::BackTrackerService> bt_serv;
277  std::vector<sim::TrackIDE> trackIDs = bt_serv->HitToTrackIDEs(clockData, hit);
278  for (unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
279  if (trackIDs.at(idIt).energy > particleEnergy) {
280  particleEnergy = trackIDs.at(idIt).energy;
281  likelyTrackID = trackIDs.at(idIt).trackID;
282  }
283  }
284  return likelyTrackID;
285 }
process_name hit
Definition: cheaterreco.fcl:51
std::pair< int, double > shower::LArPandoraShowerCheatingAlg::TrueParticleIDFromTrueChain ( detinfo::DetectorClocksData const &  clockData,
std::map< int, std::vector< int >> const &  ShowersMothers,
std::vector< art::Ptr< recob::Hit >> const &  hits,
int  planeid 
) const

Definition at line 288 of file LArPandoraShowerCheatingAlg.cxx.

293 {
294 
295  art::ServiceHandle<cheat::BackTrackerService> bt_serv;
296  art::ServiceHandle<cheat::ParticleInventoryService> particleInventory;
297 
298  //Find the energy for each track ID.
299  std::map<int, double> trackIDToEDepMap;
300  std::map<int, double> trackIDTo3EDepMap;
301  for (std::vector<art::Ptr<recob::Hit>>::const_iterator hitIt = hits.begin(); hitIt != hits.end();
302  ++hitIt) {
303  art::Ptr<recob::Hit> hit = *hitIt;
304 
305  //Get the plane ID
306  geo::WireID wireid = (*hitIt)->WireID();
307  int PlaneID = wireid.Plane;
308  std::vector<sim::TrackIDE> trackIDs = bt_serv->HitToTrackIDEs(clockData, hit);
309  for (unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
310  trackIDTo3EDepMap[std::abs(trackIDs[idIt].trackID)] += trackIDs[idIt].energy;
311  if (PlaneID == planeid) {
312  trackIDToEDepMap[std::abs(trackIDs[idIt].trackID)] += trackIDs[idIt].energy;
313  }
314  }
315  }
316 
317  //Find the energy for each showermother.
318  std::map<int, double> MotherIDtoEMap;
319  std::map<int, double> MotherIDto3EMap;
320  for (std::map<int, std::vector<int>>::const_iterator showermother = ShowersMothers.begin();
321  showermother != ShowersMothers.end();
322  ++showermother) {
323  for (std::vector<int>::const_iterator daughter = (showermother->second).begin();
324  daughter != (showermother->second).end();
325  ++daughter) {
326  MotherIDtoEMap[showermother->first] += trackIDToEDepMap[*daughter];
327  MotherIDto3EMap[showermother->first] += trackIDTo3EDepMap[*daughter];
328  }
329  }
330 
331  //Loop over the mothers to find the most like candidate by identifying which true shower deposited the most energy in the hits.
332  double maxenergy = -1;
333  int objectTrack = -99999;
334  for (std::map<int, double>::iterator mapIt = MotherIDto3EMap.begin();
335  mapIt != MotherIDto3EMap.end();
336  mapIt++) {
337  double energy_three = mapIt->second;
338  double trackid = mapIt->first;
339  if (energy_three > maxenergy) {
340  maxenergy = energy_three;
341  objectTrack = trackid;
342  }
343  }
344 
345  //If the none of the shower mother deposited no energy then we cannot match this.
346  if (maxenergy == 0) { return std::make_pair(-99999, -99999); }
347 
348  return std::make_pair(objectTrack, MotherIDtoEMap[objectTrack]);
349 }
process_name hit
Definition: cheaterreco.fcl:51
IDparameter< geo::PlaneID > PlaneID
Member type of validated geo::PlaneID parameter.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
T abs(T value)
art::ServiceHandle< cheat::ParticleInventoryService > particleInventory
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
constexpr WireID()=default
Default constructor: an invalid TPC ID.

Member Data Documentation

art::InputTag shower::LArPandoraShowerCheatingAlg::fHitModuleLabel
private

Definition at line 58 of file LArPandoraShowerCheatingAlg.h.

std::string shower::LArPandoraShowerCheatingAlg::fInitialTrackSpacePointsInputLabel
private

Definition at line 65 of file LArPandoraShowerCheatingAlg.h.

shower::LArPandoraShowerAlg shower::LArPandoraShowerCheatingAlg::fLArPandoraShowerAlg
private

Definition at line 56 of file LArPandoraShowerCheatingAlg.h.

art::InputTag shower::LArPandoraShowerCheatingAlg::fPFParticleLabel
private

Definition at line 59 of file LArPandoraShowerCheatingAlg.h.

std::string shower::LArPandoraShowerCheatingAlg::fShowerDirectionInputLabel
private

Definition at line 64 of file LArPandoraShowerCheatingAlg.h.

std::string shower::LArPandoraShowerCheatingAlg::fShowerStartPositionInputLabel
private

Definition at line 63 of file LArPandoraShowerCheatingAlg.h.

art::ServiceHandle<cheat::ParticleInventoryService> shower::LArPandoraShowerCheatingAlg::particleInventory
private

Definition at line 60 of file LArPandoraShowerCheatingAlg.h.

art::ServiceHandle<art::TFileService> shower::LArPandoraShowerCheatingAlg::tfs
private

Definition at line 61 of file LArPandoraShowerCheatingAlg.h.


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