]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliEvent.cxx
04-mar-2005 NvE Installation scripts named amdgcclib.sh introduced in all /scripts...
[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.25 2004/10/20 10:49:44 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 or AliDevice (derived) objects.
23 //
24 // All objects which are derived from TObject can be regarded as a device.
25 // However, AliDevice (or derived) objects profit from additional hit
26 // handling facilities.
27 // A "hit" is a generic name indicating an AliSignal (or derived) object.
28 // Note that AliEvent does NOT own hits; it only provides references to hits
29 // obtained from the various devices.
30 // This implies that hits should be owned by the devices themselves.
31 //
32 // The basic functionality of AliEvent is identical to the one of AliVertex.
33 // So, an AliEvent may be used as the primary vertex with some additional
34 // functionality compared to AliVertex.
35 //
36 // To provide maximal flexibility to the user, the two modes of track/jet/vertex
37 // storage as described in AliJet and AliVertex can be used.
38 // In addition an identical structure is provided for the storage of devices like
39 // AliCalorimeter objects, which can be selected by means of the memberfunction
40 // SetDevCopy().
41 //
42 // a) SetDevCopy(0) (which is the default).
43 //    Only the pointers of the 'added' devices are stored.
44 //    This mode is typically used by making studies based on a fixed set
45 //    of devices which stays under user control or is kept on an external
46 //    file/tree. 
47 //    In this way the AliEvent just represents a 'logical structure' for the
48 //    physics analysis.
49 //
50 //    Note :
51 //    Modifications made to the original devices also affect the device
52 //    objects which are stored in the AliEvent. 
53 //
54 // b) SetDevCopy(1).
55 //    Of every 'added' device a private copy will be made of which the pointer
56 //    will be stored.
57 //    In this way the AliEvent represents an entity on its own and modifications
58 //    made to the original calorimeters do not affect the AliCalorimeter objects
59 //    which are stored in the AliEvent. 
60 //    This mode will allow 'adding' many different devices into an AliEvent by
61 //    creating only one device instance in the main programme and using the
62 //    Reset() and parameter setting memberfunctions of the object representing the device.
63 //
64 //    Note :
65 //    The copy is made using the Clone() memberfunction.
66 //    All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
67 //    memberfunction.
68 //    However, devices generally contain an internal (signal) data structure
69 //    which may include pointers to other objects. Therefore it is recommended to provide
70 //    for all devices a specific copy constructor and override the default Clone()
71 //    memberfunction using this copy constructor.
72 //    Examples for this may be seen from AliCalorimeter, AliSignal and AliDevice.   
73 //
74 // See also the documentation provided for the memberfunction SetOwner(). 
75 //
76 // Coding example to make an event consisting of a primary vertex,
77 // 2 secondary vertices and a calorimeter.
78 // --------------------------------------------------------------
79 // vp contains the tracks 1,2,3 and 4 (primary vertex)
80 // v1 contains the tracks 5,6 and 7   (sec. vertex)
81 // v2 contains the jets 1 and 2       (sec. vertex)
82 //
83 //        AliEvent evt;
84 //
85 // Specify the event object as the repository of all objects
86 // for the event building and physics analysis.
87 // 
88 //        evt.SetDevCopy(1);
89 //        evt.SetTrackCopy(1);
90 //
91 // Fill the event structure with the basic objects
92 // 
93 //        AliCalorimeter emcal1;
94 //        AliCalorimeter emcal2;
95 //         ...
96 //         ... // code to fill the emcal1 and emcal2 calorimeter data
97 //         ...
98 //
99 //        evt.AddDevice(emcal1);
100 //        evt.AddDevice(emcal2);
101 //
102 //        // Assume AliTOF has been derived from AliDevice
103 //        AliTOF tof1;
104 //        AliTOF tof2;
105 //         ...
106 //         ... // code to fill the tof1 and tof2 data
107 //         ...
108 //
109 //        evt.AddDevice(tof1);
110 //        evt.AddDevice(tof2);
111 //
112 //        AliTrack* tx=new AliTrack();
113 //        for (Int_t i=0; i<10; i++)
114 //        {
115 //         ...
116 //         ... // code to fill the track data
117 //         ...
118 //         evt.AddTrack(tx);
119 //         tx->Reset(); 
120 //        }
121 //
122 //        if (tx)
123 //        {
124 //         delete tx;
125 //         tx=0;
126 //        }
127 //
128 // Order and investigate all the hits of all the TOF devices
129 //
130 //        TObjArray* hits=evt.GetHits("AliTOF");
131 //        TObjArray* orderedtofs=evt.SortHits(hits);
132 //        Int_t nhits=0;
133 //        if (orderedtofs) nhits=orderedtofs->GetEntries();
134 //        for (Int_t i=0; i<nhits; i++)
135 //        {
136 //         AliSignal* sx=(AliSignal*)orderedtofs->At(i);
137 //         if (sx) sx->Data();
138 //        }
139 //
140 // Order and investigate all the hits of all the calorimeter devices
141 //
142 //        TObjArray* hits=evt.GetHits("AliCalorimeter");
143 //        TObjArray* orderedcals=evt.SortHits(hits);
144 //        Int_t nhits=0;
145 //        if (orderedcals) nhits=orderedcals->GetEntries();
146 //        for (Int_t i=0; i<nhits; i++)
147 //        {
148 //         AliSignal* sx=(AliSignal*)orderedcals->At(i);
149 //         if (sx) sx->Data();
150 //        }
151 //
152 // Build the event structure (vertices, jets, ...) for physics analysis
153 // based on the basic objects from the event repository.
154 //
155 //        AliJet j1,j2;
156 //        for (Int_t i=0; i<evt.GetNtracks(); i++)
157 //        {
158 //         tx=evt.GetTrack(i);
159 //         ...
160 //         ... // code to fill the jet data
161 //         ...
162 //        }
163 //
164 //        AliVertex vp;
165 //        tx=evt.GetTrack(1);
166 //        vp.AddTrack(tx);
167 //        tx=evt.GetTrack(2);
168 //        vp.AddTrack(tx);
169 //        tx=evt.GetTrack(3);
170 //        vp.AddTrack(tx);
171 //        tx=evt.GetTrack(4);
172 //        vp.AddTrack(tx);
173 //
174 //        Float_t rp[3]={2.4,0.1,-8.5};
175 //        vp.SetPosition(rp,"car");
176 //
177 //        AliVertex v1;
178 //        tx=evt.GetTrack(5);
179 //        v1.AddTrack(tx);
180 //        tx=evt.GetTrack(6);
181 //        v1.AddTrack(tx);
182 //        tx=evt.GetTrack(7);
183 //        v1.AddTrack(tx);
184 //
185 //        Float_t r1[3]={1.6,-3.2,5.7};
186 //        v1.SetPosition(r1,"car");
187 //
188 //
189 //        AliVertex v2;
190 //        v2.SetJetCopy(1);
191 //        v2.AddJet(j1);
192 //        v2.AddJet(j2);
193 //
194 //        Float_t r2[3]={6.2,4.8,1.3};
195 //        v2.SetPosition(r2,"car");
196 //
197 // Specify the vertices v1 and v2 as secondary vertices of the primary
198 //
199 //        vp.SetVertexCopy(1);
200 //        vp.AddVertex(v1);
201 //        vp.AddVertex(v2);
202 //
203 // Enter the physics structures into the event
204 //        evt.SetVertexCopy(1);
205 //        evt.AddVertex(vp,0);
206 //
207 // The jets j1 and j2 are already available via sec. vertex v2,
208 // but can be made available also from the event itself if desired.
209 //        AliJet* jx;
210 //        jx=v2.GetJet(1);
211 //        evt.AddJet(jx,0); 
212 //        jx=v2.GetJet(2);
213 //        evt.AddJet(jx,0); 
214 // 
215 //        evt.Data("sph");
216 //        v1.ListAll();
217 //        v2.List("cyl");
218 //
219 //        Float_t etot=evt.GetEnergy();
220 //        Ali3Vector ptot=evt.Get3Momentum();
221 //        Float_t loc[3];
222 //        evt.GetPosition(loc,"sph");
223 //        AliPosition r=v1.GetPosition();
224 //        r.Data(); 
225 //        Int_t nt=v2.GetNtracks();
226 //        AliTrack* tv=v2.GetTrack(1); // Access track number 1 of Vertex v2
227 //
228 //        evt.List();
229 //
230 //        Int_t nv=evt.GetNvtx();
231 //        AliVertex* vx=evt.GetVertex(1); // Access primary vertex
232 //        Float_t e=vx->GetEnergy();
233 //
234 //        Float_t M=evt.GetInvmass(); 
235 //
236 // Reconstruct the event from scratch
237 //
238 //        evt.Reset();
239 //        evt.SetNvmax(25); // Increase initial no. of sec. vertices
240 //        ...
241 //        ... // code to create tracks etc... 
242 //        ...
243 //
244 // Note : All quantities are in GeV, GeV/c or GeV/c**2
245 //
246 //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
247 //- Modified: NvE $Date: 2004/10/20 10:49:44 $ UU-SAP Utrecht
248 ///////////////////////////////////////////////////////////////////////////
249
250 #include "AliEvent.h"
251 #include "Riostream.h"
252  
253 ClassImp(AliEvent) // Class implementation to enable ROOT I/O
254  
255 AliEvent::AliEvent() : AliVertex(),AliTimestamp()
256 {
257 // Default constructor.
258 // All variables initialised to default values.
259  fRun=0;
260  fEvent=0;
261  fAproj=0;
262  fZproj=0;
263  fPnucProj=0;
264  fIdProj=0;
265  fAtarg=0;
266  fZtarg=0;
267  fPnucTarg=0;
268  fIdTarg=0;
269  fDevices=0;
270  fDevCopy=0;
271  fHits=0;
272  fOrdered=0;
273  fDisplay=0;
274 }
275 ///////////////////////////////////////////////////////////////////////////
276 AliEvent::AliEvent(Int_t n) : AliVertex(n),AliTimestamp()
277 {
278 // Create an event to hold initially a maximum of n tracks
279 // All variables initialised to default values
280  if (n<=0)
281  {
282   cout << " *** This AliVertex initialisation was invoked via the AliEvent ctor." << endl;
283  }
284  fRun=0;
285  fEvent=0;
286  fAproj=0;
287  fZproj=0;
288  fPnucProj=0;
289  fIdProj=0;
290  fAtarg=0;
291  fZtarg=0;
292  fPnucTarg=0;
293  fIdTarg=0;
294  fDevices=0;
295  fDevCopy=0;
296  fHits=0;
297  fOrdered=0;
298  fDisplay=0;
299 }
300 ///////////////////////////////////////////////////////////////////////////
301 AliEvent::~AliEvent()
302 {
303 // Default destructor
304  if (fDevices)
305  {
306   delete fDevices;
307   fDevices=0;
308  }
309  if (fHits)
310  {
311   delete fHits;
312   fHits=0;
313  }
314  if (fOrdered)
315  {
316   delete fOrdered;
317   fOrdered=0;
318  }
319  if (fDisplay)
320  {
321   delete fDisplay;
322   fDisplay=0;
323  }
324 }
325 ///////////////////////////////////////////////////////////////////////////
326 AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt),AliTimestamp(evt)
327 {
328 // Copy constructor.
329  fRun=evt.fRun;
330  fEvent=evt.fEvent;
331  fAproj=evt.fAproj;
332  fZproj=evt.fZproj;
333  fPnucProj=evt.fPnucProj;
334  fIdProj=evt.fIdProj;
335  fAtarg=evt.fAtarg;
336  fZtarg=evt.fZtarg;
337  fPnucTarg=evt.fPnucTarg;
338  fIdTarg=evt.fIdTarg;
339  fDevCopy=evt.fDevCopy;
340
341  fHits=0;
342  fOrdered=0;
343  fDisplay=0;
344
345  fDevices=0;
346  Int_t ndevs=evt.GetNdevices();
347  if (ndevs)
348  {
349   fDevices=new TObjArray(ndevs);
350   if (fDevCopy) fDevices->SetOwner();
351   for (Int_t i=1; i<=ndevs; i++)
352   {
353    TObject* dev=evt.GetDevice(i);
354    if (dev)
355    {
356     if (fDevCopy)
357     {
358      fDevices->Add(dev->Clone());
359     }
360     else
361     {
362      fDevices->Add(dev);
363     }
364    }
365   }
366  }
367 }
368 ///////////////////////////////////////////////////////////////////////////
369 void AliEvent::Reset()
370 {
371 // Reset all variables to default values
372 // The max. number of tracks is set to the initial value again
373 // The max. number of vertices is set to the default value again
374 // Note : The DevCopy mode is maintained as it was set by the user before.
375
376  AliVertex::Reset();
377
378  Set();
379  fRun=0;
380  fEvent=0;
381  fAproj=0;
382  fZproj=0;
383  fPnucProj=0;
384  fIdProj=0;
385  fAtarg=0;
386  fZtarg=0;
387  fPnucTarg=0;
388  fIdTarg=0;
389
390  if (fDevices)
391  {
392   delete fDevices;
393   fDevices=0;
394  }
395  if (fHits)
396  {
397   delete fHits;
398   fHits=0;
399  }
400  if (fOrdered)
401  {
402   delete fOrdered;
403   fOrdered=0;
404  }
405  if (fDisplay)
406  {
407   delete fDisplay;
408   fDisplay=0;
409  }
410 }
411 ///////////////////////////////////////////////////////////////////////////
412 void AliEvent::SetOwner(Bool_t own)
413 {
414 // Set ownership of all added objects. 
415 // The default parameter is own=kTRUE.
416 //
417 // Invokation of this memberfunction also sets all the copy modes
418 // (e.g. TrackCopy & co.) according to the value of own.
419 //
420 // This function (with own=kTRUE) is particularly useful when reading data
421 // from a tree/file, since Reset() will then actually remove all the
422 // added objects from memory irrespective of the copy mode settings
423 // during the tree/file creation process. In this way it provides a nice way
424 // of preventing possible memory leaks in the reading/analysis process.
425 //
426 // In addition this memberfunction can also be used as a shortcut to set all
427 // copy modes in one go during a tree/file creation process.
428 // However, in this case the user has to take care to only set/change the
429 // ownership (and copy mode) for empty objects (e.g. newly created objects
430 // or after invokation of the Reset() memberfunction) otherwise it will
431 // very likely result in inconsistent destructor behaviour.
432
433  Int_t mode=1;
434  if (!own) mode=0;
435  if (fDevices) fDevices->SetOwner(own);
436  fDevCopy=mode;
437
438  AliVertex::SetOwner(own);
439 }
440 ///////////////////////////////////////////////////////////////////////////
441 void AliEvent::SetDayTime(TTimeStamp& stamp)
442 {
443 // Set the date and time stamp for this event.
444 // An exact copy of the entered date/time stamp will be saved with an
445 // accuracy of 1 nanosecond.
446 //
447 // Note : Since the introduction of the more versatile class AliTimestamp
448 //        and the fact that AliEvent has now been derived from it,
449 //        this memberfunction has become obsolete.
450 //        It is recommended to use the corresponding AliTimestamp
451 //        functionality directly for AliEvent instances.
452 //        This memberfunction is only kept for backward compatibility.
453
454  Set(stamp.GetDate(),stamp.GetTime(),0,kTRUE,0);
455 }
456 ///////////////////////////////////////////////////////////////////////////
457 void AliEvent::SetDayTime(TDatime& stamp)
458 {
459 // Set the date and time stamp for this event.
460 // The entered date/time will be interpreted as being the local date/time
461 // and the accuracy is 1 second.
462 //
463 // This function with the TDatime argument is mainly kept for backward
464 // compatibility reasons.
465 // It is recommended to use the corresponding AliTimestamp functionality
466 // directly for AliEvent instances.
467
468  Set(stamp.GetDate(),stamp.GetTime(),0,kFALSE,0);
469 }
470 ///////////////////////////////////////////////////////////////////////////
471 void AliEvent::SetRunNumber(Int_t run)
472 {
473 // Set the run number for this event
474  fRun=run;
475 }
476 ///////////////////////////////////////////////////////////////////////////
477 void AliEvent::SetEventNumber(Int_t evt)
478 {
479 // Set the event number for this event
480  fEvent=evt;
481 }
482 ///////////////////////////////////////////////////////////////////////////
483 TTimeStamp AliEvent::GetDayTime() const
484 {
485 // Provide the date and time stamp for this event
486 //
487 // Note : Since the introduction of the more versatile class AliTimestamp
488 //        and the fact that AliEvent has now been derived from it,
489 //        this memberfunction has become obsolete.
490 //        It is recommended to use the corresponding AliTimestamp
491 //        functionality directly for AliEvent instances.
492 //        This memberfunction is only kept for backward compatibility.
493
494  return (TTimeStamp)(*this);
495 }
496 ///////////////////////////////////////////////////////////////////////////
497 Int_t AliEvent::GetRunNumber() const
498 {
499 // Provide the run number for this event
500  return fRun;
501 }
502 ///////////////////////////////////////////////////////////////////////////
503 Int_t AliEvent::GetEventNumber() const
504 {
505 // Provide the event number for this event
506  return fEvent;
507 }
508 ///////////////////////////////////////////////////////////////////////////
509 void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id)
510 {
511 // Set the projectile A, Z, momentum per nucleon and user defined particle ID.
512 // By default the particle ID is set to zero.
513  fAproj=a;
514  fZproj=z;
515  fPnucProj=pnuc;
516  fIdProj=id;
517 }
518 ///////////////////////////////////////////////////////////////////////////
519 Int_t AliEvent::GetProjectileA() const
520 {
521 // Provide the projectile A value.
522  return fAproj;
523 }
524 ///////////////////////////////////////////////////////////////////////////
525 Int_t AliEvent::GetProjectileZ() const
526 {
527 // Provide the projectile Z value.
528  return fZproj;
529 }
530 ///////////////////////////////////////////////////////////////////////////
531 Double_t AliEvent::GetProjectilePnuc() const
532 {
533 // Provide the projectile momentum value per nucleon.
534  return fPnucProj;
535 }
536 ///////////////////////////////////////////////////////////////////////////
537 Int_t AliEvent::GetProjectileId() const
538 {
539 // Provide the user defined particle ID of the projectile.
540  return fIdProj;
541 }
542 ///////////////////////////////////////////////////////////////////////////
543 void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id)
544 {
545 // Set the target A, Z, momentum per nucleon and user defined particle ID.
546 // By default the particle ID is set to zero.
547  fAtarg=a;
548  fZtarg=z;
549  fPnucTarg=pnuc;
550  fIdTarg=id;
551 }
552 ///////////////////////////////////////////////////////////////////////////
553 Int_t AliEvent::GetTargetA() const
554 {
555 // Provide the target A value.
556  return fAtarg;
557 }
558 ///////////////////////////////////////////////////////////////////////////
559 Int_t AliEvent::GetTargetZ() const
560 {
561 // Provide the target Z value.
562  return fZtarg;
563 }
564 ///////////////////////////////////////////////////////////////////////////
565 Double_t AliEvent::GetTargetPnuc() const
566 {
567 // Provide the target momentum value per nucleon.
568  return fPnucTarg;
569 }
570 ///////////////////////////////////////////////////////////////////////////
571 Int_t AliEvent::GetTargetId() const
572 {
573 // Provide the user defined particle ID of the target.
574  return fIdTarg;
575 }
576 ///////////////////////////////////////////////////////////////////////////
577 void AliEvent::HeaderData()
578 {
579 // Provide event header information
580  const char* name=GetName();
581  const char* title=GetTitle();
582  cout << " *" << ClassName() << "::Data*";
583  if (strlen(name))  cout << " Name : " << GetName();
584  if (strlen(title)) cout << " Title : " << GetTitle();
585  cout << endl;
586  Date(1);
587  cout << "  Run : " << fRun << " Event : " << fEvent << endl;
588  ShowDevices(0);
589  ShowTracks(0);
590 }
591 ///////////////////////////////////////////////////////////////////////////
592 void AliEvent::Data(TString f)
593 {
594 // Provide event information within the coordinate frame f
595  HeaderData();
596  AliVertex::Data(f);
597
598 ///////////////////////////////////////////////////////////////////////////
599 Int_t AliEvent::GetNdevices() const
600 {
601 // Provide the number of stored devices
602  Int_t ndevs=0;
603  if (fDevices) ndevs=fDevices->GetEntries();
604  return ndevs;
605
606 ///////////////////////////////////////////////////////////////////////////
607 void AliEvent::AddDevice(TObject& d)
608 {
609 // Add a device to the event.
610 //
611 // Note :
612 // In case a private copy is made, this is performed via the Clone() memberfunction.
613 // All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
614 // memberfunction.
615 // However, devices generally contain an internal (signal) data structure
616 // which may include pointers to other objects. Therefore it is recommended to provide
617 // for all devices a specific copy constructor and override the default Clone()
618 // memberfunction using this copy constructor.
619 // An example for this may be seen from AliCalorimeter.   
620
621  if (!fDevices)
622  {
623   fDevices=new TObjArray();
624   if (fDevCopy) fDevices->SetOwner();
625  }
626  
627  // Add the device to this event
628  if (fDevCopy)
629  {
630   fDevices->Add(d.Clone());
631  }
632  else
633  {
634   fDevices->Add(&d);
635  }
636 }
637 ///////////////////////////////////////////////////////////////////////////
638 void AliEvent::SetDevCopy(Int_t j)
639 {
640 // (De)activate the creation of private copies of the added devices.
641 // j=0 ==> No private copies are made; pointers of original devices are stored.
642 // j=1 ==> Private copies of the devices are made and these pointers are stored.
643 //
644 //
645 // Notes :
646 //  In case a private copy is made, this is performed via the Clone() memberfunction.
647 //  All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
648 //  memberfunction.
649 //  However, devices generally contain an internal (signal) data structure
650 //  which may include pointers to other objects. Therefore it is recommended to provide
651 //  for all devices a specific copy constructor and override the default Clone()
652 //  memberfunction using this copy constructor.
653 //  An example for this may be seen from AliCalorimeter.   
654 //
655 //  Once the storage contains pointer(s) to device(s) one cannot
656 //  change the DevCopy mode anymore.
657 //  To change the DevCopy mode for an existing AliEvent containing
658 //  devices one first has to invoke Reset().
659
660  if (!fDevices)
661  {
662   if (j==0 || j==1)
663   {
664    fDevCopy=j;
665   }
666   else
667   {
668    cout << " *" << ClassName() << "::SetDevCopy* Invalid argument : " << j << endl;
669   }
670  }
671  else
672  {
673   cout << " *" << ClassName() << "::SetDevCopy* Storage already contained devices."
674        << "  ==> DevCopy mode not changed." << endl; 
675  }
676 }
677 ///////////////////////////////////////////////////////////////////////////
678 Int_t AliEvent::GetDevCopy() const
679 {
680 // Provide value of the DevCopy mode.
681 // 0 ==> No private copies are made; pointers of original devices are stored.
682 // 1 ==> Private copies of the devices are made and these pointers are stored.
683 //
684 // Note :
685 // In case a private copy is made, this is performed via the Clone() memberfunction.
686 // All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
687 // memberfunction.
688 // However, devices generally contain an internal (signal) data structure
689 // which may include pointers to other objects. Therefore it is recommended to provide
690 // for all devices a specific copy constructor and override the default Clone()
691 // memberfunction using this copy constructor.
692 // An example for this may be seen from AliCalorimeter.   
693
694  return fDevCopy;
695 }
696 ///////////////////////////////////////////////////////////////////////////
697 TObject* AliEvent::GetDevice(Int_t i) const
698 {
699 // Return the i-th device of this event.
700 // The first device corresponds to i=1.
701
702  if (!fDevices)
703  {
704   return 0;
705  }
706  else
707  {
708   Int_t ndevs=GetNdevices();
709   if (i<=0 || i>ndevs)
710   {
711    cout << " *" << ClassName() << "::GetDevice* Invalid argument i : " << i
712         << " ndevs = " << ndevs << endl;
713    return 0;
714   }
715   else
716   {
717    return fDevices->At(i-1);
718   }
719  }
720 }
721 ///////////////////////////////////////////////////////////////////////////
722 TObject* AliEvent::GetDevice(TString name) const
723 {
724 // Return the device with name tag "name"
725  if (!fDevices)
726  {
727   return 0;
728  }
729  else
730  {
731   TString s;
732   Int_t ndevs=GetNdevices();
733   for (Int_t i=0; i<ndevs; i++)
734   {
735    TObject* dev=fDevices->At(i);
736    if (dev)
737    {
738     s=dev->GetName();
739     if (s == name) return dev;
740    }
741   }
742
743   return 0; // No matching name found
744  }
745 }
746 ///////////////////////////////////////////////////////////////////////////
747 TObject* AliEvent::GetIdDevice(Int_t id) const
748 {
749 // Return the device with unique identifier "id".
750  if (!fDevices || id<0) return 0;
751
752  Int_t idx=0;
753  for (Int_t i=0; i<GetNdevices(); i++)
754  {
755   TObject* dev=fDevices->At(i);
756   if (dev)
757   {
758    idx=dev->GetUniqueID();
759    if (idx==id) return dev;
760   }
761  }
762  return 0; // No matching id found
763 }
764 ///////////////////////////////////////////////////////////////////////////
765 void AliEvent::ShowDevices(Int_t mode) const
766 {
767 // Provide an overview of the available devices.
768 // The argument mode determines the amount of information as follows :
769 // mode = 0 ==> Only printout of the number of devices
770 //        1 ==> Provide a listing with 1 line of info for each device
771 //
772 // The default is mode=1.
773 //
774  Int_t ndevs=GetNdevices();
775  if (ndevs)
776  {
777   if (!mode)
778   {
779    cout << " There are " << ndevs << " devices available." << endl; 
780   }
781   else
782   {
783    cout << " The following " << ndevs << " devices are available :" << endl; 
784    for (Int_t i=1; i<=ndevs; i++)
785    {
786     TObject* dev=GetDevice(i);
787     if (dev)
788     {
789      const char* name=dev->GetName();
790      cout << " Device number : " << i;
791      cout << " Class : " << dev->ClassName() << " Id : " << dev->GetUniqueID();
792      if (strlen(name)) cout << " Name : " << name;
793      if (dev->InheritsFrom("AliDevice")) cout << " Nhits : " << ((AliDevice*)dev)->GetNhits();
794      if (dev->InheritsFrom("AliSignal")) cout << " Nwaveforms : " << ((AliSignal*)dev)->GetNwaveforms();
795      cout << endl;
796     }
797    }
798   }
799  }
800  else
801  {
802   cout << " No devices present for this event." << endl;
803  }
804 }
805 ///////////////////////////////////////////////////////////////////////////
806 Int_t AliEvent::GetNhits(const char* classname)
807 {
808 // Provide the number of hits registered to the specified device class.
809 // The specified device class has to be derived from AliDevice.
810 // It is possible to indicate with the argument "classname" a specific
811 // device instead of a whole class of devices. However, in such a case
812 // it is more efficient to use the GetDevice() memberfunction directly.
813  LoadHits(classname);
814  Int_t nhits=0;
815  if (fHits) nhits=fHits->GetEntries();
816  return nhits;
817 }
818 ///////////////////////////////////////////////////////////////////////////
819 TObjArray* AliEvent::GetHits(const char* classname)
820 {
821 // Provide the references to all the hits registered to the specified
822 // device class.
823 // The specified device class has to be derived from AliDevice.
824 // It is possible to indicate with the argument "classname" a specific
825 // device instead of a whole class of devices. However, in such a case
826 // it is more efficient to use the GetDevice() memberfunction directly.
827  LoadHits(classname);
828  return fHits;
829 }
830 ///////////////////////////////////////////////////////////////////////////
831 AliSignal* AliEvent::GetIdHit(Int_t id,const char* classname)
832 {
833 // Return the hit with unique identifier "id" for the specified device class.
834  if (id<0) return 0;
835
836  Int_t nhits=GetNhits(classname);
837  if (!nhits) return 0;
838
839  AliSignal* sx=0;
840  Int_t sid=0;
841  for (Int_t i=0; i<nhits; i++)
842  {
843   sx=(AliSignal*)fHits->At(i);
844   if (sx)
845   {
846    sid=sx->GetUniqueID();
847    if (id==sid) return sx;
848   }
849  }
850  return 0; // No matching id found
851 }
852 ///////////////////////////////////////////////////////////////////////////
853 void AliEvent::LoadHits(const char* classname)
854 {
855 // Load the references to the various hits registered to the specified
856 // device class.
857 // The specified device class has to be derived from AliDevice.
858  if (fHits) fHits->Clear();
859
860  Int_t ndev=GetNdevices();
861  for (Int_t idev=1; idev<=ndev; idev++)
862  {
863   TObject* obj=GetDevice(idev);
864   if (!obj) continue;
865
866   if (obj->InheritsFrom(classname) && obj->InheritsFrom("AliDevice"))
867   {
868    AliDevice* dev=(AliDevice*)GetDevice(idev);
869    Int_t nhits=dev->GetNhits();
870    if (nhits)
871    {
872     if (!fHits) fHits=new TObjArray();
873     for (Int_t ih=1; ih<=nhits; ih++)
874     {
875      AliSignal* sx=dev->GetHit(ih);
876      if (sx) fHits->Add(sx);
877     }
878    }
879   }
880  }
881 }
882 ///////////////////////////////////////////////////////////////////////////
883 TObjArray* AliEvent::SortHits(const char* classname,Int_t idx,Int_t mode)
884 {
885 // Order the references to the various hits registered to the specified
886 // device class. The ordered array is returned as a TObjArray.
887 // A "hit" represents an abstract object which is derived from AliSignal.
888 // The user can specify the index of the signal slot to perform the sorting on.
889 // By default the slotindex will be 1.
890 // Via the "mode" argument the user can specify ordering in decreasing
891 // order (mode=-1) or ordering in increasing order (mode=1).
892 // The default is mode=-1.
893 // Signals which were declared as "Dead" will be rejected.
894 // The gain etc... corrected signals will be used in the ordering process.
895 //
896 // For more extended functionality see class AliDevice.
897
898  if (idx<=0 || abs(mode)!=1) return 0;
899
900  LoadHits(classname);
901
902  AliDevice dev;
903  TObjArray* ordered=dev.SortHits(idx,mode,fHits);
904
905  if (fHits)
906  {
907   delete fHits;
908   fHits=0;
909  } 
910  if (ordered) fHits=new TObjArray(*ordered);
911  return fHits;
912 }
913 ///////////////////////////////////////////////////////////////////////////
914 TObjArray* AliEvent::SortHits(const char* classname,TString name,Int_t mode)
915 {
916 // Order the references to the various hits registered to the specified
917 // device class. The ordered array is returned as a TObjArray.
918 // A "hit" represents an abstract object which is derived from AliSignal.
919 // The user can specify the name of the signal slot to perform the sorting on.
920 // In case no matching slotname is found, the signal will be skipped.
921 // Via the "mode" argument the user can specify ordering in decreasing
922 // order (mode=-1) or ordering in increasing order (mode=1).
923 // The default is mode=-1.
924 // Signals which were declared as "Dead" will be rejected.
925 // The gain etc... corrected signals will be used in the ordering process.
926 //
927 // For more extended functionality see class AliDevice.
928  
929  if (abs(mode)!=1) return 0;
930
931  LoadHits(classname);
932
933  AliDevice dev;
934  TObjArray* ordered=dev.SortHits(name,mode,fHits);
935
936  if (fHits)
937  {
938   delete fHits;
939   fHits=0;
940  } 
941  if (ordered) fHits=new TObjArray(*ordered);
942  return fHits;
943 }
944 ///////////////////////////////////////////////////////////////////////////
945 void AliEvent::GetExtremes(const char* classname,Float_t& vmin,Float_t& vmax,Int_t idx)
946 {
947 // Provide the min. and max. signal values of the various hits registered
948 // to the specified device class.
949 // The input argument "idx" denotes the index of the signal slots to be investigated.
950 // The default is idx=1;
951 // Signals which were declared as "Dead" will be rejected.
952 // The gain etc... corrected signals will be used in the process.
953 //
954 // For more extended functionality see class AliDevice.
955
956  if (idx<=0) return;
957
958  LoadHits(classname);
959
960  AliDevice dev;
961  dev.GetExtremes(vmin,vmax,idx,fHits);
962 }
963 ///////////////////////////////////////////////////////////////////////////
964 void AliEvent::GetExtremes(const char* classname,Float_t& vmin,Float_t& vmax,TString name)
965 {
966 // Provide the min. and max. signal values of the various hits registered
967 // to the specified device class.
968 // The input argument "name" denotes the name of the signal slots to be investigated.
969 // Signals which were declared as "Dead" will be rejected.
970 // The gain etc... corrected signals will be used in the process.
971 //
972 // For more extended functionality see class AliDevice.
973
974  LoadHits(classname);
975
976  AliDevice dev;
977  dev.GetExtremes(vmin,vmax,name,fHits);
978 }
979 ///////////////////////////////////////////////////////////////////////////
980 void AliEvent::DisplayHits(const char* classname,Int_t idx,Float_t scale,Int_t dp,Int_t mstyle,Int_t mcol)
981 {
982 // 3D color display of the various hits registered to the specified device class.
983 // The user can specify the index (default=1) of the signal slot to perform the display for.
984 // The marker size will indicate the absolute value of the signal (specified by the slotindex)
985 // as a percentage of the input argument "scale".
986 // In case scale<0 the maximum absolute signal value encountered in the hit array will be used
987 // to define the 100% scale. The default is scale=-1.
988 // In case dp=1 the owning device position will be used, otherwise the hit position will
989 // be used in the display. The default is dp=0.
990 // Via the "mstyle" and "mcol" arguments the user can specify the marker style
991 // and color (see TPolyMarker3D) respectively.
992 // The defaults are mstyle="large scalable dot" and mcol=blue.
993 // Signals which were declared as "Dead" will not be displayed.
994 // The gain etc... corrected signals will be used to determine the marker size.
995 //
996 // For more extended functionality see class AliDevice.
997 //
998 // Note :
999 // ------
1000 // Before any display activity, a TCanvas and a TView have to be initiated
1001 // first by the user like for instance
1002 // 
1003 // TCanvas* c1=new TCanvas("c1","c1");
1004 // TView* view=new TView(1);
1005 // view->SetRange(-1000,-1000,-1000,1000,1000,1000);
1006 // view->ShowAxis();
1007
1008  if (idx<=0) return;
1009
1010  LoadHits(classname);
1011
1012  AliDevice* dev=new AliDevice();
1013  dev->DisplayHits(idx,scale,fHits,dp,mstyle,mcol);
1014
1015  if (fDisplay)
1016  {
1017   delete fDisplay;
1018   fDisplay=0;
1019  }
1020  fDisplay=dev;
1021 }
1022 ///////////////////////////////////////////////////////////////////////////
1023 void AliEvent::DisplayHits(const char* classname,TString name,Float_t scale,Int_t dp,Int_t mstyle,Int_t mcol)
1024 {
1025 // 3D color display of the various hits registered to the specified device class.
1026 // The user can specify the name of the signal slot to perform the display for.
1027 // The marker size will indicate the absolute value of the signal (specified by the slotname)
1028 // as a percentage of the input argument "scale".
1029 // In case scale<0 the maximum absolute signal value encountered in the hit array will be used
1030 // to define the 100% scale. The default is scale=-1.
1031 // In case dp=1 the owning device position will be used, otherwise the hit position will
1032 // be used in the display. The default is dp=0.
1033 // The marker size will indicate the percentage of the maximum encountered value
1034 // of the absolute value of the name-specified input signal slots.
1035 // Via the "mstyle" and "mcol" arguments the user can specify the marker style
1036 // and color (see TPolyMarker3D) respectively.
1037 // The defaults are mstyle="large scalable dot" and mcol=blue.
1038 // Signals which were declared as "Dead" will not be displayed.
1039 // The gain etc... corrected signals will be used to determine the marker size.
1040 //
1041 // For more extended functionality see class AliDevice.
1042 //
1043 // Note :
1044 // ------
1045 // Before any display activity, a TCanvas and a TView have to be initiated
1046 // first by the user like for instance
1047 // 
1048 // TCanvas* c1=new TCanvas("c1","c1");
1049 // TView* view=new TView(1);
1050 // view->SetRange(-1000,-1000,-1000,1000,1000,1000);
1051 // view->ShowAxis();
1052
1053  LoadHits(classname);
1054
1055  AliDevice* dev=new AliDevice();
1056  dev->DisplayHits(name,scale,fHits,dp,mstyle,mcol);
1057
1058  if (fDisplay)
1059  {
1060   delete fDisplay;
1061   fDisplay=0;
1062  }
1063  fDisplay=dev;
1064 }
1065 ///////////////////////////////////////////////////////////////////////////
1066 TObjArray* AliEvent::SortDevices(const char* classname,TString name,Int_t mode)
1067 {
1068 // Order the references to the various devices based on hit signals registered
1069 // to the specified device class. The ordered array is returned as a TObjArray.
1070 // A "hit" represents an abstract object which is derived from AliSignal.
1071 // The user can specify the name of the signal slot to perform the sorting on.
1072 // In case no matching slotname is found, the signal will be skipped.
1073 // Via the "mode" argument the user can specify ordering in decreasing
1074 // order (mode=-1) or ordering in increasing order (mode=1).
1075 // The default is mode=-1.
1076 // Signals which were declared as "Dead" will be rejected.
1077 // The gain etc... corrected signals will be used in the ordering process.
1078 //
1079
1080  TObjArray* ordered=SortHits(classname,name,mode);
1081  
1082  if (!ordered) return 0;
1083
1084  TObjArray* devs=SortDevices(ordered,"*",0);
1085  return devs;
1086 }
1087 ///////////////////////////////////////////////////////////////////////////
1088 TObjArray* AliEvent::SortDevices(const char* classname,Int_t idx,Int_t mode)
1089 {
1090 // Order the references to the various devices based on hit signals registered
1091 // to the specified device class. The ordered array is returned as a TObjArray.
1092 // A "hit" represents an abstract object which is derived from AliSignal.
1093 // The user can specify the index of the signal slot to perform the sorting on.
1094 // By default the slotindex will be 1.
1095 // Via the "mode" argument the user can specify ordering in decreasing
1096 // order (mode=-1) or ordering in increasing order (mode=1).
1097 // The default is mode=-1.
1098 // Signals which were declared as "Dead" will be rejected.
1099 // The gain etc... corrected signals will be used in the ordering process.
1100 //
1101
1102  TObjArray* ordered=SortHits(classname,idx,mode);
1103  
1104  if (!ordered) return 0;
1105
1106  TObjArray* devs=SortDevices(ordered,0,0);
1107  return devs;
1108 }
1109 ///////////////////////////////////////////////////////////////////////////
1110 TObjArray* AliEvent::SortDevices(TObjArray* hits,TString name,Int_t mode)
1111 {
1112 // Order the references to the various devices based on hit signals contained
1113 // in the input array. The ordered array is returned as a TObjArray.
1114 // A "hit" represents an abstract object which is derived from AliSignal.
1115 // The user can specify the name of the signal slot to perform the sorting on.
1116 // In case no matching slotname is found, the signal will be skipped.
1117 // Via the "mode" argument the user can specify ordering in decreasing
1118 // order (mode=-1), ordering in increasing order (mode=1) or no ordering (mode=0).
1119 // The latter option provides a means to quickly obtain an ordered devices list
1120 // when the hits in the array were already ordered by the user. In this case
1121 // the input argument "name" is irrelevant.
1122 // The default is mode=-1.
1123 // Signals which were declared as "Dead" will be rejected.
1124 // The gain etc... corrected signals will be used in the ordering process.
1125 //
1126
1127  if (!hits) return 0;
1128
1129  TObjArray* ordered=hits;
1130  AliDevice dev;
1131  if (mode) ordered=dev.SortHits(name,mode,hits);
1132  
1133  if (!ordered) return 0;
1134
1135  if (fOrdered)
1136  {
1137   fOrdered->Clear();
1138  }
1139  else
1140  {
1141   fOrdered=new TObjArray();
1142  }
1143
1144  Int_t nhits=ordered->GetEntries();
1145  Int_t exist=0;
1146  for (Int_t ih=0; ih<nhits; ih++)
1147  {
1148   AliSignal* sx=(AliSignal*)ordered->At(ih);
1149   if (!sx) continue;
1150   AliDevice* dx=sx->GetDevice();
1151   exist=0;
1152   for (Int_t id=0; id<fOrdered->GetEntries(); id++)
1153   {
1154    AliDevice* odx=(AliDevice*)fOrdered->At(id);
1155    if (dx==odx)
1156    {
1157     exist=1;
1158     break;
1159    }
1160   }
1161   if (!exist) fOrdered->Add(dx);
1162  }
1163  return fOrdered;
1164 }
1165 ///////////////////////////////////////////////////////////////////////////
1166 TObjArray* AliEvent::SortDevices(TObjArray* hits,Int_t idx,Int_t mode)
1167 {
1168 // Order the references to the various devices based on hit signals contained
1169 // in the input array. The ordered array is returned as a TObjArray.
1170 // A "hit" represents an abstract object which is derived from AliSignal.
1171 // The user can specify the index of the signal slot to perform the sorting on.
1172 // By default the slotindex will be 1.
1173 // Via the "mode" argument the user can specify ordering in decreasing
1174 // order (mode=-1), ordering in increasing order (mode=1) or no ordering (mode=0).
1175 // The latter option provides a means to quickly obtain an ordered devices list
1176 // when the hits in the array were already ordered by the user. In this case
1177 // the input argument "idx" is irrelevant.
1178 // The default is mode=-1.
1179 // Signals which were declared as "Dead" will be rejected.
1180 // The gain etc... corrected signals will be used in the ordering process.
1181 //
1182
1183  if (!hits) return 0;
1184
1185  TObjArray* ordered=hits;
1186  AliDevice dev;
1187  if (mode) ordered=dev.SortHits(idx,mode,hits);
1188  
1189  if (!ordered) return 0;
1190
1191  if (fOrdered)
1192  {
1193   fOrdered->Clear();
1194  }
1195  else
1196  {
1197   fOrdered=new TObjArray();
1198  }
1199
1200  Int_t nhits=ordered->GetEntries();
1201  Int_t exist=0;
1202  for (Int_t ih=0; ih<nhits; ih++)
1203  {
1204   AliSignal* sx=(AliSignal*)ordered->At(ih);
1205   if (!sx) continue;
1206   AliDevice* dx=sx->GetDevice();
1207   exist=0;
1208   for (Int_t id=0; id<fOrdered->GetEntries(); id++)
1209   {
1210    AliDevice* odx=(AliDevice*)fOrdered->At(id);
1211    if (dx==odx)
1212    {
1213     exist=1;
1214     break;
1215    }
1216   }
1217   if (!exist) fOrdered->Add(dx);
1218  }
1219  return fOrdered;
1220 }
1221 ///////////////////////////////////////////////////////////////////////////
1222 TObject* AliEvent::Clone(const char* name) const
1223 {
1224 // Make a deep copy of the current object and provide the pointer to the copy.
1225 // This memberfunction enables automatic creation of new objects of the
1226 // correct type depending on the object type, a feature which may be very useful
1227 // for containers when adding objects in case the container owns the objects.
1228 // This feature allows to store either AliEvent objects or objects derived from
1229 // AliEvent via some generic AddEvent memberfunction, provided these derived
1230 // classes also have a proper Clone memberfunction. 
1231
1232  AliEvent* evt=new AliEvent(*this);
1233  if (name)
1234  {
1235   if (strlen(name)) evt->SetName(name);
1236  }
1237  return evt;
1238 }
1239 ///////////////////////////////////////////////////////////////////////////
1240