CMS 3D CMS Logo

MeasureLA.cc
Go to the documentation of this file.
5 
6 #include <TChain.h>
7 #include <TFile.h>
8 #include <regex>
9 #include <fstream>
10 
11 namespace sistrip {
12 
14  for (auto const& p : vpset) {
15  methods |= p.getParameter<int32_t>("Method");
16  byModule = byModule || p.getParameter<int32_t>("Granularity");
17  byLayer = byLayer || !p.getParameter<int32_t>("Granularity");
18  }
19  }
20 
22  : inputFiles(conf.getParameter<std::vector<std::string> >("InputFiles")),
23  inFileLocation(conf.getParameter<std::string>("InFileLocation")),
24  fp_(conf.getParameter<edm::FileInPath>("SiStripDetInfo")),
25  reports(conf.getParameter<edm::VParameterSet>("Reports")),
26  measurementPreferences(conf.getParameter<edm::VParameterSet>("MeasurementPreferences")),
27  calibrations(conf.getParameter<edm::VParameterSet>("Calibrations")),
28  methods(0),
29  byModule(false),
30  byLayer(false),
31  localybin(conf.getUntrackedParameter<double>("LocalYBin", 0.0)),
32  stripsperbin(conf.getUntrackedParameter<unsigned>("StripsPerBin", 0)),
33  maxEvents(conf.getUntrackedParameter<unsigned>("MaxEvents", 0)),
35  conf.getParameter<edm::FileInPath>("TrackerParameters").fullPath())) {
39 
40  TChain* const chain = new TChain("la_data");
41  for (auto const& file : inputFiles)
42  chain->Add((file + inFileLocation).c_str());
43 
45  laff.fill(chain, book);
46  laff.fit(book);
49 
51  }
52 
53  std::unique_ptr<SiStripLorentzAngle> MeasureLA::produce(const SiStripLorentzAngleRcd&) {
54  auto lorentzAngle = std::make_unique<SiStripLorentzAngle>();
55  /*
56  std::map<uint32_t,LA_Filler_Fitter::Result>
57  module_results = LA_Filler_Fitter::module_results(book, LA_Filler_Fitter::SQRTVAR);
58 
59  BOOST_FOREACH(const uint32_t& detid, SiStripDetInfoFileReader::read(fp_.fullPath()).getAllDetIds()) {
60  float la = module_results[detid].measure / module_results[detid].field ;
61  lorentzAngle->putLorentzAngle( detid, la );
62  }
63  */
64  return lorentzAngle;
65  }
66 
71  calibrate(calibration_key(result.first, method), result.second);
74  label = std::regex_replace(label, std::regex("layer"), "");
75 
76  const double mu_H = -result.second.calMeasured.first / result.second.field;
77  const double sigma_mu_H = result.second.calMeasured.second / result.second.field;
78  const double weight = pow(1. / sigma_mu_H, 2);
79 
80  book.fill(mu_H, label, 150, -0.05, 0.1, weight);
81  }
82  for (Book::iterator it = book.begin(".*" + granularity(MODULESUMMARY) + ".*"); it != book.end(); ++it) {
83  if (it->second->GetEntries())
84  it->second->Fit("gaus", "LLQ");
85  }
86  }
87  }
88 
90  for (auto const& p : reports) {
91  const GRANULARITY gran = (GRANULARITY)p.getParameter<int32_t>("Granularity");
92  const std::string name = p.getParameter<std::string>("ReportName");
93  const LA_Filler_Fitter::Method method = (LA_Filler_Fitter::Method)p.getParameter<int32_t>("Method");
94 
96  switch (gran) {
97  case LAYER:
99  break;
100  case MODULE:
102  break;
103  case MODULESUMMARY:
105  break;
106  }
107  }
108 
109  {
110  TFile widthsFile("widths.root", "RECREATE");
111  for (Book::const_iterator it = book.begin(".*_width"); it != book.end(); it++)
112  if (it->second)
113  it->second->Write();
114  widthsFile.Close();
115  }
116  }
117 
119  TFile file((name + ".root").c_str(), "RECREATE");
120  const std::string key = ".*" + granularity(gran) + ".*(" + LA_Filler_Fitter::method(method) + "|" +
121  LA_Filler_Fitter::method(method, false) + ".*)";
123  if (hist->second)
124  hist->second->Write();
125  file.Close();
126  }
127 
128  template <class T>
130  const LA_Filler_Fitter::Method& _method,
131  const std::map<T, LA_Filler_Fitter::Result>& _results) const {
133  std::map<T, LA_Filler_Fitter::Result> results = _results;
134  std::fstream file((name + ".dat").c_str(), std::ios::out);
135  for (auto& result : results) {
136  calibrate(calibration_key(result.first, method), result.second);
137  file << result.first << "\t" << result.second << std::endl;
138  }
139  file.close();
140  }
141 
143  std::fstream file((name + ".dat").c_str(), std::ios::out);
145  for (Book::const_iterator it = book.begin(key); it != book.end(); ++it) {
146  const TF1* const f = it->second->GetFunction("gaus");
147  if (f) {
148  file << it->first << "\t" << f->GetParameter(1) << "\t" << f->GetParError(1) << "\t" << f->GetParameter(2)
149  << "\t" << f->GetParError(2) << std::endl;
150  }
151  }
152  file.close();
153  }
154 
156  for (auto const& p : calibrations) {
157  LA_Filler_Fitter::Method method = (LA_Filler_Fitter::Method)p.getParameter<int32_t>("Method");
158  std::vector<double> slopes(p.getParameter<std::vector<double> >("Slopes"));
159  assert(slopes.size() == 14);
160  std::vector<double> offsets(p.getParameter<std::vector<double> >("Offsets"));
161  assert(offsets.size() == 14);
162  std::vector<double> pulls(p.getParameter<std::vector<double> >("Pulls"));
163  assert(pulls.size() == 14);
164 
165  for (unsigned i = 0; i < 14; i++) {
166  const std::pair<unsigned, LA_Filler_Fitter::Method> key(i, method);
167  offset[key] = offsets[i];
168  slope[key] = slopes[i];
169  error_scaling[key] = pulls[i];
170  }
171  }
172  }
173 
174  inline void MeasureLA::calibrate(const std::pair<unsigned, LA_Filler_Fitter::Method> key,
176  result.calMeasured = std::make_pair<float, float>(
177  (result.measured.first - offset.find(key)->second) / slope.find(key)->second,
178  result.measured.second * error_scaling.find(key)->second / slope.find(key)->second);
179  }
180 
181  std::pair<uint32_t, LA_Filler_Fitter::Method> MeasureLA::calibration_key(
182  const std::string layer, const LA_Filler_Fitter::Method method) const {
183  std::regex format(".*(T[IO]B)_layer(\\d)([as]).*");
184  const bool isTIB = "TIB" == std::regex_replace(layer, format, "\\1");
185  const bool stereo = "s" == std::regex_replace(layer, format, "\\3");
186  const unsigned layerNum = std::stoul(std::regex_replace(layer, format, "\\2"));
187  return std::make_pair(LA_Filler_Fitter::layer_index(isTIB, stereo, layerNum), method);
188  }
189 
190  std::pair<uint32_t, LA_Filler_Fitter::Method> MeasureLA::calibration_key(
191  const uint32_t detid, const LA_Filler_Fitter::Method method) const {
192  const bool isTIB = SiStripDetId(detid).subDetector() == SiStripDetId::TIB;
193  const bool stereo = isTIB ? tTopo_.tibStereo(detid) : tTopo_.tobStereo(detid);
194  const unsigned layer = isTIB ? tTopo_.tibLayer(detid) : tTopo_.tobStereo(detid);
195 
196  return std::make_pair(LA_Filler_Fitter::layer_index(isTIB, stereo, layer), method);
197  }
198 
199 } // namespace sistrip
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
static std::map< std::string, Result > layer_results(const Book &, const Method)
Definition: LA_Results.cc:69
void summarize_module_muH_byLayer(const LA_Filler_Fitter &)
Definition: MeasureLA.cc:67
static unsigned layer_index(bool TIB, bool stereo, unsigned layer)
static void fit(Book &book)
const unsigned stripsperbin
Definition: MeasureLA.h:62
const edm::VParameterSet measurementPreferences
Definition: MeasureLA.h:57
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
const std::vector< std::string > inputFiles
Definition: MeasureLA.h:54
const unsigned maxEvents
Definition: MeasureLA.h:62
const float localybin
Definition: MeasureLA.h:61
SubDetector subDetector() const
Definition: SiStripDetId.h:105
Definition: weight.py:1
constexpr int pow(int x)
Definition: conifer.h:24
assert(be >=bs)
static std::string granularity(int32_t g)
Definition: MeasureLA.h:24
sistrip classes
void store_methods_and_granularity(const edm::VParameterSet &)
Definition: MeasureLA.cc:13
void process_reports() const
Definition: MeasureLA.cc:89
char const * label
const edm::VParameterSet calibrations
Definition: MeasureLA.h:57
MeasureLA(const edm::ParameterSet &)
Definition: MeasureLA.cc:21
uint32_t tobStereo(const DetId &id) const
const edm::VParameterSet reports
Definition: MeasureLA.h:57
boost::filter_iterator< match_name, book_t::iterator > iterator
Definition: Book.h:55
double f[11][100]
iterator begin(string_t re=".*")
Definition: Book.h:57
const std::string inFileLocation
Definition: MeasureLA.h:55
static std::string method(Method m, bool fit=true)
void calibrate(const std::pair< unsigned, LA_Filler_Fitter::Method >, LA_Filler_Fitter::Result &) const
Definition: MeasureLA.cc:174
std::unique_ptr< SiStripLorentzAngle > produce(const SiStripLorentzAngleRcd &)
Definition: MeasureLA.cc:53
void write_report_plots(const std::string, const LA_Filler_Fitter::Method, const GRANULARITY) const
Definition: MeasureLA.cc:118
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
void store_calibrations()
Definition: MeasureLA.cc:155
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
static std::map< uint32_t, Result > module_results(const Book &, const Method)
Definition: LA_Results.cc:59
std::map< std::pair< uint32_t, LA_Filler_Fitter::Method >, float > error_scaling
Definition: MeasureLA.h:58
static constexpr auto TIB
Definition: SiStripDetId.h:37
void fill(TTree *, Book &) const
Definition: LA_Filler.cc:7
HLT enums.
void write_report_text(const std::string, const LA_Filler_Fitter::Method &, const std::map< T, LA_Filler_Fitter::Result > &) const
Definition: MeasureLA.cc:129
boost::filter_iterator< match_name, book_t::const_iterator > const_iterator
Definition: Book.h:56
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
std::string layerLabel(const SiStripDetId) const
Definition: LA_Filler.cc:127
void write_report_text_ms(const std::string, const LA_Filler_Fitter::Method) const
Definition: MeasureLA.cc:142
results
Definition: mysort.py:8
unsigned int tibLayer(const DetId &id) const
std::pair< unsigned, LA_Filler_Fitter::Method > calibration_key(const std::string layer, const LA_Filler_Fitter::Method) const
Definition: MeasureLA.cc:181
std::map< std::pair< uint32_t, LA_Filler_Fitter::Method >, float > slope
Definition: MeasureLA.h:58
uint32_t tibStereo(const DetId &id) const
TrackerTopology tTopo_
Definition: MeasureLA.h:65
iterator end(string_t re=".*")
Definition: Book.h:65
std::map< std::pair< uint32_t, LA_Filler_Fitter::Method >, float > offset
Definition: MeasureLA.h:58