CMS 3D CMS Logo

MillePedeDQMModule.cc
Go to the documentation of this file.
1 
10 /*** header-file ***/
12 
13 /*** ROOT objects ***/
14 #include "TH1F.h"
15 
16 /*** Core framework functionality ***/
20 
21 /*** Geometry ***/
25 
26 /*** Alignment ***/
30 
31 /*** Thresholds from DB ***/
33 
34 
37  mpReaderConfig_(
38  config.getParameter<edm::ParameterSet>("MillePedeFileReader")
39  )
40 {
41 }
42 
45 {
46 }
47 
48 //=============================================================================
49 //=== INTERFACE IMPLEMENTATION ===
50 //=============================================================================
51 
54 {
55  edm::LogInfo("MillePedeDQMModule") << "Booking histograms";
56 
57  booker.cd();
58  booker.setCurrentFolder("AlCaReco/SiPixelAli/");
59 
60  h_xPos = booker.book1D("Xpos", "Alignment fit #DeltaX;;#mum", 36, 0., 36.);
61  h_xRot = booker.book1D("Xrot", "Alignment fit #Delta#theta_{X};;#murad", 36, 0., 36.);
62  h_yPos = booker.book1D("Ypos", "Alignment fit #DeltaY;;#mum", 36, 0., 36.);
63  h_yRot = booker.book1D("Yrot", "Alignment fit #Delta#theta_{Y};;#murad", 36, 0., 36.);
64  h_zPos = booker.book1D("Zpos", "Alignment fit #DeltaZ;;#mum", 36, 0., 36.);
65  h_zRot = booker.book1D("Zrot", "Alignment fit #Delta#theta_{Z};;#murad", 36, 0., 36.);
66 
67  booker.cd();
68 }
69 
70 
73 {
74  bookHistograms(booker);
75  if (mpReader_) {
76  mpReader_->read();
77  } else {
78  throw cms::Exception("LogicError")
79  << "@SUB=MillePedeDQMModule::dqmEndJob\n"
80  << "Try to read MillePede results before initializing MillePedeFileReader";
81  }
82  fillExpertHistos();
83 }
84 
85 
86 
87 //=============================================================================
88 //=== PRIVATE METHOD IMPLEMENTATION ===
89 //=============================================================================
90 
93 
94  if (!setupChanged(setup)) return;
95 
97  setup.get<TrackerTopologyRcd>().get(tTopo);
98  edm::ESHandle<GeometricDet> geometricDet;
99  setup.get<IdealGeometryRecord>().get(geometricDet);
101  setup.get<PTrackerParametersRcd>().get(ptp);
102 
103  // take the thresholds from DB
104  edm::ESHandle<AlignPCLThresholds> thresholdHandle;
105  setup.get<AlignPCLThresholdsRcd>().get(thresholdHandle);
106  auto thresholds_ = thresholdHandle.product();
107 
108  auto myThresholds = std::make_shared<AlignPCLThresholds>();
109  myThresholds->setAlignPCLThresholds(thresholds_->getNrecords(),thresholds_->getThreshold_Map());
110 
112 
113  const auto trackerGeometry = builder.build(&(*geometricDet), *ptp, &(*tTopo));
114  tracker_ = std::make_unique<AlignableTracker>(trackerGeometry, &(*tTopo));
115 
116  const std::string labelerPlugin{"PedeLabeler"};
117  edm::ParameterSet labelerConfig{};
118  labelerConfig.addUntrackedParameter("plugin", labelerPlugin);
119  labelerConfig.addUntrackedParameter("RunRangeSelection", edm::VParameterSet{});
120 
121  std::shared_ptr<PedeLabelerBase> pedeLabeler{
123  ->create(labelerPlugin,
124  PedeLabelerBase::TopLevelAlignables(tracker_.get(), nullptr, nullptr),
125  labelerConfig)
126  };
127 
128 
129  mpReader_ = std::make_unique<MillePedeFileReader>(mpReaderConfig_, pedeLabeler, std::shared_ptr<const AlignPCLThresholds>(myThresholds));
130 
131 }
132 
133 
136 {
137 
138  std::array<double, 6> Xcut_, sigXcut_, maxMoveXcut_, maxErrorXcut_;
139  std::array<double, 6> tXcut_, sigtXcut_, maxMovetXcut_, maxErrortXcut_;
140 
141  std::array<double, 6> Ycut_, sigYcut_, maxMoveYcut_, maxErrorYcut_;
142  std::array<double, 6> tYcut_, sigtYcut_, maxMovetYcut_, maxErrortYcut_;
143 
144  std::array<double, 6> Zcut_, sigZcut_, maxMoveZcut_, maxErrorZcut_;
145  std::array<double, 6> tZcut_, sigtZcut_, maxMovetZcut_, maxErrortZcut_;
146 
147  auto myMap = mpReader_->getThresholdMap();
148 
149  std::vector<std::string> alignablesList;
150  for(auto it = myMap.begin(); it != myMap.end() ; ++it){
151  alignablesList.push_back(it->first);
152  }
153 
154  for (auto &alignable : alignablesList){
155 
156  int detIndex = getIndexFromString(alignable);
157 
158  Xcut_[detIndex] = myMap[alignable].getXcut() ;
159  sigXcut_[detIndex] = myMap[alignable].getSigXcut() ;
160  maxMoveXcut_[detIndex] = myMap[alignable].getMaxMoveXcut() ;
161  maxErrorXcut_[detIndex] = myMap[alignable].getErrorXcut() ;
162 
163  Ycut_[detIndex] = myMap[alignable].getYcut() ;
164  sigYcut_[detIndex] = myMap[alignable].getSigYcut() ;
165  maxMoveYcut_[detIndex] = myMap[alignable].getMaxMoveYcut() ;
166  maxErrorYcut_[detIndex] = myMap[alignable].getErrorYcut() ;
167 
168  Zcut_[detIndex] = myMap[alignable].getZcut() ;
169  sigZcut_[detIndex] = myMap[alignable].getSigZcut() ;
170  maxMoveZcut_[detIndex] = myMap[alignable].getMaxMoveZcut() ;
171  maxErrorZcut_[detIndex] = myMap[alignable].getErrorZcut() ;
172 
173  tXcut_[detIndex] = myMap[alignable].getThetaXcut() ;
174  sigtXcut_[detIndex] = myMap[alignable].getSigThetaXcut() ;
175  maxMovetXcut_[detIndex] = myMap[alignable].getMaxMoveThetaXcut() ;
176  maxErrortXcut_[detIndex] = myMap[alignable].getErrorThetaXcut() ;
177 
178  tYcut_[detIndex] = myMap[alignable].getThetaYcut() ;
179  sigtYcut_[detIndex] = myMap[alignable].getSigThetaYcut() ;
180  maxMovetYcut_[detIndex] = myMap[alignable].getMaxMoveThetaYcut() ;
181  maxErrortYcut_[detIndex] = myMap[alignable].getErrorThetaYcut() ;
182 
183  tZcut_[detIndex] = myMap[alignable].getThetaZcut() ;
184  sigtZcut_[detIndex] = myMap[alignable].getSigThetaZcut() ;
185  maxMovetZcut_[detIndex] = myMap[alignable].getMaxMoveThetaZcut() ;
186  maxErrortZcut_[detIndex] = myMap[alignable].getErrorThetaZcut() ;
187 
188  }
189 
190  fillExpertHisto(h_xPos, Xcut_, sigXcut_, maxMoveXcut_, maxErrorXcut_, mpReader_->getXobs(), mpReader_->getXobsErr());
191  fillExpertHisto(h_xRot, tXcut_, sigtXcut_, maxMovetXcut_, maxErrortXcut_, mpReader_->getTXobs(), mpReader_->getTXobsErr());
192 
193  fillExpertHisto(h_yPos, Ycut_, sigYcut_, maxMoveYcut_, maxErrorYcut_, mpReader_->getYobs(), mpReader_->getYobsErr());
194  fillExpertHisto(h_yRot, tYcut_, sigtYcut_, maxMovetYcut_, maxErrortYcut_, mpReader_->getTYobs(), mpReader_->getTYobsErr());
195 
196  fillExpertHisto(h_zPos, Zcut_, sigZcut_, maxMoveZcut_, maxErrorZcut_, mpReader_->getZobs(), mpReader_->getZobsErr());
197  fillExpertHisto(h_zRot, tZcut_, sigtZcut_, maxMovetZcut_, maxErrortZcut_, mpReader_->getTZobs(), mpReader_->getTZobsErr());
198 
199 }
200 
203  const std::array<double, 6>& cut, const std::array<double, 6>& sigCut,
204  const std::array<double, 6>& maxMoveCut,const std::array<double, 6>& maxErrorCut,
205  const std::array<double, 6>& obs,const std::array<double, 6>& obsErr)
206 {
207  TH1F* histo_0 = histo->getTH1F();
208 
209  double max_ = *std::max_element(maxMoveCut.begin(),maxMoveCut.end());
210 
211  histo_0->SetMinimum(-(max_));
212  histo_0->SetMaximum( max_);
213 
214  // Schematics of the bin contents
215  //
216  // XX XX XX XX XX XX OO OO OO OO II II II II
217  // |--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
218  // | 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16|17| ...
219  //
220  // |-----------------| |-----------| |-----------|
221  // |observed movement| |thresholds1| |thresholds2|
222 
223  for (size_t i = 0; i < obs.size(); ++i) {
224 
225  // fist obs.size() bins for observed movements
226  histo_0->SetBinContent(i+1, obs[i]);
227  histo_0->SetBinError(i+1, obsErr[i]);
228 
229  // then at bin 8,8+5,8+10,... for cutoffs
230  // 5 bins is the space allocated for the 4 other thresholds + 1 empty separation bin
231  histo_0->SetBinContent(8+i*5 , cut[i]);
232 
233  // then at bin 9,9+5,9+10,... for significances
234  histo_0->SetBinContent(9+i*5 , sigCut[i]);
235 
236  // then at bin 10,10+5,10+10,... for maximum movements
237  histo_0->SetBinContent(10+i*5, maxMoveCut[i]);
238 
239  // then at bin 11,11+5,11+10,... for maximum errors
240  histo_0->SetBinContent(11+i*5, maxErrorCut[i]);
241 
242  }
243 }
244 
247 {
248  bool changed{false};
249 
250  if (watchIdealGeometryRcd_.check(setup)) changed = true;
251  if (watchTrackerTopologyRcd_.check(setup)) changed = true;
252  if (watchPTrackerParametersRcd_.check(setup)) changed = true;
253 
254  return changed;
255 }
256 
257 
260 {
261 
262  if(alignableId == "TPBHalfBarrelXminus"){
263  return 3;
264  } else if(alignableId == "TPBHalfBarrelXplus"){
265  return 2;
266  } else if(alignableId == "TPEHalfCylinderXminusZminus") {
267  return 1;
268  } else if(alignableId == "TPEHalfCylinderXplusZminus") {
269  return 0;
270  } else if(alignableId == "TPEHalfCylinderXminusZplus") {
271  return 5;
272  } else if(alignableId == "TPEHalfCylinderXplusZplus") {
273  return 4;
274  } else{
275  throw cms::Exception("LogicError")
276  << "@SUB=MillePedeDQMModule::getIndexFromString\n"
277  << "Retrieving conversion for not supported Alignable partition"
278  << alignableId;
279  }
280 }
static const char tracker_[]
TH1F * getTH1F() const
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
bool setupChanged(const edm::EventSetup &)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
virtual example_stream void bookHistograms(DQMStore::IBooker &,@example_stream edm::Run const &,@example_stream edm::EventSetup const &) override
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
DQM Plotter for PCL-Alignment.
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
Definition: config.py:1
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MillePedeDQMModule(const edm::ParameterSet &)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
void bookHistograms(DQMStore::IBooker &)
void fillExpertHisto(MonitorElement *histo, const std::array< double, 6 > &cut, const std::array< double, 6 > &sigCut, const std::array< double, 6 > &maxMoveCut, const std::array< double, 6 > &maxErrorCut, const std::array< double, 6 > &obs, const std::array< double, 6 > &obsErr)
void beginRun(const edm::Run &, const edm::EventSetup &) override
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:207
void setAlignPCLThresholds(const int &Nrecords, const threshold_map &Thresholds)
HLT enums.
T get() const
Definition: EventSetup.h:62
int getIndexFromString(const std::string &alignableId)
~MillePedeDQMModule() override
T const * product() const
Definition: ESHandle.h:86
T get(const Candidate &c)
Definition: component.h:55
Definition: Run.h:44