Skip to content

Commit

Permalink
Merge branch 'star-bnl:main' into QA_FCS
Browse files Browse the repository at this point in the history
  • Loading branch information
genevb authored Mar 27, 2024
2 parents 2ec9cc9 + 2e09826 commit a0b4b41
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 49 deletions.
22 changes: 11 additions & 11 deletions StRoot/StBTofSimMaker/StBTofSimMaker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ int StBTofSimMaker::CellResponse(g2t_ctf_hit_st* tofHitsFromGeant,
g2t_track_st *tof_track = g2t_track->GetTable();
int no_tracks= g2t_track->GetNRows();

double beta;
// Initialize beta to be a large negative value. This is a flag in case the following if
// condition is not satisfied and meaning there is something wrong with the beta value.
//
double beta = -999.;
int trackId = -1;
for(int j=0;j<no_tracks;j++){
if(tofHitsFromGeant->track_p==tof_track[j].id){
Expand Down Expand Up @@ -803,7 +806,11 @@ int StBTofSimMaker::FastCellResponse(g2t_ctf_hit_st* tofHitsFromGeant, StBTofCol
int no_tracks= g2t_track->GetNRows();

StMcTrack *partnerTrk = 0;
int partnerTrkId;

// Initialize partnerTrkId to be a negative value. This is a flag in case the following if
// condition is not satisfied and meaning there is something wrong with the track ID.
//
int partnerTrkId = -1;
for(int j=0;j<no_tracks;j++){
if(tofHitsFromGeant->track_p==tof_track[j].id){
partnerTrk = new StMcTrack(&(tof_track[j]));
Expand All @@ -820,15 +827,8 @@ int StBTofSimMaker::FastCellResponse(g2t_ctf_hit_st* tofHitsFromGeant, StBTofCol
double pathL = tofHitsFromGeant->s_track;
double q = 0.;

double Rawtof = tofHitsFromGeant->tof*1000./nanosecond;
float Rawbeta=pathL/Rawtof/3e-2;
double momentum=partnerTrk->momentum().mag();
double mass=partnerTrk->fourMomentum().m();
double calcTof=pathL/(3e-2)/sqrt(1 - mass*mass/(momentum*momentum + mass*mass));

double time_blur = ranGauss.shoot()*mSimResDb->timeres_tof(itray, imodule, icell)*1e-9/nanosecond;
double tof = tofHitsFromGeant->tof*1000./nanosecond + time_blur; //! 85ps per channel

if ( mVpdSim ) { // VpdSimMaker present, assume vpdstart
tof += mVpdSimConfig->getMcClock()*1000;
}
Expand All @@ -851,9 +851,9 @@ int StBTofSimMaker::FastCellResponse(g2t_ctf_hit_st* tofHitsFromGeant, StBTofCol
}
}

// tof = tof - mSimDb->toffset(); // Apply offset correction.
// tof = tof - mSimDb->toffset(); // Apply offset correction.
double t0 = tofHitsFromGeant->tof*1000./nanosecond;
float beta=pathL/tof/3e-2;
// float beta=pathL/tof/3e-2;

StMcBTofHit *mcBTofHit = new StMcBTofHit(itray,imodule,icell,de,pathL,t0,tof,q);
mcBTofHit->setPosition(local);
Expand Down
68 changes: 64 additions & 4 deletions StRoot/StFwdTrackMaker/FwdTrackerConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,48 @@ std::stringstream FwdTrackerConfig::sstr;
// template specializations
////

// Specialization for string to avoid extra conversions
/**
* @brief write a value to path
*
* @tparam template specialization for std::string
* @param path path to write, if it DNE it is created
* @param v value (of type string) to write
*/
template <>
void FwdTrackerConfig::set( std::string path, std::string v ) {

FwdTrackerConfig::canonize( path );
// convrt from string to type T and return
mNodes[ path ] = v;
}

/**
* @brief write a value to path
*
* @tparam template specialization for bool
* @param path path to write, if it DNE it is created
* @param bv boolean to write
*/
template <>
void FwdTrackerConfig::set( std::string path, bool bv ) {

FwdTrackerConfig::canonize( path );
// convrt from string to type T and return
std::string v = "false";
if (bv)
v = "true";
mNodes[ path ] = v;
}

//
/**
* @brief Get a value from the path
*
* @tparam Specialization for string to avoid extra conversions
* @param path path to lookup
* @param dv default value if path DNE
* @return std::string value at path or default
*/
template <>
std::string FwdTrackerConfig::get( std::string path, std::string dv ) const {
// return default value if path DNE
Expand All @@ -20,13 +61,26 @@ std::string FwdTrackerConfig::get( std::string path, std::string dv ) const {
return ( mNodes.at( path ) );
}

// conversion to string is a noop
/**
* @brief conversion to string is a noop
*
* @tparam string specialization
* @param str input
* @return std::string output (unchanged)
*/
template <>
std::string FwdTrackerConfig::convert( std::string str ) const {
return str;
}

// specialization for bool adds recognition of strings "true" and "false" (lower case)
/**
* @brief specialization for bool adds recognition of strings "true" and "false" (lower case)
*
* @tparam bool specialization, fallback to int check
* @param str input string
* @return true for "true"
* @return false for "false"
*/
template <>
bool FwdTrackerConfig::convert( std::string str ) const {

Expand All @@ -39,7 +93,13 @@ bool FwdTrackerConfig::convert( std::string str ) const {
return static_cast<bool>(convert<int>( str ));
}

// get as ROOT TString
/**
* @brief get as ROOT TString
*
* @tparam TString specialization
* @param str input value
* @return TString output as ROOT TString
*/
template <>
TString FwdTrackerConfig::convert(std::string str) const {
TString r(str);
Expand Down
135 changes: 116 additions & 19 deletions StRoot/StFwdTrackMaker/FwdTrackerConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ class FwdTrackerConfig {
std::map<std::string, std::string> mNodes;
static std::stringstream sstr; // reused for string to numeric conversion

// assumes bare path and adds [i] until DNE
// reports lowest non-existant index
// starts at 1 since 0 is checked on existance
/**
* @brief get lowest non-existing path index
* assumes bare path and adds [i] until DNE
* starts at 1 since 0 is checked on existance
* @param path base path to check
* @return size_t index, starts at 1
*/
size_t pathCount( const std::string path ){
size_t index = 1;
std::string p = path + TString::Format( "[%zu]", index ).Data();
Expand All @@ -39,6 +43,14 @@ class FwdTrackerConfig {
return index;
}

/**
* @brief Reads an xml document and writes it into map
*
* @param xml xml document to map
* @param node starting node - allows recursive mapping
* @param level the integer index of the level of current parsing
* @param path the path for the current node
*/
void mapFile(TXMLEngine &xml, XMLNodePointer_t node, Int_t level, std::string path = "") {
using namespace std;
// add the path delimeter above top level
Expand Down Expand Up @@ -83,7 +95,11 @@ class FwdTrackerConfig {
} // mapFile
public:

// sanitizes a path to its canonical form
/**
* @brief Returns a path in its cannonical form
*
* @param path Path to cannoize, returned in place by reference
*/
static void canonize( std::string &path ) {
// remove whitespace
path.erase(std::remove_if(path.begin(), path.end(), static_cast<int(*) (int)>(std::isspace)), path.end());
Expand All @@ -98,7 +114,11 @@ class FwdTrackerConfig {
return;
}

// dump config to a basic string representation - mostly for debugging
/**
* @brief dump config to a basic string representation - mostly for debugging
*
* @return std::string
*/
std::string dump() const {
using namespace std;
FwdTrackerConfig::sstr.str("");
Expand All @@ -109,17 +129,29 @@ class FwdTrackerConfig {
return FwdTrackerConfig::sstr.str();
}

// Does a path exist
// Either node or attribute - used to determine if default value is used
/**
* @brief returns whether or not a path exist
* Either node or attribute - used to determine if default value is used
*
* @param path - the path to check
* @return true : path exists
* @return false : path DNE
*/
bool exists( std::string path ) const {
FwdTrackerConfig::canonize( path );
if ( 0 == mNodes.count( path ) )
return false;
return true;
}

// generic conversion to type T from std::string
// override this for special conversions
/**
* @brief Generic conversion of type T from string
* override this for special conversions
*
* @tparam T : Type to convert to and return
* @param s : input string to use for conversion
* @return T converted value of type T
*/
template <typename T>
T convert( std::string s ) const {
T rv;
Expand All @@ -130,10 +162,30 @@ class FwdTrackerConfig {
return rv;
}


/**
* @brief Generic conversion of type T to a string
*
* @tparam T : type to convert
* @param v : value of type T
* @return std::string output string with representation of T
*/
template <typename T>
std::string convertTo( T v ) const {
FwdTrackerConfig::sstr.str("");
FwdTrackerConfig::sstr.clear();
FwdTrackerConfig::sstr << v;
return FwdTrackerConfig::sstr.str();
}


// template function for getting any type that can be converted from string via stringstream
/**
* @brief template function for getting any type that can be converted from string via stringstream
*
* @tparam T type to return
* @param path path to lookup
* @param dv default value to return if the node DNE
* @return T return value of type T
*/
template <typename T>
T get( std::string path, T dv ) const {

Expand All @@ -146,8 +198,28 @@ class FwdTrackerConfig {
return convert<T>( mNodes.at( path ) );
}

/**
* @brief Writes a value of type T to the map
* Uses convertTo<T> to convert type T to a string rep
* @tparam T type of value to write
* @param path path to write to
* @param v value of type T
*/
template <typename T>
void set( std::string path, T v ) {
FwdTrackerConfig::canonize( path );
// convrt from string to type T and return
mNodes[ path ] = convertTo<T>( v );
}


/**
* @brief Get a Vector object from config
*
* @tparam T type of value for the vector object
* @param path path to lookup
* @param dv default value, can use initializer list
* @return std::vector<T> vector of type T returned
*/
template <typename T>
std::vector<T> getVector( std::string path, std::vector<T> dv ) const {
if ( !exists( path ) )
Expand Down Expand Up @@ -176,7 +248,12 @@ class FwdTrackerConfig {
return result;
}

// list the paths of children nodes for a given node
/**
* @brief list the paths of children nodes for a given node
*
* @param path path to search for children
* @return std::vector<std::string> list of full paths to the children nodes
*/
std::vector<std::string> childrenOf( std::string path ) const {
using namespace std;
vector<string> result;
Expand Down Expand Up @@ -204,17 +281,28 @@ class FwdTrackerConfig {
return result;
}

// Constructor is noop, use load(...)
/**
* @brief Constructor is noop, use load(...)
*
*/
FwdTrackerConfig() {}

// constructor that immediately loads an xml file
/**
* @brief Construct a new Fwd Tracker Config object and load a file
*
* @param filename
*/
FwdTrackerConfig(std::string filename) {
load( filename );
}

// Main setup routine.
// Loads the given XML file and maps it
void load( std::string filename ) {
/**
* @brief Main setup routine
* Loads the given XML file (or string) and maps it
* @param filename filename (or xml string) to load. If file the content is loaded as an xml doc
* @param asString false: filename is loaded and contents treated as xml doc, true: treat the string `filename` directly as an xml doc
*/
void load( std::string filename, bool asString = false ) {
using namespace std;

// empty the map of mNodes
Expand All @@ -224,7 +312,12 @@ class FwdTrackerConfig {
TXMLEngine xml;

// Now try to parse xml file
XMLDocPointer_t xmldoc = xml.ParseFile(filename.c_str());
XMLDocPointer_t xmldoc;
if (asString)
xmldoc = xml.ParseString(filename.c_str());
else
xmldoc = xml.ParseFile(filename.c_str());

if (!xmldoc) { // parse failed, TODO inform of error
mErrorParsing = true;
return;
Expand All @@ -249,5 +342,9 @@ template <>
TString FwdTrackerConfig::convert(std::string str) const;
template <>
std::string FwdTrackerConfig::get( std::string path, std::string dv ) const;
template <>
void FwdTrackerConfig::set( std::string path, std::string v );
template <>
void FwdTrackerConfig::set( std::string path, bool bv );

#endif
Loading

0 comments on commit a0b4b41

Please sign in to comment.