19 #include <TLorentzVector.h>
20 #include <TGeoVolume.h>
21 #include <TGeoMaterial.h>
36 using namespace genie;
37 using namespace genie::geometry;
62 namespace pathsegutils {
66 std::ostringstream fmt;
67 fmt <<
"(" << std::setw(w) << std::setprecision(p) << vec->x()
68 <<
"," << std::setw(w) << std::setprecision(p) << vec->y()
69 <<
"," << std::setw(w+1) << std::setprecision(p) << vec->z() <<
")";
76 PathSegment::PathSegment(
void) :
77 fRayDist(0), fStepLength(0),
78 fVolume(0), fMedium(0), fMaterial(0),
85 double& ddist,
double& dstep)
const
87 double dist_recalc = (
fEnter-startpos).Mag();
106 << std::setw(16) << vname <<
" '"
107 << std::setw(18) << mname <<
"' ";
111 stream << std::setw(rngw) <<
"[ ]";
113 std::ostringstream rngset;
114 for (
size_t i = 0 ; i < n; ++i ) {
116 rngset <<
"[" << sr.first <<
":" << sr.second <<
"]";
118 stream << std::setw(rngw) << rngset.str();
120 stream << std::right;
121 #ifdef PATHSEG_KEEP_PATH
143 sum += ( sr.second - sr.first );
154 if ( sumrange < 0.0 ) {
155 LOG(
"PathS",
pFATAL) <<
"GetPosition failed fractrim=" << fractrim
156 <<
" because sumrange = " << sumrange;
157 return TVector3(0,0,0);
159 Double_t target = fractrim * sumrange;
163 Double_t ds = ( sr.second - sr.first );
166 LOG(
"PathS",
pINFO) <<
"GetPosition fractrim=" << fractrim
167 <<
" target " << target <<
" [" << i <<
"] "
168 <<
" ds " << ds <<
" sum " << sum;
170 if ( sum >= target ) {
171 Double_t overstep = sum - target;
172 Double_t fractotal = (sr.second - overstep)/
fStepLength;
174 LOG(
"PathS",
pINFO) <<
"GetPosition fractrim=" << fractrim
175 <<
" overstep " << overstep
176 <<
" fractotal " << fractotal;
181 LOG(
"PathS",
pFATAL) <<
"GetPosition failed fractrim=" << fractrim;
182 return TVector3(0,0,0);
189 : fDoCrossCheck(false), fPrintVerbose(false)
207 LOG(
"PathS",
pDEBUG) <<
"SetAllToZero called";
235 for ( ; sitr != sitr_end ; ++sitr ) {
274 for ( ; sitr != sitr_end ; ++sitr ) {
277 double addist = TMath::Abs(ddist);
278 double adstep = TMath::Abs(dstep);
279 if ( addist > mxddist ) mxddist = addist;
280 if ( adstep > mxdstep ) mxdstep = adstep;
288 stream <<
"\nPathSegmentList [-]" << endl;
292 double dstep, ddist, mxdstep = 0, mxddist = 0;
296 for ( ; sitr != sitr_end ; ++sitr, ++k ) {
299 stream <<
" [" << setw(4) << k <<
"] " <<
ps;
302 double addist = TMath::Abs(ddist);
303 double adstep = TMath::Abs(dstep);
304 if ( addist > mxddist ) mxddist = addist;
305 if ( adstep > mxdstep ) mxdstep = adstep;
306 stream <<
" recalc diff"
307 <<
" dist " << std::setw(12) << ddist
308 <<
" step " << std::setw(12) << dstep;
312 if ( nseg == 0 ) stream <<
" holds no segments." << std::endl;
315 stream <<
"PathSegmentList "
316 <<
" mxddist " << mxddist
317 <<
" mxdstep " << mxdstep
325 for ( ; mitr != mitr_end; ++mitr ) {
326 const TGeoMaterial* mat = mitr->first;
327 double sumsteps = mitr->second;
328 stream <<
" fMatStepSum[" << mat->GetName() <<
"] = " << sumsteps << std::endl;
334 #ifdef PATH_SEGMENT_SUPPORT_XML
341 <<
"Loading PathSegmentList from XML file: " << filename;
343 xmlDocPtr xml_doc = xmlParseFile(filename.c_str() );
347 <<
"XML file could not be parsed! [filename: " << filename <<
"]";
351 xmlNodePtr xmlCur = xmlDocGetRootElement(xml_doc);
355 <<
"XML doc. has null root element! [filename: " << filename <<
"]";
359 if( xmlStrcmp(xmlCur->name, (
const xmlChar *)
"path_length_list") ) {
361 <<
"XML doc. has invalid root element! [filename: " << filename <<
"]";
365 LOG(
"PathS",
pINFO) <<
"XML file was successfully parsed";
367 xmlCur = xmlCur->xmlChildrenNode;
370 while (xmlCur != NULL) {
373 if( (!xmlStrcmp(xmlCur->name, (
const xmlChar *)
"path_length")) ) {
375 xmlNodePtr xmlPlVal = xmlCur->xmlChildrenNode;
381 xmlNodeListGetString(xml_doc, xmlPlVal, 1));
383 LOG(
"PathS",
pDEBUG) <<
"pdgc = " << spdgc <<
" --> pl = " << spl;
385 int pdgc = atoi( spdgc.c_str() );
386 double pl = atof( spl.c_str() );
388 TParticlePDG * p = pdglib->
Find(pdgc);
391 <<
"No particle with pdgc " << pdgc
392 <<
" found. Will not load its path length";
394 this->insert( map<int, double>::value_type(pdgc, pl) );
398 xmlCur = xmlCur->next;
405 void PathSegmentList::SaveAsXml(
string filename)
const
410 <<
"Saving PathSegmentList as XML in file: " << filename;
412 ofstream outxml(filename.c_str());
413 if(!outxml.is_open()) {
414 LOG(
"PathS",
pERROR) <<
"Couldn't create file = " << filename;
417 outxml <<
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
418 outxml << endl << endl;
419 outxml <<
"<!-- generated by PathSegmentList::SaveAsXml() -->";
420 outxml << endl << endl;
422 outxml <<
"<path_length_list>" << endl << endl;
424 PathSegmentList::const_iterator pl_iter;
426 for(pl_iter = this->begin(); pl_iter != this->end(); ++pl_iter) {
428 int pdgc = pl_iter->first;
429 double pl = pl_iter->second;
431 outxml <<
" <path_length pdgc=\"" << pdgc <<
"\">"
432 << pl <<
"</path_length>" << endl;
434 outxml <<
"</path_length_list>";
PathSegmentV_t fSegmentList
Actual list of segments.
void CrossCheck(double &mxddist, double &mxdstep) const
MaterialMap_t fMatStepSum
Segment list re-evaluated by material for fast lookup of path lengths.
string Vec3AsString(const TVector3 *vec)
StepRangeSet fStepRangeSet
collection of {steplo,stephi} pairs
TVector3 fEnter
top vol coordinates and units
TVector3 fStartPos
Record, for future comparison, the path taken.
Object to be filled with the neutrino path-segments representing geometry volume steps (generally bou...
bool IsSameStart(const TVector3 &pos, const TVector3 &dir) const
void SetStep(Double_t step, bool setlimits=true)
step taken in the geometry element
const TGeoMaterial * fMaterial
ref only ptr to TGeoMaterial
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
PathSegmentV_t::const_iterator PathSegVCItr_t
void Print(ostream &stream) const
TVector3 fDirection
direction (in top vol coords)
const TGeoVolume * fVolume
ref only ptr to TGeoVolume
TVector3 fExit
top vol coordinates and units
void Copy(const PathSegmentList &plist)
void SetStartInfo(const TVector3 &pos=TVector3(0, 0, 1e37), const TVector3 &dir=TVector3(0, 0, 0))
Double_t GetSummedStepRange() const
get the sum of all the step range (in case step has been trimmed or split)
std::pair< Double_t, Double_t > StepRange
static constexpr double ps
string TrimSpaces(string input)
MaterialMap_t::const_iterator MaterialMapCItr_t
Double_t fRayDist
distance from start of ray
static PDGLibrary * Instance(void)
Singleton class to load & serve a TDatabasePDG.
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
TVector3 GetPosition(Double_t frac) const
calculate position within allowed ranges passed on fraction of total
void Print(ostream &stream) const
const MaterialMap_t & GetMatStepSumMap(void) const
PathSegmentList & operator=(const PathSegmentList &list)
vector< vector< double > > clear
TParticlePDG * Find(int pdgc, bool must_exist=true)
void DoCrossCheck(const TVector3 &startpos, double &ddist, double &dstep) const
perform cross check on segment, return differences
enum genie::EXmlParseStatus XmlParserStatus_t
static constexpr double sr
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
string Vec3AsString(const TVector3 *vec)
Double_t fStepLength
total step size in volume
void FillMatStepSum(void)
std::string fPathString
full path names