]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMixedEvent.cxx
Virtual method declared constant.
[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     fNEvents(0),       
36     fNumberOfTracks(0),
37     fNTracksCumul(0)
38 {
39     // Default constructor
40 }
41
42
43 AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) :
44     AliVEvent(Evnt) { } // Copy constructor
45
46 AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
47 { if (this!=&vEvnt) { 
48     AliVEvent::operator=(vEvnt); 
49   }
50   
51   return *this; 
52 }
53
54
55 void AliMixedEvent::AddEvent(AliVEvent* evt)
56 {
57     // Add a new event to the list
58     fEventList.Add(evt);
59 }
60
61
62 void AliMixedEvent::Init()
63 {
64     // Initialize meta information
65     fNEvents = fEventList.GetEntries();
66     fNTracksCumul = new Int_t[fNEvents];
67     fNumberOfTracks = 0;
68     TIter next(&fEventList);
69     AliVEvent* event;
70     Int_t iev = 0;
71     
72     while((event = (AliVEvent*)next())) {
73         fNTracksCumul[iev++] = fNumberOfTracks;
74         fNumberOfTracks += (event->GetNumberOfTracks());
75     }
76 }
77
78
79 AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
80 {
81     // Return track # i
82     Int_t iEv  = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
83
84     Int_t irel = i - fNTracksCumul[iEv];
85     AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
86     return (evt->GetTrack(irel));
87 }
88
89
90 void AliMixedEvent::Reset()
91 {
92     // Reset the event
93     fEventList.Clear();
94     fNEvents = 0;
95     fNumberOfTracks = 0;
96     if (fNTracksCumul) {
97         delete[]  fNTracksCumul;
98         fNTracksCumul = 0;
99     }
100 }
101
102 Int_t AliMixedEvent::EventIndex(Int_t itrack)
103 {
104   // Return the event index for track #itrack
105   return  TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
106 }