DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ParticleActors.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DDEve/ParticleActors.h>
16 #include <DD4hep/DD4hepUnits.h>
17 #include <DD4hep/Printout.h>
18 #include <DD4hep/Objects.h>
19 
20 #include <TEveTrack.h>
21 #include <TEveBoxSet.h>
22 #include <TEvePointSet.h>
23 #include <TEveCompound.h>
24 #include <TEveTrackPropagator.h>
25 
26 #include <TParticle.h>
27 #include <TDatabasePDG.h>
28 #include <TGeoManager.h>
29 
30 using namespace dd4hep;
31 
32 #ifdef DD4HEP_USE_GEANT4_UNITS
33 #define CM_2_MM 1.0
34 #define MM_2_CM 1.0
35 #define MEV_TO_GEV 1000.0
36 #else
37 #define CM_2_MM 10.0
38 #define MM_2_CM 0.1
39 #define MEV_TO_GEV 1.0
40 #endif
41 
42 namespace {
43  Color_t Colors[] = {
44  kRed, kBlue, kYellow, kGreen, kPink, kAzure, kOrange, kTeal, kViolet, kSpring, kMagenta, kCyan
45  };
46 }
47 
49 MCParticleCreator::MCParticleCreator(TEveTrackPropagator* p, TEveCompound* ps, const DisplayConfiguration::Config* cfg)
50  : propagator(p), particles(ps)
51 {
52  propagator->SetName("Track propagator for charged particles");
53  propagator->SetMaxR(1000);
54  propagator->SetMaxZ(1000);
55  propagator->SetMaxOrbs(10.0);
56  propagator->SetDelta(0.01); // Step
57  propagator->RefPMAtt().SetMarkerColor(kYellow);
58  propagator->RefPMAtt().SetMarkerStyle(kCircle);
59  propagator->RefPMAtt().SetMarkerSize(1.0);
60  if ( cfg ) {
61  lineWidth = cfg->data.hits.width;
63  propagator->RefPMAtt().SetMarkerSize(cfg->data.hits.size);
64  propagator->RefPMAtt().SetMarkerStyle(cfg->data.hits.type);
65  printout(ALWAYS,"MCParticleCreator","+++ Minimal particle energy: %8.3g [GeV]",threshold);
66  }
67 }
68 
70 void MCParticleCreator::addCompound(const std::string& name, TEveLine* e) {
71  Compounds::const_iterator i = types.find(name);
72  if ( i == types.end() ) {
73  static int icol = 0;
74  TEveCompound* o = new TEveCompound(name.c_str(),name.c_str());
75  particles->AddElement(o);
76  i = types.emplace(name,o).first;
77  Color_t col = Colors[icol%(sizeof(Colors)/sizeof(Colors[0]))];
78  col += icol/sizeof(Colors)/sizeof(Colors[0]);
79  o->SetMainColor(col);
80  o->CSCApplyMainColorToAllChildren();
81  ++icol;
82  }
83  TEveCompound* c = (*i).second;
84  e->SetMainColor(c->GetMainColor());
85  c->AddElement(e);
86 }
87 
89 void MCParticleCreator::addCompoundLight(const std::string& name, TEveLine* e) {
90  Compounds::const_iterator i = types.find(name);
91  if ( i == types.end() ) {
92  TEveCompound* o = new TEveCompound(name.c_str(),name.c_str());
93  particles->AddElement(o);
94  i = types.emplace(name,o).first;
95  o->SetMainColor(kBlack);
96  o->CSCApplyMainColorToAllChildren();
97  }
98  TEveCompound* c = (*i).second;
99  e->SetLineWidth(1);
100  e->SetLineStyle(2);
101  e->SetMainColor(c->GetMainColor());
102  c->AddElement(e);
103 }
104 
107  for(Compounds::const_iterator i = types.begin(); i!=types.end(); ++i) {
108  (*i).second->CSCApplyMainColorToAllChildren();
109  (*i).second->CloseCompound();
110  }
111  particles->CloseCompound();
112  particles->SetRnrSelfChildren(kTRUE,kTRUE);
113  propagator->SetRnrDecay(kTRUE);
114  propagator->SetRnrDaughters(kTRUE);
115  propagator->SetRnrCluster2Ds(kTRUE);
116  propagator->SetRnrReferences(kTRUE);
117 }
118 
120  TEveVector momentum(p.psx*MEV_2_GEV, p.psy*MEV_2_GEV, p.psz*MEV_2_GEV);
121  TEveVector start(p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM);
122  TEveVector end(p.vex*MM_2_CM, p.vey*MM_2_CM, p.vez*MM_2_CM);
123  TEveVector dir = end-start;
124 
125  // Tracks longer than 100 micron and energy > 100 MeV
126  if ( p.energy > 10e0 && p.energy > threshold && dir.R()*CM_2_MM > 100e-3 ) {
127  TDatabasePDG* db = TDatabasePDG::Instance();
128  TParticlePDG* def = db->GetParticle(p.pdgID);
129  TParticle part(p.pdgID,
130  0,0,0,0,0,
132  p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM, p.time);
133 
134  TEveTrack* t = new TEveTrack(&part,p.id,propagator);
135  ++count;
136  // Add start-vertex as path mark
137  //t->AddPathMark(TEvePathMark(TEvePathMark::kDecay,start));
138  // Add end-vertex as path mark (kDecay)
139  t->AddPathMark(TEvePathMark(TEvePathMark::kLineSegment,start,momentum,dir));
140  t->AddPathMark(TEvePathMark(TEvePathMark::kReference,start,momentum));
141  t->AddPathMark(TEvePathMark(TEvePathMark::kDecay,end,momentum));
142  t->SetLineWidth(lineWidth);
143  t->SetTitle(Form("MCParticle: Track ID=%d Parent:%d\n"
144  "Type:%s Charge=%.3f Time:%.3f ns\n"
145  "Start(Vx, Vy, Vz, t) = (%.3f, %.3f, %.3f) [cm]\n"
146  "End (Vx, Vy, Vz, t) = (%.3f, %.3f, %.3f) [cm]\n"
147  "Length:%.3f [cm]\n"
148  "(Px, Py, Pz, E) = (%.3f, %.3f, %.3f, %.3f) [GeV]",
149  p.id, p.parent,
150  def ? def->GetName() : "Unknown",
151  def ? def->Charge() : 0.0, p.time,
152  p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM,
153  p.vex*MM_2_CM, p.vey*MM_2_CM, p.vez*MM_2_CM,
154  dir.R(),
156 
157  // Add element to collection
158  int pdg = abs(p.pdgID);
159  if ( pdg == 11 )
160  addCompound("e+-", t);
161  else if ( pdg == 12 || pdg == 14 || pdg == 16 )
162  addCompoundLight("Neutrinos", t);
163  else if ( pdg == 22 )
164  addCompound("Gamma", t);
165  else if ( pdg == 13 )
166  addCompound("Muon+-", t);
167  else if ( pdg == 211 )
168  addCompound("Pi+-", t);
169  else if ( pdg == 321 )
170  addCompound("K+-", t);
171  else if ( pdg == 2112 )
172  addCompound("Neutrons", t);
173  else if ( pdg == 2212 )
174  addCompound("Protons", t);
175  else
176  addCompound("Other", t);
177  }
178  else {
179  printout(ALWAYS,"MCParticleCreator","+++ SKIP particle %4d. Energy: %8.3g [MeV]",p.id,p.energy);
180  }
181 }
182 
184 StartVertexCreator::StartVertexCreator(const std::string& collection, size_t length)
185  : pointset(0), deposit(0), count(0)
186 {
187  pointset = new TEvePointSet(collection.c_str(),length);
188  pointset->SetMarkerSize(0.2);
189 }
190 
192 StartVertexCreator::StartVertexCreator(const std::string& collection, size_t length, const DisplayConfiguration::Config& cfg)
193  : pointset(0), deposit(0), count(0)
194 {
195  pointset = new TEvePointSet(collection.c_str(),length);
196  pointset->SetMarkerSize(cfg.data.hits.size);
197  pointset->SetMarkerStyle(cfg.data.hits.type);
198  //pointset->SetMarkerAlpha(cfg.data.hits.alpha);
199  pointset->SetMainColor(cfg.data.hits.color);
200 }
202 TEveElement* StartVertexCreator::element() const {
203  return pointset;
204 }
205 
208 }
209 
212  pointset->SetPoint(count++, p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM);
213 }
214 
dd4hep::DDEveParticle::vez
double vez
Definition: DDEveEventData.h:60
dd4hep::MCParticleCreator::count
int count
Definition: ParticleActors.h:45
Objects.h
dd4hep::DDEveParticle::psx
double psx
Definition: DDEveEventData.h:61
dd4hep::StartVertexCreator::operator()
virtual void operator()(const DDEveParticle &particle)
Action callback of this functor:
Definition: ParticleActors.cpp:211
dd4hep::DisplayConfiguration::Config::Values::hits
Hits hits
Definition: DisplayConfiguration.h:101
MM_2_CM
#define MM_2_CM
Definition: ParticleActors.cpp:38
dd4hep::DDEveParticle::vsx
double vsx
Definition: DDEveEventData.h:59
dd4hep::DDEveParticle::vsy
double vsy
Definition: DDEveEventData.h:59
dd4hep::MCParticleCreator::propagator
TEveTrackPropagator * propagator
Definition: ParticleActors.h:41
CM_2_MM
#define CM_2_MM
Definition: ParticleActors.cpp:37
dd4hep::StartVertexCreator::count
int count
Definition: ParticleActors.h:69
dd4hep::MCParticleCreator::addCompound
void addCompound(const std::string &name, TEveLine *e)
Access sub-compound by name.
Definition: ParticleActors.cpp:70
dd4hep::DisplayConfiguration::Config::data
union dd4hep::DisplayConfiguration::Config::Values data
dd4hep::MCParticleCreator::types
Compounds types
Definition: ParticleActors.h:43
MEV_2_GEV
#define MEV_2_GEV
Definition: EventHandler.h:27
dd4hep::DisplayConfiguration::Defaults::color
int color
Definition: DisplayConfiguration.h:58
MEV_TO_GEV
#define MEV_TO_GEV
Definition: ParticleActors.cpp:39
dd4hep::StartVertexCreator::StartVertexCreator
StartVertexCreator(const std::string &collection, size_t length)
Standard initializing constructor.
Definition: ParticleActors.cpp:184
ParticleActors.h
dd4hep::DDEveParticle::vsz
double vsz
Definition: DDEveEventData.h:59
dd4hep::DDEveParticle::id
int id
Definition: DDEveEventData.h:58
dd4hep::DDEveParticle::energy
double energy
Definition: DDEveEventData.h:61
dd4hep::MCParticleCreator::operator()
virtual void operator()(const DDEveParticle &particle)
Action callback of this functor:
Definition: ParticleActors.cpp:119
dd4hep::DDEveParticle::time
double time
Definition: DDEveEventData.h:61
dd4hep::MCParticleCreator::lineWidth
int lineWidth
Definition: ParticleActors.h:46
dd4hep::DisplayConfiguration::Hits::width
float width
Definition: DisplayConfiguration.h:84
dd4hep::DisplayConfiguration::Hits::type
int type
Definition: DisplayConfiguration.h:88
dd4hep::DDEveParticle::parent
int parent
Definition: DDEveEventData.h:58
dd4hep::DisplayConfiguration::Hits::threshold
float threshold
Definition: DisplayConfiguration.h:85
dd4hep::MCParticleCreator::particles
TEveCompound * particles
Definition: ParticleActors.h:42
dd4hep::DisplayConfiguration::Config
Container with full display configuration.
Definition: DisplayConfiguration.h:92
dd4hep::DDEveParticle::pdgID
int pdgID
Definition: DDEveEventData.h:58
dd4hep::MCParticleCreator::addCompoundLight
void addCompoundLight(const std::string &name, TEveLine *e)
Access sub-compound by name.
Definition: ParticleActors.cpp:89
dd4hep::DDEveParticle::psy
double psy
Definition: DDEveEventData.h:61
dd4hep::DDEveParticle::psz
double psz
Definition: DDEveEventData.h:61
dd4hep::MCParticleCreator::close
void close()
Close compounds.
Definition: ParticleActors.cpp:106
dd4hep::DisplayConfiguration::Hits::size
float size
Definition: DisplayConfiguration.h:83
dd4hep::MCParticleCreator::MCParticleCreator
MCParticleCreator(TEveTrackPropagator *p, TEveCompound *ps, const DisplayConfiguration::Config *cfg)
Standard initializing constructor.
Definition: ParticleActors.cpp:49
dd4hep::MCParticleCreator::threshold
double threshold
Definition: ParticleActors.h:44
dd4hep::StartVertexCreator::pointset
TEvePointSet * pointset
Definition: ParticleActors.h:67
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::DDEveParticle
Data structure to store the MC particle information.
Definition: DDEveEventData.h:56
DD4hepUnits.h
dd4hep::DDEveParticle::vey
double vey
Definition: DDEveEventData.h:60
Printout.h
dd4hep::DDEveParticle::vex
double vex
Definition: DDEveEventData.h:60
dd4hep::StartVertexCreator::element
TEveElement * element() const
Return eve element.
Definition: ParticleActors.cpp:202
dd4hep::StartVertexCreator::~StartVertexCreator
virtual ~StartVertexCreator()
Standard destructor.
Definition: ParticleActors.cpp:207