]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG1/TRD/AliTRDpidRefMaker.cxx
- updates to run with AliEn plugin (Markus)
[u/mrichter/AliRoot.git] / PWG1 / TRD / AliTRDpidRefMaker.cxx
CommitLineData
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
32ClassImp(AliTRDpidRefMaker)
33ClassImp(AliTRDpidRefMaker::AliTRDpidRefData)
34ClassImp(AliTRDpidRefMaker::AliTRDpidRefDataArray)
35
36//________________________________________________________________________
37AliTRDpidRefMaker::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//________________________________________________________________________
46AliTRDpidRefMaker::AliTRDpidRefDataArray::~AliTRDpidRefDataArray()
47{
48 // Destructor
49 delete [] fData;
50}
51
52//________________________________________________________________________
53void 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//________________________________________________________________________
62void 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//________________________________________________________________________
75AliTRDpidRefMaker::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//________________________________________________________________________
96AliTRDpidRefMaker::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//________________________________________________________________________
126AliTRDpidRefMaker::~AliTRDpidRefMaker()
127{
128 if(fPIDdataArray) delete fPIDdataArray;
129 if(fReconstructor) delete fReconstructor;
130}
131
132//________________________________________________________________________
133Bool_t AliTRDpidRefMaker::CheckQuality(AliTRDseedV1* /*trklt*/)
134{
135// Place holder for checking tracklet quality for PID.
136 return kTRUE;
137}
138
139
140//________________________________________________________________________
141Float_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 150void AliTRDpidRefMaker::UserCreateOutputObjects()
1ee39b3a 151{
152 // Create histograms
153 // Called once
154
f8f46e4d 155 OpenFile(1, "RECREATE");
1ee39b3a 156 fContainer = new TObjArray();
157 fContainer->SetName(Form("Moni%s", GetName()));
158
159 TH2 *h2 = new TH2I("hPDG","Particle abundance", AliPID::kSPECIES, -0.5, 4.5, AliTRDCalPID::kNMom, -0.5, AliTRDCalPID::kNMom-0.5);
160 TAxis *ax = h2->GetXaxis();
161 ax->SetNdivisions(505);
162 ax->SetTitle("Particle species");
163 for(Int_t is=AliPID::kSPECIES; is--;) ax->SetBinLabel(is+1, AliPID::ParticleShortName(is));
164 h2->GetYaxis()->SetTitle("P bins");
165 h2->GetYaxis()->SetNdivisions(511);
166
167 fContainer->AddAt(h2, 0);
168
169 fData = new TTree(GetName(), Form("Reference data for %s", GetName()));
170 fData->Branch("s", &fPIDbin, "s/b");
171 fData->Branch("data", &fPIDdataArray);
172}
173
174//________________________________________________________________________
f8f46e4d 175void AliTRDpidRefMaker::UserExec(Option_t *)
1ee39b3a 176{
177 // Main loop
178 // Called for each event
179
5935a6da 180 fV0s = dynamic_cast<TObjArray*>(GetInputData(2));
181 fInfo = dynamic_cast<TObjArray*>(GetInputData(3));
705f8b0a 182
5935a6da 183 AliInfo(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//________________________________________________________________________
269void AliTRDpidRefMaker::Fill()
270{
271// Fill data tree
272
273 if(!fPIDdataArray->fNtracklets) return;
274 fPIDbin = TMath::LocMax(AliPID::kSPECIES, fPID); // get particle type
275// Fill data tree
705f8b0a 276 AliInfo(Form("fData[%p]", (void*)fData));
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//________________________________________________________________________
288void AliTRDpidRefMaker::LinkPIDdata()
289{
290// Link data tree to data members
291 fData->SetBranchAddress("s", &fPIDbin);
292 fData->SetBranchAddress("data", &fPIDdataArray);
293}
294
295//________________________________________________________________________
296void AliTRDpidRefMaker::SetRefPID(ETRDpidRefMakerSource select, void *source, Float_t *pid)
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
304
305 memset(fPID, 0, AliPID::kSPECIES*sizeof(Float_t));
306 switch(select){
307 case kV0:
308 {
309 AliTRDtrackInfo *track = static_cast<AliTRDtrackInfo*>(source);
310 if(!track){
311 AliError("No trackInfo found");
312 return;
313 }
314
315 //Get V0 PID decisions from the AliTRDv0Info for all particle species (implemented so far : electrons from conversions, pions from K0s and protons from Lambdas) :
316 AliTRDv0Info v0;
317 for(Int_t is=AliPID::kSPECIES; is--;) fPID[is] = v0.GetV0PID(is, track);
318 }
319 break;
320 case kMC:
321 if(!HasMCdata()){
322 AliError("Could not retrive reference PID from MC");
323 return;
324 }
325 {
326 AliTRDtrackInfo *track = static_cast<AliTRDtrackInfo*>(source);
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;
348 }
349 }
350 break;
351 case kRec:
352 {
353 AliTRDtrackInfo *track = static_cast<AliTRDtrackInfo*>(source);
354 AliTRDtrackV1 *trackTRD = track->GetTrack();
355 trackTRD -> SetReconstructor(fReconstructor);
356 //fReconstructor -> SetOption("nn");
357 trackTRD -> CookPID();
358 for(Int_t iPart = 0; iPart < AliPID::kSPECIES; iPart++){
359 pid[iPart] = trackTRD -> GetPID(iPart);
360 AliDebug(4, Form("PDG is (in V0info) %d %f", iPart, pid[iPart]));
361 }
362 }
363 break;
364 default:
365 AliWarning("PID reference source not implemented");
366 return;
367 }
368 AliDebug(4, Form("Ref PID [%] : %s[%5.2f] %s[%5.2f] %s[%5.2f] %s[%5.2f] %s[%5.2f]"
369 ,AliPID::ParticleShortName(0), 1.e2*fPID[0]
370 ,AliPID::ParticleShortName(1), 1.e2*fPID[1]
371 ,AliPID::ParticleShortName(2), 1.e2*fPID[2]
372 ,AliPID::ParticleShortName(3), 1.e2*fPID[3]
373 ,AliPID::ParticleShortName(4), 1.e2*fPID[4]
374 ));
375}
376
377//________________________________________________________________________
378void AliTRDpidRefMaker::SetAbundance(Float_t train)
379{
380// Split data sample between trainning and testing
381
382 if(train<0. || train >1.){
383 AliWarning("The input data should be in the interval [0, 1]");
384 return;
385 }
386
387 fFreq = train;
388}
389