]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnReader.cxx
Changes in code and adding task
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnReader.cxx
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 // ==== Class AliRsnReader ========
18 //
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.
22 //
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
30 // passed to them.
31 // 
32 // author: A. Pulvirenti
33 // email : alberto.pulvirenti@ct.infn.it
34 //
35
36 #include "AliLog.h"
37
38 #include "AliESDEvent.h"
39 #include "AliESDtrack.h"
40 #include "AliESDVertex.h"
41
42 #include "AliAODEvent.h"
43 #include "AliAODTrack.h"
44 #include "AliAODVertex.h"
45
46 #include "AliStack.h"
47 #include "AliMCEvent.h"
48 #include "AliMCParticle.h"
49 #include "AliGenEventHeader.h"
50
51 #include "AliRsnParticle.h"
52 #include "AliRsnDaughter.h"
53 #include "AliRsnEvent.h"
54 #include "AliRsnReader.h"
55
56 ClassImp(AliRsnReader)
57                 
58 //_____________________________________________________________________________
59 AliRsnReader::AliRsnReader(Bool_t checkSplit, Bool_t rejectFakes) :
60   TObject(),
61   fCheckSplit(checkSplit),
62   fRejectFakes(rejectFakes)
63 {
64 //=========================================================
65 // Constructor.
66 // Initializes the base-type data members:
67 //   - management of fake tracks
68 //=========================================================
69 }
70
71 //_____________________________________________________________________________
72 AliRsnReader::AliRsnReader(const AliRsnReader &copy) : 
73   TObject(copy),
74   fCheckSplit(copy.fCheckSplit),
75   fRejectFakes(copy.fRejectFakes)
76 {
77 //=========================================================
78 // Copy constructor.
79 //=========================================================
80 }
81
82 //_____________________________________________________________________________
83 AliRsnReader& AliRsnReader::operator=(const AliRsnReader &copy)
84 {
85 //=========================================================
86 // Assignment operator.
87 //=========================================================
88         
89         fCheckSplit = copy.fCheckSplit;
90         fRejectFakes = copy.fRejectFakes;
91         return (*this);
92 }
93
94 //_____________________________________________________________________________
95 Bool_t AliRsnReader::FillFromESD(AliRsnEvent *rsn, AliESDEvent *esd, AliMCEvent *mc)
96 {
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 //=========================================================
107         
108         // set source flag
109         rsn->SetSource(AliRsnEvent::kESD);
110         
111         // retrieve stack (if possible)
112         AliStack *stack = 0x0;
113         if (mc) stack = mc->Stack();
114         
115         // get number of tracks
116         Int_t ntracks = esd->GetNumberOfTracks();
117         if (!ntracks) {
118            AliWarning("No tracks in this event");
119            return kFALSE;
120     }
121     
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;
129     if (fCheckSplit) {
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
137                 if (lab1 == lab2) {
138                     if (trk1->GetConstrainedChi2() > trk2->GetConstrainedChi2()) {
139                         accept[i1] = kTRUE;
140                         accept[i2] = kFALSE;
141                     }
142                     else {
143                         accept[i1] = kFALSE;
144                         accept[i2] = kTRUE;
145                     }
146                 }
147             }
148         }
149     }
150         
151         // get primary vertex
152         Double_t vertex[3];
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]);
157         
158         // store tracks from ESD
159     Int_t  index, label, labmum;
160     Bool_t check;
161     AliRsnDaughter temp;
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));
166             continue;
167         }
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
177         if (stack) {
178             TParticle *part = stack->Particle(TMath::Abs(label));
179             if (part) {
180                 temp.InitParticle(part);
181                 labmum = part->GetFirstMother();
182                 if (labmum >= 0) {
183                     TParticle *mum = stack->Particle(labmum);
184                     temp.GetParticle()->SetMotherPDG(mum->GetPdgCode());
185                 }
186             }
187         }
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));
194     }
195     
196     // compute total multiplicity
197     if (rsn->GetMultiplicity() <= 0) {
198         AliWarning("Zero Multiplicity in this event");
199         return kFALSE;
200     }
201     
202     return kTRUE;
203 }
204
205 //_____________________________________________________________________________
206 Bool_t AliRsnReader::FillFromAOD(AliRsnEvent *rsn, AliAODEvent *aod, AliMCEvent *mc)
207 {
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 //=========================================================
218         
219     // set source flag
220         rsn->SetSource(AliRsnEvent::kAOD);
221     
222     // retrieve stack (if possible)
223         AliStack *stack = 0x0;
224         if (mc) stack = mc->Stack();
225     
226     // get number of tracks
227         Int_t ntracks = aod->GetNTracks();
228         if (!ntracks) {
229            AliWarning("No tracks in this event");
230            return kFALSE;
231     }
232         
233         // get primary vertex
234         Double_t vertex[3];
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]);
239         
240         // store tracks from ESD
241     Int_t  index, label, labmum;
242     Bool_t check;
243     AliAODTrack *aodTrack = 0;
244     AliRsnDaughter temp;
245     TObjArrayIter iter(aod->GetTracks());
246     while ( (aodTrack = (AliAODTrack*)iter.Next()) ) {
247         // retrieve index
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
256         if (stack) {
257             TParticle *part = stack->Particle(TMath::Abs(label));
258             if (part) {
259                 temp.InitParticle(part);
260                 labmum = part->GetFirstMother();
261                 if (labmum >= 0) {
262                     TParticle *mum = stack->Particle(labmum);
263                     temp.GetParticle()->SetMotherPDG(mum->GetPdgCode());
264                 }
265             }
266         }
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"));
273     }
274     
275     // compute total multiplicity
276     if (rsn->GetMultiplicity() <= 0) {
277         AliWarning("Zero multiplicity in this event");
278         return kFALSE;
279     }
280     
281     return kTRUE;
282 }
283
284 //_____________________________________________________________________________
285 Bool_t AliRsnReader::FillFromMC(AliRsnEvent *rsn, AliMCEvent *mc)
286 {
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 //=========================================================
296         
297         // set source flag
298         rsn->SetSource(AliRsnEvent::kMC);
299         
300         // get number of tracks
301         Int_t ntracks = mc->GetNumberOfTracks();
302         if (!ntracks) {
303            AliWarning("No tracks in this event");
304            return kFALSE;
305     }
306     
307     AliStack *stack = mc->Stack();
308         
309         // get primary vertex
310         TArrayF fvertex(3);
311         Double_t vertex[3];
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]);
317         
318         // store tracks from MC
319     Int_t  index, labmum;
320     Bool_t check;
321     AliRsnDaughter temp;
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();
331         if (labmum >= 0) {
332             TParticle *mum = stack->Particle(labmum);
333             temp.GetParticle()->SetMotherPDG(mum->GetPdgCode());
334         }
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));
341     }
342     
343     // compute total multiplicity
344     if (rsn->GetMultiplicity() <= 0) {
345         AliWarning("Zero multiplicity in this event");
346         return kFALSE;
347     }
348     
349     return kTRUE;
350 }