]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnEvent.cxx
8a7e7acb0a955cb2b6db29a9acb9fedb8ce02f2d
[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 // 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.
24 //
25 // authors: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
26 //          M. Vala (email: martin.vala@cern.ch)
27 //
28
29 #include <Riostream.h>
30
31 #include "AliLog.h"
32
33 #include "AliRsnDaughter.h"
34 #include "AliRsnEvent.h"
35 #include "AliRsnMCInfo.h"
36
37 ClassImp (AliRsnEvent)
38
39 //_____________________________________________________________________________
40 AliRsnEvent::AliRsnEvent() :
41     TNamed ("rsnEvent", ""),
42     fPVx (0.0),
43     fPVy (0.0),
44     fPVz (0.0),
45     fTracks (0x0),
46     fNoPID(0x0),
47     fPerfectPID (0x0),
48     fRealisticPID (0x0)
49 {
50 //
51 // Default constructor
52 // (implemented but not recommended for direct use)
53 //
54 }
55
56 //_____________________________________________________________________________
57 AliRsnEvent::AliRsnEvent (const AliRsnEvent &event) :
58     TNamed (event),
59     fPVx (event.fPVx),
60     fPVy (event.fPVy),
61     fPVz (event.fPVz),
62     fTracks (0x0),
63     fNoPID(0x0),
64     fPerfectPID (0x0),
65     fRealisticPID (0x0)
66 {
67 //
68 // Copy constructor.
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.
72 //
73
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));
77
78     // fill PID index arrays
79     // FillPIDArrays();
80
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));
84 }
85
86 //_____________________________________________________________________________
87 AliRsnEvent& AliRsnEvent::operator= (const AliRsnEvent &event)
88 {
89 //
90 // Works in the same way as the copy constructor.
91 //
92     // copy name and title
93     SetName (event.GetName());
94     SetTitle (event.GetTitle());
95
96     // copy primary vertex and initialize track counter to 0
97     fPVx = event.fPVx;
98     fPVy = event.fPVy;
99     fPVz = event.fPVz;
100
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));
104
105     // fill PID arrays
106     // FillPIDArrays();
107     if (event.fNoPID) {
108         if (!fNoPID) fNoPID = new AliRsnPIDIndex(*(event.fNoPID));
109         else (*fNoPID) = *(event.fNoPID);
110     }
111     if (event.fPerfectPID) {
112         if (!fPerfectPID) fPerfectPID = new AliRsnPIDIndex(*(event.fPerfectPID));
113         else (*fPerfectPID) = *(event.fPerfectPID);
114     }
115     if (event.fRealisticPID) {
116         if (!fRealisticPID) fRealisticPID = new AliRsnPIDIndex(*(event.fRealisticPID));
117         else (*fRealisticPID) = *(event.fRealisticPID);
118     }
119
120     // return this object
121     return (*this);
122 }
123
124 //_____________________________________________________________________________
125 AliRsnEvent::~AliRsnEvent()
126 {
127 //
128 // Destructor.
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.
132 //
133
134     Clear();
135     if (fTracks) delete fTracks;
136 }
137
138 //_____________________________________________________________________________
139 void AliRsnEvent::Init()
140 {
141 //
142 // Initialize TClonesArray data-member.
143 //
144
145     fTracks = new TClonesArray ("AliRsnDaughter", 1);
146     //fTracks->BypassStreamer (kFALSE);
147 }
148
149 //_____________________________________________________________________________
150 void AliRsnEvent::Clear (Option_t* /*option*/)
151 {
152 //
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.
157 //
158
159     if (fTracks) fTracks->Delete();
160     delete fNoPID;
161     fNoPID = 0x0;
162     delete fPerfectPID;
163     fPerfectPID = 0x0;
164     delete fRealisticPID;
165     fRealisticPID = 0x0;
166 }
167
168 //_____________________________________________________________________________
169 AliRsnDaughter* AliRsnEvent::AddTrack (AliRsnDaughter track)
170 {
171 //
172 // Stores a new track into the array and returns
173 // a reference pointer to it (which is NULL in case of errors).
174 //
175
176     Int_t nextIndex = fTracks->GetEntriesFast();
177     TClonesArray &tracks = (*fTracks);
178     AliRsnDaughter *copy = new (tracks[nextIndex]) AliRsnDaughter (track);
179     return copy;
180 }
181
182 //_____________________________________________________________________________
183 AliRsnDaughter* AliRsnEvent::GetTrack(Int_t index)
184 {
185 //
186 // Returns one track in the collection
187 // given the absolute index in the global TClonesArray
188 //
189     return (AliRsnDaughter*) fTracks->UncheckedAt (index);
190 }
191
192 //_____________________________________________________________________________
193 TArrayI* AliRsnEvent::GetCharged (Char_t sign)
194 {
195 //
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.
199 //
200     if (fNoPID) return fNoPID->GetTracksArray(sign, AliRsnPID::kUnknown);
201     return 0x0;
202 }
203
204 //_____________________________________________________________________________
205 TArrayI * AliRsnEvent::GetTracksArray
206 (AliRsnPID::EMethod pidtype, Char_t sign, AliRsnPID::EType type)
207 {
208 //
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.
214 //
215
216     switch (pidtype) {
217         case AliRsnPID::kRealistic:
218             if (fRealisticPID) {
219                 return fRealisticPID->GetTracksArray (sign, type);
220             }
221             break;
222         case AliRsnPID::kPerfect:
223             if (fPerfectPID) {
224                 return fPerfectPID->GetTracksArray (sign, type);
225             }
226             break;
227         default:
228             AliError ("Handled PID methods here are only kPerfect and kRealistic. Nothing done.");
229             return 0x0;
230     }
231
232     return 0x0;
233 }
234
235 //_____________________________________________________________________________
236 void AliRsnEvent::FillPIDArrays()
237 {
238 //
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.
242 //
243
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;
250
251     // loop on tracks and create references
252     Int_t i, icharge, type;
253     Short_t charge;
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;
264         else {
265             AliError("Found particle with ZERO charge!!!");
266             continue;
267         }
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)
273         if (mcinfo) {
274             fPerfectPID->AddIndex (i, icharge, (Int_t)AliRsnPID::InternalType(mcinfo->PDG()));
275         }
276     }
277
278     // adjusts the size of arrays
279     if (fNoPID) fNoPID->SetCorrectIndexSize();
280     if (fPerfectPID) fPerfectPID->SetCorrectIndexSize();
281     if (fRealisticPID) fRealisticPID->SetCorrectIndexSize();
282 }
283
284 //_____________________________________________________________________________
285 void AliRsnEvent::Print (Option_t *option) const
286 {
287 //
288 // Lists the details of the event, and the ones of each
289 // contained track.
290 // The options are passed to AliRsnDaughter::Print().
291 // Look at that method to understand option values.
292 //
293
294     cout << "...Multiplicity     : " << fTracks->GetEntries() << endl;
295     cout << "...Primary vertex   : " << fPVx << ' ' << fPVy << ' ' << fPVz << endl;
296
297     TObjArrayIter iter (fTracks);
298     AliRsnDaughter *d = 0;
299     while ((d = (AliRsnDaughter*) iter.Next())) {
300         cout << "....Track #" << fTracks->IndexOf (d) << endl;
301         d->Print (option);
302     }
303 }
304
305 //_____________________________________________________________________________
306 Int_t AliRsnEvent::GetMultiplicity() const
307 {
308 //
309 // Get number of all tracks
310 //
311
312     if (!fTracks) return 0;
313     return fTracks->GetEntries();
314 }
315
316 //_____________________________________________________________________________
317 Int_t AliRsnEvent::GetNCharged (Char_t sign)
318 {
319 //
320 // Get number of charged tracks
321 //
322
323     Int_t icharge;
324     icharge = ChargeIndex (sign);
325     if (icharge < 0) return 0;
326     TArrayI *charged = GetCharged(sign);
327     if (!charged) return 0;
328     return charged->GetSize();
329 }
330
331 //_____________________________________________________________________________
332 Int_t AliRsnEvent::Fill (TObjArray *array)
333 {
334 //
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.
340 //
341
342     // clear the array if it is already instantiated,
343     // create if otherwise
344     if (fTracks) fTracks->Delete();
345     else Init();
346
347     // copy argument entries into data-member
348     Int_t errors = 0;
349     AliRsnDaughter *track = 0;
350     TObjArrayIter iter (array);
351     while ((track = (AliRsnDaughter*) iter.Next())) {
352         AliRsnDaughter *ref = AddTrack (*track);
353         if (!ref) {
354             AliWarning (Form ("Problem occurred when copying track #%d from passed array", array->IndexOf (track)));
355             errors++;
356         }
357     }
358
359     return errors;
360 }
361
362 //_____________________________________________________________________________
363 Int_t AliRsnEvent::ChargeIndex (Char_t sign) const
364 //
365 // Returns the array index corresponding to charge
366 // 0 for positive, 1 for negative
367 //
368 {
369     if (sign == '+') return 0;
370     else if (sign == '-') return 1;
371     else {
372         AliError (Form ("Character '%c' not recognized as charge sign", sign));
373         return -1;
374     }
375 }