test
CMS 3D CMS Logo

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

#include <fitUtilities.h>

Public Member Functions

double doGaussFit (MonitorElement *ME)
 
double doGaussFit (TH1F *)
 
double doLanGaussFit (MonitorElement *ME)
 
double doLanGaussFit (TH1F *)
 
 fitUtilities ()
 
double getFitChi ()
 
int getFitnDof ()
 
double getGaussPar (std::string s)
 
double getGaussParErr (std::string s)
 
double getLanGaussConv (std::string s)
 
double getLanGaussPar (std::string s)
 
double getLanGaussParErr (std::string s)
 
void init ()
 
 ~fitUtilities ()
 

Private Attributes

double chi2GausS
 
double epGausS [3]
 
double epLanGausS [4]
 
TF1 * gausFit
 
TF1 * langausFit
 
int32_t nDofGausS
 
double pGausS [3]
 
double pLanConv [2]
 
double pLanGausS [4]
 

Detailed Description

Definition at line 28 of file fitUtilities.h.

Constructor & Destructor Documentation

fitUtilities::fitUtilities ( )

Definition at line 239 of file fitUtilities.h.

References init().

239  :langausFit(0),gausFit(0){
240  init();
241 }
TF1 * langausFit
Definition: fitUtilities.h:59
fitUtilities::~fitUtilities ( )

Definition at line 259 of file fitUtilities.h.

References gausFit, and langausFit.

259  {
260  if ( langausFit!=0 ) delete langausFit;
261  if ( gausFit!=0 ) delete gausFit;
262 }
TF1 * langausFit
Definition: fitUtilities.h:59

Member Function Documentation

double fitUtilities::doGaussFit ( MonitorElement ME)
inline

Definition at line 39 of file fitUtilities.h.

References doGaussFit(), and MonitorElement::getTH1F().

Referenced by doGaussFit().

39 {return doGaussFit(ME->getTH1F());}
double doGaussFit(MonitorElement *ME)
Definition: fitUtilities.h:39
TH1F * getTH1F(void) const
double fitUtilities::doGaussFit ( TH1F *  htoFit)

Definition at line 349 of file fitUtilities.h.

References chi2GausS, epGausS, gausFit, Gauss(), i, init(), langausFit, nDofGausS, pGausS, SiStripMonitorClusterAlca_cfi::xmax, and SiStripMonitorClusterAlca_cfi::ymax.

349  {
350  init();
351  if (htoFit->GetEntries()!=0) {
352 
353  // Setting fit range and start values
354  double fr[2];
355  double sv[3], pllo[3], plhi[3];
356  fr[0]=htoFit->GetMean()-5*htoFit->GetRMS();
357  fr[1]=htoFit->GetMean()+5*htoFit->GetRMS();
358 
359  int32_t imax=htoFit->GetMaximumBin();
360  double xmax=htoFit->GetBinCenter(imax);
361  double ymax=htoFit->GetBinContent(imax);
362  int32_t i[2];
363  int32_t iArea[2];
364 
365  i[0]=htoFit->GetXaxis()->FindBin(fr[0]);
366  i[1]=htoFit->GetXaxis()->FindBin(fr[1]);
367 
368  iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]);
369  iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]);
370  double AreaFWHM=htoFit->Integral(iArea[0],iArea[1],"width");
371 
372  sv[2]=AreaFWHM/(4*ymax);
373  sv[1]=xmax;
374  sv[0]=htoFit->Integral(i[0],i[1],"width");
375 
376  plhi[0]=1000000.0; plhi[1]=10.0; plhi[2]=10.;
377  pllo[0]=1.5 ; pllo[1]=0.1; pllo[2]=0.3;
378  Char_t FunName[100];
379  sprintf(FunName,"FitfcnLG_%s",htoFit->GetName());
380  gausFit = new TF1(FunName,Gauss,fr[0],fr[1],3);
381  gausFit->SetParameters(sv);
382  gausFit->SetParNames("Constant","GaussPeak","Sigma");
383 
384  for (int32_t i=0; i<3; i++) {
385  gausFit->SetParLimits(i,pllo[i],plhi[i]);
386  }
387 
388  try{
389  htoFit->Fit(gausFit,"R0");
390 
391  gausFit->SetRange(fr[0],fr[1]);
392  gausFit->GetParameters(pGausS);
393  std::memcpy((void*) epGausS, (void*) gausFit->GetParErrors(), 3*sizeof(double));
394 
395  chi2GausS =langausFit->GetChisquare(); // obtain chi^2
396  nDofGausS = langausFit->GetNDF();// obtain ndf
397  }
398  catch(...){
399  edm::LogError("fitUtility") << "problem in fitting " << htoFit->GetTitle() << " \n\tDefault values of the parameters will be used";
400  pGausS[0]=-9999; pGausS[1]=-9999; pGausS[2]=-9999;
401  epGausS[0]=-9999; epGausS[1]=-9999; epGausS[2]=-9999;
402  chi2GausS=-9999; nDofGausS=-9999;
403  }
404 
405  }
406  else {
407  pGausS[0]=-9999; pGausS[1]=-9999; pGausS[2]=-9999;
408  epGausS[0]=-9999; epGausS[1]=-9999; epGausS[2]=-9999;
409  chi2GausS=-9999; nDofGausS=-9999;
410  }
411 
412  return htoFit->GetEntries();
413 }
int i
Definition: DBlmapReader.cc:9
double pGausS[3]
Definition: fitUtilities.h:55
TF1 * langausFit
Definition: fitUtilities.h:59
double Gauss(double *x, double *par)
Definition: fitUtilities.h:225
double chi2GausS
Definition: fitUtilities.h:57
int32_t nDofGausS
Definition: fitUtilities.h:58
double epGausS[3]
Definition: fitUtilities.h:55
double fitUtilities::doLanGaussFit ( MonitorElement ME)
inline

Definition at line 36 of file fitUtilities.h.

References doLanGaussFit(), and MonitorElement::getTH1F().

Referenced by doLanGaussFit().

36 {return doLanGaussFit(ME->getTH1F());}
TH1F * getTH1F(void) const
double doLanGaussFit(MonitorElement *ME)
Definition: fitUtilities.h:36
double fitUtilities::doLanGaussFit ( TH1F *  htoFit)

Definition at line 267 of file fitUtilities.h.

References chi2GausS, epLanGausS, i, init(), langaufun(), langaupro(), langausFit, nDofGausS, pLanConv, pLanGausS, SiStripMonitorClusterAlca_cfi::xmax, and SiStripMonitorClusterAlca_cfi::ymax.

267  {
268  init();
269 
270  if (htoFit->GetEntries()!=0) {
271  edm::LogInfo("fitUtility")<<"Fitting "<< htoFit->GetTitle() <<std::endl;
272  // Setting fit range and start values
273  double fr[2];
274  double sv[4], pllo[4], plhi[4];
275  fr[0]=0.5*htoFit->GetMean();
276  fr[1]=3.0*htoFit->GetMean();
277 
278  // (EM) parameters setting good for signal only
279  int32_t imax=htoFit->GetMaximumBin();
280  double xmax=htoFit->GetBinCenter(imax);
281  double ymax=htoFit->GetBinContent(imax);
282  int32_t i[2];
283  int32_t iArea[2];
284 
285  i[0]=htoFit->GetXaxis()->FindBin(fr[0]);
286  i[1]=htoFit->GetXaxis()->FindBin(fr[1]);
287 
288  iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]);
289  iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]);
290  double AreaFWHM=htoFit->Integral(iArea[0],iArea[1],"width");
291 
292  sv[1]=xmax;
293  sv[2]=htoFit->Integral(i[0],i[1],"width");
294  sv[3]=AreaFWHM/(4*ymax);
295  sv[0]=sv[3];
296 
297  plhi[0]=25.0; plhi[1]=200.0; plhi[2]=1000000.0; plhi[3]=50.0;
298  pllo[0]=1.5 ; pllo[1]=10.0 ; pllo[2]=1.0 ; pllo[3]= 1.0;
299 
300  Char_t FunName[100];
301  sprintf(FunName,"FitfcnLG_%s",htoFit->GetName());
302 
303  langausFit = new TF1(FunName,langaufun,fr[0],fr[1],4);
304  langausFit->SetParameters(sv);
305  langausFit->SetParNames("Width","MP","Area","GSigma");
306 
307  for (int32_t i=0; i<4; i++) {
308  langausFit->SetParLimits(i,pllo[i],plhi[i]);
309  }
310 
311  try{
312  htoFit->Fit(langausFit,"R0"); // "R" fit in a range,"0" quiet fit
313 
314  langausFit->SetRange(fr[0],fr[1]);
315  langausFit->GetParameters(pLanGausS);
316  std::memcpy((void*) epLanGausS, (void*) langausFit->GetParErrors(), 4*sizeof(double));
317 
318  chi2GausS =langausFit->GetChisquare(); // obtain chi^2
319  nDofGausS = langausFit->GetNDF(); // obtain ndf
320 
321  double sPeak, sFWHM;
322  langaupro(pLanGausS,sPeak,sFWHM);
323  pLanConv[0]=sPeak;
324  pLanConv[1]=sFWHM;
325  edm::LogInfo("fitUtility") << "langaupro: max " << sPeak << std::endl;
326  edm::LogInfo("fitUtility") << "langaupro: FWHM " << sFWHM << std::endl;
327  }
328  catch(...){
329  edm::LogError("fitUtility") << "problem in fitting " << htoFit->GetTitle() << " \n\tDefault values of the parameters will be used";
330  pLanGausS[0]=-9999; pLanGausS[1]=-9999; pLanGausS[2]=-9999; pLanGausS[3]=-9999;
331  epLanGausS[0]=-9999; epLanGausS[1]=-9999; epLanGausS[2]=-9999; epLanGausS[3]=-9999;
332  pLanConv[0]=-9999; pLanConv[1]=-9999;
333  chi2GausS=-9999; nDofGausS=-9999;
334  }
335  }
336  else {
337  pLanGausS[0]=-9999; pLanGausS[1]=-9999; pLanGausS[2]=-9999; pLanGausS[3]=-9999;
338  epLanGausS[0]=-9999; epLanGausS[1]=-9999; epLanGausS[2]=-9999; epLanGausS[3]=-9999;
339  pLanConv[0]=-9999; pLanConv[1]=-9999;
340  chi2GausS=-9999; nDofGausS=-9999;
341  }
342 
343  return htoFit->GetEntries();
344 
345 }
int i
Definition: DBlmapReader.cc:9
TF1 * langausFit
Definition: fitUtilities.h:59
double pLanGausS[4]
Definition: fitUtilities.h:54
double epLanGausS[4]
Definition: fitUtilities.h:54
int32_t langaupro(double *params, double &maxx, double &FWHM)
Definition: fitUtilities.h:120
double pLanConv[2]
Definition: fitUtilities.h:56
double chi2GausS
Definition: fitUtilities.h:57
int32_t nDofGausS
Definition: fitUtilities.h:58
Double_t langaufun(Double_t *x, Double_t *par)
double fitUtilities::getFitChi ( )
inline

Definition at line 49 of file fitUtilities.h.

References chi2GausS.

49 {return chi2GausS;}
double chi2GausS
Definition: fitUtilities.h:57
int fitUtilities::getFitnDof ( )
inline

Definition at line 50 of file fitUtilities.h.

References nDofGausS.

50 {return nDofGausS;}
int32_t nDofGausS
Definition: fitUtilities.h:58
double fitUtilities::getGaussPar ( std::string  s)

Definition at line 451 of file fitUtilities.h.

References pGausS.

451  {
452  if(s=="area")
453  return pGausS[0];
454  else if(s=="mean")
455  return pGausS[1];
456  else if(s=="sigma")
457  return pGausS[2];
458  else
459  return -99999;
460 }
double pGausS[3]
Definition: fitUtilities.h:55
double fitUtilities::getGaussParErr ( std::string  s)

Definition at line 462 of file fitUtilities.h.

References epGausS.

462  {
463  if(s=="area")
464  return epGausS[0];
465  else if(s=="mean")
466  return epGausS[1];
467  else if(s=="sigma")
468  return epGausS[2];
469  else
470  return -99999;
471 }
double epGausS[3]
Definition: fitUtilities.h:55
double fitUtilities::getLanGaussConv ( std::string  s)

Definition at line 442 of file fitUtilities.h.

References pLanConv.

442  {
443  if(s=="mpv")
444  return pLanConv[0];
445  else if(s=="fwhm")
446  return pLanConv[1];
447  else
448  return -99999;
449 }
double pLanConv[2]
Definition: fitUtilities.h:56
double fitUtilities::getLanGaussPar ( std::string  s)

Definition at line 416 of file fitUtilities.h.

References pLanGausS.

416  {
417  if(s=="landau_width")
418  return pLanGausS[0];
419  else if(s=="mpv")
420  return pLanGausS[1];
421  else if(s=="area")
422  return pLanGausS[2];
423  else if(s=="gauss_sigma")
424  return pLanGausS[3];
425  else
426  return -99999;
427 }
double pLanGausS[4]
Definition: fitUtilities.h:54
double fitUtilities::getLanGaussParErr ( std::string  s)

Definition at line 429 of file fitUtilities.h.

References epLanGausS.

429  {
430  if(s=="landau_width")
431  return epLanGausS[0];
432  else if(s=="mpv")
433  return epLanGausS[1];
434  else if(s=="area")
435  return epLanGausS[2];
436  else if(s=="gauss_sigma")
437  return epLanGausS[3];
438  else
439  return -99999;
440 }
double epLanGausS[4]
Definition: fitUtilities.h:54
void fitUtilities::init ( void  )

Definition at line 244 of file fitUtilities.h.

References chi2GausS, epGausS, epLanGausS, nDofGausS, pGausS, pLanConv, and pLanGausS.

Referenced by doGaussFit(), doLanGaussFit(), and fitUtilities().

244  {
245  pLanGausS[0]=0 ; pLanGausS[1]=0; pLanGausS[2]=0; pLanGausS[3]=0;
246  epLanGausS[0]=0; epLanGausS[1]=0; epLanGausS[2]=0; epLanGausS[3]=0;
247  pGausS[0]=0 ; pGausS[1]=0; pGausS[2]=0;
248  epGausS[0]=0; epGausS[1]=0; epGausS[2]=0;
249  pLanConv[0]=0; pLanConv[1]=0;
250 
251  //if ( langausFit!=0 ) delete langausFit;
252  //if ( gausFit!=0 ) delete gausFit;
253 
254  chi2GausS = -9999.;
255  nDofGausS = -9999;
256 }
double pGausS[3]
Definition: fitUtilities.h:55
double pLanGausS[4]
Definition: fitUtilities.h:54
double epLanGausS[4]
Definition: fitUtilities.h:54
double pLanConv[2]
Definition: fitUtilities.h:56
double chi2GausS
Definition: fitUtilities.h:57
int32_t nDofGausS
Definition: fitUtilities.h:58
double epGausS[3]
Definition: fitUtilities.h:55

Member Data Documentation

double fitUtilities::chi2GausS
private

Definition at line 57 of file fitUtilities.h.

Referenced by doGaussFit(), doLanGaussFit(), getFitChi(), and init().

double fitUtilities::epGausS[3]
private

Definition at line 55 of file fitUtilities.h.

Referenced by doGaussFit(), getGaussParErr(), and init().

double fitUtilities::epLanGausS[4]
private

Definition at line 54 of file fitUtilities.h.

Referenced by doLanGaussFit(), getLanGaussParErr(), and init().

TF1* fitUtilities::gausFit
private

Definition at line 60 of file fitUtilities.h.

Referenced by doGaussFit(), and ~fitUtilities().

TF1* fitUtilities::langausFit
private

Definition at line 59 of file fitUtilities.h.

Referenced by doGaussFit(), doLanGaussFit(), and ~fitUtilities().

int32_t fitUtilities::nDofGausS
private

Definition at line 58 of file fitUtilities.h.

Referenced by doGaussFit(), doLanGaussFit(), getFitnDof(), and init().

double fitUtilities::pGausS[3]
private

Definition at line 55 of file fitUtilities.h.

Referenced by doGaussFit(), getGaussPar(), and init().

double fitUtilities::pLanConv[2]
private

Definition at line 56 of file fitUtilities.h.

Referenced by doLanGaussFit(), getLanGaussConv(), and init().

double fitUtilities::pLanGausS[4]
private

Definition at line 54 of file fitUtilities.h.

Referenced by doLanGaussFit(), getLanGaussPar(), and init().