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 AliVEvent::operator=(vEvnt);
85 AliMixedEvent::~AliMixedEvent()
94 void AliMixedEvent::AddEvent(AliVEvent* evt)
96 // Add a new event to the list
97 fEventList.AddLast(evt);
101 void AliMixedEvent::Init()
103 // Initialize meta information
104 fNEvents = fEventList.GetEntries();
105 fNTracksCumul = new Int_t[fNEvents];
107 fNCaloClustersCumul = new Int_t[fNEvents];
108 fNumberOfCaloClusters = 0;
109 fNumberOfPHOSCells = 0;
110 fNumberOfEMCALCells = 0;
111 fNPHOSCellsCumul = new Int_t[fNEvents];
112 fNEMCALCellsCumul = new Int_t[fNEvents];
114 TIter next(&fEventList);
118 while((event = (AliVEvent*)next())) {
119 fNTracksCumul[iev] = fNumberOfTracks;
120 fNumberOfTracks += (event->GetNumberOfTracks());
121 fNCaloClustersCumul[iev] = fNumberOfCaloClusters;
122 fNumberOfCaloClusters += event->GetNumberOfCaloClusters();
123 fNPHOSCellsCumul[iev] = fNumberOfPHOSCells;
124 if (event->GetPHOSCells())
125 fNumberOfPHOSCells += event->GetPHOSCells()->GetNumberOfCells();
126 fNEMCALCellsCumul[iev] = fNumberOfEMCALCells;
127 if (event->GetEMCALCells())
128 fNumberOfEMCALCells += event->GetEMCALCells()->GetNumberOfCells();
133 Short_t phosPos = 0, emcalPos = 0;
134 Int_t firstPHOSEvent = kTRUE;
135 Int_t firstEMCALEvent = kTRUE;
137 while((event = (AliVEvent*)next())) {
138 AliVCaloCells * phosCells = event->GetPHOSCells() ;
141 //Create the container
144 if(!fPHOSCells) fPHOSCells = phosCells->CopyCaloCells(kFALSE) ;// Just recover the first event type: ESD/AOD
145 else fPHOSCells->DeleteContainer(); //delete the previous container
146 //Now create a new container with the adequate size
147 fPHOSCells->SetType(AliVCaloCells::kPHOSCell) ;
148 fPHOSCells->CreateContainer(fNumberOfPHOSCells) ;
149 firstPHOSEvent=kFALSE;
153 Int_t ncells = event->GetPHOSCells()->GetNumberOfCells() ;
154 for (Int_t icell = 0; icell < ncells; icell++) {
155 fPHOSCells->SetCell(phosPos++, phosCells->GetCellNumber(icell), phosCells->GetAmplitude(icell), phosCells->GetTime(icell)) ;
160 AliVCaloCells * emcalCells = event->GetEMCALCells() ;
163 //Create the container
166 if(!fEMCALCells)fEMCALCells = emcalCells->CopyCaloCells(kFALSE) ; // Just recover the first event type: ESD/AOD
167 else fEMCALCells->DeleteContainer(); // delete the previous container
168 //Now create a new container with the adequate size
169 fEMCALCells->SetType(AliVCaloCells::kEMCALCell) ;
170 fEMCALCells->CreateContainer(fNumberOfEMCALCells) ;
171 firstEMCALEvent=kFALSE;
174 Int_t ncells = emcalCells->GetNumberOfCells() ;
175 for (Int_t icell = 0; icell < ncells; icell++) {
176 fEMCALCells->SetCell(emcalPos++, emcalCells->GetCellNumber(icell), emcalCells->GetAmplitude(icell), emcalCells->GetTime(icell)) ;
183 AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
186 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
187 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
189 Int_t irel = i - fNTracksCumul[iEv];
190 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
191 return (evt->GetTrack(irel));
194 AliVCluster* AliMixedEvent::GetCaloCluster(Int_t i) const
196 // Return calo cluster # i
197 Int_t iEv = TMath::BinarySearch(fNEvents, fNCaloClustersCumul, i);
198 while((iEv < (fNEvents - 1)) && (fNCaloClustersCumul[iEv] == fNCaloClustersCumul[iEv+1])) {iEv++;}
200 Int_t irel = i - fNCaloClustersCumul[iEv];
201 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
202 return (evt->GetCaloCluster(irel));
205 const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const
207 // Return vertex of track # i
208 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
209 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
210 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
211 return (evt->GetPrimaryVertex());
214 const AliVVertex* AliMixedEvent::GetVertexOfEvent(Int_t i) const
216 // Return vertex of event # i
218 AliFatal(Form("%d events in buffer, event %d requested", fNEvents, i)) ;
219 AliVEvent* evt = (AliVEvent*) (fEventList.At(i));
220 return (evt->GetPrimaryVertex());
223 void AliMixedEvent::Reset()
229 fNumberOfCaloClusters = 0;
230 fNumberOfPHOSCells = 0;
231 fNumberOfEMCALCells = 0;
233 delete[] fNTracksCumul;
236 if (fNCaloClustersCumul) {
237 delete[] fNCaloClustersCumul;
238 fNCaloClustersCumul = 0;
240 if (fNPHOSCellsCumul) {
241 delete[] fNPHOSCellsCumul;
242 fNPHOSCellsCumul = 0;
244 if (fNEMCALCellsCumul) {
245 delete[] fNEMCALCellsCumul;
246 fNEMCALCellsCumul = 0;
250 fPHOSCells->DeleteContainer();
253 fEMCALCells->DeleteContainer();
258 Int_t AliMixedEvent::EventIndex(Int_t itrack) const
260 // Return the event index for track #itrack
261 return TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
264 Int_t AliMixedEvent::EventIndexForCaloCluster(Int_t icluster) const
266 // Return the event index for track #itrack
267 return TMath::BinarySearch(fNEvents, fNCaloClustersCumul, icluster);
270 Int_t AliMixedEvent::EventIndexForPHOSCell(Int_t icell) const
272 // Return the event index for track #itrack
273 return TMath::BinarySearch(fNEvents, fNPHOSCellsCumul, icell);
276 Int_t AliMixedEvent::EventIndexForEMCALCell(Int_t icell) const
278 // Return the event index for track #itrack
279 return TMath::BinarySearch(fNEvents, fNEMCALCellsCumul, icell);
282 Bool_t AliMixedEvent::ComputeVtx(TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors){
284 // Calculate the mean vertex psoitions from events in the buffer
286 Int_t nentries = vertices->GetEntriesFast();
287 Double_t sum[3]={0.,0.,0.};
288 Double_t sumsigma[6]={0.,0.,0.,0.,0.,0.};
291 for(Int_t ivtx = 0; ivtx < nentries; ivtx++){
292 AliVVertex *vtx=(AliVVertex*)vertices->UncheckedAt(ivtx);
293 Double_t covariance[6];
294 vtx->GetCovarianceMatrix(covariance);
297 if(TMath::Abs(covariance[0])<1.e-13) {
300 sum[0]+=vtxPos[0]*(1./covariance[0]);
301 sumsigma[0]+=(1./covariance[0]);
303 if(TMath::Abs(covariance[2])<1.e-13) {
306 sum[1]+=vtxPos[1]*(1./covariance[2]);
307 sumsigma[2]+=(1./covariance[2]);
309 if(TMath::Abs(covariance[5])<1.e-13) {
312 sum[2]+=vtxPos[2]*(1./covariance[5]);
313 sumsigma[5]+=(1./covariance[5]);
315 if(TMath::Abs(covariance[1])<1.e-13) {
318 sumsigma[1]+=(1./covariance[1]);
320 if(TMath::Abs(covariance[3])<1.e-13) {
323 sumsigma[3]+=(1./covariance[3]);
325 if(TMath::Abs(covariance[4])<1.e-13) {
328 sumsigma[4]+=(1./covariance[4]);
331 nContributors[0]=nContributors[0]+vtx->GetNContributors();
334 for(Int_t i=0;i<3;i++){
335 if(TMath::Abs(sumsigma[i])<1.e-13) continue;
336 pos[i]=sum[i]/sumsigma[i];
338 for(Int_t i2=0;i2<6;i2++){
339 if(TMath::Abs(sumsigma[i2])<1.e-13) {sig[i2]=0.; continue;}
340 sig[i2]=1./sumsigma[i2];
346 Double_t AliMixedEvent::GetMagneticField() const
348 // Return magnetic field of the first event in the list
349 if (fEventList.GetEntries() == 0) return -999.;
351 AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
352 return evt->GetMagneticField();