CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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, TString plotName="")
 
TString calculateEfficiency (TH2 *pass, TH2 *all, int massDimension, TProfile *&eff, TProfile *&effChi2, 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 ()
 

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

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

Definition at line 43 of file GenericTnPFitter.h.

References category, i, and instance.

43  :
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(0),
56  verbose(verbose_)
57  {
58  //turn on/off default messaging of roofit
59  RooMsgService::instance().setSilentMode( !verbose?kTRUE:kFALSE );
60  for(int i=0; i<RooMsgService::instance().numStreams(); i++){
61  RooMsgService::instance().setStreamStatus( i, verbose?kTRUE:kFALSE );
62  }
63  category.defineType("pass");
64  category.defineType("fail");
65  };
int i
Definition: DBlmapReader.cc:9
static PFTauRenderPlugin instance
RooSimultaneous simPdf
virtual dqmTnP::AbstractFitter::~AbstractFitter ( )
inlinevirtual

Definition at line 66 of file GenericTnPFitter.h.

66 {};

Member Function Documentation

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

Definition at line 90 of file GenericTnPFitter.h.

References fit(), getChi2(), getEfficiency(), getEfficiencyError(), cmsHarvester::index, mass, 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) return "No par1Axis or par2Axis!";
121  if( par1Axis->GetXbins()->GetSize()==0 && par2Axis->GetXbins()->GetSize()==0 ){
122  eff = new TProfile2D("efficiency","efficiency",par1Axis->GetNbins(),par1Axis->GetXmin(),par1Axis->GetXmax(),par2Axis->GetNbins(),par2Axis->GetXmin(),par2Axis->GetXmax());
123  }else if( par1Axis->GetXbins()->GetSize()==0 ){
124  eff = new TProfile2D("efficiency","efficiency",par1Axis->GetNbins(),par1Axis->GetXmin(),par1Axis->GetXmax(),par2Axis->GetNbins(),par2Axis->GetXbins()->GetArray());
125  }else if( par2Axis->GetXbins()->GetSize()==0 ){
126  eff = new TProfile2D("efficiency","efficiency",par1Axis->GetNbins(),par1Axis->GetXbins()->GetArray(),par2Axis->GetNbins(),par2Axis->GetXmin(),par2Axis->GetXmax());
127  }else{
128  eff = new TProfile2D("efficiency","efficiency",par1Axis->GetNbins(),par1Axis->GetXbins()->GetArray(),par2Axis->GetNbins(),par2Axis->GetXbins()->GetArray());
129  }
130  eff->SetTitle("");
131  eff->SetXTitle( par1Axis->GetTitle() );
132  eff->SetYTitle( par2Axis->GetTitle() );
133  eff->SetStats(kFALSE);
134  effChi2 = (TProfile2D*)eff->Clone("efficiencyChi2");
135  eff->SetZTitle("Efficiency");
136  eff->SetOption("colztexte");
137  eff->GetZaxis()->SetRangeUser(-0.001,1.001);
138  effChi2->SetZTitle("Chi^2/NDF");
139  effChi2->SetOption("colztext");
140 
141  //create the 1D mass distribution container histograms
142  TH1D* all1D = (massAxis->GetXbins()->GetSize()==0) ?
143  new TH1D("all1D","all1D",massAxis->GetNbins(),massAxis->GetXmin(),massAxis->GetXmax()):
144  new TH1D("all1D","all1D",massAxis->GetNbins(),massAxis->GetXbins()->GetArray());
145  TH1D* pass1D = (TH1D *)all1D->Clone("pass1D");
146 
147  //for each parameter bin fit the mass distributions
148  for(int par1=1; par1<=par1Axis->GetNbins(); par1++){
149  for(int par2=1; par2<=par2Axis->GetNbins(); par2++){
150  for(int mass=1; mass<=massAxis->GetNbins(); mass++){
151  int index = par1*par1C + par2*par2C + mass*massC;
152  all1D->SetBinContent(mass,all->GetBinContent(index));
153  pass1D->SetBinContent(mass,pass->GetBinContent(index));
154  }
155  fit( pass1D, all1D );
156  int index = par1 + par2*(par1Axis->GetNbins()+2);
157  eff->SetBinContent( index, getEfficiency() );
158  eff->SetBinEntries( index, 1 );
159  eff->SetBinError( index, sqrt( getEfficiency()*getEfficiency() + getEfficiencyError()*getEfficiencyError() ) );
160  effChi2->SetBinContent( index, getChi2() );
161  effChi2->SetBinEntries( index, 1 );
162  if(plotName!=""){
163  savePlot( TString::Format("%s_%d_%d",plotName.Data(),par1,par2) );
164  }
165  }
166  }
167  delete all1D;
168  delete pass1D;
169  return "";//OK
170  }
void savePlot(const TString &name)
T sqrt(T t)
Definition: SSEVec.h:48
virtual void fit(TH1 *num, TH1 *den)=0
TString dqmTnP::AbstractFitter::calculateEfficiency ( TH2 *  pass,
TH2 *  all,
int  massDimension,
TProfile *&  eff,
TProfile *&  effChi2,
TString  plotName = "" 
)
inline

Definition at line 172 of file GenericTnPFitter.h.

References fit(), getChi2(), getEfficiency(), getEfficiencyError(), cmsHarvester::index, mass, savePlot(), and mathSSE::sqrt().

172  {
173  //sort out the TAxis
174  TAxis *par1Axis, *massAxis;
175  int par1C, massC;
176  if(massDimension==1){
177  massAxis = all->GetXaxis();
178  massC = 1;
179  par1Axis = all->GetYaxis();
180  par1C = all->GetXaxis()->GetNbins()+2;
181  }else if(massDimension==2){
182  par1Axis = all->GetXaxis();
183  par1C = 1;
184  massAxis = all->GetYaxis();
185  massC = all->GetXaxis()->GetNbins()+2;
186  }else{
187  return "massDimension > 2 !, skipping...";
188  }
189 
190  //create eff and effChi2 TProfiles
191  if(!par1Axis) return "No par1Axis!";
192  eff = (par1Axis->GetXbins()->GetSize()==0)?
193  new TProfile("efficiency","efficiency",par1Axis->GetNbins(),par1Axis->GetXmin(),par1Axis->GetXmax()):
194  new TProfile("efficiency","efficiency",par1Axis->GetNbins(),par1Axis->GetXbins()->GetArray());
195  eff->SetTitle("");
196  eff->SetXTitle( par1Axis->GetTitle() );
197  eff->SetLineColor(2);
198  eff->SetLineWidth(2);
199  eff->SetMarkerStyle(20);
200  eff->SetMarkerSize(0.8);
201  eff->SetStats(kFALSE);
202  effChi2 = (TProfile*)eff->Clone("efficiencyChi2");
203  eff->SetYTitle("Efficiency");
204  eff->SetOption("PE");
205  eff->GetYaxis()->SetRangeUser(-0.001,1.001);
206  effChi2->SetYTitle("Chi^2/NDF");
207  effChi2->SetOption("HIST");
208 
209  //create the 1D mass distribution container histograms
210  TH1D * all1D = (massAxis->GetXbins()->GetSize()==0) ?
211  new TH1D("all1D","all1D",massAxis->GetNbins(),massAxis->GetXmin(),massAxis->GetXmax()):
212  new TH1D("all1D","all1D",massAxis->GetNbins(),massAxis->GetXbins()->GetArray());
213  TH1D * pass1D = (TH1D *)all1D->Clone("pass1D");
214 
215  //for each parameter bin fit the mass distributions
216  for(int par1=1; par1<=par1Axis->GetNbins(); par1++){
217  for(int mass=1; mass<=massAxis->GetNbins(); mass++){
218  int index = par1*par1C + mass*massC;
219  all1D->SetBinContent(mass,all->GetBinContent(index));
220  pass1D->SetBinContent(mass,pass->GetBinContent(index));
221  }
222  fit( pass1D, all1D );
223  int index = par1;
224  eff->SetBinContent( index, getEfficiency() );
225  eff->SetBinEntries( index, 1 );
226  eff->SetBinError( index, sqrt( getEfficiency()*getEfficiency() + getEfficiencyError()*getEfficiencyError() ) );
227  effChi2->SetBinContent( index, getChi2() );
228  effChi2->SetBinEntries( index, 1 );
229  if(plotName!=""){
230  savePlot( TString::Format("%s_%d",plotName.Data(),par1) );
231  }
232  }
233  delete all1D;
234  delete pass1D;
235  return "";//OK
236  }
void savePlot(const TString &name)
T sqrt(T t)
Definition: SSEVec.h:48
virtual void fit(TH1 *num, TH1 *den)=0
virtual void dqmTnP::AbstractFitter::fit ( TH1 *  num,
TH1 *  den 
)
pure virtual
double dqmTnP::AbstractFitter::getChi2 ( )
inline

Definition at line 76 of file GenericTnPFitter.h.

References chi2.

Referenced by calculateEfficiency().

76 { return chi2; }
double dqmTnP::AbstractFitter::getEfficiency ( )
inline

Definition at line 74 of file GenericTnPFitter.h.

References efficiency.

Referenced by calculateEfficiency().

74 { return efficiency.getVal(); }
double dqmTnP::AbstractFitter::getEfficiencyError ( )
inline

Definition at line 75 of file GenericTnPFitter.h.

References efficiency.

Referenced by calculateEfficiency().

75 { return efficiency.getError(); }
void dqmTnP::AbstractFitter::savePlot ( const TString &  name)
inline

Definition at line 77 of file GenericTnPFitter.h.

References category, data, mass, and simPdf.

Referenced by calculateEfficiency().

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  }
RooSimultaneous simPdf
void dqmTnP::AbstractFitter::setup ( double  expectedMean_,
double  massLow,
double  massHigh,
double  expectedSigma_ 
)
inline

Definition at line 67 of file GenericTnPFitter.h.

References expectedMean, expectedSigma, mass, and mean.

Referenced by DQMGenericTnPClient::calculateEfficiency().

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

Member Data Documentation

RooCategory dqmTnP::AbstractFitter::category
protected
double dqmTnP::AbstractFitter::chi2
protected
RooDataHist* dqmTnP::AbstractFitter::data
protected
RooRealVar dqmTnP::AbstractFitter::efficiency
protected
double dqmTnP::AbstractFitter::expectedMean
protected
double dqmTnP::AbstractFitter::expectedSigma
protected
RooRealVar dqmTnP::AbstractFitter::mass
protected
RooRealVar dqmTnP::AbstractFitter::mean
protected
RooRealVar dqmTnP::AbstractFitter::nBackgroundFail
protected
RooRealVar dqmTnP::AbstractFitter::nBackgroundPass
protected
RooRealVar dqmTnP::AbstractFitter::nSignalAll
protected
RooFormulaVar dqmTnP::AbstractFitter::nSignalFail
protected

Definition at line 33 of file GenericTnPFitter.h.

RooFormulaVar dqmTnP::AbstractFitter::nSignalPass
protected

Definition at line 32 of file GenericTnPFitter.h.

RooRealVar dqmTnP::AbstractFitter::sigma
protected
RooSimultaneous dqmTnP::AbstractFitter::simPdf
protected
bool dqmTnP::AbstractFitter::verbose
protected