CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EnsembleCalibrationLA.cc
Go to the documentation of this file.
4 #include <TChain.h>
5 #include <TFile.h>
6 #include <boost/foreach.hpp>
7 #include <boost/lexical_cast.hpp>
8 #include <fstream>
9 
10 namespace sistrip {
11 
13  inputFiles( conf.getParameter<std::vector<std::string> >("InputFiles") ),
14  inFileLocation( conf.getParameter<std::string>("InFileLocation")),
15  Prefix( conf.getUntrackedParameter<std::string>("Prefix","")),
16  maxEvents( conf.getUntrackedParameter<unsigned>("MaxEvents",0)),
17  samples( conf.getParameter<unsigned>("Samples")),
18  nbins( conf.getParameter<unsigned>("NBins")),
19  lowBin( conf.getParameter<double>("LowBin")),
20  highBin( conf.getParameter<double>("HighBin")),
21  vMethods( conf.getParameter<std::vector<int> >("Methods"))
22 {}
23 
26 {
27  Book book("la_ensemble");
28  TChain*const chain = new TChain("la_ensemble");
29  BOOST_FOREACH(std::string file, inputFiles) chain->Add((file+inFileLocation).c_str());
30 
31  int methods = 0; BOOST_FOREACH(unsigned method, vMethods) methods|=method;
32 
34  laff(methods,samples,nbins,lowBin,highBin,maxEvents);
35  laff.fill(chain,book);
36  laff.fit(book);
37  laff.summarize_ensembles(book);
38 
41  write_samples_plots(book);
43 }
44 
46 write_ensembles_text(const Book& book) {
47  std::pair<std::string, std::vector<LA_Filler_Fitter::EnsembleSummary> > ensemble;
48  BOOST_FOREACH(ensemble, LA_Filler_Fitter::ensemble_summary(book)) {
49  std::fstream file((Prefix+ensemble.first+".dat").c_str(),std::ios::out);
50  BOOST_FOREACH(LA_Filler_Fitter::EnsembleSummary summary, ensemble.second)
51  file << summary << std::endl;
52 
53  const std::pair<std::pair<float,float>,std::pair<float,float> > line = LA_Filler_Fitter::offset_slope(ensemble.second);
54  const float pull = LA_Filler_Fitter::pull(ensemble.second);
55 
56  unsigned index = 15;
58  {
59  std::cout << ensemble.first << std::endl;
60  boost::regex format(".*(T[IO]B)_layer(\\d)([as])_(.*)");
61  if(boost::regex_match(ensemble.first,format)) {
62  const bool TIB = "TIB" == boost::regex_replace(ensemble.first, format, "\\1");
63  const bool stereo = "s" == boost::regex_replace(ensemble.first, format, "\\3");
64  const unsigned layer = boost::lexical_cast<unsigned>(boost::regex_replace(ensemble.first, format, "\\2"));
65  label = boost::regex_replace(ensemble.first, format, "\\4");
66  index = LA_Filler_Fitter::layer_index(TIB,stereo,layer);
67 
68  calibrations[label].slopes[index]=line.second.first;
69  calibrations[label].offsets[index]=line.first.first;
70  calibrations[label].pulls[index]=pull;
71  }
72  }
73 
74  file << std::endl << std::endl
75  << "# Best Fit Line: "
76  << line.first.first <<"("<< line.first.second<<") + x* "
77  << line.second.first<<"("<< line.second.second<<")"
78  << std::endl
79  << "# Pull (average sigma of (x_measure-x_truth)/e_measure): " << pull
80  << std::endl
81  << "LA_Calibration( METHOD_XXXXX , xxx, " << line.second.first << ", " << line.first.first << ", " << pull << ")," << std::endl;
82  file.close();
83  }
84 }
85 
87 write_ensembles_plots(const Book& book) const {
88  TFile file((Prefix+"sampleFits.root").c_str(),"RECREATE");
89  for(Book::const_iterator hist = book.begin(".*(profile|ratio|reconstruction|symm|symmchi2|_w\\d)"); hist!=book.end(); ++hist)
90  hist->second->Write();
91  file.Close();
92 }
93 
95 write_samples_plots(const Book& book) const {
96  TFile file((Prefix+"ensembleFits.root").c_str(),"RECREATE");
97  for(Book::const_iterator hist = book.begin(".*(measure|merr|ensembleReco|pull)"); hist!=book.end(); ++hist)
98  hist->second->Write();
99  file.Close();
100 }
101 
104  std::fstream file((Prefix+"calibrations.dat").c_str(),std::ios::out);
105  std::pair<std::string,MethodCalibrations> cal;
106  BOOST_FOREACH(cal,calibrations) {
107  file << cal.first << std::endl
108  << "\t slopes("; BOOST_FOREACH(float i, cal.second.slopes) file << i<< ","; file << ")" << std::endl
109  << "\t offsets("; BOOST_FOREACH(float i, cal.second.offsets) file << i<< ","; file << ")" << std::endl
110  << "\t pulls("; BOOST_FOREACH(float i, cal.second.pulls) file << i<< ","; file << ")" << std::endl;
111  }
112  file.close();
113 }
114 
115 }
116 
std::map< std::string, MethodCalibrations > calibrations
int i
Definition: DBlmapReader.cc:9
static unsigned layer_index(bool TIB, bool stereo, unsigned layer)
static void fit(Book &book)
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:132
static std::map< std::string, std::vector< EnsembleSummary > > ensemble_summary(const Book &)
Definition: LA_Results.cc:107
string format
Some error handling for the usage.
void fill(TTree *, Book &) const
Definition: LA_Filler.cc:8
void summarize_ensembles(Book &) const
Definition: LA_Results.cc:83
const std::vector< std::string > inputFiles
iterator begin(string_t re=".*")
Definition: Book.h:48
tuple conf
Definition: dbtoconf.py:185
void write_samples_plots(const Book &) const
tuple out
Definition: dbtoconf.py:99
EnsembleCalibrationLA(const edm::ParameterSet &)
boost::filter_iterator< match_name, book_t::const_iterator > const_iterator
Definition: Book.h:47
static float pull(const std::vector< EnsembleSummary > &)
Definition: LA_Results.cc:156
Definition: Book.h:16
tuple inputFiles
Definition: merge.py:5
tuple cout
Definition: gather_cfg.py:121
iterator end(string_t re=".*")
Definition: Book.h:50