]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnEvent.cxx
removed eff-c++ warnings
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnEvent.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 AliRsnEvent
18 //                     -------------------
19 //           Simple collection of reconstructed tracks
20 //           selected from an ESD event
21 //           to be used for analysis.
22 //           .........................................
23 // 
24 // author: A. Pulvirenti             (email: alberto.pulvirenti@ct.infn.it)
25 //-------------------------------------------------------------------------
26
27 #include <Riostream.h>
28
29 #include <TString.h>
30 #include <TObjArray.h>
31 #include <TClonesArray.h>
32
33 #include "AliRsnDaughter.h"
34 #include "AliRsnEvent.h"
35
36 ClassImp(AliRsnEvent)
37
38 //--------------------------------------------------------------------------------------------------------
39 AliRsnEvent::AliRsnEvent() :
40  fPVx(0.0),
41  fPVy(0.0),
42  fPVz(0.0),
43  fMultiplicity(-1),
44  fPosNoPID(0x0),
45  fNegNoPID(0x0)
46 {
47 //
48 // Default constructor
49 //
50         Int_t i;
51         for (i = 0; i < AliPID::kSPECIES; i++) {
52                 fPos[i] = NULL;
53                 fNeg[i] = NULL;
54         }
55 }
56 //--------------------------------------------------------------------------------------------------------
57 AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
58  TObject((TObject)event),
59  fPVx(event.fPVx),
60  fPVy(event.fPVy),
61  fPVz(event.fPVz),
62  fMultiplicity(event.fMultiplicity),
63  fPosNoPID(0x0),
64  fNegNoPID(0x0)
65 {
66 //
67 // Copy constructor.
68 // Creates new instances of all collections to store a copy of all objects.
69 //
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         }
78         fPosNoPID = (TClonesArray*)event.fPosNoPID->Clone();
79         fNegNoPID = (TClonesArray*)event.fNegNoPID->Clone();
80 }
81 //--------------------------------------------------------------------------------------------------------
82 AliRsnEvent& AliRsnEvent::operator=(const AliRsnEvent &event)
83 {
84 //
85 // Assignment operator.
86 // Creates new instances of all collections to store a copy of all objects.
87 //
88         fPVx = event.fPVx;
89         fPVy = event.fPVy;
90         fPVz = event.fPVz;
91         fMultiplicity = event.fMultiplicity;
92
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         }
101         fPosNoPID = (TClonesArray*)event.fPosNoPID->Clone();
102         fNegNoPID = (TClonesArray*)event.fNegNoPID->Clone();
103         
104         return (*this);
105 }
106 //--------------------------------------------------------------------------------------------------------
107 void AliRsnEvent::AddTrack(AliRsnDaughter track)
108 {
109 //
110 // Stores a track into the correct array
111 //
112         // if sign is zero, track is not stored
113         Char_t sign = track.GetSign();
114         if (!sign) return;
115         
116         // if PDG code is assigned, track is stored in the corresponding collection
117         // otherwise, it is stored in the array of unidentified particles with that sign
118         Int_t index, iarray, pdg = track.GetPDG();
119         if (pdg != 0) {
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);
125         }
126         else {
127                 TClonesArray &array = (sign > 0) ? *fPosNoPID : *fNegNoPID;
128                 index = array.GetEntries();
129                 new(array[index]) AliRsnDaughter(track);
130         }
131 }
132 //--------------------------------------------------------------------------------------------------------
133 void AliRsnEvent::Clear(Option_t *option)
134 {
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 //
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         }
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;
162         }
163 }
164 //--------------------------------------------------------------------------------------------------------
165 void AliRsnEvent::ComputeMultiplicity()
166 {
167 //
168 // Computes multiplicity.
169 //
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();
175         }
176         if (fPosNoPID) fMultiplicity += fPosNoPID->GetEntries();
177         if (fNegNoPID) fMultiplicity += fNegNoPID->GetEntries();
178 }
179 //--------------------------------------------------------------------------------------------------------
180 TClonesArray* AliRsnEvent::GetTracks(Char_t sign, AliPID::EParticleType type)
181 {
182 //
183 // Returns the particle collection specified in argument
184 //
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         }
189         else if (type == AliPID::kUnknown) {
190                 if (sign == '+') return fPosNoPID; else return fNegNoPID;
191         }
192         else {
193                 return NULL;
194         }
195 }
196 //--------------------------------------------------------------------------------------------------------
197 void AliRsnEvent::Init()
198 {
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 //
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         }
210         fPosNoPID = new TClonesArray("AliRsnDaughter", 0);
211         fNegNoPID = new TClonesArray("AliRsnDaughter", 0);
212         fPosNoPID->BypassStreamer(kFALSE);
213         fNegNoPID->BypassStreamer(kFALSE);
214 }
215 //--------------------------------------------------------------------------------------------------------
216 Int_t AliRsnEvent::PDG2Enum(Int_t pdgcode)
217 {
218 //
219 // Converts a PDG code into the correct slot in the EParticleType enumeration in AliPID
220 //
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 //--------------------------------------------------------------------------------------------------------
231 void AliRsnEvent::PrintTracks()
232 {
233 //
234 // Print data for particles stored in this event
235 //
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 //--------------------------------------------------------------------------------------------------------