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 **************************************************************************/
17 // *** Class AliRsnEvent ***
19 // A container for a collection of AliRsnDaughter objects from an event.
20 // Contains also the primary vertex, useful for some cuts.
21 // In order to retrieve easily the tracks which have been identified
22 // as a specific type and charge, there is an array of indexes which
23 // allows to avoid to loop on all tracks and have only the neede ones.
25 // authors: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
26 // M. Vala (email: martin.vala@cern.ch)
29 #include <Riostream.h>
33 #include "AliRsnDaughter.h"
34 #include "AliRsnEvent.h"
35 #include "AliRsnMCInfo.h"
37 ClassImp (AliRsnEvent)
39 //_____________________________________________________________________________
40 AliRsnEvent::AliRsnEvent() :
41 TNamed ("rsnEvent", ""),
51 // Default constructor
52 // (implemented but not recommended for direct use)
56 //_____________________________________________________________________________
57 AliRsnEvent::AliRsnEvent (const AliRsnEvent &event) :
69 // Copies all the tracks from the argument's collection
70 // to this' one, and then recreates the PID index arrays,
71 // trusting on the PID informations in the copied tracks.
74 // during track copy, counts how many faults happen
75 Int_t errors = Fill (event.fTracks);
76 if (errors) AliWarning (Form ("%d errors occurred in copy", errors));
78 // fill PID index arrays
81 if (event.fNoPID) fNoPID = new AliRsnPIDIndex(*(event.fNoPID));
82 if (event.fPerfectPID) fPerfectPID = new AliRsnPIDIndex(*(event.fPerfectPID));
83 if (event.fRealisticPID) fRealisticPID = new AliRsnPIDIndex(*(event.fRealisticPID));
86 //_____________________________________________________________________________
87 AliRsnEvent& AliRsnEvent::operator= (const AliRsnEvent &event)
90 // Works in the same way as the copy constructor.
92 // copy name and title
93 SetName (event.GetName());
94 SetTitle (event.GetTitle());
96 // copy primary vertex and initialize track counter to 0
101 // add tracks from array of argument
102 Int_t errors = Fill (event.fTracks);
103 if (errors) AliWarning (Form ("%d errors occurred in copy", errors));
108 if (!fNoPID) fNoPID = new AliRsnPIDIndex(*(event.fNoPID));
109 else (*fNoPID) = *(event.fNoPID);
111 if (event.fPerfectPID) {
112 if (!fPerfectPID) fPerfectPID = new AliRsnPIDIndex(*(event.fPerfectPID));
113 else (*fPerfectPID) = *(event.fPerfectPID);
115 if (event.fRealisticPID) {
116 if (!fRealisticPID) fRealisticPID = new AliRsnPIDIndex(*(event.fRealisticPID));
117 else (*fRealisticPID) = *(event.fRealisticPID);
120 // return this object
124 //_____________________________________________________________________________
125 AliRsnEvent::~AliRsnEvent()
129 // Deletes the TClonesArray, after clearing its content.
130 // Other memory-allocating arrays are cleared by their
131 // destructor, which is automatically called from here.
135 if (fTracks) delete fTracks;
138 //_____________________________________________________________________________
139 void AliRsnEvent::Init()
142 // Initialize TClonesArray data-member.
145 fTracks = new TClonesArray ("AliRsnDaughter", 1);
146 //fTracks->BypassStreamer (kFALSE);
149 //_____________________________________________________________________________
150 void AliRsnEvent::Clear (Option_t* /*option*/)
153 // Empties the collections (does not delete the objects).
154 // The track collection is emptied only at the end.
155 // Since some objects could be uninitialized, some
156 // "if" statement are used.
159 if (fTracks) fTracks->Delete();
164 delete fRealisticPID;
168 //_____________________________________________________________________________
169 AliRsnDaughter* AliRsnEvent::AddTrack (AliRsnDaughter track)
172 // Stores a new track into the array and returns
173 // a reference pointer to it (which is NULL in case of errors).
176 Int_t nextIndex = fTracks->GetEntriesFast();
177 TClonesArray &tracks = (*fTracks);
178 AliRsnDaughter *copy = new (tracks[nextIndex]) AliRsnDaughter (track);
182 //_____________________________________________________________________________
183 AliRsnDaughter* AliRsnEvent::GetTrack(Int_t index)
186 // Returns one track in the collection
187 // given the absolute index in the global TClonesArray
189 return (AliRsnDaughter*) fTracks->UncheckedAt (index);
192 //_____________________________________________________________________________
193 TArrayI* AliRsnEvent::GetCharged (Char_t sign)
196 // Returns an array with the indexes of all tracks with a given charge
197 // (arg can be '+' or '-'), irrespective of its PID.
198 // When the argument is wrong, a NULL pointer is returned.
200 if (fNoPID) return fNoPID->GetTracksArray(sign, AliRsnPID::kUnknown);
204 //_____________________________________________________________________________
205 TArrayI * AliRsnEvent::GetTracksArray
206 (AliRsnPID::EMethod pidtype, Char_t sign, AliRsnPID::EType type)
209 // Returns an array of indexes of all tracks in this event
210 // which match the charge sign and PID type in the arguments,
211 // according to one of the allowed PID methods (perfect or realistic).
212 // It retrieves this array from the AliRsnPIDIndex data members.
213 // If the arguments are wrong a NULL pointer is returned.
217 case AliRsnPID::kRealistic:
219 return fRealisticPID->GetTracksArray (sign, type);
222 case AliRsnPID::kPerfect:
224 return fPerfectPID->GetTracksArray (sign, type);
228 AliError ("Handled PID methods here are only kPerfect and kRealistic. Nothing done.");
235 //_____________________________________________________________________________
236 void AliRsnEvent::FillPIDArrays()
239 // Initializes and fills the AliRsnPIDIndex objects containing
240 // arrays of indexes for each possible charge and PID type.
241 // This method is the unique way to do this, for safety reasons.
244 if (fNoPID) delete fNoPID;
245 if (fPerfectPID) delete fPerfectPID;
246 if (fRealisticPID) delete fRealisticPID;
247 fNoPID = new AliRsnPIDIndex;
248 fPerfectPID = new AliRsnPIDIndex;
249 fRealisticPID = new AliRsnPIDIndex;
251 // loop on tracks and create references
252 Int_t i, icharge, type;
254 AliRsnMCInfo *mcinfo = 0;
255 AliRsnDaughter *track = 0;
256 TObjArrayIter iter(fTracks);
257 while ( (track = (AliRsnDaughter*) iter.Next()) ) {
258 charge = track->Charge();
259 type = (Int_t)track->PIDType();
260 i = fTracks->IndexOf(track);
261 mcinfo = track->GetMCInfo();
262 if (charge > 0) icharge = 0;
263 else if (charge < 0) icharge = 1;
265 AliError("Found particle with ZERO charge!!!");
268 // add to charged array
269 fNoPID->AddIndex(i, icharge, (Int_t)AliRsnPID::kUnknown);
270 // add to realistic PID array
271 fRealisticPID->AddIndex (i, icharge, (Int_t)type);
272 // add to perfect PID array (needs MCInfo present)
274 fPerfectPID->AddIndex (i, icharge, (Int_t)AliRsnPID::InternalType(mcinfo->PDG()));
278 // adjusts the size of arrays
279 if (fNoPID) fNoPID->SetCorrectIndexSize();
280 if (fPerfectPID) fPerfectPID->SetCorrectIndexSize();
281 if (fRealisticPID) fRealisticPID->SetCorrectIndexSize();
284 //_____________________________________________________________________________
285 void AliRsnEvent::Print (Option_t *option) const
288 // Lists the details of the event, and the ones of each
290 // The options are passed to AliRsnDaughter::Print().
291 // Look at that method to understand option values.
294 cout << "...Multiplicity : " << fTracks->GetEntries() << endl;
295 cout << "...Primary vertex : " << fPVx << ' ' << fPVy << ' ' << fPVz << endl;
297 TObjArrayIter iter (fTracks);
298 AliRsnDaughter *d = 0;
299 while ((d = (AliRsnDaughter*) iter.Next())) {
300 cout << "....Track #" << fTracks->IndexOf (d) << endl;
305 //_____________________________________________________________________________
306 Int_t AliRsnEvent::GetMultiplicity() const
309 // Get number of all tracks
312 if (!fTracks) return 0;
313 return fTracks->GetEntries();
316 //_____________________________________________________________________________
317 Int_t AliRsnEvent::GetNCharged (Char_t sign)
320 // Get number of charged tracks
324 icharge = ChargeIndex (sign);
325 if (icharge < 0) return 0;
326 TArrayI *charged = GetCharged(sign);
327 if (!charged) return 0;
328 return charged->GetSize();
331 //_____________________________________________________________________________
332 Int_t AliRsnEvent::Fill (TObjArray *array)
335 // Fills the data-member TClonesArray of tracks with
336 // the ones stored in the array passed as argument.
337 // If this data-member is already present, it is cleared.
338 // Returns the number of tracks which raised problems
339 // while attempting to add them. Zero is the best.
342 // clear the array if it is already instantiated,
343 // create if otherwise
344 if (fTracks) fTracks->Delete();
347 // copy argument entries into data-member
349 AliRsnDaughter *track = 0;
350 TObjArrayIter iter (array);
351 while ((track = (AliRsnDaughter*) iter.Next())) {
352 AliRsnDaughter *ref = AddTrack (*track);
354 AliWarning (Form ("Problem occurred when copying track #%d from passed array", array->IndexOf (track)));
362 //_____________________________________________________________________________
363 Int_t AliRsnEvent::ChargeIndex (Char_t sign) const
365 // Returns the array index corresponding to charge
366 // 0 for positive, 1 for negative
369 if (sign == '+') return 0;
370 else if (sign == '-') return 1;
372 AliError (Form ("Character '%c' not recognized as charge sign", sign));