]>
Commit | Line | Data |
---|---|---|
7eb061fb | 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" | |
bbeb9cae | 28 | #include "AliExternalTrackParam.h" |
bbeb9cae | 29 | #include "TVector3.h" |
c79face6 | 30 | #include "AliVVertex.h" |
7eb061fb | 31 | #include <TMath.h> |
bbeb9cae | 32 | #include <TMatrix.h> |
33 | #include <TMatrixD.h> | |
7eb061fb | 34 | |
35 | ClassImp(AliMixedEvent) | |
36 | ||
37 | ||
38 | AliMixedEvent::AliMixedEvent() : | |
39 | AliVEvent(), | |
bbeb9cae | 40 | fEventList(), |
7eb061fb | 41 | fNEvents(0), |
42 | fNumberOfTracks(0), | |
8c755c03 | 43 | fNTracksCumul(0), |
44 | fMeanVertex(0) | |
7eb061fb | 45 | { |
46 | // Default constructor | |
47 | } | |
48 | ||
7eb061fb | 49 | AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) : |
a2813d8b | 50 | AliVEvent(Evnt), |
bbeb9cae | 51 | fEventList(), |
52 | fNEvents(0), | |
a2813d8b | 53 | fNumberOfTracks(0), |
8c755c03 | 54 | fNTracksCumul(0), |
55 | fMeanVertex(0) | |
a2813d8b | 56 | { } // Copy constructor |
7eb061fb | 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 | |
bbeb9cae | 70 | fEventList.AddLast(evt); |
7eb061fb | 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); | |
18476ce9 | 95 | while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;} |
bbeb9cae | 96 | |
7eb061fb | 97 | Int_t irel = i - fNTracksCumul[iEv]; |
98 | AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv)); | |
99 | return (evt->GetTrack(irel)); | |
100 | } | |
101 | ||
bbeb9cae | 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 | } | |
7eb061fb | 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 | } | |
bbeb9cae | 128 | |
b4a900dc | 129 | Bool_t AliMixedEvent::ComputeVtx(TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors){ |
bbeb9cae | 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.}; | |
b4a900dc | 136 | |
bbeb9cae | 137 | |
138 | for(Int_t ivtx = 0; ivtx < nentries; ivtx++){ | |
c79face6 | 139 | AliVVertex *vtx=(AliVVertex*)vertices->UncheckedAt(ivtx); |
bbeb9cae | 140 | Double_t covariance[6]; |
c79face6 | 141 | vtx->GetCovarianceMatrix(covariance); |
bbeb9cae | 142 | Double_t vtxPos[3]; |
143 | vtx->GetXYZ(vtxPos); | |
b4a900dc | 144 | if(TMath::Abs(covariance[0])<1.e-13) { |
145 | return kFALSE; | |
146 | }else{ | |
bbeb9cae | 147 | sum[0]+=vtxPos[0]*(1./covariance[0]); |
148 | sumsigma[0]+=(1./covariance[0]); | |
b4a900dc | 149 | } |
150 | if(TMath::Abs(covariance[2])<1.e-13) { | |
151 | return kFALSE; | |
152 | }else{ | |
bbeb9cae | 153 | sum[1]+=vtxPos[1]*(1./covariance[2]); |
154 | sumsigma[2]+=(1./covariance[2]); | |
b4a900dc | 155 | } |
156 | if(TMath::Abs(covariance[5])<1.e-13) { | |
157 | return kFALSE; | |
158 | }else{ | |
bbeb9cae | 159 | sum[2]+=vtxPos[2]*(1./covariance[5]); |
160 | sumsigma[5]+=(1./covariance[5]); | |
b4a900dc | 161 | } |
162 | if(TMath::Abs(covariance[1])<1.e-13) { | |
163 | sumsigma[1]+=0.; | |
164 | }else{ | |
bbeb9cae | 165 | sumsigma[1]+=(1./covariance[1]); |
b4a900dc | 166 | } |
167 | if(TMath::Abs(covariance[3])<1.e-13) { | |
168 | sumsigma[3]+=0.; | |
169 | }else{ | |
bbeb9cae | 170 | sumsigma[3]+=(1./covariance[3]); |
b4a900dc | 171 | } |
172 | if(TMath::Abs(covariance[4])<1.e-13) { | |
173 | sumsigma[4]+=0.; | |
174 | }else{ | |
bbeb9cae | 175 | sumsigma[4]+=(1./covariance[4]); |
b4a900dc | 176 | } |
177 | ||
178 | nContributors[0]=nContributors[0]+vtx->GetNContributors(); | |
bbeb9cae | 179 | } |
180 | ||
181 | for(Int_t i=0;i<3;i++){ | |
b4a900dc | 182 | if(TMath::Abs(sumsigma[i])<1.e-13) continue; |
bbeb9cae | 183 | pos[i]=sum[i]/sumsigma[i]; |
184 | } | |
185 | for(Int_t i2=0;i2<6;i2++){ | |
b4a900dc | 186 | if(TMath::Abs(sumsigma[i2])<1.e-13) {sig[i2]=0.; continue;} |
bbeb9cae | 187 | sig[i2]=1./sumsigma[i2]; |
188 | } | |
b4a900dc | 189 | return kTRUE; |
bbeb9cae | 190 | } |
191 | ||
a8f9624e | 192 | |
193 | Double_t AliMixedEvent::GetMagneticField() const | |
194 | { | |
195 | // Return magnetic field of the first event in the list | |
196 | if (fEventList.GetEntries() == 0) return -999.; | |
197 | ||
198 | AliVEvent* evt = (AliVEvent*) (fEventList.At(0)); | |
199 | return evt->GetMagneticField(); | |
200 | } |