+
+//____________________________________________________________________________
+void AliCaloTrackReader::GetVertex(Double_t vertex[3], const Int_t evtIndex) const {
+ //Return vertex position for mixed event, recover the vertex in a particular event.
+
+ //Int_t evtIndex = 0; // for single events only one vertex stored in position 0, default value
+ //if (fMixedEvent && clusterID >=0) {
+ // evtIndex=GetMixedEvent()->EventIndexForCaloCluster(clusterID) ;
+ //}
+
+ vertex[0]=fVertex[evtIndex][0]; vertex[1]=fVertex[evtIndex][1]; vertex[2]=fVertex[evtIndex][2];
+
+}
+//
+
+
+//____________________________________________________________________________
+void AliCaloTrackReader::FillVertexArray() {
+
+ //Fill data member with vertex
+ //In case of Mixed event, multiple vertices
+
+ //Delete previous vertex
+ if(fVertex){
+ for (Int_t i = 0; i < fNMixedEvent; i++) {
+ delete [] fVertex[i] ;
+ }
+ delete [] fVertex ;
+ }
+
+ fVertex = new Double_t*[fNMixedEvent] ;
+ for (Int_t i = 0; i < fNMixedEvent; i++) {
+ fVertex[i] = new Double_t[3] ;
+ fVertex[i][0] = 0.0 ;
+ fVertex[i][1] = 0.0 ;
+ fVertex[i][2] = 0.0 ;
+ }
+
+ if (!fMixedEvent) { //Single event analysis
+ if(fDataType!=kMC){
+
+ if(fInputEvent->GetPrimaryVertex()){
+ fInputEvent->GetPrimaryVertex()->GetXYZ(fVertex[0]);
+ }
+ else {
+ printf("AliCaloTrackReader::FillVertexArray() - NULL primary vertex\n");
+ fVertex[0][0]=0.; fVertex[0][1]=0.; fVertex[0][2]=0.;
+ }//Primary vertex pointer do not exist
+
+ } else {//MC read event
+ fVertex[0][0]=0.; fVertex[0][1]=0.; fVertex[0][2]=0.;
+ }
+
+ if(fDebug > 1)
+ printf("AliCaloTrackReader::FillVertexArray() - Single Event Vertex : %f,%f,%f\n",fVertex[0][0],fVertex[0][1],fVertex[0][2]);
+
+ } else { // MultiEvent analysis
+ for (Int_t iev = 0; iev < fNMixedEvent; iev++) {
+ if (fMixedEvent->GetVertexOfEvent(iev))
+ fMixedEvent->GetVertexOfEvent(iev)->GetXYZ(fVertex[iev]);
+ else { // no vertex found !!!!
+ AliWarning("No vertex found");
+ }
+
+ if(fDebug > 1)
+ printf("AliCaloTrackReader::FillVertexArray() - Multi Event %d Vertex : %f,%f,%f\n",iev,fVertex[iev][0],fVertex[iev][1],fVertex[iev][2]);
+
+ }
+ }
+
+}
+
+//____________________________________________________________________________
+void AliCaloTrackReader::FillInputCTS() {
+ //Return array with Central Tracking System (CTS) tracks
+
+ if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputCTS()\n");
+
+ Int_t nTracks = fInputEvent->GetNumberOfTracks() ;
+ Double_t p[3];
+ fTrackMult = 0;
+ Int_t nstatus = 0;
+ for (Int_t itrack = 0; itrack < nTracks; itrack++) {////////////// track loop
+ AliVTrack * track = (AliVTrack*)fInputEvent->GetTrack(itrack) ; // retrieve track from esd
+
+ //Select tracks under certain conditions, TPCrefit, ITSrefit ... check the set bits
+ if (fTrackStatus && !((track->GetStatus() & fTrackStatus) == fTrackStatus))
+ continue ;
+
+ nstatus++;
+
+ if(fDataType==kESD && !fESDtrackCuts->AcceptTrack((AliESDtrack*)track)) continue;
+
+ // Track filter selection
+ //if (fTrackFilter) {
+ // selectInfo = fTrackFilter->IsSelected(esdTrack);
+ // if (!selectInfo && !(esd->GetPrimaryVertex())->UsesTrack(esdTrack->GetID())) continue;
+ // }
+
+ //Count the tracks in eta < 0.9
+ //printf("Eta %f cut %f\n",TMath::Abs(track->Eta()),fTrackMultEtaCut);
+ if(TMath::Abs(track->Eta())< fTrackMultEtaCut) fTrackMult++;
+
+ track->GetPxPyPz(p) ;
+ TLorentzVector momentum(p[0],p[1],p[2],0);
+
+ if(fCTSPtMin < momentum.Pt()){
+
+ if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"CTS"))
+ continue;
+
+ if(fDebug > 2 && momentum.Pt() > 0.1)
+ printf("AliCaloTrackReader::FillInputCTS() - Selected tracks E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
+ momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
+
+ if (fMixedEvent) {
+ track->SetID(itrack);
+ }
+
+ fCTSTracks->Add(track);
+
+ }//Pt and Fiducial cut passed.
+ }// track loop
+
+ //fCTSTracksNormalInputEntries = fCTSTracks->GetEntriesFast();
+ if(fDebug > 1)
+ printf("AliCaloTrackReader::FillInputCTS() - aod entries %d, input tracks %d, pass status %d, multipliticy %d\n", fCTSTracks->GetEntriesFast(), nTracks, nstatus, fTrackMult);//fCTSTracksNormalInputEntries);
+
+ // //If second input event available, add the clusters.
+ // if(fSecondInputAODTree && fSecondInputAODEvent){
+ // nTracks = fSecondInputAODEvent->GetNumberOfTracks() ;
+ // if(fDebug > 1) printf("AliCaloTrackReader::FillInputCTS() - Add second input tracks, entries %d\n", nTracks) ;
+ // for (Int_t itrack = 0; itrack < nTracks; itrack++) {////////////// track loop
+ // AliAODTrack * track = ((AliAODEvent*)fSecondInputAODEvent)->GetTrack(itrack) ; // retrieve track from esd
+ //
+ // //Select tracks under certain conditions, TPCrefit, ITSrefit ... check the set bits
+ // if (fTrackStatus && !((track->GetStatus() & fTrackStatus) == fTrackStatus)) continue ;
+ //
+ // track->GetPxPyPz(p) ;
+ // TLorentzVector momentum(p[0],p[1],p[2],0);
+ //
+ // if(fCTSPtMin < momentum.Pt()){
+ //
+ // if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"CTS")) continue;
+ //
+ // if(fDebug > 2 && momentum.Pt() > 0.1) printf("AliCaloTrackReader::FillInputCTS() - Selected tracks E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
+ // momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
+ //
+ // fCTSTracks->Add(track);
+ //
+ // }//Pt and Fiducial cut passed.
+ // }// track loop
+ //
+ // if(fDebug > 1) printf("AliCaloTrackReader::FillInputCTS() - aod normal entries %d, after second input %d\n", fCTSTracksNormalInputEntries, fCTSTracks->GetEntriesFast());
+ // } //second input loop
+ //
+}
+
+//____________________________________________________________________________
+void AliCaloTrackReader::FillInputEMCALAlgorithm(AliVCluster * clus, const Int_t iclus) {
+ //Fill the EMCAL data in the array, do it
+
+ Int_t vindex = 0 ;
+ if (fMixedEvent)
+ vindex = fMixedEvent->EventIndexForCaloCluster(iclus);
+
+ //Check if the cluster contains any bad channel and if close to calorimeter borders
+ if(GetCaloUtils()->ClusterContainsBadChannel("EMCAL",clus->GetCellsAbsId(), clus->GetNCells()))
+ return;
+ if(!GetCaloUtils()->CheckCellFiducialRegion(clus, (AliVCaloCells*)fInputEvent->GetEMCALCells(), fInputEvent, vindex))
+ return;
+
+ //Remove suspicious clusters
+ if(fRemoveSuspiciousClusters){
+ Int_t ncells = clus->GetNCells();
+ Float_t energy = clus->E();
+ Float_t minNCells = 1+energy/3;//-x*x*0.0033
+ if(ncells < minNCells) {
+ //if(energy > 2)printf("AliCaloTrackReader::FillInputEMCALAlgorithm() - Remove cluster: e %2.2f, Ncells %d, min Ncells %2.1f\n",energy,ncells,minNCells);
+ return;
+ }
+// else {
+// if(energy > 2)printf("AliCaloTrackReader::FillInputEMCALAlgorithm() - Keep cluster: e %2.2f, Ncells %d, min Ncells %2.1f\n",energy,ncells,minNCells);
+// }
+ }
+
+
+ TLorentzVector momentum ;
+
+ clus->GetMomentum(momentum, fVertex[vindex]);
+
+ if(fEMCALPtMin < momentum.Pt()){
+
+ if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"EMCAL"))
+ return;
+
+ if(fDebug > 2 && momentum.E() > 0.1)
+ printf("AliCaloTrackReader::FillInputEMCAL() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
+ momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
+
+ //Float_t pos[3];
+ //clus->GetPosition(pos);
+ //printf("Before Corrections: e %f, x %f, y %f, z %f\n",clus->E(),pos[0],pos[1],pos[2]);
+
+ //Recalibrate the cluster energy
+ if(GetCaloUtils()->IsRecalibrationOn()) {
+ Float_t energy = GetCaloUtils()->RecalibrateClusterEnergy(clus, GetEMCALCells());
+ clus->SetE(energy);
+ //printf("Recalibrated Energy %f\n",clus->E());
+ GetCaloUtils()->RecalculateClusterShowerShapeParameters(GetEMCALCells(),clus);
+ GetCaloUtils()->RecalculateClusterPID(clus);
+
+ }
+
+ //Recalculate distance to bad channels, if new list of bad channels provided
+ GetCaloUtils()->RecalculateClusterDistanceToBadChannel(GetEMCALCells(),clus);
+
+ //Recalculate cluster position
+ if(GetCaloUtils()->IsRecalculationOfClusterPositionOn()){
+ GetCaloUtils()->RecalculateClusterPosition(GetEMCALCells(),clus);
+ //clus->GetPosition(pos);
+ //printf("After Corrections: e %f, x %f, y %f, z %f\n",clus->E(),pos[0],pos[1],pos[2]);
+ }
+
+ //Correct non linearity
+ if(GetCaloUtils()->IsCorrectionOfClusterEnergyOn()){
+ GetCaloUtils()->CorrectClusterEnergy(clus) ;
+ //printf("Linearity Corrected Energy %f\n",clus->E());
+ }
+
+ //In case of MC analysis, to match resolution/calibration in real data
+ if(fSmearClusterEnergy){
+ Float_t energy = clus->E();
+ Float_t rdmEnergy = fRandom.Gaus(energy,fSmearClusterParam[0]*TMath::Sqrt(energy)+
+ fSmearClusterParam[1]*energy+fSmearClusterParam[2]);
+ clus->SetE(rdmEnergy);
+ if(fDebug > 2) printf("\t Energy %f, smeared %f\n", energy, clus->E());
+ }
+
+ if (fMixedEvent)
+ clus->SetID(iclus) ;
+
+ fEMCALClusters->Add(clus);
+ }
+}
+
+//____________________________________________________________________________
+void AliCaloTrackReader::FillInputEMCAL() {
+ //Return array with EMCAL clusters in aod format
+
+ if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputEMCAL()\n");
+
+ //Loop to select clusters in fiducial cut and fill container with aodClusters
+ if(fEMCALClustersListName==""){
+ Int_t nclusters = fInputEvent->GetNumberOfCaloClusters();
+ for (Int_t iclus = 0; iclus < nclusters; iclus++) {
+ AliVCluster * clus = 0;
+ if ( (clus = fInputEvent->GetCaloCluster(iclus)) ) {
+ if (IsEMCALCluster(clus)){
+ FillInputEMCALAlgorithm(clus, iclus);
+ }//EMCAL cluster
+ }// cluster exists
+ }// cluster loop
+
+ //Recalculate track matching
+ if(fDataType==kESD)GetCaloUtils()->RecalculateClusterTrackMatching(fInputEvent);
+
+ }//Get the clusters from the input event
+ else {
+ TClonesArray * clusterList = dynamic_cast<TClonesArray*> (fOutputEvent->FindListObject(fEMCALClustersListName));
+ if(!clusterList){
+ printf("AliCaloTrackReader::FillInputEMCAL() - Wrong name of list with clusters? <%s>\n",fEMCALClustersListName.Data());
+ return;
+ }
+ Int_t nclusters = clusterList->GetEntriesFast();
+ for (Int_t iclus = 0; iclus < nclusters; iclus++) {
+ AliVCluster * clus = dynamic_cast<AliVCluster*> (clusterList->At(iclus));
+ //printf("E %f\n",clus->E());
+ if (clus) FillInputEMCALAlgorithm(clus, iclus);
+ else printf("AliCaloTrackReader::FillInputEMCAL() - Null cluster in list!\n");
+
+ }// cluster loop
+
+ //Recalculate track matching, not necessary, already done in the reclusterization task
+ //GetCaloUtils()->RecalculateClusterTrackMatching(fInputEvent,clusterList);
+
+ }
+
+ //fEMCALClustersNormalInputEntries = fEMCALClusters->GetEntriesFast();
+ if(fDebug > 1) printf("AliCaloTrackReader::FillInputEMCAL() - aod entries %d\n", fEMCALClusters->GetEntriesFast());//fEMCALClustersNormalInputEntries);
+
+ //If second input event available, add the clusters.
+ // if(fSecondInputAODTree && fSecondInputAODEvent){
+ // GetSecondInputAODVertex(v);
+ // nclusters = ((AliAODEvent*)fSecondInputAODEvent)->GetNumberOfCaloClusters();
+ // if(fDebug > 1) printf("AliCaloTrackReader::FillInputEMCAL() - Add second input clusters, entries %d\n", nclusters) ;
+ // for (Int_t iclus = 0; iclus < nclusters; iclus++) {
+ // AliAODCaloCluster * clus = 0;
+ // if ( (clus = ((AliAODEvent*)fSecondInputAODEvent)->GetCaloCluster(iclus)) ) {
+ // if (clus->IsEMCAL()){
+ // TLorentzVector momentum ;
+ // clus->GetMomentum(momentum, v);
+ //
+ // if(fEMCALPtMin < momentum.Pt()){
+ //
+ // if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"EMCAL")) continue;
+ //
+ // if(fDebug > 2 && momentum.E() > 0.1) printf("AliCaloTrackReader::FillInputEMCAL() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
+ // momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
+ // fEMCALClusters->Add(clus);
+ // }//Pt and Fiducial cut passed.
+ // }//EMCAL cluster
+ // }// cluster exists
+ // }// cluster loop
+ //
+ // if(fDebug > 1) printf("AliCaloTrackReader::FillInputEMCAL() - aod normal entries %d, after second input %d\n", fEMCALClustersNormalInputEntries, fEMCALClusters->GetEntriesFast());
+ //
+ // } //second input loop
+}
+
+ //____________________________________________________________________________
+void AliCaloTrackReader::FillInputPHOS() {
+ //Return array with PHOS clusters in aod format
+
+ if(fDebug > 2 ) printf("AliCaloTrackReader::FillInputPHOS()\n");
+
+ //Loop to select clusters in fiducial cut and fill container with aodClusters
+ Int_t nclusters = fInputEvent->GetNumberOfCaloClusters();
+ for (Int_t iclus = 0; iclus < nclusters; iclus++) {
+ AliVCluster * clus = 0;
+ if ( (clus = fInputEvent->GetCaloCluster(iclus)) ) {
+ if (IsPHOSCluster(clus)){
+ //Check if the cluster contains any bad channel and if close to calorimeter borders
+ Int_t vindex = 0 ;
+ if (fMixedEvent)
+ vindex = fMixedEvent->EventIndexForCaloCluster(iclus);
+ if( GetCaloUtils()->ClusterContainsBadChannel("PHOS",clus->GetCellsAbsId(), clus->GetNCells()))
+ continue;
+ if(!GetCaloUtils()->CheckCellFiducialRegion(clus, fInputEvent->GetPHOSCells(), fInputEvent, vindex))
+ continue;
+
+ TLorentzVector momentum ;
+
+ clus->GetMomentum(momentum, fVertex[vindex]);
+
+ if(fPHOSPtMin < momentum.Pt()){
+
+ if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"PHOS"))
+ continue;
+
+ if(fDebug > 2 && momentum.E() > 0.1)
+ printf("AliCaloTrackReader::FillInputPHOS() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
+ momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
+
+ //Recalibrate the cluster energy
+ if(GetCaloUtils()->IsRecalibrationOn()) {
+ Float_t energy = GetCaloUtils()->RecalibrateClusterEnergy(clus, (AliAODCaloCells*)GetPHOSCells());
+ clus->SetE(energy);
+ }
+
+ if (fMixedEvent) {
+ clus->SetID(iclus) ;
+ }
+
+ fPHOSClusters->Add(clus);
+
+ }//Pt and Fiducial cut passed.
+ }//PHOS cluster
+ }//cluster exists
+ }//esd cluster loop
+
+ //fPHOSClustersNormalInputEntries = fPHOSClusters->GetEntriesFast() ;
+ if(fDebug > 1) printf("AliCaloTrackReader::FillInputPHOS() - aod entries %d\n", fPHOSClusters->GetEntriesFast());//fPHOSClustersNormalInputEntries);
+
+ //If second input event available, add the clusters.
+ // if(fSecondInputAODTree && fSecondInputAODEvent){
+ // GetSecondInputAODVertex(v);
+ // nclusters = ((AliAODEvent*)fSecondInputAODEvent)->GetNumberOfCaloClusters();
+ // if(fDebug > 1) printf("AliCaloTrackReader::FillInputPHOS() - Add second input clusters, entries %d\n", nclusters);
+ // for (Int_t iclus = 0; iclus < nclusters; iclus++) {
+ // AliAODCaloCluster * clus = 0;
+ // if ( (clus = ((AliAODEvent*)fSecondInputAODEvent)->GetCaloCluster(iclus)) ) {
+ // if (clus->IsPHOS()){
+ // TLorentzVector momentum ;
+ // clus->GetMomentum(momentum, v);
+ //
+ // if(fPHOSPtMin < momentum.Pt()){
+ //
+ // if(fCheckFidCut && !fFiducialCut->IsInFiducialCut(momentum,"PHOS")) continue;
+ //
+ // if(fDebug > 2 && momentum.E() > 0.1) printf("AliCaloTrackReader::FillInputPHOS() - Selected clusters E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
+ // momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
+ // fPHOSClusters->Add(clus);
+ // }//Pt and Fiducial cut passed.
+ // }//PHOS cluster
+ // }// cluster exists
+ // }// cluster loop
+ // if(fDebug > 1) printf("AliCaloTrackReader::FillInputPHOS() - aod normal entries %d, after second input %d\n", fPHOSClustersNormalInputEntries, fPHOSClusters->GetEntriesFast());
+ // } //second input loop
+
+}
+
+//____________________________________________________________________________
+void AliCaloTrackReader::FillInputEMCALCells() {
+ //Return array with EMCAL cells in aod format
+
+ fEMCALCells = fInputEvent->GetEMCALCells();
+
+}
+
+//____________________________________________________________________________
+void AliCaloTrackReader::FillInputPHOSCells() {
+ //Return array with PHOS cells in aod format
+
+ fPHOSCells = fInputEvent->GetPHOSCells();
+
+}
+
+//____________________________________________________________________________
+void AliCaloTrackReader::FillInputVZERO(){
+ //Fill VZERO information in data member, add all the channels information.
+ AliVVZERO* v0 = fInputEvent->GetVZEROData();
+ //printf("Init V0: ADC (%d,%d), Multiplicity (%d,%d) \n",fV0ADC[0],fV0ADC[1],fV0Mul[0],fV0Mul[1]);
+
+ if (v0)
+ {
+ AliESDVZERO* esdV0 = dynamic_cast<AliESDVZERO*> (v0);
+ for (Int_t i = 0; i < 32; i++)
+ {
+ if(esdV0){//Only available in ESDs
+ fV0ADC[0] += (Int_t)esdV0->GetAdcV0C(i);
+ fV0ADC[1] += (Int_t)esdV0->GetAdcV0A(i);
+ }
+ fV0Mul[0] += (Int_t)v0->GetMultiplicityV0C(i);
+ fV0Mul[1] += (Int_t)v0->GetMultiplicityV0A(i);
+ }
+ if(fDebug > 0)
+ printf("V0: ADC (%d,%d), Multiplicity (%d,%d) \n",fV0ADC[0],fV0ADC[1],fV0Mul[0],fV0Mul[1]);
+ }
+ else
+ {
+ if(fDebug > 0)
+ printf("Cannot retrieve V0 ESD! Run w/ null V0 charges\n ");
+ }
+}
+
+
+//____________________________________________________________________________
+Bool_t AliCaloTrackReader::IsEMCALCluster(AliVCluster* cluster) const {
+ // Check if it is a cluster from EMCAL. For old AODs cluster type has
+ // different number and need to patch here
+
+ if(fDataType==kAOD && fOldAOD)
+ {
+ if (cluster->GetType() == 2) return kTRUE;
+ else return kFALSE;
+ }
+ else
+ {
+ return cluster->IsEMCAL();
+ }
+
+}
+
+//____________________________________________________________________________
+Bool_t AliCaloTrackReader::IsPHOSCluster(AliVCluster * cluster) const {
+ //Check if it is a cluster from PHOS.For old AODs cluster type has
+ // different number and need to patch here
+
+ if(fDataType==kAOD && fOldAOD)
+ {
+ Int_t type = cluster->GetType();
+ if (type == 0 || type == 1) return kTRUE;
+ else return kFALSE;
+ }
+ else
+ {
+ return cluster->IsPHOS();
+ }
+
+}
+
+//____________________________________________________________________________
+Bool_t AliCaloTrackReader::CheckForPrimaryVertex(){
+ //Check if the vertex was well reconstructed, copy from V0Reader of conversion group
+ //Only for ESDs ...
+
+ AliESDEvent * event = dynamic_cast<AliESDEvent*> (fInputEvent);
+ if(!event) return kFALSE;
+
+ if(event->GetPrimaryVertexTracks()->GetNContributors() > 0) {
+ return kTRUE;
+ }
+
+ if(event->GetPrimaryVertexTracks()->GetNContributors() < 1) {
+ // SPD vertex
+ if(event->GetPrimaryVertexSPD()->GetNContributors() > 0) {
+ //cout<<"spd vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
+ return kTRUE;
+
+ }
+ if(event->GetPrimaryVertexSPD()->GetNContributors() < 1) {
+ // cout<<"bad vertex type::"<< event->GetPrimaryVertex()->GetName() << endl;
+ return kFALSE;
+ }
+ }
+
+ return kFALSE;
+
+}
+
+
+