]>
Commit | Line | Data |
---|---|---|
e75408ba | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | ||
17 | /////////////////////////////////////////////////////////////////////////////// | |
18 | // // | |
19 | // TRD tender: reapply pid on the fly // | |
20 | // // | |
21 | /////////////////////////////////////////////////////////////////////////////// | |
22 | ||
00685073 | 23 | #include <TChain.h> |
24 | #include <TList.h> | |
25 | #include <TObjString.h> | |
26 | #include <TTree.h> | |
27 | #include <TString.h> | |
28 | ||
29 | #include <AliCDBEntry.h> | |
30 | #include <AliCDBId.h> | |
31 | #include <AliCDBManager.h> | |
32 | #include <AliTRDCalDet.h> | |
e75408ba | 33 | |
34 | #include <AliLog.h> | |
35 | #include <TTree.h> | |
36 | #include <TChain.h> | |
37 | #include <AliPID.h> | |
38 | #include <AliVEvent.h> | |
39 | #include <AliESDEvent.h> | |
40 | #include <AliESDpid.h> | |
41 | #include <AliESDtrack.h> | |
42 | #include <AliESDInputHandler.h> | |
43 | #include <AliAnalysisManager.h> | |
44 | #include <AliTRDPIDResponse.h> | |
45 | #include <AliTender.h> | |
46 | ||
47 | #include "AliTRDTenderSupply.h" | |
48 | ||
00685073 | 49 | ClassImp(AliTRDTenderSupply) |
e75408ba | 50 | |
00685073 | 51 | //_____________________________________________________ |
e75408ba | 52 | AliTRDTenderSupply::AliTRDTenderSupply() : |
53 | AliTenderSupply(), | |
00685073 | 54 | fESD(NULL), |
55 | fESDpid(NULL), | |
56 | fChamberGainOld(NULL), | |
57 | fChamberGainNew(NULL), | |
58 | fChamberVdriftOld(NULL), | |
59 | fChamberVdriftNew(NULL), | |
9daf22f8 | 60 | fFileNNref(""), |
61 | fPIDmethod(kNNpid), | |
00685073 | 62 | fPthreshold(0.8), |
63 | fNBadChambers(0), | |
64 | fGainCorrection(kTRUE) | |
e75408ba | 65 | { |
66 | // | |
67 | // default ctor | |
68 | // | |
5f01edb7 | 69 | memset(fBadChamberID, 0, sizeof(Int_t) * kNChambers); |
e75408ba | 70 | } |
71 | ||
72 | //_____________________________________________________ | |
73 | AliTRDTenderSupply::AliTRDTenderSupply(const char *name, const AliTender *tender) : | |
74 | AliTenderSupply(name,tender), | |
00685073 | 75 | fESD(NULL), |
76 | fESDpid(NULL), | |
77 | fChamberGainOld(NULL), | |
78 | fChamberGainNew(NULL), | |
79 | fChamberVdriftOld(NULL), | |
80 | fChamberVdriftNew(NULL), | |
9daf22f8 | 81 | fFileNNref(""), |
82 | fPIDmethod(kNNpid), | |
00685073 | 83 | fPthreshold(0.8), |
84 | fNBadChambers(0), | |
85 | fGainCorrection(kTRUE) | |
e75408ba | 86 | { |
87 | // | |
88 | // named ctor | |
89 | // | |
00685073 | 90 | memset(fBadChamberID, 0, sizeof(Int_t) * kNChambers); |
e75408ba | 91 | } |
92 | ||
00685073 | 93 | //_____________________________________________________ |
e75408ba | 94 | AliTRDTenderSupply::~AliTRDTenderSupply() |
95 | { | |
96 | // | |
97 | // dtor | |
98 | // | |
99 | } | |
100 | ||
101 | //_____________________________________________________ | |
102 | void AliTRDTenderSupply::Init() | |
103 | { | |
104 | // | |
105 | // Initialise TRD tender | |
106 | // | |
107 | ||
e75408ba | 108 | AliAnalysisManager *mgr=AliAnalysisManager::GetAnalysisManager(); |
109 | ||
110 | // 1DLQ PID implemented in the AliESD object | |
111 | fESDpid=fTender->GetESDhandler()->GetESDpid(); | |
112 | if (!fESDpid) { | |
113 | fESDpid=new AliESDpid; | |
114 | fTender->GetESDhandler()->SetESDpid(fESDpid); | |
115 | } | |
116 | // Set Normalisation Factors | |
117 | if(mgr->GetMCtruthEventHandler()){ | |
118 | // Assume MC | |
9daf22f8 | 119 | //fESDpid->GetTRDResponse().SetGainNormalisationFactor(1.); |
00685073 | 120 | SwitchOffGainCorrection(); |
e75408ba | 121 | } |
122 | else{ | |
123 | // Assume Data | |
9daf22f8 | 124 | //if(fPIDmethod == kNNpid) fPidRecal->SetGainScaleFactor(1.14); |
125 | //fESDpid->GetTRDResponse().SetGainNormalisationFactor(1.14); | |
00685073 | 126 | SwitchOnGainCorrection(); |
e75408ba | 127 | } |
e75408ba | 128 | } |
129 | ||
130 | //_____________________________________________________ | |
131 | void AliTRDTenderSupply::ProcessEvent() | |
132 | { | |
133 | // | |
134 | // Reapply pid information | |
135 | // | |
00685073 | 136 | if (fTender->RunChanged()){ |
137 | AliDebug(0, Form("AliTPCTenderSupply::ProcessEvent - Run Changed (%d)\n",fTender->GetRun())); | |
138 | if (fGainCorrection) SetChamberGain(); | |
139 | } | |
e75408ba | 140 | |
00685073 | 141 | fESD = fTender->GetEvent(); |
142 | if (!fESD) return; | |
143 | Int_t ntracks=fESD->GetNumberOfTracks(); | |
144 | ||
145 | // | |
146 | // recalculate PID probabilities | |
147 | // | |
148 | for(Int_t itrack = 0; itrack < ntracks; itrack++){ | |
149 | AliESDtrack *track=fESD->GetTrack(itrack); | |
9daf22f8 | 150 | // Recalculate likelihoods |
00685073 | 151 | if(!(track->GetStatus() & AliESDtrack::kTRDout)) continue; |
152 | if(fGainCorrection) ApplyGainCorrection(track); | |
9daf22f8 | 153 | switch(fPIDmethod){ |
154 | case kNNpid: | |
155 | break; | |
156 | case k1DLQpid: | |
157 | fESDpid->MakeTRDPID(fESD->GetTrack(itrack)); | |
158 | break; | |
159 | default: | |
160 | AliError("PID Method not implemented (yet)"); | |
161 | } | |
00685073 | 162 | } |
163 | } | |
e75408ba | 164 | |
00685073 | 165 | //_____________________________________________________ |
166 | void AliTRDTenderSupply::SetChamberGain(){ | |
167 | // | |
168 | // Load Chamber Gain factors into the Tender supply | |
169 | // | |
e75408ba | 170 | |
00685073 | 171 | //find previous entry from the UserInfo |
0e373bac | 172 | // TTree *tree=((TChain*)fTender->GetInputData(0))->GetTree(); |
173 | AliAnalysisManager*mgr = AliAnalysisManager::GetAnalysisManager(); | |
174 | AliAnalysisTaskSE *task = (AliAnalysisTaskSE*)mgr->GetTasks()->First(); | |
175 | TTree *tree=((TChain*)task->GetInputData(0))->GetTree(); | |
00685073 | 176 | if (!tree) { |
177 | AliError("Tree not found in ESDhandler"); | |
178 | return; | |
179 | } | |
180 | ||
181 | TList *userInfo=(TList*)tree->GetUserInfo(); | |
182 | if (!userInfo) { | |
183 | AliError("No UserInfo found in tree"); | |
184 | return; | |
185 | } | |
186 | ||
187 | TList *cdbList=(TList*)userInfo->FindObject("cdbList"); | |
188 | if (!cdbList) { | |
189 | AliError("No cdbList found in UserInfo"); | |
190 | if (AliLog::GetGlobalLogLevel()>=AliLog::kError) userInfo->Print(); | |
191 | return; | |
192 | } | |
193 | ||
194 | TIter nextCDB(cdbList); | |
195 | TObjString *os=0x0; | |
196 | while ( (os=(TObjString*)nextCDB()) ){ | |
197 | if(os->GetString().Contains("TRD/Calib/ChamberGainFactor")){ | |
198 | // Get Old gain calibration | |
199 | AliCDBId *id=AliCDBId::MakeFromString(os->GetString()); | |
200 | ||
9daf22f8 | 201 | AliCDBEntry *entry=fTender->GetCDBManager()->Get(id->GetPath(), id->GetFirstRun(), id->GetVersion()); |
00685073 | 202 | if (!entry) { |
203 | AliError("No previous gain calibration entry found"); | |
204 | return; | |
205 | } | |
206 | ||
207 | fChamberGainOld = dynamic_cast<AliTRDCalDet *>(entry->GetObject()); | |
208 | ||
209 | AliDebug(1, Form("Used old Gain entry: %s\n",entry->GetId().ToString().Data())); | |
210 | } else if(os->GetString().Contains("TRD/Calib/ChamberVdrift")){ | |
211 | // Get Old drift velocity calibration | |
212 | AliCDBId *id=AliCDBId::MakeFromString(os->GetString()); | |
213 | ||
9daf22f8 | 214 | AliCDBEntry *entry=fTender->GetCDBManager()->Get(id->GetPath(), id->GetFirstRun(), id->GetVersion()); |
00685073 | 215 | if (!entry) { |
216 | AliError("No previous drift velocity calibration entry found"); | |
217 | return; | |
218 | } | |
219 | ||
220 | fChamberVdriftOld = dynamic_cast<AliTRDCalDet *>(entry->GetObject()); | |
221 | ||
222 | AliDebug(1, Form("Used old Drift velocity entry: %s\n",entry->GetId().ToString().Data())); | |
223 | ||
224 | } | |
225 | } | |
226 | ||
227 | // Get Latest Gain Calib Object | |
228 | AliCDBEntry *entryNew=fTender->GetCDBManager()->Get("TRD/Calib/ChamberGainFactor",fTender->GetRun()); | |
229 | if (entryNew) { | |
230 | AliDebug(1, Form("Used new Gain entry: %s\n",entryNew->GetId().ToString().Data())); | |
231 | fChamberGainNew = dynamic_cast<AliTRDCalDet *>(entryNew->GetObject()); | |
232 | } else | |
233 | AliError("No new gain calibration entry found"); | |
234 | ||
235 | // Also get the latest Drift Velocity calibration object | |
236 | entryNew=fTender->GetCDBManager()->Get("TRD/Calib/ChamberVdrift",fTender->GetRun()); | |
237 | if (entryNew) { | |
238 | AliDebug(1, Form("Used new Drift velocity entry: %s\n",entryNew->GetId().ToString().Data())); | |
239 | fChamberVdriftNew = dynamic_cast<AliTRDCalDet *>(entryNew->GetObject()); | |
240 | } else | |
241 | AliError("No new drift velocity calibration entry found"); | |
242 | ||
243 | if(!fChamberGainNew || !fChamberVdriftNew) AliError("No recent calibration found"); | |
244 | } | |
245 | ||
246 | //_____________________________________________________ | |
247 | void AliTRDTenderSupply::ApplyGainCorrection(AliESDtrack * track){ | |
e75408ba | 248 | // |
00685073 | 249 | // Apply new gain factors to the track |
e75408ba | 250 | // |
00685073 | 251 | if(!fChamberGainNew || !fChamberGainOld){ |
252 | AliError("Cannot apply gain correction."); | |
253 | return; | |
254 | } | |
255 | ||
256 | if(!(track->GetStatus() & AliESDtrack::kTRDout)) return; | |
257 | Double_t p = track->GetOuterParam() ? track->GetOuterParam()->P() : track->P(); | |
258 | if(p < fPthreshold) return; // Apply low momentum cutoff | |
259 | ||
260 | Bool_t applyCorrectionVdrift = kFALSE; | |
261 | if(fChamberVdriftOld && fChamberVdriftNew) applyCorrectionVdrift = kTRUE; | |
262 | ||
263 | Int_t chamberID[kNPlanes]; | |
264 | for(Int_t il = 0; il < kNPlanes; il++) chamberID[il] = -1; | |
265 | if(!GetTRDchamberID(track, chamberID)) return; | |
266 | Int_t nTrackletsPID = 0, nTracklets = track->GetTRDntracklets(); | |
267 | for(Int_t iplane = 0; iplane < kNPlanes; iplane++){ | |
268 | if(chamberID[iplane] < 0) continue; | |
269 | ||
270 | // Mask out bad chambers | |
271 | Bool_t isMasked = kFALSE; | |
272 | for(UInt_t icam = 0; icam < fNBadChambers; icam++) | |
273 | if(fBadChamberID[icam] == chamberID[iplane]){ | |
274 | isMasked = kTRUE; | |
275 | break; | |
276 | } | |
277 | if(isMasked){ | |
278 | for(Int_t islice = 0; islice < track->GetNumberOfTRDslices(); islice++){ | |
279 | track->SetTRDslice(0, iplane, islice); | |
280 | } | |
281 | continue; | |
282 | } | |
283 | ||
284 | // Take old and new gain factor and make ratio | |
285 | Double_t facOld = fChamberGainOld->GetValue(chamberID[iplane]); | |
286 | Double_t facNew = fChamberGainNew->GetValue(chamberID[iplane]); | |
287 | Double_t correction = facNew/facOld; | |
288 | if(applyCorrectionVdrift){ | |
289 | // apply also correction for drift velocity calibration | |
290 | Double_t vDriftOld = fChamberVdriftOld->GetValue(chamberID[iplane]); | |
291 | Double_t vDriftNew = fChamberVdriftNew->GetValue(chamberID[iplane]); | |
292 | correction *= vDriftNew/vDriftOld; | |
293 | } | |
294 | AliDebug(2, Form("Applying correction factor %f\n", correction)); | |
295 | Int_t nSlices = 0; | |
296 | for(Int_t islice = 0; islice < track->GetNumberOfTRDslices(); islice++){ | |
297 | Double_t qslice = track->GetTRDslice(iplane, islice); | |
298 | if(qslice <= 0.) continue; | |
299 | track->SetTRDslice(qslice / correction, iplane, islice); | |
300 | nSlices++; | |
301 | } | |
302 | if(nSlices) nTrackletsPID++; | |
303 | } | |
304 | // Use nTrackletsPID to indicate the number of tracklets from good | |
305 | // chambers so they are used for the PID | |
306 | track->SetTRDntracklets(nTrackletsPID | (nTracklets << 3)); | |
307 | } | |
308 | ||
309 | //_____________________________________________________ | |
310 | Bool_t AliTRDTenderSupply::GetTRDchamberID(AliESDtrack * const track, Int_t *detectors) { | |
311 | // | |
312 | // Calculate TRD chamber ID | |
313 | // | |
314 | Double_t xLayer[kNPlanes] = {300.2, 312.8, 325.4, 338., 350.6, 363.2}; | |
315 | Double_t etamin[kNStacks] = {0.536, 0.157, -0.145, -0.527,-0.851}; | |
316 | Double_t etamax[kNStacks] = {0.851, 0.527, 0.145, -0.157,-0.536}; | |
317 | for(Int_t ily = 0; ily < kNPlanes; ily++) detectors[ily] = -1; | |
318 | ||
319 | const AliExternalTrackParam *trueparam = NULL; | |
320 | if(track->GetTPCInnerParam()) trueparam = track->GetTPCInnerParam(); | |
321 | else if(track->GetOuterParam()) trueparam = track->GetOuterParam(); | |
322 | else if(track->GetInnerParam()) trueparam = track->GetInnerParam(); | |
323 | if(!trueparam){ | |
324 | AliDebug(2, "No Track Params"); | |
325 | return kFALSE; | |
326 | } | |
327 | ||
328 | AliExternalTrackParam workparam(*trueparam); // Do calculation on working Copy | |
329 | Double_t pos[3]; | |
330 | Int_t nDet = 0; | |
331 | for(Int_t ily = 0; ily < kNPlanes; ily++){ | |
332 | if(!workparam.PropagateTo(xLayer[ily], fESD->GetMagneticField())) { | |
333 | AliDebug(2, "Propagation failed"); | |
e75408ba | 334 | break; |
00685073 | 335 | } |
336 | workparam.GetXYZ(pos); | |
337 | Double_t trackAlpha = TMath::ATan2(pos[1], pos[0]); | |
338 | if(trackAlpha < 0) trackAlpha = 2 * TMath::Pi() + trackAlpha; | |
339 | Double_t secAlpha = 2 * TMath::Pi() / 18.; | |
340 | ||
341 | Int_t sector = static_cast<Int_t>(trackAlpha/secAlpha); | |
342 | Double_t etaTrack = track->Eta(); | |
343 | Int_t stack = -1; | |
344 | for(Int_t istack = 0; istack < 5; istack++){ | |
345 | if(etaTrack >= etamin[istack] && etaTrack <= etamax[istack]){ | |
346 | stack = istack; | |
347 | break; | |
348 | } | |
349 | } | |
350 | if(stack < 0) { | |
351 | AliDebug(2, "Dead Area"); | |
352 | continue; | |
353 | } | |
354 | ||
355 | detectors[ily] = sector * kNStacks * kNPlanes + stack * kNPlanes + ily; | |
356 | nDet++; | |
e75408ba | 357 | } |
00685073 | 358 | return nDet ? kTRUE : kFALSE; |
e75408ba | 359 | } |
00685073 | 360 |