20 #include <G4ChargedGeantino.hh>
21 #include <G4Geantino.hh>
22 #include <G4IonTable.hh>
23 #include <G4ParticleDefinition.hh>
24 #include <G4ParticleTable.hh>
25 #include <G4VProcess.hh>
27 #include <TDatabasePDG.h>
28 #include <TParticlePDG.h>
113 G4ParticleTable* tab = G4ParticleTable::GetParticleTable();
114 G4ParticleDefinition* def = tab->FindParticle(
particle->
pdgID);
119 const int L =
id / 10000000;
id %= 10000000;
120 const int Z =
id / 10000;
id %= 10000;
121 const int A =
id / 10;
id %= 10;
123 G4IonTable* tab_ion = G4IonTable::GetIonTable();
125 G4ParticleDefinition* def_ion = tab_ion->FindIon(Z, A, L, lvl);
128 printout(VERBOSE,
"Geant4Particle",
"+++ Returning ion with PDG %10d", def_ion->GetPDGEncoding());
130 }
else if(lvl == 0) {
132 printout(VERBOSE,
"Geant4Particle",
"+++ Creating ion with PDG %10d",
particle->
pdgID);
133 return tab_ion->GetIon(Z, A, L, 0.0);
136 printout(WARNING,
"Geant4Particle",
"+++ Cannot find excited ion with PDG %10d, setting excitation level to zero",
138 return tab_ion->GetIon(Z, A, L, 0.0);
143 return G4Geantino::Definition();
144 return G4ChargedGeantino::Definition();
151 if (
const G4ParticleDefinition* def =
definition() )
152 return def->GetParticleName();
154 TDatabasePDG* db = TDatabasePDG::Instance();
156 if ( pdef )
return pdef->GetName();
165 if (
const G4ParticleDefinition* def =
definition() )
166 return def->GetParticleType();
168 TDatabasePDG* db = TDatabasePDG::Instance();
170 if ( pdef )
return pdef->ParticleClass();
179 std::vector<G4ParticleDefinition*> results;
180 std::string exp = expression;
181 G4ParticleTable* pt = G4ParticleTable::GetParticleTable();
182 G4ParticleTable::G4PTblDicIterator* iter = pt->GetIterator();
185 if ( expression ==
"*" || expression ==
".(*)" ) {
187 G4ParticleDefinition* p = iter->value();
188 results.emplace_back(p);
193 int ret = ::regcomp(®, exp.c_str(), 0);
195 throw std::runtime_error(format(
"Geant4ParticleHandle",
"REGEX: Failed to compile particle name %s", exp.c_str()));
198 G4ParticleDefinition* p = iter->value();
199 ret = ::regexec(®, p->GetParticleName().c_str(), 0, NULL, 0);
201 results.emplace_back(p);
202 else if (ret == REG_NOMATCH)
206 ::regerror(ret, ®, msgbuf,
sizeof(msgbuf));
208 throw std::runtime_error(format(
"Geant4ParticleHandle",
"REGEX: Failed to match particle name %s err=%s", exp.c_str(), msgbuf));
218 G4ParticleTable* tab = G4ParticleTable::GetParticleTable();
219 G4ParticleDefinition* def = tab->FindParticle(expression);
239 return G4VProcess::GetProcessTypeName(
particle->
process->GetProcessType());
252 for(
auto i : temp) p->
daughters.insert(i+off);
256 for(
auto i : temp ) p->
parents.insert(i+off);
265 ::snprintf(text,
sizeof(text),
"/%d",*(p->
parents.begin()));
266 else if ( p->
parents.size() > 1 ) {
267 text[0]=
'/';text[1]=0;
269 ::snprintf(text+strlen(text),
sizeof(text)-strlen(text),
"%d ",i);
271 printout((dd4hep::PrintLevel)level,src,
272 "+++ %s %4d def [%-11s,%8s] reason:%8d E:%+.2e %3s #Dau:%3d #Par:%3d%-5s",
287 if ( p->
parents.size() == 0 ) text[0]=0;
288 else if ( p->
parents.size() == 1 ) ::snprintf(text,
sizeof(text),
"/%d",*(p->
parents.begin()));
289 else if ( p->
parents.size() > 1 ) ::snprintf(text,
sizeof(text),
"/%d..",*(p->
parents.begin()));
290 printout((dd4hep::PrintLevel)level,src,
291 "+++ %s %4d G4:%4d [%-12s,%8s] reason:%8d "
292 "E:%+.2e in record:%s #Par:%3d%-5s #Dau:%3d",
309 ::snprintf(text,
sizeof(text),
"/%d",*(p->
parents.begin()));
310 else if ( p->
parents.size() > 1 ) {
311 text[0]=
'/';text[1]=0;
313 ::snprintf(text+strlen(text),
sizeof(text)-strlen(text),
"%d ",i);
315 printout((dd4hep::PrintLevel)level,src,
316 "+++ %s ID:%3d %-12s status:%08X PDG:%6d Vtx:(%+.2e,%+.2e,%+.2e)[mm] "
317 "time: %+.2e [ns] #Dau:%3d #Par:%1d%-6s",
319 p->
vsx/CLHEP::mm,p->
vsy/CLHEP::mm,p->
vsz/CLHEP::mm,p->
time/CLHEP::ns,
332 ::snprintf(text,
sizeof(text),
"/%d",*(p->
parents.begin()));
333 else if ( p->
parents.size() > 1 ) {
334 text[0]=
'/';text[1]=0;
336 ::snprintf(text+strlen(text),
sizeof(text)-strlen(text),
"%d ",i);
338 printout((dd4hep::PrintLevel)level,src,
339 "+++%s ID:%3d %-12s stat:%08X PDG:%6d Mom:(%+.2e,%+.2e,%+.2e)[MeV] "
340 "time: %+.2e [ns] #Dau:%3d #Par:%1d%-6s",
342 p->
psx/CLHEP::MeV,p->
psy/CLHEP::MeV,p->
psz/CLHEP::MeV,p->
time/CLHEP::ns,
354 ::snprintf(text,
sizeof(text),
"/%d",*(p->
parents.begin()));
355 else if ( p->
parents.size() > 1 ) {
356 text[0]=
'/';text[1]=0;
358 ::snprintf(text+strlen(text),
sizeof(text)-strlen(text),
"%d ",i);
360 printout((dd4hep::PrintLevel)level,src,
361 "+++%s %3d %-12s stat:%08X PDG:%6d Mom:(%+.2e,%+.2e,%+.2e)[MeV] "
362 "Vtx:(%+.2e,%+.2e,%+.2e)[mm] #Dau:%3d #Par:%1d%-6s",
364 p->
psx/CLHEP::MeV,p->
psy/CLHEP::MeV,p->
psz/CLHEP::MeV,
365 p->
vsx/CLHEP::mm,p->
vsy/CLHEP::mm,p->
vsz/CLHEP::mm,
372 printout((dd4hep::PrintLevel)level,src,
373 "+++ %s %10s/%-7s %12s/%-10s %6s/%-6s %4s %4s "
374 "%-4s %-3s %-3s %-10s "
375 "%-5s %-6s %-3s %-3s %-20s %s",
376 tag,
"ID",
"G4-ID",
"Part-Name",
"PDG",
"Parent",
"G4-ID",
"#Par",
"#Dau",
377 "Prim",
"Sec",
">E",
"Energy",
378 "EMPTY",
"STAB",
"DEC",
"DOC",
379 "Process",
"Processing Flags");
383 using PropertyMask = dd4hep::detail::ReferenceBitMask<int>;
390 std::string proc =
'['+proc_name+(p->
process ?
"/" :
"")+proc_type+
']';
397 std::stringstream str;
399 for(
const auto i : p->
parents )
401 str <<
" Daughters: ";
404 printout((dd4hep::PrintLevel)level,src,
405 "+++ %s ID:%7d/%-7d %12s/%-10d %6d/%-6d %4d %4d %-4s %-3s %-3s %+.3e "
406 "%-5s %-4s %-3s %-3s %-20s %c%c%c%c -- %c%c%c%c%c%c%c%c%c %s",
441 printout((dd4hep::PrintLevel)level,src,
442 "+++ %s ID:%7d %12s %6d%-7s %7s %3s %5d %3s %+.3e %-4s %-7s %-3s %-3s %2d [%s%s%s] %c%c%c%c -- %c%c%c%c%c%c%c",
497 std::cout <<
"Particle map:" << std::endl;
499 std::snprintf(text,
sizeof(text),
" [%-4d:%p]",p.second->id,(
void*)p.second);
502 std::cout << std::endl;
506 std::cout << std::endl;
509 std::cout <<
"Equivalents:" << std::endl;
511 std::snprintf(text,
sizeof(text),
" [%-5d : %-5d]",p.first,p.second);
514 std::cout << std::endl;
518 std::cout << std::endl;
540 printout(ERROR,
"Geant4ParticleMap",
"+++ No Equivalent particle for track:%d."
541 " Monte Carlo truth record looks broken!",g4_id);