1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 //-------------------------------------------------------------------------
27 #include "AliMixedEvent.h"
28 #include "AliExternalTrackParam.h"
30 #include "AliVVertex.h"
35 ClassImp(AliMixedEvent)
38 AliMixedEvent::AliMixedEvent() :
46 // Default constructor
49 AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) :
56 { } // Copy constructor
58 AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
60 AliVEvent::operator=(vEvnt);
67 void AliMixedEvent::AddEvent(AliVEvent* evt)
69 // Add a new event to the list
70 fEventList.AddLast(evt);
74 void AliMixedEvent::Init()
76 // Initialize meta information
77 fNEvents = fEventList.GetEntries();
78 fNTracksCumul = new Int_t[fNEvents];
80 TIter next(&fEventList);
84 while((event = (AliVEvent*)next())) {
85 fNTracksCumul[iev++] = fNumberOfTracks;
86 fNumberOfTracks += (event->GetNumberOfTracks());
91 AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
94 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
95 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
97 Int_t irel = i - fNTracksCumul[iEv];
98 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
99 return (evt->GetTrack(irel));
102 const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const
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());
111 void AliMixedEvent::Reset()
118 delete[] fNTracksCumul;
123 Int_t AliMixedEvent::EventIndex(Int_t itrack)
125 // Return the event index for track #itrack
126 return TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
129 Bool_t AliMixedEvent::ComputeVtx(TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors){
131 // Calculate the mean vertex psoitions from events in the buffer
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.};
138 for(Int_t ivtx = 0; ivtx < nentries; ivtx++){
139 AliVVertex *vtx=(AliVVertex*)vertices->UncheckedAt(ivtx);
140 Double_t covariance[6];
141 vtx->GetCovarianceMatrix(covariance);
144 if(TMath::Abs(covariance[0])<1.e-13) {
147 sum[0]+=vtxPos[0]*(1./covariance[0]);
148 sumsigma[0]+=(1./covariance[0]);
150 if(TMath::Abs(covariance[2])<1.e-13) {
153 sum[1]+=vtxPos[1]*(1./covariance[2]);
154 sumsigma[2]+=(1./covariance[2]);
156 if(TMath::Abs(covariance[5])<1.e-13) {
159 sum[2]+=vtxPos[2]*(1./covariance[5]);
160 sumsigma[5]+=(1./covariance[5]);
162 if(TMath::Abs(covariance[1])<1.e-13) {
165 sumsigma[1]+=(1./covariance[1]);
167 if(TMath::Abs(covariance[3])<1.e-13) {
170 sumsigma[3]+=(1./covariance[3]);
172 if(TMath::Abs(covariance[4])<1.e-13) {
175 sumsigma[4]+=(1./covariance[4]);
178 nContributors[0]=nContributors[0]+vtx->GetNContributors();
181 for(Int_t i=0;i<3;i++){
182 if(TMath::Abs(sumsigma[i])<1.e-13) continue;
183 pos[i]=sum[i]/sumsigma[i];
185 for(Int_t i2=0;i2<6;i2++){
186 if(TMath::Abs(sumsigma[i2])<1.e-13) {sig[i2]=0.; continue;}
187 sig[i2]=1./sumsigma[i2];
193 Double_t AliMixedEvent::GetMagneticField() const
195 // Return magnetic field of the first event in the list
196 if (fEventList.GetEntries() == 0) return -999.;
198 AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
199 return evt->GetMagneticField();