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