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
EcalUncalibRecHitMultiFitAlgo Class Reference

#include <EcalUncalibRecHitMultiFitAlgo.h>

Public Member Functions

void disableErrorCalculation ()
 
 EcalUncalibRecHitMultiFitAlgo ()
 
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 More...
 
void setDoPrefit (bool b)
 
void setGainSwitchUseMaxSample (bool b)
 
void setPrefitMaxChiSq (double x)
 
 ~EcalUncalibRecHitMultiFitAlgo ()
 

Private Attributes

bool _computeErrors
 
bool _doPrefit
 
bool _gainSwitchUseMaxSample
 
double _prefitMaxChiSq
 
PulseChiSqSNNLS _pulsefunc
 
PulseChiSqSNNLS _pulsefuncSingle
 
BXVector _singlebx
 

Detailed Description

Amplitude reconstucted by the multi-template fit

Author
J.Bendavid, E.Di Marco

Definition at line 21 of file EcalUncalibRecHitMultiFitAlgo.h.

Constructor & Destructor Documentation

EcalUncalibRecHitMultiFitAlgo::EcalUncalibRecHitMultiFitAlgo ( )

Definition at line 8 of file EcalUncalibRecHitMultiFitAlgo.cc.

References _pulsefuncSingle, _singlebx, PulseChiSqSNNLS::disableErrorCalculation(), BXVector< T >::resize(), PulseChiSqSNNLS::setMaxIters(), and PulseChiSqSNNLS::setMaxIterWarnings().

EcalUncalibRecHitMultiFitAlgo::~EcalUncalibRecHitMultiFitAlgo ( )
inline

Definition at line 27 of file EcalUncalibRecHitMultiFitAlgo.h.

27 { };

Member Function Documentation

void EcalUncalibRecHitMultiFitAlgo::disableErrorCalculation ( )
inline

Definition at line 30 of file EcalUncalibRecHitMultiFitAlgo.h.

References _computeErrors.

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 
)

compute rechits

Definition at line 24 of file EcalUncalibRecHitMultiFitAlgo.cc.

References _computeErrors, _doPrefit, _gainSwitchUseMaxSample, _prefitMaxChiSq, _pulsefunc, _pulsefuncSingle, _singlebx, EcalMGPASample::adc(), PulseChiSqSNNLS::BXs(), PulseChiSqSNNLS::ChiSq(), PulseChiSqSNNLS::disableErrorCalculation(), PulseChiSqSNNLS::DoFit(), PulseChiSqSNNLS::Errors(), flags, EcalMGPAGainRatio::gain12Over6(), EcalMGPAGainRatio::gain6Over1(), ecalMGPA::gainId(), EcalMGPASample::gainId(), EcalDataFrame::id(), bookConverter::max, EcalDataFrame::MAXSAMPLES, EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, EcalCondDBWriter_cfi::pedestal, EcalPedestal::rms_x1, EcalPedestal::rms_x12, EcalPedestal::rms_x6, compare_using_db::sample, EcalDataFrame::sample(), EcalUncalibratedRecHit::setAmplitudeError(), mps_update::status, and PulseChiSqSNNLS::X().

24  {
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 }
DetId id() const
Definition: EcalDataFrame.h:24
int gainId(sample_type sample)
get the gainId (2 bits)
void disableErrorCalculation()
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
int gainId() const
get the gainId (2 bits)
const PulseVector & X() const
float gain6Over1() const
void setAmplitudeError(float amplitudeerror)
double ChiSq() const
float gain12Over6() const
const BXVector & BXs() const
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
void EcalUncalibRecHitMultiFitAlgo::setDoPrefit ( bool  b)
inline

Definition at line 31 of file EcalUncalibRecHitMultiFitAlgo.h.

References _doPrefit, and b.

void EcalUncalibRecHitMultiFitAlgo::setGainSwitchUseMaxSample ( bool  b)
inline

Definition at line 29 of file EcalUncalibRecHitMultiFitAlgo.h.

References _gainSwitchUseMaxSample, and b.

void EcalUncalibRecHitMultiFitAlgo::setPrefitMaxChiSq ( double  x)
inline

Member Data Documentation

bool EcalUncalibRecHitMultiFitAlgo::_computeErrors
private

Definition at line 37 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by disableErrorCalculation(), and makeRecHit().

bool EcalUncalibRecHitMultiFitAlgo::_doPrefit
private

Definition at line 38 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setDoPrefit().

bool EcalUncalibRecHitMultiFitAlgo::_gainSwitchUseMaxSample
private

Definition at line 40 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setGainSwitchUseMaxSample().

double EcalUncalibRecHitMultiFitAlgo::_prefitMaxChiSq
private

Definition at line 39 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit(), and setPrefitMaxChiSq().

PulseChiSqSNNLS EcalUncalibRecHitMultiFitAlgo::_pulsefunc
private

Definition at line 35 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by makeRecHit().

PulseChiSqSNNLS EcalUncalibRecHitMultiFitAlgo::_pulsefuncSingle
private

Definition at line 36 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by EcalUncalibRecHitMultiFitAlgo(), and makeRecHit().

BXVector EcalUncalibRecHitMultiFitAlgo::_singlebx
private

Definition at line 41 of file EcalUncalibRecHitMultiFitAlgo.h.

Referenced by EcalUncalibRecHitMultiFitAlgo(), and makeRecHit().