]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliEvent.cxx
Enlarged number of clusters (Yu.Belikov)
[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.8 2002/12/02 15:10:37 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.Info("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.Info(); 
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: 2002/12/02 15:10:37 $ UU-SAP Utrecht
193 ///////////////////////////////////////////////////////////////////////////
194
195 #include "AliEvent.h"
196  
197 ClassImp(AliEvent) // Class implementation to enable ROOT I/O
198  
199 AliEvent::AliEvent()
200 {
201 // Default constructor.
202 // All variables initialised to default values.
203  fDaytime.Set();
204  fRun=0;
205  fEvent=0;
206  fAproj=0;
207  fZproj=0;
208  fPnucProj=0;
209  fIdProj=0;
210  fAtarg=0;
211  fZtarg=0;
212  fPnucTarg=0;
213  fIdTarg=0;
214  fNcals=0;
215  fCalorimeters=0;
216  fCalCopy=0;
217 }
218 ///////////////////////////////////////////////////////////////////////////
219 AliEvent::AliEvent(Int_t n): AliVertex(n)
220 {
221 // Create an event to hold initially a maximum of n tracks
222 // All variables initialised to default values
223  fDaytime.Set();
224  fRun=0;
225  fEvent=0;
226  fAproj=0;
227  fZproj=0;
228  fPnucProj=0;
229  fIdProj=0;
230  fAtarg=0;
231  fZtarg=0;
232  fPnucTarg=0;
233  fIdTarg=0;
234  fNcals=0;
235  fCalorimeters=0;
236  fCalCopy=0;
237 }
238 ///////////////////////////////////////////////////////////////////////////
239 AliEvent::~AliEvent()
240 {
241 // Default destructor
242  if (fCalorimeters)
243  {
244   delete fCalorimeters;
245   fCalorimeters=0;
246  }
247 }
248 ///////////////////////////////////////////////////////////////////////////
249 void AliEvent::Reset()
250 {
251 // Reset all variables to default values
252 // The max. number of tracks is set to the initial value again
253 // The max. number of vertices is set to the default value again
254 // Note : The CalCopy mode is maintained as it was set by the user before.
255  fDaytime.Set();
256  fRun=0;
257  fEvent=0;
258  fAproj=0;
259  fZproj=0;
260  fPnucProj=0;
261  fIdProj=0;
262  fAtarg=0;
263  fZtarg=0;
264  fPnucTarg=0;
265  fIdTarg=0;
266
267  fNcals=0;
268  if (fCalorimeters)
269  {
270   delete fCalorimeters;
271   fCalorimeters=0;
272  }
273
274  AliVertex::Reset();
275 }
276 ///////////////////////////////////////////////////////////////////////////
277 void AliEvent::SetOwner(Bool_t own)
278 {
279 // Set ownership of all added objects. 
280 // The default parameter is own=kTRUE.
281 //
282 // Invokation of this memberfunction also sets all the copy modes
283 // (e.g. TrackCopy & co.) according to the value of own.
284 //
285 // This function (with own=kTRUE) is particularly useful when reading data
286 // from a tree/file, since Reset() will then actually remove all the
287 // added objects from memory irrespective of the copy mode settings
288 // during the tree/file creation process. In this way it provides a nice way
289 // of preventing possible memory leaks in the reading/analysis process.
290 //
291 // In addition this memberfunction can also be used as a shortcut to set all
292 // copy modes in one go during a tree/file creation process.
293 // However, in this case the user has to take care to only set/change the
294 // ownership (and copy mode) for empty objects (e.g. newly created objects
295 // or after invokation of the Reset() memberfunction) otherwise it will
296 // very likely result in inconsistent destructor behaviour.
297
298  Int_t mode=1;
299  if (!own) mode=0;
300  if (fCalorimeters) fCalorimeters->SetOwner(own);
301  fCalCopy=mode;
302
303  AliVertex::SetOwner(own);
304 }
305 ///////////////////////////////////////////////////////////////////////////
306 void AliEvent::SetDayTime(TDatime& stamp)
307 {
308 // Set the date and time stamp for this event
309  fDaytime=stamp;
310 }
311 ///////////////////////////////////////////////////////////////////////////
312 void AliEvent::SetRunNumber(Int_t run)
313 {
314 // Set the run number for this event
315  fRun=run;
316 }
317 ///////////////////////////////////////////////////////////////////////////
318 void AliEvent::SetEventNumber(Int_t evt)
319 {
320 // Set the event number for this event
321  fEvent=evt;
322 }
323 ///////////////////////////////////////////////////////////////////////////
324 TDatime AliEvent::GetDayTime()
325 {
326 // Provide the date and time stamp for this event
327  return fDaytime;
328 }
329 ///////////////////////////////////////////////////////////////////////////
330 Int_t AliEvent::GetRunNumber()
331 {
332 // Provide the run number for this event
333  return fRun;
334 }
335 ///////////////////////////////////////////////////////////////////////////
336 Int_t AliEvent::GetEventNumber()
337 {
338 // Provide the event number for this event
339  return fEvent;
340 }
341 ///////////////////////////////////////////////////////////////////////////
342 void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id)
343 {
344 // Set the projectile A, Z, momentum per nucleon and user defined particle ID.
345 // By default the particle ID is set to zero.
346  fAproj=a;
347  fZproj=z;
348  fPnucProj=pnuc;
349  fIdProj=id;
350 }
351 ///////////////////////////////////////////////////////////////////////////
352 Int_t AliEvent::GetProjectileA()
353 {
354 // Provide the projectile A value.
355  return fAproj;
356 }
357 ///////////////////////////////////////////////////////////////////////////
358 Int_t AliEvent::GetProjectileZ()
359 {
360 // Provide the projectile Z value.
361  return fZproj;
362 }
363 ///////////////////////////////////////////////////////////////////////////
364 Double_t AliEvent::GetProjectilePnuc()
365 {
366 // Provide the projectile momentum value per nucleon.
367  return fPnucProj;
368 }
369 ///////////////////////////////////////////////////////////////////////////
370 Int_t AliEvent::GetProjectileId()
371 {
372 // Provide the user defined particle ID of the projectile.
373  return fIdProj;
374 }
375 ///////////////////////////////////////////////////////////////////////////
376 void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id)
377 {
378 // Set the target A, Z, momentum per nucleon and user defined particle ID.
379 // By default the particle ID is set to zero.
380  fAtarg=a;
381  fZtarg=z;
382  fPnucTarg=pnuc;
383  fIdTarg=id;
384 }
385 ///////////////////////////////////////////////////////////////////////////
386 Int_t AliEvent::GetTargetA()
387 {
388 // Provide the target A value.
389  return fAtarg;
390 }
391 ///////////////////////////////////////////////////////////////////////////
392 Int_t AliEvent::GetTargetZ()
393 {
394 // Provide the target Z value.
395  return fZtarg;
396 }
397 ///////////////////////////////////////////////////////////////////////////
398 Double_t AliEvent::GetTargetPnuc()
399 {
400 // Provide the target momentum value per nucleon.
401  return fPnucTarg;
402 }
403 ///////////////////////////////////////////////////////////////////////////
404 Int_t AliEvent::GetTargetId()
405 {
406 // Provide the user defined particle ID of the target.
407  return fIdTarg;
408 }
409 ///////////////////////////////////////////////////////////////////////////
410 void AliEvent::HeaderInfo()
411 {
412 // Provide event header information
413  Int_t date=fDaytime.GetDate();
414  Int_t time=fDaytime.GetTime();
415
416  Int_t year=date/10000;
417  Int_t month=(date%10000)/100;
418  Int_t day=date%100;
419  Int_t hh=time/10000;
420  Int_t mm=(time%10000)/100;
421  Int_t ss=time%100;
422
423  char* c[12]={"jan","feb","mar","apr","may","jun",
424               "jul","aug","sep","oct","nov","dec"};
425
426  cout << " *AliEvent::Info* Run : " << fRun << " Event : " << fEvent;
427  cout.fill('0');
428  cout << " Date : " << setw(2) << day << "-" << c[month-1] << "-" << year
429       << " Time : " << setw(2) << hh << ":" << setw(2) << mm << ":" << setw(2) << ss;
430  cout.fill(' ');
431  cout << " Ncalorimeters : " << fNcals << endl;
432 }
433 ///////////////////////////////////////////////////////////////////////////
434 void AliEvent::Info(TString f)
435 {
436 // Provide event information within the coordinate frame f
437  HeaderInfo();
438  AliVertex::Info(f);
439
440 ///////////////////////////////////////////////////////////////////////////
441 Int_t AliEvent::GetNcalorimeters()
442 {
443 // Provide the number of stored calorimeter systems
444  return fNcals;
445
446 ///////////////////////////////////////////////////////////////////////////
447 void AliEvent::AddCalorimeter(AliCalorimeter& c)
448 {
449 // Add a calorimeter system to the event
450  if (!fCalorimeters)
451  {
452   fCalorimeters=new TObjArray();
453   if (fCalCopy) fCalorimeters->SetOwner();
454  }
455  
456  // Add the calorimeter system to this event
457  fNcals++;
458  if (fCalCopy)
459  {
460   fCalorimeters->AddLast((AliCalorimeter*)c.Clone());
461  }
462  else
463  {
464   fCalorimeters->AddLast(&c);
465  }
466 }
467 ///////////////////////////////////////////////////////////////////////////
468 void AliEvent::SetCalCopy(Int_t j)
469 {
470 // (De)activate the creation of private copies of the added calorimeters.
471 // j=0 ==> No private copies are made; pointers of original cals. are stored.
472 // j=1 ==> Private copies of the cals. are made and these pointers are stored.
473 //
474 // Note : Once the storage contains pointer(s) to AliCalorimeter(s) one cannot
475 //        change the CalCopy mode anymore.
476 //        To change the CalCopy mode for an existing AliEvent containing
477 //        calorimeters one first has to invoke Reset().
478  if (!fCalorimeters)
479  {
480   if (j==0 || j==1)
481   {
482    fCalCopy=j;
483   }
484   else
485   {
486    cout << "*AliEvent::SetCalCopy* Invalid argument : " << j << endl;
487   }
488  }
489  else
490  {
491   cout << "*AliEvent::SetCalCopy* Storage already contained calorimeters."
492        << "  ==> CalCopy mode not changed." << endl; 
493  }
494 }
495 ///////////////////////////////////////////////////////////////////////////
496 Int_t AliEvent::GetCalCopy()
497 {
498 // Provide value of the CalCopy mode.
499 // 0 ==> No private copies are made; pointers of original cals. are stored.
500 // 1 ==> Private copies of the cals. are made and these pointers are stored.
501  return fCalCopy;
502 }
503 ///////////////////////////////////////////////////////////////////////////
504 AliCalorimeter* AliEvent::GetCalorimeter(Int_t i)
505 {
506 // Return the i-th calorimeter of this event
507  if (!fCalorimeters)
508  {
509   cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
510   return 0;
511  }
512  else
513  {
514   if (i<=0 || i>fNcals)
515   {
516    cout << " *AliEvent::GetCalorimeter* Invalid argument i : " << i
517         << " Ncals = " << fNcals << endl;
518    return 0;
519   }
520   else
521   {
522    return (AliCalorimeter*)fCalorimeters->At(i-1);
523   }
524  }
525 }
526 ///////////////////////////////////////////////////////////////////////////
527 AliCalorimeter* AliEvent::GetCalorimeter(TString name)
528 {
529 // Return the calorimeter with name tag "name"
530  if (!fCalorimeters)
531  {
532   cout << " *AliEvent::GetCalorimeter* No calorimeters present." << endl;
533   return 0;
534  }
535  else
536  {
537   AliCalorimeter* cx;
538   TString s;
539   for (Int_t i=0; i<fNcals; i++)
540   {
541    cx=(AliCalorimeter*)fCalorimeters->At(i);
542    if (cx)
543    {
544     s=cx->GetName();
545     if (s == name) return cx;
546    }
547   }
548
549   return 0; // No matching name found
550  }
551 }
552 ///////////////////////////////////////////////////////////////////////////
553