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 if (event->GetPHOSCells()) {
140 //Create the container
143 fPHOSCells = event->GetPHOSCells() ;// Just recover the pointer of the type ESD or AOD
145 //Get the arrays and put them in a temporary array
146 Int_t ncells = fPHOSCells->GetNumberOfCells() ;
147 Short_t *cellNumber = new Short_t [ncells];
148 Double32_t *amplitude = new Double32_t[ncells];
149 Double32_t *time = new Double32_t[ncells];
150 for (Int_t icell = 0; icell < ncells; icell++) {
151 cellNumber[icell] = fPHOSCells->GetCellNumber(icell);
152 amplitude [icell] = fPHOSCells->GetAmplitude(icell);
153 time [icell] = fPHOSCells->GetTime(icell) ;
156 //Now clean the event and enlarge the arrays
157 fPHOSCells->DeleteContainer(); // Delete the arrays set for the first event we need a larger array
158 fPHOSCells->SetType(AliVCaloCells::kPHOSCell) ;
159 fPHOSCells->CreateContainer(fNumberOfPHOSCells) ;
161 //Put back the contents of the first event to the enlarged array
162 for (Int_t icell = 0; icell < ncells; icell++) {
163 fPHOSCells->SetCell(phosPos++, cellNumber[icell], amplitude[icell], time[icell]) ;
166 delete [] cellNumber ;
167 delete [] amplitude ;
170 firstPHOSEvent=kFALSE;
172 else // Add the rest of the events
174 Int_t ncells = event->GetPHOSCells()->GetNumberOfCells() ;
175 AliVCaloCells * phosCells = event->GetPHOSCells() ;
176 for (Int_t icell = 0; icell < ncells; icell++) {
177 fPHOSCells->SetCell(phosPos++, phosCells->GetCellNumber(icell), phosCells->GetAmplitude(icell), phosCells->GetTime(icell)) ;
181 if (event->GetEMCALCells()) {
183 //Create the container
186 fEMCALCells = event->GetEMCALCells() ; // Just recover the pointer of the type ESD or AOD
188 //Get the arrays and put them in a temporary array
189 Int_t ncells = fEMCALCells->GetNumberOfCells() ;
190 Short_t *cellNumber = new Short_t [ncells];
191 Double32_t *amplitude = new Double32_t[ncells];
192 Double32_t *time = new Double32_t[ncells];
193 for (Int_t icell = 0; icell < ncells; icell++) {
194 cellNumber[icell] = fEMCALCells->GetCellNumber(icell);
195 amplitude [icell] = fEMCALCells->GetAmplitude(icell);
196 time [icell] = fEMCALCells->GetTime(icell) ;
199 //Now clean the event and enlarge the arrays
200 fEMCALCells->DeleteContainer(); // Delete the arrays set for the first event we need a larger array
201 fEMCALCells->SetType(AliVCaloCells::kEMCALCell) ;
202 fEMCALCells->CreateContainer(fNumberOfEMCALCells) ;
204 //Put back the contents of the first event to the enlarged array
205 for (Int_t icell = 0; icell < ncells; icell++) {
206 fEMCALCells->SetCell(emcalPos++, cellNumber[icell], amplitude[icell], time[icell]) ;
209 delete [] cellNumber ;
210 delete [] amplitude ;
213 firstEMCALEvent=kFALSE;
215 else // Add the rest of the events
217 Int_t ncells = event->GetEMCALCells()->GetNumberOfCells() ;
218 AliVCaloCells * emcalCells = event->GetEMCALCells() ;
219 for (Int_t icell = 0; icell < ncells; icell++) {
220 fEMCALCells->SetCell(emcalPos++, emcalCells->GetCellNumber(icell), emcalCells->GetAmplitude(icell), emcalCells->GetTime(icell)) ;
227 AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
230 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
231 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
233 Int_t irel = i - fNTracksCumul[iEv];
234 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
235 return (evt->GetTrack(irel));
238 AliVCluster* AliMixedEvent::GetCaloCluster(Int_t i) const
240 // Return calo cluster # i
241 Int_t iEv = TMath::BinarySearch(fNEvents, fNCaloClustersCumul, i);
242 while((iEv < (fNEvents - 1)) && (fNCaloClustersCumul[iEv] == fNCaloClustersCumul[iEv+1])) {iEv++;}
244 Int_t irel = i - fNCaloClustersCumul[iEv];
245 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
246 return (evt->GetCaloCluster(irel));
249 const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const
251 // Return vertex of track # i
252 Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
253 while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
254 AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
255 return (evt->GetPrimaryVertex());
258 const AliVVertex* AliMixedEvent::GetVertexOfEvent(Int_t i) const
260 // Return vertex of event # i
262 AliFatal(Form("%d events in buffer, event %d requested", fNEvents, i)) ;
263 AliVEvent* evt = (AliVEvent*) (fEventList.At(i));
264 return (evt->GetPrimaryVertex());
267 void AliMixedEvent::Reset()
273 fNumberOfCaloClusters = 0;
274 fNumberOfPHOSCells = 0;
275 fNumberOfEMCALCells = 0;
277 delete[] fNTracksCumul;
280 if (fNCaloClustersCumul) {
281 delete[] fNCaloClustersCumul;
282 fNCaloClustersCumul = 0;
284 if (fNPHOSCellsCumul) {
285 delete[] fNPHOSCellsCumul;
286 fNPHOSCellsCumul = 0;
288 if (fNEMCALCellsCumul) {
289 delete[] fNEMCALCellsCumul;
290 fNEMCALCellsCumul = 0;
293 fPHOSCells->DeleteContainer();
296 fEMCALCells->DeleteContainer();
300 Int_t AliMixedEvent::EventIndex(Int_t itrack) const
302 // Return the event index for track #itrack
303 return TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
306 Int_t AliMixedEvent::EventIndexForCaloCluster(Int_t icluster) const
308 // Return the event index for track #itrack
309 return TMath::BinarySearch(fNEvents, fNCaloClustersCumul, icluster);
312 Int_t AliMixedEvent::EventIndexForPHOSCell(Int_t icell) const
314 // Return the event index for track #itrack
315 return TMath::BinarySearch(fNEvents, fNPHOSCellsCumul, icell);
318 Int_t AliMixedEvent::EventIndexForEMCALCell(Int_t icell) const
320 // Return the event index for track #itrack
321 return TMath::BinarySearch(fNEvents, fNEMCALCellsCumul, icell);
324 Bool_t AliMixedEvent::ComputeVtx(TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors){
326 // Calculate the mean vertex psoitions from events in the buffer
328 Int_t nentries = vertices->GetEntriesFast();
329 Double_t sum[3]={0.,0.,0.};
330 Double_t sumsigma[6]={0.,0.,0.,0.,0.,0.};
333 for(Int_t ivtx = 0; ivtx < nentries; ivtx++){
334 AliVVertex *vtx=(AliVVertex*)vertices->UncheckedAt(ivtx);
335 Double_t covariance[6];
336 vtx->GetCovarianceMatrix(covariance);
339 if(TMath::Abs(covariance[0])<1.e-13) {
342 sum[0]+=vtxPos[0]*(1./covariance[0]);
343 sumsigma[0]+=(1./covariance[0]);
345 if(TMath::Abs(covariance[2])<1.e-13) {
348 sum[1]+=vtxPos[1]*(1./covariance[2]);
349 sumsigma[2]+=(1./covariance[2]);
351 if(TMath::Abs(covariance[5])<1.e-13) {
354 sum[2]+=vtxPos[2]*(1./covariance[5]);
355 sumsigma[5]+=(1./covariance[5]);
357 if(TMath::Abs(covariance[1])<1.e-13) {
360 sumsigma[1]+=(1./covariance[1]);
362 if(TMath::Abs(covariance[3])<1.e-13) {
365 sumsigma[3]+=(1./covariance[3]);
367 if(TMath::Abs(covariance[4])<1.e-13) {
370 sumsigma[4]+=(1./covariance[4]);
373 nContributors[0]=nContributors[0]+vtx->GetNContributors();
376 for(Int_t i=0;i<3;i++){
377 if(TMath::Abs(sumsigma[i])<1.e-13) continue;
378 pos[i]=sum[i]/sumsigma[i];
380 for(Int_t i2=0;i2<6;i2++){
381 if(TMath::Abs(sumsigma[i2])<1.e-13) {sig[i2]=0.; continue;}
382 sig[i2]=1./sumsigma[i2];
388 Double_t AliMixedEvent::GetMagneticField() const
390 // Return magnetic field of the first event in the list
391 if (fEventList.GetEntries() == 0) return -999.;
393 AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
394 return evt->GetMagneticField();