CMS 3D CMS Logo

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

◆ ModularFunctionMinimizer

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

Definition at line 17 of file CSCFitAFEBThr.h.

Constructor & Destructor Documentation

◆ CSCFitAFEBThr()

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:36
CSCThrTurnOnFcn * theOBJfun
Definition: CSCFitAFEBThr.h:37

◆ ~CSCFitAFEBThr()

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:36
CSCThrTurnOnFcn * theOBJfun
Definition: CSCFitAFEBThr.h:37

Member Function Documentation

◆ ThresholdNoise()

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 change_name::diff, nano_mu_digi_cff::float, mps_fire::i, AlCaHLTBitMon_ParallelJobs::p, alignCSCRings::r, alignCSCRings::s, CSCThrTurnOnFcn::setData(), CSCThrTurnOnFcn::setErrors(), CSCThrTurnOnFcn::setNorm(), mathSSE::sqrt(), mps_update::status, theFitter, theOBJfun, x, and y.

Referenced by CSCAFEBThrAnalysis::done().

34  {
35  bool status = false;
36 
37  std::vector<double> parinit(2, 0);
38  std::vector<double> erparinit(2, 0);
39 
41  parinit[0] = 30.0;
42  parinit[1] = 2.0;
43 
44  erparinit[0] = 20;
45  erparinit[1] = 0.5;
46 
48  std::vector<float> x;
49  std::vector<float> y;
50  std::vector<float> ynorm;
51  std::vector<float> ery;
52  x.clear();
53  y.clear();
54  ynorm.clear();
55  ery.clear();
56 
64 
65  int sum = 0;
66  float r;
67  for (size_t i = 0; i < inputx.size(); i++) {
68  if (inputy[i] > 0.0)
69  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  int nbeg = inputx.size();
81  // for(size_t i=inputx.size()-1;i>=0;i--) // Wrong.
82  // Because i is unsigned, i>=0 is always true,
83  // and the loop termination condition is never reached.
84  // We offset by 1.
85  for (size_t i = inputx.size(); i > 0; i--) {
86  if (ynorm[i - 1] < 1.0)
87  nbeg--;
88  if (ynorm[i - 1] == 1.0)
89  break;
90  }
91 
92  for (size_t i = nbeg; i < inputx.size(); i++) {
93  if (ynorm[i] > 0.0) {
94  x.push_back(inputx[i]);
95  y.push_back(ynorm[i]);
96 
97  float p = inputy[i] / (float)dacoccup[i];
98  float s = (float)dacoccup[i] * p * (1.0 - p);
99  s = sqrt(s) / (float)dacoccup[i];
100  ery.push_back(s);
101  }
102  }
103 
105  ndf = x.size() - 2;
106  if (ndf <= 0)
107  return status;
108 
110  float half = 0.5;
111  float dmin = 999999.0;
112  float diff;
113  for (size_t i = 0; i < x.size(); i++) {
114  diff = y[i] - half;
115  if (diff < 0.0)
116  diff = -diff;
117  if (diff < dmin) {
118  dmin = diff;
119  parinit[0] = x[i];
120  } // par[0] from data
121  //std::cout<<i+1<<" "<<x[i]<<" "<<y[i]<<" "<<ery[i]<<std::endl;
122  }
123 
125  theOBJfun->setData(x, y);
126  theOBJfun->setErrors(ery);
127  theOBJfun->setNorm(1.0);
128 
129  // for(size_t int i=0;i<x.size();i++) std::cout<<" "<<x[i]<<" "<<y[i]
130  // <<" "<<ery[i]<<std::endl;
131 
133  FunctionMinimum fmin = theFitter->Minimize(*theOBJfun, parinit, erparinit, 1, 500, 0.1);
134 
135  status = fmin.IsValid();
136 
137  if (status) {
138  mypar[0] = (float)fmin.Parameters().Vec()(0);
139  mypar[1] = (float)fmin.Parameters().Vec()(1);
140  ermypar[0] = (float)sqrt(fmin.Error().Matrix()(0, 0));
141  ermypar[1] = (float)sqrt(fmin.Error().Matrix()(1, 1));
142  ercorr = 0;
143  if (ermypar[0] != 0.0 && ermypar[1] != 0.0)
144  ercorr = (float)fmin.Error().Matrix()(0, 1) / (ermypar[0] * ermypar[1]);
145 
146  chisq = fmin.Fval();
147  ndf = y.size() - mypar.size();
148  niter = fmin.NFcn();
149  edm = fmin.Edm();
150  } else
151  ndf = -3;
152  return status;
153 }
void setNorm(float n)
Set the norm (if needed)
ModularFunctionMinimizer * theFitter
Definition: CSCFitAFEBThr.h:36
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:19
CSCThrTurnOnFcn * theOBJfun
Definition: CSCFitAFEBThr.h:37
void setErrors(const std::vector< float > &er)
Set the errors.
HLT enums.

Member Data Documentation

◆ theFitter

ModularFunctionMinimizer* CSCFitAFEBThr::theFitter
private

Definition at line 36 of file CSCFitAFEBThr.h.

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

◆ theOBJfun

CSCThrTurnOnFcn* CSCFitAFEBThr::theOBJfun
private

Definition at line 37 of file CSCFitAFEBThr.h.

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