]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliMixedEvent.cxx
01dd541b7917eb2cf5477160ab59309ecf68b6c8
[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 "AliESDVertex.h"
29 #include "AliExternalTrackParam.h"
30 #include "AliESDtrack.h"
31 #include "TVector3.h"
32 #include "AliAODVertex.h"
33 #include <TMath.h>
34 #include <TMatrix.h>
35 #include <TMatrixD.h>
36
37 ClassImp(AliMixedEvent)
38
39
40 AliMixedEvent::AliMixedEvent() :
41     AliVEvent(),
42     fEventList(),
43     fNEvents(0),       
44     fNumberOfTracks(0),
45     fNTracksCumul(0)
46 {
47     // Default constructor
48 }
49
50 AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) :
51     AliVEvent(Evnt),
52     fEventList(),
53     fNEvents(0),
54     fNumberOfTracks(0),
55     fNTracksCumul(0)
56 { } // Copy constructor
57
58 AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
59 { if (this!=&vEvnt) { 
60     AliVEvent::operator=(vEvnt); 
61   }
62   
63   return *this; 
64 }
65
66
67 void AliMixedEvent::AddEvent(AliVEvent* evt)
68 {
69     // Add a new event to the list
70     fEventList.AddLast(evt);
71 }
72
73
74 void AliMixedEvent::Init()
75 {
76     // Initialize meta information
77     fNEvents = fEventList.GetEntries();
78     fNTracksCumul = new Int_t[fNEvents];
79     fNumberOfTracks = 0;
80     TIter next(&fEventList);
81     AliVEvent* event;
82     Int_t iev = 0;
83     
84     while((event = (AliVEvent*)next())) {
85         fNTracksCumul[iev++] = fNumberOfTracks;
86         fNumberOfTracks += (event->GetNumberOfTracks());
87     }
88 }
89
90
91 AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
92 {
93     // Return track # i
94     Int_t iEv  = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
95     while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
96
97     Int_t irel = i - fNTracksCumul[iEv];
98     AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
99     return (evt->GetTrack(irel));
100 }
101
102 const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const
103 {
104     // Return track # i
105     Int_t iEv  = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
106     while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
107     AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
108     return (evt->GetPrimaryVertex());
109 }
110
111 void AliMixedEvent::Reset()
112 {
113     // Reset the event
114     fEventList.Clear();
115     fNEvents = 0;
116     fNumberOfTracks = 0;
117     if (fNTracksCumul) {
118         delete[]  fNTracksCumul;
119         fNTracksCumul = 0;
120     }
121 }
122
123 Int_t AliMixedEvent::EventIndex(Int_t itrack)
124 {
125   // Return the event index for track #itrack
126   return  TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
127 }
128
129 void AliMixedEvent::ComputeVtx(TObjArray *vertices, Double_t *pos,Double_t *sig){
130 //
131 // Calculate the mean vertex psoitions from events in the buffer
132  
133     Int_t nentries = vertices->GetEntriesFast();
134     Double_t sum[3]={0.,0.,0.};
135     Double_t sumsigma[6]={0.,0.,0.,0.,0.,0.};
136     
137     for(Int_t ivtx = 0; ivtx < nentries; ivtx++){
138         AliAODVertex *vtx=(AliAODVertex*)vertices->UncheckedAt(ivtx);
139         if(!vtx) return;
140         Double_t covariance[6];
141         vtx->GetCovMatrix(covariance);
142
143         Double_t vtxPos[3];
144         vtx->GetXYZ(vtxPos);
145         if(covariance[0]==0) continue;
146         sum[0]+=vtxPos[0]*(1./covariance[0]);
147         sumsigma[0]+=(1./covariance[0]);
148         if(covariance[2]==0) continue;
149         sum[1]+=vtxPos[1]*(1./covariance[2]);
150         sumsigma[2]+=(1./covariance[2]);
151         if(covariance[5]==0) continue;
152         sum[2]+=vtxPos[2]*(1./covariance[5]);
153         sumsigma[5]+=(1./covariance[5]);
154         if(covariance[1]==0) continue;
155         sumsigma[1]+=(1./covariance[1]);
156         if(covariance[3]==0) continue;
157         sumsigma[3]+=(1./covariance[3]);
158         if(covariance[4]==0) continue;
159         sumsigma[4]+=(1./covariance[4]);
160     }
161     
162     for(Int_t i=0;i<3;i++){
163         if(sumsigma[i]==0) continue;
164         pos[i]=sum[i]/sumsigma[i];
165     }
166     for(Int_t i2=0;i2<6;i2++){
167         if(sumsigma[i2]==0) {sig[i2]=0.; continue;}
168         sig[i2]=1./sumsigma[i2];
169     }
170     return;
171 }
172