CMS 3D CMS Logo

MahiFit.cc
Go to the documentation of this file.
3 
5  fullTSSize_(19),
6  fullTSofInterest_(8)
7 {}
8 
9 void MahiFit::setParameters(bool iDynamicPed, double iTS4Thresh, double chiSqSwitch,
10  bool iApplyTimeSlew, HcalTimeSlew::BiasSetting slewFlavor,
11  double iMeanTime, double iTimeSigmaHPD, double iTimeSigmaSiPM,
12  const std::vector <int> &iActiveBXs, int iNMaxItersMin, int iNMaxItersNNLS,
13  double iDeltaChiSqThresh, double iNnlsThresh) {
14 
15  dynamicPed_ = iDynamicPed;
16 
17  ts4Thresh_ = iTS4Thresh;
19 
20  applyTimeSlew_ = iApplyTimeSlew;
21  slewFlavor_ = slewFlavor;
22 
23  meanTime_ = iMeanTime;
24  timeSigmaHPD_ = iTimeSigmaHPD;
25  timeSigmaSiPM_ = iTimeSigmaSiPM;
26 
27  activeBXs_ = iActiveBXs;
28 
29  nMaxItersMin_ = iNMaxItersMin;
30  nMaxItersNNLS_ = iNMaxItersNNLS;
31 
32  deltaChiSqThresh_ = iDeltaChiSqThresh;
33  nnlsThresh_ = iNnlsThresh;
34 
35  bxOffsetConf_ = -(*std::min_element(activeBXs_.begin(), activeBXs_.end()));
36  bxSizeConf_ = activeBXs_.size();
37 
38 }
39 
40 void MahiFit::phase1Apply(const HBHEChannelInfo& channelData,
41  float& reconstructedEnergy,
42  float& reconstructedTime,
43  bool& useTriple,
44  float& chi2) const {
45 
46  assert(channelData.nSamples()==8||channelData.nSamples()==10);
47 
49 
50  nnlsWork_.tsSize = channelData.nSamples();
51  nnlsWork_.tsOffset = channelData.soi();
53 
54  // 1 sigma time constraint
55  if (channelData.hasTimeInfo()) nnlsWork_.dt=timeSigmaSiPM_;
57 
58 
59  //Average pedestal width (for covariance matrix constraint)
60  float pedVal = 0.25*( channelData.tsPedestalWidth(0)*channelData.tsPedestalWidth(0)+
61  channelData.tsPedestalWidth(1)*channelData.tsPedestalWidth(1)+
62  channelData.tsPedestalWidth(2)*channelData.tsPedestalWidth(2)+
63  channelData.tsPedestalWidth(3)*channelData.tsPedestalWidth(3) );
64 
68 
69  std::array<float,3> reconstructedVals {{ 0.0, -9999, -9999 }};
70 
71  double tsTOT = 0, tstrig = 0; // in GeV
72  for(unsigned int iTS=0; iTS<nnlsWork_.tsSize; ++iTS){
73  double charge = channelData.tsRawCharge(iTS);
74  double ped = channelData.tsPedestal(iTS);
75 
76  nnlsWork_.amplitudes.coeffRef(iTS) = charge - ped;
77 
78  //ADC granularity
79  double noiseADC = (1./sqrt(12))*channelData.tsDFcPerADC(iTS);
80 
81  //Photostatistics
82  double noisePhoto = 0;
83  if ( (charge-ped)>channelData.tsPedestalWidth(iTS)) {
84  noisePhoto = sqrt((charge-ped)*channelData.fcByPE());
85  }
86 
87  //Electronic pedestal
88  double pedWidth = channelData.tsPedestalWidth(iTS);
89 
90  //Total uncertainty from all sources
91  nnlsWork_.noiseTerms.coeffRef(iTS) = noiseADC*noiseADC + noisePhoto*noisePhoto + pedWidth*pedWidth;
92 
93  tsTOT += (charge - ped)*channelData.tsGain(0);
94  if( iTS==nnlsWork_.tsOffset ){
95  tstrig += (charge - ped)*channelData.tsGain(0);
96  }
97  }
98 
99  if(tstrig >= ts4Thresh_ && tsTOT > 0) {
100 
101  useTriple=false;
102 
103  // only do pre-fit with 1 pulse if chiSq threshold is positive
104  if (chiSqSwitch_>0) {
105  doFit(reconstructedVals,1);
106  if (reconstructedVals[2]>chiSqSwitch_) {
107  doFit(reconstructedVals,0); //nbx=0 means use configured BXs
108  useTriple=true;
109  }
110  }
111  else {
112  doFit(reconstructedVals,0);
113  useTriple=true;
114  }
115  }
116  else{
117  reconstructedVals.at(0) = 0.; //energy
118  reconstructedVals.at(1) = -9999.; //time
119  reconstructedVals.at(2) = -9999.; //chi2
120  }
121 
122  reconstructedEnergy = reconstructedVals[0]*channelData.tsGain(0);
123  reconstructedTime = reconstructedVals[1];
124  chi2 = reconstructedVals[2];
125 
126 }
127 
128 void MahiFit::doFit(std::array<float,3> &correctedOutput, int nbx) const {
129 
130  unsigned int bxSize=1;
131 
132  if (nbx==1) {
133  nnlsWork_.bxOffset = 0;
134  }
135  else {
136  bxSize = bxSizeConf_;
138  }
139 
140  nnlsWork_.nPulseTot = bxSize;
141 
143  nnlsWork_.bxs.setZero(nnlsWork_.nPulseTot);
144 
145  if (nbx==1) {
146  nnlsWork_.bxs.coeffRef(0) = 0;
147  }
148  else {
149  for (unsigned int iBX=0; iBX<bxSize; ++iBX) {
150  nnlsWork_.bxs.coeffRef(iBX) = activeBXs_[iBX];
151  }
152  }
153 
154  nnlsWork_.maxoffset = nnlsWork_.bxs.coeffRef(bxSize-1);
156 
161 
162  int offset=0;
163  for (unsigned int iBX=0; iBX<nnlsWork_.nPulseTot; ++iBX) {
164  offset=nnlsWork_.bxs.coeff(iBX);
165 
169 
170 
171  if (offset==pedestalBX_) {
172  nnlsWork_.pulseMat.col(iBX) = SampleVector::Ones(nnlsWork_.tsSize);
173  }
174  else {
175 
179  nnlsWork_.pulseCovArray[iBX]);
180 
181 
182  nnlsWork_.pulseMat.col(iBX) = nnlsWork_.pulseShapeArray[iBX].segment(nnlsWork_.maxoffset - offset, nnlsWork_.tsSize);
183  }
184  }
185 
189 
190  double chiSq = minimize();
191 
192  bool foundintime = false;
193  unsigned int ipulseintime = 0;
194 
195  for (unsigned int iBX=0; iBX<nnlsWork_.nPulseTot; ++iBX) {
196  if (nnlsWork_.bxs.coeff(iBX)==0) {
197  ipulseintime = iBX;
198  foundintime = true;
199  }
200  }
201 
202  if (foundintime) {
203  correctedOutput.at(0) = nnlsWork_.ampVec.coeff(ipulseintime); //charge
204  if (correctedOutput.at(0)!=0) {
205  double arrivalTime = calculateArrivalTime();
206  correctedOutput.at(1) = arrivalTime; //time
207  }
208  else correctedOutput.at(1) = -9999;//time
209 
210  correctedOutput.at(2) = chiSq; //chi2
211 
212  }
213 
214 }
215 
216 double MahiFit::minimize() const {
217 
218  double oldChiSq=9999;
219  double chiSq=oldChiSq;
220 
221  for( int iter=1; iter<nMaxItersMin_ ; ++iter) {
222 
223  updateCov();
224 
225  if (nnlsWork_.nPulseTot>1) {
226  nnls();
227  }
228  else {
230  }
231 
232  double newChiSq=calculateChiSq();
233  double deltaChiSq = newChiSq - chiSq;
234 
235  if (newChiSq==oldChiSq && newChiSq<chiSq) {
236  break;
237  }
238  oldChiSq=chiSq;
239  chiSq = newChiSq;
240 
241  if (std::abs(deltaChiSq)<deltaChiSqThresh_) break;
242 
243  }
244 
245  return chiSq;
246 
247 }
248 
249 void MahiFit::updatePulseShape(double itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv,
250  FullSampleMatrix &pulseCov) const {
251 
252  float t0=meanTime_;
253 
254  if(applyTimeSlew_) {
255  if(itQ<=1.0) t0+=tsDelay1GeV_;
256  else t0+=hcalTimeSlewDelay_->delay(itQ,slewFlavor_);
257  }
258 
259  nnlsWork_.pulseN.fill(0);
260  nnlsWork_.pulseM.fill(0);
261  nnlsWork_.pulseP.fill(0);
262 
263  const double xx[4]={t0, 1.0, 0.0, 3};
264  const double xxm[4]={-nnlsWork_.dt+t0, 1.0, 0.0, 3};
265  const double xxp[4]={ nnlsWork_.dt+t0, 1.0, 0.0, 3};
266 
267  (*pfunctor_)(&xx[0]);
268  psfPtr_->getPulseShape(nnlsWork_.pulseN);
269 
270  (*pfunctor_)(&xxm[0]);
271  psfPtr_->getPulseShape(nnlsWork_.pulseM);
272 
273  (*pfunctor_)(&xxp[0]);
274  psfPtr_->getPulseShape(nnlsWork_.pulseP);
275 
276  //in the 2018+ case where the sample of interest (SOI) is in TS3, add an extra offset to align
277  //with previous SOI=TS4 case assumed by psfPtr_->getPulseShape()
278  int delta =nnlsWork_. tsOffset == 3 ? 1 : 0;
279 
280  for (unsigned int iTS=0; iTS<nnlsWork_.tsSize; ++iTS) {
281 
282  pulseShape.coeffRef(iTS+nnlsWork_.maxoffset) = nnlsWork_.pulseN[iTS+delta];
283  pulseDeriv.coeffRef(iTS+nnlsWork_.maxoffset) = 0.5*(nnlsWork_.pulseM[iTS+delta]+nnlsWork_.pulseP[iTS+delta])/(2*nnlsWork_.dt);
284 
285  nnlsWork_.pulseM[iTS] -= nnlsWork_.pulseN[iTS];
286  nnlsWork_.pulseP[iTS] -= nnlsWork_.pulseN[iTS];
287  }
288 
289  for (unsigned int iTS=0; iTS<nnlsWork_.tsSize; ++iTS) {
290  for (unsigned int jTS=0; jTS<iTS+1; ++jTS) {
291 
292  double tmp = 0.5*( nnlsWork_.pulseP[iTS+delta]*nnlsWork_.pulseP[jTS+delta] +
294 
295  pulseCov(iTS+nnlsWork_.maxoffset,jTS+nnlsWork_.maxoffset) += tmp;
296  pulseCov(jTS+nnlsWork_.maxoffset,iTS+nnlsWork_.maxoffset) += tmp;
297 
298  }
299  }
300 
301 }
302 
303 void MahiFit::updateCov() const {
304 
306 
307  nnlsWork_.invCovMat = nnlsWork_.noiseTerms.asDiagonal();
309 
310  for (unsigned int iBX=0; iBX<nnlsWork_.nPulseTot; ++iBX) {
311  if (nnlsWork_.ampVec.coeff(iBX)==0) continue;
312 
313  int offset=nnlsWork_.bxs.coeff(iBX);
314 
315  if (offset==pedestalBX_) continue;
316  else {
317  nnlsWork_.invCovMat += nnlsWork_.ampVec.coeff(iBX)*nnlsWork_.ampVec.coeff(iBX)
319  }
320  }
321 
323 }
324 
326 
328 
330 
331  int itIndex=0;
332 
333  for (unsigned int iBX=0; iBX<nnlsWork_.nPulseTot; ++iBX) {
334  int offset=nnlsWork_.bxs.coeff(iBX);
335  if (offset==0) itIndex=iBX;
336 
337  if (offset==pedestalBX_) {
338  nnlsWork_.pulseDerivMat.col(iBX) = SampleVector::Zero(nnlsWork_.tsSize);
339  }
340  else {
342  }
343  }
344 
345  PulseVector solution = nnlsWork_.pulseDerivMat.colPivHouseholderQr().solve(nnlsWork_.residuals);
346  float t = solution.coeff(itIndex)/nnlsWork_.ampVec.coeff(itIndex);
347  t = (t>timeLimit_) ? timeLimit_ :
348  ((t<-timeLimit_) ? -timeLimit_ : t);
349 
350  return t;
351 
352 }
353 
354 
355 void MahiFit::nnls() const {
356  const unsigned int npulse = nnlsWork_.nPulseTot;
357 
359  nnlsWork_.aTaMat = nnlsWork_.invcovp.transpose().lazyProduct(nnlsWork_.invcovp);
360  nnlsWork_.aTbVec = nnlsWork_.invcovp.transpose().lazyProduct(nnlsWork_.covDecomp.matrixL().solve(nnlsWork_.amplitudes));
361 
362  int iter = 0;
363  Index idxwmax = 0;
364  double wmax = 0.0;
365  double threshold = nnlsThresh_;
366 
367  nnlsWork_.nP=0;
368 
369  while (true) {
370  if (iter>0 || nnlsWork_.nP==0) {
371  if ( nnlsWork_.nP==std::min(npulse, nnlsWork_.tsSize)) break;
372 
373  const unsigned int nActive = npulse - nnlsWork_.nP;
375 
376  Index idxwmaxprev = idxwmax;
377  double wmaxprev = wmax;
378  wmax = nnlsWork_.updateWork.tail(nActive).maxCoeff(&idxwmax);
379 
380  if (wmax<threshold || (idxwmax==idxwmaxprev && wmax==wmaxprev)) {
381  break;
382  }
383 
384  if (iter>=nMaxItersNNLS_) {
385  break;
386  }
387 
388  //unconstrain parameter
389  Index idxp = nnlsWork_.nP + idxwmax;
391 
392  }
393 
394  while (true) {
395  if (nnlsWork_.nP==0) break;
396 
398 
400 
401  //check solution
402  bool positive = true;
403  for (unsigned int i = 0; i < nnlsWork_.nP; ++i)
404  positive &= (nnlsWork_.ampvecpermtest(i) > 0);
405  if (positive) {
407  break;
408  }
409 
410  //update parameter vector
411  Index minratioidx=0;
412 
413  // no realizable optimization here (because it autovectorizes!)
414  double minratio = std::numeric_limits<double>::max();
415  for (unsigned int ipulse=0; ipulse<nnlsWork_.nP; ++ipulse) {
416  if (nnlsWork_.ampvecpermtest.coeff(ipulse)<=0.) {
417  const double c_ampvec = nnlsWork_.ampVec.coeff(ipulse);
418  const double ratio = c_ampvec/(c_ampvec-nnlsWork_.ampvecpermtest.coeff(ipulse));
419  if (ratio<minratio) {
420  minratio = ratio;
421  minratioidx = ipulse;
422  }
423  }
424  }
426 
427  //avoid numerical problems with later ==0. check
428  nnlsWork_.ampVec.coeffRef(minratioidx) = 0.;
429 
430  nnlsConstrainParameter(minratioidx);
431  }
432 
433  ++iter;
434 
435  //adaptive convergence threshold to avoid infinite loops but still
436  //ensure best value is used
437  if (iter%10==0) {
438  threshold *= 10.;
439  }
440 
441  }
442 
443 
444 }
445 
447 
449 
450  SingleMatrix aTamatval = nnlsWork_.invcovp.transpose()*nnlsWork_.invcovp;
451  SingleVector aTbvecval = nnlsWork_.invcovp.transpose()*nnlsWork_.covDecomp.matrixL().solve(nnlsWork_.amplitudes);
452 
453  nnlsWork_.ampVec.coeffRef(0) = std::max(0., aTbvecval.coeff(0)/aTamatval.coeff(0));
454 
455 
456 }
457 
458 double MahiFit::calculateChiSq() const {
459 
460  return (nnlsWork_.covDecomp.matrixL().solve(nnlsWork_.pulseMat*nnlsWork_.ampVec - nnlsWork_.amplitudes)).squaredNorm();
461 }
462 
463 void MahiFit::setPulseShapeTemplate(const HcalPulseShapes::Shape& ps,const HcalTimeSlew* hcalTimeSlewDelay) {
464 
465  if (!(&ps == currentPulseShape_ ))
466  {
467 
468  hcalTimeSlewDelay_ = hcalTimeSlewDelay;
469  tsDelay1GeV_= hcalTimeSlewDelay->delay(1.0, slewFlavor_);
470 
472  currentPulseShape_ = &ps;
473  }
474 }
475 
478 
479  // only the pulse shape itself from PulseShapeFunctor is used for Mahi
480  // the uncertainty terms calculated inside PulseShapeFunctor are used for Method 2 only
481  psfPtr_.reset(new FitterFuncs::PulseShapeFunctor(ps,false,false,false,
482  1,0,0,10));
483  pfunctor_ = std::unique_ptr<ROOT::Math::Functor>( new ROOT::Math::Functor(psfPtr_.get(),&FitterFuncs::PulseShapeFunctor::singlePulseShapeFunc, 3) );
484 
485 
486 }
487 
489  nnlsWork_.aTaMat.col(nnlsWork_.nP).swap(nnlsWork_.aTaMat.col(idxp));
490  nnlsWork_.aTaMat.row(nnlsWork_.nP).swap(nnlsWork_.aTaMat.row(idxp));
491  nnlsWork_.pulseMat.col(nnlsWork_.nP).swap(nnlsWork_.pulseMat.col(idxp));
492  std::swap(nnlsWork_.aTbVec.coeffRef(nnlsWork_.nP),nnlsWork_.aTbVec.coeffRef(idxp));
493  std::swap(nnlsWork_.ampVec.coeffRef(nnlsWork_.nP),nnlsWork_.ampVec.coeffRef(idxp));
494  std::swap(nnlsWork_.bxs.coeffRef(nnlsWork_.nP),nnlsWork_.bxs.coeffRef(idxp));
495  ++nnlsWork_.nP;
496 }
497 
498 void MahiFit::nnlsConstrainParameter(Index minratioidx) const {
499  nnlsWork_.aTaMat.col(nnlsWork_.nP-1).swap(nnlsWork_.aTaMat.col(minratioidx));
500  nnlsWork_.aTaMat.row(nnlsWork_.nP-1).swap(nnlsWork_.aTaMat.row(minratioidx));
501  nnlsWork_.pulseMat.col(nnlsWork_.nP-1).swap(nnlsWork_.pulseMat.col(minratioidx));
502  std::swap(nnlsWork_.aTbVec.coeffRef(nnlsWork_.nP-1),nnlsWork_.aTbVec.coeffRef(minratioidx));
503  std::swap(nnlsWork_.ampVec.coeffRef(nnlsWork_.nP-1),nnlsWork_.ampVec.coeffRef(minratioidx));
504  std::swap(nnlsWork_.bxs.coeffRef(nnlsWork_.nP-1),nnlsWork_.bxs.coeffRef(minratioidx));
505  --nnlsWork_.nP;
506 
507 }
508 
509 void MahiFit::phase1Debug(const HBHEChannelInfo& channelData,
510  MahiDebugInfo& mdi) const {
511 
512  float recoEnergy, recoTime, chi2;
513  bool use3;
514  phase1Apply(channelData, recoEnergy, recoTime, use3, chi2);
515 
516 
517  mdi.nSamples = channelData.nSamples();
518  mdi.soi = channelData.soi();
519 
520  mdi.use3 = use3;
521 
522  mdi.inTimeConst = nnlsWork_.dt;
523  mdi.inPedAvg = 0.25*( channelData.tsPedestalWidth(0)*channelData.tsPedestalWidth(0)+
524  channelData.tsPedestalWidth(1)*channelData.tsPedestalWidth(1)+
525  channelData.tsPedestalWidth(2)*channelData.tsPedestalWidth(2)+
526  channelData.tsPedestalWidth(3)*channelData.tsPedestalWidth(3) );
527  mdi.inGain = channelData.tsGain(0);
528 
529  for (unsigned int iTS=0; iTS<channelData.nSamples(); ++iTS) {
530 
531  double charge = channelData.tsRawCharge(iTS);
532  double ped = channelData.tsPedestal(iTS);
533 
534  mdi.inNoiseADC[iTS] = (1./sqrt(12))*channelData.tsDFcPerADC(iTS);
535 
536  if ( (charge-ped)>channelData.tsPedestalWidth(iTS)) {
537  mdi.inNoisePhoto[iTS] = sqrt((charge-ped)*channelData.fcByPE());
538  }
539  else { mdi.inNoisePhoto[iTS] = 0; }
540 
541  mdi.inPedestal[iTS] = channelData.tsPedestalWidth(iTS);
542  mdi.totalUCNoise[iTS] = nnlsWork_.noiseTerms.coeffRef(iTS);
543 
544  if (channelData.hasTimeInfo()) {
545  mdi.inputTDC[iTS] = channelData.tsRiseTime(iTS);
546  }
547  else { mdi.inputTDC[iTS]=-1; }
548 
549  }
550 
551  mdi.arrivalTime = recoTime;
552  mdi.chiSq = chi2;
553 
554  for (unsigned int iBX=0; iBX<nnlsWork_.nPulseTot; ++iBX) {
555  if (nnlsWork_.bxs.coeff(iBX)==0) {
556  mdi.mahiEnergy=nnlsWork_.ampVec.coeff(iBX);
557  for(unsigned int iTS=0; iTS<nnlsWork_.tsSize; ++iTS){
558  mdi.count[iTS] = iTS;
559  mdi.inputTS[iTS] = nnlsWork_.amplitudes.coeff(iTS);
560  mdi.itPulse[iTS] = nnlsWork_.pulseMat.col(iBX).coeff(iTS);
561  }
562  }
563  else if (nnlsWork_.bxs.coeff(iBX)==pedestalBX_) {
564  mdi.pedEnergy=nnlsWork_.ampVec.coeff(iBX);
565  }
566  else if (nnlsWork_.bxs.coeff(iBX)==-1) {
567  mdi.pEnergy=nnlsWork_.ampVec.coeff(iBX);
568  for(unsigned int iTS=0; iTS<nnlsWork_.tsSize; ++iTS){
569  mdi.pPulse[iTS] = nnlsWork_.pulseMat.col(iBX).coeff(iTS);
570  }
571  }
572  else if (nnlsWork_.bxs.coeff(iBX)==1) {
573  mdi.nEnergy=nnlsWork_.ampVec.coeff(iBX);
574  for(unsigned int iTS=0; iTS<nnlsWork_.tsSize; ++iTS){
575  mdi.nPulse[iTS] = nnlsWork_.pulseMat.col(iBX).coeff(iTS);
576  }
577  }
578  }
579 }
580 
581 
582 void MahiFit::solveSubmatrix(PulseMatrix& mat, PulseVector& invec, PulseVector& outvec, unsigned nP) const {
583  using namespace Eigen;
584  switch( nP ) { // pulse matrix is always square.
585  case 10:
586  {
587  Matrix<double,10,10> temp = mat;
588  outvec.head<10>() = temp.ldlt().solve(invec.head<10>());
589  }
590  break;
591  case 9:
592  {
593  Matrix<double,9,9> temp = mat.topLeftCorner<9,9>();
594  outvec.head<9>() = temp.ldlt().solve(invec.head<9>());
595  }
596  break;
597  case 8:
598  {
599  Matrix<double,8,8> temp = mat.topLeftCorner<8,8>();
600  outvec.head<8>() = temp.ldlt().solve(invec.head<8>());
601  }
602  break;
603  case 7:
604  {
605  Matrix<double,7,7> temp = mat.topLeftCorner<7,7>();
606  outvec.head<7>() = temp.ldlt().solve(invec.head<7>());
607  }
608  break;
609  case 6:
610  {
611  Matrix<double,6,6> temp = mat.topLeftCorner<6,6>();
612  outvec.head<6>() = temp.ldlt().solve(invec.head<6>());
613  }
614  break;
615  case 5:
616  {
617  Matrix<double,5,5> temp = mat.topLeftCorner<5,5>();
618  outvec.head<5>() = temp.ldlt().solve(invec.head<5>());
619  }
620  break;
621  case 4:
622  {
623  Matrix<double,4,4> temp = mat.topLeftCorner<4,4>();
624  outvec.head<4>() = temp.ldlt().solve(invec.head<4>());
625  }
626  break;
627  case 3:
628  {
629  Matrix<double,3,3> temp = mat.topLeftCorner<3,3>();
630  outvec.head<3>() = temp.ldlt().solve(invec.head<3>());
631  }
632  break;
633  case 2:
634  {
635  Matrix<double,2,2> temp = mat.topLeftCorner<2,2>();
636  outvec.head<2>() = temp.ldlt().solve(invec.head<2>());
637  }
638  break;
639  case 1:
640  {
641  Matrix<double,1,1> temp = mat.topLeftCorner<1,1>();
642  outvec.head<1>() = temp.ldlt().solve(invec.head<1>());
643  }
644  break;
645  default:
646  throw cms::Exception("HcalMahiWeirdState")
647  << "Weird number of pulses encountered in Mahi, module is configured incorrectly!";
648  }
649 }
650 
652 
654  nnlsWork_.tsSize=0;
659  nnlsWork_.dt=0;
660 
664 
665  nnlsWork_.amplitudes.setZero();
666  nnlsWork_.invCovMat.setZero();
667  nnlsWork_.noiseTerms.setZero();
668  nnlsWork_.pedConstraint.setZero();
669  nnlsWork_.residuals.setZero();
670 
671 
672 
673 }
unsigned int nPulseTot
Definition: MahiFit.h:19
dbl * delta
Definition: mlp_gen.cc:36
void nnls() const
Definition: MahiFit.cc:355
void phase1Apply(const HBHEChannelInfo &channelData, float &reconstructedEnergy, float &reconstructedTime, bool &useTriple, float &chi2) const
Definition: MahiFit.cc:40
float chiSqSwitch_
Definition: MahiFit.h:182
float itPulse[MaxSVSize]
Definition: MahiFit.h:112
SamplePulseMatrix invcovp
Definition: MahiFit.h:72
HcalTimeSlew::BiasSetting slewFlavor_
Definition: MahiFit.h:185
bool hasTimeInfo() const
double tsGain(const unsigned ts) const
void nnlsConstrainParameter(Index minratioidx) const
Definition: MahiFit.cc:498
SampleVector amplitudes
Definition: MahiFit.h:31
MahiNnlsWorkspace nnlsWork_
Definition: MahiFit.h:167
BXVector::Index Index
Definition: MahiFit.h:144
double singlePulseShapeFunc(const double *x)
void solveSubmatrix(PulseMatrix &mat, PulseVector &invec, PulseVector &outvec, unsigned nP) const
Definition: MahiFit.cc:582
double delay(double fC, BiasSetting bias=Medium) const
Returns the amount (ns) by which a pulse of the given number of fC will be delayed by the timeslew ef...
Definition: HcalTimeSlew.cc:14
bool applyTimeSlew_
Definition: MahiFit.h:184
void resetPulseShapeTemplate(const HcalPulseShapes::Shape &ps)
Definition: MahiFit.cc:476
unsigned soi() const
PulseVector ampVec
Definition: MahiFit.h:68
SampleDecompLLT covDecomp
Definition: MahiFit.h:77
PulseVector ampvecpermtest
Definition: MahiFit.h:70
std::array< FullSampleVector, MaxPVSize > pulseShapeArray
Definition: MahiFit.h:47
float meanTime_
Definition: MahiFit.h:188
void nnlsUnconstrainParameter(Index idxp) const
Definition: MahiFit.cc:488
std::array< double, MaxSVSize > pulseM
Definition: MahiFit.h:54
float count[MaxSVSize]
Definition: MahiFit.h:109
double tsDelay1GeV_
Definition: MahiFit.h:186
double tsPedestal(const unsigned ts) const
float totalUCNoise[MaxSVSize]
Definition: MahiFit.h:99
float nPulse[MaxSVSize]
Definition: MahiFit.h:114
float inNoiseADC[MaxSVSize]
Definition: MahiFit.h:94
float pedEnergy
Definition: MahiFit.h:107
SamplePulseMatrix pulseDerivMat
Definition: MahiFit.h:61
std::array< double, MaxSVSize > pulseN
Definition: MahiFit.h:53
int bxOffsetConf_
Definition: MahiFit.h:201
PulseVector aTbVec
Definition: MahiFit.h:74
double tsRawCharge(const unsigned ts) const
float nnlsThresh_
Definition: MahiFit.h:198
float inPedestal[MaxSVSize]
Definition: MahiFit.h:97
int cntsetPulseShape_
Definition: MahiFit.h:204
void onePulseMinimize() const
Definition: MahiFit.cc:446
std::unique_ptr< FitterFuncs::PulseShapeFunctor > psfPtr_
Definition: MahiFit.h:205
MahiFit()
Definition: MahiFit.cc:4
Eigen::Matrix< double, FullSampleVectorSize, 1 > FullSampleVector
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:18
void doFit(std::array< float, 3 > &correctedOutput, const int nbx) const
Definition: MahiFit.cc:128
unsigned int bxSizeConf_
Definition: MahiFit.h:200
double fcByPE() const
int nMaxItersMin_
Definition: MahiFit.h:194
PulseVector residuals
Definition: MahiFit.h:64
Eigen::Matrix< double, 1, 1 > SingleVector
static float timeLimit_
Definition: MahiFit.h:177
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int nSamples
Definition: MahiFit.h:84
float chiSq
Definition: MahiFit.h:102
#define end
Definition: vmac.h:39
float nEnergy
Definition: MahiFit.h:106
T min(T a, T b)
Definition: MathUtil.h:58
double calculateArrivalTime() const
Definition: MahiFit.cc:325
SampleMatrix pedConstraint
Definition: MahiFit.h:40
std::vector< int > activeBXs_
Definition: MahiFit.h:192
std::array< FullSampleVector, MaxPVSize > pulseDerivArray
Definition: MahiFit.h:50
bool use3
Definition: MahiFit.h:87
const unsigned int fullTSofInterest_
Definition: MahiFit.h:171
float inGain
Definition: MahiFit.h:92
float arrivalTime
Definition: MahiFit.h:103
SampleMatrix invCovMat
Definition: MahiFit.h:34
void updatePulseShape(double itQ, FullSampleVector &pulseShape, FullSampleVector &pulseDeriv, FullSampleMatrix &pulseCov) const
Definition: MahiFit.cc:249
unsigned int tsOffset
Definition: MahiFit.h:21
void resetWorkspace() const
Definition: MahiFit.cc:651
void phase1Debug(const HBHEChannelInfo &channelData, MahiDebugInfo &mdi) const
Definition: MahiFit.cc:509
float inPedAvg
Definition: MahiFit.h:91
std::unique_ptr< ROOT::Math::Functor > pfunctor_
Definition: MahiFit.h:206
Eigen::Matrix< double, FullSampleVectorSize, FullSampleVectorSize > FullSampleMatrix
float tsRiseTime(const unsigned ts) const
double tsPedestalWidth(const unsigned ts) const
double calculateChiSq() const
Definition: MahiFit.cc:458
PulseMatrix aTaMat
Definition: MahiFit.h:73
float mahiEnergy
Definition: MahiFit.h:101
unsigned int fullTSOffset
Definition: MahiFit.h:22
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, PulseVectorSize, 1 > PulseVector
SamplePulseMatrix pulseMat
Definition: MahiFit.h:58
bool dynamicPed_
Definition: MahiFit.h:180
std::array< FullSampleMatrix, MaxPVSize > pulseCovArray
Definition: MahiFit.h:44
float inputTS[MaxSVSize]
Definition: MahiFit.h:110
int inputTDC[MaxSVSize]
Definition: MahiFit.h:111
float timeSigmaSiPM_
Definition: MahiFit.h:190
float inNoisePhoto[MaxSVSize]
Definition: MahiFit.h:96
SampleVector noiseTerms
Definition: MahiFit.h:37
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
float pEnergy
Definition: MahiFit.h:105
#define begin
Definition: vmac.h:32
void setParameters(bool iDynamicPed, double iTS4Thresh, double chiSqSwitch, bool iApplyTimeSlew, HcalTimeSlew::BiasSetting slewFlavor, double iMeanTime, double iTimeSigmaHPD, double iTimeSigmaSiPM, const std::vector< int > &iActiveBXs, int iNMaxItersMin, int iNMaxItersNNLS, double iDeltaChiSqThresh, double iNnlsThresh)
Definition: MahiFit.cc:9
float ts4Thresh_
Definition: MahiFit.h:181
float pPulse[MaxSVSize]
Definition: MahiFit.h:113
const HcalTimeSlew * hcalTimeSlewDelay_
Definition: MahiFit.h:146
unsigned int tsSize
Definition: MahiFit.h:20
float deltaChiSqThresh_
Definition: MahiFit.h:197
void updateCov() const
Definition: MahiFit.cc:303
float timeSigmaHPD_
Definition: MahiFit.h:189
unsigned int nP
Definition: MahiFit.h:67
BXVector bxs
Definition: MahiFit.h:28
const HcalPulseShapes::Shape * currentPulseShape_
Definition: MahiFit.h:145
float inTimeConst
Definition: MahiFit.h:89
unsigned nSamples() const
int nMaxItersNNLS_
Definition: MahiFit.h:195
std::array< double, MaxSVSize > pulseP
Definition: MahiFit.h:55
Eigen::Matrix< double, 1, 1 > SingleMatrix
PulseVector updateWork
Definition: MahiFit.h:75
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, 0, PulseVectorSize, PulseVectorSize > PulseMatrix
double minimize() const
Definition: MahiFit.cc:216
static int pedestalBX_
Definition: MahiFit.h:173
float tsDFcPerADC(const unsigned ts) const
void setPulseShapeTemplate(const HcalPulseShapes::Shape &ps, const HcalTimeSlew *hcalTimeSlewDelay)
Definition: MahiFit.cc:463