CMS 3D CMS Logo

LA_Results.cc
Go to the documentation of this file.
3 
4 #include <cmath>
5 #include <regex>
6 #include <boost/lexical_cast.hpp>
7 #include <boost/algorithm/string/erase.hpp>
8 #include <TF1.h>
9 #include <TGraphErrors.h>
10 #include <TProfile.h>
11 
13  Result p;
14  const std::string base = boost::erase_all_copy(name, method(m));
15 
16  const TH1* const h = book[name];
17  const TH1* const reco = book[base + "_reconstruction"];
18  const TH1* const field = book[base + "_field"];
19 
20  if (reco)
21  p.reco = std::make_pair<float, float>(reco->GetMean(), reco->GetMeanError());
22  if (field)
23  p.field = field->GetMean();
24  if (h) {
25  switch (m) {
26  case WIDTH: {
27  const TF1* const f = h->GetFunction("LA_profile_fit");
28  if (!f)
29  break;
30  p.measured = std::make_pair<float, float>(f->GetParameter(0), f->GetParError(0));
31  p.chi2 = f->GetChisquare();
32  p.ndof = f->GetNDF();
33  p.entries = (unsigned)(h->GetEntries());
34  break;
35  }
36  case PROB1:
37  case AVGV2:
38  case AVGV3:
39  case RMSV2:
40  case RMSV3: /*case MULTI:*/ {
41  const TF1* const f = h->GetFunction("SymmetryFit");
42  if (!f)
43  break;
44  p.measured = std::make_pair<float, float>(p.reco.first + f->GetParameter(0), f->GetParameter(1));
45  p.chi2 = f->GetParameter(2);
46  p.ndof = (unsigned)(f->GetParameter(3));
47  p.entries = (m & PROB1) ? (unsigned)book[base + "_w1"]->GetEntries()
48  : (m & (AVGV2 | RMSV2)) ? (unsigned)book[base + method(AVGV2, false)]->GetEntries()
49  : (m & (AVGV3 | RMSV3)) ? (unsigned)book[base + method(AVGV3, false)]->GetEntries()
50  : 0;
51  break;
52  }
53  default:
54  break;
55  }
56  }
57  return p;
58 }
59 
60 std::map<uint32_t, LA_Filler_Fitter::Result> LA_Filler_Fitter::module_results(const Book& book, const Method m) {
61  std::map<uint32_t, Result> results;
62  for (Book::const_iterator it = book.begin(".*_module\\d*" + method(m)); it != book.end(); ++it) {
63  const uint32_t detid = boost::lexical_cast<uint32_t>(
64  std::regex_replace(it->first, std::regex(".*_module(\\d*)_.*"), std::string("\\1")));
65  results[detid] = result(m, it->first, book);
66  }
67  return results;
68 }
69 
70 std::map<std::string, LA_Filler_Fitter::Result> LA_Filler_Fitter::layer_results(const Book& book, const Method m) {
71  std::map<std::string, Result> results;
72  for (Book::const_iterator it = book.begin(".*layer\\d.*" + method(m)); it != book.end(); ++it) {
73  const std::string name = boost::erase_all_copy(it->first, method(m));
74  results[name] = result(m, it->first, book);
75  }
76  return results;
77 }
78 
79 std::map<std::string, std::vector<LA_Filler_Fitter::Result> > LA_Filler_Fitter::ensemble_results(const Book& book,
80  const Method m) {
81  std::map<std::string, std::vector<Result> > results;
82  for (Book::const_iterator it = book.begin(".*_sample.*" + method(m)); it != book.end(); ++it) {
83  const std::string name = std::regex_replace(it->first, std::regex("sample\\d*_"), "");
84  results[name].push_back(result(m, it->first, book));
85  }
86  return results;
87 }
88 
90  typedef std::map<std::string, std::vector<Result> > results_t;
91  results_t results;
92  for (int m = FIRST_METHOD; m <= LAST_METHOD; m <<= 1)
93  if (methods_ & m) {
94  results_t g = ensemble_results(book, (Method)(m));
95  results.insert(g.begin(), g.end());
96  }
97 
98  for (auto const& group : results) {
99  const std::string name = group.first;
100  for (auto const& p : group.second) {
101  const float pad = (ensembleUp_ - ensembleLow_) / 10;
102  book.fill(p.reco.first, name + "_ensembleReco", 12 * ensembleBins_, ensembleLow_ - pad, ensembleUp_ + pad);
103  book.fill(p.measured.first, name + "_measure", 12 * ensembleBins_, ensembleLow_ - pad, ensembleUp_ + pad);
104  book.fill(p.measured.second, name + "_merr", 500, 0, 0.01);
105  book.fill((p.measured.first - p.reco.first) / p.measured.second, name + "_pull", 500, -10, 10);
106  }
107  //Need our own copy for thread safety
108  TF1 gaus("mygaus", "gaus");
109  book[name + "_measure"]->Fit(&gaus, "LLQ");
110  book[name + "_merr"]->Fit(&gaus, "LLQ");
111  book[name + "_pull"]->Fit(&gaus, "LLQ");
112  }
113 }
114 
115 std::map<std::string, std::vector<LA_Filler_Fitter::EnsembleSummary> > LA_Filler_Fitter::ensemble_summary(
116  const Book& book) {
117  std::map<std::string, std::vector<EnsembleSummary> > summary;
118  for (Book::const_iterator it = book.begin(".*_ensembleReco"); it != book.end(); ++it) {
119  const std::string base = boost::erase_all_copy(it->first, "_ensembleReco");
120 
121  const TH1* const reco = it->second;
122  const TH1* const measure = book[base + "_measure"];
123  const TH1* const merr = book[base + "_merr"];
124  const TH1* const pull = book[base + "_pull"];
125 
127  s.samples = reco->GetEntries();
128  s.truth = reco->GetMean();
129  s.meanMeasured = std::make_pair<float, float>(measure->GetFunction("gaus")->GetParameter(1),
130  measure->GetFunction("gaus")->GetParError(1));
131  s.sigmaMeasured = std::make_pair<float, float>(measure->GetFunction("gaus")->GetParameter(2),
132  measure->GetFunction("gaus")->GetParError(2));
133  s.meanUncertainty = std::make_pair<float, float>(merr->GetFunction("gaus")->GetParameter(1),
134  merr->GetFunction("gaus")->GetParError(1));
135  s.pull = std::make_pair<float, float>(pull->GetFunction("gaus")->GetParameter(2),
136  pull->GetFunction("gaus")->GetParError(2));
137 
138  const std::string name = std::regex_replace(base, std::regex("ensembleBin\\d*_"), "");
139  summary[name].push_back(s);
140  }
141  return summary;
142 }
143 
144 std::pair<std::pair<float, float>, std::pair<float, float> > LA_Filler_Fitter::offset_slope(
145  const std::vector<LA_Filler_Fitter::EnsembleSummary>& ensembles) {
146  try {
147  std::vector<float> x, y, xerr, yerr;
148  for (auto const& ensemble : ensembles) {
149  x.push_back(ensemble.truth);
150  xerr.push_back(0);
151  y.push_back(ensemble.meanMeasured.first);
152  yerr.push_back(ensemble.meanMeasured.second);
153  }
154  TGraphErrors graph(x.size(), &(x[0]), &(y[0]), &(xerr[0]), &(yerr[0]));
155  //Need our own copy for thread safety
156  TF1 pol1("mypol1", "pol1");
157  graph.Fit(&pol1);
158  const TF1* const fit = graph.GetFunction("pol1");
159 
160  return std::make_pair(std::make_pair(fit->GetParameter(0), fit->GetParError(0)),
161  std::make_pair(fit->GetParameter(1), fit->GetParError(1)));
162  } catch (edm::Exception const& e) {
163  std::cerr << "Fitting Line Failed " << std::endl << e << std::endl;
164  return std::make_pair(std::make_pair(0, 0), std::make_pair(0, 0));
165  }
166 }
167 
168 float LA_Filler_Fitter::pull(const std::vector<LA_Filler_Fitter::EnsembleSummary>& ensembles) {
169  float p(0), w(0);
170  for (auto const& ensemble : ensembles) {
171  const float unc2 = pow(ensemble.pull.second, 2);
172  p += ensemble.pull.first / unc2;
173  w += 1 / unc2;
174  }
175  return p / w;
176 }
177 
178 std::ostream& operator<<(std::ostream& strm, const LA_Filler_Fitter::Result& r) {
179  return strm << r.reco.first << "\t" << r.reco.second << "\t" << r.measured.first << "\t" << r.measured.second << "\t"
180  << r.calMeasured.first << "\t" << r.calMeasured.second << "\t" << r.field << "\t" << r.chi2 << "\t"
181  << r.ndof << "\t" << r.entries;
182 }
183 
184 std::ostream& operator<<(std::ostream& strm, const LA_Filler_Fitter::EnsembleSummary& e) {
185  return strm << e.truth << "\t" << e.meanMeasured.first << "\t" << e.meanMeasured.second << "\t"
186  << e.sigmaMeasured.first << "\t" << e.sigmaMeasured.second << "\t" << e.meanUncertainty.first << "\t"
187  << e.meanUncertainty.second << "\t" << e.pull.first << "\t" << e.pull.second << "\t" << e.samples;
188 }
LA_Filler_Fitter::Method
Method
Definition: LA_Filler_Fitter.h:50
DDAxes::y
LA_Filler_Fitter::offset_slope
static std::pair< std::pair< float, float >, std::pair< float, float > > offset_slope(const std::vector< EnsembleSummary > &)
Definition: LA_Results.cc:144
LA_Filler_Fitter::PROB1
Definition: LA_Filler_Fitter.h:53
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
LA_Filler_Fitter::Result
Definition: LA_Filler_Fitter.h:80
LA_Filler_Fitter::methods_
const int methods_
Definition: LA_Filler_Fitter.h:137
LA_Filler_Fitter.h
Book::const_iterator
boost::filter_iterator< match_name, book_t::const_iterator > const_iterator
Definition: Book.h:56
bookConverter.results
results
Definition: bookConverter.py:144
DDAxes::x
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
Book
Definition: Book.h:16
edm::Exception
Definition: EDMException.h:77
LA_Filler_Fitter::AVGV2
Definition: LA_Filler_Fitter.h:54
EDMException.h
operator<<
std::ostream & operator<<(std::ostream &strm, const LA_Filler_Fitter::Result &r)
Definition: LA_Results.cc:178
alignCSCRings.s
s
Definition: alignCSCRings.py:92
LA_Filler_Fitter::RMSV3
Definition: LA_Filler_Fitter.h:57
LA_Filler_Fitter::summarize_ensembles
void summarize_ensembles(Book &) const
Definition: LA_Results.cc:89
w
const double w
Definition: UKUtility.cc:23
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:78
LA_Filler_Fitter::method
static std::string method(Method m, bool fit=true)
Definition: LA_Filler_Fitter.h:61
Book::end
iterator end(string_t re=".*")
Definition: Book.h:65
LA_Filler_Fitter::ensembleBins_
const int ensembleBins_
Definition: LA_Filler_Fitter.h:131
LA_Filler_Fitter::WIDTH
Definition: LA_Filler_Fitter.h:51
LA_Filler_Fitter::ensemble_results
static std::map< std::string, std::vector< Result > > ensemble_results(const Book &, const Method)
Definition: LA_Results.cc:79
h
LA_Filler_Fitter::LAST_METHOD
Definition: LA_Filler_Fitter.h:58
LA_Filler_Fitter::ensembleUp_
const double ensembleUp_
Definition: LA_Filler_Fitter.h:132
Book::fill
void fill(double_t X, const char *name, uint_t NbinsX, double_t Xlow, double_t Xup, double_t W=1)
Definition: Book.h:96
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
LA_Filler_Fitter::layer_results
static std::map< std::string, Result > layer_results(const Book &, const Method)
Definition: LA_Results.cc:70
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
LA_Filler_Fitter::pull
static float pull(const std::vector< EnsembleSummary > &)
Definition: LA_Results.cc:168
LA_Filler_Fitter::AVGV3
Definition: LA_Filler_Fitter.h:55
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
alignCSCRings.r
r
Definition: alignCSCRings.py:93
LA_Filler_Fitter::EnsembleSummary
Definition: LA_Filler_Fitter.h:87
LA_Filler_Fitter::ensembleLow_
const double ensembleLow_
Definition: LA_Filler_Fitter.h:132
Book::begin
iterator begin(string_t re=".*")
Definition: Book.h:57
LA_Filler_Fitter::ensemble_summary
static std::map< std::string, std::vector< EnsembleSummary > > ensemble_summary(const Book &)
Definition: LA_Results.cc:115
LA_Filler_Fitter::result
static Result result(Method, const std::string name, const Book &)
Definition: LA_Results.cc:12
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
LA_Filler_Fitter::RMSV2
Definition: LA_Filler_Fitter.h:56
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
LA_Filler_Fitter::module_results
static std::map< uint32_t, Result > module_results(const Book &, const Method)
Definition: LA_Results.cc:60
LA_Filler_Fitter::FIRST_METHOD
Definition: LA_Filler_Fitter.h:52
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
fit
Definition: CombinedChiSquaredLikelihood.h:6
g
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
watchdog.group
group
Definition: watchdog.py:82