1414#include " R3BMCTracks.h"
1515#include " R3BEventManager.h"
1616
17- #include " FairEventManager.h" // for FairEventManager
18- #include " FairLogger.h"
19- #include " FairRootManager.h" // for FairRootManager
17+ #include < FairEventManager.h> // for FairEventManager
18+ #include < FairLogger.h>
19+ #include < FairRootManager.h> // for FairRootManager
2020
2121#include < TClonesArray.h> // for TClonesArray
2222#include < TEveManager.h> // for TEveManager, gEve
2929#include < TObjArray.h> // for TObjArray
3030#include < TParticle.h> // for TParticle
3131#include < cstring> // for strcmp
32-
3332#include < iostream>
33+ #include < sstream>
34+ #include < string>
35+
3436using std::cout;
3537using std::endl;
3638
3739// ----- Default constructor -------------------------------------------
38- R3BMCTracks::R3BMCTracks ()
39- : FairTask(" R3BMCTracks" , 0 )
40- , fTrackList(nullptr )
41- , fTrPr(nullptr )
42- , fEventManager(nullptr )
43- , fEveTrList(nullptr )
44- , fEvent(" " )
45- , fTrList(nullptr )
46- , MinEnergyLimit(-1 .)
47- , MaxEnergyLimit(-1 .)
48- , PEnergy(-1 .)
49- {
50- }
51-
5240R3BMCTracks::R3BMCTracks (const char * name, Int_t iVerbose)
5341 : FairTask(name, iVerbose)
54- , fTrackList(nullptr )
55- , fTrPr(nullptr )
56- , fEventManager(nullptr )
5742 , fEveTrList(new TObjArray(16 ))
58- , fEvent(" " )
59- , fTrList(nullptr )
60- , MinEnergyLimit(-1 .)
61- , MaxEnergyLimit(-1 .)
62- , PEnergy(-1 .)
6343{
6444}
6545
@@ -68,7 +48,7 @@ InitStatus R3BMCTracks::Init()
6848 if (fVerbose > 1 )
6949 cout << " R3BMCTracks::Init()" << endl;
7050
71- FairRootManager* fManager = FairRootManager::Instance ();
51+ auto fManager = FairRootManager::Instance ();
7252 fTrackList = dynamic_cast <TClonesArray*>(fManager ->GetObject (" GeoTracks" ));
7353 if (fTrackList == 0 )
7454 {
@@ -93,26 +73,25 @@ InitStatus R3BMCTracks::Init()
9373 return kERROR ;
9474}
9575
96- void R3BMCTracks::Exec (Option_t* option )
76+ void R3BMCTracks::Exec (Option_t*)
9777{
9878 if (IsActive ())
9979 {
100-
10180 if (fVerbose > 1 )
10281 cout << " FairMCTracks::Exec " << endl;
10382 TGeoTrack* tr;
10483 const Double_t* point;
10584
10685 Reset ();
10786
108- for (Int_t i = 0 ; i < fTrackList ->GetEntriesFast (); i++)
87+ for (size_t i = 0 ; i < fTrackList ->GetEntriesFast (); i++)
10988 {
11089 if (fVerbose > 2 )
11190 cout << " FairMCTracks::Exec " << i << endl;
11291 tr = dynamic_cast <TGeoTrack*>(fTrackList ->At (i));
113- TParticle* P = dynamic_cast <TParticle*>(tr->GetParticle ());
92+ auto Par = dynamic_cast <TParticle*>(tr->GetParticle ());
11493
115- PEnergy = (P ->Energy () - P ->GetCalcMass ()) * 1000 ; // [MeV]
94+ PEnergy = (Par ->Energy () - Par ->GetCalcMass ()) * 1000 ; // [MeV]
11695 MinEnergyLimit = TMath::Min (PEnergy - 10 , MinEnergyLimit);
11796 MinEnergyLimit = TMath::Max (0.0 , MinEnergyLimit);
11897 MaxEnergyLimit = TMath::Max (PEnergy + 10 , MaxEnergyLimit);
@@ -121,7 +100,7 @@ void R3BMCTracks::Exec(Option_t* option)
121100
122101 if (fVerbose > 2 )
123102 cout << " MinEnergyLimit " << MinEnergyLimit << " MaxEnergyLimit " << MaxEnergyLimit << endl;
124- if (fEventManager ->IsPriOnly () && P ->GetMother (0 ) > -1 )
103+ if (fEventManager ->IsPriOnly () && Par ->GetMother (0 ) > -1 )
125104 continue ;
126105 if (fEventManager ->GetCurrentPDG () != 0 && fEventManager ->GetCurrentPDG () != tr->GetPDG ())
127106 continue ;
@@ -136,13 +115,13 @@ void R3BMCTracks::Exec(Option_t* option)
136115 if (fVerbose > 3 )
137116 cout << " Particle with PDG " << tr->GetPDG () << " added to DataBase " << endl;
138117 if (fVerbose > 3 )
139- cout << " Particle " << P << " and propagator " << fTrPr << endl;
118+ cout << " Particle " << Par << " and propagator " << fTrPr << endl;
140119
141120 Int_t Np = tr->GetNpoints ();
142- fTrList = GetTrGroup (P );
121+ fTrList = GetTrGroup (Par );
143122 if (fVerbose > 3 )
144123 cout << " Track list: " << fTrList << " - " << fTrList ->GetLimP () << " - " << fTrList ->GetMaxP () << endl;
145- TEveTrack* track = new TEveTrack (P , tr->GetPDG (), fTrPr );
124+ auto track = new TEveTrack (Par , tr->GetPDG (), fTrPr );
146125 if (fVerbose > 3 )
147126 cout << " Track: " << track << " - " << track->GetPdg () << " - " << track->GetLabel () << endl;
148127 if (tr->GetPDG () > 5000000 )
@@ -156,30 +135,37 @@ void R3BMCTracks::Exec(Option_t* option)
156135 track->SetLineStyle (9 );
157136
158137 // Set Title / Tooltip
159- char title[100 ];
160- sprintf (title,
161- " pdg: %i, name: %s\n TrackID: %i, MotherID: %i\n E: %f MeV\n T: %f ns" ,
162- tr->GetPDG (),
163- P->GetTitle (),
164- i,
165- P->GetMother (0 ),
166- PEnergy,
167- P->T ());
168- track->SetTitle (title);
138+ std::ostringstream oss;
139+ if (tr->GetPDG () < 5000000 )
140+ {
141+ oss << " PDG: " << tr->GetPDG () << " , name: " << Par->GetTitle () << " \n TrackID: " << i
142+ << " , MotherID: " << Par->GetMother (0 ) << " \n Mass: " << Par->GetMass () * 1000 . << " MeV"
143+ << " \n E: " << PEnergy << " MeV"
144+ << " \n Strangeness: " << Par->Strangeness () << " \n T: " << Par->T () / 1e-9 << " ns" ;
145+ }
146+ else
147+ {
148+ auto mass = (tr->GetPDG () / 10 ) % 1000 ;
149+ oss << " PDG: " << tr->GetPDG () << " , name: " << Par->GetTitle () << " \n TrackID: " << i
150+ << " , MotherID: " << Par->GetMother (0 ) << " \n Mass: " << mass << " (A)"
151+ << " \n E: " << PEnergy / mass << " MeV/u"
152+ << " \n Strangeness: " << Par->Strangeness () << " \n T: " << Par->T () / 1e-9 << " ns" ;
153+ }
154+ track->SetTitle (oss.str ().c_str ());
169155
170156 // Set the line width depending on energy
171157 if ((dynamic_cast <R3BEventManager*>(fEventManager ))->IsScaleByEnergy ())
172158 {
173- Int_t lineWidth =
159+ auto lineWidth =
174160 (Int_t)(PEnergy / TMath::Min (fEventManager ->GetMaxEnergy (), (Float_t)MaxEnergyLimit) * 15.0 );
175161 if (fVerbose > 3 )
176- cout << " lineWidth: " << lineWidth << " for track " << track->GetPdg () << " - " << P ->GetTitle ()
162+ cout << " lineWidth: " << lineWidth << " for track " << track->GetPdg () << " - " << Par ->GetTitle ()
177163 << endl;
178164
179165 if (lineWidth > 0 )
180166 {
181167 track->SetLineWidth (lineWidth);
182- if (P ->GetMother (0 ) > -1 )
168+ if (Par ->GetMother (0 ) > -1 )
183169 track->SetLineStyle (2 );
184170 }
185171 else
@@ -189,57 +175,42 @@ void R3BMCTracks::Exec(Option_t* option)
189175 }
190176 }
191177
192- for (Int_t n = 0 ; n < Np; n++)
178+ for (size_t n = 0 ; n < Np; n++)
193179 {
194180 point = tr->GetPoint (n);
195181 track->SetPoint (n, point[0 ], point[1 ], point[2 ]);
196- TEveVector pos = TEveVector (point[0 ], point[1 ], point[2 ]);
197- TEvePathMark* path = new TEvePathMark ();
182+ auto pos = TEveVector (point[0 ], point[1 ], point[2 ]);
183+ auto path = std::make_unique< TEvePathMark> ();
198184 path->fV = pos;
199185 path->fTime = point[3 ];
200186 if (n == 0 )
201187 {
202- TEveVector Mom = TEveVector (P ->Px (), P ->Py (), P ->Pz ());
188+ auto Mom = TEveVector (Par ->Px (), Par ->Py (), Par ->Pz ());
203189 path->fP = Mom;
204190 }
205191 if (fVerbose > 3 )
206- cout << " Path marker added " << path << endl;
192+ cout << " Path marker added " << path. get () << endl;
207193
208- #if ROOT_VERSION_CODE <= ROOT_VERSION(5, 18, 0)
209- track->AddPathMark (path);
210- #else
211194 track->AddPathMark (*path);
212- # endif
195+
213196 if (fVerbose > 3 )
214- cout << " Path marker added " << path << endl;
197+ cout << " Path marker added " << path. get () << endl;
215198 }
216199 fTrList ->AddElement (track);
217200 if (fVerbose > 3 )
218201 cout << " track added " << track->GetName () << endl;
219202 }
220-
221- for (Int_t i = 0 ; i < fEveTrList ->GetEntriesFast (); i++)
222- {
223- // TEveTrackList *TrListIn=( TEveTrackList *) fEveTrList->At(i);
224- // TrListIn->FindMomentumLimits(TrListIn, kFALSE);
225- }
226203 fEventManager ->SetEvtMaxEnergy (MaxEnergyLimit);
227204 fEventManager ->SetEvtMinEnergy (MinEnergyLimit);
228205 gEve ->Redraw3D (kFALSE );
229206 }
230207}
231208
232- R3BMCTracks::~R3BMCTracks () {}
233-
234- void R3BMCTracks::SetParContainers () {}
235-
236- void R3BMCTracks::Finish () {}
237-
238209void R3BMCTracks::Reset ()
239210{
240- for (Int_t i = 0 ; i < fEveTrList ->GetEntriesFast (); i++)
211+ for (size_t i = 0 ; i < fEveTrList ->GetEntriesFast (); i++)
241212 {
242- TEveTrackList* ele = static_cast <TEveTrackList*>(fEveTrList ->At (i));
213+ auto ele = static_cast <TEveTrackList*>(fEveTrList ->At (i));
243214 gEve ->RemoveElement (ele, fEventManager );
244215 }
245216 fEveTrList ->Clear ();
@@ -248,9 +219,9 @@ void R3BMCTracks::Reset()
248219TEveTrackList* R3BMCTracks::GetTrGroup (TParticle* P)
249220{
250221 fTrList = 0 ;
251- for (Int_t i = 0 ; i < fEveTrList ->GetEntriesFast (); i++)
222+ for (size_t i = 0 ; i < fEveTrList ->GetEntriesFast (); i++)
252223 {
253- TEveTrackList* TrListIn = static_cast <TEveTrackList*>(fEveTrList ->At (i));
224+ auto TrListIn = static_cast <TEveTrackList*>(fEveTrList ->At (i));
254225 if (strcmp (TrListIn->GetName (), P->GetName ()) == 0 )
255226 {
256227 fTrList = TrListIn;
@@ -269,4 +240,4 @@ TEveTrackList* R3BMCTracks::GetTrGroup(TParticle* P)
269240 return fTrList ;
270241}
271242
272- ClassImp (R3BMCTracks);
243+ ClassImp (R3BMCTracks)
0 commit comments