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"
34 #include "AliESDCaloCluster.h"
35 #include "AliAODCaloCluster.h"
36 #include "AliAODCaloCells.h"
37 #include "AliESDCaloCells.h"
39 #include "AliVCaloCells.h"
42 ClassImp(AliMixedEvent)
45 AliMixedEvent::AliMixedEvent() :
50 fNumberOfCaloClusters(0),
51 fNumberOfPHOSCells(0),
52 fNumberOfEMCALCells(0),
54 fNCaloClustersCumul(0),
61 // Default constructor
64 AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) :
69 fNumberOfCaloClusters(0),
70 fNumberOfPHOSCells(0),
71 fNumberOfEMCALCells(0),
73 fNCaloClustersCumul(0),
79 { } // Copy constructor
81 AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
83 AliVEvent::operator=(vEvnt);
89 AliMixedEvent::~AliMixedEvent()
98 void AliMixedEvent::AddEvent(AliVEvent* evt)
100 // Add a new event to the list
101 fEventList.AddLast(evt);
105 void AliMixedEvent::Init()
107 // Initialize meta information
108 fNEvents = fEventList.GetEntries();
109 fNTracksCumul = new Int_t[fNEvents];
111 fNCaloClustersCumul = new Int_t[fNEvents];
112 fNumberOfCaloClusters = 0;
113 fNumberOfPHOSCells = 0;
114 fNumberOfEMCALCells = 0;
115 fNPHOSCellsCumul = new Int_t[fNEvents];
116 fNEMCALCellsCumul = new Int_t[fNEvents];
118 TIter next(&fEventList);
122 while((event = (AliVEvent*)next())) {
123 fNTracksCumul[iev] = fNumberOfTracks;
124 fNumberOfTracks += (event->GetNumberOfTracks());
125 fNCaloClustersCumul[iev] = fNumberOfCaloClusters;
126 fNumberOfCaloClusters += event->GetNumberOfCaloClusters();
127 fNPHOSCellsCumul[iev] = fNumberOfPHOSCells;
128 if (event->GetPHOSCells())
129 fNumberOfPHOSCells += event->GetPHOSCells()->GetNumberOfCells();
130 fNEMCALCellsCumul[iev] = fNumberOfEMCALCells;
131 if (event->GetEMCALCells())
132 fNumberOfEMCALCells += event->GetEMCALCells()->GetNumberOfCells();
136 AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
137 if (dynamic_cast<AliESDCaloCluster*>(evt->GetCaloCluster(0))) { //it's a ESD
138 fPHOSCells = new AliESDCaloCells() ;
139 } else if (dynamic_cast<AliAODCaloCluster*>(evt->GetCaloCluster(0))) { //it's a ESD
140 fPHOSCells = new AliAODCaloCells() ;
142 AliFatal("Unrecognized CaloCluster type (not ESD nor AOD)") ;
145 fPHOSCells->SetType(AliVCaloCells::kPHOSCell) ;
146 fPHOSCells->CreateContainer(fNumberOfPHOSCells) ;
149 AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
150 if (dynamic_cast<AliESDCaloCluster*>(evt->GetCaloCluster(0))) { //it's a ESD
151 fEMCALCells = new AliESDCaloCells() ;
152 } else if (dynamic_cast<AliAODCaloCluster*>(evt->GetCaloCluster(0))) { //it's a ESD
153 fEMCALCells = new AliAODCaloCells() ;
155 AliFatal("Unrecognized CaloCluster type (not ESD nor AOD)") ;
158 fEMCALCells->SetType(AliVCaloCells::kEMCALCell) ;
159 fEMCALCells->CreateContainer(fNumberOfEMCALCells) ;
162 Short_t phosPos = 0, emcalPos = 0;
164 while((event = (AliVEvent*)next())) {
165 if (event->GetPHOSCells()) {
166 Int_t ncells = event->GetPHOSCells()->GetNumberOfCells() ;
167 AliVCaloCells * phosCells = event->GetPHOSCells() ;
168 for (Int_t icell = 0; icell < ncells; icell++) {
169 fPHOSCells->SetCell(phosPos++, phosCells->GetCellNumber(icell), phosCells->GetAmplitude(icell), phosCells->GetTime(icell)) ;
172 if (event->GetEMCALCells()) {
173 Int_t ncells = event->GetEMCALCells()->GetNumberOfCells() ;
174 AliVCaloCells * emcalCells = event->GetEMCALCells() ;
175 for (Int_t icell = 0; icell < ncells; icell++) {
176 fEMCALCells->SetCell(emcalPos++, emcalCells->GetCellNumber(icell), emcalCells->GetAmplitude(icell), emcalCells->GetTime(icell)) ;
182 AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
185 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
186 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
188 Int_t irel = i - fNTracksCumul[iEv];
189 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
190 return (evt->GetTrack(irel));
193 AliVCluster* AliMixedEvent::GetCaloCluster(Int_t i) const
195 // Return calo cluster # i
196 Int_t iEv = TMath::BinarySearch(fNEvents, fNCaloClustersCumul, i);
197 while((iEv < (fNEvents - 1)) && (fNCaloClustersCumul[iEv] == fNCaloClustersCumul[iEv+1])) {iEv++;}
199 Int_t irel = i - fNCaloClustersCumul[iEv];
200 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
201 return (evt->GetCaloCluster(irel));
204 const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const
206 // Return vertex of track # i
207 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
208 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
209 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
210 return (evt->GetPrimaryVertex());
213 const AliVVertex* AliMixedEvent::GetVertexOfEvent(Int_t i) const
215 // Return vertex of event # i
217 AliFatal(Form("%d events in buffer, event %d requested", fNEvents, i)) ;
218 AliVEvent* evt = (AliVEvent*) (fEventList.At(i));
219 return (evt->GetPrimaryVertex());
222 void AliMixedEvent::Reset()
228 fNumberOfCaloClusters = 0;
229 fNumberOfPHOSCells = 0;
230 fNumberOfEMCALCells = 0;
232 delete[] fNTracksCumul;
235 if (fNCaloClustersCumul) {
236 delete[] fNCaloClustersCumul;
237 fNCaloClustersCumul = 0;
239 if (fNPHOSCellsCumul) {
240 delete[] fNPHOSCellsCumul;
241 fNPHOSCellsCumul = 0;
243 if (fNEMCALCellsCumul) {
244 delete[] fNEMCALCellsCumul;
245 fNEMCALCellsCumul = 0;
248 fPHOSCells->DeleteContainer();
251 fEMCALCells->DeleteContainer();
255 Int_t AliMixedEvent::EventIndex(Int_t itrack) const
257 // Return the event index for track #itrack
258 return TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
261 Int_t AliMixedEvent::EventIndexForCaloCluster(Int_t icluster) const
263 // Return the event index for track #itrack
264 return TMath::BinarySearch(fNEvents, fNCaloClustersCumul, icluster);
267 Int_t AliMixedEvent::EventIndexForPHOSCell(Int_t icell) const
269 // Return the event index for track #itrack
270 return TMath::BinarySearch(fNEvents, fNPHOSCellsCumul, icell);
273 Int_t AliMixedEvent::EventIndexForEMCALCell(Int_t icell) const
275 // Return the event index for track #itrack
276 return TMath::BinarySearch(fNEvents, fNEMCALCellsCumul, icell);
279 Bool_t AliMixedEvent::ComputeVtx(TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors){
281 // Calculate the mean vertex psoitions from events in the buffer
283 Int_t nentries = vertices->GetEntriesFast();
284 Double_t sum[3]={0.,0.,0.};
285 Double_t sumsigma[6]={0.,0.,0.,0.,0.,0.};
288 for(Int_t ivtx = 0; ivtx < nentries; ivtx++){
289 AliVVertex *vtx=(AliVVertex*)vertices->UncheckedAt(ivtx);
290 Double_t covariance[6];
291 vtx->GetCovarianceMatrix(covariance);
294 if(TMath::Abs(covariance[0])<1.e-13) {
297 sum[0]+=vtxPos[0]*(1./covariance[0]);
298 sumsigma[0]+=(1./covariance[0]);
300 if(TMath::Abs(covariance[2])<1.e-13) {
303 sum[1]+=vtxPos[1]*(1./covariance[2]);
304 sumsigma[2]+=(1./covariance[2]);
306 if(TMath::Abs(covariance[5])<1.e-13) {
309 sum[2]+=vtxPos[2]*(1./covariance[5]);
310 sumsigma[5]+=(1./covariance[5]);
312 if(TMath::Abs(covariance[1])<1.e-13) {
315 sumsigma[1]+=(1./covariance[1]);
317 if(TMath::Abs(covariance[3])<1.e-13) {
320 sumsigma[3]+=(1./covariance[3]);
322 if(TMath::Abs(covariance[4])<1.e-13) {
325 sumsigma[4]+=(1./covariance[4]);
328 nContributors[0]=nContributors[0]+vtx->GetNContributors();
331 for(Int_t i=0;i<3;i++){
332 if(TMath::Abs(sumsigma[i])<1.e-13) continue;
333 pos[i]=sum[i]/sumsigma[i];
335 for(Int_t i2=0;i2<6;i2++){
336 if(TMath::Abs(sumsigma[i2])<1.e-13) {sig[i2]=0.; continue;}
337 sig[i2]=1./sumsigma[i2];
343 Double_t AliMixedEvent::GetMagneticField() const
345 // Return magnetic field of the first event in the list
346 if (fEventList.GetEntries() == 0) return -999.;
348 AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
349 return evt->GetMagneticField();