Putting momentum cut on tracks to cut
[u/mrichter/AliRoot.git] / PWGLF / totEt / AliAnalysisEtSelectorEmcal.cxx
1 //_________________________________________________________________________
2 //  Utility Class for transverse energy studies
3 //  Selection class for EMCAL
4 //
5 //*-- Authors: Oystein Djuvsland (Bergen)
6 //_________________________________________________________________________
7
8
9 #include "AliAnalysisEtSelectorEmcal.h"
10 #include "AliAnalysisEtCuts.h"
11 #include "AliEMCALTrack.h"
12 #include "TParticle.h"
13
14 AliAnalysisEtSelectorEmcal::AliAnalysisEtSelectorEmcal(AliAnalysisEtCuts* cuts):AliAnalysisEtSelector(cuts)
15 {
16
17 }
18 AliAnalysisEtSelectorEmcal::AliAnalysisEtSelectorEmcal():AliAnalysisEtSelector()
19 {
20 }
21
22 AliAnalysisEtSelectorEmcal::~AliAnalysisEtSelectorEmcal()
23 {
24
25 }
26
27 void AliAnalysisEtSelectorEmcal::Init()
28 {
29     AliAnalysisEtSelector::Init();
30 }
31
32 Int_t AliAnalysisEtSelectorEmcal::Init(const AliESDEvent* event)
33 {   // Init
34
35     AliAnalysisEtSelector::Init(event);
36     Printf("Initializing selector for run: %d", event->GetRunNumber());
37     fInitialized = kTRUE;
38     return 0;
39 }
40
41 TRefArray* AliAnalysisEtSelectorEmcal::GetClusters()
42 {   // Get clusters
43
44     if(!fClusterArray) fClusterArray = new TRefArray;
45
46     if(fClusterArray)
47     {
48         fEvent->GetEMCALClusters(fClusterArray);
49     }
50     else
51     {
52         Printf("Could not initialize cluster array");
53     }
54     return fClusterArray;
55 }
56
57 Bool_t AliAnalysisEtSelectorEmcal::PassMinEnergyCut(const AliESDCaloCluster& cl) const
58 {
59   Float_t pos[3];
60   cl.GetPosition(pos);
61   TVector3 cp(pos);
62   return TMath::Sin(cp.Theta())*cl.E() > fCuts->GetReconstructedEmcalClusterEnergyCut();
63 }
64
65 Bool_t AliAnalysisEtSelectorEmcal::PassMinEnergyCut(const TParticle& p) const
66 {
67   return TMath::Sin(p.Theta())*p.Energy() > fCuts->GetReconstructedEmcalClusterEnergyCut();
68 }
69
70 Bool_t AliAnalysisEtSelectorEmcal::PassDistanceToBadChannelCut(const AliESDCaloCluster& ) const
71 {
72     return kTRUE;
73 }
74
75 Bool_t AliAnalysisEtSelectorEmcal::PassTrackMatchingCut(const AliESDCaloCluster& cluster) const
76 {
77
78   Int_t nTracksMatched = cluster.GetNTracksMatched();
79   if(nTracksMatched == 0){
80     return kTRUE;
81   }
82   
83   Int_t trackMatchedIndex = cluster.GetTrackMatchedIndex();
84   if(trackMatchedIndex < 0){
85     return kTRUE;
86   }
87   AliVParticle *track = fEvent->GetTrack(trackMatchedIndex);
88   if(track->Pt()<0.5) return kTRUE;//Track matches below about 500 MeV are mostly random.  It takes ~460 MeV to reach the EMCal
89
90   //Float_t recoE = cluster.E();
91   //Float_t pos[3];
92
93 //     //cluster.GetPosition(pos);
94 //     Int_t trackMatchIdx = cluster.GetTrackMatchedIndex();
95 //     //Double_t distance = 9999.0;
96 //     if(trackMatchIdx>-1)
97 //     {
98 //       return kTRUE;
99 //       //distance = CalcTrackClusterDistance(pos, &trackMatchIdx);
100 //     }
101
102
103     return kFALSE;
104     //return distance > fCuts->GetEmcalTrackDistanceCut();
105 }
106
107 Bool_t AliAnalysisEtSelectorEmcal::CutGeometricalAcceptance(const TParticle& part) const
108 {
109     return TMath::Abs(part.Eta()) < fCuts->GetGeometryEmcalEtaAccCut()
110            && part.Phi() < fCuts->GetGeometryEmcalPhiAccMaxCut()*TMath::Pi()/180.
111            && part.Phi() > fCuts->GetGeometryEmcalPhiAccMinCut()*TMath::Pi()/180.;
112 }
113
114 Bool_t AliAnalysisEtSelectorEmcal::CutGeometricalAcceptance(const AliVTrack& part) const
115 {
116     return TMath::Abs(part.Eta()) < fCuts->GetGeometryEmcalEtaAccCut()
117            && part.Phi() < fCuts->GetGeometryEmcalPhiAccMaxCut()*TMath::Pi()/180.
118            && part.Phi() > fCuts->GetGeometryEmcalPhiAccMinCut()*TMath::Pi()/180.;
119 }
120
121
122 Double_t
123 AliAnalysisEtSelectorEmcal::CalcTrackClusterDistance(const Float_t clsPos[3],Int_t *trkMatchId) const
124 {   // calculate distance between cluster and closest track
125
126     Double_t trkPos[3] = {0,0,0};
127
128     Int_t bestTrkMatchId = -1;
129     Double_t distance = 9999; // init to a big number
130
131     Double_t dist = 0;
132     Double_t distX = 0, distY = 0, distZ = 0;
133
134     for (Int_t iTrack = 0; iTrack < fEvent->GetNumberOfTracks(); iTrack++) {
135         AliESDtrack *track = static_cast<AliESDtrack*>( fEvent->GetTrack(iTrack) );
136         if (!track) {
137             AliError(Form("ERROR: Could not get track %d", iTrack));
138             continue;
139         }
140
141         // check for approx. eta and phi range before we propagate..
142         // TBD
143
144         AliEMCALTrack emctrack(*track);
145         if (!emctrack.PropagateToGlobal(clsPos[0],clsPos[1],clsPos[2],0.,0.) ) {
146             continue;
147         }
148         emctrack.GetXYZ(trkPos);
149
150         distX = clsPos[0]-trkPos[0];
151         distY = clsPos[1]-trkPos[1];
152         distZ = clsPos[2]-trkPos[2];
153         dist = TMath::Sqrt(distX*distX + distY*distY + distZ*distZ);
154
155         if (dist < distance) {
156             distance = dist;
157             bestTrkMatchId = iTrack;
158         }
159     } // iTrack
160
161     // printf("CalcTrackClusterDistance: bestTrkMatch %d origTrkMatch %d distance %f\n", bestTrkMatchId, *trkMatchId, distance);
162     *trkMatchId = bestTrkMatchId;
163     return distance;
164 }
165
166
167
168
169