]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEERBase/AliMixedEvent.cxx
Fix in the last caall to CleanOwnPrimaryVertex
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliMixedEvent.cxx
CommitLineData
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>
c8fe2783 34#include "AliLog.h"
35#include "AliVCaloCells.h"
36
7eb061fb 37
38ClassImp(AliMixedEvent)
39
40
41AliMixedEvent::AliMixedEvent() :
c8fe2783 42 AliVEvent(),
43 fEventList(),
44 fNEvents(0),
45 fNumberOfTracks(0),
46 fNumberOfCaloClusters(0),
47 fNumberOfPHOSCells(0),
48 fNumberOfEMCALCells(0),
49 fNTracksCumul(0),
50 fNCaloClustersCumul(0),
51 fNPHOSCellsCumul(0),
52 fNEMCALCellsCumul(0),
53 fPHOSCells(NULL),
54 fEMCALCells(NULL),
55 fMeanVertex(0)
7eb061fb 56{
57 // Default constructor
58}
59
7eb061fb 60AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) :
c8fe2783 61 AliVEvent(Evnt),
62 fEventList(),
63 fNEvents(0),
64 fNumberOfTracks(0),
65 fNumberOfCaloClusters(0),
66 fNumberOfPHOSCells(0),
67 fNumberOfEMCALCells(0),
68 fNTracksCumul(0),
69 fNCaloClustersCumul(0),
70 fNPHOSCellsCumul(0),
71 fNEMCALCellsCumul(0),
72 fPHOSCells(NULL),
73 fEMCALCells(NULL),
74 fMeanVertex(0)
a2813d8b 75{ } // Copy constructor
7eb061fb 76
77AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
aa7e002c 78{
79// Assignment operator
80 if (this!=&vEvnt) {
7eb061fb 81 AliVEvent::operator=(vEvnt);
aa7e002c 82}
7eb061fb 83
84 return *this;
85}
86
c8fe2783 87AliMixedEvent::~AliMixedEvent()
88{
89 // dtor
90 Reset();
91 delete fPHOSCells ;
92 delete fEMCALCells ;
93}
94
7eb061fb 95
96void AliMixedEvent::AddEvent(AliVEvent* evt)
97{
98 // Add a new event to the list
bbeb9cae 99 fEventList.AddLast(evt);
7eb061fb 100}
101
102
103void AliMixedEvent::Init()
104{
105 // Initialize meta information
c8fe2783 106 fNEvents = fEventList.GetEntries();
107 fNTracksCumul = new Int_t[fNEvents];
108 fNumberOfTracks = 0;
109 fNCaloClustersCumul = new Int_t[fNEvents];
110 fNumberOfCaloClusters = 0;
111 fNumberOfPHOSCells = 0;
112 fNumberOfEMCALCells = 0;
113 fNPHOSCellsCumul = new Int_t[fNEvents];
114 fNEMCALCellsCumul = new Int_t[fNEvents];
115
116 TIter next(&fEventList);
117 AliVEvent* event;
118 Int_t iev = 0;
7eb061fb 119
c8fe2783 120 while((event = (AliVEvent*)next())) {
121 fNTracksCumul[iev] = fNumberOfTracks;
122 fNumberOfTracks += (event->GetNumberOfTracks());
123 fNCaloClustersCumul[iev] = fNumberOfCaloClusters;
124 fNumberOfCaloClusters += event->GetNumberOfCaloClusters();
125 fNPHOSCellsCumul[iev] = fNumberOfPHOSCells;
126 if (event->GetPHOSCells())
127 fNumberOfPHOSCells += event->GetPHOSCells()->GetNumberOfCells();
128 fNEMCALCellsCumul[iev] = fNumberOfEMCALCells;
129 if (event->GetEMCALCells())
130 fNumberOfEMCALCells += event->GetEMCALCells()->GetNumberOfCells();
131 iev++ ;
132 }
7eb061fb 133
c8fe2783 134 next.Reset() ;
135 Short_t phosPos = 0, emcalPos = 0;
a02655c6 136 Int_t firstPHOSEvent = kTRUE;
137 Int_t firstEMCALEvent = kTRUE;
138
c8fe2783 139 while((event = (AliVEvent*)next())) {
ecff8f07 140 AliVCaloCells * phosCells = event->GetPHOSCells() ;
141 if (phosCells) {
a02655c6 142
143 //Create the container
144 if(firstPHOSEvent)
145 {
ecff8f07 146 if(!fPHOSCells) fPHOSCells = phosCells->CopyCaloCells(kFALSE) ;// Just recover the first event type: ESD/AOD
147 else fPHOSCells->DeleteContainer(); //delete the previous container
148 //Now create a new container with the adequate size
a02655c6 149 fPHOSCells->SetType(AliVCaloCells::kPHOSCell) ;
150 fPHOSCells->CreateContainer(fNumberOfPHOSCells) ;
a02655c6 151 firstPHOSEvent=kFALSE;
ecff8f07 152
153 }//First event
154
155 Int_t ncells = event->GetPHOSCells()->GetNumberOfCells() ;
156 for (Int_t icell = 0; icell < ncells; icell++) {
a02655c6 157 fPHOSCells->SetCell(phosPos++, phosCells->GetCellNumber(icell), phosCells->GetAmplitude(icell), phosCells->GetTime(icell)) ;
ecff8f07 158 }
159
160 }// phos cells
161
162 AliVCaloCells * emcalCells = event->GetEMCALCells() ;
163 if (emcalCells) {
a02655c6 164
165 //Create the container
166 if(firstEMCALEvent)
167 {
ecff8f07 168 if(!fEMCALCells)fEMCALCells = emcalCells->CopyCaloCells(kFALSE) ; // Just recover the first event type: ESD/AOD
169 else fEMCALCells->DeleteContainer(); // delete the previous container
170 //Now create a new container with the adequate size
a02655c6 171 fEMCALCells->SetType(AliVCaloCells::kEMCALCell) ;
172 fEMCALCells->CreateContainer(fNumberOfEMCALCells) ;
a02655c6 173 firstEMCALEvent=kFALSE;
ecff8f07 174 }//First event
175
176 Int_t ncells = emcalCells->GetNumberOfCells() ;
177 for (Int_t icell = 0; icell < ncells; icell++) {
a02655c6 178 fEMCALCells->SetCell(emcalPos++, emcalCells->GetCellNumber(icell), emcalCells->GetAmplitude(icell), emcalCells->GetTime(icell)) ;
ecff8f07 179 }
180 }//EMCAL cells
181 }//while event
182
c8fe2783 183}
7eb061fb 184
185AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
186{
187 // Return track # i
188 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
18476ce9 189 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
bbeb9cae 190
7eb061fb 191 Int_t irel = i - fNTracksCumul[iEv];
192 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
193 return (evt->GetTrack(irel));
194}
195
c8fe2783 196AliVCluster* AliMixedEvent::GetCaloCluster(Int_t i) const
197{
198 // Return calo cluster # i
199 Int_t iEv = TMath::BinarySearch(fNEvents, fNCaloClustersCumul, i);
200 while((iEv < (fNEvents - 1)) && (fNCaloClustersCumul[iEv] == fNCaloClustersCumul[iEv+1])) {iEv++;}
201
202 Int_t irel = i - fNCaloClustersCumul[iEv];
203 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
204 return (evt->GetCaloCluster(irel));
205}
206
bbeb9cae 207const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const
208{
c8fe2783 209 // Return vertex of track # i
bbeb9cae 210 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
211 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
212 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
213 return (evt->GetPrimaryVertex());
214}
7eb061fb 215
c8fe2783 216const AliVVertex* AliMixedEvent::GetVertexOfEvent(Int_t i) const
217{
218 // Return vertex of event # i
219 if (i > fNEvents)
220 AliFatal(Form("%d events in buffer, event %d requested", fNEvents, i)) ;
221 AliVEvent* evt = (AliVEvent*) (fEventList.At(i));
222 return (evt->GetPrimaryVertex());
223}
224
7eb061fb 225void AliMixedEvent::Reset()
226{
227 // Reset the event
c8fe2783 228 fEventList.Clear();
229 fNEvents = 0;
230 fNumberOfTracks = 0;
231 fNumberOfCaloClusters = 0;
232 fNumberOfPHOSCells = 0;
233 fNumberOfEMCALCells = 0;
234 if (fNTracksCumul) {
235 delete[] fNTracksCumul;
236 fNTracksCumul = 0;
237 }
238 if (fNCaloClustersCumul) {
239 delete[] fNCaloClustersCumul;
240 fNCaloClustersCumul = 0;
241 }
242 if (fNPHOSCellsCumul) {
243 delete[] fNPHOSCellsCumul;
244 fNPHOSCellsCumul = 0;
245 }
246 if (fNEMCALCellsCumul) {
247 delete[] fNEMCALCellsCumul;
248 fNEMCALCellsCumul = 0;
249 }
ecff8f07 250
251 if (fPHOSCells) {
252 fPHOSCells->DeleteContainer();
253 }
254 if (fEMCALCells) {
255 fEMCALCells->DeleteContainer();
256 }
257
7eb061fb 258}
259
c8fe2783 260Int_t AliMixedEvent::EventIndex(Int_t itrack) const
7eb061fb 261{
262 // Return the event index for track #itrack
263 return TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
264}
bbeb9cae 265
c8fe2783 266Int_t AliMixedEvent::EventIndexForCaloCluster(Int_t icluster) const
267{
268 // Return the event index for track #itrack
269 return TMath::BinarySearch(fNEvents, fNCaloClustersCumul, icluster);
270}
271
272Int_t AliMixedEvent::EventIndexForPHOSCell(Int_t icell) const
273{
274 // Return the event index for track #itrack
275 return TMath::BinarySearch(fNEvents, fNPHOSCellsCumul, icell);
276}
277
278Int_t AliMixedEvent::EventIndexForEMCALCell(Int_t icell) const
279{
280 // Return the event index for track #itrack
281 return TMath::BinarySearch(fNEvents, fNEMCALCellsCumul, icell);
282}
283
aa7e002c 284Bool_t AliMixedEvent::ComputeVtx(const TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors) {
bbeb9cae 285//
286// Calculate the mean vertex psoitions from events in the buffer
287
288 Int_t nentries = vertices->GetEntriesFast();
289 Double_t sum[3]={0.,0.,0.};
290 Double_t sumsigma[6]={0.,0.,0.,0.,0.,0.};
b4a900dc 291
bbeb9cae 292
293 for(Int_t ivtx = 0; ivtx < nentries; ivtx++){
c79face6 294 AliVVertex *vtx=(AliVVertex*)vertices->UncheckedAt(ivtx);
bbeb9cae 295 Double_t covariance[6];
c79face6 296 vtx->GetCovarianceMatrix(covariance);
bbeb9cae 297 Double_t vtxPos[3];
298 vtx->GetXYZ(vtxPos);
b4a900dc 299 if(TMath::Abs(covariance[0])<1.e-13) {
300 return kFALSE;
301 }else{
bbeb9cae 302 sum[0]+=vtxPos[0]*(1./covariance[0]);
303 sumsigma[0]+=(1./covariance[0]);
b4a900dc 304 }
305 if(TMath::Abs(covariance[2])<1.e-13) {
306 return kFALSE;
307 }else{
bbeb9cae 308 sum[1]+=vtxPos[1]*(1./covariance[2]);
309 sumsigma[2]+=(1./covariance[2]);
b4a900dc 310 }
311 if(TMath::Abs(covariance[5])<1.e-13) {
312 return kFALSE;
313 }else{
bbeb9cae 314 sum[2]+=vtxPos[2]*(1./covariance[5]);
315 sumsigma[5]+=(1./covariance[5]);
b4a900dc 316 }
317 if(TMath::Abs(covariance[1])<1.e-13) {
318 sumsigma[1]+=0.;
319 }else{
bbeb9cae 320 sumsigma[1]+=(1./covariance[1]);
b4a900dc 321 }
322 if(TMath::Abs(covariance[3])<1.e-13) {
323 sumsigma[3]+=0.;
324 }else{
bbeb9cae 325 sumsigma[3]+=(1./covariance[3]);
b4a900dc 326 }
327 if(TMath::Abs(covariance[4])<1.e-13) {
328 sumsigma[4]+=0.;
329 }else{
bbeb9cae 330 sumsigma[4]+=(1./covariance[4]);
b4a900dc 331 }
332
333 nContributors[0]=nContributors[0]+vtx->GetNContributors();
bbeb9cae 334 }
335
336 for(Int_t i=0;i<3;i++){
b4a900dc 337 if(TMath::Abs(sumsigma[i])<1.e-13) continue;
bbeb9cae 338 pos[i]=sum[i]/sumsigma[i];
339 }
531cd64c 340 for(Int_t i2=0;i2<3;i2++){
b4a900dc 341 if(TMath::Abs(sumsigma[i2])<1.e-13) {sig[i2]=0.; continue;}
bbeb9cae 342 sig[i2]=1./sumsigma[i2];
343 }
b4a900dc 344 return kTRUE;
bbeb9cae 345}
346
a8f9624e 347
348Double_t AliMixedEvent::GetMagneticField() const
349{
350 // Return magnetic field of the first event in the list
351 if (fEventList.GetEntries() == 0) return -999.;
352
353 AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
354 return evt->GetMagneticField();
355}