@@ -354,16 +354,19 @@ bool DQMHistAnalysisEventT0Module::processHistogram(TH1* h, TString tag)
354354 return false ;
355355 }
356356
357- int nToFit = h->GetEntries ();// - h->GetBinContent(0) - h->GetBinContent(h->GetNbinsX()+1);
358- if (nToFit < m_nEntriesMin) {
357+ // The default value for the EventT0 value is -1000, but bins start at -100, so we might mostly fill the underflow bin if
358+ // EventT0 for a detector is not present. And also the nominal EventT0 might be too big or too small. Only use the content
359+ // of the actually useful bins to decide whether or not to fit the histogram.
360+ auto nValidEntries = h->GetEntries () - h->GetBinContent (0 ) - h->GetBinContent (h->GetNbinsX () + 1 );
361+ if (static_cast <uint>(nValidEntries) < m_nEntriesMin) {
359362 B2DEBUG (20 , " not enough entries" );
360363 m_monObj->setVariable (Form (" fit_%s" , tag.Data ()), 0 );
361364 return false ;
362365 }
363366
364367
365- // scale the histogram
366- h->Scale (1 . / h-> GetEntries () );
368+ // scale the histogram only with content of valid bins, ignore over and underflow bins
369+ h->Scale (1 . / nValidEntries );
367370 h->GetXaxis ()->SetRangeUser (-50 , 50 );
368371
369372 // define the fitting function
@@ -400,7 +403,7 @@ bool DQMHistAnalysisEventT0Module::processHistogram(TH1* h, TString tag)
400403 gauss2.SetParameters (par[0 ] * (1 - par[1 ]), par[4 ], par[5 ]);
401404
402405 m_monObj->setVariable (Form (" fit_%s" , tag.Data ()), 1 );
403- m_monObj->setVariable (Form (" N_%s" , tag.Data ()), h-> GetEntries () , TMath::Sqrt (h-> GetEntries () ));
406+ m_monObj->setVariable (Form (" N_%s" , tag.Data ()), nValidEntries , TMath::Sqrt (nValidEntries ));
404407 m_monObj->setVariable (Form (" f_%s" , tag.Data ()), par[1 ], parErr[1 ]);
405408 m_monObj->setVariable (Form (" mean1_%s" , tag.Data ()), par[2 ], parErr[2 ]);
406409 m_monObj->setVariable (Form (" sigma1_%s" , tag.Data ()), par[3 ], parErr[3 ]);
0 commit comments