File indexing completed on 2025-12-16 09:26:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DDEve/ParticleActors.h>
0016 #include <DD4hep/DD4hepUnits.h>
0017 #include <DD4hep/Printout.h>
0018 #include <DD4hep/Objects.h>
0019
0020 #include <TEveTrack.h>
0021 #include <TEveBoxSet.h>
0022 #include <TEvePointSet.h>
0023 #include <TEveCompound.h>
0024 #include <TEveTrackPropagator.h>
0025
0026 #include <TParticle.h>
0027 #include <TDatabasePDG.h>
0028 #include <TGeoManager.h>
0029
0030 using namespace dd4hep;
0031
0032 #ifdef DD4HEP_USE_GEANT4_UNITS
0033 #define CM_2_MM 1.0
0034 #define MM_2_CM 1.0
0035 #define MEV_TO_GEV 1000.0
0036 #else
0037 #define CM_2_MM 10.0
0038 #define MM_2_CM 0.1
0039 #define MEV_TO_GEV 1.0
0040 #endif
0041
0042 namespace {
0043 Color_t Colors[] = {
0044 kRed, kBlue, kYellow, kGreen, kPink, kAzure, kOrange, kTeal, kViolet, kSpring, kMagenta, kCyan
0045 };
0046 }
0047
0048
0049 MCParticleCreator::MCParticleCreator(TEveTrackPropagator* p, TEveCompound* ps, const DisplayConfiguration::Config* cfg)
0050 : propagator(p), particles(ps)
0051 {
0052 propagator->SetName("Track propagator for charged particles");
0053 propagator->SetMaxR(1000);
0054 propagator->SetMaxZ(1000);
0055 propagator->SetMaxOrbs(10.0);
0056 propagator->SetDelta(0.01);
0057 propagator->RefPMAtt().SetMarkerColor(kYellow);
0058 propagator->RefPMAtt().SetMarkerStyle(kCircle);
0059 propagator->RefPMAtt().SetMarkerSize(1.0);
0060 if ( cfg ) {
0061 lineWidth = cfg->data.hits.width;
0062 threshold = cfg->data.hits.threshold * MEV_TO_GEV;
0063 propagator->RefPMAtt().SetMarkerSize(cfg->data.hits.size);
0064 propagator->RefPMAtt().SetMarkerStyle(cfg->data.hits.type);
0065 printout(ALWAYS,"MCParticleCreator","+++ Minimal particle energy: %8.3g [GeV]",threshold);
0066 }
0067 }
0068
0069
0070 void MCParticleCreator::addCompound(const std::string& name, TEveLine* e) {
0071 Compounds::const_iterator i = types.find(name);
0072 if ( i == types.end() ) {
0073 static int icol = 0;
0074 TEveCompound* o = new TEveCompound(name.c_str(),name.c_str());
0075 particles->AddElement(o);
0076 i = types.emplace(name,o).first;
0077 Color_t col = Colors[icol%(sizeof(Colors)/sizeof(Colors[0]))];
0078 col += icol/sizeof(Colors)/sizeof(Colors[0]);
0079 o->SetMainColor(col);
0080 o->CSCApplyMainColorToAllChildren();
0081 ++icol;
0082 }
0083 TEveCompound* c = (*i).second;
0084 e->SetMainColor(c->GetMainColor());
0085 c->AddElement(e);
0086 }
0087
0088
0089 void MCParticleCreator::addCompoundLight(const std::string& name, TEveLine* e) {
0090 Compounds::const_iterator i = types.find(name);
0091 if ( i == types.end() ) {
0092 TEveCompound* o = new TEveCompound(name.c_str(),name.c_str());
0093 particles->AddElement(o);
0094 i = types.emplace(name,o).first;
0095 o->SetMainColor(kBlack);
0096 o->CSCApplyMainColorToAllChildren();
0097 }
0098 TEveCompound* c = (*i).second;
0099 e->SetLineWidth(1);
0100 e->SetLineStyle(2);
0101 e->SetMainColor(c->GetMainColor());
0102 c->AddElement(e);
0103 }
0104
0105
0106 void MCParticleCreator::close() {
0107 for(Compounds::const_iterator i = types.begin(); i!=types.end(); ++i) {
0108 (*i).second->CSCApplyMainColorToAllChildren();
0109 (*i).second->CloseCompound();
0110 }
0111 particles->CloseCompound();
0112 particles->SetRnrSelfChildren(kTRUE,kTRUE);
0113 propagator->SetRnrDecay(kTRUE);
0114 propagator->SetRnrDaughters(kTRUE);
0115 propagator->SetRnrCluster2Ds(kTRUE);
0116 propagator->SetRnrReferences(kTRUE);
0117 }
0118
0119 void MCParticleCreator::operator()(const DDEveParticle& p) {
0120 TEveVector momentum(p.psx*MEV_2_GEV, p.psy*MEV_2_GEV, p.psz*MEV_2_GEV);
0121 TEveVector start(p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM);
0122 TEveVector end(p.vex*MM_2_CM, p.vey*MM_2_CM, p.vez*MM_2_CM);
0123 TEveVector dir = end-start;
0124
0125
0126 if ( p.energy > 10e0 && p.energy > threshold && dir.R()*CM_2_MM > 100e-3 ) {
0127 TDatabasePDG* db = TDatabasePDG::Instance();
0128 TParticlePDG* def = db->GetParticle(p.pdgID);
0129 TParticle part(p.pdgID,
0130 0,0,0,0,0,
0131 p.psx*MEV_2_GEV, p.psy*MEV_2_GEV, p.psz*MEV_2_GEV, p.energy*MEV_2_GEV,
0132 p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM, p.time);
0133
0134 TEveTrack* t = new TEveTrack(&part,p.id,propagator);
0135 ++count;
0136
0137
0138
0139 t->AddPathMark(TEvePathMark(TEvePathMark::kLineSegment,start,momentum,dir));
0140 t->AddPathMark(TEvePathMark(TEvePathMark::kReference,start,momentum));
0141 t->AddPathMark(TEvePathMark(TEvePathMark::kDecay,end,momentum));
0142 t->SetLineWidth(lineWidth);
0143 t->SetTitle(Form("MCParticle: Track ID=%d Parent:%d\n"
0144 "Type:%s Charge=%.3f Time:%.3f ns\n"
0145 "Start(Vx, Vy, Vz, t) = (%.3f, %.3f, %.3f) [cm]\n"
0146 "End (Vx, Vy, Vz, t) = (%.3f, %.3f, %.3f) [cm]\n"
0147 "Length:%.3f [cm]\n"
0148 "(Px, Py, Pz, E) = (%.3f, %.3f, %.3f, %.3f) [GeV]",
0149 p.id, p.parent,
0150 def ? def->GetName() : "Unknown",
0151 def ? def->Charge() : 0.0, p.time,
0152 p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM,
0153 p.vex*MM_2_CM, p.vey*MM_2_CM, p.vez*MM_2_CM,
0154 dir.R(),
0155 p.psx*MEV_2_GEV, p.psy*MEV_2_GEV, p.psz*MEV_2_GEV, p.energy*MEV_2_GEV));
0156
0157
0158 int pdg = abs(p.pdgID);
0159 if ( pdg == 11 )
0160 addCompound("e+-", t);
0161 else if ( pdg == 12 || pdg == 14 || pdg == 16 )
0162 addCompoundLight("Neutrinos", t);
0163 else if ( pdg == 22 )
0164 addCompound("Gamma", t);
0165 else if ( pdg == 13 )
0166 addCompound("Muon+-", t);
0167 else if ( pdg == 211 )
0168 addCompound("Pi+-", t);
0169 else if ( pdg == 321 )
0170 addCompound("K+-", t);
0171 else if ( pdg == 2112 )
0172 addCompound("Neutrons", t);
0173 else if ( pdg == 2212 )
0174 addCompound("Protons", t);
0175 else
0176 addCompound("Other", t);
0177 }
0178 else {
0179 printout(ALWAYS,"MCParticleCreator","+++ SKIP particle %4d. Energy: %8.3g [MeV]",p.id,p.energy);
0180 }
0181 }
0182
0183
0184 StartVertexCreator::StartVertexCreator(const std::string& collection, size_t length)
0185 : pointset(0), deposit(0), count(0)
0186 {
0187 pointset = new TEvePointSet(collection.c_str(),length);
0188 pointset->SetMarkerSize(0.2);
0189 }
0190
0191
0192 StartVertexCreator::StartVertexCreator(const std::string& collection, size_t length, const DisplayConfiguration::Config& cfg)
0193 : pointset(0), deposit(0), count(0)
0194 {
0195 pointset = new TEvePointSet(collection.c_str(),length);
0196 pointset->SetMarkerSize(cfg.data.hits.size);
0197 pointset->SetMarkerStyle(cfg.data.hits.type);
0198
0199 pointset->SetMainColor(cfg.data.hits.color);
0200 }
0201
0202 TEveElement* StartVertexCreator::element() const {
0203 return pointset;
0204 }
0205
0206
0207 StartVertexCreator::~StartVertexCreator() {
0208 }
0209
0210
0211 void StartVertexCreator::operator()(const DDEveParticle& p) {
0212 pointset->SetPoint(count++, p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM);
0213 }
0214