CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 (std::string, const std::vector< TH1 * > &, const std::pair< unsigned, unsigned >)
 
static TH1 * symmetryChi2 (const 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 ( const TH1 *  h,
const std::pair< unsigned, unsigned >  r 
)
private

Definition at line 33 of file SymmetryFit.cc.

References fillchi2(), and makeChi2Histogram().

34  : symm_candidate_(h),
35  minDF_(r.second-r.first),
36  range_(r),
38  ndf_( minmaxUsable_.first<minmaxUsable_.second ? minmaxUsable_.second-minmaxUsable_.first : 0),
39  chi2_(0)
40 {
42  fillchi2();
43 }
const std::pair< unsigned, unsigned > minmaxUsable_
Definition: SymmetryFit.h:33
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::pair< unsigned, unsigned > findUsableMinMax() const
Definition: SymmetryFit.cc:55
const std::pair< unsigned, unsigned > range_
Definition: SymmetryFit.h:33
TH1 * chi2_
Definition: SymmetryFit.h:35
unsigned ndf_
Definition: SymmetryFit.h:34
const TH1 * symm_candidate_
Definition: SymmetryFit.h:31
void fillchi2()
Definition: SymmetryFit.cc:89
const unsigned minDF_
Definition: SymmetryFit.h:32
void makeChi2Histogram()
Definition: SymmetryFit.cc:45

Member Function Documentation

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

Definition at line 99 of file SymmetryFit.cc.

References chi2_element(), i, minmaxUsable_, ndf_, and XX.

Referenced by fillchi2().

100 {
101  point.first -= minmaxUsable_.first;
102  point.second += minmaxUsable_.first;
103  float XX=0;
104  unsigned i=ndf_;
105  while(i-->0) {
106  XX += chi2_element(point);
107  point.first--;
108  point.second++;
109  }
110  return XX;
111 }
int i
Definition: DBlmapReader.cc:9
const std::pair< unsigned, unsigned > minmaxUsable_
Definition: SymmetryFit.h:33
double XX[2]
Definition: herwig.h:152
float chi2_element(std::pair< unsigned, unsigned >)
Definition: SymmetryFit.cc:113
unsigned ndf_
Definition: SymmetryFit.h:34
*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
float SymmetryFit::chi2_element ( std::pair< unsigned, unsigned >  range)
private

Definition at line 113 of file SymmetryFit.cc.

References assert(), reco::e1, funct::pow(), and symm_candidate_.

Referenced by chi2().

114 {
115  float
116  y0(symm_candidate_->GetBinContent(range.first)),
117  y1(symm_candidate_->GetBinContent(range.second)),
118  e0(symm_candidate_->GetBinError(range.first)),
119  e1(symm_candidate_->GetBinError(range.second)); assert(e0&&e1);
120 
121  return pow(y0-y1, 2)/(e0*e0+e1*e1);
122 }
assert(m_qm.get())
Float e1
Definition: deltaR.h:20
const TH1 * symm_candidate_
Definition: SymmetryFit.h:31
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::vector< std::pair< unsigned, unsigned > > SymmetryFit::continuousRanges ( ) const
private

Definition at line 73 of file SymmetryFit.cc.

References i, SiStripMonitorClusterAlca_cfi::Nbins, diffTwoXMLs::ranges, and symm_candidate_.

Referenced by findUsableMinMax().

74 {
75  std::vector<std::pair<unsigned,unsigned> > ranges;
76  const unsigned Nbins = symm_candidate_->GetNbinsX();
77  unsigned i=0;
78  while(++i<=Nbins) {
79  if(symm_candidate_->GetBinError(i)) {
80  std::pair<unsigned,unsigned> range(i,i+1);
81  while(++i<=Nbins && symm_candidate_->GetBinError(i)) range.second++;
82  ranges.push_back(range);
83  }
84  }
85  return ranges;
86 }
int i
Definition: DBlmapReader.cc:9
string ranges
Definition: diffTwoXMLs.py:78
const TH1 * symm_candidate_
Definition: SymmetryFit.h:31
void SymmetryFit::fillchi2 ( )
private

Definition at line 89 of file SymmetryFit.cc.

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

Referenced by SymmetryFit().

90 {
91  if(ndf_<minDF_) return;
92 
93  for(int i=1; i<=chi2_->GetNbinsX() ; ++i) {
94  const unsigned L( range_.first-1+(i-1)/2 ), R( range_.first+i/2 );
95  chi2_->SetBinContent( i, chi2( std::make_pair(L,R)) );
96  }
97 }
int i
Definition: DBlmapReader.cc:9
const std::pair< unsigned, unsigned > range_
Definition: SymmetryFit.h:33
TH1 * chi2_
Definition: SymmetryFit.h:35
unsigned ndf_
Definition: SymmetryFit.h:34
float chi2(std::pair< unsigned, unsigned >)
Definition: SymmetryFit.cc:99
const unsigned minDF_
Definition: SymmetryFit.h:32
std::pair< unsigned, unsigned > SymmetryFit::findUsableMinMax ( ) const
private

Definition at line 55 of file SymmetryFit.cc.

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

56 {
57  unsigned NEAR(0), FAR(0);
58  const std::vector<std::pair<unsigned,unsigned> > cont = continuousRanges();
59  for(unsigned L=0; L<cont.size(); L++) { if( cont[L].first > range_.first) continue;
60  for(unsigned R=L; R<cont.size(); R++) { if( cont[R].second < range_.second) continue;
61 
62  const unsigned far = std::min( range_.first - cont[L].first,
63  cont[R].second - range_.second );
64  const unsigned near = std::max( range_.second<cont[L].second ? 0 : range_.second - cont[L].second,
65  cont[R].first<range_.first ? 0 : cont[R].first - range_.first );
66 
67  if ( (far>near) && (far-near)>(FAR-NEAR) ) { FAR = far; NEAR = near;}
68  }
69  }
70  return std::make_pair(NEAR,FAR);
71 }
tuple cont
load Luminosity info ##
Definition: generateEDF.py:622
const std::pair< unsigned, unsigned > range_
Definition: SymmetryFit.h:33
U second(std::pair< T, U > const &p)
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< std::pair< unsigned, unsigned > > continuousRanges() const
Definition: SymmetryFit.cc:73
int SymmetryFit::fit ( )
private

Definition at line 124 of file SymmetryFit.cc.

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

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

124  {
125 
126  std::vector<double> p = pol2_from_pol3(chi2_);
127  if( !p.size() ||
128  p[0] < chi2_->GetBinCenter(1) ||
129  p[0] > chi2_->GetBinCenter(chi2_->GetNbinsX()))
130  return 7;
131 
132  std::unique_ptr<TF1> f( fitfunction() );
133  f->SetParameter(0, p[0]); f->SetParLimits(0, p[0], p[0]);
134  f->SetParameter(1, p[1]); f->SetParLimits(1, p[1], p[1]);
135  f->SetParameter(2, p[2]); f->SetParLimits(2, p[2], p[2]);
136  f->SetParameter(3, ndf_); f->SetParLimits(3, ndf_,ndf_); //Fixed
137  chi2_->Fit(f.get(),"WQ");
138  return 0;
139 }
TH1 * chi2_
Definition: SymmetryFit.h:35
unsigned ndf_
Definition: SymmetryFit.h:34
static std::vector< double > pol2_from_pol3(TH1 *hist)
Definition: SymmetryFit.cc:172
static TF1 * fitfunction()
Definition: SymmetryFit.cc:141
double f[11][100]
TF1 * SymmetryFit::fitfunction ( )
static

Definition at line 141 of file SymmetryFit.cc.

References f.

Referenced by fit().

142 {
143  TF1* f = new TF1("SymmetryFit","((x-[0])/[1])**2+[2]+0*[3]");
144  f->SetParName(0,"middle");
145  f->SetParName(1,"uncertainty");
146  f->SetParName(2,"chi2");
147  f->SetParName(3,"NDF");
148  return f;
149 }
double f[11][100]
void SymmetryFit::makeChi2Histogram ( )
private

Definition at line 45 of file SymmetryFit.cc.

References chi2_, name(), SiStripMonitorClusterAlca_cfi::Nbins, range_, AlCaHLTBitMon_QueryRunRegistry::string, symm_candidate_, and up.

Referenced by SymmetryFit().

46 {
47  std::string XXname = name(symm_candidate_->GetName());
48  unsigned Nbins = 2*( range_.second - range_.first ) + 1;
49  double binwidth = symm_candidate_->GetBinWidth(1);
50  double low = symm_candidate_->GetBinCenter(range_.first) - 3*binwidth/4;
51  double up = symm_candidate_->GetBinCenter(range_.second-1) + 3*binwidth/4;
52  chi2_ = new TH1F(XXname.c_str(),"", Nbins, low, up);
53 }
Definition: BitonicSort.h:8
static std::string name(std::string base)
Definition: SymmetryFit.h:14
const std::pair< unsigned, unsigned > range_
Definition: SymmetryFit.h:33
TH1 * chi2_
Definition: SymmetryFit.h:35
const TH1 * symm_candidate_
Definition: SymmetryFit.h:31
static std::string SymmetryFit::name ( std::string  base)
inlinestatic
SymmetryFit SymmetryFit::operator+= ( const SymmetryFit R)
inlineprivate

Definition at line 29 of file SymmetryFit.h.

References chi2_, and ndf_.

29 { ndf_+=R.ndf_; chi2_->Add(R.chi2_); return *this;}
TH1 * chi2_
Definition: SymmetryFit.h:35
unsigned ndf_
Definition: SymmetryFit.h:34
std::vector< double > SymmetryFit::pol2_from_pol2 ( TH1 *  hist)
static

Definition at line 152 of file SymmetryFit.cc.

References RecoJets_EventContent_cff::func, AlCaHLTBitMon_ParallelJobs::p, mathSSE::sqrt(), mps_update::status, and findQualityFiles::v.

152  {
153  std::vector<double> v;
154 
155  //Need our own copy for thread safety
156  TF1 func("mypol2","pol2");
157  int status = hist->Fit(&func,"WQ");
158  if(!status) {
159  std::vector<double> p;
160  p.push_back(func.GetParameter(0));
161  p.push_back(func.GetParameter(1));
162  p.push_back(func.GetParameter(2));
163  if(p[2]>0) {
164  v.push_back( -0.5*p[1]/p[2] );
165  v.push_back( 1./sqrt(p[2]) );
166  v.push_back( p[0]-0.25*p[1]*p[1]/p[2] );
167  }
168  }
169  return v;
170 }
T sqrt(T t)
Definition: SSEVec.h:18
tuple status
Definition: mps_update.py:57
std::vector< double > SymmetryFit::pol2_from_pol3 ( TH1 *  hist)
static

Definition at line 172 of file SymmetryFit.cc.

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

Referenced by fit().

172  {
173  std::vector<double> v;
174 
175  std::unique_ptr<TF1> func( new TF1("mypol3","pol3"));
176  int status = hist->Fit(func.get(),"WQ");
177  if(!status) {
178  std::vector<double> p;
179  p.push_back(func->GetParameter(0));
180  p.push_back(func->GetParameter(1));
181  p.push_back(func->GetParameter(2));
182  p.push_back(func->GetParameter(3));
183  double radical = p[2]*p[2] - 3*p[1]*p[3] ;
184  if(radical>0) {
185  double x0 = ( -p[2] + sqrt(radical) ) / ( 3*p[3] ) ;
186  v.push_back( x0 );
187  v.push_back( pow( radical, -0.25) );
188  v.push_back( p[0] + p[1]*x0 + p[2]*x0*x0 + p[3]*x0*x0*x0 );
189  }
190  }
191  return v;
192 }
T sqrt(T t)
Definition: SSEVec.h:18
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
tuple status
Definition: mps_update.py:57
TH1 * SymmetryFit::symmetryChi2 ( std::string  basename,
const std::vector< TH1 * > &  candidates,
const std::pair< unsigned, unsigned >  range 
)
static

Definition at line 7 of file SymmetryFit.cc.

References chi2_, runregparse::combined, fit(), and mps_update::status.

Referenced by LA_Filler_Fitter::make_and_fit_symmchi2().

8 {
9  TH1* fake = (TH1*)(candidates[0]->Clone(basename.c_str()));
10  fake->Reset();
11  SymmetryFit combined(fake,range);
12  delete fake;
13 
14  BOOST_FOREACH(const TH1* candidate, candidates) {
15  SymmetryFit sf(candidate,range);
16  combined+=sf;
17  delete sf.chi2_;
18  }
19 
20  int status = combined.fit();
21  if(status) { delete combined.chi2_; combined.chi2_=0;}
22  return combined.chi2_;
23 }
tuple status
Definition: mps_update.py:57
TH1 * SymmetryFit::symmetryChi2 ( const TH1 *  candidate,
const std::pair< unsigned, unsigned >  range 
)
static

Definition at line 25 of file SymmetryFit.cc.

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

26 {
27  SymmetryFit sf(candidate, range);
28  int status = sf.fit();
29  if(status) { delete sf.chi2_; sf.chi2_=0; }
30  return sf.chi2_;
31 }
tuple status
Definition: mps_update.py:57

Member Data Documentation

TH1* SymmetryFit::chi2_
private

Definition at line 35 of file SymmetryFit.h.

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

const unsigned SymmetryFit::minDF_
private

Definition at line 32 of file SymmetryFit.h.

Referenced by fillchi2().

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

Definition at line 33 of file SymmetryFit.h.

Referenced by chi2().

unsigned SymmetryFit::ndf_
private

Definition at line 34 of file SymmetryFit.h.

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

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

Definition at line 33 of file SymmetryFit.h.

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

const TH1* SymmetryFit::symm_candidate_
private

Definition at line 31 of file SymmetryFit.h.

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