8 #include "cetlib_except/exception.h" 12 #include <TLorentzVector.h> 30 const TLorentzVector& momentum )
39 std::advance(i,index);
47 std::advance(i,index);
59 for(
int n = 0;
n < N-1; ++
n){
71 int numberOfDigits = (int) std::log10( (
double) numberOfTrajectories ) + 1;
74 output.width( numberOfDigits );
75 output <<
"#" <<
": < position (x,y,z,t), momentum (Px,Py,Pz,E) >" << std::endl;
80 output.width( numberOfDigits );
81 output << nTrajectory <<
": " 82 <<
"< (" << (*trajectory).first.X()
83 <<
"," << (*trajectory).first.Y()
84 <<
"," << (*trajectory).first.Z()
85 <<
"," << (*trajectory).first.T()
86 <<
") , (" << (*trajectory).second.Px()
87 <<
"," << (*trajectory).second.Py()
88 <<
"," << (*trajectory).second.Pz()
89 <<
"," << (*trajectory).second.E()
90 <<
") >" << std::endl;
99 unsigned char key = 0;
101 if (process.compare(
"hadElastic") == 0) key = 1;
102 else if(process.compare(
"pi-Inelastic") == 0) key = 2;
103 else if(process.compare(
"pi+Inelastic") == 0) key = 3;
104 else if(process.compare(
"kaon-Inelastic") == 0) key = 4;
105 else if(process.compare(
"kaon+Inelastic") == 0) key = 5;
106 else if(process.compare(
"protonInelastic") == 0) key = 6;
107 else if(process.compare(
"neutronInelastic") == 0) key = 7;
115 std::string process(
"Unknown");
117 if (key == 1) process =
"hadElastic";
118 else if(key == 2) process =
"pi-Inelastic";
119 else if(key == 3) process =
"pi+Inelastic";
120 else if(key == 4) process =
"kaon-Inelastic";
121 else if(key == 5) process =
"kaon+Inelastic";
122 else if(key == 6) process =
"protonInelastic";
123 else if(key == 7) process =
"neutronInelastic";
130 TLorentzVector
const& m,
131 std::string
const& process )
161 if(
size() <= 2)
return;
168 std::deque<std::pair<int, int> > toCheck;
171 toCheck.push_back(std::make_pair(0,
size()-1));
178 while(!toCheck.empty()){
179 const int loIdx = toCheck.front().first;
180 const int hiIdx = toCheck.front().second;
185 throw cet::exception(
"MCTrajectory") <<
"Degnerate range in Sparsify method";
187 const TVector3 loVec =
at(loIdx).first.Vect();
188 const TVector3 hiVec =
at(hiIdx).first.Vect();
190 const TVector3
dir = (hiVec-loVec).Unit();
194 for(
int i = loIdx+1; i < hiIdx; ++i){
195 const TVector3 toHere =
at(i).first.Vect()-loVec;
197 const double impact = (toHere-dir.Dot(toHere)*
dir).Mag2();
198 if(impact > margin){ok =
false;
break;}
207 const int midIdx = (loIdx+hiIdx)/2;
210 throw cet::exception(
"MCTrajectory") <<
"Midpoint in sparsification is same as lowpoint";
212 throw cet::exception(
"MCTrajectory") <<
"Midpoint in sparsification is same as hipoint";
218 if(midIdx == loIdx+1){
222 toCheck.push_back(std::make_pair(loIdx, midIdx));
225 if(midIdx == hiIdx-1){
229 toCheck.push_back(std::make_pair(midIdx, hiIdx));
236 std::map< size_t, unsigned char> processMap;
238 done.insert(itr.first);
239 processMap[itr.first] = itr.second;
244 const unsigned int I = done.size();
246 newTraj.reserve(I+1);
251 for(
auto idx : done){
252 newTraj.push_back(
at(idx));
253 if(processMap.count(idx) > 0){
254 newProcMap.push_back(std::make_pair(newTraj.size() - 1,
255 processMap.find(idx)->second)
265 std::swap(fTrajectoryProcess, newProcMap);
void Add(TLorentzVector const &p, TLorentzVector const &m)
void push_back(value_type const &v)
reverse_iterator rbegin()
const value_type & at(const size_type i) const
std::string KeyToProcess(unsigned char const &key) const
std::vector< std::pair< TLorentzVector, TLorentzVector > > list_type
unsigned char ProcessToKey(std::string const &process) const
list_type::value_type value_type
void Sparsify(double margin=.1)
list_type::size_type size_type
list_type::const_iterator const_iterator
ProcessMap fTrajectoryProcess
const TLorentzVector & Position(const size_type) const
The accessor methods described above.
std::vector< std::pair< size_t, unsigned char > > ProcessMap
double TotalLength() const
const TLorentzVector & Momentum(const size_type) const
friend std::ostream & operator<<(std::ostream &output, const MCTrajectory &)
cet::coded_exception< error, detail::translate > exception
list_type ftrajectory
The list of trajectory points.