CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes
ResidualFitter Class Reference

#include <ResidualFitter.h>

Inheritance diagram for ResidualFitter:

Classes

class  Point
 

Public Member Functions

void AddMeas (double x, double y, double z)
 
void AddTrue (double x, double y, double z)
 
void cd ()
 
void CreateCanvas ()
 
TH1D * CurBin ()
 
void ExecuteEvent (Int_t event, Int_t px, Int_t py, TObject *sel)
 
void Fill ()
 
void Fit (int x, int y, const char *opt="")
 
void FitSlicesZ (TF1 *f1=0)
 
TCanvas * GetCanvas ()
 
TF1 * GetFunction ()
 
 ResidualFitter (const char *name, const char *title, int nbinsx, double xlow, double xup, int nbinsy, double ylow, double yup, int nbinsz, double zlow, double zup)
 
void SetAutoRange (int n)
 
void SetFitFunction (TF1 *func)
 
void SetFitOptions (const char *opt)
 
void SetMinN (int n)
 
void ShowFit (TH2 *h2d, double x, double y)
 
 ~ResidualFitter ()
 

Static Public Member Functions

static void SetCanvas (int x, int y)
 

Private Attributes

int autoRangeN_
 
TCanvas * canvas_
 
TCanvas * canvasFit_
 
TH2D * chi2_
 
TH1D * curBin_
 
TF1 * fitFunction_
 
std::string fitOptions_
 
TH2D * mean_
 
std::vector
< ResidualFitter::Point
meas_
 
int minN_
 
int oldBinx_
 
int oldBiny_
 
TH2D * sigma_
 
std::vector
< ResidualFitter::Point
true_
 

Static Private Attributes

static int xCanvas_ = 600
 
static int yCanvas_ = 600
 

Detailed Description

Definition at line 11 of file ResidualFitter.h.

Constructor & Destructor Documentation

ResidualFitter::ResidualFitter ( const char *  name,
const char *  title,
int  nbinsx,
double  xlow,
double  xup,
int  nbinsy,
double  ylow,
double  yup,
int  nbinsz,
double  zlow,
double  zup 
)

Definition at line 21 of file ResidualFitter.cc.

References chi2_, gather_cfg::cout, CreateCanvas(), mean_, mergeVDriftHistosByStation::name, and sigma_.

26  : TH3D( name, title,
27  nbinsx, xlow, xup,
28  nbinsy, ylow, yup,
29  nbinsz, zlow, zup ),
30  fitFunction_( new TF1("gaus", "gaus") ),
31  canvasFit_(0),
32  curBin_(0),
33  autoRangeN_(0),
34  minN_(5) {
35 
36  cout<<"creating residual fitter with name "<<name<<endl;
37 
38  string meanname = name; meanname += "_mean";
39  mean_ = new TH2D(meanname.c_str(), meanname.c_str(),
40  nbinsx, xlow, xup,
41  nbinsy, ylow, yup);
42  mean_->SetStats(0);
43 
44  string sigmaname = name; sigmaname += "_sigma";
45  sigma_ = new TH2D(sigmaname.c_str(), sigmaname.c_str(),
46  nbinsx, xlow, xup,
47  nbinsy, ylow, yup);
48 
49  sigma_->SetStats(0);
50 
51  string chi2name = name; chi2name += "_chi2";
52  chi2_ = new TH2D(chi2name.c_str(), chi2name.c_str(),
53  nbinsx, xlow, xup,
54  nbinsy, ylow, yup);
55  chi2_->SetStats(0);
56 
57  // string nseenname = name; nseenname += "_nseen";
58  // nseen_ = new TH2D(nseenname.c_str(), nseenname.c_str(),
59  // nbinsx, xlow, xup,
60  // nbinsy, ylow, yup);
61  // nseen_->SetStats(0);
62 
63  gDirectory->ls();
64 
65  CreateCanvas();
66 }
TCanvas * canvasFit_
tuple cout
Definition: gather_cfg.py:121
ResidualFitter::~ResidualFitter ( )

Definition at line 68 of file ResidualFitter.cc.

References canvas_, chi2_, curBin_, fitFunction_, mean_, and sigma_.

68  {
69  delete fitFunction_;
70  if(canvas_) delete canvas_;
71  if(curBin_) delete curBin_;
72 
73  delete mean_;
74  delete sigma_;
75  delete chi2_;
76  // delete nseen_;
77 }
TCanvas * canvas_

Member Function Documentation

void ResidualFitter::AddMeas ( double  x,
double  y,
double  z 
)
inline

Definition at line 29 of file ResidualFitter.h.

References meas_.

30  {meas_.push_back( Point(x,y,z) ); }
std::pair< double, double > Point
Definition: CaloEllipse.h:18
float float float z
std::vector< ResidualFitter::Point > meas_
Definition: DDAxes.h:10
void ResidualFitter::AddTrue ( double  x,
double  y,
double  z 
)
inline

Definition at line 27 of file ResidualFitter.h.

References true_.

28  {true_.push_back( Point(x,y,z) ); }
std::pair< double, double > Point
Definition: CaloEllipse.h:18
float float float z
std::vector< ResidualFitter::Point > true_
Definition: DDAxes.h:10
void ResidualFitter::cd ( void  )
inline
void ResidualFitter::CreateCanvas ( )

Definition at line 79 of file ResidualFitter.cc.

References canvas_, xCanvas_, and yCanvas_.

Referenced by ResidualFitter().

79  {
80  string cname = "ResidualFitterCanvas_"; cname += GetName();
81  canvas_ = new TCanvas(cname.c_str(), cname.c_str(),xCanvas_, yCanvas_);
82 
83  canvas_ ->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
84  "ResidualFitter",
85  this, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");
86 
87 
88 }
TCanvas * canvas_
static int xCanvas_
static int yCanvas_
TH1D* ResidualFitter::CurBin ( )
inline

Definition at line 53 of file ResidualFitter.h.

References curBin_.

53 {return curBin_;}
void ResidualFitter::ExecuteEvent ( Int_t  event,
Int_t  px,
Int_t  py,
TObject *  sel 
)

Definition at line 124 of file ResidualFitter.cc.

References canvas_, EgammaValidation_Wenu_cff::sel, ShowFit(), x, and detailsBasic3DVector::y.

124  {
125 
126  if( event != kButton1Down ) return;
127 
128  TH2* histo2d = dynamic_cast<TH2*>(sel);
129  if(!histo2d) return;
130 
131  float x = canvas_->AbsPixeltoX(px);
132  float y = canvas_->AbsPixeltoY(py);
133  x = canvas_->PadtoX(x);
134  y = canvas_->PadtoY(y);
135 
136  ShowFit(histo2d, x, y);
137 }
TCanvas * canvas_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
Definition: DDAxes.h:10
void ShowFit(TH2 *h2d, double x, double y)
void ResidualFitter::Fill ( )

Definition at line 91 of file ResidualFitter.cc.

References HcalObjRepresent::Fill(), meas_, HcalObjRepresent::Reset(), and true_.

91  {
92 
93  Reset();
94 
95  for(unsigned it = 0; it<true_.size(); it++) {
96  for(unsigned im = 0; im<meas_.size(); im++) {
97  TH3D::Fill(true_[it].x_,
98  true_[it].y_,
99  meas_[it].z_ - true_[it].z_ );
100  }
101  }
102 }
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
std::vector< ResidualFitter::Point > true_
std::vector< ResidualFitter::Point > meas_
void Reset(std::vector< TH2F > &depth)
void ResidualFitter::Fit ( int  x,
int  y,
const char *  opt = "" 
)

Definition at line 166 of file ResidualFitter.cc.

References autoRangeN_, chi2_, gather_cfg::cout, curBin_, fitFunction_, fitOptions_, mean_, minN_, and sigma_.

Referenced by FitSlicesZ(), and ShowFit().

166  {
167  TH1::AddDirectory(0);
168 
169  if(curBin_) delete curBin_;
170  curBin_ = TH3::ProjectionZ("", binx, binx, biny, biny);
171 
172  if(curBin_->GetEntries() < minN_ ) {
173  TH1::AddDirectory(1);
174  return;
175  }
176 
177  string sopt = fitOptions_; sopt += opt;
178 
179  if( autoRangeN_ ) {
180  double maxpos = curBin_->GetBinCenter( curBin_->GetMaximumBin() );
181 
182  double minrange = maxpos-curBin_->GetRMS()* autoRangeN_;
183  double maxrange = maxpos+curBin_->GetRMS()* autoRangeN_;
184 
185  fitFunction_->SetRange( minrange, maxrange );
186  cout<<"range : "<<minrange<<" "<<maxrange<<endl;
187  }
188 
189  curBin_->Fit(fitFunction_, sopt.c_str() );
190 
191 
192  double chi2overndf=0;
193  if(fitFunction_->GetNDF() ) {
194  chi2overndf = fitFunction_->GetChisquare()/ fitFunction_->GetNDF();
195  mean_->SetBinContent(binx,biny, fitFunction_->GetParameter(1) );
196  mean_->SetBinError(binx,biny, fitFunction_->GetParError(1) );
197  sigma_->SetBinContent(binx,biny, fitFunction_->GetParameter(2) );
198  sigma_->SetBinError(binx,biny, fitFunction_->GetParError(2) );
199 
200  chi2_->SetBinContent(binx,biny,chi2overndf);
201  }
202  // nseen_->SetBinContent(binx, biny,
203  // fitFunction_->Integral( fitFunction_->GetXmin(),
204  // fitFunction_->GetXmax())
205  // /curBin_->GetBinWidth(1) );
206 
207  TH1::AddDirectory(1);
208 }
std::string fitOptions_
tuple cout
Definition: gather_cfg.py:121
void ResidualFitter::FitSlicesZ ( TF1 *  f1 = 0)

Definition at line 104 of file ResidualFitter.cc.

References chi2_, gather_cfg::cout, Fit(), mean_, SetFitFunction(), and sigma_.

104  {
105 
106  mean_->Reset();
107  sigma_->Reset();
108  chi2_->Reset();
109  // nseen_->Reset();
110 
111  cout<<"ResidualFitter::FitSlicesZ"<<endl;
112  if(f1) SetFitFunction(f1);
113 
114  for(int ix=1; ix<=GetNbinsX(); ix++) {
115  for(int iy=1; iy<=GetNbinsY(); iy++) {
116  Fit(ix, iy, "Q0");
117  }
118  }
119 
120  // TH3D::FitSlicesZ(f1);
121 }
void Fit(int x, int y, const char *opt="")
void SetFitFunction(TF1 *func)
tuple cout
Definition: gather_cfg.py:121
TCanvas* ResidualFitter::GetCanvas ( )
inline

Definition at line 55 of file ResidualFitter.h.

References canvas_.

55 {return canvas_;}
TCanvas * canvas_
TF1* ResidualFitter::GetFunction ( )
inline

Definition at line 51 of file ResidualFitter.h.

References fitFunction_.

51 {return fitFunction_;}
void ResidualFitter::SetAutoRange ( int  n)
inline

Definition at line 42 of file ResidualFitter.h.

References autoRangeN_, fitOptions_, and n.

42  {
43  autoRangeN_= n;
44  fitOptions_ += "R";
45  }
std::string fitOptions_
static void ResidualFitter::SetCanvas ( int  x,
int  y 
)
inlinestatic

Definition at line 24 of file ResidualFitter.h.

References x, xCanvas_, detailsBasic3DVector::y, and yCanvas_.

24 { xCanvas_=x; yCanvas_=y;}
static int xCanvas_
static int yCanvas_
Definition: DDAxes.h:10
void ResidualFitter::SetFitFunction ( TF1 *  func)
inline

Definition at line 33 of file ResidualFitter.h.

References fitFunction_, and statics::func.

Referenced by FitSlicesZ().

33 { fitFunction_ = func; }
string func
Definition: statics.py:48
void ResidualFitter::SetFitOptions ( const char *  opt)
inline

Definition at line 34 of file ResidualFitter.h.

References fitOptions_.

34 {fitOptions_ = opt; }
std::string fitOptions_
void ResidualFitter::SetMinN ( int  n)
inline

Definition at line 47 of file ResidualFitter.h.

References minN_, and n.

47 { minN_ = n;}
void ResidualFitter::ShowFit ( TH2 *  h2d,
double  x,
double  y 
)

Definition at line 140 of file ResidualFitter.cc.

References canvas_, canvasFit_, Fit(), oldBinx_, and oldBiny_.

Referenced by ExecuteEvent().

140  {
141 
142  if(!canvasFit_) {
143  string cname = "ResidualFitterCanvasFit_"; cname += GetName();
144  canvasFit_ = new TCanvas(cname.c_str(), cname.c_str(),300,300);
145  }
146  canvasFit_ ->cd();
147 
148  int binx = histo2d->GetXaxis()->FindBin(x);
149  int biny = histo2d->GetYaxis()->FindBin(y);
150 
151  if(binx == oldBinx_ && biny == oldBiny_ ) return;
152  oldBinx_ = binx;
153  oldBiny_ = biny;
154 
155  Fit(binx, biny);
156 
157  canvasFit_->Modified();
158  canvasFit_->Update();
159 
160  canvas_->Modified();
161  canvas_->Update();
162  canvas_->cd();
163 }
void Fit(int x, int y, const char *opt="")
TCanvas * canvas_
TCanvas * canvasFit_
Definition: DDAxes.h:10

Member Data Documentation

int ResidualFitter::autoRangeN_
private

Definition at line 94 of file ResidualFitter.h.

Referenced by Fit(), and SetAutoRange().

TCanvas* ResidualFitter::canvas_
private

Definition at line 77 of file ResidualFitter.h.

Referenced by cd(), CreateCanvas(), ExecuteEvent(), GetCanvas(), ShowFit(), and ~ResidualFitter().

TCanvas* ResidualFitter::canvasFit_
private

Definition at line 83 of file ResidualFitter.h.

Referenced by ShowFit().

TH2D* ResidualFitter::chi2_
private

Definition at line 88 of file ResidualFitter.h.

Referenced by Fit(), FitSlicesZ(), ResidualFitter(), and ~ResidualFitter().

TH1D* ResidualFitter::curBin_
private

Definition at line 85 of file ResidualFitter.h.

Referenced by CurBin(), Fit(), and ~ResidualFitter().

TF1* ResidualFitter::fitFunction_
private

Definition at line 74 of file ResidualFitter.h.

Referenced by Fit(), GetFunction(), SetFitFunction(), and ~ResidualFitter().

std::string ResidualFitter::fitOptions_
private

Definition at line 75 of file ResidualFitter.h.

Referenced by Fit(), SetAutoRange(), and SetFitOptions().

TH2D* ResidualFitter::mean_
private

Definition at line 86 of file ResidualFitter.h.

Referenced by Fit(), FitSlicesZ(), ResidualFitter(), and ~ResidualFitter().

std::vector< ResidualFitter::Point > ResidualFitter::meas_
private

Definition at line 72 of file ResidualFitter.h.

Referenced by AddMeas(), and Fill().

int ResidualFitter::minN_
private

if the number of entries in a bin is lower than this, fit is not performed. set to 5 by default.

Definition at line 98 of file ResidualFitter.h.

Referenced by Fit(), and SetMinN().

int ResidualFitter::oldBinx_
private

Definition at line 91 of file ResidualFitter.h.

Referenced by ShowFit().

int ResidualFitter::oldBiny_
private

Definition at line 92 of file ResidualFitter.h.

Referenced by ShowFit().

TH2D* ResidualFitter::sigma_
private

Definition at line 87 of file ResidualFitter.h.

Referenced by Fit(), FitSlicesZ(), ResidualFitter(), and ~ResidualFitter().

std::vector< ResidualFitter::Point > ResidualFitter::true_
private

Definition at line 71 of file ResidualFitter.h.

Referenced by AddTrue(), and Fill().

int ResidualFitter::xCanvas_ = 600
staticprivate

Definition at line 79 of file ResidualFitter.h.

Referenced by CreateCanvas(), and SetCanvas().

int ResidualFitter::yCanvas_ = 600
staticprivate

Definition at line 80 of file ResidualFitter.h.

Referenced by CreateCanvas(), and SetCanvas().