Line data Source code
1 : #include "AliNanoAODTrackMapping.h"
2 : #include "TString.h"
3 : #include "TObjArray.h"
4 : #include "TObjString.h"
5 : #include "AliLog.h"
6 : #include <iostream>
7 :
8 :
9 170 : ClassImp(AliNanoAODTrackMapping)
10 :
11 : AliNanoAODTrackMapping * AliNanoAODTrackMapping::fInstance = 0;
12 170 : TString AliNanoAODTrackMapping::fMappingString = "";
13 :
14 0 : AliNanoAODTrackMapping::AliNanoAODTrackMapping() :
15 0 : TObject(),
16 0 : fPt(-1),
17 0 : fPhi(-1),
18 0 : fTheta(-1),
19 0 : fChi2PerNDF(-1),
20 0 : fPosX(-1),
21 0 : fPosY(-1),
22 0 : fPosZ(-1),
23 0 : fPDCAX(-1),
24 0 : fPDCAY(-1),
25 0 : fPDCAZ(-1),
26 0 : fPosDCAx(-1),
27 0 : fPosDCAy(-1),
28 0 : fRAtAbsorberEnd(-1),
29 0 : fTPCncls(-1),
30 0 : fid(-1),
31 0 : fTPCnclsF(-1),
32 0 : fTPCNCrossedRows(-1),
33 0 : fTrackPhiOnEMCal(-1),
34 0 : fTrackEtaOnEMCal(-1),
35 0 : fITSsignal(-1),
36 0 : fTPCsignal(-1),
37 0 : fTPCsignalTuned(-1),
38 0 : fTPCsignalN(-1),
39 0 : fTPCmomentum(-1),
40 0 : fTPCTgl(-1),
41 0 : fTOFsignal(-1),
42 0 : fintegratedLenght(-1),
43 0 : fTOFsignalTuned(-1),
44 0 : fHMPIDsignal(-1),
45 0 : fHMPIDoccupancy(-1),
46 0 : fTRDsignal(-1),
47 0 : fTRDChi2(-1),
48 0 : fTRDnSlices(-1),
49 0 : fcovmat(-1)
50 :
51 0 : {
52 : // default ctor
53 :
54 0 : }
55 :
56 0 : AliNanoAODTrackMapping::AliNanoAODTrackMapping(const char * mappingString) :
57 0 : TObject(),
58 0 : fPt(-1),
59 0 : fPhi(-1),
60 0 : fTheta(-1),
61 0 : fChi2PerNDF(-1),
62 0 : fPosX(-1),
63 0 : fPosY(-1),
64 0 : fPosZ(-1),
65 0 : fPDCAX(-1),
66 0 : fPDCAY(-1),
67 0 : fPDCAZ(-1),
68 0 : fPosDCAx(-1),
69 0 : fPosDCAy(-1),
70 0 : fRAtAbsorberEnd(-1),
71 0 : fTPCncls(-1),
72 0 : fid(-1),
73 0 : fTPCnclsF(-1),
74 0 : fTPCNCrossedRows(-1),
75 0 : fTrackPhiOnEMCal(-1),
76 0 : fTrackEtaOnEMCal(-1),
77 0 : fITSsignal(-1),
78 0 : fTPCsignal(-1),
79 0 : fTPCsignalTuned(-1),
80 0 : fTPCsignalN(-1),
81 0 : fTPCmomentum(-1),
82 0 : fTPCTgl(-1),
83 0 : fTOFsignal(-1),
84 0 : fintegratedLenght(-1),
85 0 : fTOFsignalTuned(-1),
86 0 : fHMPIDsignal(-1),
87 0 : fHMPIDoccupancy(-1),
88 0 : fTRDsignal(-1),
89 0 : fTRDChi2(-1),
90 0 : fTRDnSlices(-1),
91 0 : fcovmat(-1)
92 :
93 0 : {
94 : // ctor
95 : //std::cout << "Standard construct " << mappingString << std::endl;
96 :
97 0 : if (fInstance) {
98 0 : AliWarning("Cannot instantiate this class twice");
99 0 : if (fMappingString != mappingString) AliFatal ("Attempt to initialize with a differnt mapping string");
100 : return ;
101 : }
102 0 : fMappingString = mappingString;
103 :
104 : static const char * validatorString[] = {"pt", "theta", "phi", "chi2perNDF", "posx", "posy", "posz", "covmat", "posDCAx","posDCAy", "pDCAx", "pDCAy", "pDCAz", "RAtAbsorberEnd", "TPCnclsF", "TPCNCrossedRows", "TrackPhiOnEMCal", "TrackEtaOnEMCal", "TrackPtOnEMCal", "ITSsignal", "TPCsignal", "TPCsignalTuned", "TPCsignalN", "TPCmomentum", "TPCTgl", "TOFsignal", "integratedLenght", "TOFsignalTuned", "HMPIDsignal", "HMPIDoccupancy", "TRDsignal", "TRDChi2", "TRDnSlices", 0};
105 :
106 : // Tokenize list of variables
107 0 : TString varString(mappingString);
108 0 : TObjArray * vars = varString.Tokenize(",");
109 : // Allocate the internal array, based on size of the tokens array
110 0 : fSize = vars->GetSize();
111 : // Loop over all tokens, check sanity of the vars,
112 0 : TIter it(vars);
113 : TObjString *token = 0;
114 : Int_t index=0;
115 0 : while ((token = (TObjString*) it.Next())) {
116 0 : TString var = token->GetString().Strip(TString::kBoth, ' '); // remove trailing and leading spaces
117 : // Check if string ...
118 : // ... is in the allowed list
119 : Bool_t isValid = kFALSE;
120 : Int_t ivalidator = 0;
121 0 : while (validatorString[ivalidator]) {
122 0 : if(var == validatorString[ivalidator++]) isValid = kTRUE;
123 : }
124 : //... it is custom
125 0 : if (!( isValid || var.BeginsWith("cst")) ) AliFatal(Form("Invalid var [%s]", var.Data()));
126 : // If the variable is valid, add it to the list. We have to create a new TObjstring because otherwise it is deleted with the tokens
127 0 : if (var == "pt" ) fPt = index;
128 0 : else if(var == "phi" ) fPhi = index;
129 0 : else if(var == "theta" ) fTheta = index; // FIXME: consider adding a "eta" variable explicitly (possibly with a check for theta aldready there), so that you don't have to carry over also "theta" in case you only need eta.
130 0 : else if(var == "chi2perNDF" ) fChi2PerNDF = index;
131 0 : else if(var == "posx" ) fPosX = index;
132 0 : else if(var == "posy" ) fPosY = index;
133 0 : else if(var == "posz" ) fPosZ = index;
134 0 : else if(var == "pDCAx" ) fPDCAX = index;
135 0 : else if(var == "pDCAy" ) fPDCAY = index;
136 0 : else if(var == "pDCAz" ) fPDCAZ = index;
137 0 : else if(var == "posDCAx" ) fPosDCAx = index;
138 0 : else if(var == "posDCAy" ) fPosDCAy = index;
139 0 : else if(var == "RAtAbsorberEnd" ) fRAtAbsorberEnd = index;
140 0 : else if(var == "TPCncls" ) fTPCncls = index;
141 0 : else if(var == "id" ) fid = index;
142 0 : else if(var == "TPCnclsF" ) fTPCnclsF = index;
143 0 : else if(var == "TPCNCrossedRows" ) fTPCNCrossedRows = index;
144 0 : else if(var == "TrackPhiOnEMCal" ) fTrackPhiOnEMCal = index;
145 0 : else if(var == "TrackEtaOnEMCal" ) fTrackEtaOnEMCal = index;
146 0 : else if(var == "TrackPtOnEMCal" ) fTrackPtOnEMCal = index;
147 0 : else if(var == "ITSsignal" ) fITSsignal = index;
148 0 : else if(var == "TPCsignal" ) fTPCsignal = index;
149 0 : else if(var == "TPCsignalTuned" ) fTPCsignalTuned = index;
150 0 : else if(var == "TPCsignalN" ) fTPCsignalN = index;
151 0 : else if(var == "TPCmomentum" ) fTPCmomentum = index;
152 0 : else if(var == "TPCTgl" ) fTPCTgl = index;
153 0 : else if(var == "TOFsignal" ) fTOFsignal = index;
154 0 : else if(var == "integratedLenght" ) fintegratedLenght = index;
155 0 : else if(var == "TOFsignalTuned" ) fTOFsignalTuned = index;
156 0 : else if(var == "HMPIDsignal" ) fHMPIDsignal = index;
157 0 : else if(var == "HMPIDoccupancy" ) fHMPIDoccupancy = index;
158 0 : else if(var == "TRDsignal" ) fTRDsignal = index;
159 0 : else if(var == "TRDChi2" ) fTRDChi2 = index;
160 0 : else if(var == "TRDnSlices" ) fTRDnSlices = index;
161 0 : else if(var == "covmat" ) AliFatal("cov matrix To be implemented");
162 : else {
163 0 : fMapCstVar[var] = index;
164 0 : std::cout << "ADDING " << index << " " << fMapCstVar[var] << " " << var.Data() << std::endl;
165 :
166 : }
167 :
168 : // init kin vars to 0
169 0 : index++;
170 0 : }
171 0 : fSize = index;
172 0 : if(vars) vars->Delete();
173 :
174 :
175 0 : }
176 :
177 : Int_t AliNanoAODTrackMapping::GetVarIndex(TString varName){
178 :
179 0 : if (varName == "pt" ) return fPt ;
180 0 : else if(varName == "phi" ) return fPhi ;
181 0 : else if(varName == "theta" ) return fTheta ;
182 0 : else if(varName == "chi2perNDF" ) return fChi2PerNDF ;
183 0 : else if(varName == "posx" ) return fPosX ;
184 0 : else if(varName == "posy" ) return fPosY ;
185 0 : else if(varName == "posz" ) return fPosZ ;
186 0 : else if(varName == "pDCAx" ) return fPDCAX ;
187 0 : else if(varName == "pDCAy" ) return fPDCAY ;
188 0 : else if(varName == "pDCAz" ) return fPDCAZ ;
189 0 : else if(varName == "posDCAx" ) return fPosDCAx ;
190 0 : else if(varName == "posDCAy" ) return fPosDCAy ;
191 0 : else if(varName == "RAtAbsorberEnd" ) return fRAtAbsorberEnd ;
192 0 : else if(varName == "TPCncls" ) return fTPCncls ;
193 0 : else if(varName == "id" ) return fid ;
194 0 : else if(varName == "TPCnclsF" ) return fTPCnclsF ;
195 0 : else if(varName == "TPCNCrossedRows" ) return fTPCNCrossedRows ;
196 0 : else if(varName == "TrackPhiOnEMCal" ) return fTrackPhiOnEMCal ;
197 0 : else if(varName == "TrackEtaOnEMCal" ) return fTrackEtaOnEMCal ;
198 0 : else if(varName == "TrackPtOnEMCal" ) return fTrackPtOnEMCal ;
199 0 : else if(varName == "ITSsignal" ) return fITSsignal ;
200 0 : else if(varName == "TPCsignal" ) return fTPCsignal ;
201 0 : else if(varName == "TPCsignalTuned" ) return fTPCsignalTuned ;
202 0 : else if(varName == "TPCsignalN" ) return fTPCsignalN ;
203 0 : else if(varName == "TPCmomentum" ) return fTPCmomentum ;
204 0 : else if(varName == "TPCTgl" ) return fTPCTgl ;
205 0 : else if(varName == "TOFsignal" ) return fTOFsignal ;
206 0 : else if(varName == "integratedLenght" ) return fintegratedLenght ;
207 0 : else if(varName == "TOFsignalTuned" ) return fTOFsignalTuned ;
208 0 : else if(varName == "HMPIDsignal" ) return fHMPIDsignal ;
209 0 : else if(varName == "HMPIDoccupancy" ) return fHMPIDoccupancy ;
210 0 : else if(varName == "TRDsignal" ) return fTRDsignal ;
211 0 : else if(varName == "TRDChi2" ) return fTRDChi2 ;
212 0 : else if(varName == "TRDnSlices" ) return fTRDnSlices ;
213 :
214 0 : std::map<TString,Int_t>::iterator it = fMapCstVar.find(varName); // FIXME: do I need to delete "it"?
215 0 : if(it != fMapCstVar.end()) {
216 : //element found;
217 0 : return it->second;
218 : }
219 :
220 0 : return -1;
221 :
222 0 : }
223 :
224 : const char * AliNanoAODTrackMapping::GetVarName(Int_t index) const {
225 : // Get Variable name from index
226 0 : if (index == fPt ) return "pt" ;
227 0 : else if(index == fPhi ) return "phi" ;
228 0 : else if(index == fTheta ) return "theta" ;
229 0 : else if(index == fChi2PerNDF ) return "chi2perNDF" ;
230 0 : else if(index == fPosX ) return "posx" ;
231 0 : else if(index == fPosY ) return "posy" ;
232 0 : else if(index == fPosZ ) return "posz" ;
233 0 : else if(index == fPDCAX ) return "pDCAx" ;
234 0 : else if(index == fPDCAY ) return "pDCAy" ;
235 0 : else if(index == fPDCAZ ) return "pDCAz" ;
236 0 : else if(index == fPosDCAx ) return "posDCAx" ;
237 0 : else if(index == fPosDCAy ) return "posDCAy" ;
238 0 : else if(index == fRAtAbsorberEnd ) return "RAtAbsorberEnd" ;
239 0 : else if(index == fTPCncls ) return "TPCncls" ;
240 0 : else if(index == fid ) return "id" ;
241 0 : else if(index == fTPCnclsF ) return "TPCnclsF" ;
242 0 : else if(index == fTPCNCrossedRows ) return "TPCNCrossedRows" ;
243 0 : else if(index == fTrackPhiOnEMCal ) return "TrackPhiOnEMCal" ;
244 0 : else if(index == fTrackEtaOnEMCal ) return "TrackEtaOnEMCal" ;
245 0 : else if(index == fTrackPtOnEMCal ) return "TrackPtOnEMCal" ;
246 0 : else if(index == fITSsignal ) return "ITSsignal" ;
247 0 : else if(index == fTPCsignal ) return "TPCsignal" ;
248 0 : else if(index == fTPCsignalTuned ) return "TPCsignalTuned" ;
249 0 : else if(index == fTPCsignalN ) return "TPCsignalN" ;
250 0 : else if(index == fTPCmomentum ) return "TPCmomentum" ;
251 0 : else if(index == fTPCTgl ) return "TPCTgl" ;
252 0 : else if(index == fTOFsignal ) return "TOFsignal" ;
253 0 : else if(index == fintegratedLenght ) return "integratedLenght" ;
254 0 : else if(index == fTOFsignalTuned ) return "TOFsignalTuned" ;
255 0 : else if(index == fHMPIDsignal ) return "HMPIDsignal" ;
256 0 : else if(index == fHMPIDoccupancy ) return "HMPIDoccupancy" ;
257 0 : else if(index == fTRDsignal ) return "TRDsignal" ;
258 0 : else if(index == fTRDChi2 ) return "TRDChi2" ;
259 0 : else if(index == fTRDnSlices ) return "TRDnSlices" ;
260 0 : if (index >= fSize) {
261 0 : AliWarning(Form("Invalid index %d", index));
262 0 : return "<Invalid index>";
263 : }
264 : else {
265 0 : std::map<TString,Int_t>::const_iterator it ;
266 0 : for (it = fMapCstVar.begin(); it != fMapCstVar.end(); ++it) {
267 0 : if(it->second == index) return it->first.Data();
268 : }
269 0 : }
270 0 : return "<YOU SHOULD NEVER GET THIS>";// Should never happen
271 0 : }
272 :
273 : void AliNanoAODTrackMapping::Print(const Option_t* /*opt*/) const {
274 0 : std::cout << "Printing AliNanoAODTrackMapping" << std::endl;
275 :
276 0 : for (Int_t ivar = 0; ivar<fSize; ivar++) {
277 0 : std::cout << " " << ivar << " " << GetVarName(ivar) << std::endl;
278 : }
279 :
280 0 : }
281 :
282 :
283 : void AliNanoAODTrackMapping::LoadInstance() {
284 :
285 0 : if(!fInstance) { // try to get it from the current file
286 0 : Printf("AliNanoAODTrackMapping::LoadInstance() instance from file");
287 : // Try to get it from the UserInfo of the AOD tree; FIXME: shall we try to probe the Analysis manager?
288 : // FIXME: to be implmented Otherwise, try to get it from the esdTree
289 0 : TTree * tree = (TTree*)gDirectory->Get("aodTree") ? (TTree*)gDirectory->Get("aodTree"): (TTree*)gFile->Get("aodTree");
290 0 : if(!tree) {
291 0 : std::cout << "NO TREE?" << std::endl;
292 0 : gDirectory->ls();
293 0 : gFile->ls();
294 0 : }
295 :
296 :
297 0 : if(tree) {
298 0 : tree->GetUserInfo()->Print();
299 0 : fInstance = new AliNanoAODTrackMapping(*((AliNanoAODTrackMapping*) tree->GetUserInfo()->FindObject("AliNanoAODTrackMapping")));
300 : // Otherwise try to get it from the current directory
301 0 : std::cout << " from tree: " << fInstance << std::endl;
302 :
303 0 : }
304 0 : if(!fInstance) fInstance = (AliNanoAODTrackMapping *) gDirectory->Get("AliNanoAODTrackMapping");
305 0 : if(!fInstance) {
306 0 : Printf("AliNanoAODTrackMapping::LoadInstance(): Not initialized and cannot find in current file");
307 0 : gSystem->Exit(1);
308 0 : }
309 0 : }
310 :
311 :
312 0 : }
|