CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
PulseShapeFitOOTPileupCorrection Class Reference

#include <PulseShapeFitOOTPileupCorrection.h>

Public Member Functions

void apply (const CaloSamples &cs, const std::vector< int > &capidvec, const HcalCalibrations &calibs, double &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
 
void phase1Apply (const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
 
 PulseShapeFitOOTPileupCorrection ()
 
void resetPulseShapeTemplate (const HcalPulseShapes::Shape &ps)
 
void setChi2Term (bool isHPD)
 
void setPulseShapeTemplate (const HcalPulseShapes::Shape &ps, bool isHPD)
 
void setPUParams (bool iPedestalConstraint, bool iTimeConstraint, bool iAddPulseJitter, bool iApplyTimeSlew, double iTS4Min, const std::vector< double > &iTS4Max, double iPulseJitter, double iTimeMean, double iTimeSigHPD, double iTimeSigSiPM, double iPedMean, double iPedSigHPD, double iPedSigSiPM, double iNoiseHPD, double iNoiseSiPM, double iTMin, double iTMax, const std::vector< double > &its4Chi2, HcalTimeSlew::BiasSetting slewFlavor, int iFitTimes)
 
 ~PulseShapeFitOOTPileupCorrection ()
 

Public Attributes

const HcalPulseShapes::ShapecurrentPulseShape_ =NULL
 

Private Member Functions

void fit (int iFit, float &timevalfit, float &chargevalfit, float &pedvalfit, float &chi2, bool &fitStatus, double &iTSMax, const double &iTSTOTen, double *iEnArr, int(&iBX)[3]) const
 
int pulseShapeFit (const double *energyArr, const double *pedenArr, const double *chargeArr, const double *pedArr, const double *gainArr, const double tsTOTen, std::vector< float > &fitParsVec, const double *ADCnoise) const
 

Private Attributes

bool addPulseJitter_
 
bool applyTimeSlew_
 
double chargeThreshold_
 
int cntsetPulseShape
 
std::unique_ptr< ROOT::Math::Functor > dpfunctor_
 
int fitTimes_
 
PSFitter::HybridMinimizerhybridfitter
 
std::array< double, HcalConst::maxSamplesiniTimesArr
 
bool isCurrentChannelHPD_
 
double noise_
 
double noiseHPD_
 
double noiseSiPM_
 
bool pedestalConstraint_
 
double pedMean_
 
double pedSig_
 
double pedSigHPD_
 
double pedSigSiPM_
 
std::unique_ptr< FitterFuncs::PulseShapeFunctorpsfPtr_
 
double pulseJitter_
 
HcalTimeSlew::BiasSetting slewFlavor_
 
std::unique_ptr< ROOT::Math::Functor > spfunctor_
 
bool timeConstraint_
 
double timeMean_
 
double timeSig_
 
double timeSigHPD_
 
double timeSigSiPM_
 
std::unique_ptr< ROOT::Math::Functor > tpfunctor_
 
double ts4Chi2_
 
double ts4Max_
 
double ts4Min_
 
int TSMax_
 
int TSMin_
 
bool unConstrainedFit_
 
std::vector< double > vts4Chi2_
 
std::vector< double > vts4Max_
 

Detailed Description

Definition at line 91 of file PulseShapeFitOOTPileupCorrection.h.

Constructor & Destructor Documentation

PulseShapeFitOOTPileupCorrection::PulseShapeFitOOTPileupCorrection ( )

Definition at line 210 of file PulseShapeFitOOTPileupCorrection.cc.

References hybridfitter, iniTimesArr, and PSFitter::HybridMinimizer::kMigrad.

210  : cntsetPulseShape(0),
211  psfPtr_(nullptr), spfunctor_(nullptr), dpfunctor_(nullptr), tpfunctor_(nullptr),
214  ts4Min_(0), vts4Max_(0), pulseJitter_(0), timeMean_(0), timeSig_(0), pedMean_(0), pedSig_(0),
215  noise_(0) {
217  iniTimesArr = { {-100,-75,-50,-25,0,25,50,75,100,125} };
218 }
std::array< double, HcalConst::maxSamples > iniTimesArr
std::unique_ptr< ROOT::Math::Functor > tpfunctor_
std::unique_ptr< ROOT::Math::Functor > dpfunctor_
std::unique_ptr< ROOT::Math::Functor > spfunctor_
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
PulseShapeFitOOTPileupCorrection::~PulseShapeFitOOTPileupCorrection ( )

Definition at line 220 of file PulseShapeFitOOTPileupCorrection.cc.

References hybridfitter.

220  {
221  if(hybridfitter) delete hybridfitter;
222 }

Member Function Documentation

void PulseShapeFitOOTPileupCorrection::apply ( const CaloSamples cs,
const std::vector< int > &  capidvec,
const HcalCalibrations calibs,
double &  reconstructedEnergy,
float &  reconstructedTime,
bool &  useTriple,
float &  chi2 
) const

Definition at line 298 of file PulseShapeFitOOTPileupCorrection.cc.

References ALCARECOTkAlJpsiMuMu_cff::charge, muonCSCDigis_cfi::gain, HcalConst::maxSamples, noise_, HcalCalibrations::pedestal(), psfPtr_, pulseShapeFit(), HcalCalibrations::respcorrgain(), CaloSamples::size(), mathSSE::sqrt(), ts4Chi2_, ts4Max_, ts4Min_, vts4Chi2_, and vts4Max_.

Referenced by heavyIonTools.ConfigureHeavyIons::__call__(), editorTools.UserCodeTool::__call__(), HiCoreTools.RestrictInputToAOD::__call__(), coreTools.RunOnData::__call__(), trackTools.MakeAODTrackCandidates::__call__(), runJetUncertainties.RunJetUncertainties::__call__(), metTools.AddMETCollection::__call__(), heavyIonTools.ProductionDefaults::__call__(), editorTools.ChangeSource::__call__(), HiCoreTools.RemoveMCMatching::__call__(), coreTools.RemoveMCMatching::__call__(), trackTools.MakePATTrackCandidates::__call__(), trigTools.SwitchOnTrigger::__call__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::__call__(), heavyIonTools.SelectionDefaults::__call__(), HiCoreTools.RemoveAllPATObjectsBut::__call__(), heavyIonTools.DisbaleMonteCarloDeps::__call__(), HiCoreTools.RemoveSpecificPATObjects::__call__(), trigTools.SwitchOnTriggerStandAlone::__call__(), trackTools.MakeTrackCandidates::__call__(), tauTools.AddTauCollection::__call__(), trigTools.SwitchOnTriggerMatching::__call__(), HiCoreTools.RemoveCleaning::__call__(), HiCoreTools.AddCleaning::__call__(), trigTools.SwitchOnTriggerMatchingStandAlone::__call__(), trigTools.SwitchOnTriggerMatchEmbedding::__call__(), jetTools.AddJetCollection::__call__(), jetTools.SwitchJetCollection::__call__(), jetTools.UpdateJetCollection::__call__(), jetTools.AddJetID::__call__(), jetTools.SetTagInfos::__call__(), HcalSimpleRecAlgoImpl::reco(), and HcalSimpleRecAlgoImpl::recoHBHE().

305 {
306  psfPtr_->setDefaultcntNANinfit();
307 
308  const unsigned int cssize = cs.size();
309 // initialize arrays to be zero
310  double chargeArr[HcalConst::maxSamples]={}, pedArr[HcalConst::maxSamples]={}, gainArr[HcalConst::maxSamples]={};
311  double energyArr[HcalConst::maxSamples]={}, pedenArr[HcalConst::maxSamples]={};
312  double noiseADCArr[HcalConst::maxSamples]={};
313  double noisePHArr[HcalConst::maxSamples]={};
314  double noiseArrSq[HcalConst::maxSamples]={};
315 
316  double tsTOT = 0, tstrig = 0; // in fC
317  double tsTOTen = 0; // in GeV
318  for(unsigned int ip=0; ip<cssize; ++ip){
319  if( ip >= (unsigned) HcalConst::maxSamples ) continue; // Too many samples than what we wanna fit (10 is enough...) -> skip them
320  const int capid = capidvec[ip];
321  double charge = cs[ip];
322  double ped = calibs.pedestal(capid);
323  double gain = calibs.respcorrgain(capid);
324 
325  double energy = charge*gain;
326  double peden = ped*gain;
327 
328  chargeArr[ip] = charge; pedArr[ip] = ped; gainArr[ip] = gain;
329  energyArr[ip] = energy; pedenArr[ip] = peden;
330 
331  // HPD fcByPE from
332  // https://github.com/cms-sw/cmssw/blob/CMSSW_8_1_0/SimCalorimetry/HcalSimProducers/python/hcalSimParameters_cfi.py#L62
333  if((charge-ped)>noise_) {
334  noisePHArr[ip] = sqrt((charge-ped)*0.3305); // Add photostatistics uncertainty
335  }
336 
337  noiseADCArr[ip] = psfPtr_->sigmaHPDQIE8(chargeArr[ip]); // Add Greg's channel discretization
338  noiseArrSq[ip] = noise_ * noise_ + noiseADCArr[ip] * noiseADCArr[ip] + noisePHArr[ip] * noisePHArr[ip];
339 
340  tsTOT += charge - ped;
341  tsTOTen += energy - peden;
342  if( ip ==4 || ip==5 ){
343  tstrig += charge - ped;
344  }
345  }
346 
347  ts4Max_=vts4Max_[0]; // HB and HE are identical for Run2
348  ts4Chi2_=vts4Chi2_[0]; // HB and HE are identical for Run2
349 
350  std::vector<float> fitParsVec;
351 
352  if(tstrig >= ts4Min_&& tsTOTen > 0.) { //Two sigma from 0
353  pulseShapeFit(energyArr, pedenArr, chargeArr, pedArr, gainArr, tsTOTen, fitParsVec, noiseArrSq);
354  } else {
355  fitParsVec.clear();
356  fitParsVec.push_back(0.); //charge
357  fitParsVec.push_back(-9999); // time
358  fitParsVec.push_back(0.); // ped
359  fitParsVec.push_back(-9999); // chi2
360  fitParsVec.push_back(false); // triple
361  }
362 
363  reconstructedEnergy=fitParsVec[0];
364  reconstructedTime=fitParsVec[1];
365  chi2 = fitParsVec[3];
366  useTriple=fitParsVec[4];
367 
368 }
double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
double pedestal(int fCapId) const
get pedestal for capid=0..3
T sqrt(T t)
Definition: SSEVec.h:18
int size() const
get the size
Definition: CaloSamples.h:24
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
int pulseShapeFit(const double *energyArr, const double *pedenArr, const double *chargeArr, const double *pedArr, const double *gainArr, const double tsTOTen, std::vector< float > &fitParsVec, const double *ADCnoise) const
void PulseShapeFitOOTPileupCorrection::fit ( int  iFit,
float &  timevalfit,
float &  chargevalfit,
float &  pedvalfit,
float &  chi2,
bool &  fitStatus,
double &  iTSMax,
const double &  iTSTOTen,
double *  iEnArr,
int(&)  iBX[3] 
) const
private

Definition at line 436 of file PulseShapeFitOOTPileupCorrection.cc.

References funct::abs(), PSFitter::HybridMinimizer::Clear(), dpfunctor_, fitTimes_, hybridfitter, mps_fire::i, iniTimesArr, createfilelist::int, PSFitter::HybridMinimizer::kMigrad, PSFitter::HybridMinimizer::kScan, PSFitter::HybridMinimizer::Minimize(), PSFitter::HybridMinimizer::MinValue(), gen::n, pedMean_, pedSig_, mps_update::results, PSFitter::HybridMinimizer::SetFixedVariable(), PSFitter::HybridMinimizer::SetFunction(), PSFitter::HybridMinimizer::SetLimitedVariable(), PSFitter::HybridMinimizer::SetMinimizerType(), spfunctor_, timeMean_, timeSig_, tpfunctor_, TSMax_, TSMin_, varNames, and PSFitter::HybridMinimizer::X().

Referenced by trackingPlots.Iteration::modules(), and pulseShapeFit().

436  {
437  int n = 3;
438  if(iFit == 2) n = 5; //Two Pulse Fit
439  if(iFit == 3) n = 7; //Three Pulse Fit
440  //Step 1 Single Pulse fit
441  float pedMax = iTSMax; //=> max timeslice
442  float tMin = TSMin_; //Fitting Time Min
443  float tMax = TSMax_; //Fitting Time Max
444  //Checks to make sure fitting happens
445  if(pedMax < 1.) pedMax = 1.;
446  // Set starting values andf step sizes for parameters
447  double vstart[n];
448  for(int i = 0; i < int((n-1)/2); i++) {
449  vstart[2*i+0] = iniTimesArr[iBX[i]]+timeMean_;
450  vstart[2*i+1] = iEnArr[iBX[i]];
451  }
452  vstart[n-1] = pedMean_;
453 
454  double step[n];
455  for(int i = 0; i < n; i++) step[i] = 0.1;
456 
457  if(iFit == 1) hybridfitter->SetFunction(*spfunctor_);
458  if(iFit == 2) hybridfitter->SetFunction(*dpfunctor_);
459  if(iFit == 3) hybridfitter->SetFunction(*tpfunctor_);
460  hybridfitter->Clear();
461  //Times and amplitudes
462  for(int i = 0; i < int((n-1)/2); i++) {
463  hybridfitter->SetLimitedVariable(0+i*2, varNames[2*i+0] , vstart[0+i*2], step[0+i*2],iniTimesArr[iBX[i]]+tMin, iniTimesArr[ iBX[i] ]+tMax);
464  hybridfitter->SetLimitedVariable(1+i*2, varNames[2*i+1] , vstart[1+i*2], step[1+i*2], 0, 1.2*iTSTOTEn);
465  //Secret Option to fix the time
466  if(timeSig_ < 0) hybridfitter->SetFixedVariable(0+i*2, varNames[2*i+0],vstart[0+i*2]);
467  }
468  //Pedestal
469  if(vstart[n-1] > std::abs(pedMax)) vstart[n-1] = pedMax;
470  hybridfitter->SetLimitedVariable(n-1, varNames[n-1], vstart[n-1], step[n-1],-pedMax,pedMax);
471  //Secret Option to fix the pedestal
472  if(pedSig_ < 0) hybridfitter->SetFixedVariable(n-1,varNames[n-1],vstart[n-1]);
473  //a special number to label the initial condition
474  chi2=-1;
475  //3 fits why?!
476  const double *results = 0;
477  for(int tries=0; tries<=3;++tries){
478  if( fitTimes_ != 2 || tries !=1 ){
480  fitStatus = hybridfitter->Minimize();
481  }
482  double chi2valfit = hybridfitter->MinValue();
483  const double *newresults = hybridfitter->X();
484  if(chi2 == -1 || chi2>chi2valfit+0.01) {
485  results=newresults;
486  chi2=chi2valfit;
487  if( tries == 0 && fitTimes_ == 1 ) break;
488  if( tries == 1 && (fitTimes_ == 2 || fitTimes_ ==3 ) ) break;
489  if( tries == 2 && fitTimes_ == 4 ) break;
490  if( tries == 3 && fitTimes_ == 5 ) break;
491  //Secret option to speed up the fit => perhaps we should drop this
492  if(timeSig_ < 0 || pedSig_ < 0) break;
493  if(tries==0){
495  fitStatus = hybridfitter->Minimize();
496  } else if(tries==1){
497  hybridfitter->SetStrategy(1);
498  } else if(tries==2){
499  hybridfitter->SetStrategy(2);
500  }
501  } else {
502  break;
503  }
504  }
505  assert(results);
506 
507  timevalfit = results[0];
508  chargevalfit = results[1];
509  pedvalfit = results[n-1];
510 
511 }
constexpr char const * varNames[]
virtual const double * X() const
return pointer to X values at the minimum
void SetMinimizerType(EMinimizerType type)
std::array< double, HcalConst::maxSamples > iniTimesArr
virtual double MinValue() const
return minimum function value
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< ROOT::Math::Functor > tpfunctor_
virtual bool SetFixedVariable(unsigned int, const std::string &, double)
set fixed variable (override if minimizer supports them )
std::unique_ptr< ROOT::Math::Functor > dpfunctor_
std::unique_ptr< ROOT::Math::Functor > spfunctor_
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
virtual bool SetLimitedVariable(unsigned int ivar, const std::string &name, double val, double step, double, double)
set upper/lower limited variable (override if minimizer supports them )
step
void PulseShapeFitOOTPileupCorrection::phase1Apply ( const HBHEChannelInfo channelData,
float &  reconstructedEnergy,
float &  reconstructedTime,
bool &  useTriple,
float &  chi2 
) const

Definition at line 513 of file PulseShapeFitOOTPileupCorrection.cc.

References ALCARECOTkAlJpsiMuMu_cff::charge, HBHEChannelInfo::darkCurrent(), HBHEChannelInfo::fcByPE(), muonCSCDigis_cfi::gain, HBHEChannelInfo::hasTimeInfo(), HBHEChannelInfo::lambda(), HcalConst::maxSamples, HBHEChannelInfo::nSamples(), psfPtr_, pulseShapeFit(), mathSSE::sqrt(), ts4Chi2_, ts4Max_, ts4Min_, HBHEChannelInfo::tsDFcPerADC(), HBHEChannelInfo::tsGain(), HBHEChannelInfo::tsPedestal(), HBHEChannelInfo::tsPedestalWidth(), HBHEChannelInfo::tsRawCharge(), vts4Chi2_, and vts4Max_.

Referenced by SimpleHBHEPhase1Algo::reconstruct().

518 {
519 
520  psfPtr_->setDefaultcntNANinfit();
521 
522  const unsigned cssize = channelData.nSamples();
523  // initialize arrays to be zero
524  double chargeArr[HcalConst::maxSamples]={}, pedArr[HcalConst::maxSamples]={}, gainArr[HcalConst::maxSamples]={};
525  double energyArr[HcalConst::maxSamples]={}, pedenArr[HcalConst::maxSamples]={};
526  double noiseADCArr[HcalConst::maxSamples]={};
527  double noiseDCArr[HcalConst::maxSamples]={};
528  double noiseArrSq[HcalConst::maxSamples]={};
529  double noisePHArr[HcalConst::maxSamples]={};
530  double tsTOT = 0, tstrig = 0; // in fC
531  double tsTOTen = 0; // in GeV
532 
533  // go over the time slices
534  for(unsigned int ip=0; ip<cssize; ++ip){
535  if( ip >= (unsigned) HcalConst::maxSamples ) continue; // Too many samples than what we wanna fit (10 is enough...) -> skip them
536 
537  // const int capid = channelData.capid(); // not needed
538  double charge = channelData.tsRawCharge(ip);
539  double ped = channelData.tsPedestal(ip);
540  double gain = channelData.tsGain(ip);
541 
542  double energy = charge*gain;
543  double peden = ped*gain;
544 
545  chargeArr[ip] = charge; pedArr[ip] = ped; gainArr[ip] = gain;
546  energyArr[ip] = energy; pedenArr[ip] = peden;
547 
548  // quantization noise from the ADC (QIE8 or QIE10/11)
549  noiseADCArr[ip] = (1./sqrt(12))*channelData.tsDFcPerADC(ip);
550 
551  // dark current noise relevant for siPM
552  noiseDCArr[ip] = 0;
553  if(channelData.hasTimeInfo() && (charge-ped)>channelData.tsPedestalWidth(ip)) {
554  noiseDCArr[ip] = psfPtr_->getSiPMDarkCurrent(channelData.darkCurrent(),channelData.fcByPE(),channelData.lambda());
555  }
556 
557  // Photo statistics uncertainties
558  // sigmaFC/FC = 1/sqrt(Ne);
559  // Note2. (from kPedro): the output number of photoelectrons after smearing is treated very differently for SiPMs: *each* pe is assigned a different time based on a random generation from the Y11 pulse plus the SimHit time. In HPDs, the overall pulse is shaped all at once using just the SimHit time.
560 
561  noisePHArr[ip] = 0;
562  if((charge-ped)>channelData.tsPedestalWidth(ip)) {
563  noisePHArr[ip] = sqrt((charge-ped)*channelData.fcByPE());
564  }
565 
566  // sum all in quadrature
567  noiseArrSq[ip]= noiseADCArr[ip]*noiseADCArr[ip] + noiseDCArr[ip]*noiseDCArr[ip] + channelData.tsPedestalWidth(ip)*channelData.tsPedestalWidth(ip) + noisePHArr[ip]*noisePHArr[ip];
568 
569  tsTOT += charge - ped;
570  tsTOTen += energy - peden;
571  if( ip ==4 || ip==5 ){
572  tstrig += charge - ped;
573  }
574  }
575 
576  double averagePedSig2GeV=0.25*(channelData.tsPedestalWidth(0)*channelData.tsPedestalWidth(0)*channelData.tsGain(0)*channelData.tsGain(0) +
577  channelData.tsPedestalWidth(1)*channelData.tsPedestalWidth(1)*channelData.tsGain(1)*channelData.tsGain(1) +
578  channelData.tsPedestalWidth(2)*channelData.tsPedestalWidth(2)*channelData.tsGain(2)*channelData.tsGain(2) +
579  channelData.tsPedestalWidth(3)*channelData.tsPedestalWidth(3)*channelData.tsGain(3)*channelData.tsGain(3));
580 
581  // redefine the invertpedSig2
582  psfPtr_->setinvertpedSig2(1./(averagePedSig2GeV));
583 
584  if(channelData.hasTimeInfo()) {
586  } else {
588  }
589 
590  std::vector<float> fitParsVec;
591  if(tstrig >= ts4Min_ && tsTOTen > 0.) { //Two sigma from 0
592  pulseShapeFit(energyArr, pedenArr, chargeArr, pedArr, gainArr, tsTOTen, fitParsVec,noiseArrSq);
593  } else {
594  fitParsVec.clear();
595  fitParsVec.push_back(0.); //charge
596  fitParsVec.push_back(-9999); // time
597  fitParsVec.push_back(0.); // ped
598  fitParsVec.push_back(-9999); // chi2
599  fitParsVec.push_back(false); // triple
600  }
601 
602 
603  reconstructedEnergy = fitParsVec[0];
604  reconstructedTime = fitParsVec[1];
605  chi2 = fitParsVec[3];
606  useTriple = fitParsVec[4];
607 
608 }
double lambda() const
bool hasTimeInfo() const
double tsGain(const unsigned ts) const
double tsPedestal(const unsigned ts) const
double tsRawCharge(const unsigned ts) const
T sqrt(T t)
Definition: SSEVec.h:18
double fcByPE() const
double darkCurrent() const
double tsPedestalWidth(const unsigned ts) const
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
unsigned nSamples() const
int pulseShapeFit(const double *energyArr, const double *pedenArr, const double *chargeArr, const double *pedArr, const double *gainArr, const double tsTOTen, std::vector< float > &fitParsVec, const double *ADCnoise) const
float tsDFcPerADC(const unsigned ts) const
int PulseShapeFitOOTPileupCorrection::pulseShapeFit ( const double *  energyArr,
const double *  pedenArr,
const double *  chargeArr,
const double *  pedArr,
const double *  gainArr,
const double  tsTOTen,
std::vector< float > &  fitParsVec,
const double *  ADCnoise 
) const
private

Definition at line 372 of file PulseShapeFitOOTPileupCorrection.cc.

References funct::abs(), applyTimeSlew_, rpcdqm::BX, HiEvtPlane_cfi::chi2, HcalTimeSlew::delay(), fit(), mps_fire::i, hpstanc_transforms::max, HcalConst::maxSamples, psfPtr_, slewFlavor_, mathSSE::sqrt(), ts4Chi2_, and ts4Max_.

Referenced by apply(), and phase1Apply().

372  {
373  double tsMAX=0;
375  double tstrig = 0; // in fC
376  for(int i=0;i<HcalConst::maxSamples;++i){
377  tmpx[i]=i;
378  tmpy[i]=energyArr[i]-pedenArr[i];
379  //Add Time Slew !!! does this need to be pedestal subtracted
380  tmpslew[i] = 0;
381  if(applyTimeSlew_) tmpslew[i] = HcalTimeSlew::delay(std::max(1.0,chargeArr[i]),slewFlavor_);
382  // add the noise components
383  tmperry2[i]=noiseArrSq[i];
384 
385  //Propagate it through
386  tmperry2[i]*=(gainArr[i]*gainArr[i]); //Convert from fC to GeV
387  tmperry [i]=sqrt(tmperry2[i]);
388 
389  if(std::abs(energyArr[i])>tsMAX) tsMAX=std::abs(tmpy[i]);
390  if( i ==4 || i ==5 ){
391  tstrig += chargeArr[i] - pedArr[i];
392  }
393  }
394  psfPtr_->setpsFitx (tmpx);
395  psfPtr_->setpsFity (tmpy);
396  psfPtr_->setpsFiterry (tmperry);
397  psfPtr_->setpsFiterry2(tmperry2);
398  psfPtr_->setpsFitslew (tmpslew);
399 
400  //Fit 1 single pulse
401  float timevalfit = 0;
402  float chargevalfit= 0;
403  float pedvalfit = 0;
404  float chi2 = 999; //cannot be zero
405  bool fitStatus = false;
406  bool useTriple = false;
407 
408  int BX[3] = {4,5,3};
409  if(ts4Chi2_ != 0) fit(1,timevalfit,chargevalfit,pedvalfit,chi2,fitStatus,tsMAX,tsTOTen,tmpy,BX);
410 // Based on the pulse shape ( 2. likely gives the same performance )
411  if(tmpy[2] > 3.*tmpy[3]) BX[2] = 2;
412 // Only do three-pulse fit when tstrig < ts4Max_, otherwise one-pulse fit is used (above)
413  if(chi2 > ts4Chi2_ && tstrig < ts4Max_) { //fails chi2 cut goes straight to 3 Pulse fit
414  fit(3,timevalfit,chargevalfit,pedvalfit,chi2,fitStatus,tsMAX,tsTOTen,tmpy,BX);
415  useTriple=true;
416  }
417 
418  /*
419  if(chi2 > ts345Chi2_) { //fails do two pulse chi2 for TS5
420  BX[1] = 5;
421  fit(3,timevalfit,chargevalfit,pedvalfit,chi2,fitStatus,tsMAX,tsTOTen,BX);
422  }
423  */
424  //Fix back the timeslew
425  //if(applyTimeSlew_) timevalfit+=HcalTimeSlew::delay(std::max(1.0,chargeArr[4]),slewFlavor_);
426  int outfitStatus = (fitStatus ? 1: 0 );
427  fitParsVec.clear();
428  fitParsVec.push_back(chargevalfit);
429  fitParsVec.push_back(timevalfit);
430  fitParsVec.push_back(pedvalfit);
431  fitParsVec.push_back(chi2);
432  fitParsVec.push_back(useTriple);
433  return outfitStatus;
434 }
void fit(int iFit, float &timevalfit, float &chargevalfit, float &pedvalfit, float &chi2, bool &fitStatus, double &iTSMax, const double &iTSTOTen, double *iEnArr, int(&iBX)[3]) const
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
static double delay(double fC, BiasSetting bias=Medium)
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:16
void PulseShapeFitOOTPileupCorrection::resetPulseShapeTemplate ( const HcalPulseShapes::Shape ps)

Definition at line 288 of file PulseShapeFitOOTPileupCorrection.cc.

References addPulseJitter_, applyTimeSlew_, cntsetPulseShape, FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc(), dpfunctor_, noise_, pedestalConstraint_, pedMean_, pedSig_, psfPtr_, pulseJitter_, FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc(), spfunctor_, timeConstraint_, timeMean_, timeSig_, tpfunctor_, and FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc().

Referenced by setPulseShapeTemplate().

288  {
289  ++ cntsetPulseShape;
292  spfunctor_ = std::unique_ptr<ROOT::Math::Functor>( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc, 3) );
293  dpfunctor_ = std::unique_ptr<ROOT::Math::Functor>( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::doublePulseShapeFunc, 5) );
294  tpfunctor_ = std::unique_ptr<ROOT::Math::Functor>( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::triplePulseShapeFunc, 7) );
295 
296 }
std::unique_ptr< ROOT::Math::Functor > tpfunctor_
std::unique_ptr< ROOT::Math::Functor > dpfunctor_
std::unique_ptr< ROOT::Math::Functor > spfunctor_
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
void PulseShapeFitOOTPileupCorrection::setChi2Term ( bool  isHPD)

Definition at line 224 of file PulseShapeFitOOTPileupCorrection.cc.

References noise_, noiseHPD_, noiseSiPM_, pedSig_, pedSigHPD_, pedSigSiPM_, timeSig_, timeSigHPD_, and timeSigSiPM_.

Referenced by setPulseShapeTemplate().

224  {
225 
226  if(isHPD) {
228  pedSig_ = pedSigHPD_; // unused in Phase1, take the average pedestal width from the DB
229  noise_ = noiseHPD_; // unused in Phase1, take the pedestal width from the DB
230  } else {
232  pedSig_ = pedSigSiPM_; // unused in Phase1, take the average pedestal width from the DB
233  noise_ = noiseSiPM_; // unused in Phase1, take the pedestal width from the DB
234  }
235 
236 }
void PulseShapeFitOOTPileupCorrection::setPulseShapeTemplate ( const HcalPulseShapes::Shape ps,
bool  isHPD 
)

Definition at line 276 of file PulseShapeFitOOTPileupCorrection.cc.

References currentPulseShape_, isCurrentChannelHPD_, resetPulseShapeTemplate(), and setChi2Term().

276  {
277  // initialize for every different channel types (HPD vs SiPM)
278 
279  if (!(&ps == currentPulseShape_ && isHPD == isCurrentChannelHPD_))
280  {
281  setChi2Term(isHPD);
283  currentPulseShape_ = &ps;
284  isCurrentChannelHPD_ = isHPD;
285  }
286 }
void resetPulseShapeTemplate(const HcalPulseShapes::Shape &ps)
const HcalPulseShapes::Shape * currentPulseShape_
void PulseShapeFitOOTPileupCorrection::setPUParams ( bool  iPedestalConstraint,
bool  iTimeConstraint,
bool  iAddPulseJitter,
bool  iApplyTimeSlew,
double  iTS4Min,
const std::vector< double > &  iTS4Max,
double  iPulseJitter,
double  iTimeMean,
double  iTimeSigHPD,
double  iTimeSigSiPM,
double  iPedMean,
double  iPedSigHPD,
double  iPedSigSiPM,
double  iNoiseHPD,
double  iNoiseSiPM,
double  iTMin,
double  iTMax,
const std::vector< double > &  its4Chi2,
HcalTimeSlew::BiasSetting  slewFlavor,
int  iFitTimes 
)

Definition at line 239 of file PulseShapeFitOOTPileupCorrection.cc.

References addPulseJitter_, applyTimeSlew_, fitTimes_, noiseHPD_, noiseSiPM_, pedestalConstraint_, pedMean_, pedSigHPD_, pedSigSiPM_, pulseJitter_, slewFlavor_, timeConstraint_, timeMean_, timeSigHPD_, timeSigSiPM_, ts4Min_, TSMax_, TSMin_, vts4Chi2_, and vts4Max_.

246  {
247 
248  TSMin_ = iTMin;
249  TSMax_ = iTMax;
250  // ts4Chi2_ = its4Chi2;
251  vts4Chi2_ = its4Chi2;
252  pedestalConstraint_ = iPedestalConstraint;
253  timeConstraint_ = iTimeConstraint;
254  addPulseJitter_ = iAddPulseJitter;
255  applyTimeSlew_ = iApplyTimeSlew;
256  ts4Min_ = iTS4Min;
257  // ts4Max_ = iTS4Max;
258  vts4Max_ = iTS4Max;
259  pulseJitter_ = iPulseJitter*iPulseJitter;
260  timeMean_ = iTimeMean;
261  // timeSig_ = iTimeSig;
262  timeSigHPD_ = iTimeSigHPD;
263  timeSigSiPM_ = iTimeSigSiPM;
264  pedMean_ = iPedMean;
265  // pedSig_ = iPedSig;
266  pedSigHPD_ = iPedSigHPD;
267  pedSigSiPM_ = iPedSigSiPM;
268  // noise_ = iNoise;
269  noiseHPD_ = iNoiseHPD;
270  noiseSiPM_ = iNoiseSiPM;
271  slewFlavor_ = slewFlavor;
272  fitTimes_ = iFitTimes;
273 
274 }

Member Data Documentation

bool PulseShapeFitOOTPileupCorrection::addPulseJitter_
private

Definition at line 148 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by resetPulseShapeTemplate(), and setPUParams().

bool PulseShapeFitOOTPileupCorrection::applyTimeSlew_
private
double PulseShapeFitOOTPileupCorrection::chargeThreshold_
private

Definition at line 135 of file PulseShapeFitOOTPileupCorrection.h.

int PulseShapeFitOOTPileupCorrection::cntsetPulseShape
private

Definition at line 133 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by resetPulseShapeTemplate().

const HcalPulseShapes::Shape* PulseShapeFitOOTPileupCorrection::currentPulseShape_ =NULL

Definition at line 120 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by setPulseShapeTemplate().

std::unique_ptr<ROOT::Math::Functor> PulseShapeFitOOTPileupCorrection::dpfunctor_
private

Definition at line 140 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), and resetPulseShapeTemplate().

int PulseShapeFitOOTPileupCorrection::fitTimes_
private

Definition at line 136 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), and setPUParams().

PSFitter::HybridMinimizer* PulseShapeFitOOTPileupCorrection::hybridfitter
private
std::array<double,HcalConst::maxSamples> PulseShapeFitOOTPileupCorrection::iniTimesArr
private

Definition at line 134 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), and PulseShapeFitOOTPileupCorrection().

bool PulseShapeFitOOTPileupCorrection::isCurrentChannelHPD_
private

Definition at line 168 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by setPulseShapeTemplate().

double PulseShapeFitOOTPileupCorrection::noise_
private

Definition at line 163 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by apply(), resetPulseShapeTemplate(), and setChi2Term().

double PulseShapeFitOOTPileupCorrection::noiseHPD_
private

Definition at line 164 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by setChi2Term(), and setPUParams().

double PulseShapeFitOOTPileupCorrection::noiseSiPM_
private

Definition at line 165 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by setChi2Term(), and setPUParams().

bool PulseShapeFitOOTPileupCorrection::pedestalConstraint_
private

Definition at line 146 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by resetPulseShapeTemplate(), and setPUParams().

double PulseShapeFitOOTPileupCorrection::pedMean_
private

Definition at line 159 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), resetPulseShapeTemplate(), and setPUParams().

double PulseShapeFitOOTPileupCorrection::pedSig_
private

Definition at line 160 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), resetPulseShapeTemplate(), and setChi2Term().

double PulseShapeFitOOTPileupCorrection::pedSigHPD_
private

Definition at line 161 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by setChi2Term(), and setPUParams().

double PulseShapeFitOOTPileupCorrection::pedSigSiPM_
private

Definition at line 162 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by setChi2Term(), and setPUParams().

std::unique_ptr<FitterFuncs::PulseShapeFunctor> PulseShapeFitOOTPileupCorrection::psfPtr_
private
double PulseShapeFitOOTPileupCorrection::pulseJitter_
private

Definition at line 154 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by resetPulseShapeTemplate(), and setPUParams().

HcalTimeSlew::BiasSetting PulseShapeFitOOTPileupCorrection::slewFlavor_
private

Definition at line 166 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by pulseShapeFit(), and setPUParams().

std::unique_ptr<ROOT::Math::Functor> PulseShapeFitOOTPileupCorrection::spfunctor_
private

Definition at line 139 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), and resetPulseShapeTemplate().

bool PulseShapeFitOOTPileupCorrection::timeConstraint_
private

Definition at line 147 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by resetPulseShapeTemplate(), and setPUParams().

double PulseShapeFitOOTPileupCorrection::timeMean_
private

Definition at line 155 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), resetPulseShapeTemplate(), and setPUParams().

double PulseShapeFitOOTPileupCorrection::timeSig_
private

Definition at line 156 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), resetPulseShapeTemplate(), and setChi2Term().

double PulseShapeFitOOTPileupCorrection::timeSigHPD_
private

Definition at line 157 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by setChi2Term(), and setPUParams().

double PulseShapeFitOOTPileupCorrection::timeSigSiPM_
private

Definition at line 158 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by setChi2Term(), and setPUParams().

std::unique_ptr<ROOT::Math::Functor> PulseShapeFitOOTPileupCorrection::tpfunctor_
private

Definition at line 141 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), and resetPulseShapeTemplate().

double PulseShapeFitOOTPileupCorrection::ts4Chi2_
mutableprivate

Definition at line 144 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by apply(), phase1Apply(), and pulseShapeFit().

double PulseShapeFitOOTPileupCorrection::ts4Max_
mutableprivate

Definition at line 152 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by apply(), phase1Apply(), and pulseShapeFit().

double PulseShapeFitOOTPileupCorrection::ts4Min_
private

Definition at line 151 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by apply(), phase1Apply(), and setPUParams().

int PulseShapeFitOOTPileupCorrection::TSMax_
private

Definition at line 143 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), and setPUParams().

int PulseShapeFitOOTPileupCorrection::TSMin_
private

Definition at line 142 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by fit(), and setPUParams().

bool PulseShapeFitOOTPileupCorrection::unConstrainedFit_
private

Definition at line 149 of file PulseShapeFitOOTPileupCorrection.h.

std::vector<double> PulseShapeFitOOTPileupCorrection::vts4Chi2_
private

Definition at line 145 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by apply(), phase1Apply(), and setPUParams().

std::vector<double> PulseShapeFitOOTPileupCorrection::vts4Max_
private

Definition at line 153 of file PulseShapeFitOOTPileupCorrection.h.

Referenced by apply(), phase1Apply(), and setPUParams().