]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliEvent.cxx
08e645fb7cb1e60a6e0097154c8eb4efd1807e02
[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.5 2002/01/18 08:46:59 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 // Coding example to make an event consisting of a primary vertex,
56 // 2 secondary vertices and a calorimeter.
57 // --------------------------------------------------------------
58 // vp contains the tracks 1,2,3 and 4 (primary vertex)
59 // v1 contains the tracks 5,6 and 7   (sec. vertex)
60 // v2 contains the jets 1 and 2       (sec. vertex)
61 //
62 //        AliEvent evt;
63 //
64 // Specify the event object as the repository of all objects
65 // for the event building and physics analysis.
66 // 
67 //        evt.SetCalCopy(1);
68 //        evt.SetTrackCopy(1);
69 //
70 // Fill the event structure with the basic objects
71 // 
72 //        AliCalorimeter emcal;
73 //         ...
74 //         ... // code to fill the calorimeter data
75 //         ...
76 //
77 //        evt.AddCalorimeter(emcal);
78 //
79 //        AliTrack* tx=new AliTrack();
80 //        for (Int_t i=0; i<10; i++)
81 //        {
82 //         ...
83 //         ... // code to fill the track data
84 //         ...
85 //         evt.AddTrack(tx);
86 //         tx->Reset(); 
87 //        }
88 //
89 //        if (tx)
90 //        {
91 //         delete tx;
92 //         tx=0;
93 //        }
94 //
95 // Build the event structure (vertices, jets, ...) for physics analysis
96 // based on the basic objects from the event repository.
97 //
98 //        AliJet j1,j2;
99 //        for (Int_t i=0; i<evt.GetNtracks(); i++)
100 //        {
101 //         tx=evt.GetTrack(i);
102 //         ...
103 //         ... // code to fill the jet data
104 //         ...
105 //        }
106 //
107 //        AliVertex vp;
108 //        tx=evt.GetTrack(1);
109 //        vp.AddTrack(tx);
110 //        tx=evt.GetTrack(2);
111 //        vp.AddTrack(tx);
112 //        tx=evt.GetTrack(3);
113 //        vp.AddTrack(tx);
114 //        tx=evt.GetTrack(4);
115 //        vp.AddTrack(tx);
116 //
117 //        Float_t rp[3]={2.4,0.1,-8.5};
118 //        vp.SetPosition(rp,"car");
119 //
120 //        AliVertex v1;
121 //        tx=evt.GetTrack(5);
122 //        v1.AddTrack(tx);
123 //        tx=evt.GetTrack(6);
124 //        v1.AddTrack(tx);
125 //        tx=evt.GetTrack(7);
126 //        v1.AddTrack(tx);
127 //
128 //        Float_t r1[3]={1.6,-3.2,5.7};
129 //        v1.SetPosition(r1,"car");
130 //
131 //
132 //        AliVertex v2;
133 //        v2.SetJetCopy(1);
134 //        v2.AddJet(j1);
135 //        v2.AddJet(j2);
136 //
137 //        Float_t r2[3]={6.2,4.8,1.3};
138 //        v2.SetPosition(r2,"car");
139 //
140 // Specify the vertices v1 and v2 as secondary vertices of the primary
141 //
142 //        vp.SetVertexCopy(1);
143 //        vp.AddVertex(v1);
144 //        vp.AddVertex(v2);
145 //
146 // Enter the physics structures into the event
147 //        evt.SetVertexCopy(1);
148 //        evt.AddVertex(vp,0);
149 //
150 // The jets j1 and j2 are already available via sec. vertex v2,
151 // but can be made available also from the event itself if desired.
152 //        AliJet* jx;
153 //        jx=v2.GetJet(1);
154 //        evt.AddJet(jx,0); 
155 //        jx=v2.GetJet(2);
156 //        evt.AddJet(jx,0); 
157 // 
158 //        evt.Info("sph");
159 //        v1.ListAll();
160 //        v2.List("cyl");
161 //
162 //        Float_t etot=evt.GetEnergy();
163 //        Ali3Vector ptot=evt.Get3Momentum();
164 //        Float_t loc[3];
165 //        evt.GetPosition(loc,"sph");
166 //        AliPosition r=v1.GetPosition();
167 //        r.Info(); 
168 //        Int_t nt=v2.GetNtracks();
169 //        AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
170 //
171 //        evt.List();
172 //
173 //        Int_t nv=evt.GetNvtx();
174 //        AliVertex* vx=evt.GetVertex(1); // Access primary vertex
175 //        Float_t e=vx->GetEnergy();
176 //
177 //        Float_t M=evt.GetInvmass(); 
178 //
179 // Reconstruct the event from scratch
180 //
181 //        evt.Reset();
182 //        evt.SetNvmax(25); // Increase initial no. of sec. vertices
183 //        ...
184 //        ... // code to create tracks etc... 
185 //        ...
186 //
187 // Note : All quantities are in GeV, GeV/c or GeV/c**2
188 //
189 //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
190 //- Modified: NvE $Date: 2002/01/18 08:46:59 $ UU-SAP Utrecht
191 ///////////////////////////////////////////////////////////////////////////
192
193 #include "AliEvent.h"
194  
195 ClassImp(AliEvent) // Class implementation to enable ROOT I/O
196  
197 AliEvent::AliEvent()
198 {
199 // Default constructor.
200 // All variables initialised to default values.
201  fDaytime.Set();
202  fRun=0;
203  fEvent=0;
204  fAproj=0;
205  fZproj=0;
206  fPnucProj=0;
207  fAtarg=0;
208  fZtarg=0;
209  fPnucTarg=0;
210  fNcals=0;
211  fCalorimeters=0;
212  fCalCopy=0;
213 }
214 ///////////////////////////////////////////////////////////////////////////
215 AliEvent::AliEvent(Int_t n): AliVertex(n)
216 {
217 // Create an event to hold initially a maximum of n tracks
218 // All variables initialised to default values
219  fDaytime.Set();
220  fRun=0;
221  fEvent=0;
222  fAproj=0;
223  fZproj=0;
224  fPnucProj=0;
225  fAtarg=0;
226  fZtarg=0;
227  fPnucTarg=0;
228  fNcals=0;
229  fCalorimeters=0;
230  fCalCopy=0;
231 }
232 ///////////////////////////////////////////////////////////////////////////
233 AliEvent::~AliEvent()
234 {
235 // Default destructor
236  if (fCalorimeters)
237  {
238   delete fCalorimeters;
239   fCalorimeters=0;
240  }
241 }
242 ///////////////////////////////////////////////////////////////////////////
243 void AliEvent::Reset()
244 {
245 // Reset all variables to default values
246 // The max. number of tracks is set to the initial value again
247 // The max. number of vertices is set to the default value again
248  fDaytime.Set();
249  fRun=0;
250  fEvent=0;
251  fAproj=0;
252  fZproj=0;
253  fPnucProj=0;
254  fAtarg=0;
255  fZtarg=0;
256  fPnucTarg=0;
257
258  fNcals=0;
259  if (fCalorimeters)
260  {
261   delete fCalorimeters;
262   fCalorimeters=0;
263  }
264
265  AliVertex::Reset();
266 }
267 ///////////////////////////////////////////////////////////////////////////
268 void AliEvent::SetDayTime(TDatime& stamp)
269 {
270 // Set the date and time stamp for this event
271  fDaytime=stamp;
272 }
273 ///////////////////////////////////////////////////////////////////////////
274 void AliEvent::SetRunNumber(Int_t run)
275 {
276 // Set the run number for this event
277  fRun=run;
278 }
279 ///////////////////////////////////////////////////////////////////////////
280 void AliEvent::SetEventNumber(Int_t evt)
281 {
282 // Set the event number for this event
283  fEvent=evt;
284 }
285 ///////////////////////////////////////////////////////////////////////////
286 TDatime AliEvent::GetDayTime()
287 {
288 // Provide the date and time stamp for this event
289  return fDaytime;
290 }
291 ///////////////////////////////////////////////////////////////////////////
292 Int_t AliEvent::GetRunNumber()
293 {
294 // Provide the run number for this event
295  return fRun;
296 }
297 ///////////////////////////////////////////////////////////////////////////
298 Int_t AliEvent::GetEventNumber()
299 {
300 // Provide the event number for this event
301  return fEvent;
302 }
303 ///////////////////////////////////////////////////////////////////////////
304 void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc)
305 {
306 // Set the projectile A, Z and momentum value per nucleon.
307  fAproj=a;
308  fZproj=z;
309  fPnucProj=pnuc;
310 }
311 ///////////////////////////////////////////////////////////////////////////
312 Int_t AliEvent::GetProjectileA()
313 {
314 // Provide the projectile A value.
315  return fAproj;
316 }
317 ///////////////////////////////////////////////////////////////////////////
318 Int_t AliEvent::GetProjectileZ()
319 {
320 // Provide the projectile Z value.
321  return fZproj;
322 }
323 ///////////////////////////////////////////////////////////////////////////
324 Double_t AliEvent::GetProjectilePnuc()
325 {
326 // Provide the projectile momentum value per nucleon.
327  return fPnucProj;
328 }
329 ///////////////////////////////////////////////////////////////////////////
330 void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc)
331 {
332 // Set the target A, Z and momentum value per nucleon.
333  fAtarg=a;
334  fZtarg=z;
335  fPnucTarg=pnuc;
336 }
337 ///////////////////////////////////////////////////////////////////////////
338 Int_t AliEvent::GetTargetA()
339 {
340 // Provide the target A value.
341  return fAtarg;
342 }
343 ///////////////////////////////////////////////////////////////////////////
344 Int_t AliEvent::GetTargetZ()
345 {
346 // Provide the target Z value.
347  return fZtarg;
348 }
349 ///////////////////////////////////////////////////////////////////////////
350 Double_t AliEvent::GetTargetPnuc()
351 {
352 // Provide the target momentum value per nucleon.
353  return fPnucTarg;
354 }
355 ///////////////////////////////////////////////////////////////////////////
356 void AliEvent::HeaderInfo()
357 {
358 // Provide event header information
359  Int_t date=fDaytime.GetDate();
360  Int_t time=fDaytime.GetTime();
361
362  Int_t year=date/10000;
363  Int_t month=(date%10000)/100;
364  Int_t day=date%100;
365  Int_t hh=time/10000;
366  Int_t mm=(time%10000)/100;
367  Int_t ss=time%100;
368
369  char* c[12]={"jan","feb","mar","apr","may","jun",
370               "jul","aug","sep","oct","nov","dec"};
371
372  cout << " *AliEvent::Info* Run : " << fRun << " Event : " << fEvent;
373  cout.fill('0');
374  cout << " Date : " << setw(2) << day << "-" << c[month-1] << "-" << year
375       << " Time : " << setw(2) << hh << ":" << setw(2) << mm << ":" << setw(2) << ss;
376  cout.fill(' ');
377  cout << " Ncalorimeters : " << fNcals << endl;
378 }
379 ///////////////////////////////////////////////////////////////////////////
380 void AliEvent::Info(TString f)
381 {
382 // Provide event information within the coordinate frame f
383  HeaderInfo();
384  AliVertex::Info(f);
385
386 ///////////////////////////////////////////////////////////////////////////
387 Int_t AliEvent::GetNcalorimeters()
388 {
389 // Provide the number of stored calorimeter systems
390  return fNcals;
391
392 ///////////////////////////////////////////////////////////////////////////
393 void AliEvent::AddCalorimeter(AliCalorimeter& c)
394 {
395 // Add a calorimeter system to the event
396  if (!fCalorimeters)
397  {
398   fCalorimeters=new TObjArray();
399   if (fCalCopy) fCalorimeters->SetOwner();
400  }
401  
402  // Add the calorimeter system to this event
403  fNcals++;
404  if (fCalCopy)
405  {
406   fCalorimeters->AddLast((AliCalorimeter*)c.Clone());
407  }
408  else
409  {
410   fCalorimeters->AddLast(&c);
411  }
412 }
413 ///////////////////////////////////////////////////////////////////////////
414 void AliEvent::SetCalCopy(Int_t j)
415 {
416 // (De)activate the creation of private copies of the added calorimeters.
417 // j=0 ==> No private copies are made; pointers of original cals. are stored.
418 // j=1 ==> Private copies of the cals. are made and these pointers are stored.
419 //
420 // Note : Once the storage contains pointer(s) to AliCalorimeter(s) one cannot
421 //        change the CalCopy mode anymore.
422 //        To change the CalCopy mode for an existing AliEvent containing
423 //        calorimeters one first has to invoke Reset().
424  if (!fCalorimeters)
425  {
426   if (j==0 || j==1)
427   {
428    fCalCopy=j;
429   }
430   else
431   {
432    cout << "*AliEvent::SetCalCopy* Invalid argument : " << j << endl;
433   }
434  }
435  else
436  {
437   cout << "*AliEvent::SetCalCopy* Storage already contained calorimeters."
438        << "  ==> CalCopy mode not changed." << endl; 
439  }
440 }
441 ///////////////////////////////////////////////////////////////////////////
442 Int_t AliEvent::GetCalCopy()
443 {
444 // Provide value of the CalCopy mode.
445 // 0 ==> No private copies are made; pointers of original cals. are stored.
446 // 1 ==> Private copies of the cals. are made and these pointers are stored.
447  return fCalCopy;
448 }
449 ///////////////////////////////////////////////////////////////////////////
450 AliCalorimeter* AliEvent::GetCalorimeter(Int_t i)
451 {
452 // Return the i-th calorimeter of this event
453  if (!fCalorimeters)
454  {
455   cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
456   return 0;
457  }
458  else
459  {
460   if (i<=0 || i>fNcals)
461   {
462    cout << " *AliEvent::GetCalorimeter* Invalid argument i : " << i
463         << " Ncals = " << fNcals << endl;
464    return 0;
465   }
466   else
467   {
468    return (AliCalorimeter*)fCalorimeters->At(i-1);
469   }
470  }
471 }
472 ///////////////////////////////////////////////////////////////////////////
473 AliCalorimeter* AliEvent::GetCalorimeter(TString name)
474 {
475 // Return the calorimeter with name tag "name"
476  if (!fCalorimeters)
477  {
478   cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
479   return 0;
480  }
481  else
482  {
483   AliCalorimeter* cx;
484   TString s;
485   for (Int_t i=0; i<fNcals; i++)
486   {
487    cx=(AliCalorimeter*)fCalorimeters->At(i);
488    if (cx)
489    {
490     s=cx->GetName();
491     if (s == name) return cx;
492    }
493   }
494
495   return 0; // No matching name found
496  }
497 }
498 ///////////////////////////////////////////////////////////////////////////
499