Commit PWG2 Makefile. To compile the code of the PWG2 module one has to do: make...
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnEvent.cxx
CommitLineData
0dffcc8a 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 AliRsnEvent
18// Simple collection of reconstructed tracks, selected from an ESD event
19//
20// author: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
21//-------------------------------------------------------------------------
22
23#include <Riostream.h>
24
25#include <TTree.h>
26#include <TString.h>
27#include <TParticle.h>
28#include <TObjArray.h>
29#include <TRefArray.h>
30#include <TClonesArray.h>
31
32#include "AliESD.h"
33#include "AliStack.h"
34#include "AliESDtrack.h"
35#include "AliRsnDaughter.h"
36#include "AliRsnEvent.h"
37
38ClassImp(AliRsnEvent)
39
40//--------------------------------------------------------------------------------------------------------
41AliRsnEvent::AliRsnEvent() :
42 fIsESD(kTRUE),
43 fPath(""),
44 fPVx(0.0),
45 fPVy(0.0),
46 fPVz(0.0),
47 fMultiplicity(-1)
48//
49// Default constructor
50//
51{
52 Int_t i;
53 for (i = 0; i < AliPID::kSPECIES; i++) {
54 fPos[i] = NULL;
55 fNeg[i] = NULL;
56 }
57}
58//--------------------------------------------------------------------------------------------------------
59AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
60 TObject((TObject)event),
61 fIsESD(event.fIsESD),
62 fPath(event.fPath),
63 fPVx(event.fPVx),
64 fPVy(event.fPVy),
65 fPVz(event.fPVz),
66 fMultiplicity(event.fMultiplicity)
67//
68// Copy constructor.
69// Creates new instances of all collections to store a copy of all objects.
70//
71{
72 // clone tracks collections
73 Int_t i;
74 for (i = 0; i < AliPID::kSPECIES; i++) {
75 fPos[i] = 0;
76 fNeg[i] = 0;
77 if (event.fPos[i]) fPos[i] = (TClonesArray*)event.fPos[i]->Clone();
78 if (event.fNeg[i]) fNeg[i] = (TClonesArray*)event.fNeg[i]->Clone();
79 }
80}
81//--------------------------------------------------------------------------------------------------------
82void AliRsnEvent::AddTrack(AliRsnDaughter track)
83//
84// Stores a track into the correct array
85//
86{
87 Int_t pdg, sign, ifirst, ilast;
88
89 // if sign is zero, track is not stored
90 sign = (Int_t)track.GetSign();
91 if (!sign) return;
92
93 // if PDG code is assigned, track is stored in the corresponding collection
94 // otherwise, a copy of track is is stored in each collection (undefined track)
95 pdg = track.GetPDG();
96 if (pdg != 0) {
97 ifirst = PDG2Enum(pdg);
98 ilast = ifirst;
99 if (ifirst < AliPID::kElectron || ifirst > AliPID::kProton) return;
100 }
101 else {
102 ifirst = AliPID::kElectron;
103 ilast = AliPID::kProton;
104 }
105
106 // track is stored
107 Int_t i, index;
108 for (i = ifirst; i <= ilast; i++) {
109 if (sign > 0) {
110 index = fPos[i]->GetEntries();
111 TClonesArray &array = *fPos[i];
112 new(array[index]) AliRsnDaughter(track);
113 }
114 else {
115 index = fNeg[i]->GetEntries();
116 TClonesArray &array = *fNeg[i];
117 new(array[index]) AliRsnDaughter(track);
118 }
119 }
120}
121//--------------------------------------------------------------------------------------------------------
122void AliRsnEvent::Clear(Option_t *option)
123//
124// Clears list of tracks and references.
125// If the string "DELETE" is specified, the collection classes
126// are also cleared from heap.
127//
128{
129 // evaluate option
130 TString opt(option);
131 Bool_t deleteCollections = opt.Contains("DELETE", TString::kIgnoreCase);
132
133 Int_t i;
134 for (i = 0; i < AliPID::kSPECIES; i++) {
135 if (fPos[i]) fPos[i]->Delete();
136 if (fNeg[i]) fNeg[i]->Delete();
137 if (deleteCollections) {
138 delete fPos[i];
139 delete fNeg[i];
140 fPos[i] = 0;
141 fNeg[i] = 0;
142 }
143 }
144}
145//--------------------------------------------------------------------------------------------------------
146Int_t AliRsnEvent::GetMultiplicity(Bool_t recalc)
147//
148// Computes multiplicity.
149// If it is already computed (fMultiplicity > -1), it returns that value,
150// unless one sets the argument to kTRUE.
151//
152{
153 if (fMultiplicity < 0) recalc = kTRUE;
154 if (recalc) {
155 fMultiplicity = 0;
156 Int_t i;
157 for (i = 0; i < AliPID::kSPECIES; i++) {
158 fMultiplicity += (Int_t)fPos[i]->GetEntries();
159 fMultiplicity += (Int_t)fNeg[i]->GetEntries();
160 }
161 }
162
163 return fMultiplicity;
164}
165//--------------------------------------------------------------------------------------------------------
166const char * AliRsnEvent::GetOriginFileName()
167//
168// Returns the path where input file was stored
169//
170{
171 TString str(fPath);
172 if (fIsESD) {
173 str.Append("/AliESDs.root");
174 }
175 else {
176 str.Append("/galice.root");
177 }
178
179 return str.Data();
180}
181//--------------------------------------------------------------------------------------------------------
182TClonesArray* AliRsnEvent::GetTracks(Char_t sign, AliPID::EParticleType type)
183//
184// Returns the particle collection specified in argument
185//
186{
187 Int_t itype = (Int_t)type;
188 if (itype >= 0 && itype < AliPID::kSPECIES) {
189 if (sign == '+') return fPos[type]; else return fNeg[type];
190 }
191 else {
192 return NULL;
193 }
194}
195//--------------------------------------------------------------------------------------------------------
196void AliRsnEvent::Init()
197//
198// Action 1: define default values for some data members (including pointers).
199// Action 2: if 'ntracks' > 0 allocates memory to store tracks.
200//
201{
202 Int_t i;
203 for (i = 0; i < AliPID::kSPECIES; i++) {
204 fPos[i] = new TClonesArray("AliRsnDaughter", 0);
205 fNeg[i] = new TClonesArray("AliRsnDaughter", 0);
206 fPos[i]->BypassStreamer(kFALSE);
207 fNeg[i]->BypassStreamer(kFALSE);
208 }
209}
210//--------------------------------------------------------------------------------------------------------
211Int_t AliRsnEvent::PDG2Enum(Int_t pdgcode)
212//
213// Converts a PDG code into the correct slot in the EParticleType enumeration in AliPID
214//
215{
216 Int_t i;
217 for (i = 0; i < AliPID::kSPECIES; i++) {
218 if (AliPID::ParticleCode((AliPID::EParticleType)i) == TMath::Abs(pdgcode)) {
219 return i;
220 }
221 }
222
223 return -1;
224}
225//--------------------------------------------------------------------------------------------------------
226void AliRsnEvent::PrintTracks()
227//
228// Print data for particles stored in this event
229//
230{
231 cout << endl;
232
233 AliRsnDaughter *track = 0;
234
235 Int_t type;
236 for (type = 0; type < AliPID::kSPECIES; type++) {
237 TObjArrayIter iterPos(fPos[type]);
238 cout << "Positive " << AliPID::ParticleName(type) << "s" << endl;
239 if (!fPos[type]) cout << "NOT INITIALIZED" << endl;
240 while ( (track = (AliRsnDaughter*)iterPos.Next()) ) {
241 cout << "Index, Sign, PDG = ";
242 cout << track->GetIndex() << " ";
243 cout << (Int_t)track->GetSign() << " ";
244 cout << track->GetPDG() << endl;
245 }
246 TObjArrayIter iterNeg(fNeg[type]);
247 cout << "Negative " << AliPID::ParticleName(type) << "s" << endl;
248 if (!fNeg[type]) cout << "NOT INITIALIZED" << endl;
249 while ( (track = (AliRsnDaughter*)iterNeg.Next()) ) {
250 cout << "Index, Sign, PDG = ";
251 cout << track->GetIndex() << " ";
252 cout << (Int_t)track->GetSign() << " ";
253 cout << track->GetPDG() << endl;
254 }
255 }
256}
257//--------------------------------------------------------------------------------------------------------