DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleActors.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DDEve/ParticleActors.h"
17 #include "DD4hep/Objects.h"
18 
19 #include "TEveCompound.h"
20 #include "TEveTrack.h"
21 #include "TEveTrackPropagator.h"
22 
23 #include "TParticle.h"
24 #include "TDatabasePDG.h"
25 #include "TGeoManager.h"
26 
27 using namespace std;
28 using namespace DD4hep;
29 
30 static Color_t Colors[] = {
31  kRed, kBlue, kYellow, kGreen, kPink, kAzure, kOrange, kTeal, kViolet, kSpring, kMagenta, kCyan
32 };
33 
35 MCParticleCreator::MCParticleCreator(TEveTrackPropagator* p, TEveCompound* ps, const DisplayConfiguration::Config* cfg)
36  : propagator(p), particles(ps), count(0), lineWidth(4)
37 {
38  propagator->SetName("Track propagator for charged particles");
39  propagator->SetMaxR(1000);
40  propagator->SetMaxZ(1000);
41  propagator->SetMaxOrbs(10.0);
42  propagator->SetDelta(0.01); // Step
43  propagator->RefPMAtt().SetMarkerColor(kYellow);
44  propagator->RefPMAtt().SetMarkerStyle(kCircle);
45  propagator->RefPMAtt().SetMarkerSize(1.0);
46  if ( cfg ) {
47  lineWidth = cfg->data.hits.width;
48  propagator->RefPMAtt().SetMarkerSize(cfg->data.hits.size);
49  propagator->RefPMAtt().SetMarkerStyle(cfg->data.hits.type);
50  }
51 }
52 
54 void MCParticleCreator::addCompound(const std::string& name, TEveLine* e) {
55  Compounds::const_iterator i = types.find(name);
56  if ( i == types.end() ) {
57  static int icol = 0;
58  TEveCompound* o = new TEveCompound(name.c_str(),name.c_str());
59  particles->AddElement(o);
60  i = types.insert(make_pair(name,o)).first;
61  Color_t col = Colors[icol%(sizeof(Colors)/sizeof(Colors[0]))];
62  col += icol/sizeof(Colors)/sizeof(Colors[0]);
63  o->SetMainColor(col);
64  o->CSCApplyMainColorToAllChildren();
65  ++icol;
66  }
67  TEveCompound* c = (*i).second;
68  e->SetMainColor(c->GetMainColor());
69  c->AddElement(e);
70 }
71 
73 void MCParticleCreator::addCompoundLight(const std::string& name, TEveLine* e) {
74  Compounds::const_iterator i = types.find(name);
75  if ( i == types.end() ) {
76  static int icol = 0;
77  TEveCompound* o = new TEveCompound(name.c_str(),name.c_str());
78  particles->AddElement(o);
79  i = types.insert(make_pair(name,o)).first;
80  o->SetMainColor(kBlack);
81  o->CSCApplyMainColorToAllChildren();
82  ++icol;
83  }
84  TEveCompound* c = (*i).second;
85  e->SetLineWidth(1);
86  e->SetLineStyle(2);
87  e->SetMainColor(c->GetMainColor());
88  c->AddElement(e);
89 }
90 
93  for(Compounds::const_iterator i = types.begin(); i!=types.end(); ++i) {
94  (*i).second->CSCApplyMainColorToAllChildren();
95  (*i).second->CloseCompound();
96  }
97  particles->CloseCompound();
98  particles->SetRnrSelfChildren(kTRUE,kTRUE);
99  propagator->SetRnrDecay(kTRUE);
100  propagator->SetRnrDaughters(kTRUE);
101  propagator->SetRnrCluster2Ds(kTRUE);
102  propagator->SetRnrReferences(kTRUE);
103 }
104 
106  TEveVector momentum(p.psx*MEV_2_GEV, p.psy*MEV_2_GEV, p.psz*MEV_2_GEV);
107  TEveVector start(p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM);
108  TEveVector end(p.vex*MM_2_CM, p.vey*MM_2_CM, p.vez*MM_2_CM);
109  TEveVector dir = end-start;
110 
111  // Tracks longer than 100 micron and energy > 100 MeV
112  if ( dir.R()*CM_2_MM > 100e-3 && p.energy > 10e0 ) {
113  TDatabasePDG* db = TDatabasePDG::Instance();
114  TParticlePDG* def = db->GetParticle(p.pdgID);
115  TParticle part(p.pdgID,
116  0,0,0,0,0,
118  p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM, p.time);
119 
120  TEveTrack* t = new TEveTrack(&part,p.id,propagator);
121 
122  // Add start-vertex as path mark
123  //t->AddPathMark(TEvePathMark(TEvePathMark::kDecay,start));
124  // Add end-vertex as path mark (kDecay)
125  t->AddPathMark(TEvePathMark(TEvePathMark::kLineSegment,start,momentum,dir));
126  t->AddPathMark(TEvePathMark(TEvePathMark::kReference,start,momentum));
127  t->AddPathMark(TEvePathMark(TEvePathMark::kDecay,end,momentum));
128  t->SetLineWidth(lineWidth);
129  t->SetTitle(Form("MCParticle: Track ID=%d Parent:%d\n"
130  "Type:%s Charge=%.3f Time:%.3f ns\n"
131  "Start(Vx, Vy, Vz, t) = (%.3f, %.3f, %.3f) [cm]\n"
132  "End (Vx, Vy, Vz, t) = (%.3f, %.3f, %.3f) [cm]\n"
133  "Length:%.3f [cm]\n"
134  "(Px, Py, Pz, E) = (%.3f, %.3f, %.3f, %.3f) [GeV]",
135  p.id, p.parent,
136  def ? def->GetName() : "Unknown",
137  def ? def->Charge() : 0.0, p.time,
138  p.vsx*MM_2_CM, p.vsy*MM_2_CM, p.vsz*MM_2_CM,
139  p.vex*MM_2_CM, p.vey*MM_2_CM, p.vez*MM_2_CM,
140  dir.R(),
142 
143  // Add element to collection
144  int pdg = abs(p.pdgID);
145  if ( pdg == 11 )
146  addCompound("e+-", t);
147  else if ( pdg == 12 || pdg == 14 || pdg == 16 )
148  addCompoundLight("Neutrinos", t);
149  else if ( pdg == 22 )
150  addCompound("Gamma", t);
151  else if ( pdg == 13 )
152  addCompound("Muon+-", t);
153  else if ( pdg == 211 )
154  addCompound("Pi+-", t);
155  else if ( pdg == 321 )
156  addCompound("K+-", t);
157  else if ( pdg == 2112 )
158  addCompound("Neutrons", t);
159  else if ( pdg == 2212 )
160  addCompound("Protons", t);
161  else
162  addCompound("Other", t);
163  //cout << "Add particle " << p.id << " to compound." << endl;
164  }
165  else {
166  cout << "SKIP particle " << p.id << "." << endl;
167  }
168 }
TEveTrackPropagator * propagator
void addCompoundLight(const std::string &name, TEveLine *e)
Access sub-compound by name.
Data structure to store the MC particle information.
#define MEV_2_GEV
Definition: EventHandler.h:28
return e
Definition: Volumes.cpp:297
union DD4hep::DisplayConfiguration::Config::Values data
void close()
Close compounds.
#define MM_2_CM
Definition: Handle.h:35
virtual void operator()(const DDEveParticle &particle)
Action callback of this functor:
static Color_t Colors[]
#define CM_2_MM
Definition: Handle.h:32
void addCompound(const std::string &name, TEveLine *e)
Access sub-compound by name.