23 #include <fmt/format.h> 24 #include <fmt/printf.h> 47 #include "TFitResult.h" 48 #include "TVirtualFitter.h" 59 arg = par[1] * par[1] + par[2] * par[2] * (
x[0] - par[3]) * (
x[0] - par[3]);
61 arg = par[1] * par[1] + par[4] * par[4] * (
x[0] - par[3]) * (
x[0] - par[3]);
63 Double_t fitval = par[0] +
sqrt(
arg);
75 void fcn_func(Int_t& npar, Double_t* deriv, Double_t&
f, Double_t* par, Int_t
flag);
84 friend void fcn_func(Int_t& npar, Double_t* deriv, Double_t&
f, Double_t* par, Int_t
flag);
87 int fit(
double initVal) {
90 double tanlorpertesla = initVal;
91 minuit->SetParameter(0,
"muH", tanlorpertesla, 0.1, 0., 0.);
95 minuit->ExecuteCommand(
"SET PRINT", arglist, 0);
99 int status =
minuit->ExecuteCommand(
"MIGRAD", arglist, 0);
117 double tanlorpertesla = par_0;
118 double tlpt2 = tanlorpertesla * tanlorpertesla;
119 double v[3], xshift, yshift;
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]);
129 xshift =
v[0] /
v[2];
130 yshift =
v[1] /
v[2];
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]));
150 using FpixMuHResults = std::unordered_map<std::string, std::pair<double, double>>;
160 int getIndex(
bool isBetaAngle,
int r,
int p,
int s);
194 dqmDir_(iConfig.getParameter<
std::
string>(
"dqmDir")),
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")) {
207 throw cms::Exception(
"SiPixelLorentzAnglePCLHarvesterMCS") <<
"Wrong number of fit range parameters specified";
212 <<
"Wrong number of initial values for fit parameters specified";
217 <<
"Wrong number of initial values for fit parameters specified";
228 throw cms::Exception(
"SiPixelLorentzAnglePCLHarvesterMCS") <<
"PoolDBService required";
253 if (modulename.find(
"BPix_") != std::string::npos) {
260 }
else if (modulename.find(
"FPix_") != std::string::npos) {
273 LogDebug(
"SiPixelLorentzAnglePCLHarvesterMCS") <<
id;
276 LogDebug(
"SiPixelLorentzAnglePCLHarvesterMCS") <<
"Stored a total of " <<
count <<
" new detIds.";
282 std::vector<uint32_t> treatedIndices;
284 for (
const auto& det :
geom->detsPXB()) {
295 if (
std::find(treatedIndices.begin(), treatedIndices.end(), i_index) != treatedIndices.end()) {
298 hists_.
detIdsList.insert(std::pair<uint32_t, std::vector<uint32_t>>(i_index, {rawId}));
299 treatedIndices.push_back(i_index);
304 for (
const auto&
i : treatedIndices) {
306 LogDebug(
"SiPixelLorentzAnglePCLHarvesterMCS") <<
id;
310 LogDebug(
"SiPixelLorentzAnglePCLHarvesterMCS") <<
"Stored a total of " <<
count <<
" detIds.";
321 iBooker.
book1D(
"fpixMeanHistoFitStatus",
322 "fit status by angles/rings/panels/sides; angle/ring/panel/side; fit status",
327 iBooker.
book1D(
"fpixMinClusterSizeCotAngle",
328 "cot angle of minimal cluster size by angles/rings/panels/sides; angle/ring/panel/side; ",
333 iBooker.
book1D(
"fpixNhitsClusterSizeCotAngle",
334 "number of hits by angles/rings/panels/sides; angle/ring/panel/side; ",
342 const auto& prefix_ = fmt::sprintf(
"%s/FPix",
dqmDir_);
343 int histsCounter = 0;
344 int nHistoExpected = 0;
353 edm::LogError(
"SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
354 <<
"Failed to retrieve " << hname <<
" histogram";
361 edm::LogError(
"SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
362 <<
"Failed to retrieve " << hname <<
" histogram";
367 hname =
fmt::format(
"{}/R{}_P{}_z{}_alpha", prefix_,
r + 1,
p + 1,
s + 1);
369 edm::LogError(
"SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
370 <<
"Failed to retrieve " << hname <<
" histogram";
375 hname =
fmt::format(
"{}/R{}_P{}_z{}_beta", prefix_,
r + 1,
p + 1,
s + 1);
377 edm::LogError(
"SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
378 <<
"Failed to retrieve " << hname <<
" histogram";
382 for (
int m = 0;
m < 3; ++
m) {
384 hname =
fmt::format(
"{}/R{}_P{}_z{}_B{}", prefix_,
r + 1,
p + 1,
s + 1,
m);
386 edm::LogError(
"SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
387 <<
"Failed to retrieve " << hname <<
" histogram";
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);
411 if (histsCounter != nHistoExpected) {
412 edm::LogError(
"SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob")
413 <<
"Failed to retrieve all histograms, expected 56 got " << histsCounter;
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);
425 "fpixDeltaMuH",
"#Delta muH by rings/panels; ring/panel; #Delta #muH [1/T]", nBinsMuH, -0.5, nBinsMuH - 0.5);
427 "#Delta #muH/#muH by rings/panels; ring/panel; #Delta #muH/#MuH",
435 binName = fmt::sprintf(
"R%d_P%d",
r + 1,
p + 1);
448 TH1D* h_slice =
new TH1D(
"h_slice",
"slice of cot_angle histogram", nSizeBins, minSize,
maxSize);
450 f1_->SetParNames(
"Offset",
"RMS Constant",
"SlopeL",
"cot(angle)_min",
"SlopeR");
459 int binAlpha =
idx + 1;
460 int binBeta = idxBeta + 1;
482 assert(strcmp(
f1_->GetName(),
"f1") == 0);
488 double shiftY =
hists_.
h_fpixMean_[idxBeta]->getTH1()->GetFunction(
"f1")->GetParameter(3);
489 double errShiftY =
hists_.
h_fpixMean_[idxBeta]->getTH1()->GetFunction(
"f1")->GetParError(3);
512 double muH = fitMuH.
getMuH();
517 fpixMuHResults.insert(std::make_pair(fpixPartNames, std::make_pair(muH, muH)));
522 std::shared_ptr<SiPixelLorentzAngle>
LorentzAngle = std::make_shared<SiPixelLorentzAngle>();
524 bool isPayloadChanged{
false};
528 float muHForDB =
value;
536 double deltaMuH =
value - measuredMuH;
537 double deltaMuHoverMuH = deltaMuH /
value;
541 muHForDB = measuredMuH;
542 if (!isPayloadChanged && (deltaMuHoverMuH != 0.
f))
543 isPayloadChanged =
true;
548 <<
"[SiPixelLorentzAnglePCLHarvesterMCS::dqmEndJob]: detid (" <<
id <<
") already exists";
552 if (isPayloadChanged) {
561 edm::LogError(
"SiPixelLorentzAngleDB") <<
"caught std::exception " << er.what();
564 edm::LogError(
"SiPixelLorentzAngleDB") <<
"Service is unavailable";
567 edm::LogPrint(
"SiPixelLorentzAngleDB") << __PRETTY_FUNCTION__ <<
" there is no new valid measurement to append! ";
578 for (
int i = 1;
i <= n_x;
i++) {
579 h_slice->Reset(
"ICE");
583 for (
int j = 1;
j <= n_y;
j++) {
586 double mean = h_slice->GetMean();
587 double error = h_slice->GetMeanError();
614 TFitResultPtr
r = h_mean->
getTH1()->Fit(
f1_.get(),
"ERSM",
"", fitMin, fitMax);
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");
dqm::reco::MonitorElement * h_fpixDeltaMuH_
std::vector< int > BPixnewModule_
const std::string recordName_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
unsigned int pxbLayer(const DetId &id) const
Base exception class for the object to relational access.
dqm::reco::MonitorElement * h_fpixRelDeltaMuH_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
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)
void beginRun(const edm::Run &, const edm::EventSetup &) override
const TrackerTopology * tTopo
std::vector< int > nLadders_
std::vector< std::string > FPixnewmodulename_
MonitorMap h_fpixAngleSize_
int bladeName() const
blade id
int moduleName() const
module id (index in z)
std::pair< double, double > theFitRange_
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)
~SiPixelLorentzAnglePCLHarvesterMCS() override=default
const std::map< unsigned int, float > & getLorentzAngles() const
std::vector< int > nModules_
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< FPixMuH > cmvar
void findMean(dqm::reco::MonitorElement *h_2D, dqm::reco::MonitorElement *h_mean, TH1D *h_slice)
std::vector< int > FPixnewDetIds_
std::vector< unsigned int > BPixnewDetIds_
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
double calcChi2(double par_0)
std::unique_ptr< TF1 > f1_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomEsToken_
cond::Time_t currentTime() const
int diskName() const
disk id
std::unordered_map< uint32_t, std::vector< uint32_t > > detIdsList
dqm::reco::MonitorElement * h_fpixMuH_
dqm::reco::MonitorElement * h_fpixNhitsClusterSizeCotAngle_
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
static constexpr int nAngles_
#define DEFINE_FWK_MODULE(type)
dqm::reco::MonitorElement * h_fpixMeanHistoFitStatus_
FpixMuHResults fpixMuHResults
static constexpr int nRings_
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.
Log< level::Warning, true > LogPrint
const std::vector< double > fitRange_
SiPixelLorentzAnglePCLHarvesterMCS(const edm::ParameterSet &)
virtual int getNbinsY() const
get # of bins in Y-axis
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenBR_
const SiPixelLorentzAngle * currentLorentzAngle_
PXFDetId getDetId()
return DetId
const std::string dqmDir_
~FitFPixMuH() override=default
friend void fcn_func(Int_t &npar, Double_t *deriv, Double_t &f, Double_t *par, Int_t flag)
std::vector< std::string > newmodulelist_
static constexpr int nPanels_
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
dqm::reco::MonitorElement * h_fpixFitStatusMuH_
constexpr uint32_t rawId() const
get the raw id
int layerName() const
layer id
static constexpr int betaStartIdx_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
Double_t MCSFitFunction(Double_t *x, Double_t *par)
virtual MonitorElement * get(std::string const &fullpath) const
std::vector< int > FPixnewBlade_
const std::vector< double > fitParametersInitValuesMuHFit_
SiPixelLAHarvestMCS::fitStatus fitMCSHistogram(dqm::reco::MonitorElement *h_mean)
const edm::ESGetToken< SiPixelLorentzAngle, SiPixelLorentzAngleRcd > siPixelLAEsToken_
static constexpr int nSides_
const std::vector< double > fitParametersInitValues_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenER_
MonitorMap h_fpixMagField_[3]
virtual int getNbinsX() const
get # of bins in X-axis
static void fillDescriptions(edm::ConfigurationDescriptions &)
std::vector< std::string > BPixnewmodulename_
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
std::vector< int > FPixnewDisk_
std::vector< int > BPixnewLayer_
unsigned int pxbModule(const DetId &id) const
dqm::reco::MonitorElement * h_fpixMinClusterSizeCotAngle_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
char const * what() const noexcept override
PXBDetId getDetId()
return the DetId
void add(const FPixMuH &fmh)
int pannelName() const
pannel id
SiPixelLorentzAngleCalibrationHistograms hists_
virtual double getBinContent(int binx) const
get content of bin (1-D)
std::unordered_map< std::string, double > FitParametersInitValuesMuHFitMap