8 #include "cetlib_except/exception.h" 12 #include <TLorentzVector.h> 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()
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;
108 else if(process.compare(
"CoulombScat") == 0) key = 8;
109 else if(process.compare(
"nCapture") == 0) key = 9;
110 else if(process.compare(
"Transportation") == 0)
121 if (key == 1) process =
"hadElastic";
122 else if(key == 2) process =
"pi-Inelastic";
123 else if(key == 3) process =
"pi+Inelastic";
124 else if(key == 4) process =
"kaon-Inelastic";
125 else if(key == 5) process =
"kaon+Inelastic";
126 else if(key == 6) process =
"protonInelastic";
127 else if(key == 7) process =
"neutronInelastic";
128 else if(key == 8) process =
"CoulombScat";
129 else if(key == 9) process =
"nCapture";
130 else if(key == 10) process =
"Transportation";
137 TLorentzVector
const&
m,
139 bool keepTransportation)
153 if(
key > 0 && (
key != 10 || keepTransportation))
174 if(
size() <= 3 && keep_second_to_last)
return;
175 else if(
size() <= 2)
return;
182 std::deque<std::pair<int, int> > toCheck;
185 toCheck.push_back(std::make_pair(0,
size()-1));
191 if (keep_second_to_last)
192 done.insert(
size()-2);
194 while(!toCheck.empty()){
195 const int loIdx = toCheck.front().first;
196 const int hiIdx = toCheck.front().second;
201 throw cet::exception(
"MCTrajectory") <<
"Degnerate range in Sparsify method";
203 const TVector3 loVec =
at(loIdx).first.Vect();
204 const TVector3 hiVec =
at(hiIdx).first.Vect();
206 const TVector3
dir = (hiVec-loVec).Unit();
210 for(
int i = loIdx+1; i < hiIdx; ++i){
211 const TVector3 toHere =
at(i).first.Vect()-loVec;
213 const double impact = (toHere-dir.Dot(toHere)*
dir).Mag2();
214 if(impact > margin){ok =
false;
break;}
223 const int midIdx = (loIdx+hiIdx)/2;
226 throw cet::exception(
"MCTrajectory") <<
"Midpoint in sparsification is same as lowpoint";
228 throw cet::exception(
"MCTrajectory") <<
"Midpoint in sparsification is same as hipoint";
234 if(midIdx == loIdx+1){
238 toCheck.push_back(std::make_pair(loIdx, midIdx));
241 if(midIdx == hiIdx-1){
245 toCheck.push_back(std::make_pair(midIdx, hiIdx));
254 done.insert(itr.first);
255 processMap[itr.first] = itr.second;
260 const unsigned int I = done.size();
262 newTraj.reserve(I+1);
267 for(
auto idx : done){
268 newTraj.push_back(
at(idx));
269 if(processMap.count(idx) > 0){
270 newProcMap.push_back(std::make_pair(newTraj.size() - 1,
271 processMap.find(idx)->second)
281 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
std::unordered_map< std::string, int > processMap
unsigned char ProcessToKey(std::string const &process) const
list_type::value_type value_type
list_type::size_type size_type
void swap(Handle< T > &a, Handle< T > &b)
list_type::const_iterator const_iterator
ProcessMap fTrajectoryProcess
const TLorentzVector & Position(const size_type) const
The accessor methods described above.
Base utilities and modules for event generation and detector simulation.
std::vector< std::pair< size_t, unsigned char > > ProcessMap
void Sparsify(double margin=.1, bool keep_second_to_last=false)
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
double TotalLength() const
def momentum(x1, x2, x3, scale=1.)
const TLorentzVector & Momentum(const size_type) const
friend std::ostream & operator<<(std::ostream &output, const MCTrajectory &)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
list_type ftrajectory
The list of trajectory points.