CMS 3D CMS Logo

EnsembleCalibrationLA.cc
Go to the documentation of this file.
4 #include <TChain.h>
5 #include <TFile.h>
6 #include <boost/lexical_cast.hpp>
7 #include <fstream>
8 #include <regex>
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  tTopoToken_(esConsumes<edm::Transition::EndRun>()) {}
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 
46  tTopo_ = &eSetup.getData(tTopoToken_);
47  }
48 
50  for (auto const& ensemble : LA_Filler_Fitter::ensemble_summary(book)) {
51  std::fstream file((Prefix + ensemble.first + ".dat").c_str(), std::ios::out);
52  for (auto const& summary : ensemble.second)
53  file << summary << std::endl;
54 
55  const std::pair<std::pair<float, float>, std::pair<float, float> > line =
56  LA_Filler_Fitter::offset_slope(ensemble.second);
57  const float pull = LA_Filler_Fitter::pull(ensemble.second);
58 
59  unsigned index = 15;
61  {
62  std::cout << ensemble.first << std::endl;
63  std::regex format(".*(T[IO]B)_layer(\\d)([as])_(.*)");
64  if (std::regex_match(ensemble.first, format)) {
65  const bool TIB = "TIB" == std::regex_replace(ensemble.first, format, "\\1");
66  const bool stereo = "s" == std::regex_replace(ensemble.first, format, "\\3");
67  const unsigned layer = boost::lexical_cast<unsigned>(std::regex_replace(ensemble.first, format, "\\2"));
68  label = std::regex_replace(ensemble.first, format, "\\4");
69  index = LA_Filler_Fitter::layer_index(TIB, stereo, layer);
70 
71  calibrations[label].slopes[index] = line.second.first;
72  calibrations[label].offsets[index] = line.first.first;
73  calibrations[label].pulls[index] = pull;
74  }
75  }
76 
77  file << std::endl
78  << std::endl
79  << "# Best Fit Line: " << line.first.first << "(" << line.first.second << ") + x* " << line.second.first
80  << "(" << line.second.second << ")" << std::endl
81  << "# Pull (average sigma of (x_measure-x_truth)/e_measure): " << pull << std::endl
82  << "LA_Calibration( METHOD_XXXXX , xxx, " << line.second.first << ", " << line.first.first << ", " << pull
83  << ")," << std::endl;
84  file.close();
85  }
86  }
87 
89  TFile file((Prefix + "sampleFits.root").c_str(), "RECREATE");
90  for (Book::const_iterator hist = book.begin(".*(profile|ratio|reconstruction|symm|symmchi2|_w\\d)");
91  hist != book.end();
92  ++hist)
93  hist->second->Write();
94  file.Close();
95  }
96 
98  TFile file((Prefix + "ensembleFits.root").c_str(), "RECREATE");
99  for (Book::const_iterator hist = book.begin(".*(measure|merr|ensembleReco|pull)"); hist != book.end(); ++hist)
100  hist->second->Write();
101  file.Close();
102  }
103 
105  std::fstream file((Prefix + "calibrations.dat").c_str(), std::ios::out);
106  for (auto const& cal : calibrations) {
107  file << cal.first << std::endl << "\t slopes(";
108  for (float i : cal.second.slopes)
109  file << i << ",";
110  file << ")" << std::endl << "\t offsets(";
111  for (float i : cal.second.offsets)
112  file << i << ",";
113  file << ")" << std::endl << "\t pulls(";
114  for (float i : cal.second.pulls)
115  file << i << ",";
116  file << ")" << std::endl;
117  }
118  file.close();
119  }
120 
121 } // namespace sistrip
sistrip::EnsembleCalibrationLA::calibrations
std::map< std::string, MethodCalibrations > calibrations
Definition: EnsembleCalibrationLA.h:36
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
mps_fire.i
i
Definition: mps_fire.py:428
sistrip::EnsembleCalibrationLA::nbins
const unsigned nbins
Definition: EnsembleCalibrationLA.h:25
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
AlcaSiPixelAliHarvester0T_cff.method
method
Definition: AlcaSiPixelAliHarvester0T_cff.py:41
Book::const_iterator
boost::filter_iterator< match_name, book_t::const_iterator > const_iterator
Definition: Book.h:56
EnsembleCalibrationLA.h
sistrip::EnsembleCalibrationLA::EnsembleCalibrationLA
EnsembleCalibrationLA(const edm::ParameterSet &)
Definition: EnsembleCalibrationLA.cc:12
sistrip::EnsembleCalibrationLA::write_calibrations
void write_calibrations() const
Definition: EnsembleCalibrationLA.cc:104
sistrip::EnsembleCalibrationLA::write_ensembles_text
void write_ensembles_text(const Book &)
Definition: EnsembleCalibrationLA.cc:49
EgammaValidation_cff.samples
samples
Definition: EgammaValidation_cff.py:19
Book
Definition: Book.h:16
sistrip::EnsembleCalibrationLA::tTopoToken_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
Definition: EnsembleCalibrationLA.h:38
sistrip::EnsembleCalibrationLA::maxEvents
const unsigned maxEvents
Definition: EnsembleCalibrationLA.h:25
sistrip::EnsembleCalibrationLA::write_ensembles_plots
void write_ensembles_plots(const Book &) const
Definition: EnsembleCalibrationLA.cc:88
compare.hist
hist
Definition: compare.py:376
LA_Filler_Fitter::summarize_ensembles
void summarize_ensembles(Book &) const
Definition: LA_Results.cc:90
sistrip::TIB
Definition: ConstantsForGranularity.h:66
sistrip::EnsembleCalibrationLA::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: EnsembleCalibrationLA.cc:45
dqm-mbProfile.format
format
Definition: dqm-mbProfile.py:16
L1TCaloTriggerNtuples_cff.Prefix
Prefix
Definition: L1TCaloTriggerNtuples_cff.py:8
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
Book::end
iterator end(string_t re=".*")
Definition: Book.h:65
sistrip::EnsembleCalibrationLA::endJob
void endJob() override
Definition: EnsembleCalibrationLA.cc:24
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
sistrip::EnsembleCalibrationLA::vMethods
std::vector< int > vMethods
Definition: EnsembleCalibrationLA.h:27
LA_Filler_Fitter::layer_index
static unsigned layer_index(bool TIB, bool stereo, unsigned layer)
Definition: LA_Filler_Fitter.h:105
sistrip::EnsembleCalibrationLA::write_samples_plots
void write_samples_plots(const Book &) const
Definition: EnsembleCalibrationLA.cc:97
Book.h
createfilelist.int
int
Definition: createfilelist.py:10
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
LA_Filler_Fitter::fit
static void fit(Book &book)
Definition: LA_Filler_Fitter.h:110
LA_Filler_Fitter::pull
static float pull(const std::vector< EnsembleSummary > &)
Definition: LA_Results.cc:169
edm::EventSetup
Definition: EventSetup.h:57
sistrip::EnsembleCalibrationLA::Prefix
const std::string Prefix
Definition: EnsembleCalibrationLA.h:24
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:120
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
std
Definition: JetResolutionObject.h:76
Data_TkAlMinBias_Run2018C_PromptReco_v3_cff.maxEvents
maxEvents
Definition: Data_TkAlMinBias_Run2018C_PromptReco_v3_cff.py:3
format
sistrip::EnsembleCalibrationLA::lowBin
const double lowBin
Definition: EnsembleCalibrationLA.h:26
LA_Filler_Fitter
Definition: LA_Filler_Fitter.h:14
sistrip::EnsembleCalibrationLA::highBin
const double highBin
Definition: EnsembleCalibrationLA.h:26
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
submitPVValidationJobs.inputFiles
list inputFiles
Definition: submitPVValidationJobs.py:929
sistrip::EnsembleCalibrationLA::inFileLocation
const std::string inFileLocation
Definition: EnsembleCalibrationLA.h:24
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
sistrip::EnsembleCalibrationLA::inputFiles
const std::vector< std::string > inputFiles
Definition: EnsembleCalibrationLA.h:23
ParameterSet.h
sistrip
sistrip classes
Definition: SiStripQualityHelpers.h:14
LA_Filler_Fitter::fill
void fill(TTree *, Book &) const
Definition: LA_Filler.cc:7
mps_splice.line
line
Definition: mps_splice.py:76
label
const char * label
Definition: PFTauDecayModeTools.cc:11
chain
Definition: chain.py:1
sistrip::EnsembleCalibrationLA::samples
const unsigned samples
Definition: EnsembleCalibrationLA.h:25
sistrip::EnsembleCalibrationLA::tTopo_
const TrackerTopology * tTopo_
Definition: EnsembleCalibrationLA.h:39