1 //_________________________________________________________________________
2 // Utility Class for transverse energy studies
3 // Selection class for EMCAL
5 //*-- Authors: Oystein Djuvsland (Bergen)
6 //_________________________________________________________________________
9 #include "AliAnalysisEtSelectorEmcal.h"
10 #include "AliAnalysisEtCuts.h"
11 #include "AliEMCALTrack.h"
12 #include "TParticle.h"
16 AliAnalysisEtSelectorEmcal::AliAnalysisEtSelectorEmcal(AliAnalysisEtCuts* cuts):AliAnalysisEtSelector(cuts)
20 AliAnalysisEtSelectorEmcal::AliAnalysisEtSelectorEmcal():AliAnalysisEtSelector()
24 AliAnalysisEtSelectorEmcal::~AliAnalysisEtSelectorEmcal()
29 void AliAnalysisEtSelectorEmcal::Init()
31 AliAnalysisEtSelector::Init();
34 Int_t AliAnalysisEtSelectorEmcal::Init(const AliESDEvent* event)
37 AliAnalysisEtSelector::Init(event);
38 Printf("Initializing selector for run: %d", event->GetRunNumber());
43 TRefArray* AliAnalysisEtSelectorEmcal::GetClusters()
46 if(!fClusterArray) fClusterArray = new TRefArray;
50 fEvent->GetEMCALClusters(fClusterArray);
54 Printf("Could not initialize cluster array");
59 Bool_t AliAnalysisEtSelectorEmcal::PassMinEnergyCut(const AliESDCaloCluster& cl) const
64 return TMath::Sin(cp.Theta())*cl.E() > fCuts->GetReconstructedEmcalClusterEnergyCut();
67 Bool_t AliAnalysisEtSelectorEmcal::PassMinEnergyCut(const TParticle& p) const
69 return TMath::Sin(p.Theta())*p.Energy() > fCuts->GetReconstructedEmcalClusterEnergyCut();
72 Bool_t AliAnalysisEtSelectorEmcal::PassDistanceToBadChannelCut(const AliESDCaloCluster& ) const
77 Bool_t AliAnalysisEtSelectorEmcal::PassTrackMatchingCut(const AliESDCaloCluster& cluster) const
80 Int_t nTracksMatched = cluster.GetNTracksMatched();
81 if(nTracksMatched == 0){
85 Int_t trackMatchedIndex = cluster.GetTrackMatchedIndex();
86 if(trackMatchedIndex < 0){
89 AliVParticle *track = fEvent->GetTrack(trackMatchedIndex);
90 if(track->Pt()<0.5) return kTRUE;//Track matches below about 500 MeV are mostly random. It takes ~460 MeV to reach the EMCal
92 //Float_t recoE = cluster.E();
95 // //cluster.GetPosition(pos);
96 // Int_t trackMatchIdx = cluster.GetTrackMatchedIndex();
97 // //Double_t distance = 9999.0;
98 // if(trackMatchIdx>-1)
101 // //distance = CalcTrackClusterDistance(pos, &trackMatchIdx);
106 //return distance > fCuts->GetEmcalTrackDistanceCut();
109 Bool_t AliAnalysisEtSelectorEmcal::CutGeometricalAcceptance(const TParticle& part)
111 float myphi = part.Phi();
112 myphi = AliAnalysisEtSelector::ShiftAngle(myphi);
113 return TMath::Abs(part.Eta()) < fCuts->GetGeometryEmcalEtaAccCut()
114 && myphi < fCuts->GetGeometryEmcalPhiAccMaxCut()*TMath::Pi()/180.
115 && myphi > fCuts->GetGeometryEmcalPhiAccMinCut()*TMath::Pi()/180.;
118 Bool_t AliAnalysisEtSelectorEmcal::CutGeometricalAcceptance(const AliVTrack& part)
120 float myphi = part.Phi();
121 myphi = AliAnalysisEtSelector::ShiftAngle(myphi);
122 return TMath::Abs(part.Eta()) < fCuts->GetGeometryEmcalEtaAccCut()
123 && myphi < fCuts->GetGeometryEmcalPhiAccMaxCut()*TMath::Pi()/180.
124 && myphi > fCuts->GetGeometryEmcalPhiAccMinCut()*TMath::Pi()/180.;
127 Bool_t AliAnalysisEtSelectorEmcal::CutGeometricalAcceptance(const AliESDCaloCluster& cluster)
130 cluster.GetPosition(pos);
132 float myphi = cp.Phi();
133 myphi = AliAnalysisEtSelector::ShiftAngle(myphi);
134 return TMath::Abs(cp.Eta()) < fCuts->GetGeometryEmcalEtaAccCut()
135 && myphi < fCuts->GetGeometryEmcalPhiAccMaxCut()*TMath::Pi()/180.
136 && myphi > fCuts->GetGeometryEmcalPhiAccMinCut()*TMath::Pi()/180.;
141 AliAnalysisEtSelectorEmcal::CalcTrackClusterDistance(const Float_t clsPos[3],Int_t *trkMatchId) const
142 { // calculate distance between cluster and closest track
144 Double_t trkPos[3] = {0,0,0};
146 Int_t bestTrkMatchId = -1;
147 Double_t distance = 9999; // init to a big number
150 Double_t distX = 0, distY = 0, distZ = 0;
152 for (Int_t iTrack = 0; iTrack < fEvent->GetNumberOfTracks(); iTrack++) {
153 AliESDtrack *track = static_cast<AliESDtrack*>( fEvent->GetTrack(iTrack) );
155 AliError(Form("ERROR: Could not get track %d", iTrack));
159 // check for approx. eta and phi range before we propagate..
162 AliEMCALTrack emctrack(*track);
163 if (!emctrack.PropagateToGlobal(clsPos[0],clsPos[1],clsPos[2],0.,0.) ) {
166 emctrack.GetXYZ(trkPos);
168 distX = clsPos[0]-trkPos[0];
169 distY = clsPos[1]-trkPos[1];
170 distZ = clsPos[2]-trkPos[2];
171 dist = TMath::Sqrt(distX*distX + distY*distY + distZ*distZ);
173 if (dist < distance) {
175 bestTrkMatchId = iTrack;
179 // printf("CalcTrackClusterDistance: bestTrkMatch %d origTrkMatch %d distance %f\n", bestTrkMatchId, *trkMatchId, distance);
180 *trkMatchId = bestTrkMatchId;
184 UInt_t AliAnalysisEtSelectorEmcal::GetLabel(const AliESDCaloCluster *cluster, AliStack *stack){
185 UInt_t correctLabel = TMath::Abs(cluster->GetLabel());
186 correctLabel = GetFirstMotherNotFromDetectorCover(correctLabel,*stack);
188 //Now we want to see if this particle is really just something that converted in the cover of the detector and if so, override the label
189 // if(!stack){return 0;}
190 // if( correctLabel > 0 && stack->IsSecondaryFromMaterial(correctLabel)){//if this is flagged as a secondary then we look to see where it really came from
191 // TParticle *hitParticle = stack->Particle(correctLabel);
193 // Bool_t partVtxSecondary = (TMath::Sqrt(hitParticle->Vx()*hitParticle->Vx() + hitParticle->Vy()*hitParticle->Vy()) >420);
194 // if(partVtxSecondary){//at this point we have something which converted near the detector. Let's find the mother particle
195 // UInt_t mothIdx = stack->Particle(correctLabel)->GetMother(0);
197 // TParticle *mother = stack->Particle(mothIdx);
199 // if(AliAnalysisEtSelector::CutGeometricalAcceptance(*mother)){//and the mother is in the acceptance
200 // if( !(mother->GetPdgCode()==fgPi0Code)){//some of these are decays that just happen this far out
201 // cout<<"I am declaring that "<<hitParticle->GetName()<<" with a vertex of "<< TMath::Sqrt(hitParticle->Vx()*hitParticle->Vx() + hitParticle->Vy()*hitParticle->Vy()) <<" is actually "<<mother->GetName()<<endl;
202 // cout<<"ID check "<<mothIdx<<" vs "<<mother->GetUniqueID()<<endl;
203 // //so now we know that the particle originated near the cover and within the acceptance of the detector
213 return correctLabel ; // DS: should this line be inside n>0 check, and return another value if n<=0 ?