AliRoot Core  3dc7879 (3dc7879)
AliMixedEvent.cxx
Go to the documentation of this file.
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"
28 #include "AliExternalTrackParam.h"
29 #include "TVector3.h"
30 #include "AliVVertex.h"
31 #include <TMath.h>
32 #include <TMatrix.h>
33 #include <TMatrixD.h>
34 #include "AliLog.h"
35 #include "AliVCaloCells.h"
36 
37 
38 ClassImp(AliMixedEvent)
39 
40 
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)
56 {
57  // Default constructor
58 }
59 
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)
75 { } // Copy constructor
76 
78 {
79 // Assignment operator
80  if (this!=&vEvnt) {
81  AliVEvent::operator=(vEvnt);
82 }
83 
84  return *this;
85 }
86 
88 {
89  // dtor
90  Reset();
91  delete fPHOSCells ;
92  delete fEMCALCells ;
93 }
94 
95 
97 {
98  // Add a new event to the list
99  fEventList.AddLast(evt);
100 }
101 
102 
104 {
105  // Initialize meta information
106  fNEvents = fEventList.GetEntries();
107  fNTracksCumul = new Int_t[fNEvents];
108  fNumberOfTracks = 0;
109  fNCaloClustersCumul = new Int_t[fNEvents];
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;
119 
120  while((event = (AliVEvent*)next())) {
122  fNumberOfTracks += (event->GetNumberOfTracks());
124  fNumberOfCaloClusters += event->GetNumberOfCaloClusters();
126  if (event->GetPHOSCells())
129  if (event->GetEMCALCells())
131  iev++ ;
132  }
133 
134  next.Reset() ;
135  Short_t phosPos = 0, emcalPos = 0;
136  Int_t firstPHOSEvent = kTRUE;
137  Int_t firstEMCALEvent = kTRUE;
138 
139  while((event = (AliVEvent*)next())) {
140  AliVCaloCells * phosCells = event->GetPHOSCells() ;
141  if (phosCells) {
142 
143  //Create the container
144  if(firstPHOSEvent)
145  {
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
151  firstPHOSEvent=kFALSE;
152 
153  }//First event
154 
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)) ;
159  }
160 
161  }// phos cells
162 
163  AliVCaloCells * emcalCells = event->GetEMCALCells() ;
164  if (emcalCells) {
165 
166  //Create the container
167  if(firstEMCALEvent)
168  {
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
174  firstEMCALEvent=kFALSE;
175  }//First event
176 
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)) ;
181  }
182  }//EMCAL cells
183  }//while event
184 
185 }
186 
188 {
189  // Return track # i
190  Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
191  while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
192 
193  Int_t irel = i - fNTracksCumul[iEv];
194  AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
195  return (evt->GetTrack(irel));
196 }
197 
199 {
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++;}
203 
204  Int_t irel = i - fNCaloClustersCumul[iEv];
205  AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
206  return (evt->GetCaloCluster(irel));
207 }
208 
210 {
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());
216 }
217 
219 {
220  // Return vertex of event # i
221  if (i > fNEvents)
222  AliFatal(Form("%d events in buffer, event %d requested", fNEvents, i)) ;
223  AliVEvent* evt = (AliVEvent*) (fEventList.At(i));
224  return (evt->GetPrimaryVertex());
225 }
226 
228 {
229  // Reset the event
230  fEventList.Clear();
231  fNEvents = 0;
232  fNumberOfTracks = 0;
234  fNumberOfPHOSCells = 0;
236  if (fNTracksCumul) {
237  delete[] fNTracksCumul;
238  fNTracksCumul = 0;
239  }
240  if (fNCaloClustersCumul) {
241  delete[] fNCaloClustersCumul;
243  }
244  if (fNPHOSCellsCumul) {
245  delete[] fNPHOSCellsCumul;
246  fNPHOSCellsCumul = 0;
247  }
248  if (fNEMCALCellsCumul) {
249  delete[] fNEMCALCellsCumul;
250  fNEMCALCellsCumul = 0;
251  }
252 
253  if (fPHOSCells) {
255  }
256  if (fEMCALCells) {
258  }
259 
260 }
261 
262 Int_t AliMixedEvent::EventIndex(Int_t itrack) const
263 {
264  // Return the event index for track #itrack
265  return TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
266 }
267 
268 Int_t AliMixedEvent::EventIndexForCaloCluster(Int_t icluster) const
269 {
270  // Return the event index for track #itrack
271  return TMath::BinarySearch(fNEvents, fNCaloClustersCumul, icluster);
272 }
273 
274 Int_t AliMixedEvent::EventIndexForPHOSCell(Int_t icell) const
275 {
276  // Return the event index for track #itrack
277  return TMath::BinarySearch(fNEvents, fNPHOSCellsCumul, icell);
278 }
279 
281 {
282  // Return the event index for track #itrack
283  return TMath::BinarySearch(fNEvents, fNEMCALCellsCumul, icell);
284 }
285 
286 Bool_t AliMixedEvent::ComputeVtx(const TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors) {
287 //
288 // Calculate the mean vertex psoitions from events in the buffer
289 
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.};
293 
294 
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);
299  Double_t vtxPos[3];
300  vtx->GetXYZ(vtxPos);
301  if(TMath::Abs(covariance[0])<1.e-13) {
302  return kFALSE;
303  }else{
304  sum[0]+=vtxPos[0]*(1./covariance[0]);
305  sumsigma[0]+=(1./covariance[0]);
306  }
307  if(TMath::Abs(covariance[2])<1.e-13) {
308  return kFALSE;
309  }else{
310  sum[1]+=vtxPos[1]*(1./covariance[2]);
311  sumsigma[2]+=(1./covariance[2]);
312  }
313  if(TMath::Abs(covariance[5])<1.e-13) {
314  return kFALSE;
315  }else{
316  sum[2]+=vtxPos[2]*(1./covariance[5]);
317  sumsigma[5]+=(1./covariance[5]);
318  }
319  if(TMath::Abs(covariance[1])<1.e-13) {
320  sumsigma[1]+=0.;
321  }else{
322  sumsigma[1]+=(1./covariance[1]);
323  }
324  if(TMath::Abs(covariance[3])<1.e-13) {
325  sumsigma[3]+=0.;
326  }else{
327  sumsigma[3]+=(1./covariance[3]);
328  }
329  if(TMath::Abs(covariance[4])<1.e-13) {
330  sumsigma[4]+=0.;
331  }else{
332  sumsigma[4]+=(1./covariance[4]);
333  }
334 
335  nContributors[0]=nContributors[0]+vtx->GetNContributors();
336  }
337 
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];
341  }
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];
345  }
346  return kTRUE;
347 }
348 
349 
351 {
352  // Return magnetic field of the first event in the list
353  if (fEventList.GetEntries() == 0) return -999.;
354 
355  AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
356  return evt->GetMagneticField();
357 }
358 
360 {
361  return AliVEvent::kMixed;
362 }
virtual void Init()
virtual const AliVVertex * GetPrimaryVertex() const
Definition: AliVEvent.h:247
Int_t * fNEMCALCellsCumul
Cumulant.
virtual Int_t EventIndexForPHOSCell(Int_t icell) const
virtual AliVCaloCells * GetPHOSCells() const
Definition: AliVEvent.h:190
Int_t fNEvents
List of Events.
virtual Short_t GetCellNumber(Short_t pos) const =0
Int_t fNumberOfCaloClusters
Total number of tracks.
virtual Bool_t SetCell(Short_t pos, Short_t cellNumber, Double_t amplitude, Double_t time, Int_t mclabel=-1, Double_t efrac=0, Bool_t isHG=kTRUE)=0
virtual Double_t GetMagneticField() const =0
virtual Short_t GetNumberOfCells() const =0
#define TObjArray
AliVCaloCells * fPHOSCells
Cumulant.
const AliVVertex * GetVertexOfEvent(Int_t i) const
Virtual class for calorimeter cell data handling.
Definition: AliVCaloCells.h:19
virtual void AddEvent(AliVEvent *evt)
virtual void GetCovarianceMatrix(Double_t covmatrix[6]) const =0
Int_t * fNCaloClustersCumul
Cumulant.
Virtual class for calorimeter cluster data handling.
Definition: AliVCluster.h:20
virtual void Reset()
const AliVVertex * GetEventVertex(Int_t i) const
virtual ~AliMixedEvent()
virtual AliVCluster * GetCaloCluster(Int_t) const
Definition: AliVEvent.h:185
virtual Int_t GetNContributors() const =0
virtual Int_t GetMCLabel(Short_t pos) const =0
void sum()
AliVCaloCells * fEMCALCells
array ofPHOS cells
virtual AliVParticle * GetTrack(Int_t i) const =0
virtual EDataLayoutType GetDataLayoutType() const
virtual Double_t GetMagneticField() const
virtual Double_t GetAmplitude(Short_t pos) const =0
Int_t * fNPHOSCellsCumul
Cumulant.
Int_t * fNTracksCumul
Total number of EMCAL Cells.
virtual AliVCaloCells * CopyCaloCells(Bool_t all) const =0
virtual void GetXYZ(Double_t position[3]) const =0
virtual Int_t EventIndexForEMCALCell(Int_t icell) const
Int_t fNumberOfTracks
Number of Events.
Int_t fNumberOfPHOSCells
Total number of calo clusters.
AliVEvent & operator=(const AliVEvent &vEvnt)
Definition: AliVEvent.cxx:29
virtual Double_t GetTime(Short_t pos) const =0
#define AliFatal(message)
Definition: AliLog.h:640
virtual Int_t EventIndex(Int_t itrack) const
virtual void SetType(Char_t ttype)=0
EDataLayoutType
Definition: AliVEvent.h:46
virtual AliVParticle * GetTrack(Int_t i) const
virtual void DeleteContainer()=0
virtual Double_t GetEFraction(Short_t pos) const =0
virtual AliVCluster * GetCaloCluster(Int_t i) const
virtual Bool_t ComputeVtx(const TObjArray *vertices, Double_t *pos, Double_t *sig, Int_t *nContributors)
virtual Int_t EventIndexForCaloCluster(Int_t iclu) const
AliMixedEvent & operator=(const AliMixedEvent &vEvnt)
virtual AliVCaloCells * GetEMCALCells() const
Definition: AliVEvent.h:189
Int_t fNumberOfEMCALCells
Total number of PHOS Cells.
virtual void CreateContainer(Short_t nCells)=0