X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=STEER%2FAliMixedEvent.cxx;h=6be894f83578b0d611bb34a6aed9b77b5678c5ad;hb=8f16115a61ede20ac71354ccf4a126d81c099942;hp=f9213281b9701d5203a72fd171dfcb72b98e9aaf;hpb=c79face618db0410f202ebf605407a4db5575a3e;p=u%2Fmrichter%2FAliRoot.git diff --git a/STEER/AliMixedEvent.cxx b/STEER/AliMixedEvent.cxx index f9213281b97..6be894f8357 100644 --- a/STEER/AliMixedEvent.cxx +++ b/STEER/AliMixedEvent.cxx @@ -25,36 +25,53 @@ #include "AliMixedEvent.h" -#include "AliESDVertex.h" #include "AliExternalTrackParam.h" -#include "AliESDtrack.h" #include "TVector3.h" #include "AliVVertex.h" #include #include #include +#include "AliLog.h" +#include "AliVCaloCells.h" + ClassImp(AliMixedEvent) AliMixedEvent::AliMixedEvent() : - AliVEvent(), - fEventList(), - fNEvents(0), - fNumberOfTracks(0), - fNTracksCumul(0), - fMeanVertex(0) + AliVEvent(), + fEventList(), + fNEvents(0), + fNumberOfTracks(0), + fNumberOfCaloClusters(0), + fNumberOfPHOSCells(0), + fNumberOfEMCALCells(0), + fNTracksCumul(0), + fNCaloClustersCumul(0), + fNPHOSCellsCumul(0), + fNEMCALCellsCumul(0), + fPHOSCells(NULL), + fEMCALCells(NULL), + fMeanVertex(0) { // Default constructor } AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) : - AliVEvent(Evnt), - fEventList(), - fNEvents(0), - fNumberOfTracks(0), - fNTracksCumul(0), - fMeanVertex(0) + AliVEvent(Evnt), + fEventList(), + fNEvents(0), + fNumberOfTracks(0), + fNumberOfCaloClusters(0), + fNumberOfPHOSCells(0), + fNumberOfEMCALCells(0), + fNTracksCumul(0), + fNCaloClustersCumul(0), + fNPHOSCellsCumul(0), + fNEMCALCellsCumul(0), + fPHOSCells(NULL), + fEMCALCells(NULL), + fMeanVertex(0) { } // Copy constructor AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt) @@ -65,6 +82,14 @@ AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt) return *this; } +AliMixedEvent::~AliMixedEvent() +{ + // dtor + Reset(); + delete fPHOSCells ; + delete fEMCALCells ; +} + void AliMixedEvent::AddEvent(AliVEvent* evt) { @@ -76,19 +101,84 @@ void AliMixedEvent::AddEvent(AliVEvent* evt) void AliMixedEvent::Init() { // Initialize meta information - fNEvents = fEventList.GetEntries(); - fNTracksCumul = new Int_t[fNEvents]; - fNumberOfTracks = 0; - TIter next(&fEventList); - AliVEvent* event; - Int_t iev = 0; + fNEvents = fEventList.GetEntries(); + fNTracksCumul = new Int_t[fNEvents]; + fNumberOfTracks = 0; + fNCaloClustersCumul = new Int_t[fNEvents]; + fNumberOfCaloClusters = 0; + fNumberOfPHOSCells = 0; + fNumberOfEMCALCells = 0; + fNPHOSCellsCumul = new Int_t[fNEvents]; + fNEMCALCellsCumul = new Int_t[fNEvents]; + + TIter next(&fEventList); + AliVEvent* event; + Int_t iev = 0; - while((event = (AliVEvent*)next())) { - fNTracksCumul[iev++] = fNumberOfTracks; - fNumberOfTracks += (event->GetNumberOfTracks()); - } -} + while((event = (AliVEvent*)next())) { + fNTracksCumul[iev] = fNumberOfTracks; + fNumberOfTracks += (event->GetNumberOfTracks()); + fNCaloClustersCumul[iev] = fNumberOfCaloClusters; + fNumberOfCaloClusters += event->GetNumberOfCaloClusters(); + fNPHOSCellsCumul[iev] = fNumberOfPHOSCells; + if (event->GetPHOSCells()) + fNumberOfPHOSCells += event->GetPHOSCells()->GetNumberOfCells(); + fNEMCALCellsCumul[iev] = fNumberOfEMCALCells; + if (event->GetEMCALCells()) + fNumberOfEMCALCells += event->GetEMCALCells()->GetNumberOfCells(); + iev++ ; + } + + next.Reset() ; + Short_t phosPos = 0, emcalPos = 0; + Int_t firstPHOSEvent = kTRUE; + Int_t firstEMCALEvent = kTRUE; + + while((event = (AliVEvent*)next())) { + AliVCaloCells * phosCells = event->GetPHOSCells() ; + if (phosCells) { + + //Create the container + if(firstPHOSEvent) + { + if(!fPHOSCells) fPHOSCells = phosCells->CopyCaloCells(kFALSE) ;// Just recover the first event type: ESD/AOD + else fPHOSCells->DeleteContainer(); //delete the previous container + //Now create a new container with the adequate size + fPHOSCells->SetType(AliVCaloCells::kPHOSCell) ; + fPHOSCells->CreateContainer(fNumberOfPHOSCells) ; + firstPHOSEvent=kFALSE; + }//First event + + Int_t ncells = event->GetPHOSCells()->GetNumberOfCells() ; + for (Int_t icell = 0; icell < ncells; icell++) { + fPHOSCells->SetCell(phosPos++, phosCells->GetCellNumber(icell), phosCells->GetAmplitude(icell), phosCells->GetTime(icell)) ; + } + + }// phos cells + + AliVCaloCells * emcalCells = event->GetEMCALCells() ; + if (emcalCells) { + + //Create the container + if(firstEMCALEvent) + { + if(!fEMCALCells)fEMCALCells = emcalCells->CopyCaloCells(kFALSE) ; // Just recover the first event type: ESD/AOD + else fEMCALCells->DeleteContainer(); // delete the previous container + //Now create a new container with the adequate size + fEMCALCells->SetType(AliVCaloCells::kEMCALCell) ; + fEMCALCells->CreateContainer(fNumberOfEMCALCells) ; + firstEMCALEvent=kFALSE; + }//First event + + Int_t ncells = emcalCells->GetNumberOfCells() ; + for (Int_t icell = 0; icell < ncells; icell++) { + fEMCALCells->SetCell(emcalPos++, emcalCells->GetCellNumber(icell), emcalCells->GetAmplitude(icell), emcalCells->GetTime(icell)) ; + } + }//EMCAL cells + }//while event + +} AliVParticle* AliMixedEvent::GetTrack(Int_t i) const { @@ -101,73 +191,163 @@ AliVParticle* AliMixedEvent::GetTrack(Int_t i) const return (evt->GetTrack(irel)); } +AliVCluster* AliMixedEvent::GetCaloCluster(Int_t i) const +{ + // Return calo cluster # i + Int_t iEv = TMath::BinarySearch(fNEvents, fNCaloClustersCumul, i); + while((iEv < (fNEvents - 1)) && (fNCaloClustersCumul[iEv] == fNCaloClustersCumul[iEv+1])) {iEv++;} + + Int_t irel = i - fNCaloClustersCumul[iEv]; + AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv)); + return (evt->GetCaloCluster(irel)); +} + const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const { - // Return track # i + // Return vertex of track # i Int_t iEv = TMath::BinarySearch(fNEvents, fNTracksCumul, i); while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;} AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv)); return (evt->GetPrimaryVertex()); } +const AliVVertex* AliMixedEvent::GetVertexOfEvent(Int_t i) const +{ + // Return vertex of event # i + if (i > fNEvents) + AliFatal(Form("%d events in buffer, event %d requested", fNEvents, i)) ; + AliVEvent* evt = (AliVEvent*) (fEventList.At(i)); + return (evt->GetPrimaryVertex()); +} + void AliMixedEvent::Reset() { // Reset the event - fEventList.Clear(); - fNEvents = 0; - fNumberOfTracks = 0; - if (fNTracksCumul) { - delete[] fNTracksCumul; - fNTracksCumul = 0; - } + fEventList.Clear(); + fNEvents = 0; + fNumberOfTracks = 0; + fNumberOfCaloClusters = 0; + fNumberOfPHOSCells = 0; + fNumberOfEMCALCells = 0; + if (fNTracksCumul) { + delete[] fNTracksCumul; + fNTracksCumul = 0; + } + if (fNCaloClustersCumul) { + delete[] fNCaloClustersCumul; + fNCaloClustersCumul = 0; + } + if (fNPHOSCellsCumul) { + delete[] fNPHOSCellsCumul; + fNPHOSCellsCumul = 0; + } + if (fNEMCALCellsCumul) { + delete[] fNEMCALCellsCumul; + fNEMCALCellsCumul = 0; + } + + if (fPHOSCells) { + fPHOSCells->DeleteContainer(); + } + if (fEMCALCells) { + fEMCALCells->DeleteContainer(); + } + } -Int_t AliMixedEvent::EventIndex(Int_t itrack) +Int_t AliMixedEvent::EventIndex(Int_t itrack) const { // Return the event index for track #itrack return TMath::BinarySearch(fNEvents, fNTracksCumul, itrack); } -void AliMixedEvent::ComputeVtx(TObjArray *vertices, Double_t *pos,Double_t *sig){ +Int_t AliMixedEvent::EventIndexForCaloCluster(Int_t icluster) const +{ + // Return the event index for track #itrack + return TMath::BinarySearch(fNEvents, fNCaloClustersCumul, icluster); +} + +Int_t AliMixedEvent::EventIndexForPHOSCell(Int_t icell) const +{ + // Return the event index for track #itrack + return TMath::BinarySearch(fNEvents, fNPHOSCellsCumul, icell); +} + +Int_t AliMixedEvent::EventIndexForEMCALCell(Int_t icell) const +{ + // Return the event index for track #itrack + return TMath::BinarySearch(fNEvents, fNEMCALCellsCumul, icell); +} + +Bool_t AliMixedEvent::ComputeVtx(TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors){ // // Calculate the mean vertex psoitions from events in the buffer Int_t nentries = vertices->GetEntriesFast(); Double_t sum[3]={0.,0.,0.}; Double_t sumsigma[6]={0.,0.,0.,0.,0.,0.}; + for(Int_t ivtx = 0; ivtx < nentries; ivtx++){ AliVVertex *vtx=(AliVVertex*)vertices->UncheckedAt(ivtx); - if(!vtx) return; Double_t covariance[6]; vtx->GetCovarianceMatrix(covariance); Double_t vtxPos[3]; vtx->GetXYZ(vtxPos); - if(covariance[0]==0) continue; + if(TMath::Abs(covariance[0])<1.e-13) { + return kFALSE; + }else{ sum[0]+=vtxPos[0]*(1./covariance[0]); sumsigma[0]+=(1./covariance[0]); - if(covariance[2]==0) continue; + } + if(TMath::Abs(covariance[2])<1.e-13) { + return kFALSE; + }else{ sum[1]+=vtxPos[1]*(1./covariance[2]); sumsigma[2]+=(1./covariance[2]); - if(covariance[5]==0) continue; + } + if(TMath::Abs(covariance[5])<1.e-13) { + return kFALSE; + }else{ sum[2]+=vtxPos[2]*(1./covariance[5]); sumsigma[5]+=(1./covariance[5]); - if(covariance[1]==0) continue; + } + if(TMath::Abs(covariance[1])<1.e-13) { + sumsigma[1]+=0.; + }else{ sumsigma[1]+=(1./covariance[1]); - if(covariance[3]==0) continue; + } + if(TMath::Abs(covariance[3])<1.e-13) { + sumsigma[3]+=0.; + }else{ sumsigma[3]+=(1./covariance[3]); - if(covariance[4]==0) continue; + } + if(TMath::Abs(covariance[4])<1.e-13) { + sumsigma[4]+=0.; + }else{ sumsigma[4]+=(1./covariance[4]); + } + + nContributors[0]=nContributors[0]+vtx->GetNContributors(); } for(Int_t i=0;i<3;i++){ - if(sumsigma[i]==0) continue; + if(TMath::Abs(sumsigma[i])<1.e-13) continue; pos[i]=sum[i]/sumsigma[i]; } for(Int_t i2=0;i2<6;i2++){ - if(sumsigma[i2]==0) {sig[i2]=0.; continue;} + if(TMath::Abs(sumsigma[i2])<1.e-13) {sig[i2]=0.; continue;} sig[i2]=1./sumsigma[i2]; } - return; + return kTRUE; } + +Double_t AliMixedEvent::GetMagneticField() const +{ + // Return magnetic field of the first event in the list + if (fEventList.GetEntries() == 0) return -999.; + + AliVEvent* evt = (AliVEvent*) (fEventList.At(0)); + return evt->GetMagneticField(); +}