]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliEvent.cxx
Added protection in Mlem()
[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 : By default all quantities are in meter, GeV, GeV/c or GeV/c**2
245 //        but the user can indicate the usage of a different scale for
246 //        the metric and/or energy-momentum units via the SetUnitScale()
247 //        and SetEscale() memberfunctions, respectively.
248 //        The actual metric and energy-momentum unit scales in use can be
249 //        obtained via the GetUnitScale() and GetEscale() memberfunctions.
250 //
251 //--- Author: Nick van Eijndhoven 27-may-2001 UU-SAP Utrecht
252 //- Modified: NvE $Date: 2004/10/20 10:49:44 $ UU-SAP Utrecht
253 ///////////////////////////////////////////////////////////////////////////
254
255 #include "AliEvent.h"
256 #include "Riostream.h"
257  
258 ClassImp(AliEvent) // Class implementation to enable ROOT I/O
259  
260 AliEvent::AliEvent() : AliVertex(),AliTimestamp()
261 {
262 // Default constructor.
263 // All variables initialised to default values.
264  fRun=0;
265  fEvent=0;
266  fDevices=0;
267  fDevCopy=0;
268  fHits=0;
269  fOrdered=0;
270  fDisplay=0;
271  fDevs=0;
272 }
273 ///////////////////////////////////////////////////////////////////////////
274 AliEvent::AliEvent(Int_t n) : AliVertex(n),AliTimestamp()
275 {
276 // Create an event to hold initially a maximum of n tracks
277 // All variables initialised to default values
278  if (n<=0)
279  {
280   cout << " *** This AliVertex initialisation was invoked via the AliEvent ctor." << endl;
281  }
282  fRun=0;
283  fEvent=0;
284  fDevices=0;
285  fDevCopy=0;
286  fHits=0;
287  fOrdered=0;
288  fDisplay=0;
289  fDevs=0;
290 }
291 ///////////////////////////////////////////////////////////////////////////
292 AliEvent::~AliEvent()
293 {
294 // Default destructor
295  if (fDevices)
296  {
297   delete fDevices;
298   fDevices=0;
299  }
300  if (fHits)
301  {
302   delete fHits;
303   fHits=0;
304  }
305  if (fOrdered)
306  {
307   delete fOrdered;
308   fOrdered=0;
309  }
310  if (fDisplay)
311  {
312   delete fDisplay;
313   fDisplay=0;
314  }
315  if (fDevs)
316  {
317   delete fDevs;
318   fDevs=0;
319  }
320 }
321 ///////////////////////////////////////////////////////////////////////////
322 AliEvent::AliEvent(const AliEvent& evt) : AliVertex(evt),AliTimestamp(evt)
323 {
324 // Copy constructor.
325  fRun=evt.fRun;
326  fEvent=evt.fEvent;
327  fDevCopy=evt.fDevCopy;
328
329  fHits=0;
330  fOrdered=0;
331  fDisplay=0;
332  fDevs=0;
333
334  fDevices=0;
335  Int_t ndevs=evt.GetNdevices();
336  if (ndevs)
337  {
338   fDevices=new TObjArray(ndevs);
339   if (fDevCopy) fDevices->SetOwner();
340   for (Int_t i=1; i<=ndevs; i++)
341   {
342    TObject* dev=evt.GetDevice(i);
343    if (dev)
344    {
345     if (fDevCopy)
346     {
347      fDevices->Add(dev->Clone());
348     }
349     else
350     {
351      fDevices->Add(dev);
352     }
353    }
354   }
355  }
356 }
357 ///////////////////////////////////////////////////////////////////////////
358 void AliEvent::Reset()
359 {
360 // Reset all variables to default values
361 // The max. number of tracks is set to the initial value again
362 // The max. number of vertices is set to the default value again
363 // Note : The DevCopy mode is maintained as it was set by the user before.
364
365  AliVertex::Reset();
366
367  Set();
368  fRun=0;
369  fEvent=0;
370
371  if (fDevices)
372  {
373   delete fDevices;
374   fDevices=0;
375  }
376  if (fHits)
377  {
378   delete fHits;
379   fHits=0;
380  }
381  if (fOrdered)
382  {
383   delete fOrdered;
384   fOrdered=0;
385  }
386  if (fDisplay)
387  {
388   delete fDisplay;
389   fDisplay=0;
390  }
391  if (fDevs)
392  {
393   delete fDevs;
394   fDevs=0;
395  }
396 }
397 ///////////////////////////////////////////////////////////////////////////
398 void AliEvent::SetOwner(Bool_t own)
399 {
400 // Set ownership of all added objects. 
401 // The default parameter is own=kTRUE.
402 //
403 // Invokation of this memberfunction also sets all the copy modes
404 // (e.g. TrackCopy & co.) according to the value of own.
405 //
406 // This function (with own=kTRUE) is particularly useful when reading data
407 // from a tree/file, since Reset() will then actually remove all the
408 // added objects from memory irrespective of the copy mode settings
409 // during the tree/file creation process. In this way it provides a nice way
410 // of preventing possible memory leaks in the reading/analysis process.
411 //
412 // In addition this memberfunction can also be used as a shortcut to set all
413 // copy modes in one go during a tree/file creation process.
414 // However, in this case the user has to take care to only set/change the
415 // ownership (and copy mode) for empty objects (e.g. newly created objects
416 // or after invokation of the Reset() memberfunction) otherwise it will
417 // very likely result in inconsistent destructor behaviour.
418
419  Int_t mode=1;
420  if (!own) mode=0;
421  if (fDevices) fDevices->SetOwner(own);
422  fDevCopy=mode;
423
424  AliVertex::SetOwner(own);
425 }
426 ///////////////////////////////////////////////////////////////////////////
427 void AliEvent::SetDayTime(TTimeStamp& stamp)
428 {
429 // Set the date and time stamp for this event.
430 // An exact copy of the entered date/time stamp will be saved with an
431 // accuracy of 1 nanosecond.
432 //
433 // Note : Since the introduction of the more versatile class AliTimestamp
434 //        and the fact that AliEvent has now been derived from it,
435 //        this memberfunction has become obsolete.
436 //        It is recommended to use the corresponding AliTimestamp
437 //        functionality directly for AliEvent instances.
438 //        This memberfunction is only kept for backward compatibility.
439
440  Set(stamp.GetDate(),stamp.GetTime(),0,kTRUE,0);
441 }
442 ///////////////////////////////////////////////////////////////////////////
443 void AliEvent::SetDayTime(TDatime& stamp)
444 {
445 // Set the date and time stamp for this event.
446 // The entered date/time will be interpreted as being the local date/time
447 // and the accuracy is 1 second.
448 //
449 // This function with the TDatime argument is mainly kept for backward
450 // compatibility reasons.
451 // It is recommended to use the corresponding AliTimestamp functionality
452 // directly for AliEvent instances.
453
454  Set(stamp.GetDate(),stamp.GetTime(),0,kFALSE,0);
455 }
456 ///////////////////////////////////////////////////////////////////////////
457 void AliEvent::SetRunNumber(Int_t run)
458 {
459 // Set the run number for this event
460  fRun=run;
461 }
462 ///////////////////////////////////////////////////////////////////////////
463 void AliEvent::SetEventNumber(Int_t evt)
464 {
465 // Set the event number for this event
466  fEvent=evt;
467 }
468 ///////////////////////////////////////////////////////////////////////////
469 TTimeStamp AliEvent::GetDayTime() const
470 {
471 // Provide the date and time stamp for this event
472 //
473 // Note : Since the introduction of the more versatile class AliTimestamp
474 //        and the fact that AliEvent has now been derived from it,
475 //        this memberfunction has become obsolete.
476 //        It is recommended to use the corresponding AliTimestamp
477 //        functionality directly for AliEvent instances.
478 //        This memberfunction is only kept for backward compatibility.
479
480  return (TTimeStamp)(*this);
481 }
482 ///////////////////////////////////////////////////////////////////////////
483 Int_t AliEvent::GetRunNumber() const
484 {
485 // Provide the run number for this event
486  return fRun;
487 }
488 ///////////////////////////////////////////////////////////////////////////
489 Int_t AliEvent::GetEventNumber() const
490 {
491 // Provide the event number for this event
492  return fEvent;
493 }
494 ///////////////////////////////////////////////////////////////////////////
495 void AliEvent::SetProjectile(Int_t a,Int_t z,Double_t pnuc,Int_t id)
496 {
497 // Set the projectile A, Z, momentum per nucleon and user defined particle ID.
498 // If not explicitly specified by the user, the projectile particle ID is set
499 // to zero by default and will not be stored in the event structure.
500 // The projectile specifications will be stored in a device named "Beam"
501 // which is an instance of AliSignal.
502 // As such these data are easily retrievable from the event structure.
503 // However, for backward compatibility reasons the beam data can also be
504 // retrieved via memberfunctions like GetProjectileA() etc...
505
506  Int_t newdev=0;
507  
508  AliSignal* beam=(AliSignal*)GetDevice("Beam");
509  
510  if (!beam)
511  {
512   beam=new AliSignal();
513   beam->SetNameTitle("Beam","Beam and target specifications");
514   newdev=1;
515  }
516
517  if (a || z)
518  {
519   beam->AddNamedSlot("Aproj");
520   beam->SetSignal(a,"Aproj");
521   beam->AddNamedSlot("Zproj");
522   beam->SetSignal(z,"Zproj");
523  }
524  beam->AddNamedSlot("Pnucproj");
525  beam->SetSignal(pnuc,"Pnucproj");
526  if (id)
527  {
528   beam->AddNamedSlot("Idproj");
529   beam->SetSignal(id,"Idproj");
530  }
531
532  if (newdev)
533  {
534   AddDevice(beam);
535   if (fDevCopy) delete beam;
536  }
537 }
538 ///////////////////////////////////////////////////////////////////////////
539 Int_t AliEvent::GetProjectileA() const
540 {
541 // Provide the projectile A value.
542  Int_t val=0;
543  AliSignal* beam=(AliSignal*)GetDevice("Beam");
544  if (beam) val=int(beam->GetSignal("Aproj"));
545  return val;
546 }
547 ///////////////////////////////////////////////////////////////////////////
548 Int_t AliEvent::GetProjectileZ() const
549 {
550 // Provide the projectile Z value.
551  Int_t val=0;
552  AliSignal* beam=(AliSignal*)GetDevice("Beam");
553  if (beam) val=int(beam->GetSignal("Zproj"));
554  return val;
555 }
556 ///////////////////////////////////////////////////////////////////////////
557 Double_t AliEvent::GetProjectilePnuc() const
558 {
559 // Provide the projectile momentum value per nucleon.
560  Double_t val=0;
561  AliSignal* beam=(AliSignal*)GetDevice("Beam");
562  if (beam) val=beam->GetSignal("Pnucproj");
563  return val;
564 }
565 ///////////////////////////////////////////////////////////////////////////
566 Int_t AliEvent::GetProjectileId() const
567 {
568 // Provide the user defined particle ID of the projectile.
569  Int_t val=0;
570  AliSignal* beam=(AliSignal*)GetDevice("Beam");
571  if (beam) val=int(beam->GetSignal("Idproj"));
572  return val;
573 }
574 ///////////////////////////////////////////////////////////////////////////
575 void AliEvent::SetTarget(Int_t a,Int_t z,Double_t pnuc,Int_t id)
576 {
577 // Set the target A, Z, momentum per nucleon and user defined particle ID.
578 // If not explicitly specified by the user, the target particle ID is set
579 // to zero by default and will not be stored in the event structure.
580 // The target specifications will be stored in a device named "Beam"
581 // which is an instance of AliSignal.
582 // As such these data are easily retrievable from the event structure.
583 // However, for backward compatibility reasons the beam data can also be
584 // retrieved via memberfunctions like GetTargetA() etc...
585
586  Int_t newdev=0;
587  
588  AliSignal* beam=(AliSignal*)GetDevice("Beam");
589  
590  if (!beam)
591  {
592   beam=new AliSignal();
593   beam->SetNameTitle("Beam","Beam and target specifications");
594   newdev=1;
595  }
596
597  if (a || z)
598  {
599   beam->AddNamedSlot("Atarg");
600   beam->SetSignal(a,"Atarg");
601   beam->AddNamedSlot("Ztarg");
602   beam->SetSignal(z,"Ztarg");
603  }
604  beam->AddNamedSlot("Pnuctarg");
605  beam->SetSignal(pnuc,"Pnuctarg");
606  if (id)
607  {
608   beam->AddNamedSlot("Idtarg");
609   beam->SetSignal(id,"Idtarg");
610  }
611
612  if (newdev)
613  {
614   AddDevice(beam);
615   if (fDevCopy) delete beam;
616  }
617 }
618 ///////////////////////////////////////////////////////////////////////////
619 Int_t AliEvent::GetTargetA() const
620 {
621 // Provide the target A value.
622  Int_t val=0;
623  AliSignal* beam=(AliSignal*)GetDevice("Beam");
624  if (beam) val=int(beam->GetSignal("Atarg"));
625  return val;
626 }
627 ///////////////////////////////////////////////////////////////////////////
628 Int_t AliEvent::GetTargetZ() const
629 {
630 // Provide the target Z value.
631  Int_t val=0;
632  AliSignal* beam=(AliSignal*)GetDevice("Beam");
633  if (beam) val=int(beam->GetSignal("Ztarg"));
634  return val;
635 }
636 ///////////////////////////////////////////////////////////////////////////
637 Double_t AliEvent::GetTargetPnuc() const
638 {
639 // Provide the target momentum value per nucleon.
640  Double_t val=0;
641  AliSignal* beam=(AliSignal*)GetDevice("Beam");
642  if (beam) val=beam->GetSignal("Pnuctarg");
643  return val;
644 }
645 ///////////////////////////////////////////////////////////////////////////
646 Int_t AliEvent::GetTargetId() const
647 {
648 // Provide the user defined particle ID of the target.
649  Int_t val=0;
650  AliSignal* beam=(AliSignal*)GetDevice("Beam");
651  if (beam) val=int(beam->GetSignal("Idtarg"));
652  return val;
653 }
654 ///////////////////////////////////////////////////////////////////////////
655 void AliEvent::HeaderData()
656 {
657 // Provide event header information
658  const char* name=GetName();
659  const char* title=GetTitle();
660  cout << " *" << ClassName() << "::Data*";
661  if (strlen(name))  cout << " Name : " << GetName();
662  if (strlen(title)) cout << " Title : " << GetTitle();
663  cout << endl;
664  Date(1);
665  cout << "  Run : " << fRun << " Event : " << fEvent << endl;
666  ShowDevices(0);
667  ShowTracks(0);
668 }
669 ///////////////////////////////////////////////////////////////////////////
670 void AliEvent::Data(TString f,TString u)
671 {
672 // Provide event information within the coordinate frame f
673 //
674 // The string argument "u" allows to choose between different angular units
675 // in case e.g. a spherical frame is selected.
676 // u = "rad" : angles provided in radians
677 //     "deg" : angles provided in degrees
678 //
679 // The defaults are f="car" and u="rad".
680
681  HeaderData();
682  AliVertex::Data(f,u);
683
684 ///////////////////////////////////////////////////////////////////////////
685 Int_t AliEvent::GetNdevices() const
686 {
687 // Provide the number of stored devices
688  Int_t ndevs=0;
689  if (fDevices) ndevs=fDevices->GetEntries();
690  return ndevs;
691
692 ///////////////////////////////////////////////////////////////////////////
693 Int_t AliEvent::GetNdevices(const char* classname) const
694 {
695 // Provide the number of stored devices of the specified class.
696
697  Int_t ndevs=0;
698  for (Int_t idev=1; idev<=GetNdevices(); idev++)
699  {
700   TObject* obj=GetDevice(idev);
701   if (!obj) continue;
702
703   if (obj->InheritsFrom(classname)) ndevs++;
704  }
705  return ndevs;
706
707 ///////////////////////////////////////////////////////////////////////////
708 void AliEvent::AddDevice(TObject& d)
709 {
710 // Add a device to the event.
711 //
712 // Note :
713 // In case a private copy is made, this is performed via the Clone() memberfunction.
714 // All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
715 // memberfunction.
716 // However, devices generally contain an internal (signal) data structure
717 // which may include pointers to other objects. Therefore it is recommended to provide
718 // for all devices a specific copy constructor and override the default Clone()
719 // memberfunction using this copy constructor.
720 // An example for this may be seen from AliCalorimeter.   
721
722  if (!fDevices)
723  {
724   fDevices=new TObjArray();
725   if (fDevCopy) fDevices->SetOwner();
726  }
727  
728  // Add the device to this event
729  if (fDevCopy)
730  {
731   fDevices->Add(d.Clone());
732  }
733  else
734  {
735   fDevices->Add(&d);
736  }
737 }
738 ///////////////////////////////////////////////////////////////////////////
739 void AliEvent::SetDevCopy(Int_t j)
740 {
741 // (De)activate the creation of private copies of the added devices.
742 // j=0 ==> No private copies are made; pointers of original devices are stored.
743 // j=1 ==> Private copies of the devices are made and these pointers are stored.
744 //
745 //
746 // Notes :
747 //  In case a private copy is made, this is performed via the Clone() memberfunction.
748 //  All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
749 //  memberfunction.
750 //  However, devices generally contain an internal (signal) data structure
751 //  which may include pointers to other objects. Therefore it is recommended to provide
752 //  for all devices a specific copy constructor and override the default Clone()
753 //  memberfunction using this copy constructor.
754 //  An example for this may be seen from AliCalorimeter.   
755 //
756 //  Once the storage contains pointer(s) to device(s) one cannot
757 //  change the DevCopy mode anymore.
758 //  To change the DevCopy mode for an existing AliEvent containing
759 //  devices one first has to invoke Reset().
760
761  if (!fDevices)
762  {
763   if (j==0 || j==1)
764   {
765    fDevCopy=j;
766   }
767   else
768   {
769    cout << " *" << ClassName() << "::SetDevCopy* Invalid argument : " << j << endl;
770   }
771  }
772  else
773  {
774   cout << " *" << ClassName() << "::SetDevCopy* Storage already contained devices."
775        << "  ==> DevCopy mode not changed." << endl; 
776  }
777 }
778 ///////////////////////////////////////////////////////////////////////////
779 Int_t AliEvent::GetDevCopy() const
780 {
781 // Provide value of the DevCopy mode.
782 // 0 ==> No private copies are made; pointers of original devices are stored.
783 // 1 ==> Private copies of the devices are made and these pointers are stored.
784 //
785 // Note :
786 // In case a private copy is made, this is performed via the Clone() memberfunction.
787 // All devices (i.e. classes derived from TObject) have the default TObject::Clone() 
788 // memberfunction.
789 // However, devices generally contain an internal (signal) data structure
790 // which may include pointers to other objects. Therefore it is recommended to provide
791 // for all devices a specific copy constructor and override the default Clone()
792 // memberfunction using this copy constructor.
793 // An example for this may be seen from AliCalorimeter.   
794
795  return fDevCopy;
796 }
797 ///////////////////////////////////////////////////////////////////////////
798 TObject* AliEvent::GetDevice(Int_t i) const
799 {
800 // Return the i-th device of this event.
801 // The first device corresponds to i=1.
802
803  if (!fDevices)
804  {
805   return 0;
806  }
807  else
808  {
809   Int_t ndevs=GetNdevices();
810   if (i<=0 || i>ndevs)
811   {
812    cout << " *" << ClassName() << "::GetDevice* Invalid argument i : " << i
813         << " ndevs = " << ndevs << endl;
814    return 0;
815   }
816   else
817   {
818    return fDevices->At(i-1);
819   }
820  }
821 }
822 ///////////////////////////////////////////////////////////////////////////
823 TObject* AliEvent::GetDevice(TString name) const
824 {
825 // Return the device with name tag "name"
826  if (!fDevices)
827  {
828   return 0;
829  }
830  else
831  {
832   TString s;
833   Int_t ndevs=GetNdevices();
834   for (Int_t i=0; i<ndevs; i++)
835   {
836    TObject* dev=fDevices->At(i);
837    if (dev)
838    {
839     s=dev->GetName();
840     if (s == name) return dev;
841    }
842   }
843
844   return 0; // No matching name found
845  }
846 }
847 ///////////////////////////////////////////////////////////////////////////
848 TObject* AliEvent::GetIdDevice(Int_t id,TObjArray* devs) const
849 {
850 // Return the device with identifier "id" from the specified array "devs".
851 // In case devs=0 (which is the default) all devices stored in the event
852 // structure will be evaluated.
853 // Note : In case of multiple occurrences of identifier "id", the first
854 //        encountered matching device will be returned.
855
856  TObjArray* arr=devs;
857  if (!arr) arr=fDevices;
858
859  if (!arr || id<0) return 0;
860
861  Int_t idx=0;
862  for (Int_t i=0; i<arr->GetSize(); i++)
863  {
864   TObject* dev=arr->At(i);
865   if (dev)
866   {
867    idx=dev->GetUniqueID();
868    if (idx==id) return dev;
869   }
870  }
871  return 0; // No matching id found
872 }
873 ///////////////////////////////////////////////////////////////////////////
874 TObject* AliEvent::GetIdDevice(Int_t id,const char* classname) const
875 {
876 // Return the device with identifier "id" of the specified class.
877 // Note : In case of multiple occurrences of identifier "id", the first
878 //        encountered matching device will be returned.
879
880  if (!fDevices || id<0) return 0;
881
882  Int_t idx=0;
883  for (Int_t i=0; i<GetNdevices(); i++)
884  {
885   TObject* dev=fDevices->At(i);
886   if (dev)
887   {
888    idx=dev->GetUniqueID();
889    if (idx==id && dev->InheritsFrom(classname)) return dev;
890   }
891  }
892  return 0; // No matching id found for the specified class
893 }
894 ///////////////////////////////////////////////////////////////////////////
895 void AliEvent::ShowDevices(Int_t mode) const
896 {
897 // Provide an overview of the available devices.
898 // The argument mode determines the amount of information as follows :
899 // mode = 0 ==> Only printout of the number of devices
900 //        1 ==> Provide a listing with 1 line of info for each device
901 //
902 // The default is mode=1.
903 //
904  Int_t ndevs=GetNdevices();
905  if (ndevs)
906  {
907   if (!mode)
908   {
909    cout << " There are " << ndevs << " devices available." << endl; 
910   }
911   else
912   {
913    cout << " The following " << ndevs << " devices are available :" << endl; 
914    Int_t nh=0,nw=0;
915    for (Int_t i=1; i<=ndevs; i++)
916    {
917     TObject* dev=GetDevice(i);
918     if (dev)
919     {
920      const char* name=dev->GetName();
921      cout << " Device number : " << i;
922      cout << " Class : " << dev->ClassName() << " Id : " << dev->GetUniqueID();
923      if (strlen(name)) cout << " Name : " << name;
924      if (dev->InheritsFrom("AliDevice"))
925      {
926       nh=((AliDevice*)dev)->GetNhits();
927       if (nh) cout << " Nhits : " << nh;
928      }
929      if (dev->InheritsFrom("AliSignal"))
930      {
931       nw=((AliSignal*)dev)->GetNwaveforms();
932       if (nw) cout << " Nwaveforms : " << nw;
933      }
934      cout << endl;
935     }
936    }
937   }
938  }
939  else
940  {
941   cout << " No devices present for this event." << endl;
942  }
943 }
944 ///////////////////////////////////////////////////////////////////////////
945 void AliEvent::ShowDevices(const char* classname,Int_t mode) const
946 {
947 // Provide an overview of the available devices of the specified class.
948 // The argument mode determines the amount of information as follows :
949 // mode = 0 ==> Only printout of the number of devices
950 //        1 ==> Provide a listing with 1 line of info for each device
951 //
952 // The default is mode=1.
953 //
954  Int_t ndevs=GetNdevices();
955  if (ndevs)
956  {
957   Int_t ndevs2=GetNdevices(classname);
958   if (!mode || !ndevs2)
959   {
960    cout << " There are " << ndevs2 << " selected devices available." << endl; 
961   }
962   else
963   {
964    cout << " The following " << ndevs2 << " selected devices are available :" << endl; 
965    Int_t nh=0,nw=0;
966    for (Int_t i=1; i<=ndevs; i++)
967    {
968     TObject* dev=GetDevice(i);
969     if (dev)
970     {
971      if (dev->InheritsFrom(classname))
972      {
973       const char* name=dev->GetName();
974       cout << " Device number : " << i;
975       cout << " Class : " << dev->ClassName() << " Id : " << dev->GetUniqueID();
976       if (strlen(name)) cout << " Name : " << name;
977       if (dev->InheritsFrom("AliDevice"))
978       {
979        nh=((AliDevice*)dev)->GetNhits();
980        if (nh) cout << " Nhits : " << nh;
981       }
982       if (dev->InheritsFrom("AliSignal"))
983       {
984        nw=((AliSignal*)dev)->GetNwaveforms();
985        if (nw) cout << " Nwaveforms : " << nw;
986       }
987       cout << endl;
988      }
989     }
990    }
991   }
992  }
993  else
994  {
995   cout << " No devices present for this event." << endl;
996  }
997 }
998 ///////////////////////////////////////////////////////////////////////////
999 TObjArray* AliEvent::GetDevices(const char* classname)
1000 {
1001 // Provide the references to the various devices derived from the
1002 // specified class.
1003  if (fDevs) fDevs->Clear();
1004
1005  Int_t ndev=GetNdevices();
1006  for (Int_t idev=1; idev<=ndev; idev++)
1007  {
1008   TObject* obj=GetDevice(idev);
1009   if (!obj) continue;
1010
1011   if (obj->InheritsFrom(classname))
1012   {
1013    if (!fDevs) fDevs=new TObjArray();
1014    fDevs->Add(obj);
1015   }
1016  }
1017  return fDevs;
1018 }
1019 ///////////////////////////////////////////////////////////////////////////
1020 Int_t AliEvent::GetNhits(const char* classname)
1021 {
1022 // Provide the number of hits registered to the specified device class.
1023 // The specified device class has to be derived from AliDevice.
1024 // It is possible to indicate with the argument "classname" a specific
1025 // device instead of a whole class of devices. However, in such a case
1026 // it is more efficient to use the GetDevice() memberfunction directly.
1027  LoadHits(classname);
1028  Int_t nhits=0;
1029  if (fHits) nhits=fHits->GetEntries();
1030  return nhits;
1031 }
1032 ///////////////////////////////////////////////////////////////////////////
1033 TObjArray* AliEvent::GetHits(const char* classname)
1034 {
1035 // Provide the references to all the hits registered to the specified
1036 // device class.
1037 // The specified device class has to be derived from AliDevice.
1038 // It is possible to indicate with the argument "classname" a specific
1039 // device instead of a whole class of devices. However, in such a case
1040 // it is more efficient to use the GetDevice() memberfunction directly.
1041  LoadHits(classname);
1042  return fHits;
1043 }
1044 ///////////////////////////////////////////////////////////////////////////
1045 AliSignal* AliEvent::GetIdHit(Int_t id,const char* classname)
1046 {
1047 // Return the hit with unique identifier "id" for the specified device class.
1048  if (id<0) return 0;
1049
1050  Int_t nhits=GetNhits(classname);
1051  if (!nhits) return 0;
1052
1053  AliSignal* sx=0;
1054  Int_t sid=0;
1055  for (Int_t i=0; i<nhits; i++)
1056  {
1057   sx=(AliSignal*)fHits->At(i);
1058   if (sx)
1059   {
1060    sid=sx->GetUniqueID();
1061    if (id==sid) return sx;
1062   }
1063  }
1064  return 0; // No matching id found
1065 }
1066 ///////////////////////////////////////////////////////////////////////////
1067 void AliEvent::LoadHits(const char* classname)
1068 {
1069 // Load the references to the various hits registered to the specified
1070 // device class.
1071 // The specified device class has to be derived from AliDevice.
1072  if (fHits) fHits->Clear();
1073
1074  Int_t ndev=GetNdevices();
1075  for (Int_t idev=1; idev<=ndev; idev++)
1076  {
1077   TObject* obj=GetDevice(idev);
1078   if (!obj) continue;
1079
1080   if (obj->InheritsFrom(classname) && obj->InheritsFrom("AliDevice"))
1081   {
1082    AliDevice* dev=(AliDevice*)GetDevice(idev);
1083    Int_t nhits=dev->GetNhits();
1084    if (nhits)
1085    {
1086     if (!fHits) fHits=new TObjArray();
1087     for (Int_t ih=1; ih<=nhits; ih++)
1088     {
1089      AliSignal* sx=dev->GetHit(ih);
1090      if (sx) fHits->Add(sx);
1091     }
1092    }
1093   }
1094  }
1095 }
1096 ///////////////////////////////////////////////////////////////////////////
1097 TObjArray* AliEvent::SortHits(const char* classname,Int_t idx,Int_t mode,Int_t mcal)
1098 {
1099 // Order the references to the various hits registered to the specified
1100 // device class. The ordered array is returned as a TObjArray.
1101 // A "hit" represents an abstract object which is derived from AliSignal.
1102 // The user can specify the index of the signal slot to perform the sorting on.
1103 // By default the slotindex will be 1.
1104 // Via the "mode" argument the user can specify ordering in decreasing
1105 // order (mode=-1) or ordering in increasing order (mode=1).
1106 // The default is mode=-1.
1107 // Signals which were declared as "Dead" will be rejected.
1108 // The gain etc... corrected signals will be used in the ordering process as
1109 // specified by the "mcal" argument. The definition of this "mcal" parameter
1110 // corresponds to the signal correction mode described in the GetSignal
1111 // memberfunction of class AliSignal.
1112 // The default is mcal=1 (for backward compatibility reasons).
1113 //
1114 // For more extended functionality see class AliDevice.
1115
1116  if (idx<=0 || abs(mode)!=1) return 0;
1117
1118  LoadHits(classname);
1119
1120  AliDevice dev;
1121  TObjArray* ordered=dev.SortHits(idx,mode,fHits,mcal);
1122
1123  if (fHits)
1124  {
1125   delete fHits;
1126   fHits=0;
1127  } 
1128  if (ordered) fHits=new TObjArray(*ordered);
1129  return fHits;
1130 }
1131 ///////////////////////////////////////////////////////////////////////////
1132 TObjArray* AliEvent::SortHits(const char* classname,TString name,Int_t mode,Int_t mcal)
1133 {
1134 // Order the references to the various hits registered to the specified
1135 // device class. The ordered array is returned as a TObjArray.
1136 // A "hit" represents an abstract object which is derived from AliSignal.
1137 // The user can specify the name of the signal slot to perform the sorting on.
1138 // In case no matching slotname is found, the signal will be skipped.
1139 // Via the "mode" argument the user can specify ordering in decreasing
1140 // order (mode=-1) or ordering in increasing order (mode=1).
1141 // The default is mode=-1.
1142 // Signals which were declared as "Dead" will be rejected.
1143 // The gain etc... corrected signals will be used in the ordering process as
1144 // specified by the "mcal" argument. The definition of this "mcal" parameter
1145 // corresponds to the signal correction mode described in the GetSignal
1146 // memberfunction of class AliSignal.
1147 // The default is mcal=1 (for backward compatibility reasons).
1148 //
1149 // For more extended functionality see class AliDevice.
1150  
1151  if (abs(mode)!=1) return 0;
1152
1153  LoadHits(classname);
1154
1155  AliDevice dev;
1156  TObjArray* ordered=dev.SortHits(name,mode,fHits,mcal);
1157
1158  if (fHits)
1159  {
1160   delete fHits;
1161   fHits=0;
1162  } 
1163  if (ordered) fHits=new TObjArray(*ordered);
1164  return fHits;
1165 }
1166 ///////////////////////////////////////////////////////////////////////////
1167 void AliEvent::GetExtremes(const char* classname,Float_t& vmin,Float_t& vmax,Int_t idx,Int_t mode)
1168 {
1169 // Provide the min. and max. signal values of the various hits registered
1170 // to the specified device class.
1171 // The input argument "idx" denotes the index of the signal slots to be investigated.
1172 // The default is idx=1;
1173 // Signals which were declared as "Dead" will be rejected.
1174 // The gain etc... corrected signals will be used in the process as specified
1175 // by the  "mode" argument. The definition of this "mode" parameter corresponds to
1176 // the description provided in the GetSignal memberfunction of class AliSignal.
1177 // The default is mode=1 (for backward compatibility reasons).
1178 //
1179 // For more extended functionality see class AliDevice.
1180
1181  if (idx<=0) return;
1182
1183  LoadHits(classname);
1184
1185  AliDevice dev;
1186  dev.GetExtremes(vmin,vmax,idx,fHits,mode);
1187 }
1188 ///////////////////////////////////////////////////////////////////////////
1189 void AliEvent::GetExtremes(const char* classname,Float_t& vmin,Float_t& vmax,TString name,Int_t mode)
1190 {
1191 // Provide the min. and max. signal values of the various hits registered
1192 // to the specified device class.
1193 // The input argument "name" denotes the name of the signal slots to be investigated.
1194 // Signals which were declared as "Dead" will be rejected.
1195 // The gain etc... corrected signals will be used in the process as specified
1196 // by the  "mode" argument. The definition of this "mode" parameter corresponds to
1197 // the description provided in the GetSignal memberfunction of class AliSignal.
1198 // The default is mode=1 (for backward compatibility reasons).
1199 //
1200 // For more extended functionality see class AliDevice.
1201
1202  LoadHits(classname);
1203
1204  AliDevice dev;
1205  dev.GetExtremes(vmin,vmax,name,fHits,mode);
1206 }
1207 ///////////////////////////////////////////////////////////////////////////
1208 void AliEvent::DisplayHits(const char* classname,Int_t idx,Float_t scale,Int_t dp,Int_t mode,Int_t mcol)
1209 {
1210 // 3D color display of the various hits registered to the specified device class.
1211 // The user can specify the index (default=1) of the signal slot to perform the display for.
1212 // The marker size will indicate the absolute value of the signal (specified by the slotindex)
1213 // as a percentage of the input argument "scale".
1214 // In case scale<0 the maximum absolute signal value encountered in the hit array will be used
1215 // to define the 100% scale. The default is scale=-1.
1216 // In case dp=1 the owning device position will be used, otherwise the hit position will
1217 // be used in the display. The default is dp=0.
1218 // Via the "mcol" argument the user can specify the marker color (see TPolyMarker3D).
1219 // The default is mcol=blue.
1220 // Signals which were declared as "Dead" will not be displayed.
1221 // The gain etc... corrected signals will be used to determine the marker size.
1222 // The gain correction is performed according to "mode" argument. The definition of this
1223 // "mode" parameter corresponds to the description provided in the GetSignal
1224 // memberfunction of class AliSignal.
1225 // The default is mode=1 (for backward compatibility reasons).
1226 //
1227 // For more extended functionality see class AliDevice.
1228 //
1229 // Note :
1230 // ------
1231 // Before any display activity, a TCanvas and a TView have to be initiated
1232 // first by the user like for instance
1233 // 
1234 // TCanvas* c1=new TCanvas("c1","c1");
1235 // TView* view=new TView(1);
1236 // view->SetRange(-1000,-1000,-1000,1000,1000,1000);
1237 // view->ShowAxis();
1238
1239  if (idx<=0) return;
1240
1241  LoadHits(classname);
1242
1243  AliDevice* dev=new AliDevice();
1244  dev->DisplayHits(idx,scale,fHits,dp,mode,mcol);
1245
1246  if (fDisplay)
1247  {
1248   delete fDisplay;
1249   fDisplay=0;
1250  }
1251  fDisplay=dev;
1252 }
1253 ///////////////////////////////////////////////////////////////////////////
1254 void AliEvent::DisplayHits(const char* classname,TString name,Float_t scale,Int_t dp,Int_t mode,Int_t mcol)
1255 {
1256 // 3D color display of the various hits registered to the specified device class.
1257 // The user can specify the name of the signal slot to perform the display for.
1258 // The marker size will indicate the absolute value of the signal (specified by the slotname)
1259 // as a percentage of the input argument "scale".
1260 // In case scale<0 the maximum absolute signal value encountered in the hit array will be used
1261 // to define the 100% scale. The default is scale=-1.
1262 // In case dp=1 the owning device position will be used, otherwise the hit position will
1263 // be used in the display. The default is dp=0.
1264 // The marker size will indicate the percentage of the maximum encountered value
1265 // of the absolute value of the name-specified input signal slots.
1266 // Via the "mcol" argument the user can specify the marker color (see TPolyMarker3D).
1267 // The default is mcol=blue.
1268 // Signals which were declared as "Dead" will not be displayed.
1269 // The gain etc... corrected signals will be used to determine the marker size.
1270 // The gain correction is performed according to "mode" argument. The definition of this
1271 // "mode" parameter corresponds to the description provided in the GetSignal
1272 // memberfunction of class AliSignal.
1273 // The default is mode=1 (for backward compatibility reasons).
1274 //
1275 // For more extended functionality see class AliDevice.
1276 //
1277 // Note :
1278 // ------
1279 // Before any display activity, a TCanvas and a TView have to be initiated
1280 // first by the user like for instance
1281 // 
1282 // TCanvas* c1=new TCanvas("c1","c1");
1283 // TView* view=new TView(1);
1284 // view->SetRange(-1000,-1000,-1000,1000,1000,1000);
1285 // view->ShowAxis();
1286
1287  LoadHits(classname);
1288
1289  AliDevice* dev=new AliDevice();
1290  dev->DisplayHits(name,scale,fHits,dp,mode,mcol);
1291
1292  if (fDisplay)
1293  {
1294   delete fDisplay;
1295   fDisplay=0;
1296  }
1297  fDisplay=dev;
1298 }
1299 ///////////////////////////////////////////////////////////////////////////
1300 TObjArray* AliEvent::SortDevices(const char* classname,TString name,Int_t mode,Int_t mcal)
1301 {
1302 // Order the references to the various devices based on hit signals registered
1303 // to the specified device class. The ordered array is returned as a TObjArray.
1304 // A "hit" represents an abstract object which is derived from AliSignal.
1305 // The user can specify the name of the signal slot to perform the sorting on.
1306 // In case no matching slotname is found, the signal will be skipped.
1307 // Via the "mode" argument the user can specify ordering in decreasing
1308 // order (mode=-1) or ordering in increasing order (mode=1).
1309 // The default is mode=-1.
1310 // Signals which were declared as "Dead" will be rejected.
1311 // The gain etc... corrected signals will be used in the ordering process as
1312 // specified by the "mcal" argument. The definition of this "mcal" parameter
1313 // corresponds to the signal correction mode described in the GetSignal
1314 // memberfunction of class AliSignal.
1315 // The default is mcal=1 (for backward compatibility reasons).
1316 //
1317
1318  TObjArray* ordered=SortHits(classname,name,mode,mcal);
1319  
1320  if (!ordered) return 0;
1321
1322  TObjArray* devs=SortDevices(ordered,"*",0,mcal);
1323  return devs;
1324 }
1325 ///////////////////////////////////////////////////////////////////////////
1326 TObjArray* AliEvent::SortDevices(const char* classname,Int_t idx,Int_t mode,Int_t mcal)
1327 {
1328 // Order the references to the various devices based on hit signals registered
1329 // to the specified device class. The ordered array is returned as a TObjArray.
1330 // A "hit" represents an abstract object which is derived from AliSignal.
1331 // The user can specify the index of the signal slot to perform the sorting on.
1332 // By default the slotindex will be 1.
1333 // Via the "mode" argument the user can specify ordering in decreasing
1334 // order (mode=-1) or ordering in increasing order (mode=1).
1335 // The default is mode=-1.
1336 // Signals which were declared as "Dead" will be rejected.
1337 // The gain etc... corrected signals will be used in the ordering process as
1338 // specified by the "mcal" argument. The definition of this "mcal" parameter
1339 // corresponds to the signal correction mode described in the GetSignal
1340 // memberfunction of class AliSignal.
1341 // The default is mcal=1 (for backward compatibility reasons).
1342 //
1343
1344  TObjArray* ordered=SortHits(classname,idx,mode,mcal);
1345  
1346  if (!ordered) return 0;
1347
1348  TObjArray* devs=SortDevices(ordered,0,0,mcal);
1349  return devs;
1350 }
1351 ///////////////////////////////////////////////////////////////////////////
1352 TObjArray* AliEvent::SortDevices(TObjArray* hits,TString name,Int_t mode,Int_t mcal)
1353 {
1354 // Order the references to the various devices based on hit signals contained
1355 // in the input array. The ordered array is returned as a TObjArray.
1356 // A "hit" represents an abstract object which is derived from AliSignal.
1357 // The user can specify the name of the signal slot to perform the sorting on.
1358 // In case no matching slotname is found, the signal will be skipped.
1359 // Via the "mode" argument the user can specify ordering in decreasing
1360 // order (mode=-1), ordering in increasing order (mode=1) or no ordering (mode=0).
1361 // The latter option provides a means to quickly obtain an ordered devices list
1362 // when the hits in the array were already ordered by the user. In this case
1363 // the input argument "name" is irrelevant.
1364 // The default is mode=-1.
1365 // Signals which were declared as "Dead" will be rejected.
1366 // The gain etc... corrected signals will be used in the ordering process as
1367 // specified by the "mcal" argument. The definition of this "mcal" parameter
1368 // corresponds to the signal correction mode described in the GetSignal
1369 // memberfunction of class AliSignal.
1370 // The default is mcal=1 (for backward compatibility reasons).
1371 //
1372
1373  if (!hits) return 0;
1374
1375  TObjArray* ordered=hits;
1376  AliDevice dev;
1377  if (mode) ordered=dev.SortHits(name,mode,hits,mcal);
1378  
1379  if (!ordered) return 0;
1380
1381  if (fOrdered)
1382  {
1383   fOrdered->Clear();
1384  }
1385  else
1386  {
1387   fOrdered=new TObjArray();
1388  }
1389
1390  Int_t nhits=ordered->GetEntries();
1391  Int_t exist=0;
1392  for (Int_t ih=0; ih<nhits; ih++)
1393  {
1394   AliSignal* sx=(AliSignal*)ordered->At(ih);
1395   if (!sx) continue;
1396   AliDevice* dx=sx->GetDevice();
1397   exist=0;
1398   for (Int_t id=0; id<fOrdered->GetEntries(); id++)
1399   {
1400    AliDevice* odx=(AliDevice*)fOrdered->At(id);
1401    if (dx==odx)
1402    {
1403     exist=1;
1404     break;
1405    }
1406   }
1407   if (!exist) fOrdered->Add(dx);
1408  }
1409  return fOrdered;
1410 }
1411 ///////////////////////////////////////////////////////////////////////////
1412 TObjArray* AliEvent::SortDevices(TObjArray* hits,Int_t idx,Int_t mode,Int_t mcal)
1413 {
1414 // Order the references to the various devices based on hit signals contained
1415 // in the input array. The ordered array is returned as a TObjArray.
1416 // A "hit" represents an abstract object which is derived from AliSignal.
1417 // The user can specify the index of the signal slot to perform the sorting on.
1418 // By default the slotindex will be 1.
1419 // Via the "mode" argument the user can specify ordering in decreasing
1420 // order (mode=-1), ordering in increasing order (mode=1) or no ordering (mode=0).
1421 // The latter option provides a means to quickly obtain an ordered devices list
1422 // when the hits in the array were already ordered by the user. In this case
1423 // the input argument "idx" is irrelevant.
1424 // The default is mode=-1.
1425 // Signals which were declared as "Dead" will be rejected.
1426 // The gain etc... corrected signals will be used in the ordering process as
1427 // specified by the "mcal" argument. The definition of this "mcal" parameter
1428 // corresponds to the signal correction mode described in the GetSignal
1429 // memberfunction of class AliSignal.
1430 // The default is mcal=1 (for backward compatibility reasons).
1431 //
1432
1433  if (!hits) return 0;
1434
1435  TObjArray* ordered=hits;
1436  AliDevice dev;
1437  if (mode) ordered=dev.SortHits(idx,mode,hits,mcal);
1438  
1439  if (!ordered) return 0;
1440
1441  if (fOrdered)
1442  {
1443   fOrdered->Clear();
1444  }
1445  else
1446  {
1447   fOrdered=new TObjArray();
1448  }
1449
1450  Int_t nhits=ordered->GetEntries();
1451  Int_t exist=0;
1452  for (Int_t ih=0; ih<nhits; ih++)
1453  {
1454   AliSignal* sx=(AliSignal*)ordered->At(ih);
1455   if (!sx) continue;
1456   AliDevice* dx=sx->GetDevice();
1457   exist=0;
1458   for (Int_t id=0; id<fOrdered->GetEntries(); id++)
1459   {
1460    AliDevice* odx=(AliDevice*)fOrdered->At(id);
1461    if (dx==odx)
1462    {
1463     exist=1;
1464     break;
1465    }
1466   }
1467   if (!exist) fOrdered->Add(dx);
1468  }
1469  return fOrdered;
1470 }
1471 ///////////////////////////////////////////////////////////////////////////
1472 TObject* AliEvent::Clone(const char* name) const
1473 {
1474 // Make a deep copy of the current object and provide the pointer to the copy.
1475 // This memberfunction enables automatic creation of new objects of the
1476 // correct type depending on the object type, a feature which may be very useful
1477 // for containers when adding objects in case the container owns the objects.
1478 // This feature allows to store either AliEvent objects or objects derived from
1479 // AliEvent via some generic AddEvent memberfunction, provided these derived
1480 // classes also have a proper Clone memberfunction. 
1481
1482  AliEvent* evt=new AliEvent(*this);
1483  if (name)
1484  {
1485   if (strlen(name)) evt->SetName(name);
1486  }
1487  return evt;
1488 }
1489 ///////////////////////////////////////////////////////////////////////////
1490