All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GenericCRT.cxx
Go to the documentation of this file.
1 /*!
2  * Title: GenericCRT Utility Class
3  * Author: Andrzej Szelc (andrzejs@fnal.gov)
4  *
5  * Description:
6  * Class with Algorithms to convert sim::AuxDetHits to sim::AuxDetSimChannels
7  *
8  */
9 
10 
11 #include "GenericCRT.h"
12 
13 #include "messagefacility/MessageLogger/MessageLogger.h"
14 
15 #include "CLHEP/Evaluator/Evaluator.h"
16 
17 #include <algorithm> // std::find()
18 #include <utility> // std::move()
19 
20 sim::GenericCRTUtility::GenericCRTUtility(const std::string energyUnitsScale)
21 {
22  HepTool::Evaluator eval;
23  eval.setStdMath();
24  eval.setSystemOfUnits();
25 
26  const std::string scaleExpression = "MeV / " + energyUnitsScale;
27  fEnergyUnitsScale = eval.evaluate(scaleExpression.c_str());
28 
29  if(eval.status() != 0) fEnergyUnitsScale = 1.;
30 }
31 
33 {
34  sim::AuxDetIDE outputIDE;
35 
36  outputIDE.trackID = InputHit.GetTrackID();
37  outputIDE.energyDeposited = InputHit.GetEnergyDeposited() * fEnergyUnitsScale;
38  outputIDE.entryX = InputHit.GetEntryX();
39  outputIDE.entryY = InputHit.GetEntryY();
40  outputIDE.entryZ = InputHit.GetEntryZ();
41  outputIDE.entryT = InputHit.GetEntryT();
42  outputIDE.exitX = InputHit.GetExitX();
43  outputIDE.exitY = InputHit.GetExitY();
44  outputIDE.exitZ = InputHit.GetExitZ();
45  outputIDE.exitT = InputHit.GetExitT();
46  outputIDE.exitMomentumX = InputHit.GetExitMomentumX();
47  outputIDE.exitMomentumY = InputHit.GetExitMomentumY();
48  outputIDE.exitMomentumZ = InputHit.GetExitMomentumZ();
49 
50 
51  return outputIDE;
52 }
53 
54 
55 
56 std::vector<unsigned int> sim::GenericCRTUtility::GetAuxDetChannels(const std::vector<sim::AuxDetHit>& InputHitVector) const
57 {
58 
59  std::vector<unsigned int> AuxDetChanNumber;
60  AuxDetChanNumber.reserve(size(InputHitVector));
61 
62 
63  for(auto const& hit : InputHitVector)
64  {
65 
66  std::vector<unsigned int>::iterator Chanitr
67  = std::find(AuxDetChanNumber.begin(), AuxDetChanNumber.end(), hit.GetID());
68 
69  if(Chanitr == AuxDetChanNumber.end()){ //If trackID is already in the map, update it
70  //if channel ID is not in the set yet, add it
71  AuxDetChanNumber.push_back(hit.GetID());
72  }//
73 
74  }
75 
76  return AuxDetChanNumber;
77 
78 }
79 
80 
81 
82 sim::AuxDetSimChannel sim::GenericCRTUtility::GetAuxDetSimChannelByNumber(const std::vector<sim::AuxDetHit>& InputHitVector, unsigned int inputchannel) const
83 {
84  std::vector<sim::AuxDetIDE> IDEvector;
85  //loop over sim::AuxDetHits and assign them to AuxDetSimChannels.
86 
87  size_t ad_id_no = 9999;
88  size_t ad_sen_id_no = 9999;
89 
90  for (auto const& auxDetHit : InputHitVector)
91  {
92 
93  double xcoordinate = (auxDetHit.GetEntryX() + auxDetHit.GetExitX())/2.0;
94  double ycoordinate = (auxDetHit.GetEntryY() + auxDetHit.GetExitY())/2.0;
95  double zcoordinate = (auxDetHit.GetEntryZ() + auxDetHit.GetExitZ())/2.0;
96  double worldPos[3] = {xcoordinate,ycoordinate,zcoordinate};
97 
98  if(auxDetHit.GetID() == inputchannel) // this is the channel we want.
99  {
100  // Find the IDs given the hit position
101  fGeo->FindAuxDetSensitiveAtPosition(worldPos, ad_id_no, ad_sen_id_no, 0.0001);
102 
103  mf::LogDebug("GenericCRTUtility") << "Found an AuxDetHit with ID " << auxDetHit.GetID()
104  << " for AuxDet ID " << ad_id_no
105  << " Sens ID " << ad_sen_id_no << std::endl;
106 
107  auto tempIDE = toAuxDetIDE(auxDetHit);
108 
109  std::vector<sim::AuxDetIDE>::iterator IDEitr
110  = std::find(IDEvector.begin(), IDEvector.end(), tempIDE);
111 
112  if(IDEitr != IDEvector.end()){ //If trackID is already in the map, update it
113  //Andrzej's note - following logic from AuxDetReadout in Legacy, but why are the other paremeters getting overwritten like that?
114  IDEitr->energyDeposited += tempIDE.energyDeposited;
115  IDEitr->exitX = tempIDE.exitX;
116  IDEitr->exitY = tempIDE.exitY;
117  IDEitr->exitZ = tempIDE.exitZ;
118  IDEitr->exitT = tempIDE.exitT;
119  IDEitr->exitMomentumX = tempIDE.exitMomentumX;
120  IDEitr->exitMomentumY = tempIDE.exitMomentumY;
121  IDEitr->exitMomentumZ = tempIDE.exitMomentumZ;
122  }
123  else{ //if trackID is not in the set yet, add it
124  IDEvector.push_back(std::move(tempIDE));
125  }//else
126 
127  // break;
128  } // end if the AuxDetHit channel checks out.
129 
130  } // end main loop on AuxDetHit
131 
132 
133  mf::LogDebug("GenericCRTUtility") << "Returning AuxDetSimChannel for ID "
134  << ad_id_no << " " << ad_sen_id_no
135  << ", with " << IDEvector.size() << " IDEs." << std::endl;
136 
137  //push back the AuxDetSimChannel Vector.
138  //TODO check the last parameter values.
139  return sim::AuxDetSimChannel(ad_id_no, std::move(IDEvector), ad_sen_id_no);
140 }
141 
142 
143 
144 
145 std::vector<sim::AuxDetSimChannel> sim::GenericCRTUtility::GetAuxDetSimChannels(const std::vector<sim::AuxDetHit>& InputHitVector) const
146 {
147  auto const auxDetChannels = GetAuxDetChannels(InputHitVector);
148  std::vector<sim::AuxDetSimChannel> auxDetVector;
149  auxDetVector.reserve(size(auxDetChannels));
150 
151  for (auto const channelNum : auxDetChannels) {
152  auxDetVector.push_back(GetAuxDetSimChannelByNumber(InputHitVector, channelNum));
153  }
154 
155  return auxDetVector;
156 }
unsigned int GetTrackID() const
Definition: AuxDetHit.h:169
sim::AuxDetIDE toAuxDetIDE(sim::AuxDetHit const &InputHit) const
Definition: GenericCRT.cxx:32
sim::AuxDetSimChannel GetAuxDetSimChannelByNumber(const std::vector< sim::AuxDetHit > &InputHitVector, unsigned int inputchannel) const
Definition: GenericCRT.cxx:82
float GetExitX() const
Definition: AuxDetHit.h:121
int trackID
Geant4 supplied track ID.
float exitMomentumZ
Exit Z-Momentum of particle.
std::vector< unsigned int > GetAuxDetChannels(const std::vector< sim::AuxDetHit > &InputHitVector) const
Definition: GenericCRT.cxx:56
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
process_name hit
Definition: cheaterreco.fcl:51
float GetExitMomentumY() const
Definition: AuxDetHit.h:81
float exitY
Exit position Y of particle.
Collection of particles crossing one auxiliary detector cell.
float entryT
Entry time of particle.
std::vector< sim::AuxDetSimChannel > GetAuxDetSimChannels(const std::vector< sim::AuxDetHit > &InputHitVector) const
Definition: GenericCRT.cxx:145
float GetEntryX() const
Definition: AuxDetHit.h:153
float exitMomentumX
Exit X-Momentum of particle.
GenericCRTUtility(const std::string energyUnitsScale)
Definition: GenericCRT.cxx:20
float exitT
Exit time of particle.
float GetExitT() const
Definition: AuxDetHit.h:97
float GetEntryT() const
Definition: AuxDetHit.h:129
float GetEnergyDeposited() const
Definition: AuxDetHit.h:161
float exitZ
Exit position Z of particle.
float entryZ
Entry position Z of particle.
float exitX
Exit position X of particle.
float energyDeposited
total energy deposited for this track ID and time
float GetExitY() const
Definition: AuxDetHit.h:113
float entryX
Entry position X of particle.
float entryY
Entry position Y of particle.
float GetExitMomentumX() const
Definition: AuxDetHit.h:89
float GetEntryZ() const
Definition: AuxDetHit.h:137
float GetExitZ() const
Definition: AuxDetHit.h:105
MC truth information to make RawDigits and do back tracking.
float exitMomentumY
Exit Y-Momentum of particle.
float GetExitMomentumZ() const
Definition: AuxDetHit.h:73
float GetEntryY() const
Definition: AuxDetHit.h:145