CMS 3D CMS Logo

SiPixelLorentzAnglePCLHarvesterMCS.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CalibTracker/SiPixelLorentzAnglePCLHarvesterMCS
4 // Class: SiPixelLorentzAnglePCLHarvesterMCS
5 //
15 //
16 // Original Author: tsusa
17 // Created: Sat, 14 Jan 2021 10:12:21 GMT
18 //
19 //
20 
21 // system includes
22 
23 #include <fmt/format.h>
24 #include <fmt/printf.h>
25 #include <fstream>
26 
27 // user includes
45 
46 // for ROOT fits
47 #include "TFitResult.h"
48 #include "TVirtualFitter.h"
49 #include "TH1D.h"
50 
52 
54 
55  Double_t MCSFitFunction(Double_t* x, Double_t* par) {
56  Double_t arg;
57 
58  if (x[0] < par[3]) {
59  arg = par[1] * par[1] + par[2] * par[2] * (x[0] - par[3]) * (x[0] - par[3]);
60  } else {
61  arg = par[1] * par[1] + par[4] * par[4] * (x[0] - par[3]) * (x[0] - par[3]);
62  }
63  Double_t fitval = par[0] + sqrt(arg);
64  return fitval;
65  }
66 
67  struct FPixMuH {
68  double bfield[3];
69  double shiftx; // Shift in x direction
70  double shifty; // Shift in y direction
71  double shiftx_err;
72  double shifty_err;
73  };
74 
75  void fcn_func(Int_t& npar, Double_t* deriv, Double_t& f, Double_t* par, Int_t flag);
76 
77  class FitFPixMuH : public TObject {
78  public:
79  FitFPixMuH() : muH(0), muHErr(0) {}
80 
81  //-----------------------------------------------------------
82  ~FitFPixMuH() override = default;
83 
84  friend void fcn_func(Int_t& npar, Double_t* deriv, Double_t& f, Double_t* par, Int_t flag);
85 
86  void add(const FPixMuH& fmh) { cmvar.push_back(fmh); }
87  int fit(double initVal) {
88  minuit = TVirtualFitter::Fitter(this, 1);
89  minuit->SetFCN(fcn_func);
90  double tanlorpertesla = initVal;
91  minuit->SetParameter(0, "muH", tanlorpertesla, 0.1, 0., 0.);
92 
93  double arglist[100];
94  arglist[0] = 3.;
95  minuit->ExecuteCommand("SET PRINT", arglist, 0);
96  double up = 1.0;
97  minuit->SetErrorDef(up);
98  arglist[0] = 100000.;
99  int status = minuit->ExecuteCommand("MIGRAD", arglist, 0);
100  muH = minuit->GetParameter(0);
101  muHErr = minuit->GetParError(0);
102 
103  return status;
104  }
105 
106  double getMuH() { return muH; }
107  double getMuHErr() { return muHErr; }
108  unsigned int size() { return cmvar.size(); }
109 
110  private:
111  TVirtualFitter* minuit;
112  std::vector<FPixMuH> cmvar;
113  double muH;
114  double muHErr;
115 
116  double calcChi2(double par_0) {
117  double tanlorpertesla = par_0;
118  double tlpt2 = tanlorpertesla * tanlorpertesla;
119  double v[3], xshift, yshift;
120 
121  int n = cmvar.size();
122 
123  double chi2 = 0.0;
124  for (int i = 0; i < n; i++) {
125  v[0] = -(tanlorpertesla * cmvar[i].bfield[1] + tlpt2 * cmvar[i].bfield[0] * cmvar[i].bfield[2]);
126  v[1] = tanlorpertesla * cmvar[i].bfield[0] - tlpt2 * cmvar[i].bfield[1] * cmvar[i].bfield[2];
127  v[2] = -(1. + tlpt2 * cmvar[i].bfield[2] * cmvar[i].bfield[2]);
128 
129  xshift = v[0] / v[2];
130  yshift = v[1] / v[2];
131 
132  chi2 += (xshift - cmvar[i].shiftx) * (xshift - cmvar[i].shiftx) / cmvar[i].shiftx_err / cmvar[i].shiftx_err +
133  (yshift - cmvar[i].shifty) * (yshift - cmvar[i].shifty) / cmvar[i].shifty_err / cmvar[i].shifty_err;
134  }
135  return chi2;
136  }
137  };
138 
139  void fcn_func(Int_t& npar, Double_t* deriv, Double_t& f, Double_t* par, Int_t flag) {
140  f = ((dynamic_cast<FitFPixMuH*>((TVirtualFitter::GetFitter())->GetObjectFit()))->calcChi2(par[0]));
141  }
142 } // namespace SiPixelLAHarvestMCS
143 
144 //------------------------------------------------------------------------------
146 public:
148  ~SiPixelLorentzAnglePCLHarvesterMCS() override = default;
149  using FPixCotAngleFitResults = std::unordered_map<uint32_t, std::pair<double, double>>;
150  using FpixMuHResults = std::unordered_map<std::string, std::pair<double, double>>;
151  using FitParametersInitValuesMuHFitMap = std::unordered_map<std::string, double>;
152 
153  void beginRun(const edm::Run&, const edm::EventSetup&) override;
154 
156 
157 private:
159  void findMean(dqm::reco::MonitorElement* h_2D, dqm::reco::MonitorElement* h_mean, TH1D* h_slice);
160  int getIndex(bool isBetaAngle, int r, int p, int s);
161 
162  // es tokens
167 
169  std::vector<std::string> newmodulelist_;
170  const std::vector<double> fitRange_;
171  const std::vector<double> fitParametersInitValues_;
172  const std::vector<double> fitParametersInitValuesMuHFit_;
174 
175  const int minHitsCut_;
179  std::pair<double, double> theFitRange_{-1.5, 1.5};
180 
181  std::unique_ptr<TF1> f1_;
183 
186 };
187 
188 //------------------------------------------------------------------------------
190  : geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
191  topoEsTokenBR_(esConsumes<edm::Transition::BeginRun>()),
192  topoEsTokenER_(esConsumes<edm::Transition::EndRun>()),
193  siPixelLAEsToken_(esConsumes<edm::Transition::BeginRun>()),
194  dqmDir_(iConfig.getParameter<std::string>("dqmDir")),
195  newmodulelist_(iConfig.getParameter<std::vector<std::string>>("newmodulelist")),
196  fitRange_(iConfig.getParameter<std::vector<double>>("fitRange")),
197  fitParametersInitValues_(iConfig.getParameter<std::vector<double>>("fitParameters")),
198  fitParametersInitValuesMuHFit_(iConfig.getParameter<std::vector<double>>("fitParametersMuHFit")),
199  minHitsCut_(iConfig.getParameter<int>("minHitsCut")),
200  recordName_(iConfig.getParameter<std::string>("record")) {
201  // initialize the fit range
202 
203  if (fitRange_.size() == 2) {
204  theFitRange_.first = fitRange_[0];
205  theFitRange_.second = fitRange_[1];
206  } else {
207  throw cms::Exception("SiPixelLorentzAnglePCLHarvesterMCS") << "Wrong number of fit range parameters specified";
208  }
209 
210  if (fitParametersInitValues_.size() != 5) {
211  throw cms::Exception("SiPixelLorentzAnglePCLHarvesterMCS")
212  << "Wrong number of initial values for fit parameters specified";
213  }
214 
215  if (fitParametersInitValuesMuHFit_.size() != 4) {
216  throw cms::Exception("SiPixelLorentzAnglePCLHarvesterMCS")
217  << "Wrong number of initial values for fit parameters specified";
218  }
219 
224 
225  // first ensure DB output service is available
227  if (!poolDbService.isAvailable())
228  throw cms::Exception("SiPixelLorentzAnglePCLHarvesterMCS") << "PoolDBService required";
229 }
230 
231 //------------------------------------------------------------------------------
233  // geometry
234 
235  const TrackerGeometry* geom = &iSetup.getData(geomEsToken_);
236  tTopo = &iSetup.getData(topoEsTokenBR_);
239  hists_.nlay = geom->numberOfLayers(PixelSubdetector::PixelBarrel);
240  hists_.nModules_.resize(hists_.nlay);
241  hists_.nLadders_.resize(hists_.nlay);
242  for (int i = 0; i < hists_.nlay; i++) {
243  hists_.nModules_[i] = map.getPXBModules(i + 1);
244  hists_.nLadders_[i] = map.getPXBLadders(i + 1);
245  }
246 
247  // list of modules already filled, then return (we already entered here)
248  if (!hists_.BPixnewDetIds_.empty() || !hists_.FPixnewDetIds_.empty())
249  return;
250 
251  if (!newmodulelist_.empty()) {
252  for (auto const& modulename : newmodulelist_) {
253  if (modulename.find("BPix_") != std::string::npos) {
254  PixelBarrelName bn(modulename, true);
255  const auto& detId = bn.getDetId(tTopo);
256  hists_.BPixnewmodulename_.push_back(modulename);
257  hists_.BPixnewDetIds_.push_back(detId.rawId());
258  hists_.BPixnewModule_.push_back(bn.moduleName());
259  hists_.BPixnewLayer_.push_back(bn.layerName());
260  } else if (modulename.find("FPix_") != std::string::npos) {
261  PixelEndcapName en(modulename, true);
262  const auto& detId = en.getDetId(tTopo);
263  hists_.FPixnewmodulename_.push_back(modulename);
264  hists_.FPixnewDetIds_.push_back(detId.rawId());
265  hists_.FPixnewDisk_.push_back(en.diskName());
266  hists_.FPixnewBlade_.push_back(en.bladeName());
267  }
268  }
269  }
270 
271  uint count = 0;
272  for (const auto& id : hists_.BPixnewDetIds_) {
273  LogDebug("SiPixelLorentzAnglePCLHarvesterMCS") << id;
274  count++;
275  }
276  LogDebug("SiPixelLorentzAnglePCLHarvesterMCS") << "Stored a total of " << count << " new detIds.";
277 
278  // list of modules already filled, return (we already entered here)
279  if (!hists_.detIdsList.empty())
280  return;
281 
282  std::vector<uint32_t> treatedIndices;
283 
284  for (const auto& det : geom->detsPXB()) {
285  const PixelGeomDetUnit* pixelDet = dynamic_cast<const PixelGeomDetUnit*>(det);
286  const auto& layer = tTopo->pxbLayer(pixelDet->geographicalId());
287  const auto& module = tTopo->pxbModule(pixelDet->geographicalId());
288  int i_index = module + (layer - 1) * hists_.nModules_[layer - 1];
289 
290  uint32_t rawId = pixelDet->geographicalId().rawId();
291 
292  // if the detId is already accounted for in the special class, do not attach it
293  if (std::find(hists_.BPixnewDetIds_.begin(), hists_.BPixnewDetIds_.end(), rawId) != hists_.BPixnewDetIds_.end())
294  continue;
295  if (std::find(treatedIndices.begin(), treatedIndices.end(), i_index) != treatedIndices.end()) {
296  hists_.detIdsList[i_index].push_back(rawId);
297  } else {
298  hists_.detIdsList.insert(std::pair<uint32_t, std::vector<uint32_t>>(i_index, {rawId}));
299  treatedIndices.push_back(i_index);
300  }
301  }
302 
303  count = 0;
304  for (const auto& i : treatedIndices) {
305  for (const auto& id : hists_.detIdsList[i]) {
306  LogDebug("SiPixelLorentzAnglePCLHarvesterMCS") << id;
307  count++;
308  };
309  }
310  LogDebug("SiPixelLorentzAnglePCLHarvesterMCS") << "Stored a total of " << count << " detIds.";
311 }
312 //------------------------------------------------------------------------------
314  iGetter.cd();
315  iGetter.setCurrentFolder(dqmDir_);
316 
317  // get mean and size-angle hists, book summary hists
318  std::string hname;
321  iBooker.book1D("fpixMeanHistoFitStatus",
322  "fit status by angles/rings/panels/sides; angle/ring/panel/side; fit status",
323  nBins,
324  -0.5,
325  nBins - 0.5);
327  iBooker.book1D("fpixMinClusterSizeCotAngle",
328  "cot angle of minimal cluster size by angles/rings/panels/sides; angle/ring/panel/side; ",
329  nBins,
330  -0.5,
331  nBins - 0.5);
333  iBooker.book1D("fpixNhitsClusterSizeCotAngle",
334  "number of hits by angles/rings/panels/sides; angle/ring/panel/side; ",
335  nBins,
336  -0.5,
337  nBins - 0.5);
338 
339  std::string binNameAlpha;
340  std::string binNameBeta;
341 
342  const auto& prefix_ = fmt::sprintf("%s/FPix", dqmDir_);
343  int histsCounter = 0;
344  int nHistoExpected = 0;
345  for (int r = 0; r < hists_.nRings_; ++r) {
346  for (int p = 0; p < hists_.nPanels_; ++p) {
347  for (int s = 0; s < hists_.nSides_; ++s) {
348  int idx = getIndex(false, r, p, s);
349  int idxBeta = getIndex(true, r, p, s);
350  nHistoExpected++;
351  hname = fmt::format("{}/R{}_P{}_z{}_alphaMean", dqmDir_, r + 1, p + 1, s + 1);
352  if ((hists_.h_fpixMean_[idx] = iGetter.get(hname)) == nullptr) {
353  edm::LogError("SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
354  << "Failed to retrieve " << hname << " histogram";
355  } else
356  histsCounter++;
357 
358  nHistoExpected++;
359  hname = fmt::format("{}/R{}_P{}_z{}_betaMean", dqmDir_, r + 1, p + 1, s + 1);
360  if ((hists_.h_fpixMean_[idxBeta] = iGetter.get(hname)) == nullptr) {
361  edm::LogError("SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
362  << "Failed to retrieve " << hname << " histogram";
363  } else
364  histsCounter++;
365 
366  nHistoExpected++;
367  hname = fmt::format("{}/R{}_P{}_z{}_alpha", prefix_, r + 1, p + 1, s + 1);
368  if ((hists_.h_fpixAngleSize_[idx] = iGetter.get(hname)) == nullptr) {
369  edm::LogError("SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
370  << "Failed to retrieve " << hname << " histogram";
371  } else
372  histsCounter++;
373 
374  nHistoExpected++;
375  hname = fmt::format("{}/R{}_P{}_z{}_beta", prefix_, r + 1, p + 1, s + 1);
376  if ((hists_.h_fpixAngleSize_[idxBeta] = iGetter.get(hname)) == nullptr) {
377  edm::LogError("SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
378  << "Failed to retrieve " << hname << " histogram";
379  } else
380  histsCounter++;
381 
382  for (int m = 0; m < 3; ++m) {
383  nHistoExpected++;
384  hname = fmt::format("{}/R{}_P{}_z{}_B{}", prefix_, r + 1, p + 1, s + 1, m);
385  if ((hists_.h_fpixMagField_[m][idx] = iGetter.get(hname)) == nullptr) {
386  edm::LogError("SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
387  << "Failed to retrieve " << hname << " histogram";
388  } else
389  histsCounter++;
390  }
391 
392  // set labels & init summary histos
393  int binAlpha = idx + 1;
394  int binBeta = idxBeta + 1;
395  char sign = s == 0 ? '-' : '+';
396  binNameAlpha = fmt::sprintf("#alpha: R%d_P%d_z%c", r + 1, p + 1, sign);
397  binNameBeta = fmt::sprintf("#beta:R%d_P%d_z%c", r + 1, p + 1, sign);
398  hists_.h_fpixMeanHistoFitStatus_->setBinLabel(binAlpha, binNameAlpha);
399  hists_.h_fpixMeanHistoFitStatus_->setBinLabel(binBeta, binNameBeta);
402 
403  hists_.h_fpixMinClusterSizeCotAngle_->setBinLabel(binAlpha, binNameAlpha);
404  hists_.h_fpixMinClusterSizeCotAngle_->setBinLabel(binBeta, binNameBeta);
405  hists_.h_fpixNhitsClusterSizeCotAngle_->setBinLabel(binAlpha, binNameAlpha);
406  hists_.h_fpixNhitsClusterSizeCotAngle_->setBinLabel(binBeta, binNameBeta);
407  }
408  }
409  }
410 
411  if (histsCounter != nHistoExpected) {
412  edm::LogError("SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
413  << "Failed to retrieve all histograms, expected 56 got " << histsCounter;
414  return;
415  }
416 
417  // book hervesting hists
418  iBooker.setCurrentFolder(fmt::format("{}Harvesting", dqmDir_));
419  int nBinsMuH = hists_.nRings_ * hists_.nPanels_;
421  "fpixFitStatusMuH", "muH fit status by rings/panels; ring/panel; fitStatus", nBinsMuH, -0.5, nBinsMuH - 0.5);
423  iBooker.book1D("fpixMuH", "muH by rings/panels; ring/panel; #muH [1/T]", nBinsMuH, -0.5, nBinsMuH - 0.5);
424  hists_.h_fpixDeltaMuH_ = iBooker.book1D(
425  "fpixDeltaMuH", "#Delta muH by rings/panels; ring/panel; #Delta #muH [1/T]", nBinsMuH, -0.5, nBinsMuH - 0.5);
426  hists_.h_fpixRelDeltaMuH_ = iBooker.book1D("fpixRelDeltaMuH",
427  "#Delta #muH/#muH by rings/panels; ring/panel; #Delta #muH/#MuH",
428  nBinsMuH,
429  -0.5,
430  nBinsMuH - 0.5);
431  std::string binName;
432  for (int r = 0; r < hists_.nRings_; ++r) {
433  for (int p = 0; p < hists_.nPanels_; ++p) {
434  int idx = r * hists_.nPanels_ + p + 1;
435  binName = fmt::sprintf("R%d_P%d", r + 1, p + 1);
438  hists_.h_fpixMuH_->setBinLabel(idx, binName);
441  }
442  }
443 
444  // make and fit profile hists, fit muH
445  int nSizeBins = hists_.h_fpixAngleSize_[0]->getNbinsY();
446  double minSize = hists_.h_fpixAngleSize_[0]->getAxisMin(2);
447  double maxSize = hists_.h_fpixAngleSize_[0]->getAxisMax(2);
448  TH1D* h_slice = new TH1D("h_slice", "slice of cot_angle histogram", nSizeBins, minSize, maxSize);
449  f1_ = std::make_unique<TF1>("f1", SiPixelLAHarvestMCS::MCSFitFunction, -3., 3., 5);
450  f1_->SetParNames("Offset", "RMS Constant", "SlopeL", "cot(angle)_min", "SlopeR");
451 
452  for (int r = 0; r < hists_.nRings_; ++r) {
453  for (int p = 0; p < hists_.nPanels_; ++p) {
456  for (int s = 0; s < hists_.nSides_; ++s) {
457  int idx = getIndex(false, r, p, s);
458  int idxBeta = getIndex(true, r, p, s);
459  int binAlpha = idx + 1;
460  int binBeta = idxBeta + 1;
461 
462  int entriesAlpha = hists_.h_fpixAngleSize_[idx]->getEntries();
463  int entriesBeta = hists_.h_fpixAngleSize_[idxBeta]->getEntries();
464  hists_.h_fpixNhitsClusterSizeCotAngle_->setBinContent(binAlpha, entriesAlpha);
467  findMean(hists_.h_fpixAngleSize_[idxBeta], hists_.h_fpixMean_[idxBeta], h_slice);
468 
469  SiPixelLAHarvestMCS::fitStatus statusAlphaFit = entriesAlpha < minHitsCut_
472  SiPixelLAHarvestMCS::fitStatus statusBetaFit = entriesBeta < minHitsCut_
474  : fitMCSHistogram(hists_.h_fpixMean_[idxBeta]);
475 
476  hists_.h_fpixMeanHistoFitStatus_->setBinContent(binAlpha, statusAlphaFit);
477  hists_.h_fpixMeanHistoFitStatus_->setBinContent(binBeta, statusBetaFit);
478 
479  if (entriesAlpha < minHitsCut_ || entriesBeta < minHitsCut_)
480  continue;
481 
482  assert(strcmp(f1_->GetName(), "f1") == 0);
483 
484  if (statusAlphaFit == SiPixelLAHarvestMCS::kFitConverged &&
485  statusBetaFit == SiPixelLAHarvestMCS::kFitConverged) {
486  double shiftX = hists_.h_fpixMean_[idx]->getTH1()->GetFunction("f1")->GetParameter(3);
487  double errShiftX = hists_.h_fpixMean_[idx]->getTH1()->GetFunction("f1")->GetParError(3);
488  double shiftY = hists_.h_fpixMean_[idxBeta]->getTH1()->GetFunction("f1")->GetParameter(3);
489  double errShiftY = hists_.h_fpixMean_[idxBeta]->getTH1()->GetFunction("f1")->GetParError(3);
490 
492  hists_.h_fpixMinClusterSizeCotAngle_->setBinError(binAlpha, errShiftX);
494  hists_.h_fpixMinClusterSizeCotAngle_->setBinError(binBeta, errShiftY);
495 
496  fmh.shiftx = shiftX;
497  fmh.shiftx_err = errShiftX;
498  fmh.shifty = shiftY;
499  fmh.shifty_err = errShiftY;
500  fmh.bfield[0] = hists_.h_fpixMagField_[0][idx]->getMean();
501  fmh.bfield[1] = hists_.h_fpixMagField_[1][idx]->getMean();
502  fmh.bfield[2] = hists_.h_fpixMagField_[2][idx]->getMean();
503  fitMuH.add(fmh);
504  } // if fut converged
505  } // loop over z sides
506 
507  if (fitMuH.size() == hists_.nSides_) {
508  std::string fpixPartNames = "R" + std::to_string(r + 1) + "_P" + std::to_string(p + 1);
509  double initMuH = fitParametersInitValuesMuHFitMap_[fpixPartNames];
510  int status = fitMuH.fit(initMuH);
511  int idxMuH = r * hists_.nPanels_ + p + 1;
512  double muH = fitMuH.getMuH();
513  double muHErr = fitMuH.getMuHErr();
515  hists_.h_fpixMuH_->setBinContent(idxMuH, muH);
516  hists_.h_fpixMuH_->setBinError(idxMuH, muHErr);
517  fpixMuHResults.insert(std::make_pair(fpixPartNames, std::make_pair(muH, muH)));
518  }
519  }
520  }
521 
522  std::shared_ptr<SiPixelLorentzAngle> LorentzAngle = std::make_shared<SiPixelLorentzAngle>();
523 
524  bool isPayloadChanged{false};
525 
526  for (const auto& [id, value] : currentLorentzAngle_->getLorentzAngles()) {
527  DetId ID = DetId(id);
528  float muHForDB = value;
529  if (ID.subdetId() == PixelSubdetector::PixelEndcap) {
530  PixelEndcapName pen(ID, tTopo, true); // use det-id phaseq
531  int panel = pen.pannelName();
532  int ring = pen.ringName();
533  std::string fpixPartNames = "R" + std::to_string(ring) + "_P" + std::to_string(panel);
534  if (fpixMuHResults.find(fpixPartNames) != fpixMuHResults.end()) {
535  double measuredMuH = fpixMuHResults[fpixPartNames].first;
536  double deltaMuH = value - measuredMuH;
537  double deltaMuHoverMuH = deltaMuH / value;
538  int idxMuH = (ring - 1) * hists_.nPanels_ + panel;
539  hists_.h_fpixDeltaMuH_->setBinContent(idxMuH, deltaMuH);
540  hists_.h_fpixRelDeltaMuH_->setBinContent(idxMuH, deltaMuHoverMuH);
541  muHForDB = measuredMuH;
542  if (!isPayloadChanged && (deltaMuHoverMuH != 0.f))
543  isPayloadChanged = true;
544  }
545  } // if endcap
546  if (!LorentzAngle->putLorentzAngle(id, muHForDB)) {
547  edm::LogError("SiPixelLorentzAnglePCLHarvesterMCS")
548  << "[SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob]: detid (" << id << ") already exists";
549  }
550  }
551 
552  if (isPayloadChanged) {
553  // fill the DB object record
555  if (mydbservice.isAvailable()) {
556  try {
557  mydbservice->writeOneIOV(*LorentzAngle, mydbservice->currentTime(), recordName_);
558  } catch (const cond::Exception& er) {
559  edm::LogError("SiPixelLorentzAngleDB") << er.what();
560  } catch (const std::exception& er) {
561  edm::LogError("SiPixelLorentzAngleDB") << "caught std::exception " << er.what();
562  }
563  } else {
564  edm::LogError("SiPixelLorentzAngleDB") << "Service is unavailable";
565  }
566  } else {
567  edm::LogPrint("SiPixelLorentzAngleDB") << __PRETTY_FUNCTION__ << " there is no new valid measurement to append! ";
568  }
569 }
570 
571 //------------------------------------------------------------------------------
574  TH1D* h_slice) {
575  int n_x = h_2D->getNbinsX();
576  int n_y = h_2D->getNbinsY();
577 
578  for (int i = 1; i <= n_x; i++) {
579  h_slice->Reset("ICE");
580 
581  //loop over bins in size
582 
583  for (int j = 1; j <= n_y; j++) {
584  h_slice->SetBinContent(j, h_2D->getBinContent(i, j));
585  }
586  double mean = h_slice->GetMean();
587  double error = h_slice->GetMeanError();
588  h_mean->setBinContent(i, mean);
589  h_mean->setBinError(i, error);
590  } // end loop over bins in depth
591 }
592 
593 //------------------------------------------------------------------------------
596 
597  f1_->SetParameters(fitParametersInitValues_[0],
602 
603  int nFits = 0;
604  while (nFits < 5) {
605  nFits++;
606  double fitMin = f1_->GetParameter(3) + theFitRange_.first;
607  double fitMax = f1_->GetParameter(3) + theFitRange_.second;
608 
609  if (fitMin < -3)
610  fitMin = -3;
611  if (fitMax > 3)
612  fitMax = 3;
613 
614  TFitResultPtr r = h_mean->getTH1()->Fit(f1_.get(), "ERSM", "", fitMin, fitMax);
615  retVal = r == -1 ? SiPixelLAHarvestMCS::kNoFitResult
618  }
619  return retVal;
620 }
621 
622 //------------------------------------------------------------------------------
625  desc.setComment("Harvester module of the SiPixel Lorentz Angle PCL monitoring workflow for MinimalClusterSizeMethod");
626  desc.add<std::string>("dqmDir", "AlCaReco/SiPixelLorentzAngle")->setComment("the directory of PCL Worker output");
627  desc.add<std::vector<std::string>>("newmodulelist", {})->setComment("the list of DetIds for new sensors");
628  desc.add<std::vector<double>>("fitRange", {-1.5, 1.5})->setComment("range to perform the fit");
629  desc.add<std::vector<double>>("fitParameters", {1., 0.1, -1.6, 0., 1.6})
630  ->setComment("initial values for fit parameters");
631  desc.add<std::vector<double>>("fitParametersMuHFit", {0.08, 0.08, 0.08, 0.08})
632  ->setComment("initial values for fit parameters (muH fit)");
633  desc.add<int>("minHitsCut", 1000)->setComment("cut on minimum number of on-track hits to accept measurement");
634  desc.add<std::string>("record", "SiPixelLorentzAngleRcdMCS")->setComment("target DB record");
635  descriptions.addWithDefaultLabel(desc);
636 }
637 
638 int SiPixelLorentzAnglePCLHarvesterMCS::getIndex(bool isBetaAngle, int r, int p, int s) {
639  int idx = hists_.nSides_ * hists_.nPanels_ * r + hists_.nSides_ * p + s;
640  return (isBetaAngle ? idx + hists_.betaStartIdx_ : idx);
641 }
Definition: BitonicSort.h:7
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
unsigned int pxbLayer(const DetId &id) const
Base exception class for the object to relational access.
Definition: Exception.h:11
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
int ringName() const
ring Id
void fcn_func(Int_t &npar, Double_t *deriv, Double_t &f, Double_t *par, Int_t flag)
FitParametersInitValuesMuHFitMap fitParametersInitValuesMuHFitMap_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void beginRun(const edm::Run &, const edm::EventSetup &) override
int bladeName() const
blade id
int moduleName() const
module id (index in z)
uint32_t ID
Definition: Definitions.h:24
int getIndex(bool isBetaAngle, int r, int p, int s)
std::unordered_map< std::string, std::pair< double, double > > FpixMuHResults
std::string to_string(const V &value)
Definition: OMSAccess.h:77
~SiPixelLorentzAnglePCLHarvesterMCS() override=default
const std::map< unsigned int, float > & getLorentzAngles() const
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
A arg
Definition: Factorize.h:31
void findMean(dqm::reco::MonitorElement *h_2D, dqm::reco::MonitorElement *h_mean, TH1D *h_slice)
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomEsToken_
int diskName() const
disk id
T sqrt(T t)
Definition: SSEVec.h:19
std::unordered_map< uint32_t, std::vector< uint32_t > > detIdsList
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Transition
Definition: Transition.h:12
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Definition: value.py:1
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
Log< level::Warning, true > LogPrint
virtual int getNbinsY() const
get # of bins in Y-axis
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenBR_
PXFDetId getDetId()
return DetId
Definition: DetId.h:17
~FitFPixMuH() override=default
friend void fcn_func(Int_t &npar, Double_t *deriv, Double_t &f, Double_t *par, Int_t flag)
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int layerName() const
layer id
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
Double_t MCSFitFunction(Double_t *x, Double_t *par)
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
SiPixelLAHarvestMCS::fitStatus fitMCSHistogram(dqm::reco::MonitorElement *h_mean)
const edm::ESGetToken< SiPixelLorentzAngle, SiPixelLorentzAngleRcd > siPixelLAEsToken_
HLT enums.
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenER_
float x
virtual int getNbinsX() const
get # of bins in X-axis
static void fillDescriptions(edm::ConfigurationDescriptions &)
bool isAvailable() const
Definition: Service.h:40
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
virtual void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
std::unordered_map< uint32_t, std::pair< double, double > > FPixCotAngleFitResults
unsigned int pxbModule(const DetId &id) const
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
char const * what() const noexcept override
Definition: Exception.cc:103
PXBDetId getDetId()
return the DetId
int pannelName() const
pannel id
SiPixelLorentzAngleCalibrationHistograms hists_
Definition: Run.h:45
#define LogDebug(id)
virtual double getBinContent(int binx) const
get content of bin (1-D)
std::unordered_map< std::string, double > FitParametersInitValuesMuHFitMap