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