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 (TH2 *pass, TH2 *all, int massDimension, TProfile *&eff, TProfile *&effChi2, const TString &plotName="")
 
TString calculateEfficiency (TH3 *pass, TH3 *all, int massDimension, TProfile2D *&eff, TProfile2D *&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 23 of file GenericTnPFitter.h.

Constructor & Destructor Documentation

◆ AbstractFitter()

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

Definition at line 43 of file GenericTnPFitter.h.

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

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

◆ ~AbstractFitter()

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

Member Function Documentation

◆ calculateEfficiency() [1/2]

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

Definition at line 199 of file GenericTnPFitter.h.

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

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

◆ calculateEfficiency() [2/2]

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

Definition at line 90 of file GenericTnPFitter.h.

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

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

◆ fit()

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

◆ getChi2()

double dqmTnP::AbstractFitter::getChi2 ( )
inline

Definition at line 76 of file GenericTnPFitter.h.

76 { return chi2; }

References chi2.

Referenced by calculateEfficiency().

◆ getEfficiency()

double dqmTnP::AbstractFitter::getEfficiency ( )
inline

Definition at line 74 of file GenericTnPFitter.h.

74 { return efficiency.getVal(); }

References efficiency.

Referenced by calculateEfficiency().

◆ getEfficiencyError()

double dqmTnP::AbstractFitter::getEfficiencyError ( )
inline

Definition at line 75 of file GenericTnPFitter.h.

75 { return efficiency.getError(); }

References efficiency.

Referenced by calculateEfficiency().

◆ savePlot()

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

Definition at line 77 of file GenericTnPFitter.h.

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

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

Referenced by calculateEfficiency().

◆ setup()

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

Definition at line 67 of file GenericTnPFitter.h.

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

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

Referenced by DQMGenericTnPClient::calculateEfficiency().

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 33 of file GenericTnPFitter.h.

◆ nSignalPass

RooFormulaVar dqmTnP::AbstractFitter::nSignalPass
protected

Definition at line 32 of file GenericTnPFitter.h.

◆ sigma

RooRealVar dqmTnP::AbstractFitter::sigma
protected

◆ simPdf

RooSimultaneous dqmTnP::AbstractFitter::simPdf
protected

◆ verbose

bool dqmTnP::AbstractFitter::verbose
protected
dqmTnP::AbstractFitter::nSignalPass
RooFormulaVar nSignalPass
Definition: GenericTnPFitter.h:32
dqmTnP::AbstractFitter::nBackgroundPass
RooRealVar nBackgroundPass
Definition: GenericTnPFitter.h:35
dqmTnP::AbstractFitter::simPdf
RooSimultaneous simPdf
Definition: GenericTnPFitter.h:37
mps_fire.i
i
Definition: mps_fire.py:428
SiStripClientConfig_Tier0_cff.Name
Name
Definition: SiStripClientConfig_Tier0_cff.py:12
dqmTnP::AbstractFitter::expectedMean
double expectedMean
Definition: GenericTnPFitter.h:27
EgHLTOffHistBins_cfi.massHigh
massHigh
Definition: EgHLTOffHistBins_cfi.py:35
dqmTnP::AbstractFitter::nSignalAll
RooRealVar nSignalAll
Definition: GenericTnPFitter.h:31
dqmTnP::AbstractFitter::mass
RooRealVar mass
Definition: GenericTnPFitter.h:25
pfMETCorrectionType0_cfi.par1
par1
Definition: pfMETCorrectionType0_cfi.py:48
dqmTnP::AbstractFitter::getEfficiency
double getEfficiency()
Definition: GenericTnPFitter.h:74
python.cmstools.all
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
dqmTnP::AbstractFitter::nBackgroundFail
RooRealVar nBackgroundFail
Definition: GenericTnPFitter.h:34
dqmTnP::AbstractFitter::verbose
bool verbose
Definition: GenericTnPFitter.h:40
dqmTnP::AbstractFitter::savePlot
void savePlot(const TString &name)
Definition: GenericTnPFitter.h:77
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
L1TEGammaDiff_cfi.plotName
plotName
Definition: L1TEGammaDiff_cfi.py:20
dqmTnP::AbstractFitter::mean
RooRealVar mean
Definition: GenericTnPFitter.h:26
dqmTnP::AbstractFitter::efficiency
RooRealVar efficiency
Definition: GenericTnPFitter.h:30
dqmTnP::AbstractFitter::nSignalFail
RooFormulaVar nSignalFail
Definition: GenericTnPFitter.h:33
dqmTnP::AbstractFitter::data
RooDataHist * data
Definition: GenericTnPFitter.h:38
pfMETCorrectionType0_cfi.par2
par2
Definition: pfMETCorrectionType0_cfi.py:49
dqmTnP::AbstractFitter::category
RooCategory category
Definition: GenericTnPFitter.h:36
dqmTnP::AbstractFitter::getChi2
double getChi2()
Definition: GenericTnPFitter.h:76
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
dqmTnP::AbstractFitter::getEfficiencyError
double getEfficiencyError()
Definition: GenericTnPFitter.h:75
dqmTnP::AbstractFitter::expectedSigma
double expectedSigma
Definition: GenericTnPFitter.h:29
dqmTnP::AbstractFitter::fit
virtual void fit(TH1 *num, TH1 *den)=0
amptDefault_cfi.frame
frame
Definition: amptDefault_cfi.py:12
dqmTnP::AbstractFitter::chi2
double chi2
Definition: GenericTnPFitter.h:39
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
dqmTnP::AbstractFitter::sigma
RooRealVar sigma
Definition: GenericTnPFitter.h:28