Bug correction: PID Cut did not have the default ctor
[u/mrichter/AliRoot.git] / RALICE / AliEvent.cxx
CommitLineData
d16062ac 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
88cb7938 16// $Id: AliEvent.cxx,v 1.6 2002/04/26 11:23:37 nick Exp $
d16062ac 17
18///////////////////////////////////////////////////////////////////////////
19// Class AliEvent
20// Creation and investigation of an Alice physics event.
7849a8ab 21// An AliEvent can be constructed by adding AliTracks, Alivertices, AliJets
22// and/or AliCalorimeters.
d16062ac 23//
24// The basic functionality of AliEvent is identical to the one of AliVertex.
35044448 25// So, an AliEvent may be used as the primary vertex with some additional
26// functionality compared to AliVertex.
d16062ac 27//
7849a8ab 28// To provide maximal flexibility to the user, the two modes of track/jet/vertex
29// storage as described in AliJet and AliVertex can be used.
30// In addition an identical structure is provided for the storage of AliCalorimeter
31// objects, which can be selected by means of the memberfunction SetCalCopy().
32//
33// a) SetCalCopy(0) (which is the default).
34// Only the pointers of the 'added' calorimeters are stored.
35// This mode is typically used by making cal. studies based on a fixed set
36// of calorimeters which stays under user control or is kept on an external
37// file/tree.
38// In this way the AliEvent just represents a 'logical structure' for the
39// physics analysis.
35044448 40//
41// Note :
7849a8ab 42// Modifications made to the original calorimeters also affect the AliCalorimeter
43// objects which are stored in the AliEvent.
35044448 44//
7849a8ab 45// b) SetCalCopy(1).
46// Of every 'added' calorimeter a private copy will be made of which the pointer
47// will be stored.
48// In this way the AliEvent represents an entity on its own and modifications
49// made to the original calorimeters do not affect the AliCalorimeter objects
50// which are stored in the AliEvent.
51// This mode will allow 'adding' many different AliCalorimeters into an AliEvent by
52// creating only one AliCalorimeter instance in the main programme and using the
53// AliCalorimeter::Reset() and AliCalorimeter parameter setting memberfunctions.
54//
8e8e6c7f 55// See also the documentation provided for the memberfunction SetOwner().
56//
7849a8ab 57// Coding example to make an event consisting of a primary vertex,
58// 2 secondary vertices and a calorimeter.
d16062ac 59// --------------------------------------------------------------
7849a8ab 60// vp contains the tracks 1,2,3 and 4 (primary vertex)
61// v1 contains the tracks 5,6 and 7 (sec. vertex)
62// v2 contains the jets 1 and 2 (sec. vertex)
63//
7849a8ab 64// AliEvent evt;
65//
66// Specify the event object as the repository of all objects
67// for the event building and physics analysis.
68//
69// evt.SetCalCopy(1);
70// evt.SetTrackCopy(1);
71//
72// Fill the event structure with the basic objects
73//
35044448 74// AliCalorimeter emcal;
75// ...
76// ... // code to fill the calorimeter data
77// ...
78//
7849a8ab 79// evt.AddCalorimeter(emcal);
80//
35044448 81// AliTrack* tx=new AliTrack();
7849a8ab 82// for (Int_t i=0; i<10; i++)
83// {
d16062ac 84// ...
85// ... // code to fill the track data
86// ...
7849a8ab 87// evt.AddTrack(tx);
88// tx->Reset();
89// }
90//
35044448 91// if (tx)
92// {
93// delete tx;
94// tx=0;
95// }
96//
7849a8ab 97// Build the event structure (vertices, jets, ...) for physics analysis
98// based on the basic objects from the event repository.
d16062ac 99//
100// AliJet j1,j2;
7849a8ab 101// for (Int_t i=0; i<evt.GetNtracks(); i++)
102// {
103// tx=evt.GetTrack(i);
d16062ac 104// ...
105// ... // code to fill the jet data
106// ...
7849a8ab 107// }
d16062ac 108//
7849a8ab 109// AliVertex vp;
35044448 110// tx=evt.GetTrack(1);
7849a8ab 111// vp.AddTrack(tx);
35044448 112// tx=evt.GetTrack(2);
7849a8ab 113// vp.AddTrack(tx);
35044448 114// tx=evt.GetTrack(3);
7849a8ab 115// vp.AddTrack(tx);
35044448 116// tx=evt.GetTrack(4);
7849a8ab 117// vp.AddTrack(tx);
d16062ac 118//
7849a8ab 119// Float_t rp[3]={2.4,0.1,-8.5};
120// vp.SetPosition(rp,"car");
d16062ac 121//
7849a8ab 122// AliVertex v1;
35044448 123// tx=evt.GetTrack(5);
7849a8ab 124// v1.AddTrack(tx);
35044448 125// tx=evt.GetTrack(6);
7849a8ab 126// v1.AddTrack(tx);
35044448 127// tx=evt.GetTrack(7);
7849a8ab 128// v1.AddTrack(tx);
d16062ac 129//
130// Float_t r1[3]={1.6,-3.2,5.7};
131// v1.SetPosition(r1,"car");
132//
d16062ac 133//
7849a8ab 134// AliVertex v2;
135// v2.SetJetCopy(1);
d16062ac 136// v2.AddJet(j1);
137// v2.AddJet(j2);
138//
139// Float_t r2[3]={6.2,4.8,1.3};
140// v2.SetPosition(r2,"car");
141//
7849a8ab 142// Specify the vertices v1 and v2 as secondary vertices of the primary
143//
144// vp.SetVertexCopy(1);
145// vp.AddVertex(v1);
146// vp.AddVertex(v2);
147//
148// Enter the physics structures into the event
149// evt.SetVertexCopy(1);
150// evt.AddVertex(vp,0);
151//
152// The jets j1 and j2 are already available via sec. vertex v2,
153// but can be made available also from the event itself if desired.
154// AliJet* jx;
155// jx=v2.GetJet(1);
156// evt.AddJet(jx,0);
157// jx=v2.GetJet(2);
158// evt.AddJet(jx,0);
159//
84bb7c66 160// evt.Data("sph");
d16062ac 161// v1.ListAll();
162// v2.List("cyl");
163//
164// Float_t etot=evt.GetEnergy();
165// Ali3Vector ptot=evt.Get3Momentum();
166// Float_t loc[3];
167// evt.GetPosition(loc,"sph");
168// AliPosition r=v1.GetPosition();
84bb7c66 169// r.Data();
d16062ac 170// Int_t nt=v2.GetNtracks();
171// AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
172//
d16062ac 173// evt.List();
174//
175// Int_t nv=evt.GetNvtx();
7849a8ab 176// AliVertex* vx=evt.GetVertex(1); // Access primary vertex
d16062ac 177// Float_t e=vx->GetEnergy();
178//
179// Float_t M=evt.GetInvmass();
180//
181// Reconstruct the event from scratch
182//
183// evt.Reset();
184// evt.SetNvmax(25); // Increase initial no. of sec. vertices
7849a8ab 185// ...
186// ... // code to create tracks etc...
187// ...
d16062ac 188//
189// Note : All quantities are in GeV, GeV/c or GeV/c**2
190//
191//--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
1ce8a857 192//- Modified: NvE $Date: 2003/02/03 13:19:44 $ UU-SAP Utrecht
d16062ac 193///////////////////////////////////////////////////////////////////////////
194
195#include "AliEvent.h"
196
197ClassImp(AliEvent) // Class implementation to enable ROOT I/O
198
199AliEvent::AliEvent()
200{
201// Default constructor.
202// All variables initialised to default values.
203 fDaytime.Set();
204 fRun=0;
205 fEvent=0;
4575fcea 206 fAproj=0;
207 fZproj=0;
208 fPnucProj=0;
da17f667 209 fIdProj=0;
4575fcea 210 fAtarg=0;
211 fZtarg=0;
212 fPnucTarg=0;
da17f667 213 fIdTarg=0;
7849a8ab 214 fNcals=0;
215 fCalorimeters=0;
216 fCalCopy=0;
d16062ac 217}
218///////////////////////////////////////////////////////////////////////////
81508922 219AliEvent::AliEvent(Int_t n): AliVertex(n)
d16062ac 220{
221// Create an event to hold initially a maximum of n tracks
222// All variables initialised to default values
88cb7938 223 cout << "AliEvent init with n = " << n << endl;
d16062ac 224 fDaytime.Set();
225 fRun=0;
226 fEvent=0;
4575fcea 227 fAproj=0;
228 fZproj=0;
229 fPnucProj=0;
da17f667 230 fIdProj=0;
4575fcea 231 fAtarg=0;
232 fZtarg=0;
233 fPnucTarg=0;
da17f667 234 fIdTarg=0;
7849a8ab 235 fNcals=0;
236 fCalorimeters=0;
237 fCalCopy=0;
d16062ac 238}
239///////////////////////////////////////////////////////////////////////////
240AliEvent::~AliEvent()
241{
242// Default destructor
7849a8ab 243 if (fCalorimeters)
244 {
7849a8ab 245 delete fCalorimeters;
246 fCalorimeters=0;
247 }
d16062ac 248}
249///////////////////////////////////////////////////////////////////////////
250void AliEvent::Reset()
251{
252// Reset all variables to default values
253// The max. number of tracks is set to the initial value again
254// The max. number of vertices is set to the default value again
8e8e6c7f 255// Note : The CalCopy mode is maintained as it was set by the user before.
d16062ac 256 fDaytime.Set();
257 fRun=0;
258 fEvent=0;
4575fcea 259 fAproj=0;
260 fZproj=0;
261 fPnucProj=0;
da17f667 262 fIdProj=0;
4575fcea 263 fAtarg=0;
264 fZtarg=0;
265 fPnucTarg=0;
da17f667 266 fIdTarg=0;
d16062ac 267
7849a8ab 268 fNcals=0;
269 if (fCalorimeters)
270 {
7849a8ab 271 delete fCalorimeters;
272 fCalorimeters=0;
273 }
274
d16062ac 275 AliVertex::Reset();
276}
277///////////////////////////////////////////////////////////////////////////
8e8e6c7f 278void AliEvent::SetOwner(Bool_t own)
279{
280// Set ownership of all added objects.
281// The default parameter is own=kTRUE.
282//
283// Invokation of this memberfunction also sets all the copy modes
284// (e.g. TrackCopy & co.) according to the value of own.
285//
286// This function (with own=kTRUE) is particularly useful when reading data
287// from a tree/file, since Reset() will then actually remove all the
288// added objects from memory irrespective of the copy mode settings
289// during the tree/file creation process. In this way it provides a nice way
290// of preventing possible memory leaks in the reading/analysis process.
291//
292// In addition this memberfunction can also be used as a shortcut to set all
293// copy modes in one go during a tree/file creation process.
294// However, in this case the user has to take care to only set/change the
295// ownership (and copy mode) for empty objects (e.g. newly created objects
296// or after invokation of the Reset() memberfunction) otherwise it will
297// very likely result in inconsistent destructor behaviour.
298
299 Int_t mode=1;
300 if (!own) mode=0;
301 if (fCalorimeters) fCalorimeters->SetOwner(own);
302 fCalCopy=mode;
303
304 AliVertex::SetOwner(own);
305}
306///////////////////////////////////////////////////////////////////////////
d16062ac 307void AliEvent::SetDayTime(TDatime& stamp)
308{
309// Set the date and time stamp for this event
310 fDaytime=stamp;
311}
312///////////////////////////////////////////////////////////////////////////
313void AliEvent::SetRunNumber(Int_t run)
314{
315// Set the run number for this event
316 fRun=run;
317}
318///////////////////////////////////////////////////////////////////////////
319void AliEvent::SetEventNumber(Int_t evt)
320{
321// Set the event number for this event
322 fEvent=evt;
323}
324///////////////////////////////////////////////////////////////////////////
325TDatime AliEvent::GetDayTime()
326{
327// Provide the date and time stamp for this event
328 return fDaytime;
329}
330///////////////////////////////////////////////////////////////////////////
331Int_t AliEvent::GetRunNumber()
332{
333// Provide the run number for this event
334 return fRun;
335}
336///////////////////////////////////////////////////////////////////////////
337Int_t AliEvent::GetEventNumber()
338{
339// Provide the event number for this event
340 return fEvent;
341}
342///////////////////////////////////////////////////////////////////////////
da17f667 343void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id)
4575fcea 344{
da17f667 345// Set the projectile A, Z, momentum per nucleon and user defined particle ID.
346// By default the particle ID is set to zero.
4575fcea 347 fAproj=a;
348 fZproj=z;
349 fPnucProj=pnuc;
da17f667 350 fIdProj=id;
4575fcea 351}
352///////////////////////////////////////////////////////////////////////////
353Int_t AliEvent::GetProjectileA()
354{
355// Provide the projectile A value.
356 return fAproj;
357}
358///////////////////////////////////////////////////////////////////////////
359Int_t AliEvent::GetProjectileZ()
360{
361// Provide the projectile Z value.
362 return fZproj;
363}
364///////////////////////////////////////////////////////////////////////////
365Double_t AliEvent::GetProjectilePnuc()
366{
367// Provide the projectile momentum value per nucleon.
368 return fPnucProj;
369}
370///////////////////////////////////////////////////////////////////////////
da17f667 371Int_t AliEvent::GetProjectileId()
4575fcea 372{
da17f667 373// Provide the user defined particle ID of the projectile.
374 return fIdProj;
375}
376///////////////////////////////////////////////////////////////////////////
377void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id)
378{
379// Set the target A, Z, momentum per nucleon and user defined particle ID.
380// By default the particle ID is set to zero.
4575fcea 381 fAtarg=a;
382 fZtarg=z;
383 fPnucTarg=pnuc;
da17f667 384 fIdTarg=id;
4575fcea 385}
386///////////////////////////////////////////////////////////////////////////
387Int_t AliEvent::GetTargetA()
388{
389// Provide the target A value.
390 return fAtarg;
391}
392///////////////////////////////////////////////////////////////////////////
393Int_t AliEvent::GetTargetZ()
394{
395// Provide the target Z value.
396 return fZtarg;
397}
398///////////////////////////////////////////////////////////////////////////
399Double_t AliEvent::GetTargetPnuc()
400{
401// Provide the target momentum value per nucleon.
402 return fPnucTarg;
403}
404///////////////////////////////////////////////////////////////////////////
da17f667 405Int_t AliEvent::GetTargetId()
406{
407// Provide the user defined particle ID of the target.
408 return fIdTarg;
409}
410///////////////////////////////////////////////////////////////////////////
84bb7c66 411void AliEvent::HeaderData()
d16062ac 412{
413// Provide event header information
1ce8a857 414 cout << " *AliEvent::Data* Run : " << fRun << " Event : " << fEvent
415 << " Date : " << fDaytime.AsString() << endl;
d16062ac 416
1ce8a857 417 ShowCalorimeters();
d16062ac 418}
419///////////////////////////////////////////////////////////////////////////
84bb7c66 420void AliEvent::Data(TString f)
d16062ac 421{
422// Provide event information within the coordinate frame f
84bb7c66 423 HeaderData();
424 AliVertex::Data(f);
d16062ac 425}
426///////////////////////////////////////////////////////////////////////////
7849a8ab 427Int_t AliEvent::GetNcalorimeters()
428{
429// Provide the number of stored calorimeter systems
430 return fNcals;
431}
432///////////////////////////////////////////////////////////////////////////
433void AliEvent::AddCalorimeter(AliCalorimeter& c)
434{
435// Add a calorimeter system to the event
6516b62d 436 if (!fCalorimeters)
437 {
438 fCalorimeters=new TObjArray();
439 if (fCalCopy) fCalorimeters->SetOwner();
440 }
7849a8ab 441
442 // Add the calorimeter system to this event
443 fNcals++;
444 if (fCalCopy)
445 {
6516b62d 446 fCalorimeters->AddLast((AliCalorimeter*)c.Clone());
7849a8ab 447 }
448 else
449 {
450 fCalorimeters->AddLast(&c);
451 }
452}
453///////////////////////////////////////////////////////////////////////////
454void AliEvent::SetCalCopy(Int_t j)
455{
456// (De)activate the creation of private copies of the added calorimeters.
457// j=0 ==> No private copies are made; pointers of original cals. are stored.
458// j=1 ==> Private copies of the cals. are made and these pointers are stored.
459//
460// Note : Once the storage contains pointer(s) to AliCalorimeter(s) one cannot
461// change the CalCopy mode anymore.
462// To change the CalCopy mode for an existing AliEvent containing
463// calorimeters one first has to invoke Reset().
464 if (!fCalorimeters)
465 {
466 if (j==0 || j==1)
467 {
468 fCalCopy=j;
469 }
470 else
471 {
472 cout << "*AliEvent::SetCalCopy* Invalid argument : " << j << endl;
473 }
474 }
475 else
476 {
477 cout << "*AliEvent::SetCalCopy* Storage already contained calorimeters."
478 << " ==> CalCopy mode not changed." << endl;
479 }
480}
481///////////////////////////////////////////////////////////////////////////
482Int_t AliEvent::GetCalCopy()
483{
484// Provide value of the CalCopy mode.
485// 0 ==> No private copies are made; pointers of original cals. are stored.
486// 1 ==> Private copies of the cals. are made and these pointers are stored.
487 return fCalCopy;
488}
489///////////////////////////////////////////////////////////////////////////
490AliCalorimeter* AliEvent::GetCalorimeter(Int_t i)
491{
492// Return the i-th calorimeter of this event
493 if (!fCalorimeters)
494 {
495 cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
496 return 0;
497 }
498 else
499 {
500 if (i<=0 || i>fNcals)
501 {
502 cout << " *AliEvent::GetCalorimeter* Invalid argument i : " << i
503 << " Ncals = " << fNcals << endl;
504 return 0;
505 }
506 else
507 {
508 return (AliCalorimeter*)fCalorimeters->At(i-1);
509 }
510 }
511}
512///////////////////////////////////////////////////////////////////////////
513AliCalorimeter* AliEvent::GetCalorimeter(TString name)
514{
515// Return the calorimeter with name tag "name"
516 if (!fCalorimeters)
517 {
518 cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
519 return 0;
520 }
521 else
522 {
523 AliCalorimeter* cx;
524 TString s;
525 for (Int_t i=0; i<fNcals; i++)
526 {
527 cx=(AliCalorimeter*)fCalorimeters->At(i);
35044448 528 if (cx)
529 {
530 s=cx->GetName();
531 if (s == name) return cx;
532 }
7849a8ab 533 }
534
535 return 0; // No matching name found
536 }
537}
538///////////////////////////////////////////////////////////////////////////
1ce8a857 539void AliEvent::ShowCalorimeters()
540{
541// Provide an overview of the available calorimeter systems.
542 if (fNcals>0)
543 {
544 cout << " The following " << fNcals << " calorimeter systems are available :" << endl;
545 for (Int_t i=1; i<=fNcals; i++)
546 {
547 AliCalorimeter* cal=GetCalorimeter(i);
548 if (cal) cout << " Calorimeter number : " << i << " Name : " << cal->GetName() << endl;
549 }
550 }
551 else
552 {
553 cout << " No calorimeters present for this event." << endl;
554 }
555}
556///////////////////////////////////////////////////////////////////////////
d16062ac 557