CMS 3D CMS Logo

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

#include <SymmetryFit.h>

Static Public Member Functions

static TF1 * fitfunction ()
 
static std::string name (std::string base)
 
static std::vector< double > pol2_from_pol2 (TH1 *hist)
 
static std::vector< double > pol2_from_pol3 (TH1 *hist)
 
static TH1 * symmetryChi2 (const TH1 *, const std::pair< unsigned, unsigned >)
 
static TH1 * symmetryChi2 (std::string, const std::vector< TH1 * > &, const std::pair< unsigned, unsigned >)
 

Private Member Functions

float chi2 (std::pair< unsigned, unsigned >)
 
float chi2_element (std::pair< unsigned, unsigned >)
 
std::vector< std::pair< unsigned, unsigned > > continuousRanges () const
 
void fillchi2 ()
 
std::pair< unsigned, unsigned > findUsableMinMax () const
 
int fit ()
 
void makeChi2Histogram ()
 
SymmetryFit operator+= (const SymmetryFit &R)
 
 SymmetryFit (const TH1 *, const std::pair< unsigned, unsigned >)
 

Private Attributes

TH1 * chi2_
 
const unsigned minDF_
 
const std::pair< unsigned, unsigned > minmaxUsable_
 
unsigned ndf_
 
const std::pair< unsigned, unsigned > range_
 
const TH1 * symm_candidate_
 

Detailed Description

Definition at line 8 of file SymmetryFit.h.

Constructor & Destructor Documentation

◆ SymmetryFit()

SymmetryFit::SymmetryFit ( const TH1 *  h,
const std::pair< unsigned, unsigned >  r 
)
private

Definition at line 38 of file SymmetryFit.cc.

39  : symm_candidate_(h),
40  minDF_(r.second - r.first),
41  range_(r),
43  ndf_(minmaxUsable_.first < minmaxUsable_.second ? minmaxUsable_.second - minmaxUsable_.first : 0),
44  chi2_(nullptr) {
46  fillchi2();
47 }

References fillchi2(), and makeChi2Histogram().

Member Function Documentation

◆ chi2()

float SymmetryFit::chi2 ( std::pair< unsigned, unsigned >  point)
private

Definition at line 106 of file SymmetryFit.cc.

106  {
107  point.first -= minmaxUsable_.first;
108  point.second += minmaxUsable_.first;
109  float XX = 0;
110  unsigned i = ndf_;
111  while (i-- > 0) {
112  XX += chi2_element(point);
113  point.first--;
114  point.second++;
115  }
116  return XX;
117 }

References chi2_element(), mps_fire::i, minmaxUsable_, ndf_, point, and XX.

Referenced by fillchi2().

◆ chi2_element()

float SymmetryFit::chi2_element ( std::pair< unsigned, unsigned >  range)
private

Definition at line 119 of file SymmetryFit.cc.

119  {
120  float y0(symm_candidate_->GetBinContent(range.first)), y1(symm_candidate_->GetBinContent(range.second)),
121  e0(symm_candidate_->GetBinError(range.first)), e1(symm_candidate_->GetBinError(range.second));
122  assert(e0 && e1);
123 
124  return pow(y0 - y1, 2) / (e0 * e0 + e1 * e1);
125 }

References cms::cuda::assert(), StorageManager_cfg::e1, funct::pow(), FastTimerService_cff::range, symm_candidate_, and testProducerWithPsetDescEmpty_cfi::y1.

Referenced by chi2().

◆ continuousRanges()

std::vector< std::pair< unsigned, unsigned > > SymmetryFit::continuousRanges ( ) const
private

Definition at line 81 of file SymmetryFit.cc.

81  {
82  std::vector<std::pair<unsigned, unsigned> > ranges;
83  const unsigned Nbins = symm_candidate_->GetNbinsX();
84  unsigned i = 0;
85  while (++i <= Nbins) {
86  if (symm_candidate_->GetBinError(i)) {
87  std::pair<unsigned, unsigned> range(i, i + 1);
88  while (++i <= Nbins && symm_candidate_->GetBinError(i))
89  range.second++;
90  ranges.push_back(range);
91  }
92  }
93  return ranges;
94 }

References mps_fire::i, SiStripMonitorCluster_cfi::Nbins, FastTimerService_cff::range, diffTwoXMLs::ranges, and symm_candidate_.

Referenced by findUsableMinMax().

◆ fillchi2()

void SymmetryFit::fillchi2 ( )
private

Definition at line 96 of file SymmetryFit.cc.

96  {
97  if (ndf_ < minDF_)
98  return;
99 
100  for (int i = 1; i <= chi2_->GetNbinsX(); ++i) {
101  const unsigned L(range_.first - 1 + (i - 1) / 2), R(range_.first + i / 2);
102  chi2_->SetBinContent(i, chi2(std::make_pair(L, R)));
103  }
104 }

References chi2(), chi2_, mps_fire::i, dttmaxenums::L, minDF_, ndf_, dttmaxenums::R, and range_.

Referenced by SymmetryFit().

◆ findUsableMinMax()

std::pair< unsigned, unsigned > SymmetryFit::findUsableMinMax ( ) const
private

Definition at line 58 of file SymmetryFit.cc.

58  {
59  unsigned NEAR(0), FAR(0);
60  const std::vector<std::pair<unsigned, unsigned> > cont = continuousRanges();
61  for (unsigned L = 0; L < cont.size(); L++) {
62  if (cont[L].first > range_.first)
63  continue;
64  for (unsigned R = L; R < cont.size(); R++) {
65  if (cont[R].second < range_.second)
66  continue;
67 
68  const unsigned far = std::min(range_.first - cont[L].first, cont[R].second - range_.second);
69  const unsigned near = std::max(range_.second < cont[L].second ? 0 : range_.second - cont[L].second,
70  cont[R].first < range_.first ? 0 : cont[R].first - range_.first);
71 
72  if ((far > near) && (far - near) > (FAR - NEAR)) {
73  FAR = far;
74  NEAR = near;
75  }
76  }
77  }
78  return std::make_pair(NEAR, FAR);
79 }

References generateEDF::cont, continuousRanges(), dqmdumpme::first, dttmaxenums::L, SiStripPI::max, min(), dttmaxenums::R, range_, and edm::second().

◆ fit()

int SymmetryFit::fit ( )
private

Definition at line 127 of file SymmetryFit.cc.

127  {
128  std::vector<double> p = pol2_from_pol3(chi2_);
129  if (p.empty() || p[0] < chi2_->GetBinCenter(1) || p[0] > chi2_->GetBinCenter(chi2_->GetNbinsX()))
130  return 7;
131 
132  std::unique_ptr<TF1> f(fitfunction());
133  f->SetParameter(0, p[0]);
134  f->SetParLimits(0, p[0], p[0]);
135  f->SetParameter(1, p[1]);
136  f->SetParLimits(1, p[1], p[1]);
137  f->SetParameter(2, p[2]);
138  f->SetParLimits(2, p[2], p[2]);
139  f->SetParameter(3, ndf_);
140  f->SetParLimits(3, ndf_, ndf_); //Fixed
141  chi2_->Fit(f.get(), "WQ");
142  return 0;
143 }

References chi2_, f, fitfunction(), ndf_, AlCaHLTBitMon_ParallelJobs::p, and pol2_from_pol3().

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

◆ fitfunction()

TF1 * SymmetryFit::fitfunction ( )
static

Definition at line 145 of file SymmetryFit.cc.

145  {
146  TF1* f = new TF1("SymmetryFit", "((x-[0])/[1])**2+[2]+0*[3]");
147  f->SetParName(0, "middle");
148  f->SetParName(1, "uncertainty");
149  f->SetParName(2, "chi2");
150  f->SetParName(3, "NDF");
151  return f;
152 }

References f, and tools::TF1.

Referenced by fit().

◆ makeChi2Histogram()

void SymmetryFit::makeChi2Histogram ( )
private

Definition at line 49 of file SymmetryFit.cc.

49  {
50  std::string XXname = name(symm_candidate_->GetName());
51  unsigned Nbins = 2 * (range_.second - range_.first) + 1;
52  double binwidth = symm_candidate_->GetBinWidth(1);
53  double low = symm_candidate_->GetBinCenter(range_.first) - 3 * binwidth / 4;
54  double up = symm_candidate_->GetBinCenter(range_.second - 1) + 3 * binwidth / 4;
55  chi2_ = new TH1F(XXname.c_str(), "", Nbins, low, up);
56 }

References chi2_, LaserClient_cfi::low, name(), SiStripMonitorCluster_cfi::Nbins, range_, AlCaHLTBitMon_QueryRunRegistry::string, symm_candidate_, and up.

Referenced by SymmetryFit().

◆ name()

static std::string SymmetryFit::name ( std::string  base)
inlinestatic

◆ operator+=()

SymmetryFit SymmetryFit::operator+= ( const SymmetryFit R)
inlineprivate

Definition at line 26 of file SymmetryFit.h.

26  {
27  ndf_ += R.ndf_;
28  chi2_->Add(R.chi2_);
29  return *this;
30  }

References chi2_, ndf_, and dttmaxenums::R.

◆ pol2_from_pol2()

std::vector< double > SymmetryFit::pol2_from_pol2 ( TH1 *  hist)
static

Definition at line 154 of file SymmetryFit.cc.

154  {
155  std::vector<double> v;
156 
157  //Need our own copy for thread safety
158  TF1 func("mypol2", "pol2");
159  int status = hist->Fit(&func, "WQ");
160  if (!status) {
161  std::vector<double> p;
162  p.push_back(func.GetParameter(0));
163  p.push_back(func.GetParameter(1));
164  p.push_back(func.GetParameter(2));
165  if (p[2] > 0) {
166  v.push_back(-0.5 * p[1] / p[2]);
167  v.push_back(1. / sqrt(p[2]));
168  v.push_back(p[0] - 0.25 * p[1] * p[1] / p[2]);
169  }
170  }
171  return v;
172 }

References TrackCollections2monitor_cff::func, compare::hist, AlCaHLTBitMon_ParallelJobs::p, mathSSE::sqrt(), mps_update::status, tools::TF1, and findQualityFiles::v.

◆ pol2_from_pol3()

std::vector< double > SymmetryFit::pol2_from_pol3 ( TH1 *  hist)
static

Definition at line 174 of file SymmetryFit.cc.

174  {
175  std::vector<double> v;
176 
177  auto func = std::make_unique<TF1>("mypol3", "pol3");
178  int status = hist->Fit(func.get(), "WQ");
179  if (!status) {
180  std::vector<double> p;
181  p.push_back(func->GetParameter(0));
182  p.push_back(func->GetParameter(1));
183  p.push_back(func->GetParameter(2));
184  p.push_back(func->GetParameter(3));
185  double radical = p[2] * p[2] - 3 * p[1] * p[3];
186  if (radical > 0) {
187  double x0 = (-p[2] + sqrt(radical)) / (3 * p[3]);
188  v.push_back(x0);
189  v.push_back(pow(radical, -0.25));
190  v.push_back(p[0] + p[1] * x0 + p[2] * x0 * x0 + p[3] * x0 * x0 * x0);
191  }
192  }
193  return v;
194 }

References TrackCollections2monitor_cff::func, compare::hist, AlCaHLTBitMon_ParallelJobs::p, funct::pow(), mathSSE::sqrt(), mps_update::status, and findQualityFiles::v.

Referenced by fit().

◆ symmetryChi2() [1/2]

TH1 * SymmetryFit::symmetryChi2 ( const TH1 *  candidate,
const std::pair< unsigned, unsigned >  range 
)
static

Definition at line 28 of file SymmetryFit.cc.

28  {
29  SymmetryFit sf(candidate, range);
30  int status = sf.fit();
31  if (status) {
32  delete sf.chi2_;
33  sf.chi2_ = nullptr;
34  }
35  return sf.chi2_;
36 }

References chi2_, fit(), FastTimerService_cff::range, and mps_update::status.

◆ symmetryChi2() [2/2]

TH1 * SymmetryFit::symmetryChi2 ( std::string  basename,
const std::vector< TH1 * > &  candidates,
const std::pair< unsigned, unsigned >  range 
)
static

Definition at line 6 of file SymmetryFit.cc.

8  {
9  TH1* fake = (TH1*)(candidates[0]->Clone(basename.c_str()));
10  fake->Reset();
11  SymmetryFit combined(fake, range);
12  delete fake;
13 
14  for (auto const* candidate : candidates) {
15  SymmetryFit sf(candidate, range);
16  combined += sf;
17  delete sf.chi2_;
18  }
19 
20  int status = combined.fit();
21  if (status) {
22  delete combined.chi2_;
23  combined.chi2_ = nullptr;
24  }
25  return combined.chi2_;
26 }

References HLT_FULL_cff::candidates, chi2_, RunInfoPI::fake, fit(), FastTimerService_cff::range, and mps_update::status.

Referenced by LA_Filler_Fitter::make_and_fit_symmchi2().

Member Data Documentation

◆ chi2_

TH1* SymmetryFit::chi2_
private

Definition at line 36 of file SymmetryFit.h.

Referenced by fillchi2(), fit(), makeChi2Histogram(), operator+=(), and symmetryChi2().

◆ minDF_

const unsigned SymmetryFit::minDF_
private

Definition at line 33 of file SymmetryFit.h.

Referenced by fillchi2().

◆ minmaxUsable_

const std::pair<unsigned, unsigned> SymmetryFit::minmaxUsable_
private

Definition at line 34 of file SymmetryFit.h.

Referenced by chi2().

◆ ndf_

unsigned SymmetryFit::ndf_
private

Definition at line 35 of file SymmetryFit.h.

Referenced by chi2(), fillchi2(), fit(), and operator+=().

◆ range_

const std::pair<unsigned, unsigned> SymmetryFit::range_
private

Definition at line 34 of file SymmetryFit.h.

Referenced by fillchi2(), findUsableMinMax(), and makeChi2Histogram().

◆ symm_candidate_

const TH1* SymmetryFit::symm_candidate_
private

Definition at line 32 of file SymmetryFit.h.

Referenced by chi2_element(), continuousRanges(), and makeChi2Histogram().

SymmetryFit::range_
const std::pair< unsigned, unsigned > range_
Definition: SymmetryFit.h:34
diffTwoXMLs.ranges
string ranges
Definition: diffTwoXMLs.py:79
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
dttmaxenums::L
Definition: DTTMax.h:29
SymmetryFit::makeChi2Histogram
void makeChi2Histogram()
Definition: SymmetryFit.cc:49
mps_fire.i
i
Definition: mps_fire.py:428
SymmetryFit::minmaxUsable_
const std::pair< unsigned, unsigned > minmaxUsable_
Definition: SymmetryFit.h:34
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
mps_update.status
status
Definition: mps_update.py:69
min
T min(T a, T b)
Definition: MathUtil.h:58
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SymmetryFit
Definition: SymmetryFit.h:8
generateEDF.cont
cont
load Luminosity info ##
Definition: generateEDF.py:629
cms::cuda::assert
assert(be >=bs)
SymmetryFit::findUsableMinMax
std::pair< unsigned, unsigned > findUsableMinMax() const
Definition: SymmetryFit.cc:58
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
SymmetryFit::name
static std::string name(std::string base)
Definition: SymmetryFit.h:12
findQualityFiles.v
v
Definition: findQualityFiles.py:179
tools.TF1
TF1
Definition: tools.py:23
dqmdumpme.first
first
Definition: dqmdumpme.py:55
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
SymmetryFit::pol2_from_pol3
static std::vector< double > pol2_from_pol3(TH1 *hist)
Definition: SymmetryFit.cc:174
compare.hist
hist
Definition: compare.py:376
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
SymmetryFit::chi2_
TH1 * chi2_
Definition: SymmetryFit.h:36
h
SymmetryFit::fitfunction
static TF1 * fitfunction()
Definition: SymmetryFit.cc:145
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SymmetryFit::chi2_element
float chi2_element(std::pair< unsigned, unsigned >)
Definition: SymmetryFit.cc:119
SymmetryFit::ndf_
unsigned ndf_
Definition: SymmetryFit.h:35
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
SiStripMonitorCluster_cfi.Nbins
Nbins
Definition: SiStripMonitorCluster_cfi.py:32
SymmetryFit::continuousRanges
std::vector< std::pair< unsigned, unsigned > > continuousRanges() const
Definition: SymmetryFit.cc:81
StorageManager_cfg.e1
e1
Definition: StorageManager_cfg.py:16
SymmetryFit::symm_candidate_
const TH1 * symm_candidate_
Definition: SymmetryFit.h:32
SymmetryFit::chi2
float chi2(std::pair< unsigned, unsigned >)
Definition: SymmetryFit.cc:106
RunInfoPI::fake
Definition: RunInfoPayloadInspectoHelper.h:16
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HLT_FULL_cff.candidates
candidates
Definition: HLT_FULL_cff.py:55048
SymmetryFit::fillchi2
void fillchi2()
Definition: SymmetryFit.cc:96
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
point
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
dttmaxenums::R
Definition: DTTMax.h:29
XX
double XX[2]
Definition: herwig.h:145
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
SymmetryFit::minDF_
const unsigned minDF_
Definition: SymmetryFit.h:33
up
Definition: BitonicSort.h:7