CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
getMaxPt.h
Go to the documentation of this file.
1 // For DT PT Assignment.
2 // getMaxPT() will solve for the maximum allowable PT as defined by the "corridors".
3 // The corridor root files were generated with "runBasicCuts.C", which defines the
4 // number of PT bins. The parameter NPTBins below MUST match NPTBins in runBasicCuts.C.
5 
6 #include <iomanip>
7 #include <vector>
8 #include <cstdlib>
9 #include <vector>
10 #include <iostream>
11 #include <map>
12 #include <string>
13 #include <iomanip>
14 
15 #include "TFile.h"
16 #include "TTree.h"
17 #include "TString.h"
18 #include "TSystem.h"
19 #include "sstream"
20 #include "TNtuple.h"
21 #include "TGraphErrors.h"
22 #include "TH1F.h"
23 #include "TH1.h"
24 #include "TH2.h"
25 #include "TMatrixD.h"
26 #include "TGraph.h"
27 #include "TF1.h"
28 #include "TCanvas.h"
29 #include "sstream"
30 #include "TMath.h"
31 #include "TGraphAsymmErrors.h"
32 #include "TLegend.h"
33 
34 using namespace std;
35 
36 
37 int NETABITS = 5;
38 int NETABINS = 1<<NETABITS;
39 int NPTBins = 200;
40 
41 // The TGraphs which define the corridors for dPhi vs PT. The arrays are in the form dPhi_Cut[stationA-1][stationB-1].
42 TGraph *gdPhi12_Cut__[32];
43 TGraph *gdPhi23_Cut__[32];
44 TGraph *gdPhi34_Cut__[32];
45 TGraph *gdEta12_Cut__[32];
46 TGraph *gdEta23_Cut__[32];
47 TGraph *gdEta34_Cut__[32];
48 TGraph *gCLCT1_Cut__[32];
49 TGraph *gCLCT2_Cut__[32];
50 TGraph *gCLCT3_Cut__[32];
51 TGraph *gCLCT4_Cut__[32];
52 
53 int loaded__ = false;
54 
55 // Histogram used to rebin PT.
56 TH1F *hPT__;
57 
58 // load() reads in the corridor TGraphs from the root files.
59 void load(int perCUT=90)
60 {
61  // "perCUT" is the fraction of events under the corridor curve.
62  // For DTs, you currently have three options: perCUT = 85, perCUT = 90, or perCUT = 98.
63  // You'll need to use "runBasicCuts.C" to generate other tail fraction scenarios.
64 
65 
66  hPT__ = new TH1F("hPT__","",NPTBins,0,200);
67 
68  TString name = "L1Trigger/L1TMuon/data/emtf_luts/dPhi_Cuts_";
69  name += perCUT; name += ".root";
70 
71  TFile f(name);
72 
73  for (int j=0;j<NETABINS;j++)
74  {
75  TString name = "gCut_dPhi12_eta_";
76  name += j;
77  gdPhi12_Cut__[j] = (TGraph *)f.Get(name);
78  cout << gdPhi12_Cut__[j]->GetName() << " loaded " << endl;
79  }
80  for (int j=0;j<NETABINS;j++)
81  {
82  TString name = "gCut_dPhi23_eta_";
83  name += j;
84  gdPhi23_Cut__[j] = (TGraph *)f.Get(name);
85  cout << gdPhi23_Cut__[j]->GetName() << " loaded " << endl;
86  }
87  for (int j=0;j<NETABINS;j++)
88  {
89  TString name = "gCut_dPhi34_eta_";
90  name+=j;
91  gdPhi34_Cut__[j] = (TGraph *)f.Get(name);
92  cout << gdPhi34_Cut__[j]->GetName() << " loaded " << endl;
93  }
94  for (int j=0;j<NETABINS;j++)
95  {
96  TString name = "gCut_dEta12_eta_";
97  name+=j;
98  gdEta12_Cut__[j] = (TGraph *)f.Get(name);
99  cout << gdEta12_Cut__[j]->GetName() << " loaded " << endl;
100  }
101  for (int j=0;j<NETABINS;j++)
102  {
103  TString name = "gCut_dEta23_eta_";
104  name+=j;
105  gdEta23_Cut__[j] = (TGraph *)f.Get(name);
106  cout << gdEta23_Cut__[j]->GetName() << " loaded " << endl;
107  }
108  for (int j=0;j<NETABINS;j++)
109  {
110  TString name = "gCut_dEta34_eta_";
111  name+=j;
112  gdEta34_Cut__[j] = (TGraph *)f.Get(name);
113  cout << gdEta34_Cut__[j]->GetName() << " loaded " << endl;
114  }
115  for (int j=0;j<NETABINS;j++)
116  {
117  TString name = "gCut_CLCT1_eta_";
118  name+=j;
119  gCLCT1_Cut__[j] = (TGraph *)f.Get(name);
120  cout << gCLCT1_Cut__[j]->GetName() << " loaded " << endl;
121  }
122 for (int j=0;j<NETABINS;j++)
123  {
124  TString name = "gCut_CLCT2_eta_";
125  name+=j;
126  gCLCT2_Cut__[j] = (TGraph *)f.Get(name);
127  cout << gCLCT2_Cut__[j]->GetName() << " loaded " << endl;
128  }
129 for (int j=0;j<NETABINS;j++)
130  {
131  TString name = "gCut_CLCT3_eta_";
132  name+=j;
133  gCLCT3_Cut__[j] = (TGraph *)f.Get(name);
134  cout << gCLCT3_Cut__[j]->GetName() << " loaded " << endl;
135  }
136 for (int j=0;j<NETABINS;j++)
137  {
138  TString name = "gCut_CLCT4_eta_";
139  name+=j;
140  gCLCT4_Cut__[j] = (TGraph *)f.Get(name);
141  cout << gCLCT4_Cut__[j]->GetName() << " loaded " << endl;
142  }
143  loaded__ = true;
144 
145 
146 }
147 
148 // solve() takes the PT hypothesis (generally from BDT) and checks for the
149 // maximum PT consistent with the input value (such as dPhiAB) and input corridor
150 // given by the TGraph pointer. For the given input value, the maximum acceptable
151 // PT is returned such that the corridor condition is satisfied.
152 float solve(float ptHyp, float val, TGraph *g)
153 {
154  Int_t theBIN = hPT__->FindBin( ptHyp); // for the pt hypothesis get the bin
155  Float_t thePT = theBIN;
156 
157  float maxPt = 1e6;
158  float cut = g->Eval( theBIN ) ;
159 
160  // cout << "thePT = " << thePT << ", cut = " << cut << endl;
161 
162  if (cut>-1) // is a cut defined at this PT? Sometimes the training sample has too few events for a given PT bin.
163  if (fabs(val) > cut ) // check if the value is greater than the corridor cut
164  {
165  maxPt = 1;
166  for (float p=thePT-1; p>0; p=p-1) // The corridor TGraphs count PT bins by "0"...sorry.
167  {
168  float eval = g->Eval((float)p); // Get the maximum acceptable input value at this test-PT
169  // cout << eval << " " << val << endl;
170  if (eval>=0) // make sure there is corridor value defined here, or else we ignore this test-PT and move on
171  {
172  if (fabs(val) < eval) // Finally, is the input value below the corridor at the test-PT? If so, we can stop.
173  {
174  maxPt = p;
175  break;
176  }
177  }
178  }
179  }
180 
181  float output = ptHyp;
182  if (maxPt < output) // If the final test-PT is lower than the original hypothesis, we need to use the final test-PT.
183  output = maxPt;
184 
185  return output;
186 }
187 
188 // getMaxPT() solves for the maximum acceptable PT value given an ensemble of corridors defined for
189 // the dPhi and PhiBend input values. For a given station pair, this will call the solve function
190 // above for dPhiAB and PhiBendA, and will choose the minimum of the best PT solutions. The minimum
191 // of the PTs will satisfy all corridors simultaniously, I promise.
192 float getMaxPT(float ptHyp, Int_t eta, float dPhi12, float dPhi23, float dPhi34, int perCUT=100)
193 {
194  //cout << dPhi12 << " " << dPhi23 << " " << dPhi34 << endl;
195  if (!loaded__) // make sure the corridor TGraphs are loaded from the root files!
196  load(perCUT);
197 
198  if (eta>NETABINS) eta = NETABINS-1;
199 
200  float maxPt_dPhi12 = solve(ptHyp, dPhi12, gdPhi12_Cut__[eta]); // Get the best PT using dPhiAB corridors.
201  float maxPt_dPhi23 = solve(ptHyp, dPhi23, gdPhi23_Cut__[eta]); // Get the best PT using dPhiAB corridors.
202  float maxPt_dPhi34 = solve(ptHyp, dPhi34, gdPhi34_Cut__[eta]); // Get the best PT using dPhiAB corridors.
203 
204  // Now take the minimum of the four possible PT values.
205  float ptOut = ptHyp;
206 
207  if (maxPt_dPhi12 < ptOut)
208  ptOut = maxPt_dPhi12;
209  if (maxPt_dPhi23 < ptOut)
210  ptOut = maxPt_dPhi23;
211  if (maxPt_dPhi34 < ptOut)
212  ptOut = maxPt_dPhi34;
213 
214  //ptOut = (maxPt_dPhi12 + maxPt_dPhi23 + maxPt_dPhi34)/3;
215 
216  return ptOut;
217 }
218 float getMaxPT_dEta(float ptHyp, Int_t eta, float dEta12, float dEta23, float dEta34, int perCUT=100)
219 {
220  //cout << dPhi12 << " " << dPhi23 << " " << dPhi34 << endl;
221  if (!loaded__) // make sure the corridor TGraphs are loaded from the root files!
222  load();
223 
224  if (eta>NETABINS) eta = NETABINS-1;
225 
226  float maxPt_dEta12 = solve(ptHyp, dEta12, gdEta12_Cut__[eta]); // Get the best PT using dPhiAB corridors.
227  float maxPt_dEta23 = solve(ptHyp, dEta23, gdEta23_Cut__[eta]); // Get the best PT using dPhiAB corridors.
228  float maxPt_dEta34 = solve(ptHyp, dEta34, gdEta34_Cut__[eta]); // Get the best PT using dPhiAB corridors.
229 
230  // Now take the minimum of the four possible PT values.
231  float ptOut = ptHyp;
232 
233  if (maxPt_dEta12 < ptOut)
234  ptOut = maxPt_dEta12;
235  if (maxPt_dEta23 < ptOut)
236  ptOut = maxPt_dEta23;
237  if (maxPt_dEta34 < ptOut)
238  ptOut = maxPt_dEta34;
239 
240 
241 
242  return ptOut;
243 }
244 float getMaxPT_CLCT(float ptHyp, Int_t eta, float CLCT1, float CLCT2, float CLCT3, float CLCT4, int perCUT=100)
245 {
246  //cout << dPhi12 << " " << dPhi23 << " " << dPhi34 << endl;
247  if (!loaded__) // make sure the corridor TGraphs are loaded from the root files!
248  load();
249 
250  if (eta>NETABINS) eta = NETABINS-1;
251 
252  float maxPt_CLCT1 = solve(ptHyp, CLCT1, gCLCT1_Cut__[eta]); // Get the best PT using dPhiAB corridors.
253  float maxPt_CLCT2 = solve(ptHyp, CLCT2, gCLCT2_Cut__[eta]); // Get the best PT using dPhiAB corridors.
254  float maxPt_CLCT3 = solve(ptHyp, CLCT3, gCLCT3_Cut__[eta]); // Get the best PT using dPhiAB corridors.
255  float maxPt_CLCT4 = solve(ptHyp, CLCT4, gCLCT4_Cut__[eta]); // Get the best PT using dPhiAB corridors.
256 
257  // Now take the minimum of the four possible PT values.
258  float ptOut = ptHyp;
259 
260  if (maxPt_CLCT1 < ptOut)
261  ptOut = maxPt_CLCT1;
262  if (maxPt_CLCT2 < ptOut)
263  ptOut = maxPt_CLCT2;
264  if (maxPt_CLCT3 < ptOut)
265  ptOut = maxPt_CLCT3;
266  if (maxPt_CLCT4 < ptOut)
267  ptOut = maxPt_CLCT4;
268 
269  return ptOut;
270 }
271 
272 
273 // dumpTables just makes a text dump of the corridors as a function of PT. This may be useful
274 // when ported to CMSSW.
275 /*
276 float dumpTables()
277 {
278  int perDiff = 0;
279  for (int itr=0; itr<3; itr++)
280  {
281  if (itr==0) perDiff = 85;
282  if (itr==1) perDiff = 90;
283  if (itr==2) perDiff = 98;
284 
285  TString pd; pd+=perDiff;
286 
287  load(perDiff);
288  std::cout << std::endl;
289  std::cout << "Writing delta-Phi(MB1-MB2) tables for " << (100-perDiff) << " % tail clip" << std::endl;
290  ofstream file1("dPhi_Cut_12_" + pd + "percent.dat");
291  for (float pt_=0;pt_<=140; pt_+=0.5)
292  {
293  Int_t theBIN = hPT__->FindBin(pt_);
294  float cut = gdPhi_Cut__[0][1]->Eval(theBIN);
295  std::cout << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
296  file1 << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
297  }
298  std::cout << std::endl;
299  std::cout << "Writing delta-Phi(MB1-MB3) tables for " << (100-perDiff) << " % tail clip" << std::endl;
300  ofstream file2("dPhi_Cut_13_" + pd + "percent.dat");
301  for (float pt_=0;pt_<=140; pt_+=0.5)
302  {
303  Int_t theBIN = hPT__->FindBin(pt_);
304  float cut = gdPhi_Cut__[0][2]->Eval(theBIN);
305  std::cout << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
306  file2 << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
307  }
308  std::cout << std::endl;
309  std::cout << "Writing delta-Phi(MB1-MB4) tables for " << (100-perDiff) << " % tail clip" << std::endl;
310  ofstream file3("dPhi_Cut_14_" + pd + "percent.dat");
311  for (float pt_=0;pt_<=140; pt_+=0.5)
312  {
313  Int_t theBIN = hPT__->FindBin(pt_);
314  float cut = gdPhi_Cut__[0][3]->Eval(theBIN);
315  std::cout << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
316  file3 << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
317  }
318  std::cout << std::endl;
319  std::cout << "Writing delta-Phi(MB2-MB3) tables for " << (100-perDiff) << " % tail clip" << std::endl;
320  ofstream file4("dPhi_Cut_23_" + pd + "percent.dat");
321  for (float pt_=0;pt_<=140; pt_+=0.5)
322  {
323  Int_t theBIN = hPT__->FindBin(pt_);
324  float cut = gdPhi_Cut__[1][2]->Eval(theBIN);
325  std::cout << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
326  file4 << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
327  }
328  std::cout << std::endl;
329  std::cout << "Writing delta-Phi(MB2-MB4) tables for " << (100-perDiff) << " % tail clip" << std::endl;
330  ofstream file5("dPhi_Cut_24_" + pd + "percent.dat");
331  for (float pt_=0;pt_<=140; pt_+=0.5)
332  {
333  Int_t theBIN = hPT__->FindBin(pt_);
334  float cut = gdPhi_Cut__[1][3]->Eval(theBIN);
335  std::cout << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
336  file5 << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
337  }
338  std::cout << std::endl;
339  std::cout << "Writing delta-Phi(MB3-MB4) tables for " << (100-perDiff) << " % tail clip" << std::endl;
340  ofstream file6("dPhi_Cut_34_" + pd + "percent.dat");
341  for (float pt_=0;pt_<=140; pt_+=0.5)
342  {
343  Int_t theBIN = hPT__->FindBin(pt_);
344  float cut = gdPhi_Cut__[2][3]->Eval(theBIN);
345  std::cout << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
346  file6 << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
347  }
348 
349  std::cout << std::endl;
350  std::cout << "Writing Phib(MB1) tables for " << (100-perDiff) << " % tail clip" << std::endl;
351  ofstream file7("dPhib_Cut_1_" + pd + "percent.dat");
352  for (float pt_=0;pt_<=140; pt_+=0.5)
353  {
354  Int_t theBIN = hPT__->FindBin(pt_);
355  float cut = gPhib_Cut__[0]->Eval(theBIN);
356  std::cout << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
357  file7 << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
358  }
359  std::cout << std::endl;
360  std::cout << "Writing Phib(MB2) tables for " << (100-perDiff) << " % tail clip" << std::endl;
361  ofstream file8("dPhib_Cut_2_" + pd + "percent.dat");
362  for (float pt_=0;pt_<=140; pt_+=0.5)
363  {
364  Int_t theBIN = hPT__->FindBin(pt_);
365  float cut = gPhib_Cut__[1]->Eval(theBIN);
366  std::cout << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
367  file8 << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
368  }
369  std::cout << std::endl;
370  std::cout << "Writing Phib(MB4) tables for " << (100-perDiff) << " % tail clip" << std::endl;
371  ofstream file9("dPhib_Cut_4_" + pd + "percent.dat");
372  for (float pt_=0;pt_<=140; pt_+=0.5)
373  {
374  Int_t theBIN = hPT__->FindBin(pt_);
375  float cut = gPhib_Cut__[3]->Eval(theBIN);
376  std::cout << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
377  file9 << std::setw(10) << pt_ << std::setw(10) << cut << std::endl;
378  }
379 
380 
381  }
382 
383 }
384 */
float getMaxPT_dEta(float ptHyp, Int_t eta, float dEta12, float dEta23, float dEta34, int perCUT=100)
Definition: getMaxPt.h:218
int NETABITS
Definition: getMaxPt.h:37
TGraph * gCLCT1_Cut__[32]
Definition: getMaxPt.h:48
TGraph * gdEta34_Cut__[32]
Definition: getMaxPt.h:47
float getMaxPT(float ptHyp, Int_t eta, float dPhi12, float dPhi23, float dPhi34, int perCUT=100)
Definition: getMaxPt.h:192
float solve(float ptHyp, float val, TGraph *g)
Definition: getMaxPt.h:152
TGraph * gdPhi12_Cut__[32]
Definition: getMaxPt.h:42
TGraph * gdPhi23_Cut__[32]
Definition: getMaxPt.h:43
TGraph * gdEta23_Cut__[32]
Definition: getMaxPt.h:46
TGraph * gCLCT2_Cut__[32]
Definition: getMaxPt.h:49
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
float getMaxPT_CLCT(float ptHyp, Int_t eta, float CLCT1, float CLCT2, float CLCT3, float CLCT4, int perCUT=100)
Definition: getMaxPt.h:244
int loaded__
Definition: getMaxPt.h:53
TGraph * gdEta12_Cut__[32]
Definition: getMaxPt.h:45
TGraph * gdPhi34_Cut__[32]
Definition: getMaxPt.h:44
TGraph * gCLCT3_Cut__[32]
Definition: getMaxPt.h:50
int j
Definition: DBlmapReader.cc:9
double f[11][100]
int NETABINS
Definition: getMaxPt.h:38
void load(int perCUT=90)
Definition: getMaxPt.h:59
TGraph * gCLCT4_Cut__[32]
Definition: getMaxPt.h:51
int NPTBins
Definition: getMaxPt.h:39
tuple cout
Definition: gather_cfg.py:145
TH1F * hPT__
Definition: getMaxPt.h:56