]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMixedEvent.cxx
Protection against empty events.
[u/mrichter/AliRoot.git] / STEER / AliMixedEvent.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, 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$ */
17
18
19 //-------------------------------------------------------------------------
20 //                          Class AliMixedEvent
21 // VEvent which is the container of several VEvents 
22 // Use Case: Event Mixing     
23 // Origin: Andreas Morsch, CERN, Andreas.Morsch@cern.ch 
24 //-------------------------------------------------------------------------
25
26
27 #include "AliMixedEvent.h"
28 #include <TMath.h>
29
30 ClassImp(AliMixedEvent)
31
32
33 AliMixedEvent::AliMixedEvent() :
34     AliVEvent(),
35     fEventList(), 
36     fNEvents(0),       
37     fNumberOfTracks(0),
38     fNTracksCumul(0)
39 {
40     // Default constructor
41 }
42
43
44 AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) :
45     AliVEvent(Evnt),
46     fEventList(), 
47     fNEvents(0),       
48     fNumberOfTracks(0),
49     fNTracksCumul(0)
50 { } // Copy constructor
51
52 AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
53 { if (this!=&vEvnt) { 
54     AliVEvent::operator=(vEvnt); 
55   }
56   
57   return *this; 
58 }
59
60
61 void AliMixedEvent::AddEvent(AliVEvent* evt)
62 {
63     // Add a new event to the list
64     fEventList.Add(evt);
65 }
66
67
68 void AliMixedEvent::Init()
69 {
70     // Initialize meta information
71     fNEvents = fEventList.GetEntries();
72     fNTracksCumul = new Int_t[fNEvents];
73     fNumberOfTracks = 0;
74     TIter next(&fEventList);
75     AliVEvent* event;
76     Int_t iev = 0;
77     
78     while((event = (AliVEvent*)next())) {
79         fNTracksCumul[iev++] = fNumberOfTracks;
80         fNumberOfTracks += (event->GetNumberOfTracks());
81     }
82 }
83
84
85 AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
86 {
87     // Return track # i
88     Int_t iEv  = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
89     while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
90     
91     Int_t irel = i - fNTracksCumul[iEv];
92     AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
93     return (evt->GetTrack(irel));
94 }
95
96
97 void AliMixedEvent::Reset()
98 {
99     // Reset the event
100     fEventList.Clear();
101     fNEvents = 0;
102     fNumberOfTracks = 0;
103     if (fNTracksCumul) {
104         delete[]  fNTracksCumul;
105         fNTracksCumul = 0;
106     }
107 }
108
109 Int_t AliMixedEvent::EventIndex(Int_t itrack)
110 {
111   // Return the event index for track #itrack
112   return  TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
113 }