1212// /
1313// / @file DelphesO2TrackSmearer.h
1414// / @brief Porting to O2Physics of DelphesO2 code.
15- // / Minimal changes have been made to the original code for adaptation purposes, formatting and commented parts have been considered.
1615// / Relevant sources:
1716// / DelphesO2/src/lutCovm.hh https://github.com/AliceO2Group/DelphesO2/blob/master/src/lutCovm.hh
1817// / DelphesO2/src/TrackSmearer.cc https://github.com/AliceO2Group/DelphesO2/blob/master/src/TrackSmearer.cc
2928
3029#include < TRandom.h>
3130
32- #include < cstdio>
3331#include < fstream>
34- #include < iostream>
3532#include < map>
3633#include < string>
3734
38- // /////////////////////////////
39- // / DelphesO2/src/lutCovm.hh //
40- // /////////////////////////////
41-
42- // / @author: Roberto Preghenella
43- // / @email: preghenella@bo.infn.it
44-
45- // #pragma // once
46- #define LUTCOVM_VERSION 20210801
47-
48- struct map_t {
49- int nbins = 1 ;
50- float min = 0 .;
51- float max = 1 .e6 ;
52- bool log = false ;
53- float eval (int bin)
54- {
55- float width = (max - min) / nbins;
56- float val = min + (bin + 0.5 ) * width;
57- if (log)
58- return pow (10 ., val);
59- return val;
60- }
61- // function needed to interpolate some dimensions
62- float fracPositionWithinBin (float val)
63- {
64- float width = (max - min) / nbins;
65- int bin;
66- float returnVal = 0 .5f ;
67- if (log) {
68- bin = static_cast <int >((log10 (val) - min) / width);
69- returnVal = ((log10 (val) - min) / width) - bin;
70- } else {
71- bin = static_cast <int >((val - min) / width);
72- returnVal = val / width - bin;
73- }
74- return returnVal;
75- }
76-
77- int find (float val)
78- {
79- float width = (max - min) / nbins;
80- int bin;
81- if (log)
82- bin = static_cast <int >((log10 (val) - min) / width); // Changed due to MegaLinter error.
83- // bin = (int)((log10(val) - min) / width); // Original line.
84- else
85- bin = static_cast <int >((val - min) / width); // Changed due to MegaLinter error.
86- // bin = (int)((val - min) / width); // Original line.
87- if (bin < 0 )
88- return 0 ;
89- if (bin > nbins - 1 )
90- return nbins - 1 ;
91- return bin;
92- } // ;
93- void print () { printf (" nbins = %d, min = %f, max = %f, log = %s \n " , nbins, min, max, log ? " on" : " off" ); } // ;
94- };
95-
96- struct lutHeader_t {
97- int version = LUTCOVM_VERSION;
98- int pdg = 0 ;
99- float mass = 0 .;
100- float field = 0 .;
101- map_t nchmap;
102- map_t radmap;
103- map_t etamap;
104- map_t ptmap;
105- bool check_version ()
106- {
107- return (version == LUTCOVM_VERSION);
108- } // ;
109- void print ()
110- {
111- printf (" version: %d \n " , version);
112- printf (" pdg: %d \n " , pdg);
113- printf (" field: %f \n " , field);
114- printf (" nchmap: " );
115- nchmap.print ();
116- printf (" radmap: " );
117- radmap.print ();
118- printf (" etamap: " );
119- etamap.print ();
120- printf (" ptmap: " );
121- ptmap.print ();
122- } // ;
123- };
124-
125- struct lutEntry_t {
126- float nch = 0 .;
127- float eta = 0 .;
128- float pt = 0 .;
129- bool valid = false ;
130- float eff = 0 .;
131- float eff2 = 0 .;
132- float itof = 0 .;
133- float otof = 0 .;
134- float covm[15 ] = {0 .};
135- float eigval[5 ] = {0 .};
136- float eigvec[5 ][5 ] = {{0 .}};
137- float eiginv[5 ][5 ] = {{0 .}};
138- void print ()
139- {
140- printf (" --- lutEntry: pt = %f, eta = %f (%s)\n " , pt, eta, valid ? " valid" : " not valid" );
141- printf (" efficiency: %f\n " , eff);
142- printf (" covMatix: " );
143- int k = 0 ;
144- for (int i = 0 ; i < 5 ; ++i) {
145- for (int j = 0 ; j < i + 1 ; ++j)
146- printf (" % e " , covm[k++]);
147- printf (" \n " );
148- }
149- printf (" \n " );
150- }
151- };
152-
153- // //////////////////////////////////
154- // / DelphesO2/src/TrackSmearer.hh //
155- // //////////////////////////////////
156-
157- // / @author: Roberto Preghenella
158- // / @email: preghenella@bo.infn.it
159-
160- // #ifndef _DelphesO2_TrackSmearer_h_
161- // #define _DelphesO2_TrackSmearer_h_
162-
163- // #include "ReconstructionDataFormats/Track.h"
164- // #include "classes/DelphesClasses.h"
165- // #include "lutCovm.hh"
166- // #include <map>
167-
168- using O2Track = o2::track::TrackParCov;
169-
17035namespace o2
17136{
17237namespace delphes
17338{
17439
175- class TrackSmearer
40+ class DelphesO2TrackSmearer : public TNamed
17641{
17742
17843 public:
179- TrackSmearer () = default ;
180- ~TrackSmearer () = default ;
44+ #define LUTCOVM_VERSION 20210801
45+ struct map_t {
46+ int nbins = 1 ;
47+ float min = 0 .;
48+ float max = 1 .e6 ;
49+ bool log = false ;
50+ float eval (int bin)
51+ {
52+ float width = (max - min) / nbins;
53+ float val = min + (bin + 0.5 ) * width;
54+ if (log)
55+ return pow (10 ., val);
56+ return val;
57+ }
58+ // function needed to interpolate some dimensions
59+ float fracPositionWithinBin (float val)
60+ {
61+ float width = (max - min) / nbins;
62+ int bin;
63+ float returnVal = 0 .5f ;
64+ if (log) {
65+ bin = static_cast <int >((log10 (val) - min) / width);
66+ returnVal = ((log10 (val) - min) / width) - bin;
67+ } else {
68+ bin = static_cast <int >((val - min) / width);
69+ returnVal = val / width - bin;
70+ }
71+ return returnVal;
72+ }
73+
74+ int find (float val)
75+ {
76+ float width = (max - min) / nbins;
77+ int bin;
78+ if (log)
79+ bin = static_cast <int >((log10 (val) - min) / width); // Changed due to MegaLinter error.
80+ // bin = (int)((log10(val) - min) / width); // Original line.
81+ else
82+ bin = static_cast <int >((val - min) / width); // Changed due to MegaLinter error.
83+ // bin = (int)((val - min) / width); // Original line.
84+ if (bin < 0 )
85+ return 0 ;
86+ if (bin > nbins - 1 )
87+ return nbins - 1 ;
88+ return bin;
89+ } // ;
90+ void print () { printf (" nbins = %d, min = %f, max = %f, log = %s \n " , nbins, min, max, log ? " on" : " off" ); } // ;
91+ };
92+
93+ struct lutHeader_t {
94+ int version = LUTCOVM_VERSION;
95+ int pdg = 0 ;
96+ float mass = 0 .;
97+ float field = 0 .;
98+ map_t nchmap;
99+ map_t radmap;
100+ map_t etamap;
101+ map_t ptmap;
102+ bool check_version ()
103+ {
104+ return (version == LUTCOVM_VERSION);
105+ } // ;
106+ void print ()
107+ {
108+ printf (" version: %d \n " , version);
109+ printf (" pdg: %d \n " , pdg);
110+ printf (" field: %f \n " , field);
111+ printf (" nchmap: " );
112+ nchmap.print ();
113+ printf (" radmap: " );
114+ radmap.print ();
115+ printf (" etamap: " );
116+ etamap.print ();
117+ printf (" ptmap: " );
118+ ptmap.print ();
119+ } // ;
120+ };
121+
122+ struct lutEntry_t {
123+ float nch = 0 .;
124+ float eta = 0 .;
125+ float pt = 0 .;
126+ bool valid = false ;
127+ float eff = 0 .;
128+ float eff2 = 0 .;
129+ float itof = 0 .;
130+ float otof = 0 .;
131+ float covm[15 ] = {0 .};
132+ float eigval[5 ] = {0 .};
133+ float eigvec[5 ][5 ] = {{0 .}};
134+ float eiginv[5 ][5 ] = {{0 .}};
135+ void print ()
136+ {
137+ printf (" --- lutEntry: pt = %f, eta = %f (%s)\n " , pt, eta, valid ? " valid" : " not valid" );
138+ printf (" efficiency: %f\n " , eff);
139+ printf (" covMatix: " );
140+ int k = 0 ;
141+ for (int i = 0 ; i < 5 ; ++i) {
142+ for (int j = 0 ; j < i + 1 ; ++j)
143+ printf (" % e " , covm[k++]);
144+ printf (" \n " );
145+ }
146+ printf (" \n " );
147+ }
148+ };
149+
150+ DelphesO2TrackSmearer () = default ;
151+ ~DelphesO2TrackSmearer () = default ;
181152
182153 /* * LUT methods **/
183154 bool loadTable (int pdg, const char * filename, bool forceReload = false );
@@ -189,66 +160,17 @@ class TrackSmearer
189160 lutHeader_t* getLUTHeader (int pdg) { return mLUTHeader [getIndexPDG (pdg)]; } // ;
190161 lutEntry_t* getLUTEntry (const int pdg, const float nch, const float radius, const float eta, const float pt, float & interpolatedEff);
191162
192- bool smearTrack (O2Track & o2track, lutEntry_t* lutEntry, float interpolatedEff);
193- bool smearTrack (O2Track & o2track, int pdg, float nch);
163+ bool smearTrack (o2::track::TrackParCov & o2track, lutEntry_t* lutEntry, float interpolatedEff);
164+ bool smearTrack (o2::track::TrackParCov & o2track, int pdg, float nch);
194165 // bool smearTrack(Track& track, bool atDCA = true); // Only in DelphesO2
195166 double getPtRes (const int pdg, const float nch, const float eta, const float pt);
196167 double getEtaRes (const int pdg, const float nch, const float eta, const float pt);
197168 double getAbsPtRes (const int pdg, const float nch, const float eta, const float pt);
198169 double getAbsEtaRes (const int pdg, const float nch, const float eta, const float pt);
199170 double getEfficiency (const int pdg, const float nch, const float eta, const float pt);
200171
201- int getIndexPDG (const int pdg)
202- {
203- switch (abs (pdg)) {
204- case 11 :
205- return 0 ; // Electron
206- case 13 :
207- return 1 ; // Muon
208- case 211 :
209- return 2 ; // Pion
210- case 321 :
211- return 3 ; // Kaon
212- case 2212 :
213- return 4 ; // Proton
214- case 1000010020 :
215- return 5 ; // Deuteron
216- case 1000010030 :
217- return 6 ; // Triton
218- case 1000020030 :
219- return 7 ; // Helium3
220- case 1000020040 :
221- return 8 ; // Alphas
222- default :
223- return 2 ; // Default: pion
224- }
225- }
226-
227- const char * getParticleName (int pdg)
228- {
229- switch (abs (pdg)) {
230- case 11 :
231- return " electron" ;
232- case 13 :
233- return " muon" ;
234- case 211 :
235- return " pion" ;
236- case 321 :
237- return " kaon" ;
238- case 2212 :
239- return " proton" ;
240- case 1000010020 :
241- return " deuteron" ;
242- case 1000010030 :
243- return " triton" ;
244- case 1000020030 :
245- return " helium3" ;
246- case 1000020040 :
247- return " alpha" ;
248- default :
249- return " pion" ; // Default: pion
250- }
251- }
172+ static int getIndexPDG (const int pdg);
173+ const char * getParticleName (int pdg);
252174 void setdNdEta (float val) { mdNdEta = val; } // ;
253175 void setCcdbManager (o2::ccdb::BasicCCDBManager* mgr) { mCcdbManager = mgr; } // ;
254176
@@ -269,10 +191,4 @@ class TrackSmearer
269191} // namespace delphes
270192} // namespace o2
271193
272- // #endif /** _DelphesO2_TrackSmearer_h_ **/
273-
274- namespace o2 ::delphes
275- {
276- using DelphesO2TrackSmearer = TrackSmearer;
277- }
278194#endif // ALICE3_CORE_DELPHESO2TRACKSMEARER_H_
0 commit comments