CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes
dqmTnP::AbstractFitter Class Referenceabstract

#include <GenericTnPFitter.h>

Inheritance diagram for dqmTnP::AbstractFitter:
dqmTnP::GaussianPlusLinearFitter dqmTnP::VoigtianPlusExponentialFitter

Public Member Functions

 AbstractFitter (bool verbose_=false)
 
TString calculateEfficiency (TH3 *pass, TH3 *all, int massDimension, TProfile2D *&eff, TProfile2D *&effChi2, const TString &plotName="")
 
TString calculateEfficiency (TH2 *pass, TH2 *all, int massDimension, TProfile *&eff, TProfile *&effChi2, const TString &plotName="")
 
virtual void fit (TH1 *num, TH1 *den)=0
 
double getChi2 ()
 
double getEfficiency ()
 
double getEfficiencyError ()
 
void savePlot (const TString &name)
 
void setup (double expectedMean_, double massLow, double massHigh, double expectedSigma_)
 
virtual ~AbstractFitter ()=default
 

Protected Attributes

RooCategory category
 
double chi2
 
RooDataHist * data
 
RooRealVar efficiency
 
double expectedMean
 
double expectedSigma
 
RooRealVar mass
 
RooRealVar mean
 
RooRealVar nBackgroundFail
 
RooRealVar nBackgroundPass
 
RooRealVar nSignalAll
 
RooFormulaVar nSignalFail
 
RooFormulaVar nSignalPass
 
RooRealVar sigma
 
RooSimultaneous simPdf
 
bool verbose
 

Detailed Description

Definition at line 22 of file GenericTnPFitter.h.

Constructor & Destructor Documentation

◆ AbstractFitter()

dqmTnP::AbstractFitter::AbstractFitter ( bool  verbose_ = false)
inline

Definition at line 42 of file GenericTnPFitter.h.

References category, mps_fire::i, instance, and verbose.

43  : mass("mass", "mass", 0., 100., "GeV"),
44  mean("mean", "mean", 0., 100., "GeV"),
45  sigma("sigma", "sigma", 0., 100., "GeV"),
46  efficiency("efficiency", "efficiency", 0.5, 0.0, 1.0),
47  nSignalAll("nSignalAll", "nSignalAll", 0., 1e10),
48  nSignalPass("nSignalPass", "nSignalAll*efficiency", RooArgList(nSignalAll, efficiency)),
49  nSignalFail("nSignalFail", "nSignalAll*(1-efficiency)", RooArgList(nSignalAll, efficiency)),
50  nBackgroundFail("nBackgroundFail", "nBackgroundFail", 0., 1e10),
51  nBackgroundPass("nBackgroundPass", "nBackgroundPass", 0., 1e10),
52  category("category", "category"),
53  simPdf("simPdf", "simPdf", category),
54  data(nullptr),
55  verbose(verbose_) {
56  //turn on/off default messaging of roofit
57  RooMsgService::instance().setSilentMode(!verbose ? kTRUE : kFALSE);
58  for (int i = 0; i < RooMsgService::instance().numStreams(); i++) {
59  RooMsgService::instance().setStreamStatus(i, verbose ? kTRUE : kFALSE);
60  }
61  category.defineType("pass");
62  category.defineType("fail");
63  };
static PFTauRenderPlugin instance
RooSimultaneous simPdf

◆ ~AbstractFitter()

virtual dqmTnP::AbstractFitter::~AbstractFitter ( )
virtualdefault

Member Function Documentation

◆ calculateEfficiency() [1/2]

TString dqmTnP::AbstractFitter::calculateEfficiency ( TH3 *  pass,
TH3 *  all,
int  massDimension,
TProfile2D *&  eff,
TProfile2D *&  effChi2,
const TString &  plotName = "" 
)
inline

Definition at line 89 of file GenericTnPFitter.h.

References python.cmstools::all(), fit(), getChi2(), getEfficiency(), getEfficiencyError(), mass, pfMETCorrectionType0_cfi::par1, pfMETCorrectionType0_cfi::par2, L1TEGammaDiff_cfi::plotName, savePlot(), and mathSSE::sqrt().

90  {
91  //sort out the TAxis
92  TAxis *par1Axis, *par2Axis, *massAxis;
93  int par1C, par2C, massC;
94  if (massDimension == 1) {
95  massAxis = all->GetXaxis();
96  massC = 1;
97  par1Axis = all->GetYaxis();
98  par1C = all->GetXaxis()->GetNbins() + 2;
99  par2Axis = all->GetZaxis();
100  par2C = (all->GetXaxis()->GetNbins() + 2) * (all->GetYaxis()->GetNbins() + 2);
101  } else if (massDimension == 2) {
102  par1Axis = all->GetXaxis();
103  par1C = 1;
104  massAxis = all->GetYaxis();
105  massC = all->GetXaxis()->GetNbins() + 2;
106  par2Axis = all->GetZaxis();
107  par2C = (all->GetXaxis()->GetNbins() + 2) * (all->GetYaxis()->GetNbins() + 2);
108  } else if (massDimension == 3) {
109  par1Axis = all->GetXaxis();
110  par1C = 1;
111  par2Axis = all->GetYaxis();
112  par2C = all->GetXaxis()->GetNbins() + 2;
113  massAxis = all->GetZaxis();
114  massC = (all->GetXaxis()->GetNbins() + 2) * (all->GetYaxis()->GetNbins() + 2);
115  } else {
116  return "massDimension > 3 !, skipping...";
117  }
118 
119  //create eff and effChi2 TProfiles
120  if (!par1Axis || !par2Axis)
121  return "No par1Axis or par2Axis!";
122  if (par1Axis->GetXbins()->GetSize() == 0 && par2Axis->GetXbins()->GetSize() == 0) {
123  eff = new TProfile2D("efficiency",
124  "efficiency",
125  par1Axis->GetNbins(),
126  par1Axis->GetXmin(),
127  par1Axis->GetXmax(),
128  par2Axis->GetNbins(),
129  par2Axis->GetXmin(),
130  par2Axis->GetXmax());
131  } else if (par1Axis->GetXbins()->GetSize() == 0) {
132  eff = new TProfile2D("efficiency",
133  "efficiency",
134  par1Axis->GetNbins(),
135  par1Axis->GetXmin(),
136  par1Axis->GetXmax(),
137  par2Axis->GetNbins(),
138  par2Axis->GetXbins()->GetArray());
139  } else if (par2Axis->GetXbins()->GetSize() == 0) {
140  eff = new TProfile2D("efficiency",
141  "efficiency",
142  par1Axis->GetNbins(),
143  par1Axis->GetXbins()->GetArray(),
144  par2Axis->GetNbins(),
145  par2Axis->GetXmin(),
146  par2Axis->GetXmax());
147  } else {
148  eff = new TProfile2D("efficiency",
149  "efficiency",
150  par1Axis->GetNbins(),
151  par1Axis->GetXbins()->GetArray(),
152  par2Axis->GetNbins(),
153  par2Axis->GetXbins()->GetArray());
154  }
155  eff->SetTitle("");
156  eff->SetXTitle(par1Axis->GetTitle());
157  eff->SetYTitle(par2Axis->GetTitle());
158  eff->SetStats(kFALSE);
159  effChi2 = (TProfile2D*)eff->Clone("efficiencyChi2");
160  eff->SetZTitle("Efficiency");
161  eff->SetOption("colztexte");
162  eff->GetZaxis()->SetRangeUser(-0.001, 1.001);
163  effChi2->SetZTitle("Chi^2/NDF");
164  effChi2->SetOption("colztext");
165 
166  //create the 1D mass distribution container histograms
167  TH1D* all1D = (massAxis->GetXbins()->GetSize() == 0)
168  ? new TH1D("all1D", "all1D", massAxis->GetNbins(), massAxis->GetXmin(), massAxis->GetXmax())
169  : new TH1D("all1D", "all1D", massAxis->GetNbins(), massAxis->GetXbins()->GetArray());
170  auto* pass1D = (TH1D*)all1D->Clone("pass1D");
171 
172  //for each parameter bin fit the mass distributions
173  for (int par1 = 1; par1 <= par1Axis->GetNbins(); par1++) {
174  for (int par2 = 1; par2 <= par2Axis->GetNbins(); par2++) {
175  for (int mass = 1; mass <= massAxis->GetNbins(); mass++) {
176  int index = par1 * par1C + par2 * par2C + mass * massC;
177  all1D->SetBinContent(mass, all->GetBinContent(index));
178  pass1D->SetBinContent(mass, pass->GetBinContent(index));
179  }
180  fit(pass1D, all1D);
181  int index = par1 + par2 * (par1Axis->GetNbins() + 2);
182  eff->SetBinContent(index, getEfficiency());
183  eff->SetBinEntries(index, 1);
184  eff->SetBinError(index,
186  effChi2->SetBinContent(index, getChi2());
187  effChi2->SetBinEntries(index, 1);
188  if (plotName != "") {
189  savePlot(TString::Format("%s_%d_%d", plotName.Data(), par1, par2));
190  }
191  }
192  }
193  delete all1D;
194  delete pass1D;
195  return ""; //OK
196  }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
void savePlot(const TString &name)
T sqrt(T t)
Definition: SSEVec.h:19
virtual void fit(TH1 *num, TH1 *den)=0

◆ calculateEfficiency() [2/2]

TString dqmTnP::AbstractFitter::calculateEfficiency ( TH2 *  pass,
TH2 *  all,
int  massDimension,
TProfile *&  eff,
TProfile *&  effChi2,
const TString &  plotName = "" 
)
inline

Definition at line 198 of file GenericTnPFitter.h.

References python.cmstools::all(), fit(), getChi2(), getEfficiency(), getEfficiencyError(), mass, pfMETCorrectionType0_cfi::par1, L1TEGammaDiff_cfi::plotName, savePlot(), and mathSSE::sqrt().

199  {
200  //sort out the TAxis
201  TAxis *par1Axis, *massAxis;
202  int par1C, massC;
203  if (massDimension == 1) {
204  massAxis = all->GetXaxis();
205  massC = 1;
206  par1Axis = all->GetYaxis();
207  par1C = all->GetXaxis()->GetNbins() + 2;
208  } else if (massDimension == 2) {
209  par1Axis = all->GetXaxis();
210  par1C = 1;
211  massAxis = all->GetYaxis();
212  massC = all->GetXaxis()->GetNbins() + 2;
213  } else {
214  return "massDimension > 2 !, skipping...";
215  }
216 
217  //create eff and effChi2 TProfiles
218  if (!par1Axis)
219  return "No par1Axis!";
220  eff =
221  (par1Axis->GetXbins()->GetSize() == 0)
222  ? new TProfile("efficiency", "efficiency", par1Axis->GetNbins(), par1Axis->GetXmin(), par1Axis->GetXmax())
223  : new TProfile("efficiency", "efficiency", par1Axis->GetNbins(), par1Axis->GetXbins()->GetArray());
224  eff->SetTitle("");
225  eff->SetXTitle(par1Axis->GetTitle());
226  eff->SetLineColor(2);
227  eff->SetLineWidth(2);
228  eff->SetMarkerStyle(20);
229  eff->SetMarkerSize(0.8);
230  eff->SetStats(kFALSE);
231  effChi2 = (TProfile*)eff->Clone("efficiencyChi2");
232  eff->SetYTitle("Efficiency");
233  eff->SetOption("PE");
234  eff->GetYaxis()->SetRangeUser(-0.001, 1.001);
235  effChi2->SetYTitle("Chi^2/NDF");
236  effChi2->SetOption("HIST");
237 
238  //create the 1D mass distribution container histograms
239  TH1D* all1D = (massAxis->GetXbins()->GetSize() == 0)
240  ? new TH1D("all1D", "all1D", massAxis->GetNbins(), massAxis->GetXmin(), massAxis->GetXmax())
241  : new TH1D("all1D", "all1D", massAxis->GetNbins(), massAxis->GetXbins()->GetArray());
242  auto* pass1D = (TH1D*)all1D->Clone("pass1D");
243 
244  //for each parameter bin fit the mass distributions
245  for (int par1 = 1; par1 <= par1Axis->GetNbins(); par1++) {
246  for (int mass = 1; mass <= massAxis->GetNbins(); mass++) {
247  int index = par1 * par1C + mass * massC;
248  all1D->SetBinContent(mass, all->GetBinContent(index));
249  pass1D->SetBinContent(mass, pass->GetBinContent(index));
250  }
251  fit(pass1D, all1D);
252  int index = par1;
253  eff->SetBinContent(index, getEfficiency());
254  eff->SetBinEntries(index, 1);
256  effChi2->SetBinContent(index, getChi2());
257  effChi2->SetBinEntries(index, 1);
258  if (plotName != "") {
259  savePlot(TString::Format("%s_%d", plotName.Data(), par1));
260  }
261  }
262  delete all1D;
263  delete pass1D;
264  return ""; //OK
265  }
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
void savePlot(const TString &name)
T sqrt(T t)
Definition: SSEVec.h:19
virtual void fit(TH1 *num, TH1 *den)=0

◆ fit()

virtual void dqmTnP::AbstractFitter::fit ( TH1 *  num,
TH1 *  den 
)
pure virtual

◆ getChi2()

double dqmTnP::AbstractFitter::getChi2 ( )
inline

Definition at line 75 of file GenericTnPFitter.h.

References chi2.

Referenced by calculateEfficiency().

75 { return chi2; }

◆ getEfficiency()

double dqmTnP::AbstractFitter::getEfficiency ( )
inline

Definition at line 73 of file GenericTnPFitter.h.

References efficiency.

Referenced by calculateEfficiency().

73 { return efficiency.getVal(); }

◆ getEfficiencyError()

double dqmTnP::AbstractFitter::getEfficiencyError ( )
inline

Definition at line 74 of file GenericTnPFitter.h.

References efficiency.

Referenced by calculateEfficiency().

74 { return efficiency.getError(); }

◆ savePlot()

void dqmTnP::AbstractFitter::savePlot ( const TString &  name)
inline

Definition at line 76 of file GenericTnPFitter.h.

References category, data, amptDefault_cfi::frame, mass, SiStripClientConfig_Tier0_cff::Name, Skims_PA_cff::name, and simPdf.

Referenced by calculateEfficiency().

76  {
77  using namespace RooFit;
78  RooPlot* frame = mass.frame(Name(name), Title("Failing and Passing Probe Distributions"));
79  data->plotOn(frame, Cut("category==category::pass"), LineColor(kGreen), MarkerColor(kGreen));
80  data->plotOn(frame, Cut("category==category::fail"), LineColor(kRed), MarkerColor(kRed));
81  simPdf.plotOn(frame, Slice(category, "pass"), ProjWData(category, *data), LineColor(kGreen));
82  simPdf.plotOn(frame, Slice(category, "fail"), ProjWData(category, *data), LineColor(kRed));
83  simPdf.paramOn(frame, Layout(0.58, 0.99, 0.99));
84  data->statOn(frame, Layout(0.70, 0.99, 0.5));
85  frame->Write();
86  delete frame;
87  }
RooSimultaneous simPdf

◆ setup()

void dqmTnP::AbstractFitter::setup ( double  expectedMean_,
double  massLow,
double  massHigh,
double  expectedSigma_ 
)
inline

Definition at line 66 of file GenericTnPFitter.h.

References expectedMean, expectedSigma, mass, EgHLTOffHistBins_cfi::massHigh, and mean.

Referenced by DQMGenericTnPClient::calculateEfficiency().

66  {
67  expectedMean = expectedMean_;
68  expectedSigma = expectedSigma_;
69  mass.setRange(massLow, massHigh);
70  mean.setRange(massLow, massHigh);
71  }

Member Data Documentation

◆ category

RooCategory dqmTnP::AbstractFitter::category
protected

◆ chi2

double dqmTnP::AbstractFitter::chi2
protected

◆ data

RooDataHist* dqmTnP::AbstractFitter::data
protected

◆ efficiency

RooRealVar dqmTnP::AbstractFitter::efficiency
protected

◆ expectedMean

double dqmTnP::AbstractFitter::expectedMean
protected

◆ expectedSigma

double dqmTnP::AbstractFitter::expectedSigma
protected

◆ mass

RooRealVar dqmTnP::AbstractFitter::mass
protected

◆ mean

RooRealVar dqmTnP::AbstractFitter::mean
protected

◆ nBackgroundFail

RooRealVar dqmTnP::AbstractFitter::nBackgroundFail
protected

◆ nBackgroundPass

RooRealVar dqmTnP::AbstractFitter::nBackgroundPass
protected

◆ nSignalAll

RooRealVar dqmTnP::AbstractFitter::nSignalAll
protected

◆ nSignalFail

RooFormulaVar dqmTnP::AbstractFitter::nSignalFail
protected

Definition at line 32 of file GenericTnPFitter.h.

◆ nSignalPass

RooFormulaVar dqmTnP::AbstractFitter::nSignalPass
protected

Definition at line 31 of file GenericTnPFitter.h.

◆ sigma

RooRealVar dqmTnP::AbstractFitter::sigma
protected

◆ simPdf

RooSimultaneous dqmTnP::AbstractFitter::simPdf
protected

◆ verbose

bool dqmTnP::AbstractFitter::verbose
protected