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 #include "AliVCaloCells.h"
38 ClassImp(AliMixedEvent)
41 AliMixedEvent::AliMixedEvent() :
46 fNumberOfCaloClusters(0),
47 fNumberOfPHOSCells(0),
48 fNumberOfEMCALCells(0),
50 fNCaloClustersCumul(0),
57 // Default constructor
60 AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) :
65 fNumberOfCaloClusters(0),
66 fNumberOfPHOSCells(0),
67 fNumberOfEMCALCells(0),
69 fNCaloClustersCumul(0),
75 { } // Copy constructor
77 AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
79 // Assignment operator
81 AliVEvent::operator=(vEvnt);
87 AliMixedEvent::~AliMixedEvent()
96 void AliMixedEvent::AddEvent(AliVEvent* evt)
98 // Add a new event to the list
99 fEventList.AddLast(evt);
103 void AliMixedEvent::Init()
105 // Initialize meta information
106 fNEvents = fEventList.GetEntries();
107 fNTracksCumul = new Int_t[fNEvents];
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];
116 TIter next(&fEventList);
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();
135 Short_t phosPos = 0, emcalPos = 0;
136 Int_t firstPHOSEvent = kTRUE;
137 Int_t firstEMCALEvent = kTRUE;
139 while((event = (AliVEvent*)next())) {
140 AliVCaloCells * phosCells = event->GetPHOSCells() ;
143 //Create the container
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
149 fPHOSCells->SetType(AliVCaloCells::kPHOSCell) ;
150 fPHOSCells->CreateContainer(fNumberOfPHOSCells) ;
151 firstPHOSEvent=kFALSE;
155 Int_t ncells = event->GetPHOSCells()->GetNumberOfCells() ;
156 for (Int_t icell = 0; icell < ncells; icell++) {
157 fPHOSCells->SetCell(phosPos++, phosCells->GetCellNumber(icell), phosCells->GetAmplitude(icell),
158 phosCells->GetTime(icell),phosCells->GetMCLabel(icell),phosCells->GetEFraction(icell)) ;
163 AliVCaloCells * emcalCells = event->GetEMCALCells() ;
166 //Create the container
169 if(!fEMCALCells)fEMCALCells = emcalCells->CopyCaloCells(kFALSE) ; // Just recover the first event type: ESD/AOD
170 else fEMCALCells->DeleteContainer(); // delete the previous container
171 //Now create a new container with the adequate size
172 fEMCALCells->SetType(AliVCaloCells::kEMCALCell) ;
173 fEMCALCells->CreateContainer(fNumberOfEMCALCells) ;
174 firstEMCALEvent=kFALSE;
177 Int_t ncells = emcalCells->GetNumberOfCells() ;
178 for (Int_t icell = 0; icell < ncells; icell++) {
179 fEMCALCells->SetCell(emcalPos++, emcalCells->GetCellNumber(icell), emcalCells->GetAmplitude(icell),
180 emcalCells->GetTime(icell),emcalCells->GetMCLabel(icell),emcalCells->GetEFraction(icell)) ;
187 AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
190 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
191 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
193 Int_t irel = i - fNTracksCumul[iEv];
194 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
195 return (evt->GetTrack(irel));
198 AliVCluster* AliMixedEvent::GetCaloCluster(Int_t i) const
200 // Return calo cluster # i
201 Int_t iEv = TMath::BinarySearch(fNEvents, fNCaloClustersCumul, i);
202 while((iEv < (fNEvents - 1)) && (fNCaloClustersCumul[iEv] == fNCaloClustersCumul[iEv+1])) {iEv++;}
204 Int_t irel = i - fNCaloClustersCumul[iEv];
205 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
206 return (evt->GetCaloCluster(irel));
209 const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const
211 // Return vertex of track # i
212 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
213 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
214 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
215 return (evt->GetPrimaryVertex());
218 const AliVVertex* AliMixedEvent::GetVertexOfEvent(Int_t i) const
220 // Return vertex of event # i
222 AliFatal(Form("%d events in buffer, event %d requested", fNEvents, i)) ;
223 AliVEvent* evt = (AliVEvent*) (fEventList.At(i));
224 return (evt->GetPrimaryVertex());
227 void AliMixedEvent::Reset()
233 fNumberOfCaloClusters = 0;
234 fNumberOfPHOSCells = 0;
235 fNumberOfEMCALCells = 0;
237 delete[] fNTracksCumul;
240 if (fNCaloClustersCumul) {
241 delete[] fNCaloClustersCumul;
242 fNCaloClustersCumul = 0;
244 if (fNPHOSCellsCumul) {
245 delete[] fNPHOSCellsCumul;
246 fNPHOSCellsCumul = 0;
248 if (fNEMCALCellsCumul) {
249 delete[] fNEMCALCellsCumul;
250 fNEMCALCellsCumul = 0;
254 fPHOSCells->DeleteContainer();
257 fEMCALCells->DeleteContainer();
262 Int_t AliMixedEvent::EventIndex(Int_t itrack) const
264 // Return the event index for track #itrack
265 return TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
268 Int_t AliMixedEvent::EventIndexForCaloCluster(Int_t icluster) const
270 // Return the event index for track #itrack
271 return TMath::BinarySearch(fNEvents, fNCaloClustersCumul, icluster);
274 Int_t AliMixedEvent::EventIndexForPHOSCell(Int_t icell) const
276 // Return the event index for track #itrack
277 return TMath::BinarySearch(fNEvents, fNPHOSCellsCumul, icell);
280 Int_t AliMixedEvent::EventIndexForEMCALCell(Int_t icell) const
282 // Return the event index for track #itrack
283 return TMath::BinarySearch(fNEvents, fNEMCALCellsCumul, icell);
286 Bool_t AliMixedEvent::ComputeVtx(const TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors) {
288 // Calculate the mean vertex psoitions from events in the buffer
290 Int_t nentries = vertices->GetEntriesFast();
291 Double_t sum[3]={0.,0.,0.};
292 Double_t sumsigma[6]={0.,0.,0.,0.,0.,0.};
295 for(Int_t ivtx = 0; ivtx < nentries; ivtx++){
296 AliVVertex *vtx=(AliVVertex*)vertices->UncheckedAt(ivtx);
297 Double_t covariance[6];
298 vtx->GetCovarianceMatrix(covariance);
301 if(TMath::Abs(covariance[0])<1.e-13) {
304 sum[0]+=vtxPos[0]*(1./covariance[0]);
305 sumsigma[0]+=(1./covariance[0]);
307 if(TMath::Abs(covariance[2])<1.e-13) {
310 sum[1]+=vtxPos[1]*(1./covariance[2]);
311 sumsigma[2]+=(1./covariance[2]);
313 if(TMath::Abs(covariance[5])<1.e-13) {
316 sum[2]+=vtxPos[2]*(1./covariance[5]);
317 sumsigma[5]+=(1./covariance[5]);
319 if(TMath::Abs(covariance[1])<1.e-13) {
322 sumsigma[1]+=(1./covariance[1]);
324 if(TMath::Abs(covariance[3])<1.e-13) {
327 sumsigma[3]+=(1./covariance[3]);
329 if(TMath::Abs(covariance[4])<1.e-13) {
332 sumsigma[4]+=(1./covariance[4]);
335 nContributors[0]=nContributors[0]+vtx->GetNContributors();
338 for(Int_t i=0;i<3;i++){
339 if(TMath::Abs(sumsigma[i])<1.e-13) continue;
340 pos[i]=sum[i]/sumsigma[i];
342 for(Int_t i2=0;i2<3;i2++){
343 if(TMath::Abs(sumsigma[i2])<1.e-13) {sig[i2]=0.; continue;}
344 sig[i2]=1./sumsigma[i2];
350 Double_t AliMixedEvent::GetMagneticField() const
352 // Return magnetic field of the first event in the list
353 if (fEventList.GetEntries() == 0) return -999.;
355 AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
356 return evt->GetMagneticField();