19 #include <fmt/format.h> 20 #include <fmt/printf.h> 122 dqmDir_(iConfig.getParameter<
std::
string>(
"dqmDir")),
123 fitChi2Cut_(iConfig.getParameter<double>(
"fitChi2Cut")),
124 minHitsCut_(iConfig.getParameter<
int>(
"minHitsCut")),
125 recordName_(iConfig.getParameter<
std::
string>(
"record")) {
129 throw cms::Exception(
"SiPixelLorentzAnglePCLHarvester") <<
"PoolDBService required";
164 if (modulename.find(
"BPix_") != std::string::npos) {
166 const auto& detId = bn.
getDetId(tTopo);
171 }
else if (modulename.find(
"FPix_") != std::string::npos) {
173 const auto& detId = en.
getDetId(tTopo);
184 LogDebug(
"SiPixelLorentzAnglePCLHarvester") <<
id;
187 LogDebug(
"SiPixelLorentzAnglePCLHarvester") <<
"Stored a total of " <<
count <<
" new detIds.";
193 std::vector<uint32_t> treatedIndices;
195 for (
auto det :
geom->detsPXB()) {
208 if (
std::find(treatedIndices.begin(), treatedIndices.end(), i_index) != treatedIndices.end()) {
211 hists_.
detIdsList.insert(std::pair<uint32_t, std::vector<uint32_t>>(i_index, {rawId}));
212 treatedIndices.push_back(i_index);
217 for (
const auto&
i : treatedIndices) {
219 LogDebug(
"SiPixelLorentzAnglePCLHarvester") <<
id;
223 LogDebug(
"SiPixelLorentzAnglePCLHarvester") <<
"Stored a total of " <<
count <<
" detIds.";
240 for (
int i_layer = 1; i_layer <=
hists_.
nlay; i_layer++) {
241 const auto& prefix_ = fmt::sprintf(
"%s/BPix/BPixLayer%i",
dqmDir_, i_layer);
242 for (
int i_module = 1; i_module <=
hists_.
nModules_[i_layer - 1]; i_module++) {
243 int i_index = i_module + (i_layer - 1) *
hists_.
nModules_[i_layer - 1];
246 iGetter.
get(
fmt::format(
"{}/h_drift_depth_layer{}_module{}", prefix_, i_layer, i_module));
250 <<
"Failed to retrieve electron drift over depth for layer " << i_layer <<
", module " << i_module <<
".";
255 iGetter.
get(
fmt::format(
"{}/h_drift_depth_adc_layer{}_module{}", prefix_, i_layer, i_module));
258 iGetter.
get(
fmt::format(
"{}/h_drift_depth_adc2_layer{}_module{}", prefix_, i_layer, i_module));
261 iGetter.
get(
fmt::format(
"{}/h_drift_depth_noadc_layer{}_module{}", prefix_, i_layer, i_module));
300 edm::LogError(
"SiPixelLorentzAnglePCLHarvester") <<
"Failed to retrieve the hit on track occupancy.";
323 iBooker.
book1D(
"h_drift_depth_adc_slice",
"slice of adc histogram", hist_drift_, min_drift_, max_drift_);
327 "h_diffLA",
"difference in #mu_{H}; #Delta #mu_{H}/#mu_{H} (old-new)/old [%];n. modules", 100, -150, 150);
331 const double lo = -0.5;
332 const double hi = maxSect - 0.5;
336 std::string repText =
"%s tan#theta_{LA}/B by sector;pixel sector;%s tan(#theta_{LA})/B [1/T]";
338 iBooker.
book1D(
"h_LAbySector_Measured", fmt::sprintf(repText,
"measured",
"measured"), maxSect, lo,
hi);
340 iBooker.
book1D(
"h_LAbySector_Accepted", fmt::sprintf(repText,
"accepted",
"accepted"), maxSect, lo,
hi);
342 iBooker.
book1D(
"h_LAbySector_Rejected", fmt::sprintf(repText,
"rejected",
"rejected"), maxSect, lo,
hi);
345 iBooker.
book1D(
"h_deltaLAbySector", fmt::sprintf(repText,
"#Delta",
"#Delta"), maxSect, lo,
hi);
347 iBooker.
book1D(
"h_bySectorChi2",
"Fit #chi^{2}/ndf by sector;pixel sector; fit #chi^{2}/ndf", maxSect, lo,
hi);
350 for (
int bin = 1;
bin <= maxSect;
bin++) {
364 std::string repText =
"BPix Layer %i tan#theta_{LA}/B;module number;ladder number;tan#theta_{LA}/B [1/T]";
367 fmt::sprintf(repText,
i + 1),
375 repName =
"h2_byLayerDiff_%i";
376 repText =
"BPix Layer %i #Delta#mu_{H}/#mu_{H};module number;ladder number;#Delta#mu_{H}/#mu_{H} [%%]";
378 fmt::sprintf(repText,
i + 1),
388 edm::LogPrint(
"LorentzAngle") <<
"module" <<
"\t" <<
"layer" <<
"\t" 389 <<
"offset" <<
"\t" <<
"e0" <<
"\t" 390 <<
"slope" <<
"\t" <<
"e1" <<
"\t" 391 <<
"rel.err" <<
"\t" <<
"pull" <<
"\t" 392 <<
"p2" <<
"\t" <<
"e2" <<
"\t" 393 <<
"p3" <<
"\t" <<
"e3" <<
"\t" 394 <<
"p4" <<
"\t" <<
"e4" <<
"\t" 395 <<
"p5" <<
"\t" <<
"e5" <<
"\t" 396 <<
"chi2" <<
"\t" <<
"prob" <<
"\t" 397 <<
"newDetId" <<
"\t" <<
"tan(LA)" <<
"\t" 402 std::shared_ptr<SiPixelLorentzAngle>
LorentzAngle = std::make_shared<SiPixelLorentzAngle>();
405 double p1_simul_newmodule = 0.294044;
407 for (
int i_layer = 1; i_layer <=
hists_.
nlay; i_layer++) {
408 for (
int i_module = 1; i_module <=
hists_.
nModules_[i_layer - 1]; i_module++) {
410 p1_simul[i_layer - 1][i_module - 1] = 0.436848;
411 else if (i_layer == 2)
412 p1_simul[i_layer - 1][i_module - 1] = 0.25802;
413 else if (i_layer == 3 && i_module <= 4)
414 p1_simul[i_layer - 1][i_module - 1] = 0.29374;
415 else if (i_layer == 3 && i_module >= 5)
416 p1_simul[i_layer - 1][i_module - 1] = 0.31084;
417 else if (i_layer == 4 && i_module <= 4)
418 p1_simul[i_layer - 1][i_module - 1] = 0.29944;
420 p1_simul[i_layer - 1][i_module - 1] = 0.31426;
425 p1_simul[
hists_.
nlay][i_module - 1] = p1_simul_newmodule;
434 for (
int i = 1;
i <= hist_depth_;
i++) {
435 findMean(h_drift_depth_adc_slice_,
i, new_index);
443 <<
res.p1 << std::setprecision(3) <<
"\t" <<
res.e1 <<
"\t" 444 <<
res.e1 /
res.p1 * 100. <<
"\t" 446 <<
res.e2 <<
"\t" <<
res.p3 <<
"\t" <<
res.e3 <<
"\t" <<
res.p4 <<
"\t" 447 <<
res.e4 <<
"\t" <<
res.p5 <<
"\t" <<
res.e5 <<
"\t" <<
res.chi2 <<
"\t" 453 for (
int i_layer = 1; i_layer <=
hists_.
nlay; i_layer++) {
454 for (
int i_module = 1; i_module <=
hists_.
nModules_[i_layer - 1]; i_module++) {
455 int i_index = i_module + (i_layer - 1) *
hists_.
nModules_[i_layer - 1];
459 for (
int i = 1;
i <= hist_depth_;
i++) {
460 findMean(h_drift_depth_adc_slice_,
i, i_index);
467 << std::setprecision(4) << i_module <<
"\t" << i_layer <<
"\t" <<
res.p0 <<
"\t" <<
res.e0 <<
"\t" <<
res.p1
468 << std::setprecision(3) <<
"\t" <<
res.e1 <<
"\t" <<
res.e1 /
res.p1 * 100. <<
"\t" 469 << (
res.p1 - p1_simul[i_layer - 1][i_module - 1]) /
res.e1 <<
"\t" <<
res.p2 <<
"\t" <<
res.e2 <<
"\t" 470 <<
res.p3 <<
"\t" <<
res.e3 <<
"\t" <<
res.p4 <<
"\t" <<
res.e4 <<
"\t" <<
res.p5 <<
"\t" <<
res.e5 <<
"\t" 471 <<
res.chi2 <<
"\t" <<
res.prob <<
"\t" 473 <<
"\t" <<
res.tan_LA <<
"\t" <<
res.error_LA;
479 const auto& newLAMap =
LorentzAngle->getLorentzAngles();
480 std::vector<unsigned int> currentLADets;
481 std::vector<unsigned int> newLADets;
485 std::back_inserter(currentLADets),
490 std::back_inserter(newLADets),
493 std::vector<unsigned int> notCommon;
494 std::set_symmetric_difference(
495 currentLADets.begin(), currentLADets.end(), newLADets.begin(), newLADets.end(), std::back_inserter(notCommon));
497 for (
const auto&
id : notCommon) {
499 if (!
LorentzAngle->putLorentzAngle(
id, fPixLorentzAnglePerTesla_)) {
501 <<
"[SiPixelLorentzAnglePCLHarvester::dqmEndJob] filling rest of payload: detid already exists";
505 for (
const auto&
id : newLADets) {
508 h_diffLA->
Fill(deltaMuHoverMuH * 100.
f);
511 bool isPayloadChanged{
false};
521 float deltaMuHoverMuH =
525 if (!isPayloadChanged && (deltaMuHoverMuH != 0.
f))
526 isPayloadChanged =
true;
530 if (isPayloadChanged) {
539 edm::LogError(
"SiPixelLorentzAngleDB") <<
"caught std::exception " << er.what();
542 edm::LogError(
"SiPixelLorentzAngleDB") <<
"Service is unavailable";
545 edm::LogPrint(
"SiPixelLorentzAngleDB") << __PRETTY_FUNCTION__ <<
" there is no new valid measurement to append! ";
552 h_drift_depth_adc_slice_->
Reset();
553 int hist_drift_ = h_drift_depth_adc_slice_->
getNbinsX();
557 for (
int j = 1;
j <= hist_drift_;
j++) {
577 double mean = h_drift_depth_adc_slice_->
getMean(1);
585 h_drift_depth_adc_slice_->
Reset();
590 std::shared_ptr<SiPixelLorentzAngle> theLAPayload,
int i_index,
int i_layer,
int i_module) {
594 double half_width =
width_ * 10000 / 2;
596 f1_ = std::make_unique<TF1>(
"f1",
"[0] + [1]*x + [2]*x*x + [3]*x*x*x + [4]*x*x*x*x + [5]*x*x*x*x*x", 5., 280.);
597 f1_->SetParName(0,
"offset");
598 f1_->SetParName(1,
"tan#theta_{LA}");
599 f1_->SetParName(2,
"quad term");
600 f1_->SetParName(3,
"cubic term");
601 f1_->SetParName(4,
"quartic term");
602 f1_->SetParName(5,
"quintic term");
604 f1_->SetParameter(0, 0);
605 f1_->SetParError(0, 0);
606 f1_->SetParameter(1, 0.4);
607 f1_->SetParError(1, 0);
608 f1_->SetParameter(2, 0.0);
609 f1_->SetParError(2, 0);
610 f1_->SetParameter(3, 0.0);
611 f1_->SetParError(3, 0);
612 f1_->SetParameter(4, 0.0);
613 f1_->SetParError(4, 0);
614 f1_->SetParameter(5, 0.0);
615 f1_->SetParError(5, 0);
616 f1_->SetChisquare(0);
620 res.p0 =
f1_->GetParameter(0);
621 res.e0 =
f1_->GetParError(0);
622 res.p1 =
f1_->GetParameter(1);
623 res.e1 =
f1_->GetParError(1);
624 res.p2 =
f1_->GetParameter(2);
625 res.e2 =
f1_->GetParError(2);
626 res.p3 =
f1_->GetParameter(3);
627 res.e3 =
f1_->GetParError(3);
628 res.p4 =
f1_->GetParameter(4);
629 res.e4 =
f1_->GetParError(4);
630 res.p5 =
f1_->GetParameter(5);
631 res.e5 =
f1_->GetParError(5);
632 res.chi2 =
f1_->GetChisquare();
634 res.prob =
f1_->GetProb();
637 double f1_halfwidth =
res.p0 +
res.p1 * half_width +
res.p2 *
pow(half_width, 2) +
res.p3 *
pow(half_width, 3) +
638 res.p4 *
pow(half_width, 4) +
res.p5 *
pow(half_width, 5);
640 double f1_zerowidth =
res.p0;
643 res.tan_LA = (f1_halfwidth - f1_zerowidth) / half_width;
645 (
pow(
res.e1, 2) +
pow((half_width *
res.e2), 2) +
pow((half_width * half_width *
res.e3), 2) +
646 pow((half_width * half_width * half_width *
res.e4), 2) +
647 pow((half_width * half_width * half_width * half_width *
res.e5), 2));
660 LogDebug(
"SiPixelLorentzAnglePCLHarvester")
661 <<
" isNew: " << isNew <<
" i_index: " << i_index <<
" shift index: " << shiftIdx;
663 const auto& detIdsToFill =
666 LogDebug(
"SiPixelLorentzAnglePCLHarvester")
667 <<
"index: " << i_index <<
" i_module: " << i_module <<
" i_layer: " << i_layer;
668 for (
const auto&
id : detIdsToFill) {
669 LogDebug(
"SiPixelLorentzAnglePCLHarvester") <<
id <<
",";
678 float LorentzAnglePerTesla_;
688 const auto& deltaLA = (LorentzAnglePerTesla_ - currentLA);
691 for (
const auto&
id : detIdsToFill) {
692 if (!theLAPayload->putLorentzAngle(
id, LorentzAnglePerTesla_)) {
693 edm::LogError(
"SiPixelLorentzAnglePCLHarvester") <<
"[SiPixelLorentzAnglePCLHarvester::fitAndStore]: detid (" 694 << i_layer <<
"," << i_module <<
") already exists";
704 for (
const auto&
id : detIdsToFill) {
706 if (!theLAPayload->putLorentzAngle(
id, LorentzAnglePerTesla_)) {
707 edm::LogError(
"SiPixelLorentzAnglePCLHarvester") <<
"[SiPixelLorentzAnglePCLHarvester::fitAndStore]: detid (" 708 << i_layer <<
"," << i_module <<
") already exists";
719 desc.setComment(
"Harvester module of the SiPixel Lorentz Angle PCL monitoring workflow");
720 desc.add<std::vector<std::string>>(
"newmodulelist", {})->setComment(
"the list of DetIds for new sensors");
721 desc.add<
std::string>(
"dqmDir",
"AlCaReco/SiPixelLorentzAngle")->setComment(
"the directory of PCL Worker output");
722 desc.add<
double>(
"fitChi2Cut", 20.)->setComment(
"cut on fit chi2/ndof to accept measurement");
723 desc.add<
int>(
"minHitsCut", 10000)->setComment(
"cut on minimum number of on-track hits to accept measurement");
724 desc.add<
std::string>(
"record",
"SiPixelLorentzAngleRcd")->setComment(
"target DB record");
std::vector< dqm::reco::MonitorElement * > h2_byLayerLA_
std::vector< int > BPixnewModule_
dqm::reco::MonitorElement * h_bySectSetLA_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
dqm::reco::MonitorElement * h_bySectLA_
unsigned int pxbLayer(const DetId &id) const
Base exception class for the object to relational access.
virtual void setCurrentFolder(std::string const &fullpath)
const SiPixelLorentzAngle * currentLorentzAngle_
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< int > nLadders_
std::vector< std::string > FPixnewmodulename_
#define DEFINE_FWK_MODULE(type)
int bladeName() const
blade id
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenBR_
int moduleName() const
module id (index in z)
void findMean(MonitorElement *h_drift_depth_adc_slice_, int i, int i_ring)
SiPixelLorentzAnglePCLHarvester(const edm::ParameterSet &)
SiPixelLAHarvest::fitResults fitAndStore(std::shared_ptr< SiPixelLorentzAngle > theLA, int i_idx, int i_lay, int i_mod)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenER_
const std::string dqmDir_
const std::map< unsigned int, float > & getLorentzAngles() const
std::vector< int > nModules_
Log< level::Error, false > LogError
MonitorMap h_drift_depth_
static void fillDescriptions(edm::ConfigurationDescriptions &)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::unique_ptr< TF1 > f1_
std::unique_ptr< TrackerTopology > theTrackerTopology_
std::vector< int > FPixnewDetIds_
std::vector< unsigned int > BPixnewDetIds_
constexpr std::array< uint8_t, layerIndexSize > layer
float inverseBzAtOriginInGeV() const
The inverse of field z component for this map in GeV.
MonitorMap h_drift_depth_noadc_
virtual float thickness() const =0
~SiPixelLorentzAnglePCLHarvester() override=default
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
dqm::reco::MonitorElement * h_bySectChi2_
edm::ESGetToken< SiPixelLorentzAngle, SiPixelLorentzAngleRcd > siPixelLAEsToken_
virtual double getRMS(int axis=1) const
get RMS of histogram along x, y or z axis (axis=1, 2, 3 respectively)
Container::value_type value_type
cond::Time_t currentTime() const
int diskName() const
disk id
std::unordered_map< uint32_t, std::vector< uint32_t > > detIdsList
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomEsToken_
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
dqm::reco::MonitorElement * h_bySectOccupancy_
bool getData(T &iHolder) const
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
SiPixelLorentzAngleCalibrationHistograms hists_
PXFDetId getDetId()
return DetId
const Plane & surface() const
The nominal surface of the GeomDet.
const std::string recordName_
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
constexpr uint32_t rawId() const
get the raw id
dqm::reco::MonitorElement * h_bySectMeasLA_
int layerName() const
layer id
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
static constexpr float inverseGeVtoTesla_
MonitorMap h_drift_depth_adc_
virtual MonitorElement * get(std::string const &fullpath) const
std::vector< int > FPixnewBlade_
MonitorMap h_drift_depth_adc2_
virtual double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
virtual int getNbinsX() const
get # of bins in X-axis
std::vector< std::string > BPixnewmodulename_
dqm::reco::MonitorElement * h_bySectRejectLA_
virtual void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
dqm::reco::MonitorElement * h_bySectDeltaLA_
std::vector< int > FPixnewDisk_
std::vector< int > BPixnewLayer_
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())
char const * what() const noexcept override
float getLorentzAngle(const uint32_t &) const
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
PXBDetId getDetId()
return the DetId
std::vector< dqm::reco::MonitorElement * > h2_byLayerDiff_
std::vector< std::string > newmodulelist_
Power< A, B >::type pow(const A &a, const B &b)
void endRun(const edm::Run &, const edm::EventSetup &) override
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
virtual double getBinContent(int binx) const
get content of bin (1-D)
const Bounds & bounds() const