]>
Commit | Line | Data |
---|---|---|
1ee39b3a | 1 | #include "TPDGCode.h" |
2 | #include "TFile.h" | |
3 | #include "TTree.h" | |
4 | #include "TEventList.h" | |
5 | #include "TObjArray.h" | |
6 | #include "TH2.h" | |
7 | ||
8 | #include "AliLog.h" | |
9 | #include "AliESDtrack.h" | |
10 | #include "AliTrackReference.h" | |
11 | ||
12 | #include "AliTRDReconstructor.h" | |
13 | #include "AliTRDtrackV1.h" | |
14 | #include "AliTRDseedV1.h" | |
15 | #include "AliTRDpidRefMaker.h" | |
16 | #include "info/AliTRDv0Info.h" | |
17 | ||
18 | ||
19 | // Defines and implements basic functionality for building reference data for TRD PID. | |
20 | // | |
21 | // Here is the list of functionality provided by this class | |
22 | // 1. | |
23 | // 2. | |
24 | // | |
25 | // Authors: | |
26 | // Alex Bercuci <A.Bercuci@gsi.de> | |
27 | // Alex Wilk <wilka@uni-muenster.de> | |
28 | // Markus Fasel <mfasel@gsi.de> | |
29 | // Markus Heide <mheide@uni-muenster.de> | |
30 | // | |
31 | ||
32 | ClassImp(AliTRDpidRefMaker) | |
33 | ClassImp(AliTRDpidRefMaker::AliTRDpidRefData) | |
34 | ClassImp(AliTRDpidRefMaker::AliTRDpidRefDataArray) | |
35 | ||
36 | //________________________________________________________________________ | |
37 | AliTRDpidRefMaker::AliTRDpidRefDataArray::AliTRDpidRefDataArray() : | |
38 | fNtracklets(0) | |
b91fdd71 | 39 | ,fData(NULL) |
1ee39b3a | 40 | { |
41 | // Constructor of data array | |
42 | fData = new AliTRDpidRefData[AliTRDgeometry::kNlayer]; | |
43 | } | |
44 | ||
45 | //________________________________________________________________________ | |
46 | AliTRDpidRefMaker::AliTRDpidRefDataArray::~AliTRDpidRefDataArray() | |
47 | { | |
48 | // Destructor | |
49 | delete [] fData; | |
50 | } | |
51 | ||
52 | //________________________________________________________________________ | |
53 | void AliTRDpidRefMaker::AliTRDpidRefDataArray::PushBack(Int_t ly, Int_t p, Float_t *dedx) | |
54 | { | |
55 | // Add PID data to the end of the array | |
56 | fData[fNtracklets].fPLbin= (ly<<4) | (p&0xf); | |
57 | memcpy(fData[fNtracklets].fdEdx, dedx, 8*sizeof(Float_t)); | |
58 | fNtracklets++; | |
59 | } | |
60 | ||
61 | //________________________________________________________________________ | |
62 | void AliTRDpidRefMaker::AliTRDpidRefDataArray::Reset() | |
63 | { | |
64 | // Reset content | |
65 | ||
66 | if(!fNtracklets) return; | |
67 | while(fNtracklets--){ | |
68 | fData[fNtracklets].fPLbin = 0xff; | |
69 | memset(fData[fNtracklets].fdEdx, 0, 8*sizeof(Float_t)); | |
70 | } | |
71 | fNtracklets=0; | |
72 | } | |
73 | ||
705f8b0a | 74 | //________________________________________________________________________ |
75 | AliTRDpidRefMaker::AliTRDpidRefMaker() | |
76 | :AliTRDrecoTask() | |
77 | ,fReconstructor(NULL) | |
78 | ,fV0s(NULL) | |
79 | ,fData(NULL) | |
80 | ,fInfo(NULL) | |
81 | ,fPIDdataArray(NULL) | |
82 | ,fRefPID(kMC) | |
83 | ,fRefP(kMC) | |
84 | ,fPIDbin(0xff) | |
85 | ,fFreq(1.) | |
86 | ,fP(-1.) | |
87 | ,fPthreshold(0.) | |
88 | { | |
89 | // | |
90 | // Default constructor | |
91 | // | |
92 | SetNameTitle("PIDrefMaker", "PID Reference Maker"); | |
93 | } | |
94 | ||
1ee39b3a | 95 | //________________________________________________________________________ |
96 | AliTRDpidRefMaker::AliTRDpidRefMaker(const char *name, const char *title) | |
97 | :AliTRDrecoTask(name, title) | |
b91fdd71 | 98 | ,fReconstructor(NULL) |
99 | ,fV0s(NULL) | |
100 | ,fData(NULL) | |
101 | ,fInfo(NULL) | |
102 | ,fPIDdataArray(NULL) | |
1ee39b3a | 103 | ,fRefPID(kMC) |
104 | ,fRefP(kMC) | |
105 | ,fPIDbin(0xff) | |
106 | ,fFreq(1.) | |
107 | ,fP(-1.) | |
108 | ,fPthreshold(0.5) | |
109 | { | |
110 | // | |
111 | // Default constructor | |
112 | // | |
113 | ||
114 | fReconstructor = new AliTRDReconstructor(); | |
115 | fReconstructor->SetRecoParam(AliTRDrecoParam::GetLowFluxParam()); | |
116 | memset(fdEdx, 0, 10*sizeof(Float_t)); | |
117 | memset(fPID, 0, AliPID::kSPECIES*sizeof(Float_t)); | |
118 | ||
705f8b0a | 119 | DefineInput(2, TObjArray::Class()); // v0 list |
120 | DefineInput(3, TObjArray::Class()); // pid info list | |
121 | DefineOutput(2, TTree::Class()); | |
1ee39b3a | 122 | } |
123 | ||
124 | ||
125 | //________________________________________________________________________ | |
126 | AliTRDpidRefMaker::~AliTRDpidRefMaker() | |
127 | { | |
128 | if(fPIDdataArray) delete fPIDdataArray; | |
129 | if(fReconstructor) delete fReconstructor; | |
130 | } | |
131 | ||
132 | //________________________________________________________________________ | |
133 | Bool_t AliTRDpidRefMaker::CheckQuality(AliTRDseedV1* /*trklt*/) | |
134 | { | |
135 | // Place holder for checking tracklet quality for PID. | |
136 | return kTRUE; | |
137 | } | |
138 | ||
139 | ||
140 | //________________________________________________________________________ | |
141 | Float_t* AliTRDpidRefMaker::CookdEdx(AliTRDseedV1 *trklt) | |
142 | { | |
143 | trklt->CookdEdx(AliTRDpidUtil::kNNslices); | |
144 | memcpy(fdEdx, trklt->GetdEdx(), AliTRDpidUtil::kNNslices*sizeof(Float_t)); | |
145 | return fdEdx; | |
146 | } | |
147 | ||
148 | ||
1ee39b3a | 149 | //________________________________________________________________________ |
f8f46e4d | 150 | void AliTRDpidRefMaker::UserCreateOutputObjects() |
1ee39b3a | 151 | { |
152 | // Create histograms | |
153 | // Called once | |
154 | ||
1ee39b3a | 155 | fContainer = new TObjArray(); |
156 | fContainer->SetName(Form("Moni%s", GetName())); | |
157 | ||
158 | TH2 *h2 = new TH2I("hPDG","Particle abundance", AliPID::kSPECIES, -0.5, 4.5, AliTRDCalPID::kNMom, -0.5, AliTRDCalPID::kNMom-0.5); | |
159 | TAxis *ax = h2->GetXaxis(); | |
160 | ax->SetNdivisions(505); | |
161 | ax->SetTitle("Particle species"); | |
162 | for(Int_t is=AliPID::kSPECIES; is--;) ax->SetBinLabel(is+1, AliPID::ParticleShortName(is)); | |
163 | h2->GetYaxis()->SetTitle("P bins"); | |
164 | h2->GetYaxis()->SetNdivisions(511); | |
165 | ||
166 | fContainer->AddAt(h2, 0); | |
167 | ||
168 | fData = new TTree(GetName(), Form("Reference data for %s", GetName())); | |
169 | fData->Branch("s", &fPIDbin, "s/b"); | |
170 | fData->Branch("data", &fPIDdataArray); | |
171 | } | |
172 | ||
173 | //________________________________________________________________________ | |
f8f46e4d | 174 | void AliTRDpidRefMaker::UserExec(Option_t *) |
1ee39b3a | 175 | { |
176 | // Main loop | |
177 | // Called for each event | |
178 | ||
87c9fc00 | 179 | if(!(fTracks = dynamic_cast<TObjArray*>(GetInputData(1)))) return; |
180 | if(!(fV0s = dynamic_cast<TObjArray*>(GetInputData(2)))) return; | |
181 | if(!(fInfo = dynamic_cast<TObjArray*>(GetInputData(3)))) return; | |
705f8b0a | 182 | |
87c9fc00 | 183 | AliDebug(1, Form("Analyse N[%d] tracks", fTracks->GetEntriesFast())); |
b91fdd71 | 184 | AliTRDtrackInfo *track = NULL; |
185 | AliTRDtrackV1 *trackTRD = NULL; | |
186 | AliTrackReference *ref = NULL; | |
187 | const AliTRDtrackInfo::AliESDinfo *infoESD = NULL; | |
1ee39b3a | 188 | for(Int_t itrk=0; itrk<fTracks->GetEntriesFast(); itrk++){ |
189 | track = (AliTRDtrackInfo*)fTracks->UncheckedAt(itrk); | |
190 | if(!track->HasESDtrack()) continue; | |
191 | trackTRD = track->GetTrack(); | |
192 | infoESD = track->GetESDinfo(); | |
193 | Double32_t *infoPID = infoESD->GetSliceIter(); | |
194 | Int_t n = infoESD->GetNSlices() - AliTRDgeometry::kNlayer; | |
46760dda | 195 | if(n==0){ |
196 | AliWarning(Form("dEdx info missing in ESD track %d", itrk)); | |
197 | continue; | |
198 | } | |
1ee39b3a | 199 | Double32_t *p = &infoPID[n]; |
4226db3e | 200 | AliDebug(4, Form("n[%d] p[GeV/c]{%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f}", n, p[0], p[1], p[2], p[3], p[4], p[5])); |
1ee39b3a | 201 | |
202 | ULong_t status = track->GetStatus(); | |
203 | if(!(status&AliESDtrack::kTPCout)) continue; | |
204 | ||
205 | // fill the pid information | |
206 | SetRefPID(fRefPID, track, fPID); | |
207 | ||
208 | // prepare PID data array | |
209 | if(!fPIDdataArray){ | |
210 | fPIDdataArray = new AliTRDpidRefDataArray(); | |
211 | } else fPIDdataArray->Reset(); | |
212 | ||
213 | // fill PID information | |
214 | for(Int_t ily = 0; ily < AliTRDgeometry::kNlayer; ily++){ | |
215 | ||
216 | // fill P & dE/dx information | |
217 | if(HasFriends()){ // from TRD track | |
218 | if(!trackTRD) continue; | |
b91fdd71 | 219 | AliTRDseedV1 *trackletTRD(NULL); |
1ee39b3a | 220 | trackTRD -> SetReconstructor(fReconstructor); |
221 | if(!(trackletTRD = trackTRD -> GetTracklet(ily))) continue; | |
222 | if(!CheckQuality(trackletTRD)) continue; | |
223 | if(!CookdEdx(trackletTRD)) continue; | |
224 | ||
225 | // fill momentum information | |
226 | fP = 0.; | |
227 | switch(fRefP){ | |
228 | case kMC: | |
229 | if(!(ref = track->GetTrackRef(trackletTRD))) continue; | |
230 | fP = ref->P(); | |
231 | break; | |
232 | case kRec: | |
233 | fP = trackletTRD->GetMomentum(); | |
234 | break; | |
235 | default: continue; | |
236 | } | |
237 | } else { // from ESD track | |
238 | // fill momentum information | |
239 | switch(fRefP){ | |
240 | case kMC: | |
241 | if(!(ref = track->GetTrackRef(ily))) continue; | |
242 | fP = ref->P(); | |
243 | break; | |
244 | case kRec: | |
245 | fP = p[ily]; | |
246 | break; | |
247 | default: continue; | |
248 | } | |
249 | Double32_t *it = &infoPID[ily*AliTRDCalPID::kNSlicesNN]; | |
250 | for(Int_t is=AliTRDCalPID::kNSlicesNN; is--; it++) fdEdx[is] = (*it); | |
251 | } | |
252 | ||
253 | // momentum threshold | |
254 | if(fP < fPthreshold) continue; | |
255 | ||
256 | // store information | |
257 | fPIDdataArray->PushBack(ily, AliTRDpidUtil::GetMomentumBin(fP), fdEdx); | |
258 | } | |
259 | ||
260 | Fill(); | |
261 | } | |
262 | ||
f8f46e4d | 263 | PostData(1, fContainer); |
264 | PostData(2, fData); | |
1ee39b3a | 265 | } |
266 | ||
267 | ||
268 | //________________________________________________________________________ | |
269 | void AliTRDpidRefMaker::Fill() | |
270 | { | |
271 | // Fill data tree | |
272 | ||
273 | if(!fPIDdataArray->fNtracklets) return; | |
274 | fPIDbin = TMath::LocMax(AliPID::kSPECIES, fPID); // get particle type | |
04a0ef56 | 275 | if(fPIDbin == 0 && fPID[0]<1.e-5) return; |
87c9fc00 | 276 | // Fill data tree |
1ee39b3a | 277 | fData->Fill(); |
278 | ||
279 | ||
280 | // fill monitor | |
281 | for(Int_t ily=fPIDdataArray->fNtracklets; ily--;){ | |
282 | Int_t pBin = fPIDdataArray->fData[ily].fPLbin & 0xf; | |
283 | ((TH2*)fContainer->At(0))->Fill(fPIDbin, pBin); | |
284 | } | |
285 | } | |
286 | ||
287 | //________________________________________________________________________ | |
288 | void AliTRDpidRefMaker::LinkPIDdata() | |
289 | { | |
290 | // Link data tree to data members | |
291 | fData->SetBranchAddress("s", &fPIDbin); | |
292 | fData->SetBranchAddress("data", &fPIDdataArray); | |
293 | } | |
294 | ||
295 | //________________________________________________________________________ | |
3d19c1b0 | 296 | void AliTRDpidRefMaker::SetRefPID(ETRDpidRefMakerSource select, AliTRDtrackInfo *track, Float_t *pid) |
1ee39b3a | 297 | { |
298 | // Fill the reference PID values "pid" from "source" object | |
299 | // according to the option "select". Possible options are | |
300 | // - kV0 - v0 based PID | |
301 | // - kMC - MC truth [default] | |
302 | // - kRec - outside detectors | |
303 | ||
3d19c1b0 | 304 | if(!track){ |
305 | AliError("No trackInfo found"); | |
306 | return; | |
307 | } | |
1ee39b3a | 308 | memset(fPID, 0, AliPID::kSPECIES*sizeof(Float_t)); |
309 | switch(select){ | |
310 | case kV0: | |
311 | { | |
1ee39b3a | 312 | //Get V0 PID decisions from the AliTRDv0Info for all particle species (implemented so far : electrons from conversions, pions from K0s and protons from Lambdas) : |
3d19c1b0 | 313 | AliTRDv0Info *v0(NULL); |
314 | for(Int_t iv(0); iv<fV0s->GetEntriesFast(); iv++){ | |
315 | if(!(v0 = (AliTRDv0Info*)fV0s->At(iv))) continue; | |
316 | if(!v0->HasTrack(track)) continue; | |
317 | for(Int_t is=AliPID::kSPECIES; is--;) fPID[is] = v0->GetPID(is, track); | |
318 | break; | |
319 | } | |
1ee39b3a | 320 | } |
321 | break; | |
322 | case kMC: | |
323 | if(!HasMCdata()){ | |
324 | AliError("Could not retrive reference PID from MC"); | |
325 | return; | |
326 | } | |
3d19c1b0 | 327 | switch(track->GetPDG()){ |
328 | case kElectron: | |
329 | case kPositron: | |
330 | fPID[AliPID::kElectron] = 1.; | |
331 | break; | |
332 | case kMuonPlus: | |
333 | case kMuonMinus: | |
334 | fPID[AliPID::kMuon] = 1.; | |
335 | break; | |
336 | case kPiPlus: | |
337 | case kPiMinus: | |
338 | fPID[AliPID::kPion] = 1.; | |
339 | break; | |
340 | case kKPlus: | |
341 | case kKMinus: | |
342 | fPID[AliPID::kKaon] = 1.; | |
343 | break; | |
344 | case kProton: | |
345 | case kProtonBar: | |
346 | fPID[AliPID::kProton] = 1.; | |
347 | break; | |
1ee39b3a | 348 | } |
349 | break; | |
350 | case kRec: | |
351 | { | |
1ee39b3a | 352 | AliTRDtrackV1 *trackTRD = track->GetTrack(); |
353 | trackTRD -> SetReconstructor(fReconstructor); | |
354 | //fReconstructor -> SetOption("nn"); | |
355 | trackTRD -> CookPID(); | |
356 | for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){ | |
357 | pid[iPart] = trackTRD -> GetPID(iPart); | |
358 | AliDebug(4, Form("PDG is (in V0info) %d %f", iPart, pid[iPart])); | |
359 | } | |
360 | } | |
361 | break; | |
362 | default: | |
363 | AliWarning("PID reference source not implemented"); | |
364 | return; | |
365 | } | |
366 | AliDebug(4, Form("Ref PID [%] : %s[%5.2f] %s[%5.2f] %s[%5.2f] %s[%5.2f] %s[%5.2f]" | |
367 | ,AliPID::ParticleShortName(0), 1.e2*fPID[0] | |
368 | ,AliPID::ParticleShortName(1), 1.e2*fPID[1] | |
369 | ,AliPID::ParticleShortName(2), 1.e2*fPID[2] | |
370 | ,AliPID::ParticleShortName(3), 1.e2*fPID[3] | |
371 | ,AliPID::ParticleShortName(4), 1.e2*fPID[4] | |
372 | )); | |
373 | } | |
374 | ||
375 | //________________________________________________________________________ | |
376 | void AliTRDpidRefMaker::SetAbundance(Float_t train) | |
377 | { | |
378 | // Split data sample between trainning and testing | |
379 | ||
380 | if(train<0. || train >1.){ | |
381 | AliWarning("The input data should be in the interval [0, 1]"); | |
382 | return; | |
383 | } | |
384 | ||
385 | fFreq = train; | |
386 | } | |
387 |