CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalUncalibRecHitMultiFitAlgo.cc
Go to the documentation of this file.
2 
4 
7 
9  _computeErrors(true),
10  _doPrefit(false),
11  _prefitMaxChiSq(1.0),
12  _gainSwitchUseMaxSample(false){
13 
14  _singlebx.resize(1);
15  _singlebx << 0;
16 
20 
21 }
22 
24 EcalUncalibratedRecHit EcalUncalibRecHitMultiFitAlgo::makeRecHit(const EcalDataFrame& dataFrame, const EcalPedestals::Item * aped, const EcalMGPAGainRatio * aGain, const SampleMatrix &noisecor, const FullSampleVector &fullpulse, const FullSampleMatrix &fullpulsecov, const BXVector &activeBX) {
25 
26  uint32_t flags = 0;
27 
28  const unsigned int nsample = EcalDataFrame::MAXSAMPLES;
29 
30  double maxamplitude = -std::numeric_limits<double>::max();
31  const unsigned int iSampleMax = 5;
32  const unsigned int iFullPulseMax = 9;
33 
34  double pedval = 0.;
35  double pedrms = 0.;
36  int iGainSwitch = 0;
37 
38  SampleVector amplitudes;
39  for(unsigned int iSample = 0; iSample < nsample; iSample++) {
40 
41  const EcalMGPASample &sample = dataFrame.sample(iSample);
42 
43  double amplitude = 0.;
44  int gainId = sample.gainId();
45 
46  double pedestal = 0.;
47  double pederr = 0.;
48  double gainratio = 1.;
49 
50  if (gainId==0 || gainId==3) {
51  pedestal = aped->mean_x1;
52  pederr = aped->rms_x1;
53  gainratio = aGain->gain6Over1()*aGain->gain12Over6();
54  }
55  else if (gainId==1) {
56  pedestal = aped->mean_x12;
57  pederr = aped->rms_x12;
58  gainratio = 1.;
59  }
60  else if (gainId==2) {
61  pedestal = aped->mean_x6;
62  pederr = aped->rms_x6;
63  gainratio = aGain->gain12Over6();
64  }
65  if ( (gainId != 1) && (iSample==4 || iSample==5 || iSample==6) ) iGainSwitch = 1;
66 
67  amplitude = ((double)(sample.adc()) - pedestal) * gainratio;
68 
69  if (gainId == 0) {
70  //saturation
71  amplitude = (4095. - pedestal) * gainratio;
72  }
73 
74  amplitudes[iSample] = amplitude;
75 
76  if (iSample==iSampleMax) {
77  maxamplitude = amplitude;
78  pedval = pedestal;
79  pedrms = pederr*gainratio;
80  }
81 
82  }
83 
84  double amplitude, amperr, chisq;
85  bool status = false;
86 
87  // for legacy re-reco of 2016 data, max-sample can be used for EB w/o impact on data/MC consistency
88  // in case of gain switch, just use max-sample
89  if(iGainSwitch && _gainSwitchUseMaxSample) {
90  double maxpulseamplitude = maxamplitude / fullpulse[iFullPulseMax];
91  EcalUncalibratedRecHit rh( dataFrame.id(), maxpulseamplitude, pedval, 0., 0., flags );
92  rh.setAmplitudeError(0.);
93  for (unsigned int ipulse=0; ipulse<_pulsefunc.BXs().rows(); ++ipulse) {
94  int bx = _pulsefunc.BXs().coeff(ipulse);
95  if (bx!=0) {
96  rh.setOutOfTimeAmplitude(bx+5, 0.0);
97  }
98  }
99  return rh;
100  }
101 
102  //optimized one-pulse fit for hlt
103  bool usePrefit = false;
104  if (_doPrefit) {
105  status = _pulsefuncSingle.DoFit(amplitudes,noisecor,pedrms,_singlebx,fullpulse,fullpulsecov);
106  amplitude = status ? _pulsefuncSingle.X()[0] : 0.;
107  amperr = status ? _pulsefuncSingle.Errors()[0] : 0.;
108  chisq = _pulsefuncSingle.ChiSq();
109 
110  if (chisq < _prefitMaxChiSq) {
111  usePrefit = true;
112  }
113  }
114 
115  if (!usePrefit) {
116 
118  status = _pulsefunc.DoFit(amplitudes,noisecor,pedrms,activeBX,fullpulse,fullpulsecov);
119  chisq = _pulsefunc.ChiSq();
120 
121  if (!status) {
122  edm::LogWarning("EcalUncalibRecHitMultiFitAlgo::makeRecHit") << "Failed Fit" << std::endl;
123  }
124 
125  unsigned int ipulseintime = 0;
126  for (unsigned int ipulse=0; ipulse<_pulsefunc.BXs().rows(); ++ipulse) {
127  if (_pulsefunc.BXs().coeff(ipulse)==0) {
128  ipulseintime = ipulse;
129  break;
130  }
131  }
132 
133  amplitude = status ? _pulsefunc.X()[ipulseintime] : 0.;
134  amperr = status ? _pulsefunc.Errors()[ipulseintime] : 0.;
135 
136  }
137 
138  double jitter = 0.;
139 
140  //printf("status = %i\n",int(status));
141  //printf("amplitude = %5f +- %5f, chisq = %5f\n",amplitude,amperr,chisq);
142 
143  EcalUncalibratedRecHit rh( dataFrame.id(), amplitude , pedval, jitter, chisq, flags );
144  rh.setAmplitudeError(amperr);
145 
146  if (!usePrefit) {
147  for (unsigned int ipulse=0; ipulse<_pulsefunc.BXs().rows(); ++ipulse) {
148  int bx = _pulsefunc.BXs().coeff(ipulse);
149  if (bx!=0) {
150  rh.setOutOfTimeAmplitude(bx+5, status ? _pulsefunc.X().coeff(ipulse) : 0.);
151  }
152  }
153  }
154 
155  return rh;
156 }
157 
void setMaxIterWarnings(bool b)
DetId id() const
Definition: EcalDataFrame.h:24
void setMaxIters(int n)
int gainId(sample_type sample)
get the gainId (2 bits)
void disableErrorCalculation()
EcalUncalibratedRecHit makeRecHit(const EcalDataFrame &dataFrame, const EcalPedestals::Item *aped, const EcalMGPAGainRatio *aGain, const SampleMatrix &noisecor, const FullSampleVector &fullpulse, const FullSampleMatrix &fullpulsecov, const BXVector &activeBX)
compute rechits
const PulseVector & Errors() const
Eigen::Matrix< double, 10, 1 > SampleVector
EcalMGPASample sample(int i) const
Definition: EcalDataFrame.h:29
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
Eigen::Matrix< double, 19, 19 > FullSampleMatrix
int gainId() const
get the gainId (2 bits)
const PulseVector & X() const
float gain6Over1() const
void setAmplitudeError(float amplitudeerror)
Eigen::Matrix< double, 19, 1 > FullSampleVector
double ChiSq() const
void resize(int bx, unsigned size)
float gain12Over6() const
const BXVector & BXs() const
volatile std::atomic< bool > shutdown_flag false
Eigen::Matrix< double, 10, 10 > SampleMatrix
static const int MAXSAMPLES
Definition: EcalDataFrame.h:48
bool DoFit(const SampleVector &samples, const SampleMatrix &samplecor, double pederr, const BXVector &bxs, const FullSampleVector &fullpulse, const FullSampleMatrix &fullpulsecov)
int adc() const
get the ADC sample (12 bits)
tuple status
Definition: mps_update.py:57