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

#include <CRTBackTracker.h>

Classes

struct  Config
 

Public Types

using CRTData = icarus::crt::CRTData
 
using CRTHit = sbn::crt::CRTHit
 
using CRTTrack = sbn::crt::CRTTrack
 

Public Member Functions

 CRTBackTracker (const Config &config)
 
 CRTBackTracker (const fhicl::ParameterSet &pset)
 
 ~CRTBackTracker ()
 
void reconfigure (const Config &config)
 
void Initialize (const art::Event &event)
 
bool DataCompare (const CRTData &data1, const CRTData &data2)
 
bool HitCompare (const CRTHit &hit1, const CRTHit &hit2)
 
bool TrackCompare (const CRTTrack &track1, const CRTTrack &track2)
 
std::vector< int > AllTrueIds (const art::Event &event, const CRTData &data)
 
std::vector< int > AllTrueIds (const art::Event &event, const CRTHit &hit)
 
std::vector< int > AllTrueIds (const art::Event &event, const CRTTrack &track)
 
int TrueIdFromTotalEnergy (const art::Event &event, const CRTData &data)
 
int TrueIdFromDataId (const art::Event &event, int data_i)
 
int TrueIdFromTotalEnergy (const art::Event &event, const CRTHit &hit)
 
int TrueIdFromHitId (const art::Event &event, int hit_i)
 
int TrueIdFromTotalEnergy (const art::Event &event, const CRTTrack &track)
 
int TrueIdFromTrackId (const art::Event &event, int track_i)
 

Private Attributes

art::InputTag fCRTTrueHitLabel
 
art::InputTag fCRTDataLabel
 
art::InputTag fCRTSimHitLabel
 
art::InputTag fCRTTrackLabel
 
bool fRollupUnsavedIds
 
std::map< int, std::map< int,
double > > 
fTrueHitTrueIds
 
std::map< int, std::map< int,
double > > 
fDataTrueIds
 
std::map< int, std::map< int,
double > > 
fSimHitTrueIds
 
std::map< int, std::map< int,
double > > 
fTrackTrueIds
 

Detailed Description

Definition at line 43 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.h.

Member Typedef Documentation

Constructor & Destructor Documentation

icarus::crt::CRTBackTracker::CRTBackTracker ( const Config config)

Definition at line 6 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

6  {
7  this->reconfigure(config);
8  }
icarus::crt::CRTBackTracker::CRTBackTracker ( const fhicl::ParameterSet &  pset)
inline

Definition at line 75 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.h.

75  :
76  CRTBackTracker(fhicl::Table<Config>(pset, {})()) {}
icarus::crt::CRTBackTracker::~CRTBackTracker ( )

Definition at line 11 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

11 {}

Member Function Documentation

std::vector< int > icarus::crt::CRTBackTracker::AllTrueIds ( const art::Event &  event,
const CRTData data 
)

Definition at line 208 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

208  {
209 
210  std::vector<int> ids;
211 
212  // Get a handle to the CRT data in the event
213  auto crtDataHandle = event.getValidHandle<std::vector<CRTData>>(fCRTDataLabel);
214  art::FindManyP<sim::AuxDetIDE> findManyIdes(crtDataHandle, event, fCRTDataLabel);
215 
216  // Find which one matches the data passed to the function
217  int data_i = 0, index = 0;
218 
219  int nmatch=0;
220  for(auto const& crtData : (*crtDataHandle)){
221 
222  if(DataCompare(crtData, data)) {
223  data_i = index;
224  nmatch++;
225  }
226 
227  index++;
228  }
229  if(nmatch==0)
230  mf::LogError("CRTBackTracker::AllTrueIds") << "no matches for provided CRTData product found!";
231  if(nmatch>1)
232  mf::LogError("CRTBackTracker::AllTrueIds") << "multiple matches for given CRTData product found!";
233 
234  // Get all the true IDs from all the IDEs in the hit
235  std::vector<art::Ptr<sim::AuxDetIDE>> ides = findManyIdes.at(data_i);
236 
237  for(size_t i = 0; i < ides.size(); i++){
238 
239  int id = ides[i]->trackID;
240 
241  if(fRollupUnsavedIds) id = std::abs(id);
242 
243  ids.push_back(id);
244  }
245 
246  // Remove any repeated IDs
247  std::sort(ids.begin(), ids.end());
248  ids.erase(std::unique(ids.begin(), ids.end()), ids.end());
249 
250  return ids;
251  }
bool DataCompare(const CRTData &data1, const CRTData &data2)
T abs(T value)
std::vector< int > icarus::crt::CRTBackTracker::AllTrueIds ( const art::Event &  event,
const CRTHit hit 
)

Definition at line 255 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

255  {
256 
257  std::vector<int> ids;
258 
259  // Get a handle to the CRT hits in the event
260  art::Handle< std::vector<CRTHit> > crtSimHitHandle;
261  art::Handle< std::vector<CRTHit> > crtTrueHitHandle;
262 
263  // Find which one matches the hit passed to the function
264  int hit_i = -1, tmp_hit_i = -1, index = 0;
265  bool sim=false, findsim=false, findtrue=false;
266 
267  //try to get a handle to CRTSimHits
268  if(event.getByLabel(fCRTSimHitLabel,crtSimHitHandle)) {
269  findsim = true;
270  //find vector index matching the passed CRTHit
271  for(auto const& crtHit : (*crtSimHitHandle)){
272 
273  if(HitCompare(crtHit, hit)) tmp_hit_i = index;
274  index++;
275  }
276 
277  if(tmp_hit_i!=-1) {
278  hit_i = tmp_hit_i;
279  tmp_hit_i=-1;
280  sim=true;
281  }
282  }
283 
284  //try to get handle to CRTTrueHits
285  if(event.getByLabel(fCRTTrueHitLabel,crtTrueHitHandle)) {
286  findtrue = true;
287  index=0;
288  //find vector index matching the passed CRTHit
289  for(auto const& crtHit : (*crtTrueHitHandle)){
290 
291  if(HitCompare(crtHit, hit)) tmp_hit_i = index;
292  index++;
293  }
294  if(tmp_hit_i!=-1){
295  if(hit_i!=-1) {
296  mf::LogError("CRTBackTracker::AllTrueIds") << "True/Sim CRTHit ID ambiguity!";
297  return ids;
298  }
299  hit_i=tmp_hit_i;
300  }
301  }
302  if(hit_i==-1) {
303  mf::LogError("CRTBackTracker::AllTrueIds") << "no match for passed CRTHit found!";
304  return ids;
305  }
306  if(!findsim && !findtrue) {
307  mf::LogError("CRTBackTracker::AllTrueIds") << "no handle to CRTHits could be found!";
308  return ids;
309  }
310 
311  // Get the crt data associated to that hit and the IDEs associate to the data
312  std::vector<art::Ptr<sim::AuxDetIDE>> ides;
313 
314  // Get all the true IDs from all the IDEs in the hit
315  if(sim) {
316  art::FindManyP<CRTData> findManyData(crtSimHitHandle, event, fCRTSimHitLabel);
317  std::vector<art::Ptr<CRTData>> data;
318  data = findManyData.at(hit_i);
319  art::FindManyP<sim::AuxDetIDE> findManySimIdes(data, event, fCRTDataLabel);
320  for(size_t i = 0; i < data.size(); i++){
321 
322  ides = findManySimIdes.at(i);
323  for(size_t j = 0; j < ides.size(); j++){
324 
325  int id = ides[j]->trackID;
326  if(fRollupUnsavedIds) id = std::abs(id);
327  ids.push_back(id);
328  }
329  }
330  }//if sim
331  else {
332  art::FindManyP<sim::AuxDetIDE> findManyTrueIdes(crtTrueHitHandle, event, fCRTTrueHitLabel);
333  ides = findManyTrueIdes.at(hit_i);
334  for(auto const& ide : ides) {
335  int id = ide->trackID;
336  if(fRollupUnsavedIds) id = std::abs(id);
337  ids.push_back(id);
338  }
339  }//else true
340 
341  // Remove any repeated IDs
342  std::sort(ids.begin(), ids.end());
343  ids.erase(std::unique(ids.begin(), ids.end()), ids.end());
344 
345  return ids;
346  }
bool HitCompare(const CRTHit &hit1, const CRTHit &hit2)
process_name hit
Definition: cheaterreco.fcl:51
T abs(T value)
std::vector< int > icarus::crt::CRTBackTracker::AllTrueIds ( const art::Event &  event,
const CRTTrack track 
)

Definition at line 350 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

350  {
351 
352  std::vector<int> ids;
353  // Get a handle to the CRT tracks in the event
354  auto crtTrackHandle = event.getValidHandle<std::vector<CRTTrack>>(fCRTTrackLabel);
355  art::FindManyP<CRTHit> findManyHits(crtTrackHandle, event, fCRTTrackLabel);
356  // Find which one matches the track passed to the function
357  int track_i = 0, index = 0;
358 
359  for(auto const& crtTrack : (*crtTrackHandle)){
360 
361  if(TrackCompare(crtTrack, track)) track_i = index;
362  index++;
363  }
364 
365  // Get the crt hits associated to that hit and the data associate to the hits
366  std::vector<art::Ptr<CRTHit>> hits = findManyHits.at(track_i);
367  art::FindManyP<CRTData> findManyData(hits, event, fCRTSimHitLabel);
368 
369  // Get all the true IDs from all the IDEs in the track
370  for(size_t i = 0; i < hits.size(); i++){
371 
372  std::vector<art::Ptr<CRTData>> data = findManyData.at(i);
373  art::FindManyP<sim::AuxDetIDE> findManyIdes(data, event, fCRTDataLabel);
374  for(size_t j = 0; j < data.size(); j++){
375 
376  std::vector<art::Ptr<sim::AuxDetIDE>> ides = findManyIdes.at(j);
377  for(size_t k = 0; k < ides.size(); k++){
378 
379  int id = ides[k]->trackID;
380  if(fRollupUnsavedIds) id = std::abs(id);
381  ids.push_back(id);
382 
383  }
384  }
385  }
386 
387  // Remove any repeated IDs
388  std::sort(ids.begin(), ids.end());
389  ids.erase(std::unique(ids.begin(), ids.end()), ids.end());
390 
391  return ids;
392  }
process_name use argoneut_mc_hitfinder track
T abs(T value)
bool TrackCompare(const CRTTrack &track1, const CRTTrack &track2)
pdgs k
Definition: selectors.fcl:22
bool icarus::crt::CRTBackTracker::DataCompare ( const CRTData data1,
const CRTData data2 
)

Definition at line 153 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

153  {
154 
155  if(data1.fMac5 != data2.fMac5) return false;
156  if(data1.fTs0 != data2.fTs0) return false;
157  if(data1.fTs1 != data2.fTs1) return false;
158  if(data1.fEntry != data2.fEntry) return false;
159  for(int ch=0; ch<64; ch++) {
160  if(data1.fAdc[ch] != data2.fAdc[ch]) return false;
161  }
162 
163  return true;
164  }
bool icarus::crt::CRTBackTracker::HitCompare ( const CRTHit hit1,
const CRTHit hit2 
)

Definition at line 168 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

168  {
169 
170  if(hit1.ts1_ns != hit2.ts1_ns) return false;
171  if(hit1.plane != hit2.plane) return false;
172  if(hit1.x_pos != hit2.x_pos) return false;
173  if(hit1.y_pos != hit2.y_pos) return false;
174  if(hit1.z_pos != hit2.z_pos) return false;
175  if(hit1.x_err != hit2.x_err) return false;
176  if(hit1.y_err != hit2.y_err) return false;
177  if(hit1.z_err != hit2.z_err) return false;
178  if(hit1.tagger != hit2.tagger) return false;
179 
180  return true;
181  }
void icarus::crt::CRTBackTracker::Initialize ( const art::Event &  event)

Definition at line 26 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

26  {
27 
28  bool findData = false, findSimHit = false;
29 
30  // Clear those data structures!
31  fTrueHitTrueIds.clear();
32  fDataTrueIds.clear();
33  fSimHitTrueIds.clear();
34  fTrackTrueIds.clear();
35 
36  //CRTTrueHit
37  art::Handle< std::vector<CRTHit>> crtTrueHitHandle;
38  std::vector<art::Ptr<CRTHit> > crtTrueHitList;
39  if (event.getByLabel(fCRTTrueHitLabel, crtTrueHitHandle)){
40  art::fill_ptr_vector(crtTrueHitList, crtTrueHitHandle);
41 
42  art::FindManyP<sim::AuxDetIDE> findManyIdes(crtTrueHitHandle, event, fCRTTrueHitLabel);
43  std::map<art::Ptr<CRTHit>, int> trueHitPtrMap;
44 
45  for(size_t hit_i = 0; hit_i < crtTrueHitList.size(); hit_i++){
46 
47  trueHitPtrMap[crtTrueHitList[hit_i]] = hit_i;
48  std::vector<art::Ptr<sim::AuxDetIDE>> ides = findManyIdes.at(hit_i);
49 
50  for(size_t i = 0; i < ides.size(); i++){
51 
52  int id = ides[i]->trackID;
53  if(fRollupUnsavedIds) id = std::abs(id);
54  fTrueHitTrueIds[hit_i][id] += ides[i]->energyDeposited;
55  }
56  }
57  }//if CRTTrueHit found
58  else
59  mf::LogWarning("CRTBackTracker") << "no CRTTrueHit products found";
60 
61  //CRTData
62  art::Handle< std::vector<CRTData>> crtDataHandle;
63  std::vector<art::Ptr<CRTData> > crtDataList;
64  std::map<art::Ptr<CRTData>, int> dataPtrMap;
65 
66  if (event.getByLabel(fCRTDataLabel, crtDataHandle)) {
67  art::fill_ptr_vector(crtDataList, crtDataHandle);
68  art::FindManyP<sim::AuxDetIDE> findManyIdes(crtDataHandle, event, fCRTDataLabel);
69 
70  for(size_t data_i = 0; data_i < crtDataList.size(); data_i++){
71 
72  dataPtrMap[crtDataList[data_i]] = data_i;
73  // Get all the true IDs from all the IDEs in the hit
74  std::vector<art::Ptr<sim::AuxDetIDE>> ides = findManyIdes.at(data_i);
75 
76  for(size_t i = 0; i < ides.size(); i++){
77 
78  int id = ides[i]->trackID;
79  if(fRollupUnsavedIds) id = std::abs(id);
80  fDataTrueIds[data_i][id] += ides[i]->energyDeposited;
81  }
82  }
83  findData = true;
84  }//if CRTData found
85  else
86  mf::LogWarning("CRTBackTracker") << "no CRTData products found";
87 
88  //CRTSimHit
89  art::Handle< std::vector<CRTHit>> crtSimHitHandle;
90  std::vector<art::Ptr<CRTHit> > crtSimHitList;
91  std::map<art::Ptr<CRTHit>, int> simHitPtrMap;
92  if (event.getByLabel(fCRTSimHitLabel, crtSimHitHandle)){
93 
94  if(!findData)
95  mf::LogError("CRTBackTracker")
96  << "no CRTData products found when some were expected (CRTSimHits found)";
97 
98  art::fill_ptr_vector(crtSimHitList, crtSimHitHandle);
99  art::FindManyP<CRTData> findManyData(crtSimHitHandle, event, fCRTSimHitLabel);
100 
101  for(size_t hit_i = 0; hit_i < crtSimHitList.size(); hit_i++){
102 
103  simHitPtrMap[crtSimHitList[hit_i]] = hit_i;
104  std::vector<art::Ptr<CRTData>> data = findManyData.at(hit_i);
105 
106  for(size_t data_i = 0; data_i < data.size(); data_i++){
107 
108  int dataID = dataPtrMap[data[data_i]];
109 
110  for(auto const& di : fDataTrueIds[dataID]){
111  fSimHitTrueIds[hit_i][di.first] += di.second;
112  }
113  }
114  }
115  findSimHit = true;
116  }//if CRTSimHit found
117  else
118  mf::LogWarning("CRTBackTracker") << "no CRTSimHit products found";
119 
120  //CRTTracks
121  art::Handle< std::vector<CRTTrack>> crtTrackHandle;
122  std::vector<art::Ptr<CRTTrack> > crtTrackList;
123 
124  if (event.getByLabel(fCRTTrackLabel, crtTrackHandle)) {
125 
126  if(!findSimHit)
127  mf::LogError("CRTBackTracker")
128  << "no CRTSimHit products found when some were expected (CRTTracks found)";
129 
130  art::fill_ptr_vector(crtTrackList, crtTrackHandle);
131  art::FindManyP<CRTHit> findManyHits(crtTrackHandle, event, fCRTTrackLabel);
132 
133  for(size_t track_i = 0; track_i < crtTrackList.size(); track_i++){
134 
135  std::vector<art::Ptr<CRTHit>> hits = findManyHits.at(track_i);
136  for(size_t hit_i = 0; hit_i < hits.size(); hit_i++){
137 
138  int hitID = simHitPtrMap[hits[hit_i]];
139  for(auto const& hi : fSimHitTrueIds[hitID]){
140 
141  fTrackTrueIds[track_i][hi.first] += hi.second;
142  }
143  }
144  }
145  }//if CRTrack product found
146  else
147  mf::LogWarning("CRTBackTracker") << "no CRTTrack products found";
148 
149  }//Initialize
std::map< int, std::map< int, double > > fTrueHitTrueIds
std::map< int, std::map< int, double > > fDataTrueIds
std::map< int, std::map< int, double > > fTrackTrueIds
T abs(T value)
std::map< int, std::map< int, double > > fSimHitTrueIds
void icarus::crt::CRTBackTracker::reconfigure ( const Config config)

Definition at line 14 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

14  {
15 
16  fCRTTrueHitLabel = config.CRTTrueHitLabel();
17  fCRTDataLabel = config.CRTDataLabel();
18  fCRTSimHitLabel = config.CRTSimHitLabel();
19  fCRTTrackLabel = config.CRTTrackLabel();
20  fRollupUnsavedIds = config.RollupUnsavedIds();
21 
22  return;
23  }
bool icarus::crt::CRTBackTracker::TrackCompare ( const CRTTrack track1,
const CRTTrack track2 
)

Definition at line 185 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

185  {
186 
187  if(track1.ts1_ns != track2.ts1_ns) return false;
188  if(track1.plane1 != track2.plane1) return false;
189  if(track1.x1_pos != track2.x1_pos) return false;
190  if(track1.y1_pos != track2.y1_pos) return false;
191  if(track1.z1_pos != track2.z1_pos) return false;
192  if(track1.x1_err != track2.x1_err) return false;
193  if(track1.y1_err != track2.y1_err) return false;
194  if(track1.z1_err != track2.z1_err) return false;
195  if(track1.plane2 != track2.plane2) return false;
196  if(track1.x2_pos != track2.x2_pos) return false;
197  if(track1.y2_pos != track2.y2_pos) return false;
198  if(track1.z2_pos != track2.z2_pos) return false;
199  if(track1.x2_err != track2.x2_err) return false;
200  if(track1.y2_err != track2.y2_err) return false;
201  if(track1.z2_err != track2.z2_err) return false;
202 
203  return true;
204  }
int icarus::crt::CRTBackTracker::TrueIdFromDataId ( const art::Event &  event,
int  data_i 
)

Definition at line 440 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

440  {
441 
442  if(fDataTrueIds.find(data_i) != fDataTrueIds.end()){
443 
444  double maxEnergy = -1;
445  int trueId = -99999;
446 
447  for(auto &id : fDataTrueIds[data_i]){
448 
449  if(id.second > maxEnergy){
450 
451  maxEnergy = id.second;
452  trueId = id.first;
453  }
454  }
455 
456  return trueId;
457  }
458 
459  return -99999;
460  }
std::map< int, std::map< int, double > > fDataTrueIds
int icarus::crt::CRTBackTracker::TrueIdFromHitId ( const art::Event &  event,
int  hit_i 
)

Definition at line 517 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

517  {
518 
519  if(fSimHitTrueIds.find(hit_i) != fSimHitTrueIds.end()){
520 
521  double maxEnergy = -1;
522  int trueId = -99999;
523 
524  for(auto &id : fSimHitTrueIds[hit_i]){
525 
526  if(id.second > maxEnergy){
527 
528  maxEnergy = id.second;
529  trueId = id.first;
530  }
531  }
532 
533  return trueId;
534 
535  }
536 
537  return -99999;
538 
539  }
std::map< int, std::map< int, double > > fSimHitTrueIds
int icarus::crt::CRTBackTracker::TrueIdFromTotalEnergy ( const art::Event &  event,
const CRTData data 
)

Definition at line 396 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

396  {
397 
398  std::map<int, double> ids;
399 
400  // Get a handle to the CRT data in the event
401  auto crtDataHandle = event.getValidHandle<std::vector<CRTData>>(fCRTDataLabel);
402  art::FindManyP<sim::AuxDetIDE> findManyIdes(crtDataHandle, event, fCRTDataLabel);
403 
404  // Find which one matches the data passed to the function
405  int data_i = 0, index = 0;
406 
407  for(auto const& crtData : (*crtDataHandle)){
408 
409  if(DataCompare(crtData, data)) data_i = index;
410  index++;
411  }
412 
413  // Get all the true IDs from all the IDEs in the hit
414  std::vector<art::Ptr<sim::AuxDetIDE>> ides = findManyIdes.at(data_i);
415 
416  for(size_t i = 0; i < ides.size(); i++){
417 
418  int id = ides[i]->trackID;
419  if(fRollupUnsavedIds) id = std::abs(id);
420  ids[id] += ides[i]->energyDeposited;
421  }
422 
423  // Find the true ID that contributed the most energy
424  double maxEnergy = -1;
425  int trueId = -99999;
426 
427  for(auto &id : ids){
428 
429  if(id.second > maxEnergy){
430 
431  maxEnergy = id.second;
432  trueId = id.first;
433  }
434  }
435 
436  return trueId;
437  }
bool DataCompare(const CRTData &data1, const CRTData &data2)
T abs(T value)
int icarus::crt::CRTBackTracker::TrueIdFromTotalEnergy ( const art::Event &  event,
const CRTHit hit 
)

Definition at line 464 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

464  {
465 
466  std::map<int, double> ids;
467 
468  // Get a handle to the CRT hits in the event
469  auto crtHitHandle = event.getValidHandle<std::vector<CRTHit>>(fCRTSimHitLabel);
470  art::FindManyP<CRTData> findManyData(crtHitHandle, event, fCRTSimHitLabel);
471 
472  // Find which one matches the hit passed to the function
473  int hit_i = 0, index = 0;
474 
475  for(auto const& crtHit : (*crtHitHandle)){
476 
477  if(HitCompare(crtHit, hit)) hit_i = index;
478  index++;
479  }
480 
481  // Get the crt data associated to that hit and the IDEs associate to the data
482  std::vector<art::Ptr<CRTData>> data = findManyData.at(hit_i);
483  art::FindManyP<sim::AuxDetIDE> findManyIdes(data, event, fCRTDataLabel);
484 
485  // Get all the true IDs from all the IDEs in the hit
486  for(size_t i = 0; i < data.size(); i++){
487 
488  std::vector<art::Ptr<sim::AuxDetIDE>> ides = findManyIdes.at(i);
489 
490  for(size_t j = 0; j < ides.size(); j++){
491 
492  int id = ides[j]->trackID;
493  if(fRollupUnsavedIds) id = std::abs(id);
494  ids[id] += ides[j]->energyDeposited;
495  }
496  }
497 
498  // Find the true ID that contributed the most energy
499  double maxEnergy = -1;
500  int trueId = -99999;
501 
502  for(auto &id : ids){
503 
504  if(id.second > maxEnergy){
505 
506  maxEnergy = id.second;
507  trueId = id.first;
508 
509  }
510  }
511 
512  return trueId;
513 
514  }
bool HitCompare(const CRTHit &hit1, const CRTHit &hit2)
process_name hit
Definition: cheaterreco.fcl:51
T abs(T value)
int icarus::crt::CRTBackTracker::TrueIdFromTotalEnergy ( const art::Event &  event,
const CRTTrack track 
)

Definition at line 543 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

543  {
544 
545  std::map<int, double> ids;
546 
547  // Get a handle to the CRT tracks in the event
548  auto crtTrackHandle = event.getValidHandle<std::vector<CRTTrack>>(fCRTTrackLabel);
549  art::FindManyP<CRTHit> findManyHits(crtTrackHandle, event, fCRTTrackLabel);
550 
551  // Find which one matches the track passed to the function
552  int track_i = 0, index = 0;
553 
554  for(auto const& crtTrack : (*crtTrackHandle)){
555 
556  if(TrackCompare(crtTrack, track)) track_i = index;
557  index++;
558  }
559 
560  // Get the crt hits associated to that hit and the data associate to the hits
561  std::vector<art::Ptr<CRTHit>> hits = findManyHits.at(track_i);
562  art::FindManyP<CRTData> findManyData(hits, event, fCRTSimHitLabel);
563 
564  // Get all the true IDs from all the IDEs in the track
565  for(size_t i = 0; i < hits.size(); i++){
566 
567  std::vector<art::Ptr<CRTData>> data = findManyData.at(i);
568  art::FindManyP<sim::AuxDetIDE> findManyIdes(data, event, fCRTDataLabel);
569 
570  for(size_t j = 0; j < data.size(); j++){
571 
572  std::vector<art::Ptr<sim::AuxDetIDE>> ides = findManyIdes.at(j);
573 
574  for(size_t k = 0; k < ides.size(); k++){
575 
576  int id = ides[k]->trackID;
577  if(fRollupUnsavedIds) id = std::abs(id);
578  ids[id] += ides[k]->energyDeposited;
579  }
580  }
581 
582  }
583 
584  // Find the true ID that contributed the most energy
585  double maxEnergy = -1;
586  int trueId = -99999;
587 
588  for(auto &id : ids){
589 
590  if(id.second > maxEnergy){
591 
592  maxEnergy = id.second;
593  trueId = id.first;
594  }
595  }
596 
597  return trueId;
598  }
process_name use argoneut_mc_hitfinder track
T abs(T value)
bool TrackCompare(const CRTTrack &track1, const CRTTrack &track2)
pdgs k
Definition: selectors.fcl:22
int icarus::crt::CRTBackTracker::TrueIdFromTrackId ( const art::Event &  event,
int  track_i 
)

Definition at line 601 of file icaruscode/icaruscode/CRT/CRTUtils/CRTBackTracker.cc.

601  {
602 
603  if(fTrackTrueIds.find(track_i) != fTrackTrueIds.end()){
604 
605  double maxEnergy = -1;
606 
607  int trueId = -99999;
608 
609  for(auto &id : fTrackTrueIds[track_i]){
610 
611  if(id.second > maxEnergy){
612 
613  maxEnergy = id.second;
614  trueId = id.first;
615  }
616  }
617 
618  return trueId;
619  }
620  return -99999;
621  }
std::map< int, std::map< int, double > > fTrackTrueIds

Member Data Documentation

art::InputTag icarus::crt::CRTBackTracker::fCRTDataLabel
private
art::InputTag icarus::crt::CRTBackTracker::fCRTSimHitLabel
private
art::InputTag icarus::crt::CRTBackTracker::fCRTTrackLabel
private
art::InputTag icarus::crt::CRTBackTracker::fCRTTrueHitLabel
private
std::map<int, std::map<int, double> > icarus::crt::CRTBackTracker::fDataTrueIds
private
bool icarus::crt::CRTBackTracker::fRollupUnsavedIds
private
std::map<int, std::map<int, double> > icarus::crt::CRTBackTracker::fSimHitTrueIds
private
std::map<int, std::map<int, double> > icarus::crt::CRTBackTracker::fTrackTrueIds
private
std::map<int, std::map<int, double> > icarus::crt::CRTBackTracker::fTrueHitTrueIds
private

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