CMS 3D CMS Logo

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

#include <CSCFitAFEBThr.h>

Public Types

typedef
ROOT::Minuit2::ModularFunctionMinimizer 
ModularFunctionMinimizer
 

Public Member Functions

 CSCFitAFEBThr ()
 
virtual bool ThresholdNoise (const std::vector< float > &inputx, const std::vector< float > &inputy, const int &npulses, std::vector< int > &dacoccup, std::vector< float > &mypar, std::vector< float > &ermypar, float &ercorr, float &chisq, int &ndf, int &niter, float &edm) const
 
virtual ~CSCFitAFEBThr ()
 

Private Attributes

ModularFunctionMinimizertheFitter
 
CSCThrTurnOnFcntheOBJfun
 

Detailed Description

Concrete algorithmic class used to identify threshold and noise in AFEB channel threshold scan in the endcap muon CSCs. Based on CSCFitSCAPulse as an example

Definition at line 15 of file CSCFitAFEBThr.h.

Member Typedef Documentation

typedef ROOT::Minuit2::ModularFunctionMinimizer CSCFitAFEBThr::ModularFunctionMinimizer

Definition at line 18 of file CSCFitAFEBThr.h.

Constructor & Destructor Documentation

CSCFitAFEBThr::CSCFitAFEBThr ( )

Definition at line 14 of file CSCFitAFEBThr.cc.

References theFitter, and theOBJfun.

Referenced by CSCAFEBThrAnalysis::done().

14  {
15  theOBJfun = new CSCThrTurnOnFcn();
16  theFitter = new VariableMetricMinimizer();
17 }
ModularFunctionMinimizer * theFitter
Definition: CSCFitAFEBThr.h:37
CSCThrTurnOnFcn * theOBJfun
Definition: CSCFitAFEBThr.h:38
CSCFitAFEBThr::~CSCFitAFEBThr ( )
virtual

Definition at line 19 of file CSCFitAFEBThr.cc.

References theFitter, and theOBJfun.

19  {
20  delete theFitter;
21  delete theOBJfun;
22 }
ModularFunctionMinimizer * theFitter
Definition: CSCFitAFEBThr.h:37
CSCThrTurnOnFcn * theOBJfun
Definition: CSCFitAFEBThr.h:38

Member Function Documentation

bool CSCFitAFEBThr::ThresholdNoise ( const std::vector< float > &  inputx,
const std::vector< float > &  inputy,
const int &  npulses,
std::vector< int > &  dacoccup,
std::vector< float > &  mypar,
std::vector< float > &  ermypar,
float &  ercorr,
float &  chisq,
int &  ndf,
int &  niter,
float &  edm 
) const
virtual

Find the threshold and noise from the threshold turn-on curve. The returned bool is success/fail status.

initial parameters, parinit[0]-threshold, parinit[1]-noise

do not fit input[y]==max and input[y]==0.0; calculate binom. error;

ndf > 0 if there is input data,number of points to fit > 2 and fit did not fail. ndf = 0 if number of points to fit = 2 ndf =-1 .......................... = 1 ndf =-2 .......................... = 0 ndf =-3 fit failed (number of points to fit was > 2) ndf =-4 no input data

do not fit data with less than 3 points

Calculate approximate initial threshold par[0]

store data, errors and npulses for fit

Fit as 1D, <=500 iterations, edm=10**-5 (->0.1)

Definition at line 24 of file CSCFitAFEBThr.cc.

References diffTreeTool::diff, i, AlCaHLTBitMon_ParallelJobs::p, alignCSCRings::r, alignCSCRings::s, CSCThrTurnOnFcn::setData(), CSCThrTurnOnFcn::setErrors(), CSCThrTurnOnFcn::setNorm(), mathSSE::sqrt(), ntuplemaker::status, theFitter, theOBJfun, x, and y.

Referenced by CSCAFEBThrAnalysis::done().

35  {
36  bool status = false;
37 
38  std::vector<double> parinit(2,0);
39  std::vector<double> erparinit(2,0);
40 
42  parinit[0] = 30.0;
43  parinit[1] = 2.0;
44 
45  erparinit[0] = 20;
46  erparinit[1] = 0.5;
47 
49  std::vector<float> x;
50  std::vector<float> y;
51  std::vector<float> ynorm;
52  std::vector<float> ery;
53  x.clear();
54  y.clear();
55  ynorm.clear();
56  ery.clear();
57 
65 
66  int sum=0;
67  float r;
68  for(size_t i=0;i<inputx.size();i++) {
69  if(inputy[i]>0.0) sum++;
70  r=inputy[i]/(float)dacoccup[i];
71  ynorm.push_back(r);
72 // std::cout<<" "<<ynorm[i];
73  }
74 // std::cout<<std::endl;
75  if(sum==0) {
76  ndf=-4;
77  return status;
78  }
79 
80 
81  int nbeg=inputx.size();
82  // for(size_t i=inputx.size()-1;i>=0;i--) // Wrong.
83  // Because i is unsigned, i>=0 is always true,
84  // and the loop termination condition is never reached.
85  // We offset by 1.
86  for(size_t i=inputx.size();i>0;i--) {
87  if(ynorm[i-1]<1.0) nbeg--;
88  if(ynorm[i-1]==1.0) break;
89  }
90 
91  for(size_t i=nbeg;i<inputx.size();i++) {
92  if(ynorm[i]>0.0) {
93  x.push_back(inputx[i]);
94  y.push_back(ynorm[i]);
95 
96  float p=inputy[i]/(float)dacoccup[i];
97  float s=(float)dacoccup[i] * p * (1.0-p);
98  s=sqrt(s)/(float)dacoccup[i];
99  ery.push_back(s);
100  }
101  }
102 
104  ndf=x.size()-2;
105  if(ndf <=0) return status;
106 
108  float half=0.5;
109  float dmin=999999.0;
110  float diff;
111  for(size_t i=0;i<x.size();i++) {
112  diff=y[i]-half; if(diff<0.0) diff=-diff;
113  if(diff<dmin) {dmin=diff; parinit[0]=x[i];} // par[0] from data
114  //std::cout<<i+1<<" "<<x[i]<<" "<<y[i]<<" "<<ery[i]<<std::endl;
115  }
116 
118  theOBJfun->setData(x,y);
119  theOBJfun->setErrors(ery);
120  theOBJfun->setNorm(1.0);
121 
122  // for(size_t int i=0;i<x.size();i++) std::cout<<" "<<x[i]<<" "<<y[i]
123  // <<" "<<ery[i]<<std::endl;
124 
126  FunctionMinimum fmin=theFitter->Minimize(*theOBJfun,parinit,erparinit,1,500,0.1);
127 
128  status = fmin.IsValid();
129 
130  if(status) {
131  mypar[0]=(float)fmin.Parameters().Vec()(0);
132  mypar[1]=(float)fmin.Parameters().Vec()(1);
133  ermypar[0]=(float)sqrt( fmin.Error().Matrix()(0,0) );
134  ermypar[1]=(float)sqrt( fmin.Error().Matrix()(1,1) );
135  ercorr=0;
136  if(ermypar[0] !=0.0 && ermypar[1]!=0.0)
137  ercorr=(float)fmin.Error().Matrix()(0,1)/(ermypar[0]*ermypar[1]);
138 
139  chisq = fmin.Fval();
140  ndf=y.size()-mypar.size();
141  niter=fmin.NFcn();
142  edm=fmin.Edm();
143  }
144  else ndf=-3;
145  return status;
146 }
int i
Definition: DBlmapReader.cc:9
void setNorm(float n)
Set the norm (if needed)
ModularFunctionMinimizer * theFitter
Definition: CSCFitAFEBThr.h:37
void setData(const std::vector< float > &x, const std::vector< float > &y)
Cache the current data, x and y.
T sqrt(T t)
Definition: SSEVec.h:48
CSCThrTurnOnFcn * theOBJfun
Definition: CSCFitAFEBThr.h:38
void setErrors(const std::vector< float > &er)
Set the errors.
tuple status
Definition: ntuplemaker.py:245

Member Data Documentation

ModularFunctionMinimizer* CSCFitAFEBThr::theFitter
private

Definition at line 37 of file CSCFitAFEBThr.h.

Referenced by CSCFitAFEBThr(), ThresholdNoise(), and ~CSCFitAFEBThr().

CSCThrTurnOnFcn* CSCFitAFEBThr::theOBJfun
private

Definition at line 38 of file CSCFitAFEBThr.h.

Referenced by CSCFitAFEBThr(), ThresholdNoise(), and ~CSCFitAFEBThr().