]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliEvent.cxx
08-mar-2003 NvE Compiler option /GR introduced for MSVC++ in mklibs.bat to explicitly...
[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.11 2003/02/25 12:36:28 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 AliCalorimeters.
23 //
24 // The basic functionality of AliEvent is identical to the one of AliVertex.
25 // So, an AliEvent may be used as the primary vertex with some additional
26 // functionality compared to AliVertex.
27 //
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.
40 //
41 //    Note :
42 //    Modifications made to the original calorimeters also affect the AliCalorimeter
43 //    objects which are stored in the AliEvent. 
44 //
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 //
55 // See also the documentation provided for the memberfunction SetOwner(). 
56 //
57 // Coding example to make an event consisting of a primary vertex,
58 // 2 secondary vertices and a calorimeter.
59 // --------------------------------------------------------------
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 //
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 // 
74 //        AliCalorimeter emcal;
75 //         ...
76 //         ... // code to fill the calorimeter data
77 //         ...
78 //
79 //        evt.AddCalorimeter(emcal);
80 //
81 //        AliTrack* tx=new AliTrack();
82 //        for (Int_t i=0; i<10; i++)
83 //        {
84 //         ...
85 //         ... // code to fill the track data
86 //         ...
87 //         evt.AddTrack(tx);
88 //         tx->Reset(); 
89 //        }
90 //
91 //        if (tx)
92 //        {
93 //         delete tx;
94 //         tx=0;
95 //        }
96 //
97 // Build the event structure (vertices, jets, ...) for physics analysis
98 // based on the basic objects from the event repository.
99 //
100 //        AliJet j1,j2;
101 //        for (Int_t i=0; i<evt.GetNtracks(); i++)
102 //        {
103 //         tx=evt.GetTrack(i);
104 //         ...
105 //         ... // code to fill the jet data
106 //         ...
107 //        }
108 //
109 //        AliVertex vp;
110 //        tx=evt.GetTrack(1);
111 //        vp.AddTrack(tx);
112 //        tx=evt.GetTrack(2);
113 //        vp.AddTrack(tx);
114 //        tx=evt.GetTrack(3);
115 //        vp.AddTrack(tx);
116 //        tx=evt.GetTrack(4);
117 //        vp.AddTrack(tx);
118 //
119 //        Float_t rp[3]={2.4,0.1,-8.5};
120 //        vp.SetPosition(rp,"car");
121 //
122 //        AliVertex v1;
123 //        tx=evt.GetTrack(5);
124 //        v1.AddTrack(tx);
125 //        tx=evt.GetTrack(6);
126 //        v1.AddTrack(tx);
127 //        tx=evt.GetTrack(7);
128 //        v1.AddTrack(tx);
129 //
130 //        Float_t r1[3]={1.6,-3.2,5.7};
131 //        v1.SetPosition(r1,"car");
132 //
133 //
134 //        AliVertex v2;
135 //        v2.SetJetCopy(1);
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 //
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 // 
160 //        evt.Data("sph");
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();
169 //        r.Data(); 
170 //        Int_t nt=v2.GetNtracks();
171 //        AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
172 //
173 //        evt.List();
174 //
175 //        Int_t nv=evt.GetNvtx();
176 //        AliVertex* vx=evt.GetVertex(1); // Access primary vertex
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
185 //        ...
186 //        ... // code to create tracks etc... 
187 //        ...
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
192 //- Modified: NvE $Date: 2003/02/25 12:36:28 $ UU-SAP Utrecht
193 ///////////////////////////////////////////////////////////////////////////
194
195 #include "AliEvent.h"
196 #include "Riostream.h"
197  
198 ClassImp(AliEvent) // Class implementation to enable ROOT I/O
199  
200 AliEvent::AliEvent() : AliVertex()
201 {
202 // Default constructor.
203 // All variables initialised to default values.
204  fDaytime.Set();
205  fRun=0;
206  fEvent=0;
207  fAproj=0;
208  fZproj=0;
209  fPnucProj=0;
210  fIdProj=0;
211  fAtarg=0;
212  fZtarg=0;
213  fPnucTarg=0;
214  fIdTarg=0;
215  fNcals=0;
216  fCalorimeters=0;
217  fCalCopy=0;
218 }
219 ///////////////////////////////////////////////////////////////////////////
220 AliEvent::AliEvent(Int_t n) : AliVertex(n)
221 {
222 // Create an event to hold initially a maximum of n tracks
223 // All variables initialised to default values
224  if (n<=0)
225  {
226   cout << " *** This AliVertex initialisation was invoked via the AliEvent ctor." << endl;
227  }
228  fDaytime.Set();
229  fRun=0;
230  fEvent=0;
231  fAproj=0;
232  fZproj=0;
233  fPnucProj=0;
234  fIdProj=0;
235  fAtarg=0;
236  fZtarg=0;
237  fPnucTarg=0;
238  fIdTarg=0;
239  fNcals=0;
240  fCalorimeters=0;
241  fCalCopy=0;
242 }
243 ///////////////////////////////////////////////////////////////////////////
244 AliEvent::~AliEvent()
245 {
246 // Default destructor
247  if (fCalorimeters)
248  {
249   delete fCalorimeters;
250   fCalorimeters=0;
251  }
252 }
253 ///////////////////////////////////////////////////////////////////////////
254 AliEvent::AliEvent(AliEvent& evt) : AliVertex(evt)
255 {
256 // Copy constructor.
257  fDaytime=evt.fDaytime;
258  fRun=evt.fRun;
259  fEvent=evt.fEvent;
260  fAproj=evt.fAproj;
261  fZproj=evt.fZproj;
262  fPnucProj=evt.fPnucProj;
263  fIdProj=evt.fIdProj;
264  fAtarg=evt.fAtarg;
265  fZtarg=evt.fZtarg;
266  fPnucTarg=evt.fPnucTarg;
267  fIdTarg=evt.fIdTarg;
268  fNcals=evt.fNcals;
269  fCalCopy=evt.fCalCopy;
270
271  fCalorimeters=0;
272  if (fNcals)
273  {
274   fCalorimeters=new TObjArray(fNcals);
275   if (fCalCopy) fCalorimeters->SetOwner();
276   for (Int_t i=1; i<=fNcals; i++)
277   {
278    AliCalorimeter* cal=evt.GetCalorimeter(i);
279    if (cal)
280    {
281     if (fCalCopy)
282     {
283      fCalorimeters->Add(new AliCalorimeter(*cal));
284     }
285     else
286     {
287      fCalorimeters->Add(cal);
288     }
289    }
290   }
291  }
292 }
293 ///////////////////////////////////////////////////////////////////////////
294 void AliEvent::Reset()
295 {
296 // Reset all variables to default values
297 // The max. number of tracks is set to the initial value again
298 // The max. number of vertices is set to the default value again
299 // Note : The CalCopy mode is maintained as it was set by the user before.
300
301  AliVertex::Reset();
302
303  fDaytime.Set();
304  fRun=0;
305  fEvent=0;
306  fAproj=0;
307  fZproj=0;
308  fPnucProj=0;
309  fIdProj=0;
310  fAtarg=0;
311  fZtarg=0;
312  fPnucTarg=0;
313  fIdTarg=0;
314
315  fNcals=0;
316  if (fCalorimeters)
317  {
318   delete fCalorimeters;
319   fCalorimeters=0;
320  }
321 }
322 ///////////////////////////////////////////////////////////////////////////
323 void AliEvent::SetOwner(Bool_t own)
324 {
325 // Set ownership of all added objects. 
326 // The default parameter is own=kTRUE.
327 //
328 // Invokation of this memberfunction also sets all the copy modes
329 // (e.g. TrackCopy & co.) according to the value of own.
330 //
331 // This function (with own=kTRUE) is particularly useful when reading data
332 // from a tree/file, since Reset() will then actually remove all the
333 // added objects from memory irrespective of the copy mode settings
334 // during the tree/file creation process. In this way it provides a nice way
335 // of preventing possible memory leaks in the reading/analysis process.
336 //
337 // In addition this memberfunction can also be used as a shortcut to set all
338 // copy modes in one go during a tree/file creation process.
339 // However, in this case the user has to take care to only set/change the
340 // ownership (and copy mode) for empty objects (e.g. newly created objects
341 // or after invokation of the Reset() memberfunction) otherwise it will
342 // very likely result in inconsistent destructor behaviour.
343
344  Int_t mode=1;
345  if (!own) mode=0;
346  if (fCalorimeters) fCalorimeters->SetOwner(own);
347  fCalCopy=mode;
348
349  AliVertex::SetOwner(own);
350 }
351 ///////////////////////////////////////////////////////////////////////////
352 void AliEvent::SetDayTime(TDatime& stamp)
353 {
354 // Set the date and time stamp for this event
355  fDaytime=stamp;
356 }
357 ///////////////////////////////////////////////////////////////////////////
358 void AliEvent::SetRunNumber(Int_t run)
359 {
360 // Set the run number for this event
361  fRun=run;
362 }
363 ///////////////////////////////////////////////////////////////////////////
364 void AliEvent::SetEventNumber(Int_t evt)
365 {
366 // Set the event number for this event
367  fEvent=evt;
368 }
369 ///////////////////////////////////////////////////////////////////////////
370 TDatime AliEvent::GetDayTime()
371 {
372 // Provide the date and time stamp for this event
373  return fDaytime;
374 }
375 ///////////////////////////////////////////////////////////////////////////
376 Int_t AliEvent::GetRunNumber()
377 {
378 // Provide the run number for this event
379  return fRun;
380 }
381 ///////////////////////////////////////////////////////////////////////////
382 Int_t AliEvent::GetEventNumber()
383 {
384 // Provide the event number for this event
385  return fEvent;
386 }
387 ///////////////////////////////////////////////////////////////////////////
388 void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id)
389 {
390 // Set the projectile A, Z, momentum per nucleon and user defined particle ID.
391 // By default the particle ID is set to zero.
392  fAproj=a;
393  fZproj=z;
394  fPnucProj=pnuc;
395  fIdProj=id;
396 }
397 ///////////////////////////////////////////////////////////////////////////
398 Int_t AliEvent::GetProjectileA()
399 {
400 // Provide the projectile A value.
401  return fAproj;
402 }
403 ///////////////////////////////////////////////////////////////////////////
404 Int_t AliEvent::GetProjectileZ()
405 {
406 // Provide the projectile Z value.
407  return fZproj;
408 }
409 ///////////////////////////////////////////////////////////////////////////
410 Double_t AliEvent::GetProjectilePnuc()
411 {
412 // Provide the projectile momentum value per nucleon.
413  return fPnucProj;
414 }
415 ///////////////////////////////////////////////////////////////////////////
416 Int_t AliEvent::GetProjectileId()
417 {
418 // Provide the user defined particle ID of the projectile.
419  return fIdProj;
420 }
421 ///////////////////////////////////////////////////////////////////////////
422 void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id)
423 {
424 // Set the target A, Z, momentum per nucleon and user defined particle ID.
425 // By default the particle ID is set to zero.
426  fAtarg=a;
427  fZtarg=z;
428  fPnucTarg=pnuc;
429  fIdTarg=id;
430 }
431 ///////////////////////////////////////////////////////////////////////////
432 Int_t AliEvent::GetTargetA()
433 {
434 // Provide the target A value.
435  return fAtarg;
436 }
437 ///////////////////////////////////////////////////////////////////////////
438 Int_t AliEvent::GetTargetZ()
439 {
440 // Provide the target Z value.
441  return fZtarg;
442 }
443 ///////////////////////////////////////////////////////////////////////////
444 Double_t AliEvent::GetTargetPnuc()
445 {
446 // Provide the target momentum value per nucleon.
447  return fPnucTarg;
448 }
449 ///////////////////////////////////////////////////////////////////////////
450 Int_t AliEvent::GetTargetId()
451 {
452 // Provide the user defined particle ID of the target.
453  return fIdTarg;
454 }
455 ///////////////////////////////////////////////////////////////////////////
456 void AliEvent::HeaderData()
457 {
458 // Provide event header information
459  cout << " *AliEvent::Data* Run : " << fRun << " Event : " << fEvent
460       << " Date : " << fDaytime.AsString() << endl;
461
462  ShowCalorimeters();
463 }
464 ///////////////////////////////////////////////////////////////////////////
465 void AliEvent::Data(TString f)
466 {
467 // Provide event information within the coordinate frame f
468  HeaderData();
469  AliVertex::Data(f);
470
471 ///////////////////////////////////////////////////////////////////////////
472 Int_t AliEvent::GetNcalorimeters()
473 {
474 // Provide the number of stored calorimeter systems
475  return fNcals;
476
477 ///////////////////////////////////////////////////////////////////////////
478 void AliEvent::AddCalorimeter(AliCalorimeter& c)
479 {
480 // Add a calorimeter system to the event
481  if (!fCalorimeters)
482  {
483   fCalorimeters=new TObjArray();
484   if (fCalCopy) fCalorimeters->SetOwner();
485  }
486  
487  // Add the calorimeter system to this event
488  fNcals++;
489  if (fCalCopy)
490  {
491   fCalorimeters->Add(new AliCalorimeter(c));
492  }
493  else
494  {
495   fCalorimeters->Add(&c);
496  }
497 }
498 ///////////////////////////////////////////////////////////////////////////
499 void AliEvent::SetCalCopy(Int_t j)
500 {
501 // (De)activate the creation of private copies of the added calorimeters.
502 // j=0 ==> No private copies are made; pointers of original cals. are stored.
503 // j=1 ==> Private copies of the cals. are made and these pointers are stored.
504 //
505 // Note : Once the storage contains pointer(s) to AliCalorimeter(s) one cannot
506 //        change the CalCopy mode anymore.
507 //        To change the CalCopy mode for an existing AliEvent containing
508 //        calorimeters one first has to invoke Reset().
509  if (!fCalorimeters)
510  {
511   if (j==0 || j==1)
512   {
513    fCalCopy=j;
514   }
515   else
516   {
517    cout << "*AliEvent::SetCalCopy* Invalid argument : " << j << endl;
518   }
519  }
520  else
521  {
522   cout << "*AliEvent::SetCalCopy* Storage already contained calorimeters."
523        << "  ==> CalCopy mode not changed." << endl; 
524  }
525 }
526 ///////////////////////////////////////////////////////////////////////////
527 Int_t AliEvent::GetCalCopy()
528 {
529 // Provide value of the CalCopy mode.
530 // 0 ==> No private copies are made; pointers of original cals. are stored.
531 // 1 ==> Private copies of the cals. are made and these pointers are stored.
532  return fCalCopy;
533 }
534 ///////////////////////////////////////////////////////////////////////////
535 AliCalorimeter* AliEvent::GetCalorimeter(Int_t i)
536 {
537 // Return the i-th calorimeter of this event
538  if (!fCalorimeters)
539  {
540   cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
541   return 0;
542  }
543  else
544  {
545   if (i<=0 || i>fNcals)
546   {
547    cout << " *AliEvent::GetCalorimeter* Invalid argument i : " << i
548         << " Ncals = " << fNcals << endl;
549    return 0;
550   }
551   else
552   {
553    return (AliCalorimeter*)fCalorimeters->At(i-1);
554   }
555  }
556 }
557 ///////////////////////////////////////////////////////////////////////////
558 AliCalorimeter* AliEvent::GetCalorimeter(TString name)
559 {
560 // Return the calorimeter with name tag "name"
561  if (!fCalorimeters)
562  {
563   cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
564   return 0;
565  }
566  else
567  {
568   AliCalorimeter* cx;
569   TString s;
570   for (Int_t i=0; i<fNcals; i++)
571   {
572    cx=(AliCalorimeter*)fCalorimeters->At(i);
573    if (cx)
574    {
575     s=cx->GetName();
576     if (s == name) return cx;
577    }
578   }
579
580   return 0; // No matching name found
581  }
582 }
583 ///////////////////////////////////////////////////////////////////////////
584 void AliEvent::ShowCalorimeters()
585 {
586 // Provide an overview of the available calorimeter systems.
587  if (fNcals>0)
588  {
589   cout << " The following " << fNcals << " calorimeter systems are available :" << endl; 
590   for (Int_t i=1; i<=fNcals; i++)
591   {
592    AliCalorimeter* cal=GetCalorimeter(i);
593    if (cal) cout << " Calorimeter number : " << i << " Name : " << (cal->GetName()).Data() << endl;
594   }
595  }
596  else
597  {
598   cout << " No calorimeters present for this event." << endl;
599  }
600 }
601 ///////////////////////////////////////////////////////////////////////////
602