DAS  3.0
Das Analysis System
sigmoid.h
Go to the documentation of this file.
1 #include <cassert>
2 #include <cstdlib>
3 
4 #include <iostream>
5 #include <fstream>
6 
7 #include <TF1.h>
8 #include <TH1.h>
9 
10 using namespace std;
11 
12 namespace DAS::Normalisation {
13 
14 const float threshold = 0.995;
20 float GetX (TF1 * f)
21 {
22  double m = 0, M = 7000;
23  f->GetRange(m,M);
24 
25  for (float pt = m; pt < M; ++pt)
26  if (f->Eval(pt) > threshold)
27  return pt;
28 
29  cerr << "No threshold was found from " << m << " to " << M << ".\nAborting.\n";
30  exit(EXIT_FAILURE);
31 }
32 
46 template<typename STREAM>
47 [[ deprecated ]]
49  (int trigger,
50  TH1 * h,
51  STREAM& Stream,
52  int from,
53  const char * options = "NQERS")
54 {
55  assert(from > 0);
56  int mbin = h->GetXaxis()->FindBin( from),
57  Mbin = h->GetXaxis()->FindBin(3*from);
58  float m = h->GetBinLowEdge(mbin+1), M = h->GetBinLowEdge(Mbin);
59  for (int bin = 0; bin <= mbin; ++bin) {
60  h->SetBinContent(bin, 0);
61  h->SetBinError (bin, 0);
62  }
63  for (int bin = Mbin+1; bin <= h->GetNbinsX()+1; ++bin) {
64  h->SetBinContent(bin, 0);
65  h->SetBinError (bin, 0);
66  }
67 
68  cout << "Fitting trigger " << trigger << " from " << m << " to " << M << endl;
69 
70  // function
71  TF1 * f = new TF1(Form("sigmoid%d", trigger),
72  "[0]+0.5*(1-[0])*(1+erf((x-[1])/[2]))",
73  m, M);
74 
75  f->SetParNames("a", "#mu", "#sigma");
76 
77  //f->FixParameter(0,0);
78  f->SetParameter(0,0.1);
79  f->SetParLimits(0,0,0.9);
80 
81  f->SetParameter(1,1.1*trigger);
82  f->SetParLimits(1,m,M);
83 
84  f->SetParameter(2,10);
85  f->SetParLimits(2,1,150);
86 
87  // fit
88  h->Fit(f, options, "", m, M);
89 
90  float turnon = GetX(f);
91 
92  Stream << trigger << '\t' << turnon << '\n';
93 
94  return f;
95 }
96 
100 template<typename STREAM> float GetTriggerEfficiency
101  (int trigger,
102  TH1 * h,
103  STREAM& Stream,
104  float from,
105  float minEff)
106 {
107  int mbin = h->GetXaxis()->FindBin( from),
108  Mbin = h->GetXaxis()->FindBin(6*from);
109  for (int bin = 0; bin < mbin; ++bin) {
110  h->SetBinContent(bin, 0);
111  h->SetBinError (bin, 0);
112  }
113  for (int bin = Mbin+1; bin <= h->GetNbinsX()+1; ++bin) {
114  h->SetBinContent(bin, 0);
115  h->SetBinError (bin, 0);
116  }
117  for (int bin = mbin; bin <= Mbin; ++bin) {
118  float content = h->GetBinContent(bin);
119  if (content < minEff) continue;
120  float turnon = h->GetBinLowEdge(bin);
121  Stream << trigger << '\t' << turnon << '\n';
122  return turnon;
123  }
124  return -1;
125 }
126 
127 } // end of DAS::Trigger namespace
Ntupliser_cfg.cerr
cerr
Definition: Ntupliser_cfg.py:93
DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.options
options
Definition: DYToLL_M-50_13TeV_pythia8_cff_GEN_SIM_RECOBEFMIX_DIGI_L1_DIGI2RAW_L1Reco_RECO.py:41
jmarExample.pt
pt
Definition: jmarExample.py:19
DAS::Normalisation::FitTriggerEfficiency
TF1 * FitTriggerEfficiency(int trigger, TH1 *h, STREAM &Stream, int from, const char *options="NQERS")
Definition: sigmoid.h:49
Ntupliser_cfg.f
f
Definition: Ntupliser_cfg.py:256
DAS::Normalisation
Definition: getHLTJetResponse.cc:34
DAS::Normalisation::threshold
const float threshold
Definition: sigmoid.h:14
DAS::Normalisation::GetTriggerEfficiency
float GetTriggerEfficiency(int trigger, TH1 *h, STREAM &Stream, float from, float minEff)
Definition: sigmoid.h:101
DAS::Normalisation::GetX
float GetX(TF1 *f)
Definition: sigmoid.h:20