CMS 3D CMS Logo

EnsembleCalibrationLA.cc
Go to the documentation of this file.
6 #include <TChain.h>
7 #include <TFile.h>
8 #include <boost/lexical_cast.hpp>
9 #include <fstream>
10 
11 namespace sistrip {
12 
14  : inputFiles(conf.getParameter<std::vector<std::string> >("InputFiles")),
15  inFileLocation(conf.getParameter<std::string>("InFileLocation")),
16  Prefix(conf.getUntrackedParameter<std::string>("Prefix", "")),
17  maxEvents(conf.getUntrackedParameter<unsigned>("MaxEvents", 0)),
18  samples(conf.getParameter<unsigned>("Samples")),
19  nbins(conf.getParameter<unsigned>("NBins")),
20  lowBin(conf.getParameter<double>("LowBin")),
21  highBin(conf.getParameter<double>("HighBin")),
22  vMethods(conf.getParameter<std::vector<int> >("Methods")) {}
23 
25  Book book("la_ensemble");
26  TChain* const chain = new TChain("la_ensemble");
27  for (auto const& file : inputFiles)
28  chain->Add((file + inFileLocation).c_str());
29 
30  int methods = 0;
31  for (unsigned int method : vMethods)
32  methods |= method;
33 
35  laff.fill(chain, book);
36  laff.fit(book);
37  laff.summarize_ensembles(book);
38 
41  write_samples_plots(book);
43  }
44 
47  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
48  tTopo_ = tTopoHandle.product();
49  }
50 
52  for (auto const& ensemble : LA_Filler_Fitter::ensemble_summary(book)) {
53  std::fstream file((Prefix + ensemble.first + ".dat").c_str(), std::ios::out);
54  for (auto const& summary : ensemble.second)
55  file << summary << std::endl;
56 
57  const std::pair<std::pair<float, float>, std::pair<float, float> > line =
58  LA_Filler_Fitter::offset_slope(ensemble.second);
59  const float pull = LA_Filler_Fitter::pull(ensemble.second);
60 
61  unsigned index = 15;
63  {
64  std::cout << ensemble.first << std::endl;
65  boost::regex format(".*(T[IO]B)_layer(\\d)([as])_(.*)");
66  if (boost::regex_match(ensemble.first, format)) {
67  const bool TIB = "TIB" == boost::regex_replace(ensemble.first, format, "\\1");
68  const bool stereo = "s" == boost::regex_replace(ensemble.first, format, "\\3");
69  const unsigned layer = boost::lexical_cast<unsigned>(boost::regex_replace(ensemble.first, format, "\\2"));
70  label = boost::regex_replace(ensemble.first, format, "\\4");
71  index = LA_Filler_Fitter::layer_index(TIB, stereo, layer);
72 
73  calibrations[label].slopes[index] = line.second.first;
74  calibrations[label].offsets[index] = line.first.first;
75  calibrations[label].pulls[index] = pull;
76  }
77  }
78 
79  file << std::endl
80  << std::endl
81  << "# Best Fit Line: " << line.first.first << "(" << line.first.second << ") + x* " << line.second.first
82  << "(" << line.second.second << ")" << std::endl
83  << "# Pull (average sigma of (x_measure-x_truth)/e_measure): " << pull << std::endl
84  << "LA_Calibration( METHOD_XXXXX , xxx, " << line.second.first << ", " << line.first.first << ", " << pull
85  << ")," << std::endl;
86  file.close();
87  }
88  }
89 
91  TFile file((Prefix + "sampleFits.root").c_str(), "RECREATE");
92  for (Book::const_iterator hist = book.begin(".*(profile|ratio|reconstruction|symm|symmchi2|_w\\d)");
93  hist != book.end();
94  ++hist)
95  hist->second->Write();
96  file.Close();
97  }
98 
100  TFile file((Prefix + "ensembleFits.root").c_str(), "RECREATE");
101  for (Book::const_iterator hist = book.begin(".*(measure|merr|ensembleReco|pull)"); hist != book.end(); ++hist)
102  hist->second->Write();
103  file.Close();
104  }
105 
107  std::fstream file((Prefix + "calibrations.dat").c_str(), std::ios::out);
108  for (auto const& cal : calibrations) {
109  file << cal.first << std::endl << "\t slopes(";
110  for (float i : cal.second.slopes)
111  file << i << ",";
112  file << ")" << std::endl << "\t offsets(";
113  for (float i : cal.second.offsets)
114  file << i << ",";
115  file << ")" << std::endl << "\t pulls(";
116  for (float i : cal.second.pulls)
117  file << i << ",";
118  file << ")" << std::endl;
119  }
120  file.close();
121  }
122 
123 } // namespace sistrip
std::map< std::string, MethodCalibrations > calibrations
static unsigned layer_index(bool TIB, bool stereo, unsigned layer)
static void fit(Book &book)
Definition: chain.py:1
void write_ensembles_plots(const Book &) const
static std::pair< std::pair< float, float >, std::pair< float, float > > offset_slope(const std::vector< EnsembleSummary > &)
Definition: LA_Results.cc:145
static std::map< std::string, std::vector< EnsembleSummary > > ensemble_summary(const Book &)
Definition: LA_Results.cc:116
void fill(TTree *, Book &) const
Definition: LA_Filler.cc:8
sistrip classes
void summarize_ensembles(Book &) const
Definition: LA_Results.cc:90
char const * label
const std::vector< std::string > inputFiles
iterator begin(string_t re=".*")
Definition: Book.h:57
void write_samples_plots(const Book &) const
EnsembleCalibrationLA(const edm::ParameterSet &)
boost::filter_iterator< match_name, book_t::const_iterator > const_iterator
Definition: Book.h:56
static float pull(const std::vector< EnsembleSummary > &)
Definition: LA_Results.cc:169
T get() const
Definition: EventSetup.h:73
Definition: Book.h:16
T const * product() const
Definition: ESHandle.h:86
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:45
iterator end(string_t re=".*")
Definition: Book.h:65