]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/totEt/AliAnalysisEtSelectorEmcal.cxx
Changing secondary definition
[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 #include <iostream>
14 #include "AliStack.h"
15
16 AliAnalysisEtSelectorEmcal::AliAnalysisEtSelectorEmcal(AliAnalysisEtCuts* cuts):AliAnalysisEtSelector(cuts)
17 {
18
19 }
20 AliAnalysisEtSelectorEmcal::AliAnalysisEtSelectorEmcal():AliAnalysisEtSelector()
21 {
22 }
23
24 AliAnalysisEtSelectorEmcal::~AliAnalysisEtSelectorEmcal()
25 {
26
27 }
28
29 void AliAnalysisEtSelectorEmcal::Init()
30 {
31     AliAnalysisEtSelector::Init();
32 }
33
34 Int_t AliAnalysisEtSelectorEmcal::Init(const AliESDEvent* event)
35 {   // Init
36
37     AliAnalysisEtSelector::Init(event);
38     Printf("Initializing selector for run: %d", event->GetRunNumber());
39     fInitialized = kTRUE;
40     return 0;
41 }
42
43 TRefArray* AliAnalysisEtSelectorEmcal::GetClusters()
44 {   // Get clusters
45
46     if(!fClusterArray) fClusterArray = new TRefArray;
47
48     if(fClusterArray)
49     {
50         fEvent->GetEMCALClusters(fClusterArray);
51     }
52     else
53     {
54         Printf("Could not initialize cluster array");
55     }
56     return fClusterArray;
57 }
58
59 Bool_t AliAnalysisEtSelectorEmcal::PassMinEnergyCut(const AliESDCaloCluster& cl) const
60 {
61   Float_t pos[3];
62   cl.GetPosition(pos);
63   TVector3 cp(pos);
64   return TMath::Sin(cp.Theta())*cl.E() > fCuts->GetReconstructedEmcalClusterEnergyCut();
65 }
66
67 Bool_t AliAnalysisEtSelectorEmcal::PassMinEnergyCut(const TParticle& p) const
68 {
69   return TMath::Sin(p.Theta())*p.Energy() > fCuts->GetReconstructedEmcalClusterEnergyCut();
70 }
71
72 Bool_t AliAnalysisEtSelectorEmcal::PassDistanceToBadChannelCut(const AliESDCaloCluster& ) const
73 {
74     return kTRUE;
75 }
76
77 Bool_t AliAnalysisEtSelectorEmcal::PassTrackMatchingCut(const AliESDCaloCluster& cluster) const
78 {
79
80   Int_t nTracksMatched = cluster.GetNTracksMatched();
81   if(nTracksMatched == 0){
82     return kTRUE;
83   }
84   
85   Int_t trackMatchedIndex = cluster.GetTrackMatchedIndex();
86   if(trackMatchedIndex < 0){
87     return kTRUE;
88   }
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
91
92   //Float_t recoE = cluster.E();
93   //Float_t pos[3];
94
95 //     //cluster.GetPosition(pos);
96 //     Int_t trackMatchIdx = cluster.GetTrackMatchedIndex();
97 //     //Double_t distance = 9999.0;
98 //     if(trackMatchIdx>-1)
99 //     {
100 //       return kTRUE;
101 //       //distance = CalcTrackClusterDistance(pos, &trackMatchIdx);
102 //     }
103
104
105     return kFALSE;
106     //return distance > fCuts->GetEmcalTrackDistanceCut();
107 }
108
109 Bool_t AliAnalysisEtSelectorEmcal::CutGeometricalAcceptance(const TParticle& part)
110 {
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.;
116 }
117
118 Bool_t AliAnalysisEtSelectorEmcal::CutGeometricalAcceptance(const AliVTrack& part)
119 {
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.;
125 }
126
127 Bool_t AliAnalysisEtSelectorEmcal::CutGeometricalAcceptance(const AliESDCaloCluster& cluster)
128 {
129   Float_t pos[3];
130   cluster.GetPosition(pos);
131   TVector3 cp(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.;
137 }
138
139
140 Double_t
141 AliAnalysisEtSelectorEmcal::CalcTrackClusterDistance(const Float_t clsPos[3],Int_t *trkMatchId) const
142 {   // calculate distance between cluster and closest track
143
144     Double_t trkPos[3] = {0,0,0};
145
146     Int_t bestTrkMatchId = -1;
147     Double_t distance = 9999; // init to a big number
148
149     Double_t dist = 0;
150     Double_t distX = 0, distY = 0, distZ = 0;
151
152     for (Int_t iTrack = 0; iTrack < fEvent->GetNumberOfTracks(); iTrack++) {
153         AliESDtrack *track = static_cast<AliESDtrack*>( fEvent->GetTrack(iTrack) );
154         if (!track) {
155             AliError(Form("ERROR: Could not get track %d", iTrack));
156             continue;
157         }
158
159         // check for approx. eta and phi range before we propagate..
160         // TBD
161
162         AliEMCALTrack emctrack(*track);
163         if (!emctrack.PropagateToGlobal(clsPos[0],clsPos[1],clsPos[2],0.,0.) ) {
164             continue;
165         }
166         emctrack.GetXYZ(trkPos);
167
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);
172
173         if (dist < distance) {
174             distance = dist;
175             bestTrkMatchId = iTrack;
176         }
177     } // iTrack
178
179     // printf("CalcTrackClusterDistance: bestTrkMatch %d origTrkMatch %d distance %f\n", bestTrkMatchId, *trkMatchId, distance);
180     *trkMatchId = bestTrkMatchId;
181     return distance;
182 }
183
184 UInt_t AliAnalysisEtSelectorEmcal::GetLabel(const AliESDCaloCluster *cluster, AliStack *stack){
185   UInt_t correctLabel = TMath::Abs(cluster->GetLabel());
186   correctLabel = GetFirstMotherNotFromDetectorCover(correctLabel,*stack);
187
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);
192 //     if(hitParticle){
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);
196 //      if(mothIdx>0){
197 //        TParticle *mother = stack->Particle(mothIdx);
198 //        if(mother){
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
204 //              return mothIdx;
205 //            }
206 //          }
207 //        }
208 //      }
209 //       }
210
211 //     }
212 //   }
213   return  correctLabel ; // DS: should this line be inside n>0 check, and return another value if n<=0 ? 
214
215 }