CMS 3D CMS Logo

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