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)
48  ? (unsigned)book[base + "_w1"]->GetEntries()
49  : (m & (AVGV2 | RMSV2))
50  ? (unsigned)book[base + method(AVGV2, false)]->GetEntries()
51  : (m & (AVGV3 | RMSV3)) ? (unsigned)book[base + method(AVGV3, false)]->GetEntries() : 0;
52  break;
53  }
54  default:
55  break;
56  }
57  }
58  return p;
59 }
60 
61 std::map<uint32_t, LA_Filler_Fitter::Result> LA_Filler_Fitter::module_results(const Book& book, const Method m) {
62  std::map<uint32_t, Result> results;
63  for (Book::const_iterator it = book.begin(".*_module\\d*" + method(m)); it != book.end(); ++it) {
64  const uint32_t detid = boost::lexical_cast<uint32_t>(
65  std::regex_replace(it->first, std::regex(".*_module(\\d*)_.*"), std::string("\\1")));
66  results[detid] = result(m, it->first, book);
67  }
68  return results;
69 }
70 
71 std::map<std::string, LA_Filler_Fitter::Result> LA_Filler_Fitter::layer_results(const Book& book, const Method m) {
72  std::map<std::string, Result> results;
73  for (Book::const_iterator it = book.begin(".*layer\\d.*" + method(m)); it != book.end(); ++it) {
74  const std::string name = boost::erase_all_copy(it->first, method(m));
75  results[name] = result(m, it->first, book);
76  }
77  return results;
78 }
79 
80 std::map<std::string, std::vector<LA_Filler_Fitter::Result> > LA_Filler_Fitter::ensemble_results(const Book& book,
81  const Method m) {
82  std::map<std::string, std::vector<Result> > results;
83  for (Book::const_iterator it = book.begin(".*_sample.*" + method(m)); it != book.end(); ++it) {
84  const std::string name = std::regex_replace(it->first, std::regex("sample\\d*_"), "");
85  results[name].push_back(result(m, it->first, book));
86  }
87  return results;
88 }
89 
91  typedef std::map<std::string, std::vector<Result> > results_t;
92  results_t results;
93  for (int m = FIRST_METHOD; m <= LAST_METHOD; m <<= 1)
94  if (methods_ & m) {
95  results_t g = ensemble_results(book, (Method)(m));
96  results.insert(g.begin(), g.end());
97  }
98 
99  for (auto const& group : results) {
100  const std::string name = group.first;
101  for (auto const& p : group.second) {
102  const float pad = (ensembleUp_ - ensembleLow_) / 10;
103  book.fill(p.reco.first, name + "_ensembleReco", 12 * ensembleBins_, ensembleLow_ - pad, ensembleUp_ + pad);
104  book.fill(p.measured.first, name + "_measure", 12 * ensembleBins_, ensembleLow_ - pad, ensembleUp_ + pad);
105  book.fill(p.measured.second, name + "_merr", 500, 0, 0.01);
106  book.fill((p.measured.first - p.reco.first) / p.measured.second, name + "_pull", 500, -10, 10);
107  }
108  //Need our own copy for thread safety
109  TF1 gaus("mygaus", "gaus");
110  book[name + "_measure"]->Fit(&gaus, "LLQ");
111  book[name + "_merr"]->Fit(&gaus, "LLQ");
112  book[name + "_pull"]->Fit(&gaus, "LLQ");
113  }
114 }
115 
116 std::map<std::string, std::vector<LA_Filler_Fitter::EnsembleSummary> > LA_Filler_Fitter::ensemble_summary(
117  const Book& book) {
118  std::map<std::string, std::vector<EnsembleSummary> > summary;
119  for (Book::const_iterator it = book.begin(".*_ensembleReco"); it != book.end(); ++it) {
120  const std::string base = boost::erase_all_copy(it->first, "_ensembleReco");
121 
122  const TH1* const reco = it->second;
123  const TH1* const measure = book[base + "_measure"];
124  const TH1* const merr = book[base + "_merr"];
125  const TH1* const pull = book[base + "_pull"];
126 
128  s.samples = reco->GetEntries();
129  s.truth = reco->GetMean();
130  s.meanMeasured = std::make_pair<float, float>(measure->GetFunction("gaus")->GetParameter(1),
131  measure->GetFunction("gaus")->GetParError(1));
132  s.sigmaMeasured = std::make_pair<float, float>(measure->GetFunction("gaus")->GetParameter(2),
133  measure->GetFunction("gaus")->GetParError(2));
134  s.meanUncertainty = std::make_pair<float, float>(merr->GetFunction("gaus")->GetParameter(1),
135  merr->GetFunction("gaus")->GetParError(1));
136  s.pull = std::make_pair<float, float>(pull->GetFunction("gaus")->GetParameter(2),
137  pull->GetFunction("gaus")->GetParError(2));
138 
139  const std::string name = std::regex_replace(base, std::regex("ensembleBin\\d*_"), "");
140  summary[name].push_back(s);
141  }
142  return summary;
143 }
144 
145 std::pair<std::pair<float, float>, std::pair<float, float> > LA_Filler_Fitter::offset_slope(
146  const std::vector<LA_Filler_Fitter::EnsembleSummary>& ensembles) {
147  try {
148  std::vector<float> x, y, xerr, yerr;
149  for (auto const& ensemble : ensembles) {
150  x.push_back(ensemble.truth);
151  xerr.push_back(0);
152  y.push_back(ensemble.meanMeasured.first);
153  yerr.push_back(ensemble.meanMeasured.second);
154  }
155  TGraphErrors graph(x.size(), &(x[0]), &(y[0]), &(xerr[0]), &(yerr[0]));
156  //Need our own copy for thread safety
157  TF1 pol1("mypol1", "pol1");
158  graph.Fit(&pol1);
159  const TF1* const fit = graph.GetFunction("pol1");
160 
161  return std::make_pair(std::make_pair(fit->GetParameter(0), fit->GetParError(0)),
162  std::make_pair(fit->GetParameter(1), fit->GetParError(1)));
163  } catch (edm::Exception const& e) {
164  std::cerr << "Fitting Line Failed " << std::endl << e << std::endl;
165  return std::make_pair(std::make_pair(0, 0), std::make_pair(0, 0));
166  }
167 }
168 
169 float LA_Filler_Fitter::pull(const std::vector<LA_Filler_Fitter::EnsembleSummary>& ensembles) {
170  float p(0), w(0);
171  for (auto const& ensemble : ensembles) {
172  const float unc2 = pow(ensemble.pull.second, 2);
173  p += ensemble.pull.first / unc2;
174  w += 1 / unc2;
175  }
176  return p / w;
177 }
178 
179 std::ostream& operator<<(std::ostream& strm, const LA_Filler_Fitter::Result& r) {
180  return strm << r.reco.first << "\t" << r.reco.second << "\t" << r.measured.first << "\t" << r.measured.second << "\t"
181  << r.calMeasured.first << "\t" << r.calMeasured.second << "\t" << r.field << "\t" << r.chi2 << "\t"
182  << r.ndof << "\t" << r.entries;
183 }
184 
185 std::ostream& operator<<(std::ostream& strm, const LA_Filler_Fitter::EnsembleSummary& e) {
186  return strm << e.truth << "\t" << e.meanMeasured.first << "\t" << e.meanMeasured.second << "\t"
187  << e.sigmaMeasured.first << "\t" << e.sigmaMeasured.second << "\t" << e.meanUncertainty.first << "\t"
188  << e.meanUncertainty.second << "\t" << e.pull.first << "\t" << e.pull.second << "\t" << e.samples;
189 }
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:145
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
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:45
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:179
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:90
w
const double w
Definition: UKUtility.cc:23
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
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:80
h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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
LA_Filler_Fitter::layer_results
static std::map< std::string, Result > layer_results(const Book &, const Method)
Definition: LA_Results.cc:71
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
LA_Filler_Fitter::pull
static float pull(const std::vector< EnsembleSummary > &)
Definition: LA_Results.cc:169
LA_Filler_Fitter::AVGV3
Definition: LA_Filler_Fitter.h:55
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:116
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:61
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