1 | |
---|
2 | #include "modules/Tracking.h" |
---|
3 | |
---|
4 | #include "classes/DelphesClasses.h" |
---|
5 | #include "classes/DelphesFactory.h" |
---|
6 | #include "classes/DelphesFormula.h" |
---|
7 | |
---|
8 | #include "ExRootAnalysis/ExRootResult.h" |
---|
9 | #include "ExRootAnalysis/ExRootFilter.h" |
---|
10 | #include "ExRootAnalysis/ExRootClassifier.h" |
---|
11 | |
---|
12 | #include "TMath.h" |
---|
13 | #include "TString.h" |
---|
14 | #include "TFormula.h" |
---|
15 | #include "TRandom3.h" |
---|
16 | #include "TObjArray.h" |
---|
17 | #include "TDatabasePDG.h" |
---|
18 | #include "TLorentzVector.h" |
---|
19 | |
---|
20 | #include <algorithm> |
---|
21 | #include <stdexcept> |
---|
22 | #include <iostream> |
---|
23 | #include <sstream> |
---|
24 | |
---|
25 | using namespace std; |
---|
26 | |
---|
27 | //------------------------------------------------------------------------------ |
---|
28 | |
---|
29 | Tracking::Tracking() : |
---|
30 | fItInputArray(0) |
---|
31 | { |
---|
32 | } |
---|
33 | |
---|
34 | //------------------------------------------------------------------------------ |
---|
35 | |
---|
36 | Tracking::~Tracking() |
---|
37 | { |
---|
38 | } |
---|
39 | |
---|
40 | //------------------------------------------------------------------------------ |
---|
41 | |
---|
42 | void Tracking::Init() |
---|
43 | { |
---|
44 | ExRootConfParam paramEff, paramEffEta, paramEffPt, paramEffVal, paramEffPart; |
---|
45 | ExRootConfParam paramPtRes, paramPtResEta, paramPtResPt, paramPtResVal, paramPtResPart; |
---|
46 | |
---|
47 | Int_t i, size, ref=0, pid=0; |
---|
48 | |
---|
49 | fTrkMaxEta = GetDouble("TrackMaxEta", 2.5); |
---|
50 | fTrkMinPt = GetDouble("TrackMinPt" , 1); |
---|
51 | |
---|
52 | |
---|
53 | // fTrkEff = GetDouble("TrackingEfficiency", 90); //for a flat efficiency |
---|
54 | |
---|
55 | paramEff = GetParam("TrackingEfficiency"); |
---|
56 | paramPtRes = GetParam("TrackingPtResolution"); |
---|
57 | |
---|
58 | size = paramEff.GetSize(); |
---|
59 | //default tracking efficiency all are set to 90% by default |
---|
60 | TInt EtaInt = make_pair(0.0,50); |
---|
61 | TInt PtInt = make_pair(0.0,10000.0); |
---|
62 | TPtEtaInt PtEtaInt = make_pair(EtaInt,PtInt); |
---|
63 | TTrkMap TrkEffMap; |
---|
64 | TrkEffMap[PtEtaInt]=50; //only one entry in this simple map |
---|
65 | |
---|
66 | fTrkEffPartMap[11] = TrkEffMap; // electrons |
---|
67 | fTrkEffPartMap[13] = TrkEffMap; // muons |
---|
68 | fTrkEffPartMap[999] = TrkEffMap; // hadrons (pid 999 does not exist ...) |
---|
69 | |
---|
70 | // read efficiencies from cfg file |
---|
71 | for(i = 0; i < size/4; ++i) |
---|
72 | { |
---|
73 | paramEffPart = paramEff[i*4]; |
---|
74 | paramEffEta = paramEff[i*4+1]; |
---|
75 | paramEffPt = paramEff[i*4+2]; |
---|
76 | paramEffVal = paramEff[i*4+3]; |
---|
77 | pid = paramEffPart[0].GetInt(); |
---|
78 | |
---|
79 | if(ref!=pid) TrkEffMap.clear(); |
---|
80 | ref = (ref==pid)? ref : pid; |
---|
81 | |
---|
82 | EtaInt = make_pair(paramEffEta[0].GetDouble(),paramEffEta[1].GetDouble()); |
---|
83 | PtInt = make_pair(paramEffPt[0].GetDouble(),paramEffPt[1].GetDouble()); |
---|
84 | PtEtaInt = make_pair(EtaInt,PtInt); |
---|
85 | TrkEffMap[PtEtaInt] = paramEffVal.GetDouble(); |
---|
86 | fTrkEffPartMap[pid] = TrkEffMap; |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | size = paramPtRes.GetSize(); |
---|
91 | //default tracking pt res all are set to 90% by default |
---|
92 | TTrkMap TrkPtResMap; |
---|
93 | TrkPtResMap[PtEtaInt]=1.; //only one entry in this simple map |
---|
94 | |
---|
95 | fTrkPtResPartMap[11] = TrkPtResMap; // electrons |
---|
96 | fTrkPtResPartMap[13] = TrkPtResMap; // muons |
---|
97 | fTrkPtResPartMap[999] = TrkPtResMap; // hadrons (pid 999 does not exist ...) |
---|
98 | |
---|
99 | // read resolutions from cfg file |
---|
100 | for(i = 0; i < size/4; ++i) |
---|
101 | { |
---|
102 | paramPtResPart = paramPtRes[i*4]; |
---|
103 | paramPtResEta = paramPtRes[i*4+1]; |
---|
104 | paramPtResPt = paramPtRes[i*4+2]; |
---|
105 | paramPtResVal = paramPtRes[i*4+3]; |
---|
106 | pid = paramPtResPart[0].GetInt(); |
---|
107 | |
---|
108 | if(ref!=pid) TrkPtResMap.clear(); |
---|
109 | ref = (ref==pid)? ref : pid; |
---|
110 | |
---|
111 | EtaInt = make_pair(paramPtResEta[0].GetDouble(),paramPtResEta[1].GetDouble()); |
---|
112 | PtInt = make_pair(paramPtResPt[0].GetDouble(),paramPtResPt[1].GetDouble()); |
---|
113 | PtEtaInt = make_pair(EtaInt,PtInt); |
---|
114 | TrkPtResMap[PtEtaInt] = paramPtResVal.GetDouble(); |
---|
115 | fTrkPtResPartMap[pid] = TrkPtResMap; |
---|
116 | } |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | // import array with output from filter/classifier module |
---|
121 | |
---|
122 | fInputArray = ImportArray(GetString("InputArray", "ParticlePropagator/candidates")); |
---|
123 | fItInputArray = fInputArray->MakeIterator(); |
---|
124 | |
---|
125 | // create output arrays |
---|
126 | |
---|
127 | fOutputArray = ExportArray(GetString("TrackOutputArray", "tracks")); |
---|
128 | |
---|
129 | } |
---|
130 | |
---|
131 | //------------------------------------------------------------------------------ |
---|
132 | |
---|
133 | void Tracking::Finish() |
---|
134 | { |
---|
135 | } |
---|
136 | |
---|
137 | //------------------------------------------------------------------------------ |
---|
138 | |
---|
139 | void Tracking::Process() |
---|
140 | { |
---|
141 | Candidate *candidate, *mother; |
---|
142 | TLorentzVector candidatePosition, candidateMomentum; |
---|
143 | Double_t x, y, z, px, py, pz, pt, pt2, eta, phi, e, m, q; |
---|
144 | Int_t pid; |
---|
145 | TRandom3 * grandom = new TRandom3(0); |
---|
146 | |
---|
147 | fItInputArray->Reset(); |
---|
148 | while((candidate = static_cast<Candidate*>(fItInputArray->Next()))) |
---|
149 | { |
---|
150 | candidatePosition = candidate->Position; |
---|
151 | candidateMomentum = candidate->Momentum; |
---|
152 | x = candidatePosition.X()*1.0E-3; |
---|
153 | y = candidatePosition.Y()*1.0E-3; |
---|
154 | z = candidatePosition.Z()*1.0E-3; |
---|
155 | m = candidate->Mass; |
---|
156 | q = candidate->Charge; |
---|
157 | pid = TMath::Abs(candidate->PID); |
---|
158 | px = candidateMomentum.Px(); |
---|
159 | py = candidateMomentum.Py(); |
---|
160 | pz = candidateMomentum.Pz(); |
---|
161 | pt = candidateMomentum.Pt(); |
---|
162 | pt2 = candidateMomentum.Perp2(); |
---|
163 | e = candidateMomentum.E(); |
---|
164 | eta = candidateMomentum.Eta(); |
---|
165 | phi = candidateMomentum.Phi(); |
---|
166 | |
---|
167 | // check that particle is charged, and that it passes standard acceptance cuts |
---|
168 | if(q==0 || TMath::Abs(eta)>fTrkMaxEta || pt<fTrkMinPt ) continue; |
---|
169 | |
---|
170 | // check that track is lucky |
---|
171 | if( grandom->Uniform(0,100) > Value(pid,pt,eta,fTrkEffPartMap) ) continue; |
---|
172 | |
---|
173 | //smearing pt according to tracking resolution |
---|
174 | Double_t sPT = grandom->Gaus(pt, Value(pid,pt,eta,fTrkPtResPartMap)*pt*0.01 ); |
---|
175 | if(sPT <=0) continue; |
---|
176 | else |
---|
177 | { |
---|
178 | mother = candidate; |
---|
179 | candidate = static_cast<Candidate*>(candidate->Clone()); |
---|
180 | candidate->Momentum.SetPtEtaPhiE(sPT,eta,phi,sPT*cosh(eta)); |
---|
181 | candidate->Mother = mother; |
---|
182 | } |
---|
183 | |
---|
184 | fOutputArray->Add(candidate); |
---|
185 | } |
---|
186 | delete grandom; |
---|
187 | } |
---|
188 | |
---|
189 | //------------------------------------------------------------------------------ |
---|
190 | |
---|
191 | Double_t Tracking::Value(Int_t pid, Double_t pt, Double_t eta, TTrkPartMap TrkPartMap) |
---|
192 | { |
---|
193 | |
---|
194 | Double_t eff=0; |
---|
195 | if(pid!=11 &&pid!=13) pid=999; |
---|
196 | TTrkMap TrkEffMap = TrkPartMap[pid]; |
---|
197 | |
---|
198 | for(It_tm it = TrkEffMap.begin(); it != TrkEffMap.end(); it++) |
---|
199 | { |
---|
200 | TPtEtaInt inter = it->first; |
---|
201 | TInt eta_int = inter.first; |
---|
202 | TInt pt_int = inter.second; |
---|
203 | Double_t etamin = eta_int.first; |
---|
204 | Double_t etamax = eta_int.second; |
---|
205 | Double_t ptmin = pt_int.first; |
---|
206 | Double_t ptmax = pt_int.second; |
---|
207 | Double_t EFF= it->second; |
---|
208 | |
---|
209 | // cout<<"PID: "<<pid<<" ,ETA: "<<eta<<", PT: "<<pt<<",eff: "<<EFF<<endl; |
---|
210 | |
---|
211 | Bool_t ok = pt>ptmin && pt<ptmax && TMath::Abs(eta)>etamin && TMath::Abs(eta)<etamax; |
---|
212 | if(ok)eff=EFF; |
---|
213 | if(ok)break; |
---|
214 | } |
---|
215 | return eff; |
---|
216 | |
---|
217 | } |
---|