CMS 3D CMS Logo

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