00001 // $Header: /cvs/lcd/slic/src/LcioMcpPrinter.cc,v 1.19 2007/04/27 01:54:35 jeremy Exp $ 00002 #include "LcioMcpPrinter.hh" 00003 00004 // lcdd 00005 #include "StringUtil.hh" 00006 00007 // lcio 00008 #include "IMPL/LCCollectionVec.h" 00009 00010 using EVENT::LCCollection; 00011 using IMPL::LCCollectionVec; 00012 using EVENT::MCParticle; 00013 using EVENT::MCParticleVec; 00014 00015 using namespace std; 00016 using std::ios; 00017 00018 namespace slic 00019 { 00020 00021 const int LcioMcpPrinter::idx_width = 4; 00022 const int LcioMcpPrinter::ptr_width = 10; 00023 const int LcioMcpPrinter::pdg_width = 5; 00024 const int LcioMcpPrinter::par_width = 15; 00025 const int LcioMcpPrinter::dau_width = 15; 00026 const int LcioMcpPrinter::mom_width = 20; 00027 const int LcioMcpPrinter::vtx_width = 20; 00028 const int LcioMcpPrinter::end_width = 20; 00029 const int LcioMcpPrinter::time_width = 6; 00030 const int LcioMcpPrinter::mass_width = 6; 00031 const int LcioMcpPrinter::chrg_width = 4; 00032 const int LcioMcpPrinter::e_width = 6; 00033 const int LcioMcpPrinter::stat_width = 5; 00034 const int LcioMcpPrinter::flags_width = 16; 00035 00036 LcioMcpPrinter::LcioMcpPrinter() 00037 : Module("LcioMcpPrinter"), 00038 m_coll(0), 00039 m_collName("") 00040 {} 00041 00042 LcioMcpPrinter::~LcioMcpPrinter() 00043 {} 00044 00045 void LcioMcpPrinter::printMcpCollection(const std::string& collName, EVENT::LCCollection* coll) 00046 { 00047 m_coll = coll; 00048 m_collName = collName; 00049 printMcpCollection(); 00050 } 00051 00052 void LcioMcpPrinter::printMcpCollection() 00053 { 00054 head(); 00055 00056 if ( m_coll != 0 ) { 00057 00058 // LCCollectionVec* mcpCollVec = static_cast<LCCollectionVec*> ( m_coll ); 00059 00060 if ( m_coll->getNumberOfElements() > 0 ) { 00061 00062 log() << LOG::debug << "Collection Name: " << m_collName << LOG::done; 00063 log() << LOG::debug << "# of Particles: " << m_coll->getNumberOfElements() << LOG::done; 00064 00065 colLabels(); 00066 00067 LCCollectionVec* vec = static_cast<LCCollectionVec*>(m_coll); 00068 for ( LCCollectionVec::iterator iter = vec->begin(); 00069 iter != vec->end(); 00070 iter++ ) { 00071 printMcp ( static_cast<EVENT::MCParticle*> (*iter) ); 00072 } 00073 00074 #ifdef SLIC_LOG 00075 flagLabels(); 00076 #endif 00077 00078 } 00079 else { 00080 log() << LOG::debug << "COLLECTION IS EMPTY" << LOG::done; 00081 } 00082 } 00083 else { 00084 log() << LOG::debug << "NO CURRENT MCPARTICLE COLLECTION" << LOG::done; 00085 } 00086 00087 foot(); 00088 } 00089 00090 void LcioMcpPrinter::flagLabels() 00091 { 00092 line(); 00093 00094 log() << LOG::debug << "FLAGS: createdInSimulation Backscatter vertexIsNotEndpointOfParent " 00095 << "DecayedInTracker DecayedInCalorimeter LeftDetector Stopped"; 00096 00097 line(); 00098 } 00099 00100 void LcioMcpPrinter::printMcp(EVENT::MCParticle* mcp) 00101 { 00102 // index 00103 log().getOutputStream().width(idx_width); 00104 log().getOutputStream() << left; 00105 log() << LOG::debug << findMcpIndex( mcp ); 00106 00107 sep(); 00108 00109 // ptr 00110 log().getOutputStream().width(ptr_width); 00111 log().getOutputStream() << left; 00112 log() << LOG::debug << mcp; 00113 00114 sep(); 00115 00116 // PDG 00117 log().getOutputStream().width(pdg_width); 00118 log() << LOG::debug << left << mcp->getPDG(); 00119 00120 sep(); 00121 00122 // parents 00123 log().getOutputStream().width(par_width); 00124 log() << LOG::debug << left << makeIdxVecString( findParentIndices( mcp ) ); 00125 00126 sep(); 00127 00128 // daughters 00129 log().getOutputStream().width(dau_width); 00130 log() << LOG::debug << left << makeIdxVecString( findDaughterIndices( mcp ) ); 00131 00132 sep(); 00133 00134 // momentum 00135 log().getOutputStream().width(mom_width); 00136 log() << LOG::debug << left << makeDoubleArray3String( mcp->getMomentum() ); 00137 00138 sep(); 00139 00140 // vertex 00141 log().getOutputStream().width(vtx_width); 00142 log() << LOG::debug << left << makeDoubleArray3String( mcp->getVertex() ); 00143 00144 sep(); 00145 00146 // endpoint 00147 log().getOutputStream().width(end_width); 00148 log() << LOG::debug << left << makeDoubleArray3String( mcp->getEndpoint() ); 00149 00150 sep(); 00151 00152 // time 00153 log().getOutputStream().width(time_width); 00154 log() << LOG::debug << left << mcp->getTime(); 00155 00156 sep(); 00157 00158 // mass 00159 log().getOutputStream().width(mass_width); 00160 log() << LOG::debug << left << mcp->getMass(); 00161 00162 sep(); 00163 00164 // charge 00165 log().getOutputStream().width(chrg_width); 00166 log() << LOG::debug << mcp->getCharge(); 00167 00168 sep(); 00169 00170 // energy 00171 log().getOutputStream().width(e_width); 00172 log() << LOG::debug << mcp->getEnergy(); 00173 00174 // gen status 00175 log() << LOG::debug << mcp->getGeneratorStatus(); 00176 00177 00178 #ifdef SLIC_LOG 00179 sep(); 00180 log() << LOG::debug << left << makeSimStatusCodesString( mcp ); 00181 #endif 00182 00183 line(); 00184 line(); 00185 } 00186 00187 std::string LcioMcpPrinter::makeDoubleArray3String(const double* arr) 00188 { 00189 00190 return 00191 "(" + StringUtil::toString( arr[0] ) 00192 + ", " + StringUtil::toString( arr[1] ) 00193 + ", " + StringUtil::toString( arr[2] ) 00194 + ")"; 00195 } 00196 00197 std::string LcioMcpPrinter::makeFloatArray3String(const float* arr) 00198 { 00199 return "(" + StringUtil::toString( arr[0] ) 00200 + ", " + StringUtil::toString( arr[1] ) 00201 + ", " + StringUtil::toString( arr[2] ) + ")"; 00202 } 00203 00204 std::string LcioMcpPrinter::makeSimStatusCodesString(EVENT::MCParticle* mcp) 00205 { 00206 return StringUtil::toString( mcp->isCreatedInSimulation() ) + " " 00207 + StringUtil::toString( mcp->isBackscatter() ) + " " 00208 + StringUtil::toString( mcp->vertexIsNotEndpointOfParent() ) + " " 00209 + StringUtil::toString( mcp->isDecayedInTracker() ) + " " 00210 + StringUtil::toString( mcp->isDecayedInCalorimeter() ) + " " 00211 + StringUtil::toString( mcp->hasLeftDetector() ) + " " 00212 + StringUtil::toString( mcp->isStopped() ); 00213 } 00214 00215 std::string LcioMcpPrinter::makeIdxVecString(const IdxVec& idxVec) 00216 { 00217 std::string idx_vec; 00218 idx_vec = "[ "; 00219 00220 for ( IdxVec::const_iterator iter = idxVec.begin(); 00221 iter != idxVec.end(); 00222 iter++ ) { 00223 int this_idx = (*iter); 00224 idx_vec += StringUtil::toString( this_idx ) + " "; 00225 } 00226 00227 idx_vec += "]"; 00228 return idx_vec; 00229 } 00230 00231 LcioMcpPrinter::IdxVec LcioMcpPrinter::findDaughterIndices(EVENT::MCParticle* mcp) 00232 { 00233 IdxVec dauIdxs; 00234 const EVENT::MCParticleVec& dauVec = mcp->getDaughters(); 00235 for ( EVENT::MCParticleVec::const_iterator iter = dauVec.begin(); 00236 iter != dauVec.end(); 00237 iter++ ) { 00238 dauIdxs.push_back( findMcpIndex( ( const_cast<MCParticle*> (*iter) ) ) ); 00239 } 00240 00241 return dauIdxs; 00242 } 00243 00244 LcioMcpPrinter::IdxVec LcioMcpPrinter::findParentIndices(EVENT::MCParticle* mcp) 00245 { 00246 IdxVec parIdxs; 00247 const EVENT::MCParticleVec& parVec = mcp->getParents(); 00248 for ( EVENT::MCParticleVec::const_iterator iter = parVec.begin(); 00249 iter != parVec.end(); 00250 iter++ ) { 00251 parIdxs.push_back( findMcpIndex( ( const_cast<MCParticle*> (*iter) ) ) ); 00252 } 00253 00254 return parIdxs; 00255 } 00256 00257 int LcioMcpPrinter::findMcpIndex(EVENT::MCParticle* mcp) 00258 { 00259 int idx = 0; 00260 bool fnd = false; 00261 LCCollectionVec* mcpCollVec = static_cast<LCCollectionVec*> ( m_coll ); 00262 for ( LCCollectionVec::iterator iter = mcpCollVec->begin(); 00263 iter != mcpCollVec->end(); 00264 iter++ ) { 00265 // ptr compare 00266 if ( ( static_cast<MCParticle*> (*iter) ) == mcp ) { 00267 fnd = true; 00268 break; 00269 } 00270 idx++; 00271 } 00272 00273 if ( !fnd ) { 00274 idx = -1; 00275 } 00276 00277 return idx; 00278 } 00279 00280 inline void LcioMcpPrinter::sep() 00281 { 00282 log() << LOG::debug << "|"; 00283 } 00284 00285 inline void LcioMcpPrinter::line() 00286 { 00287 log() << LOG::debug << LOG::done; 00288 } 00289 00290 inline void LcioMcpPrinter::head() 00291 { 00292 log() << LOG::debug << "---------------------MCParticle Collection---------------------"; 00293 00294 line(); 00295 } 00296 00297 inline void LcioMcpPrinter::foot() 00298 { 00299 log() << LOG::debug << "---------------------------------------------------------------"; 00300 00301 line(); 00302 } 00303 00304 void LcioMcpPrinter::colLabels() 00305 { 00306 log().getOutputStream().width(idx_width); 00307 log() << LOG::debug << left << "idx"; 00308 00309 sep(); 00310 00311 log().getOutputStream().width(ptr_width); 00312 log() << LOG::debug << left << "ptr"; 00313 00314 sep(); 00315 00316 log().getOutputStream().width(pdg_width); 00317 log() << LOG::debug << left << "pdg"; 00318 00319 sep(); 00320 00321 log().getOutputStream().width(par_width); 00322 log() << LOG::debug << left << "par"; 00323 00324 sep(); 00325 00326 log().getOutputStream().width(dau_width); 00327 log() << LOG::debug << left << "dau"; 00328 00329 sep(); 00330 00331 log().getOutputStream().width(mom_width); 00332 log() << LOG::debug << left << "mom"; 00333 00334 sep(); 00335 00336 log().getOutputStream().width(vtx_width); 00337 log() << LOG::debug << left << "vtx"; 00338 00339 sep(); 00340 00341 log().getOutputStream().width(end_width); 00342 log() << LOG::debug << left << "end"; 00343 00344 sep(); 00345 00346 log().getOutputStream().width(time_width); 00347 log() << LOG::debug << left << "time"; 00348 00349 sep(); 00350 00351 log().getOutputStream().width(mass_width); 00352 log() << LOG::debug << left << "mass"; 00353 00354 sep(); 00355 00356 log().getOutputStream().width(chrg_width); 00357 log() << LOG::debug << left << "chg"; 00358 00359 sep(); 00360 00361 log().getOutputStream().width(e_width); 00362 log() << LOG::debug << "E"; 00363 00364 sep(); 00365 00366 #ifdef SLIC_LOG 00367 log().getOutputStream().width(flags_width); 00368 log() << LOG::debug << "flags"; 00369 #endif 00370 00371 line(); 00372 } 00373 }
1.5.4