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