ATLAS Offline Software
Loading...
Searching...
No Matches
FakeTrackSmearer.h
Go to the documentation of this file.
1// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3// Stolen from A.Cerri
4
5#ifndef EFTRACKINGEMULATION_FAKETRACKSMEARER_H
6#define EFTRACKINGEMULATION_FAKETRACKSMEARER_H
8#include "TRandom3.h"
9#include "TCanvas.h"
10#include "TGraphErrors.h"
11#include "TF1.h"
12#include "TF2.h"
13#include "TH1F.h"
14#include "TROOT.h"
15
16
17#include "FTS_Track.h"
18#include <cmath>
19namespace FitFunctions {
20 #include "FitFunctions/URD/d0Fitparam_N.C"
21 #include "FitFunctions/URD/z0Fitparam_N.C"
22 #include "FitFunctions/URD/effFitparam_N.C"
23 #include "FitFunctions/URD/effFitparam_LRT.C"
24 #include "FitFunctions/URD/ptqoptFitparam_N.C"
25}
26
27
29{
30 public:
31 FakeTrackSmearer(const std::string & InstanceName, long long randomseed=0, bool verbose=false)
32 : m_baseName (InstanceName),
34 m_myRandom (new TRandom3(randomseed))
35 {
36 Prepare();
37 Tracks.clear();
38
39 // Set these in order to define the scenario:
40 //SetSigmaScaleFactor(1.0);
41 //SetResolutionPtCutOff(5.0);
42 //UseResolutionPtCutOff(true);
43
44 }
45 //
46 FakeTrackSmearer(const FakeTrackSmearer & other) = delete;
47 FakeTrackSmearer & operator=(const FakeTrackSmearer & other) = delete;
48
49// prepare the functions to use
50 void Prepare()
51 {
52 printf("Entering Prepare\n");
53 std::string name;
54
55 name="d0res_eta"+m_baseName; //pt=10GeV
56 d0res_eta=new TF1(name.c_str(),[&](double*x,double*p){return d0ResFunc(x[0],p[0]=10.,0); },0.0,4.0,1);
57 name="z0res_eta"+m_baseName;
58 z0res_eta=new TF1(name.c_str(),[&](double*x,double*p){return z0ResFunc(x[0],p[0]=10.,0); },0.0,4.0,1);
59 name="curvres_eta"+m_baseName;
60 curvres_eta=new TF1(name.c_str(),[&](double*x,double*p){return curvResFunc(x[0],p[0]=10.,0); },0.0,4.0,1);
61
62 name="d0ref_eta"+m_baseName;
63 d0ref_eta=new TF1(name.c_str(),[&](double*x,double*p){return d0RefFunc(x[0],p[0]=10.,0); },0.0,4.0,1);
64 name="z0ref_eta"+m_baseName;
65 z0ref_eta=new TF1(name.c_str(),[&](double*x,double*p){return z0RefFunc(x[0],p[0]=10.,0); },0.0,4.0,1);
66
67
68 name="d0res_pt"+m_baseName; //eta=1
69 d0res_pt=new TF1(name.c_str(),[&](double*x,double*p){return d0ResFunc(p[0]=1.,x[0],0); },1.0,200.0,1);
70 name="z0res_pt"+m_baseName;
71 z0res_pt=new TF1(name.c_str(),[&](double*x,double*p){return z0ResFunc(p[0]=1.,x[0],0); },1.0,200.0,1);
72 name="curvres_pt"+m_baseName;
73 curvres_pt=new TF1(name.c_str(),[&](double*x,double*p){return curvResFunc(p[0]=1.,x[0],0); },1.0,200.0,1);
74
75 name="d0ref_pt"+m_baseName;
76 d0ref_pt=new TF1(name.c_str(),[&](double*x,double*p){return d0RefFunc(p[0]=1.,x[0],0); },1.0,200.0,1);
77 name="z0ref_pt"+m_baseName;
78 z0ref_pt=new TF1(name.c_str(),[&](double*x,double*p){return z0RefFunc(p[0]=1.,x[0],0); },1.0,200.0,1);
79
80 name="effLRT_d0"+m_baseName;
83 effLRT_d0=new TF1(name.c_str(),[&](double*x, double*p){p[0]=1.;return effFuncLRT(x[0],0); },0.,600.0,1);
84
85 }
86
87
88 double d0ResFunc(double eta,double pt,int verbose)
89 {
90 // add here other d0 res functions
91 return FitFunctions::getd0ResParam_N(eta,pt,verbose)/1000.0;// convert to mm
92 }
93
94 double z0ResFunc(double eta,double pt,int verbose)
95 {
96 // add here other z0 res functions
97 return FitFunctions::getz0ResParam_N(eta,pt,verbose)/1000.0; // convert to mm
98 }
99
101 {
102 // add here other eta res functions
103 return 0.;
104 }
105
107 {
108 // add here other phi res functions
109 return 0.;
110 }
111
113 {
114 // add here other curv res functions
116 return 0.;
117 }
118
119// Reference functions, in case needed ////
120
122 {
123 return 1.; // no reference to scale
124 }
125
127 {
128 return 1.; // no reference to scale
129 }
130
132 {
133 return 1.;// no reference to scale
134 }
135
137 {
138 return 1.;// no reference to scale
139 }
140
142 {
143 return 1.;// no reference to scale
144 }
145
146double effFunc(double eta,double pt,int verbose)
147 {
148 // add here other efficiency functions
150 }
151
152double effFuncLRT(double d0, int verbose)
153 {
154 // add here other efficiency functions
156 }
157
158 void InitArray(double *a,int n,const double in[])
159 {
160 for (int i=0;i<n;i++) a[i]=in[i];
161 }
162
163
164
165 void SetInputTracksPtCut(double ptcut) {m_inPtCut=ptcut;};
166 void SetOutputTracksPtCut(double ptcut) {m_outPtCut=ptcut;};
167 void SetMatchRatio(double m) { m_FMatches=m;}; // NMatch/NOffline i.e. k
168 void SetFakeFraction(double f) {m_FakeFraction=f; }; // i.e. f
170 void SetResolutionPtCutOff(double cutoff) {m_resolutionPtCutOff=cutoff; };
172
173 void Clear() {m_ntracks=0; m_nfakes=0; Tracks.clear(); };
174
175 int GetNTrueTracks() {return m_ntracks; };
176 int GetNFakes() {return m_nfakes; };
177 int GetNTracks() {return m_ntracks+m_nfakes; };
178
179 void AddTrackAndTruth(double d0,double z0,double curv,double eta,double phi)
180 {
184 }
185
186
187 void AddTrack(double d0,double z0,double curv,double eta,double phi)
188 {
189 // Adding one or more tracks to this input
190 // input curv is in GeV
191 bool verbose=m_verbose;
192
193 double abseta = std::abs(eta);
194 double abspt = std::abs(1.0/curv); //GeV
195 double absd0 = std::abs(d0);
196 if (verbose) printf("Smearer::AddTrack: Initial track: curv = %f, phi=%f, eta=%f, d0=%f, z0=%f (pt=%f)\n", curv, phi, eta, d0, z0, abspt);
197
198
199 bool condition = (abspt>m_inPtCut) &&
200 (d0RefFunc(abseta,abspt,verbose)>0.0) &&
201 (d0ResFunc(abseta,abspt,verbose)>0.0) &&
202 (z0RefFunc(abseta,abspt,verbose)>0.0) &&
203 (z0ResFunc(abseta,abspt,verbose)>0.0) &&
204 (curvResFunc(abseta,abspt,verbose)>0.0);
205
206 if (!condition)
207 return;
208
209
210 //Call here SetFakeFraction() and SetMatchRatio();
211
212 double curvres = m_SigmaScaleFactor * curvResFunc(abseta,abspt,0);
213 double phires = m_SigmaScaleFactor * phiResFunc(abseta,abspt,0);
214 double etares = m_SigmaScaleFactor * etaResFunc(abseta,abspt,0);
215 double d0res = m_SigmaScaleFactor * d0ResFunc(abseta,abspt,0);
216 double z0res = m_SigmaScaleFactor * z0ResFunc(abseta,abspt,0);
217 if (verbose) printf("Smearer::AddTrack: Smearing parameters: curv = %f, phi=%f, eta=%f, d0=%f, z0=%f\n", curvres, phires, etares, d0res, z0res);
218
219
220 #ifdef STANDALONE_FAKETRACKSMEARER
221 d0Narrow->Fill(d0res);
222 z0Narrow->Fill(z0res);
223 #endif
224
225
226 #ifdef STANDALONE_FAKETRACKSMEARER
227 d0Sim->Fill(s_narrow_d0_model->Eval(abseta));
228 z0Sim->Fill(s_narrow_z0_model->Eval(abseta));
229 #endif
230
231
232
234 double eff = m_nominalEfficiency;
236 eff = eff * effFunc(abseta,abspt,verbose);
237 }
239 eff = eff * effFuncLRT( absd0, verbose);
240 }
241
242 int ntracks=( m_myRandom->Rndm()<eff)?1:0;
243
244 if (m_produceFakes)
245 {
246 if (m_useCoinToss) {
247 if (avgntracks>m_nominalEfficiency) ntracks+= m_myRandom->Poisson(avgntracks-m_nominalEfficiency);
248 else if (avgntracks<m_nominalEfficiency) ntracks=( m_myRandom->Rndm()<avgntracks)?1:0;
249 }
250 else
251 ntracks= m_myRandom->Poisson(avgntracks);
252 }
253
254 if (verbose) printf("Smearer::AddTrack: Now producing %d tracks\n", ntracks);
255 for (int i=0;i<ntracks;i++)
256 {
257
258 // Creating close track
259 double gend0,genz0, geneta, genphi, gencurv;
260 gend0 = m_myRandom->Gaus(d0,d0res);
261 genz0 = m_myRandom->Gaus(z0,z0res);
262 geneta= m_myRandom->Gaus(eta,etares);
263 genphi= m_myRandom->Gaus(phi,phires);
264 gencurv= m_myRandom->Gaus(curv,curvres);
265
267 1./gencurv, //pT
268 geneta,
269 genphi,
270 gend0,
271 genz0,
272 curvres/gencurv/gencurv, // res pT
273 etares,
274 phires,
275 d0res,
276 z0res,
277 false
278 );
279 if (verbose) printf("Smearer::AddTrack: Producing this track: curv = %f, phi=%f, eta=%f, d0=%f, z0=%f pt=%f (ptres=%f)\n",gencurv, genphi, geneta, gend0, genz0, Track.pt(), Track.sigma_pt());
280 if (std::abs(Track.pt())>=m_outPtCut)
281 {
282 Tracks.push_back(Track);
283 m_ntracks++;
284 if (verbose) printf("Smearer::AddTrack: Adding track with pt=%f ==> track #%d\n",Track.pt(), m_ntracks);
285 }
286 else if (verbose) printf("Smearer::AddTrack: No track added because of the output pt cut\n");
287
288 }
289
290
291 // AddTrack Done
292 return;
293 };
294
295 void PlotD0Res(double eta)
296 {
297 TCanvas *d0rescanvas=(TCanvas *)gROOT->FindObjectAny("d0rescanvas");
298 if (d0rescanvas==NULL) d0rescanvas=new TCanvas("d0rescanvas");
299 d0res_pt->SetParameter(0,eta);
300 d0ref_pt->SetParameter(0,eta);
301 d0res_pt->Draw();
302 d0ref_pt->SetLineColor(4);
303 d0ref_pt->Draw("same");
304 }
305
306
307 void EnableFakes(bool enable=true)
308 {
309 m_produceFakes=enable;
310 if (not Tracks.empty())
311 printf("Smearer::EnableFakes: Warning: you are reconfiguring fakes production but it seems you have already processed events with this instance of FakeTracksSmearer\n");
312 }
313
314 void FakeKillerEnable(bool enable=true)
315 {
316 m_fakeKillerEnable=enable;
317 if (not Tracks.empty())
318 printf("Smearer::FakeKillerEnable: Warning: you are reconfiguring fakes production but it seems you have already processed events with this instance of FakeTracksSmearer (FakeKillerEnable)\n");
319 }
320
322 {
324 if (not Tracks.empty())
325 printf("Smearer::IncludeFakesInResolutionCalculation: Warning: you are reconfiguring fakes production but it seems you have already processed events with this instance of FakeTracksSmearer (IncluldeFakesInResolutionCalculation)\n");
326 }
327
328 void UseCoinToss(bool enable=true)
329 {
330 m_useCoinToss=enable;
331 if (not Tracks.empty())
332 printf("Smearer::UseCoinToss: Warning: you are reconfiguring fakes production but it seems you have already processed events with this instance of FakeTracksSmearer (UseCoinToss)\n");
333 }
334
335 void SetTrackingEfficiency(double epsilon=0.95)
336 {
337 m_nominalEfficiency=epsilon;
338 }
339
340 void SetParameterizedEfficiency(bool param = false)
341 {
343 }
344
345 void SetParameterizedEfficiency_LRT(bool param = false)
346 {
348 }
349
354
359
360 std::vector<EFTrackingSmearing::FTS_Track> Tracks;
361 double z0(int idx) {return Tracks[idx].z0();};
362 double d0(int idx) {return Tracks[idx].d0();};
363 double phi(int idx) {return Tracks[idx].phi();};
364 double pt(int idx) {return Tracks[idx].pt();};
365 double curv(int idx) {return Tracks[idx].pt();};
366 double eta(int idx) {return Tracks[idx].eta();};
367
368
369 TH1F *d0Narrow = nullptr;
370 TH1F *z0Narrow = nullptr;
371 TH1F *d0Sim = nullptr;
372 TH1F *z0Sim = nullptr;
373
374 TF1 *d0res_eta = nullptr;
375 TF1 *d0ref_eta = nullptr;
376 TF1 *z0res_eta = nullptr;
377 TF1 *z0ref_eta = nullptr;
378 TF1 *d0res_pt = nullptr;
379 TF1 *d0ref_pt = nullptr;
380 TF1 *z0res_pt = nullptr;
381 TF1 *z0ref_pt = nullptr;
382 TF1 *curvres_eta = nullptr;
383 TF1 *curvres_pt = nullptr;
384 TF1 *effLRT_d0 = nullptr;
385
386
387 private:
388 std::string m_baseName;
389 int m_ntracks = 0;
390 int m_nfakes = 0;
391 bool m_verbose = false;
392 TRandom3 *m_myRandom = nullptr;
393
394 double m_FMatches = 1.; // NMatch/NOffline i.e. k
395 double m_FakeFraction = 0.;
396 double m_SigmaScaleFactor = 1.0;
397 double m_nominalEfficiency = 0.95;
398
402 bool m_fakeKillerEnable = false;
403 bool m_useCoinToss = false;
404 bool m_useInputSigmas = false;
405 bool m_produceFakes = true;
409 double m_inPtCut = 0.0;
410 double m_outPtCut = 1.0;
413
414
415};
416
417#endif
static Double_t a
__attribute__((always_inline)) inline uint16_t TileCalibDrawerBase
#define x
void unused(Args &&...)
FakeTrackSmearer & operator=(const FakeTrackSmearer &other)=delete
void UseResolutionPtCutOff(bool use)
void SetResolutionPtCutOff(double cutoff)
FakeTrackSmearer(const std::string &InstanceName, long long randomseed=0, bool verbose=false)
double curv(int idx)
double curvRefFunc(double eta __attribute__((unused)), double pt __attribute__((unused)), int verbose __attribute__((unused)))
double phi(int idx)
double m_parameterizedEfficiency_highd0_LRT
double effFunc(double eta, double pt, int verbose)
double curvResFunc(double eta __attribute__((unused)), double pt __attribute__((unused)), int verbose __attribute__((unused)))
bool m_includeFakesInResolutionCalculation
void SetSigmaScaleFactor(double s)
double pt(int idx)
void FakeKillerEnable(bool enable=true)
void SetMatchRatio(double m)
void SetParameterizedEfficiency(bool param=false)
double d0ResFunc(double eta, double pt, int verbose)
void SetParameterizedEfficiency_lowd0_LRT(double d0)
double eta(int idx)
void AddTrack(double d0, double z0, double curv, double eta, double phi)
void IncludeFakesInResolutionCalculation(bool enable=true)
void SetFakeFraction(double f)
void AddTrackAndTruth(double d0, double z0, double curv, double eta, double phi)
void PlotD0Res(double eta)
double m_parameterizedEfficiency_lowd0_LRT
FakeTrackSmearer(const FakeTrackSmearer &other)=delete
void UseCoinToss(bool enable=true)
double phiResFunc(double eta __attribute__((unused)), double pt __attribute__((unused)), int verbose __attribute__((unused)))
double z0(int idx)
double etaRefFunc(double eta __attribute__((unused)), double pt __attribute__((unused)), int verbose __attribute__((unused)))
double effFuncLRT(double d0, int verbose)
std::vector< EFTrackingSmearing::FTS_Track > Tracks
void SetOutputTracksPtCut(double ptcut)
void SetTrackingEfficiency(double epsilon=0.95)
void SetParameterizedEfficiency_highd0_LRT(double d0)
double etaResFunc(double eta __attribute__((unused)), double pt __attribute__((unused)), int verbose __attribute__((unused)))
double z0RefFunc(double eta __attribute__((unused)), double pt __attribute__((unused)), int verbose __attribute__((unused)))
void SetInputTracksPtCut(double ptcut)
double d0RefFunc(double eta __attribute__((unused)), double pt __attribute__((unused)), int verbose __attribute__((unused)))
double z0ResFunc(double eta, double pt, int verbose)
void InitArray(double *a, int n, const double in[])
double d0(int idx)
void EnableFakes(bool enable=true)
double phiRefFunc(double eta __attribute__((unused)), double pt __attribute__((unused)), int verbose __attribute__((unused)))
void SetParameterizedEfficiency_LRT(bool param=false)
bool verbose
Definition hcg.cxx:73
double getEffParam_LRT(double absd0, double lowd0_cut, double highd0_cut, bool debug=false)
double getz0ResParam_N(float abstrketa, float trkpt, bool debug=false)
double getd0ResParam_N(float abstrketa, float trkpt, bool debug=false)
double getEffParam_N(float abstrketa, float trkpt, bool debug=false)
double getptqoptResParam_N(float abstrketa, float trkpt, bool debug=false)