4 // This is the universal converter from any kind of source event
5 // (i.e. ESD, standard AOD, MC) into the internal non-standard
6 // AOD format used by RSN package.
8 // This class reads all tracks in an input event and converts them
9 // into AliRsnDaughters, and computes preliminarily the PID probabilities
10 // by doing the Bayesian combination of a set of assigned prior probabilities
11 // with the PID weights defined in each track.
13 // When filling the output event (AliRsnEvent), some arrays of indexes
14 // are created in order to organize tracks according to their PID and charge,
15 // which will then be used in further analysis steps.
17 // author: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
24 #include "AliVEvent.h"
26 #include "AliESDEvent.h"
27 #include "AliESDtrack.h"
28 #include "AliESDVertex.h"
30 #include "AliAODEvent.h"
31 #include "AliAODTrack.h"
32 #include "AliAODVertex.h"
35 #include "AliMCEvent.h"
36 #include "AliMCParticle.h"
37 #include "AliGenEventHeader.h"
39 #include "AliRsnMCInfo.h"
40 #include "AliRsnDaughter.h"
41 #include "AliRsnEvent.h"
42 #include "AliRsnPIDWeightsMgr.h"
44 #include "AliRsnReader.h"
46 ClassImp(AliRsnReader)
48 //_____________________________________________________________________________
49 AliRsnReader::AliRsnReader(AliRsnPIDWeightsMgr *mgr) :
50 TNamed("RsnReader", ""),
54 fCurrentPIDtype(AliRsnDaughter::kEsd),
65 //_____________________________________________________________________________
66 Bool_t AliRsnReader::Fill
67 (AliRsnEvent *rsn, AliVEvent *event, AliMCEvent *mc, Bool_t useTPCOnly)
70 // According to the class type of event and the selected source
71 // recalls one of the private reading methods to fill the RsnEvent
72 // passed by reference as first argument.
75 Bool_t success = kFALSE;
76 TString str(event->ClassName());
78 if (!str.CompareTo("AliESDEvent")) {
79 AliDebug(1, "Reading an ESD event");
80 success = FillFromESD(rsn, (AliESDEvent*)event, mc, useTPCOnly);
82 else if (!str.CompareTo("AliAODEvent")) {
83 AliDebug(1, "Reading an AOD event");
84 success = FillFromAOD(rsn, (AliAODEvent*)event, mc);
86 else if (!str.CompareTo("AliMCEvent")) {
87 AliDebug(1, "Reading an MC event");
88 success = FillFromMC(rsn, (AliMCEvent*)event);
91 AliError(Form("ClassName '%s' not recognized as possible source data: aborting.", str.Data()));
95 // sort tracks w.r. to Pt (from largest to smallest)
100 //_____________________________________________________________________________
101 Bool_t AliRsnReader::FillFromESD
102 (AliRsnEvent *rsn, AliESDEvent *esd, AliMCEvent *mc, Bool_t useTPCOnly)
105 // Filler from an ESD event.
106 // Stores all tracks (if a filter is defined, it will store
107 // only the ones which survive the cuts).
108 // If a reference MC event is provided, it is used to store
109 // the MC informations for each track (true PDG code,
110 // GEANT label of mother, PDG code of mother, if any).
111 // When this is used, the 'source' flag of the output
112 // AliRsnEvent object will be set to 'kESD'.
115 // retrieve stack (if possible)
116 AliStack *stack = 0x0;
117 if (mc) stack = mc->Stack();
119 // get number of tracks
120 Int_t ntracks = esd->GetNumberOfTracks();
122 // if required with the flag, scans the event
123 // and searches all split tracks (= 2 tracks with the same label);
124 // for each pair of split tracks, only the better (best chi2) is kept
125 // and the other is rejected: this info is stored into a Boolean array
126 Int_t i1, i2, lab1, lab2;
127 Bool_t *accept = new Bool_t[ntracks];
128 for (i1 = 0; i1 < ntracks; i1++) accept[i1] = kTRUE;
131 for (i1 = 0; i1 < ntracks; i1++)
133 AliESDtrack *trk1 = esd->GetTrack(i1);
134 lab1 = TMath::Abs(trk1->GetLabel());
135 for (i2 = i1+1; i2 < ntracks; i2++)
137 AliESDtrack *trk2 = esd->GetTrack(i2);
138 lab2 = TMath::Abs(trk2->GetLabel());
139 // check if labels are equal
142 if (trk1->GetConstrainedChi2() < trk2->GetConstrainedChi2())
157 // get primary vertex
161 vertex[0] = esd->GetVertex()->GetXv();
162 vertex[1] = esd->GetVertex()->GetYv();
163 vertex[2] = esd->GetVertex()->GetZv();
167 vertex[0] = esd->GetPrimaryVertexTPC()->GetXv();
168 vertex[1] = esd->GetPrimaryVertexTPC()->GetYv();
169 vertex[2] = esd->GetPrimaryVertexTPC()->GetZv();
171 rsn->SetPrimaryVertex(vertex[0], vertex[1], vertex[2]);
173 // store tracks from ESD
174 Int_t i, index, label, labmum;
177 for (index = 0; index < ntracks; index++)
179 // skip track recognized as the worse one in a splitted pair
182 AliInfo(Form("Rejecting split track #%d in this event", index));
185 // get and check ESD track
186 AliESDtrack *esdTrack = esd->GetTrack(index);
187 label = esdTrack->GetLabel();
188 if (fRejectFakes && (label < 0)) continue;
189 // copy ESD track data into RsnDaughter
190 // if unsuccessful, this track is skipped
191 // temp.SetCurrentESDPID(fCurrentPIDtype);
194 if (esdTrack->GetITSclusters(0) < fITSClusters) continue;
197 if (esdTrack->GetTPCclusters(0) < fTPCClusters) continue;
200 if (esdTrack->GetTRDclusters(0) < fTRDClusters) continue;
202 check = temp.Adopt(esdTrack,fCurrentPIDtype,fPIDDivValue, useTPCOnly);
203 if (!check) continue;
204 // if the AliRsnWeightsMgr object is initialized
205 // this means that ESD PID weights are not used
206 // and they are computed according to the Weight manager
209 //AliInfo("Using customized weights");
210 //AliInfo(Form("ESD weights = %f %f %f %f %f", temp.PID()[0], temp.PID()[1], temp.PID()[2], temp.PID()[3], temp.PID()[4], temp.PID()[5]));
211 esdTrack->GetITSpid(fWeightsMgr->GetWeightArray(AliRsnPIDWeightsMgr::kITS));
212 esdTrack->GetTPCpid(fWeightsMgr->GetWeightArray(AliRsnPIDWeightsMgr::kTPC));
213 esdTrack->GetTRDpid(fWeightsMgr->GetWeightArray(AliRsnPIDWeightsMgr::kTRD));
214 esdTrack->GetTOFpid(fWeightsMgr->GetWeightArray(AliRsnPIDWeightsMgr::kTOF));
215 esdTrack->GetHMPIDpid(fWeightsMgr->GetWeightArray(AliRsnPIDWeightsMgr::kHMPID));
216 for (i = 0; i < AliRsnPID::kSpecies; i++)
218 temp.SetPIDWeight(i, fWeightsMgr->GetWeight((AliRsnPID::EType)i, temp.Pt()));
220 //AliInfo(Form("Used weights = %f %f %f %f %f", temp.PID()[0], temp.PID()[1], temp.PID()[2], temp.PID()[3], temp.PID()[4], temp.PID()[5]));
224 //AliInfo("Using standard ESD weights");
227 // if stack is present, copy MC info
230 TParticle *part = stack->Particle(TMath::Abs(label));
233 temp.InitMCInfo(part);
234 labmum = part->GetFirstMother();
237 TParticle *mum = stack->Particle(labmum);
238 temp.GetMCInfo()->SetMotherPDG(mum->GetPdgCode());
242 // set index and label and add this object to the output container
243 temp.SetIndex(index);
244 temp.SetLabel(label);
245 AliRsnDaughter *ptr = rsn->AddTrack(temp);
246 // if problems occurred while storing, that pointer is NULL
247 if (!ptr) AliWarning(Form("Failed storing track#%d", index));
250 // compute total multiplicity
251 if (rsn->GetMultiplicity() <= 0)
253 AliDebug(1, "Zero Multiplicity in this event");
260 //_____________________________________________________________________________
261 Bool_t AliRsnReader::FillFromAOD(AliRsnEvent *rsn, AliAODEvent *aod, AliMCEvent *mc)
264 // Filler from an AOD event.
265 // Stores all tracks (if a filter is defined, it will store
266 // only the ones which survive the cuts).
267 // If a reference MC event is provided, it is used to store
268 // the MC informations for each track (true PDG code,
269 // GEANT label of mother, PDG code of mother, if any).
270 // When this is used, the 'source' flag of the output
271 // AliRsnEvent object will be set to 'kAOD'.
274 // retrieve stack (if possible)
275 AliStack *stack = 0x0;
276 if (mc) stack = mc->Stack();
278 // get number of tracks
279 Int_t ntracks = aod->GetNTracks();
282 AliWarning("No tracks in this event");
286 // get primary vertex
288 vertex[0] = aod->GetPrimaryVertex()->GetX();
289 vertex[1] = aod->GetPrimaryVertex()->GetY();
290 vertex[2] = aod->GetPrimaryVertex()->GetZ();
291 rsn->SetPrimaryVertex(vertex[0], vertex[1], vertex[2]);
293 // store tracks from ESD
294 Int_t index, label, labmum;
296 AliAODTrack *aodTrack = 0;
298 TObjArrayIter iter(aod->GetTracks());
299 while ((aodTrack = (AliAODTrack*)iter.Next()))
302 index = aod->GetTracks()->IndexOf(aodTrack);
303 label = aodTrack->GetLabel();
304 if (fRejectFakes && (label < 0)) continue;
305 // copy ESD track data into RsnDaughter
306 // if unsuccessful, this track is skipped
307 check = temp.Adopt(aodTrack);
308 if (!check) continue;
309 // if stack is present, copy MC info
312 TParticle *part = stack->Particle(TMath::Abs(label));
315 temp.InitMCInfo(part);
316 labmum = part->GetFirstMother();
319 TParticle *mum = stack->Particle(labmum);
320 temp.GetMCInfo()->SetMotherPDG(mum->GetPdgCode());
324 // set index and label and add this object to the output container
325 temp.SetIndex(index);
326 temp.SetLabel(label);
327 AliRsnDaughter *ptr = rsn->AddTrack(temp);
328 // if problems occurred while storin, that pointer is NULL
329 if (!ptr) AliWarning(Form("Failed storing track#%d"));
332 // compute total multiplicity
333 if (rsn->GetMultiplicity() <= 0)
335 AliDebug(1, "Zero multiplicity in this event");
342 //_____________________________________________________________________________
343 Bool_t AliRsnReader::FillFromMC(AliRsnEvent *rsn, AliMCEvent *mc)
346 // Filler from an ESD event.
347 // Stores all tracks which generate at least one
348 // TrackReference (a point in a sensitive volume).
349 // In this case, the MC info is stored by default and
350 // perfect particle identification is the unique available.
351 // When this is used, the 'source' flag of the output
352 // AliRsnEvent object will be set to 'kMC'.
355 // get number of tracks
356 Int_t ntracks = mc->GetNumberOfTracks();
359 AliWarning("No tracks in this event");
363 AliStack *stack = mc->Stack();
365 // get primary vertex
368 mc->GenEventHeader()->PrimaryVertex(fvertex);
369 vertex[0] = (Double_t)fvertex[0];
370 vertex[1] = (Double_t)fvertex[1];
371 vertex[2] = (Double_t)fvertex[2];
372 rsn->SetPrimaryVertex(vertex[0], vertex[1], vertex[2]);
374 // store tracks from MC
378 for (index = 0; index < ntracks; index++)
380 // get and check MC track
381 AliMCParticle *mcTrack = mc->GetTrack(index);
382 // if particle has no track references, it is rejected
383 if (mcTrack->GetNumberOfTrackReferences() <= 0) continue;
384 // try to insert in the RsnDaughter its data
385 check = temp.Adopt(mcTrack);
386 if (!check) continue;
387 labmum = temp.GetMCInfo()->Mother();
390 TParticle *mum = stack->Particle(labmum);
391 temp.GetMCInfo()->SetMotherPDG(mum->GetPdgCode());
393 // if successful, set other data and stores it
394 temp.SetIndex(index);
395 temp.SetLabel(mcTrack->Label());
396 AliRsnDaughter *ptr = rsn->AddTrack(temp);
397 // if problems occurred while storin, that pointer is NULL
398 if (!ptr) AliWarning(Form("Failed storing track#%d", index));
401 // compute total multiplicity
402 if (rsn->GetMultiplicity() <= 0)
404 AliDebug(1, "Zero multiplicity in this event");
411 void AliRsnReader::SetPIDtype(const AliRsnDaughter::EPIDType & theValue, Double_t divValue)
413 fCurrentPIDtype = theValue;
414 fPIDDivValue = divValue;
418 void AliRsnReader::SetITSTPCTRDSectors(const Int_t & its, const Int_t & tpc, const Int_t & trd)