1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // ==== Class AliRsnReader ========
19 // This object reads a 'standard' event and converts it into the internal
20 // format used for resonance analysis (AliRsnEvent).
21 // 'Standard' event means ESD, standard AOD and MC event.
23 // The input-2-AliRsnEvent conversion is done through a class which reads
24 // from AliAnalysisTaskSE, which is the standard analysis object.
25 // This class creates the AliRsnEvent's before the input event is read,
26 // so this class has not to 'create' a new outpu event, but instead it has
27 // to 'fill' one which has already been created elsewhere.
28 // Then, the methods provided here accept an AliRsnEvent as argument passed
29 // by reference, and they 'fill' this object using the data from the inputs
32 // author: A. Pulvirenti
33 // email : alberto.pulvirenti@ct.infn.it
38 #include "AliESDEvent.h"
39 #include "AliESDtrack.h"
40 #include "AliESDVertex.h"
42 #include "AliAODEvent.h"
43 #include "AliAODTrack.h"
44 #include "AliAODVertex.h"
47 #include "AliMCEvent.h"
48 #include "AliMCParticle.h"
49 #include "AliGenEventHeader.h"
51 #include "AliRsnParticle.h"
52 #include "AliRsnDaughter.h"
53 #include "AliRsnEvent.h"
54 #include "AliRsnReader.h"
56 ClassImp(AliRsnReader)
58 //_____________________________________________________________________________
59 AliRsnReader::AliRsnReader(Bool_t checkSplit, Bool_t rejectFakes) :
61 fCheckSplit(checkSplit),
62 fRejectFakes(rejectFakes)
64 //=========================================================
66 // Initializes the base-type data members:
67 // - management of fake tracks
68 //=========================================================
71 //_____________________________________________________________________________
72 AliRsnReader::AliRsnReader(const AliRsnReader ©) :
74 fCheckSplit(copy.fCheckSplit),
75 fRejectFakes(copy.fRejectFakes)
77 //=========================================================
79 //=========================================================
82 //_____________________________________________________________________________
83 AliRsnReader& AliRsnReader::operator=(const AliRsnReader ©)
85 //=========================================================
86 // Assignment operator.
87 //=========================================================
89 fCheckSplit = copy.fCheckSplit;
90 fRejectFakes = copy.fRejectFakes;
94 //_____________________________________________________________________________
95 Bool_t AliRsnReader::FillFromESD(AliRsnEvent *rsn, AliESDEvent *esd, AliMCEvent *mc)
97 //=========================================================
98 // Filler from an ESD event.
99 // Stores all tracks (if a filter is defined, it will store
100 // only the ones which survive the cuts).
101 // If a reference MC event is provided, it is used to store
102 // the MC informations for each track (true PDG code,
103 // GEANT label of mother, PDG code of mother, if any).
104 // When this is used, the 'source' flag of the output
105 // AliRsnEvent object will be set to 'kESD'.
106 //=========================================================
109 rsn->SetSource(AliRsnEvent::kESD);
111 // retrieve stack (if possible)
112 AliStack *stack = 0x0;
113 if (mc) stack = mc->Stack();
115 // get number of tracks
116 Int_t ntracks = esd->GetNumberOfTracks();
118 AliWarning("No tracks in this event");
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;
130 for (i1 = 0; i1 < ntracks; i1++) {
131 AliESDtrack *trk1 = esd->GetTrack(i1);
132 lab1 = TMath::Abs(trk1->GetLabel());
133 for (i2 = i1+1; i2 < ntracks; i2++) {
134 AliESDtrack *trk2 = esd->GetTrack(i2);
135 lab2 = TMath::Abs(trk2->GetLabel());
136 // check if labels are equal
138 if (trk1->GetConstrainedChi2() > trk2->GetConstrainedChi2()) {
151 // get primary vertex
153 vertex[0] = esd->GetVertex()->GetXv();
154 vertex[1] = esd->GetVertex()->GetYv();
155 vertex[2] = esd->GetVertex()->GetZv();
156 rsn->SetPrimaryVertex(vertex[0], vertex[1], vertex[2]);
158 // store tracks from ESD
159 Int_t index, label, labmum;
162 for (index = 0; index < ntracks; index++) {
163 // skip track recognized as the worse one in a splitted pair
164 if (!accept[index]) {
165 AliInfo(Form("Rejecting split track #%d in this event", index));
168 // get and check ESD track
169 AliESDtrack *esdTrack = esd->GetTrack(index);
170 label = esdTrack->GetLabel();
171 if (fRejectFakes && (label < 0)) continue;
172 // copy ESD track data into RsnDaughter
173 // if unsuccessful, this track is skipped
174 check = temp.Adopt(esdTrack);
175 if (!check) continue;
176 // if stack is present, copy MC info
178 TParticle *part = stack->Particle(TMath::Abs(label));
180 temp.InitParticle(part);
181 labmum = part->GetFirstMother();
183 TParticle *mum = stack->Particle(labmum);
184 temp.GetParticle()->SetMotherPDG(mum->GetPdgCode());
188 // set index and label and add this object to the output container
189 temp.SetIndex(index);
190 temp.SetLabel(label);
191 AliRsnDaughter *ptr = rsn->AddTrack(temp);
192 // if problems occurred while storing, that pointer is NULL
193 if (!ptr) AliWarning(Form("Failed storing track#%d", index));
196 // compute total multiplicity
197 if (rsn->GetMultiplicity() <= 0) {
198 AliWarning("Zero Multiplicity in this event");
205 //_____________________________________________________________________________
206 Bool_t AliRsnReader::FillFromAOD(AliRsnEvent *rsn, AliAODEvent *aod, AliMCEvent *mc)
208 //=========================================================
209 // Filler from an AOD event.
210 // Stores all tracks (if a filter is defined, it will store
211 // only the ones which survive the cuts).
212 // If a reference MC event is provided, it is used to store
213 // the MC informations for each track (true PDG code,
214 // GEANT label of mother, PDG code of mother, if any).
215 // When this is used, the 'source' flag of the output
216 // AliRsnEvent object will be set to 'kAOD'.
217 //=========================================================
220 rsn->SetSource(AliRsnEvent::kAOD);
222 // retrieve stack (if possible)
223 AliStack *stack = 0x0;
224 if (mc) stack = mc->Stack();
226 // get number of tracks
227 Int_t ntracks = aod->GetNTracks();
229 AliWarning("No tracks in this event");
233 // get primary vertex
235 vertex[0] = aod->GetPrimaryVertex()->GetX();
236 vertex[1] = aod->GetPrimaryVertex()->GetY();
237 vertex[2] = aod->GetPrimaryVertex()->GetZ();
238 rsn->SetPrimaryVertex(vertex[0], vertex[1], vertex[2]);
240 // store tracks from ESD
241 Int_t index, label, labmum;
243 AliAODTrack *aodTrack = 0;
245 TObjArrayIter iter(aod->GetTracks());
246 while ( (aodTrack = (AliAODTrack*)iter.Next()) ) {
248 index = aod->GetTracks()->IndexOf(aodTrack);
249 label = aodTrack->GetLabel();
250 if (fRejectFakes && (label < 0)) continue;
251 // copy ESD track data into RsnDaughter
252 // if unsuccessful, this track is skipped
253 check = temp.Adopt(aodTrack);
254 if (!check) continue;
255 // if stack is present, copy MC info
257 TParticle *part = stack->Particle(TMath::Abs(label));
259 temp.InitParticle(part);
260 labmum = part->GetFirstMother();
262 TParticle *mum = stack->Particle(labmum);
263 temp.GetParticle()->SetMotherPDG(mum->GetPdgCode());
267 // set index and label and add this object to the output container
268 temp.SetIndex(index);
269 temp.SetLabel(label);
270 AliRsnDaughter *ptr = rsn->AddTrack(temp);
271 // if problems occurred while storin, that pointer is NULL
272 if (!ptr) AliWarning(Form("Failed storing track#%d"));
275 // compute total multiplicity
276 if (rsn->GetMultiplicity() <= 0) {
277 AliWarning("Zero multiplicity in this event");
284 //_____________________________________________________________________________
285 Bool_t AliRsnReader::FillFromMC(AliRsnEvent *rsn, AliMCEvent *mc)
287 //=========================================================
288 // Filler from an ESD event.
289 // Stores all tracks which generate at least one
290 // TrackReference (a point in a sensitive volume).
291 // In this case, the MC info is stored by default and
292 // perfect particle identification is the unique available.
293 // When this is used, the 'source' flag of the output
294 // AliRsnEvent object will be set to 'kMC'.
295 //=========================================================
298 rsn->SetSource(AliRsnEvent::kMC);
300 // get number of tracks
301 Int_t ntracks = mc->GetNumberOfTracks();
303 AliWarning("No tracks in this event");
307 AliStack *stack = mc->Stack();
309 // get primary vertex
312 mc->GenEventHeader()->PrimaryVertex(fvertex);
313 vertex[0] = (Double_t)fvertex[0];
314 vertex[1] = (Double_t)fvertex[1];
315 vertex[2] = (Double_t)fvertex[2];
316 rsn->SetPrimaryVertex(vertex[0], vertex[1], vertex[2]);
318 // store tracks from MC
322 for (index = 0; index < ntracks; index++) {
323 // get and check MC track
324 AliMCParticle *mcTrack = mc->GetTrack(index);
325 // if particle has no track references, it is rejected
326 if (mcTrack->GetNumberOfTrackReferences() <= 0) continue;
327 // try to insert in the RsnDaughter its data
328 check = temp.Adopt(mcTrack);
329 if (!check) continue;
330 labmum = temp.GetParticle()->Mother();
332 TParticle *mum = stack->Particle(labmum);
333 temp.GetParticle()->SetMotherPDG(mum->GetPdgCode());
335 // if successful, set other data and stores it
336 temp.SetIndex(index);
337 temp.SetLabel(mcTrack->Label());
338 AliRsnDaughter *ptr = rsn->AddTrack(temp);
339 // if problems occurred while storin, that pointer is NULL
340 if (!ptr) AliWarning(Form("Failed storing track#%d", index));
343 // compute total multiplicity
344 if (rsn->GetMultiplicity() <= 0) {
345 AliWarning("Zero multiplicity in this event");