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