ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
dqm_algorithms::TripleGaussCollFit Class Reference

#include <TripleGaussCollFit.h>

Inheritance diagram for dqm_algorithms::TripleGaussCollFit:
Collaboration diagram for dqm_algorithms::TripleGaussCollFit:

Public Member Functions

 TripleGaussCollFit (const std::string &_name)
 
 ~TripleGaussCollFit ()
 
dqm_core::Resultexecute (const std::string &s, const TObject &object, const dqm_core::AlgorithmConfig &cfg)
 
void printDescription (std::ostream &out)
 
TripleGaussCollFitclone ()
 

Private Member Functions

void fitSingle (TH1 *hist1D)
 

Private Attributes

std::string m_name
 
TF1 * m_gaus3_fn
 

Detailed Description

Definition at line 19 of file TripleGaussCollFit.h.

Constructor & Destructor Documentation

◆ TripleGaussCollFit()

dqm_algorithms::TripleGaussCollFit::TripleGaussCollFit ( const std::string &  _name)

Definition at line 169 of file TripleGaussCollFit.cxx.

169  : m_name(name) {
170 
171  //Register our instance with the Alg. Manager
172  m_gaus3_fn = 0;
173  dqm_core::AlgorithmManager::instance().registerAlgorithm( "Gaus3_" + m_name +"_Fit", this );
174 
175  }

◆ ~TripleGaussCollFit()

dqm_algorithms::TripleGaussCollFit::~TripleGaussCollFit ( )

Definition at line 177 of file TripleGaussCollFit.cxx.

177  {
178 
179  if (m_gaus3_fn != 0) {
180  delete m_gaus3_fn;
181  m_gaus3_fn = 0;
182  }
183 
184  }

Member Function Documentation

◆ clone()

TripleGaussCollFit * dqm_algorithms::TripleGaussCollFit::clone ( )

Definition at line 186 of file TripleGaussCollFit.cxx.

186  {
187  return new TripleGaussCollFit(m_name);
188  }

◆ execute()

dqm_core::Result * dqm_algorithms::TripleGaussCollFit::execute ( const std::string &  s,
const TObject &  object,
const dqm_core::AlgorithmConfig &  cfg 
)

Definition at line 220 of file TripleGaussCollFit.cxx.

220  {
221 
222  const TH1* histogram;
223  if(object.IsA()->InheritsFrom("TH1")) //or this can be done via dynamic casting
224  {
225  histogram = static_cast<const TH1*>(&object);
226  if (histogram->GetDimension() > 2 ){
227  throw dqm_core::BadConfig( ERS_HERE, m_name, "called with histogram of dimension > 2" );
228  }
229  }
230  else
231  throw dqm_core::BadConfig( ERS_HERE, m_name, "called with object that does not inherit from TH1" );
232 
233  //Setup our TF1: find the binwidth
234  Double_t binwidth = 0;
235  if (histogram->GetDimension() == 1) //running in 1D mode
236  if (histogram->GetNbinsX() >= 1) {
237  binwidth = histogram->GetBinWidth(1);
238  } else {
239  throw dqm_core::BadConfig( ERS_HERE, m_name, "called with histogram with no bins");
240  }
241 
242  else { //running in 2D mode {
243  const TH1* proj = static_cast<const TH2*>(histogram)->ProjectionY("", 0, 0);
244  if (proj->GetNbinsX() >= 1) {
245  binwidth = proj ->GetBinWidth(1);
246  } else {
247  throw dqm_core::BadConfig( ERS_HERE, m_name, "called with histogram with no bins");
248  }
249  }
250  #ifdef PARAM_IS_AREA
251  m_gaus3_fn = new TF1("gaus3", Form("[3]/[2]/2.5066*%f*exp(-0.5*((x-[0]+[1])/[2])**2) + [4]/[2]/2.5066*%f*exp(-0.5*((x-[0])/[2])**2) + [5]/[2]/2.5066*%f*exp(-0.5*((x-[0]-[1])/[2])**2)", binwidth, binwidth, binwidth), -100, 100);
252  #else
253  m_gaus3_fn = new TF1("gaus3", "[3]*exp(-0.5*((x-[0]+[1])/[2])**2) + [4]*exp(-0.5*((x-[0])/[2])**2) + [5]*exp(-0.5*((x-[0]-[1])/[2])**2)", -100, 100);
254  #endif
255  m_gaus3_fn->SetParName(0, "Mean_zero_gaus"); //mean of gaussian centered at zero, should be close to zero
256  m_gaus3_fn->SetParName(1, "Mean_offzero_gaus"); //mean of other two gaussians, should be close to 20
257  m_gaus3_fn->SetParName(2, "Width_all"); //shared width, should be about 5
258  m_gaus3_fn->SetParName(3, "N_negative_gaus"); //normalization for negative-centered gaussian
259  m_gaus3_fn->SetParName(4, "N_zero_gaus"); //normalization for zero-centered gaussian
260  m_gaus3_fn->SetParName(5, "N_positive_gaus"); //normalization for positive-centered gaussian
261 
262  Double_t resolutionAll, meanZeroPeak, meanNonzeroPeaks, minEvents;
263  param_map mymap = cfg.getParameters();
264 
265  meanZeroPeak = dqm_algorithms::tools::GetFirstFromMap("meanZeroPeak", mymap, 0.0);
266  meanNonzeroPeaks = dqm_algorithms::tools::GetFirstFromMap("meanNonzeroPeaks", mymap, 23.2);
267  resolutionAll = dqm_algorithms::tools::GetFirstFromMap("resolutionAll", mymap, 4.57);
268  minEvents = dqm_algorithms::tools::GetFirstFromMap("minEvents", mymap, 5.0);
269 
270  //we DO NOT allow fits by default. If the parameter is not found, the retval is 0
271  if ( dqm_algorithms::tools::GetFirstFromMap("allowFitMean", mymap, 0) == 1 ) {
272 
273  //according to Peter, this can behave strangely, so we don't allow too much horizontal translation
274  m_gaus3_fn->SetParameter(0, meanZeroPeak);
275  m_gaus3_fn->SetParLimits(0, meanZeroPeak-5, meanZeroPeak+5);
276  }
277  else
278  m_gaus3_fn->FixParameter(0, meanZeroPeak);
279 
280  if ( dqm_algorithms::tools::GetFirstFromMap("allowFitMeanNonzeroPeaks", mymap, 0) == 1 ) {
281  m_gaus3_fn->SetParameter(1, meanNonzeroPeaks);
282  m_gaus3_fn->SetParLimits(1, meanNonzeroPeaks-10, meanNonzeroPeaks+10);
283  }
284  else
285  m_gaus3_fn->FixParameter(1, meanNonzeroPeaks);
286 
287  if ( dqm_algorithms::tools::GetFirstFromMap("allowFitResolution", mymap, 0) == 1 ) {
288  m_gaus3_fn->SetParameter(2, resolutionAll);
289  m_gaus3_fn->SetParLimits(2, 1, 10);
290  }
291  else {
292  m_gaus3_fn->FixParameter(2, resolutionAll);
293 
294  }
295  // get some starting values for the histogram
296 
298 
299  if (histogram->GetDimension() == 1) {
300  fitSingle(const_cast<TH1*>(histogram));
301 
302  try {
303 
306  for (err_map::const_iterator peit = paramErrors.begin(); peit != paramErrors.end(); ++peit) {
307  result->tags_[(*peit).first + " Error"] = (*peit).second;
308  }
309 
310  }
311  catch ( dqm_core::Exception & ex) {
312  throw dqm_core::BadConfig( ERS_HERE, m_name, ex.what(), ex);
313  }
314  }
315  else { //working with a 2D histogram
316 
317  int nxbin = histogram->GetNbinsX();
318  Double_t minsig = dqm_algorithms::tools::GetFirstFromMap("centralPeakMinSignificance", mymap, 3.0);
319 
320  bool writeSig = (dqm_algorithms::tools::GetFirstFromMap("reportSignificance", mymap, 0) == 1);
321 
322 
323  unsigned int psz = (unsigned int) std::log10(nxbin)+1;
324 
325  std::vector<int> goodLB;
326  char buf[10];
327  const std::string sig_str = "SIG_LB_";
328 
329  for (int lb = 0; lb < nxbin; lb++) {
330 
331  sprintf(buf, fmt, psz, lb); //to avoid possible leaks (?) - should see how DQ framework behaves
332  TH1D* proj = ((TH2*) histogram)->ProjectionY(buf, lb, lb);
333  Double_t good_entries = proj->GetEntries() - proj->GetBinContent(0) - proj->GetBinContent(proj->GetNbinsX()+1);
334  if (good_entries < minEvents) {
335  if (writeSig)
336  result->tags_[sig_str+buf] = 0;
337  continue; //nothing to fit here, move along
338  }
339 
340  // I probably need to reset parameters 0-2 if they are not fixed
341  if ( dqm_algorithms::tools::GetFirstFromMap("allowFitMeanZeroPeak", mymap, 0) == 1 )
342  m_gaus3_fn->SetParameter(0, meanZeroPeak);
343 
344  if ( dqm_algorithms::tools::GetFirstFromMap("allowFitMeanNonzeroPeaks", mymap, 0) == 1 )
345  m_gaus3_fn->SetParameter(1, meanNonzeroPeaks);
346 
347  if ( dqm_algorithms::tools::GetFirstFromMap("allowFitResolution", mymap, 0) == 1 )
348  m_gaus3_fn->SetParameter(2, resolutionAll);
349 
350  fitSingle(proj);
351 
352 #ifdef TC_WORKBENCH
353  result->histos_.push_back((TH1D*)proj->Clone());
354 #endif
355 
356  if (m_gaus3_fn->GetParameter(4) == 0) {
357  if (writeSig)
358  result->tags_[sig_str+buf] = 0;
359  continue;
360  }
361  Double_t sig = std::abs(m_gaus3_fn->GetParameter(4) / m_gaus3_fn->GetParError(4));
362  if (writeSig)
363  result->tags_[sig_str+buf] = sig;
364 
365  if (sig > minsig)
366  goodLB.push_back(lb); //this is grossly non-optimal
367 
368 
369  } //end loop over lumi blocks
370 
371  if (goodLB.size() != 0)
372  multLB_writeTags(&goodLB, result, histogram);
373 
374  }
375  return result;
376  }

◆ fitSingle()

void dqm_algorithms::TripleGaussCollFit::fitSingle ( TH1 *  hist1D)
private

Definition at line 385 of file TripleGaussCollFit.cxx.

385  {
386 
387  Double_t startVal;
388  const Double_t window = 5.0;
389 
390  Double_t offset_all = m_gaus3_fn->GetParameter(0);
391  Double_t offset_nz = m_gaus3_fn->GetParameter(1);
392 
393  startVal = getStartValue(hist1D, offset_all-offset_nz-window, offset_all-offset_nz+window); ADJUST_VAL;
394  if (startVal == 0.0)
395  m_gaus3_fn->FixParameter(3, 0.0);
396  else {
397  m_gaus3_fn->SetParameter(3, startVal);
398  // DO NOT do something like this if we are using areas!!
399  // m_gaus3_fn->SetParLimits(3, 0, 5 * startVal);
400  }
401 
402  startVal = getStartValue(hist1D, offset_all-window, offset_all+window); ADJUST_VAL;
403  if (startVal == 0.0)
404  m_gaus3_fn->FixParameter(4, 0.0);
405  else {
406  m_gaus3_fn->SetParameter(4, startVal);
407  // m_gaus3_fn->SetParLimits(4, 0, 100 * startVal);
408  }
409  startVal = getStartValue(hist1D, offset_all+offset_nz-window , offset_all+offset_nz+window); ADJUST_VAL;
410  if (startVal == 0.0)
411  m_gaus3_fn->FixParameter(5, 0.0);
412  else {
413  m_gaus3_fn->SetParameter(5, startVal);
414  }
415 
416 
417 
418  hist1D->Fit(m_gaus3_fn, "QN");
419 
420  }

◆ printDescription()

void dqm_algorithms::TripleGaussCollFit::printDescription ( std::ostream &  out)

Definition at line 191 of file TripleGaussCollFit.cxx.

191  {
192 
193  out << "Gaus3_"+ m_name +"_Fit: specialized fit for the Tile timining difference plot." << std::endl;
194  out << "Current parameter values: " << std::endl;
195 
196  if (m_gaus3_fn != 0)
197  for (int i=0; i < m_gaus3_fn->GetNpar(); i++)
198  out << " Param. " << i << ": " << m_gaus3_fn->GetParName(i) << " , current value: "
199  << m_gaus3_fn->GetParameter(i) << std::endl;
200 
201  else
202  out << " execute() has not been called" << std::endl;
203 
204  out << "Parameter list: " << std::endl
205  << " allowFitMean: 1 allows fitting for a shift in the entire function around zero by up to 5ns" << std::endl
206  << " allowFitMeanNonzeroPeaks: 1 allows fitting of the distance between center and off-center Gaussians" << std::endl
207  << " allowFitResolution: 1 allows fitting the (shared) width of the Gaussians" << std::endl
208  << " reportSignificance: 1 reports the central peak significance for each LB as a tag" << std::endl
209  << " meanZeroPeak: starting or fixed mean of the Gaussian centered at zero" << std::endl
210  << " meanNonZeroPeaks: starting or fixed mean of the other Gaussians" << std::endl
211  << " resolutionAll: starting or fixed value of the width of the Gaussians" << std::endl
212  << " minSignificance: number of events required for checks to be valid, undefined if not set." << std::endl
213  << " centralPeakMinSignificance: significance of central peak required for a LB to pass threshold; default is 3.0" << std::endl
214  << " minEvents: number of events required to attempt a fit; default is 5." << std::endl ;
215 
216  out << "Currently, no thresholds are defined." << std::endl;
217 
218  }

Member Data Documentation

◆ m_gaus3_fn

TF1* dqm_algorithms::TripleGaussCollFit::m_gaus3_fn
private

Definition at line 33 of file TripleGaussCollFit.h.

◆ m_name

std::string dqm_algorithms::TripleGaussCollFit::m_name
private

Definition at line 32 of file TripleGaussCollFit.h.


The documentation for this class was generated from the following files:
get_generator_info.result
result
Definition: get_generator_info.py:21
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
dqm_algorithms::TripleGaussCollFit::m_name
std::string m_name
Definition: TripleGaussCollFit.h:32
binwidth
bool binwidth
Definition: listroot.cxx:58
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
err_map
std::map< std::string, double > err_map
Definition: TripleGaussCollFit.cxx:163
ADJUST_VAL
#define ADJUST_VAL
Definition: TripleGaussCollFit.cxx:380
getStartValue
Double_t getStartValue(TH1 *thehist, Double_t minx, Double_t maxx)
Definition: TripleGaussCollFit.cxx:70
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
dqm_algorithms::TripleGaussCollFit::m_gaus3_fn
TF1 * m_gaus3_fn
Definition: TripleGaussCollFit.h:33
dqm_algorithms::TripleGaussCollFit::fitSingle
void fitSingle(TH1 *hist1D)
Definition: TripleGaussCollFit.cxx:385
python.BunchSpacingUtils.lb
lb
Definition: BunchSpacingUtils.py:88
dqm_algorithms::tools::GetFitParamErrors
std::map< std::string, double > GetFitParamErrors(const TF1 *func)
Definition: AlgorithmHelper.cxx:44
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.DecayParser.buf
buf
print ("=> [%s]"cmd)
Definition: DecayParser.py:27
multLB_writeTags
void multLB_writeTags(std::vector< int > *goodLB, dqm_core::Result *result, const TH1 *thehist)
Definition: TripleGaussCollFit.cxx:86
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
python.BuildSignatureFlags.sig
sig
Definition: BuildSignatureFlags.py:218
make_coralServer_rep.proj
proj
Definition: make_coralServer_rep.py:48
dqm_algorithms::TripleGaussCollFit::TripleGaussCollFit
TripleGaussCollFit(const std::string &_name)
Definition: TripleGaussCollFit.cxx:169
dqm_algorithms::tools::GetFitParams
std::map< std::string, double > GetFitParams(const TF1 *func)
Definition: AlgorithmHelper.cxx:30
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
fmt
param_map
std::map< std::string, double > param_map
Definition: TripleGaussCollFit.cxx:162
pickleTool.object
object
Definition: pickleTool.py:30
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
histogram
std::string histogram
Definition: chains.cxx:52