]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnEvent.cxx
Package revised - New AnalysisTask's - Added more functions
[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 **************************************************************************/
0dffcc8a 15
06351446 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//
0dffcc8a 28
06351446 29#include <Riostream.h>
0dffcc8a 30
7c2974c8 31#include "AliLog.h"
7c2974c8 32
06351446 33#include "AliRsnDaughter.h"
0dffcc8a 34#include "AliRsnEvent.h"
06351446 35#include "AliRsnMCInfo.h"
0dffcc8a 36
aec0ec32 37ClassImp(AliRsnEvent)
0dffcc8a 38
7c2974c8 39//_____________________________________________________________________________
0dffcc8a 40AliRsnEvent::AliRsnEvent() :
aec0ec32 41 TNamed("rsnEvent", ""),
42 fPVx(0.0),
43 fPVy(0.0),
44 fPVz(0.0),
45 fTracks(0x0),
06351446 46 fNoPID(0x0),
aec0ec32 47 fPerfectPID(0x0),
48 fRealisticPID(0x0)
2f769150 49{
06351446 50//
51// Default constructor
7c2974c8 52// (implemented but not recommended for direct use)
06351446 53//
0dffcc8a 54}
7c2974c8 55
56//_____________________________________________________________________________
aec0ec32 57AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
58 TNamed(event),
59 fPVx(event.fPVx),
60 fPVy(event.fPVy),
61 fPVz(event.fPVz),
62 fTracks(0x0),
06351446 63 fNoPID(0x0),
aec0ec32 64 fPerfectPID(0x0),
65 fRealisticPID(0x0)
2f769150 66{
06351446 67//
0dffcc8a 68// Copy constructor.
06351446 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
aec0ec32 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));
06351446 77
aec0ec32 78 // fill PID index arrays
79 // FillPIDArrays();
06351446 80
aec0ec32 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));
2f769150 84}
7c2974c8 85
86//_____________________________________________________________________________
06351446 87AliRsnEvent& AliRsnEvent::operator= (const AliRsnEvent &event)
0dffcc8a 88{
06351446 89//
90// Works in the same way as the copy constructor.
91//
aec0ec32 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 {
109 if (!fNoPID) fNoPID = new AliRsnPIDIndex(* (event.fNoPID));
110 else (*fNoPID) = * (event.fNoPID);
111 }
112 if (event.fPerfectPID)
113 {
114 if (!fPerfectPID) fPerfectPID = new AliRsnPIDIndex(* (event.fPerfectPID));
115 else (*fPerfectPID) = * (event.fPerfectPID);
116 }
117 if (event.fRealisticPID)
118 {
119 if (!fRealisticPID) fRealisticPID = new AliRsnPIDIndex(* (event.fRealisticPID));
120 else (*fRealisticPID) = * (event.fRealisticPID);
121 }
122
123 // return this object
124 return (*this);
0dffcc8a 125}
7c2974c8 126
127//_____________________________________________________________________________
128AliRsnEvent::~AliRsnEvent()
2f769150 129{
06351446 130//
7c2974c8 131// Destructor.
06351446 132// Deletes the TClonesArray, after clearing its content.
133// Other memory-allocating arrays are cleared by their
134// destructor, which is automatically called from here.
135//
136
aec0ec32 137 Clear();
138 if (fTracks) delete fTracks;
0dffcc8a 139}
7c2974c8 140
141//_____________________________________________________________________________
142void AliRsnEvent::Init()
2f769150 143{
06351446 144//
145// Initialize TClonesArray data-member.
146//
147
aec0ec32 148 fTracks = new TClonesArray("AliRsnDaughter", 1);
149 //fTracks->BypassStreamer (kFALSE);
0dffcc8a 150}
7c2974c8 151
152//_____________________________________________________________________________
aec0ec32 153void AliRsnEvent::Clear(Option_t* /*option*/)
2f769150 154{
06351446 155//
156// Empties the collections (does not delete the objects).
157// The track collection is emptied only at the end.
158// Since some objects could be uninitialized, some
159// "if" statement are used.
160//
161
aec0ec32 162 if (fTracks) fTracks->Delete();
163 delete fNoPID;
164 fNoPID = 0x0;
165 delete fPerfectPID;
166 fPerfectPID = 0x0;
167 delete fRealisticPID;
168 fRealisticPID = 0x0;
06351446 169}
170
171//_____________________________________________________________________________
aec0ec32 172AliRsnDaughter* AliRsnEvent::AddTrack(AliRsnDaughter track)
06351446 173{
174//
175// Stores a new track into the array and returns
176// a reference pointer to it (which is NULL in case of errors).
177//
178
aec0ec32 179 Int_t nextIndex = fTracks->GetEntriesFast();
180 TClonesArray &tracks = (*fTracks);
181 AliRsnDaughter *copy = new(tracks[nextIndex]) AliRsnDaughter(track);
182 return copy;
06351446 183}
184
185//_____________________________________________________________________________
186AliRsnDaughter* AliRsnEvent::GetTrack(Int_t index)
187{
188//
189// Returns one track in the collection
190// given the absolute index in the global TClonesArray
191//
aec0ec32 192 return (AliRsnDaughter*) fTracks->UncheckedAt(index);
06351446 193}
194
e2bafbbc 195//_____________________________________________________________________________
196AliRsnDaughter* AliRsnEvent::GetLeadingParticle
197(Double_t ptMin, AliRsnPID::EType type, Bool_t realistic)
198{
199//
200// Returns the particle in this event with largest transverse momentum,
201// provided that this momentum is larger than the first argument
202// and that the PID type correspond to the second argument.
203// If one specifies "AliRsnPID::kUnknown" as second arguments, the PID check is not done.
204//
205
aec0ec32 206 Double_t prob;
207 AliRsnPID::EType trackType;
208 AliRsnDaughter *track, *leading = 0x0;
209 TObjArrayIter iter(fTracks);
210 while ((track = (AliRsnDaughter*) iter.Next()))
211 {
212 if (track->Pt() < ptMin) continue;
213 if (realistic)
214 {
215 AliRsnDaughter::SetPIDMethod(AliRsnDaughter::kRealistic);
e2bafbbc 216 }
aec0ec32 217 else
218 {
219 AliRsnDaughter::SetPIDMethod(AliRsnDaughter::kPerfect);
220 }
221 trackType = track->PIDType(prob);
222 if (type != AliRsnPID::kUnknown && trackType != type) continue;
223 ptMin = track->Pt();
224 leading = track;
225 }
226
227 return leading;
e2bafbbc 228}
229
230//_____________________________________________________________________________
231Int_t AliRsnEvent::GetLastFastTrack
232(Double_t ptMin, AliRsnPID::EType type, Bool_t realistic)
233{
234//
235// Loops on the list of tracks (eventually skipping the ones which do not match
236// the given PID type with the specified PID method) and returns the index of the last
237// one whose transverse momentum is still larger than a specified value.
238// When no tracks are found this way, the value "-1" is returned.
239//
240
aec0ec32 241 if (realistic)
242 {
243 AliRsnDaughter::SetPIDMethod(AliRsnDaughter::kRealistic);
244 }
245 else
246 {
247 AliRsnDaughter::SetPIDMethod(AliRsnDaughter::kPerfect);
248 }
249
250 Double_t prob;
251 Int_t i, nTracks = fTracks->GetEntries(), lastIndex = -1;
252 for (i = 0; i < nTracks; i++)
253 {
254 AliRsnDaughter *d = (AliRsnDaughter*) fTracks->At(i);
255 AliRsnPID::EType trackType = d->PIDType(prob);
256 if (type != AliRsnPID::kUnknown && trackType != type) continue;
257 if (d->Pt() >= ptMin) lastIndex = i;
258 }
259
260 return lastIndex;
e2bafbbc 261}
262
06351446 263//_____________________________________________________________________________
aec0ec32 264TArrayI* AliRsnEvent::GetCharged(Char_t sign)
06351446 265{
266//
267// Returns an array with the indexes of all tracks with a given charge
268// (arg can be '+' or '-'), irrespective of its PID.
269// When the argument is wrong, a NULL pointer is returned.
270//
aec0ec32 271 if (fNoPID) return fNoPID->GetTracksArray(sign, AliRsnPID::kUnknown);
272 return 0x0;
06351446 273}
274
275//_____________________________________________________________________________
276TArrayI * AliRsnEvent::GetTracksArray
e2bafbbc 277(AliRsnDaughter::EPIDMethod pidtype, Char_t sign, AliRsnPID::EType type)
06351446 278{
279//
280// Returns an array of indexes of all tracks in this event
281// which match the charge sign and PID type in the arguments,
282// according to one of the allowed PID methods (perfect or realistic).
283// It retrieves this array from the AliRsnPIDIndex data members.
284// If the arguments are wrong a NULL pointer is returned.
285//
286
aec0ec32 287 switch (pidtype)
288 {
289 case AliRsnDaughter::kRealistic:
290 if (fRealisticPID)
291 {
292 return fRealisticPID->GetTracksArray(sign, type);
293 }
294 break;
295 case AliRsnDaughter::kPerfect:
296 if (fPerfectPID)
297 {
298 return fPerfectPID->GetTracksArray(sign, type);
299 }
300 break;
301 case AliRsnDaughter::kNoPID:
302 if (fNoPID)
303 {
304 return fNoPID->GetTracksArray(sign, AliRsnPID::kUnknown);
305 }
306 break;
307 default:
308 AliError("Handled PID methods here are only fNoPID,kPerfect and kRealistic. Nothing done.");
309 return 0x0;
310 }
311 return 0x0;
0dffcc8a 312}
7c2974c8 313
314//_____________________________________________________________________________
06351446 315void AliRsnEvent::FillPIDArrays()
2f769150 316{
06351446 317//
318// Initializes and fills the AliRsnPIDIndex objects containing
319// arrays of indexes for each possible charge and PID type.
320// This method is the unique way to do this, for safety reasons.
321//
322
aec0ec32 323 if (fNoPID) delete fNoPID;
324 if (fPerfectPID) delete fPerfectPID;
325 if (fRealisticPID) delete fRealisticPID;
326 fNoPID = new AliRsnPIDIndex(2000);
327 fPerfectPID = new AliRsnPIDIndex(2000);
328 fRealisticPID = new AliRsnPIDIndex(2000);
329
330 // set the default type to Realistic
331 AliRsnDaughter::SetPIDMethod(AliRsnDaughter::kRealistic);
332
333 // loop on tracks and create references
334 Double_t prob;
335 Int_t i, icharge, type;
336 Short_t charge;
337 AliRsnMCInfo *mcinfo = 0;
338 AliRsnDaughter *track = 0;
339 TObjArrayIter iter(fTracks);
340 while ((track = (AliRsnDaughter*) iter.Next()))
341 {
342 charge = track->Charge();
343 type = (Int_t) track->PIDType(prob);
344 i = fTracks->IndexOf(track);
345 mcinfo = track->GetMCInfo();
346 if (charge > 0) icharge = 0;
347 else if (charge < 0) icharge = 1;
348 else
349 {
350 AliError("Found particle with ZERO charge!!!");
351 continue;
352 }
353 // add to charged array
354 fNoPID->AddIndex(i, icharge, (Int_t) AliRsnPID::kUnknown);
355 // add to realistic PID array
356 fRealisticPID->AddIndex(i, icharge, (Int_t) type);
357 // add to perfect PID array (needs MCInfo present)
358 if (mcinfo)
359 {
360 fPerfectPID->AddIndex(i, icharge, (Int_t) AliRsnPID::InternalType(mcinfo->PDG()));
7c2974c8 361 }
aec0ec32 362 }
06351446 363
aec0ec32 364 // adjusts the size of arrays
365 if (fNoPID) fNoPID->SetCorrectIndexSize();
366 if (fPerfectPID) fPerfectPID->SetCorrectIndexSize();
367 if (fRealisticPID) fRealisticPID->SetCorrectIndexSize();
0dffcc8a 368}
7c2974c8 369
370//_____________________________________________________________________________
aec0ec32 371void AliRsnEvent::Print(Option_t *option) const
2f769150 372{
06351446 373//
7c2974c8 374// Lists the details of the event, and the ones of each
06351446 375// contained track.
7c2974c8 376// The options are passed to AliRsnDaughter::Print().
377// Look at that method to understand option values.
06351446 378//
7c2974c8 379
aec0ec32 380 cout << "...Multiplicity : " << fTracks->GetEntries() << endl;
381 cout << "...Primary vertex : " << fPVx << ' ' << fPVy << ' ' << fPVz << endl;
382
383 TObjArrayIter iter(fTracks);
384 AliRsnDaughter *d = 0;
385 while ((d = (AliRsnDaughter*) iter.Next()))
386 {
387 cout << "....Track #" << fTracks->IndexOf(d) << endl;
388 d->Print(option);
389 }
390}
06351446 391
aec0ec32 392//_____________________________________________________________________________
393void AliRsnEvent::CorrectByPrimaryVertex()
394{
395//
396// Corrects the X,Y,Z position of DCA vertex of all tracks
397// by the amount of stored primary vertex
398//
399
400 TObjArrayIter iter(fTracks);
7c2974c8 401 AliRsnDaughter *d = 0;
06351446 402 while ((d = (AliRsnDaughter*) iter.Next())) {
aec0ec32 403 d->ShiftZero(fPVx, fPVy, fPVz);
7c2974c8 404 }
0dffcc8a 405}
7c2974c8 406
407//_____________________________________________________________________________
06351446 408Int_t AliRsnEvent::GetMultiplicity() const
2f769150 409{
06351446 410//
7c2974c8 411// Get number of all tracks
06351446 412//
413
aec0ec32 414 if (!fTracks) return 0;
415 return fTracks->GetEntries();
0dffcc8a 416}
7c2974c8 417
418//_____________________________________________________________________________
aec0ec32 419Int_t AliRsnEvent::GetNCharged(Char_t sign)
7c2974c8 420{
06351446 421//
422// Get number of charged tracks
423//
7c2974c8 424
aec0ec32 425 Int_t icharge;
426 icharge = ChargeIndex(sign);
427 if (icharge < 0) return 0;
428 TArrayI *charged = GetCharged(sign);
429 if (!charged) return 0;
430 return charged->GetSize();
7c2974c8 431}
432
433//_____________________________________________________________________________
aec0ec32 434Int_t AliRsnEvent::Fill(TObjArray *array)
7c2974c8 435{
06351446 436//
437// Fills the data-member TClonesArray of tracks with
438// the ones stored in the array passed as argument.
439// If this data-member is already present, it is cleared.
440// Returns the number of tracks which raised problems
441// while attempting to add them. Zero is the best.
442//
443
aec0ec32 444 // clear the array if it is already instantiated,
445 // create if otherwise
446 if (fTracks) fTracks->Delete();
447 else Init();
448
449 // copy argument entries into data-member
450 Int_t errors = 0;
451 AliRsnDaughter *track = 0;
452 TObjArrayIter iter(array);
453 while ((track = (AliRsnDaughter*) iter.Next()))
454 {
455 AliRsnDaughter *ref = AddTrack(*track);
456 if (!ref)
457 {
458 AliWarning(Form("Problem occurred when copying track #%d from passed array", array->IndexOf(track)));
459 errors++;
7c2974c8 460 }
aec0ec32 461 }
06351446 462
aec0ec32 463 return errors;
7c2974c8 464}
465
466//_____________________________________________________________________________
aec0ec32 467Int_t AliRsnEvent::ChargeIndex(Char_t sign) const
06351446 468//
469// Returns the array index corresponding to charge
470// 0 for positive, 1 for negative
471//
2f769150 472{
aec0ec32 473 if (sign == '+') return 0;
474 else if (sign == '-') return 1;
475 else
476 {
477 AliError(Form("Character '%c' not recognized as charge sign", sign));
478 return -1;
479 }
0dffcc8a 480}