CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MillePedeDQMModule.cc
Go to the documentation of this file.
1 
9 /*** header-file ***/
11 
12 /*** ROOT objects ***/
13 #include "TH1F.h"
14 
15 /*** Core framework functionality ***/
18 
19 /*** Alignment ***/
23 
24 /*** Necessary Framework infrastructure ***/
27 
29  : tTopoToken_(esConsumes<edm::Transition::BeginRun>()),
30  gDetToken_(esConsumes<edm::Transition::BeginRun>()),
31  ptpToken_(esConsumes<edm::Transition::BeginRun>()),
32  ptitpToken_(esConsumes<edm::Transition::BeginRun>()),
33  aliThrToken_(esConsumes<edm::Transition::BeginRun>()),
34  mpReaderConfig_(config.getParameter<edm::ParameterSet>("MillePedeFileReader")) {
35  consumes<AlignmentToken, edm::InProcess>(config.getParameter<edm::InputTag>("alignmentTokenSrc"));
36 }
37 
39 
40 //=============================================================================
41 //=== INTERFACE IMPLEMENTATION ===
42 //=============================================================================
43 
45  edm::LogInfo("MillePedeDQMModule") << "Booking histograms";
46 
47  booker.cd();
48  booker.setCurrentFolder("AlCaReco/SiPixelAli/");
49 
50  h_xPos = booker.book1D("Xpos", "Alignment fit #DeltaX;;#mum", 36, 0., 36.);
51  h_xRot = booker.book1D("Xrot", "Alignment fit #Delta#theta_{X};;#murad", 36, 0., 36.);
52  h_yPos = booker.book1D("Ypos", "Alignment fit #DeltaY;;#mum", 36, 0., 36.);
53  h_yRot = booker.book1D("Yrot", "Alignment fit #Delta#theta_{Y};;#murad", 36, 0., 36.);
54  h_zPos = booker.book1D("Zpos", "Alignment fit #DeltaZ;;#mum", 36, 0., 36.);
55  h_zRot = booker.book1D("Zrot", "Alignment fit #Delta#theta_{Z};;#murad", 36, 0., 36.);
56 
57  statusResults = booker.book2D("statusResults", "Status of SiPixelAli PCL workflow;;", 6, 0., 6., 1, 0., 1.);
58  binariesAvalaible = booker.bookInt("BinariesFound");
59  exitCode = booker.bookString("PedeExitCode", "");
60 
61  booker.cd();
62 }
63 
65  bookHistograms(booker);
66  if (mpReader_) {
67  mpReader_->read();
68  } else {
69  throw cms::Exception("LogicError") << "@SUB=MillePedeDQMModule::dqmEndJob\n"
70  << "Try to read MillePede results before initializing MillePedeFileReader";
71  }
74  binariesAvalaible->Fill(mpReader_->binariesAmount());
75  auto theResults = mpReader_->getResults();
76  std::string exitCodeStr = theResults.getExitMessage();
77  exitCode->Fill(exitCodeStr);
78 }
79 
80 //=============================================================================
81 //=== PRIVATE METHOD IMPLEMENTATION ===
82 //=============================================================================
83 
85  if (!setupChanged(setup))
86  return;
87 
88  const TrackerTopology* const tTopo = &setup.getData(tTopoToken_);
89  const GeometricDet* geometricDet = &setup.getData(gDetToken_);
90  const PTrackerParameters* ptp = &setup.getData(ptpToken_);
92 
93  // take the thresholds from DB
94  const auto& thresholds_ = &setup.getData(aliThrToken_);
95 
96  auto myThresholds = std::make_shared<AlignPCLThresholds>();
97  myThresholds->setAlignPCLThresholds(thresholds_->getNrecords(), thresholds_->getThreshold_Map());
98 
100 
101  const auto trackerGeometry = builder.build(geometricDet, ptitp, *ptp, tTopo);
102  tracker_ = std::make_unique<AlignableTracker>(trackerGeometry, tTopo);
103 
104  const std::string labelerPlugin{"PedeLabeler"};
105  edm::ParameterSet labelerConfig{};
106  labelerConfig.addUntrackedParameter("plugin", labelerPlugin);
107  labelerConfig.addUntrackedParameter("RunRangeSelection", edm::VParameterSet{});
108 
109  std::shared_ptr<PedeLabelerBase> pedeLabeler{PedeLabelerPluginFactory::get()->create(
110  labelerPlugin, PedeLabelerBase::TopLevelAlignables(tracker_.get(), nullptr, nullptr), labelerConfig)};
111 
112  mpReader_ = std::make_unique<MillePedeFileReader>(
113  mpReaderConfig_, pedeLabeler, std::shared_ptr<const AlignPCLThresholds>(myThresholds));
114 }
115 
117  TH2F* histo_status = statusHisto->getTH2F();
118  auto theResults = mpReader_->getResults();
119  theResults.print();
120  histo_status->SetBinContent(1, 1, theResults.getDBUpdated());
121  histo_status->GetXaxis()->SetBinLabel(1, "DB updated");
122  histo_status->SetBinContent(2, 1, theResults.exceedsCutoffs());
123  histo_status->GetXaxis()->SetBinLabel(2, "significant movement");
124  histo_status->SetBinContent(3, 1, theResults.getDBVetoed());
125  histo_status->GetXaxis()->SetBinLabel(3, "DB update vetoed");
126  histo_status->SetBinContent(4, 1, !theResults.exceedsThresholds());
127  histo_status->GetXaxis()->SetBinLabel(4, "within max movement");
128  histo_status->SetBinContent(5, 1, !theResults.exceedsMaxError());
129  histo_status->GetXaxis()->SetBinLabel(5, "within max error");
130  histo_status->SetBinContent(6, 1, !theResults.belowSignificance());
131  histo_status->GetXaxis()->SetBinLabel(6, "above significance");
132 }
133 
135  std::array<double, 6> Xcut_, sigXcut_, maxMoveXcut_, maxErrorXcut_;
136  std::array<double, 6> tXcut_, sigtXcut_, maxMovetXcut_, maxErrortXcut_;
137 
138  std::array<double, 6> Ycut_, sigYcut_, maxMoveYcut_, maxErrorYcut_;
139  std::array<double, 6> tYcut_, sigtYcut_, maxMovetYcut_, maxErrortYcut_;
140 
141  std::array<double, 6> Zcut_, sigZcut_, maxMoveZcut_, maxErrorZcut_;
142  std::array<double, 6> tZcut_, sigtZcut_, maxMovetZcut_, maxErrortZcut_;
143 
144  auto myMap = mpReader_->getThresholdMap();
145 
146  std::vector<std::string> alignablesList;
147  for (auto it = myMap.begin(); it != myMap.end(); ++it) {
148  alignablesList.push_back(it->first);
149  }
150 
151  for (auto& alignable : alignablesList) {
152  int detIndex = getIndexFromString(alignable);
153 
154  Xcut_[detIndex] = myMap[alignable].getXcut();
155  sigXcut_[detIndex] = myMap[alignable].getSigXcut();
156  maxMoveXcut_[detIndex] = myMap[alignable].getMaxMoveXcut();
157  maxErrorXcut_[detIndex] = myMap[alignable].getErrorXcut();
158 
159  Ycut_[detIndex] = myMap[alignable].getYcut();
160  sigYcut_[detIndex] = myMap[alignable].getSigYcut();
161  maxMoveYcut_[detIndex] = myMap[alignable].getMaxMoveYcut();
162  maxErrorYcut_[detIndex] = myMap[alignable].getErrorYcut();
163 
164  Zcut_[detIndex] = myMap[alignable].getZcut();
165  sigZcut_[detIndex] = myMap[alignable].getSigZcut();
166  maxMoveZcut_[detIndex] = myMap[alignable].getMaxMoveZcut();
167  maxErrorZcut_[detIndex] = myMap[alignable].getErrorZcut();
168 
169  tXcut_[detIndex] = myMap[alignable].getThetaXcut();
170  sigtXcut_[detIndex] = myMap[alignable].getSigThetaXcut();
171  maxMovetXcut_[detIndex] = myMap[alignable].getMaxMoveThetaXcut();
172  maxErrortXcut_[detIndex] = myMap[alignable].getErrorThetaXcut();
173 
174  tYcut_[detIndex] = myMap[alignable].getThetaYcut();
175  sigtYcut_[detIndex] = myMap[alignable].getSigThetaYcut();
176  maxMovetYcut_[detIndex] = myMap[alignable].getMaxMoveThetaYcut();
177  maxErrortYcut_[detIndex] = myMap[alignable].getErrorThetaYcut();
178 
179  tZcut_[detIndex] = myMap[alignable].getThetaZcut();
180  sigtZcut_[detIndex] = myMap[alignable].getSigThetaZcut();
181  maxMovetZcut_[detIndex] = myMap[alignable].getMaxMoveThetaZcut();
182  maxErrortZcut_[detIndex] = myMap[alignable].getErrorThetaZcut();
183  }
184 
185  fillExpertHisto(h_xPos, Xcut_, sigXcut_, maxMoveXcut_, maxErrorXcut_, mpReader_->getXobs(), mpReader_->getXobsErr());
187  h_xRot, tXcut_, sigtXcut_, maxMovetXcut_, maxErrortXcut_, mpReader_->getTXobs(), mpReader_->getTXobsErr());
188 
189  fillExpertHisto(h_yPos, Ycut_, sigYcut_, maxMoveYcut_, maxErrorYcut_, mpReader_->getYobs(), mpReader_->getYobsErr());
191  h_yRot, tYcut_, sigtYcut_, maxMovetYcut_, maxErrortYcut_, mpReader_->getTYobs(), mpReader_->getTYobsErr());
192 
193  fillExpertHisto(h_zPos, Zcut_, sigZcut_, maxMoveZcut_, maxErrorZcut_, mpReader_->getZobs(), mpReader_->getZobsErr());
195  h_zRot, tZcut_, sigtZcut_, maxMovetZcut_, maxErrortZcut_, mpReader_->getTZobs(), mpReader_->getTZobsErr());
196 }
197 
199  const std::array<double, 6>& cut,
200  const std::array<double, 6>& sigCut,
201  const std::array<double, 6>& maxMoveCut,
202  const std::array<double, 6>& maxErrorCut,
203  const std::array<double, 6>& obs,
204  const std::array<double, 6>& obsErr) {
205  TH1F* histo_0 = histo->getTH1F();
206 
207  double max_ = *std::max_element(maxMoveCut.begin(), maxMoveCut.end());
208 
209  histo_0->SetMinimum(-(max_));
210  histo_0->SetMaximum(max_);
211 
212  // Schematics of the bin contents
213  //
214  // XX XX XX XX XX XX OO OO OO OO II II II II
215  // |--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|--|
216  // | 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16|17| ...
217  //
218  // |-----------------| |-----------| |-----------|
219  // |observed movement| |thresholds1| |thresholds2|
220 
221  for (size_t i = 0; i < obs.size(); ++i) {
222  // fist obs.size() bins for observed movements
223  histo_0->SetBinContent(i + 1, obs[i]);
224  histo_0->SetBinError(i + 1, obsErr[i]);
225 
226  // then at bin 8,8+5,8+10,... for cutoffs
227  // 5 bins is the space allocated for the 4 other thresholds + 1 empty separation bin
228  histo_0->SetBinContent(8 + i * 5, cut[i]);
229 
230  // then at bin 9,9+5,9+10,... for significances
231  histo_0->SetBinContent(9 + i * 5, sigCut[i]);
232 
233  // then at bin 10,10+5,10+10,... for maximum movements
234  histo_0->SetBinContent(10 + i * 5, maxMoveCut[i]);
235 
236  // then at bin 11,11+5,11+10,... for maximum errors
237  histo_0->SetBinContent(11 + i * 5, maxErrorCut[i]);
238  }
239 }
240 
242  bool changed{false};
243 
244  if (watchIdealGeometryRcd_.check(setup))
245  changed = true;
246  if (watchTrackerTopologyRcd_.check(setup))
247  changed = true;
249  changed = true;
250 
251  return changed;
252 }
253 
255  if (alignableId == "TPBHalfBarrelXminus") {
256  return 3;
257  } else if (alignableId == "TPBHalfBarrelXplus") {
258  return 2;
259  } else if (alignableId == "TPEHalfCylinderXminusZminus") {
260  return 1;
261  } else if (alignableId == "TPEHalfCylinderXplusZminus") {
262  return 0;
263  } else if (alignableId == "TPEHalfCylinderXminusZplus") {
264  return 5;
265  } else if (alignableId == "TPEHalfCylinderXplusZplus") {
266  return 4;
267  } else {
268  throw cms::Exception("LogicError") << "@SUB=MillePedeDQMModule::getIndexFromString\n"
269  << "Retrieving conversion for not supported Alignable partition" << alignableId;
270  }
271 }
const edm::ParameterSet mpReaderConfig_
void fillStatusHisto(MonitorElement *statusHisto)
virtual TH2F * getTH2F() const
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
virtual TH1F * getTH1F() const
TrackerGeometry * build(const GeometricDet *gd, const PTrackerAdditionalParametersPerDet *ptitp, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
bool setupChanged(const edm::EventSetup &)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
MonitorElement * h_zPos
DQM Plotter for PCL-Alignment.
const edm::ESGetToken< GeometricDet, IdealGeometryRecord > gDetToken_
MonitorElement * binariesAvalaible
MonitorElement * bookString(TString const &name, TString const &value, FUNC onbooking=NOOP())
Definition: DQMStore.h:87
void Fill(long long x)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
edm::ESWatcher< IdealGeometryRecord > watchIdealGeometryRcd_
const edm::ESGetToken< PTrackerAdditionalParametersPerDet, PTrackerAdditionalParametersPerDetRcd > ptitpToken_
MillePedeDQMModule(const edm::ParameterSet &)
void bookHistograms(DQMStore::IBooker &)
Transition
Definition: Transition.h:12
MonitorElement * h_xPos
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
MonitorElement * h_yPos
Log< level::Info, false > LogInfo
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:192
MonitorElement * statusResults
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
MonitorElement * bookInt(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:73
const edm::ESGetToken< AlignPCLThresholds, AlignPCLThresholdsRcd > aliThrToken_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::ESWatcher< TrackerTopologyRcd > watchTrackerTopologyRcd_
edm::ESWatcher< PTrackerParametersRcd > watchPTrackerParametersRcd_
MonitorElement * h_xRot
tuple config
parse the configuration file
const edm::ESGetToken< PTrackerParameters, PTrackerParametersRcd > ptpToken_
std::unique_ptr< AlignableTracker > tracker_
std::unique_ptr< MillePedeFileReader > mpReader_
int getIndexFromString(const std::string &alignableId)
#define get
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MonitorElement * h_zRot
MonitorElement * exitCode
~MillePedeDQMModule() override
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
tTopoToken_
MonitorElement * h_yRot
Definition: Run.h:45