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 **************************************************************************/
16 //-------------------------------------------------------------------------
18 // -------------------
19 // Simple collection of reconstructed tracks
20 // selected from an ESD event
21 // to be used for analysis.
22 // .........................................
24 // author: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
25 //-------------------------------------------------------------------------
27 #include <Riostream.h>
30 #include <TObjArray.h>
31 #include <TClonesArray.h>
33 #include "AliRsnDaughter.h"
34 #include "AliRsnEvent.h"
38 //--------------------------------------------------------------------------------------------------------
39 AliRsnEvent::AliRsnEvent() :
48 // Default constructor
51 for (i = 0; i < AliPID::kSPECIES; i++) {
56 //--------------------------------------------------------------------------------------------------------
57 AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
58 TObject((TObject)event),
62 fMultiplicity(event.fMultiplicity),
68 // Creates new instances of all collections to store a copy of all objects.
70 // clone tracks collections
72 for (i = 0; i < AliPID::kSPECIES; i++) {
75 if (event.fPos[i]) fPos[i] = (TClonesArray*)event.fPos[i]->Clone();
76 if (event.fNeg[i]) fNeg[i] = (TClonesArray*)event.fNeg[i]->Clone();
78 fPosNoPID = (TClonesArray*)event.fPosNoPID->Clone();
79 fNegNoPID = (TClonesArray*)event.fNegNoPID->Clone();
81 //--------------------------------------------------------------------------------------------------------
82 AliRsnEvent& AliRsnEvent::operator=(const AliRsnEvent &event)
85 // Assignment operator.
86 // Creates new instances of all collections to store a copy of all objects.
91 fMultiplicity = event.fMultiplicity;
93 // clone tracks collections
95 for (i = 0; i < AliPID::kSPECIES; i++) {
98 if (event.fPos[i]) fPos[i] = (TClonesArray*)event.fPos[i]->Clone();
99 if (event.fNeg[i]) fNeg[i] = (TClonesArray*)event.fNeg[i]->Clone();
101 fPosNoPID = (TClonesArray*)event.fPosNoPID->Clone();
102 fNegNoPID = (TClonesArray*)event.fNegNoPID->Clone();
106 //--------------------------------------------------------------------------------------------------------
107 void AliRsnEvent::AddTrack(AliRsnDaughter track)
110 // Stores a track into the correct array
112 // if sign is zero, track is not stored
113 Char_t sign = track.GetSign();
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();
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);
127 TClonesArray &array = (sign > 0) ? *fPosNoPID : *fNegNoPID;
128 index = array.GetEntries();
129 new(array[index]) AliRsnDaughter(track);
132 //--------------------------------------------------------------------------------------------------------
133 void AliRsnEvent::Clear(Option_t *option)
136 // Clears list of tracks and references.
137 // If the string "DELETE" is specified, the collection classes
138 // are also cleared from heap.
142 Bool_t deleteCollections = opt.Contains("DELETE", TString::kIgnoreCase);
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) {
155 if (fPosNoPID) fPosNoPID->Delete();
156 if (fNegNoPID) fNegNoPID->Delete();
157 if (deleteCollections) {
164 //--------------------------------------------------------------------------------------------------------
165 void AliRsnEvent::ComputeMultiplicity()
168 // Computes multiplicity.
172 for (i = 0; i < AliPID::kSPECIES; i++) {
173 fMultiplicity += (Int_t)fPos[i]->GetEntries();
174 fMultiplicity += (Int_t)fNeg[i]->GetEntries();
176 if (fPosNoPID) fMultiplicity += fPosNoPID->GetEntries();
177 if (fNegNoPID) fMultiplicity += fNegNoPID->GetEntries();
179 //--------------------------------------------------------------------------------------------------------
180 TClonesArray* AliRsnEvent::GetTracks(Char_t sign, AliPID::EParticleType type)
183 // Returns the particle collection specified in argument
185 Int_t itype = (Int_t)type;
186 if (itype >= 0 && itype < AliPID::kSPECIES) {
187 if (sign == '+') return fPos[type]; else return fNeg[type];
189 else if (type == AliPID::kUnknown) {
190 if (sign == '+') return fPosNoPID; else return fNegNoPID;
196 //--------------------------------------------------------------------------------------------------------
197 void AliRsnEvent::Init()
200 // Action 1: define default values for some data members (including pointers).
201 // Action 2: if 'ntracks' > 0 allocates memory to store tracks.
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);
210 fPosNoPID = new TClonesArray("AliRsnDaughter", 0);
211 fNegNoPID = new TClonesArray("AliRsnDaughter", 0);
212 fPosNoPID->BypassStreamer(kFALSE);
213 fNegNoPID->BypassStreamer(kFALSE);
215 //--------------------------------------------------------------------------------------------------------
216 Int_t AliRsnEvent::PDG2Enum(Int_t pdgcode)
219 // Converts a PDG code into the correct slot in the EParticleType enumeration in AliPID
222 for (i = 0; i < AliPID::kSPECIES; i++) {
223 if (AliPID::ParticleCode((AliPID::EParticleType)i) == TMath::Abs(pdgcode)) {
230 //--------------------------------------------------------------------------------------------------------
231 void AliRsnEvent::PrintTracks()
234 // Print data for particles stored in this event
238 AliRsnDaughter *track = 0;
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;
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;
262 //--------------------------------------------------------------------------------------------------------