Skip to content

Commit

Permalink
add output LorentzAngle maps to SiPixelLorentzAnglePCLHarvester
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed Feb 2, 2022
1 parent 65d1df2 commit 507cc26
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Expand Up @@ -12,6 +12,7 @@ struct SiPixelLorentzAngleCalibrationHistograms {

int nlay;
std::vector<int> nModules_;
std::vector<int> nLadders_;
std::vector<std::string> BPixnewmodulename_;
std::vector<unsigned int> BPixnewDetIds_;
std::vector<int> BPixnewModule_;
Expand Down Expand Up @@ -43,6 +44,9 @@ struct SiPixelLorentzAngleCalibrationHistograms {
dqm::reco::MonitorElement* h_bySectLA_;
dqm::reco::MonitorElement* h_bySectDeltaLA_;
dqm::reco::MonitorElement* h_bySectChi2_;

// ouput LA maps
std::vector<dqm::reco::MonitorElement*> h2_byLayerLA_;
};

#endif
Expand Up @@ -85,12 +85,13 @@ class SiPixelLorentzAnglePCLHarvester : public DQMEDHarvester {

private:
void dqmEndJob(DQMStore::IBooker&, DQMStore::IGetter&) override;
void endRun(const edm::Run&, const edm::EventSetup&) override;
void findMean(MonitorElement* h_drift_depth_adc_slice_, int i, int i_ring);
SiPixelLAHarvest::fitResults fitAndStore(std::shared_ptr<SiPixelLorentzAngle> theLA, int i_idx, int i_lay, int i_mod);

// es tokens
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomEsToken_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoEsToken_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoEsTokenBR_, topoEsTokenER_;
edm::ESGetToken<SiPixelLorentzAngle, SiPixelLorentzAngleRcd> siPixelLAEsToken_;
edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magneticFieldToken_;

Expand All @@ -105,12 +106,14 @@ class SiPixelLorentzAnglePCLHarvester : public DQMEDHarvester {
SiPixelLorentzAngleCalibrationHistograms hists;
const SiPixelLorentzAngle* currentLorentzAngle;
const MagneticField* magField;
std::unique_ptr<TrackerTopology> theTrackerTopology;
};

//------------------------------------------------------------------------------
SiPixelLorentzAnglePCLHarvester::SiPixelLorentzAnglePCLHarvester(const edm::ParameterSet& iConfig)
: geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
topoEsToken_(esConsumes<edm::Transition::BeginRun>()),
topoEsTokenBR_(esConsumes<edm::Transition::BeginRun>()),
topoEsTokenER_(esConsumes<edm::Transition::EndRun>()),
siPixelLAEsToken_(esConsumes<edm::Transition::BeginRun>()),
magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()),
newmodulelist_(iConfig.getParameter<std::vector<std::string>>("newmodulelist")),
Expand All @@ -128,16 +131,18 @@ SiPixelLorentzAnglePCLHarvester::SiPixelLorentzAnglePCLHarvester(const edm::Para
void SiPixelLorentzAnglePCLHarvester::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
// geometry
const TrackerGeometry* geom = &iSetup.getData(geomEsToken_);
const TrackerTopology* tTopo = &iSetup.getData(topoEsToken_);
const TrackerTopology* tTopo = &iSetup.getData(topoEsTokenBR_);

magField = &iSetup.getData(magneticFieldToken_);
currentLorentzAngle = &iSetup.getData(siPixelLAEsToken_);

PixelTopologyMap map = PixelTopologyMap(geom, tTopo);
hists.nlay = geom->numberOfLayers(PixelSubdetector::PixelBarrel);
hists.nModules_.resize(hists.nlay);
hists.nLadders_.resize(hists.nlay);
for (int i = 0; i < hists.nlay; i++) {
hists.nModules_[i] = map.getPXBModules(i + 1);
hists.nLadders_[i] = map.getPXBLadders(i + 1);
}

// list of modules already filled, then return (we already entered here)
Expand Down Expand Up @@ -208,6 +213,13 @@ void SiPixelLorentzAnglePCLHarvester::beginRun(const edm::Run& iRun, const edm::
LogDebug("SiPixelLorentzAnglePCLHarvester") << "Stored a total of " << count << " detIds.";
}

//------------------------------------------------------------------------------
void SiPixelLorentzAnglePCLHarvester::endRun(edm::Run const& run, edm::EventSetup const& isetup) {
if (!theTrackerTopology) {
theTrackerTopology = std::make_unique<TrackerTopology>(isetup.getData(topoEsTokenER_));
}
}

//------------------------------------------------------------------------------
void SiPixelLorentzAnglePCLHarvester::dqmEndJob(DQMStore::IBooker& iBooker, DQMStore::IGetter& iGetter) {
// go in the right directory
Expand Down Expand Up @@ -335,6 +347,22 @@ void SiPixelLorentzAnglePCLHarvester::dqmEndJob(DQMStore::IBooker& iBooker, DQMS
hists.h_bySectChi2_->setBinLabel(bin, binName);
}

// this will be booked in the Harvesting folder
iBooker.setCurrentFolder(fmt::format("{}Harvesting/LorentzAngleMaps", dqmDir_));
for (int i = 0; i < hists.nlay; i++) {
std::string repName = "h2_byLayerLA_%i";
std::string repText = "BPix Layer %i tan#theta_{LA}/B;module number;ladder number;tan#theta_{LA}/B [1/T]";

hists.h2_byLayerLA_.emplace_back(iBooker.book2D(fmt::sprintf(repName, i + 1),
fmt::sprintf(repText, i + 1),
hists.nModules_[i],
0.5,
hists.nModules_[i] + 0.5,
hists.nLadders_[i],
0.5,
hists.nLadders_[i] + 0.5));
}

// clang-format off
edm::LogPrint("LorentzAngle") << "module" << "\t" << "layer" << "\t"
<< "offset" << "\t" << "e0" << "\t"
Expand Down Expand Up @@ -448,7 +476,7 @@ void SiPixelLorentzAnglePCLHarvester::dqmEndJob(DQMStore::IBooker& iBooker, DQMS
float fPixLorentzAnglePerTesla_ = currentLorentzAngle->getLorentzAngle(id);
if (!LorentzAngle->putLorentzAngle(id, fPixLorentzAnglePerTesla_)) {
edm::LogError("SiPixelLorentzAnglePCLHarvester")
<< "[SiPixelLorentzAnglePCLHarvester::dqmEndRun] filling rest of payload: detid already exists";
<< "[SiPixelLorentzAnglePCLHarvester::dqmEndJob] filling rest of payload: detid already exists";
}
}

Expand All @@ -458,6 +486,17 @@ void SiPixelLorentzAnglePCLHarvester::dqmEndJob(DQMStore::IBooker& iBooker, DQMS
h_diffLA->Fill(deltaMuHoverMuH);
}

// fill the 2D output Lorentz Angle maps
for (const auto& [id, value] : LorentzAngle->getLorentzAngles()) {
DetId ID = DetId(id);
if (ID.subdetId() == PixelSubdetector::PixelBarrel) {
const auto& layer = theTrackerTopology->pxbLayer(id);
const auto& ladder = theTrackerTopology->pxbLadder(id);
const auto& module = theTrackerTopology->pxbModule(id);
hists.h2_byLayerLA_[layer - 1]->setBinContent(module, ladder, value);
}
}

// fill the DB object record
edm::Service<cond::service::PoolDBOutputService> mydbservice;
if (mydbservice.isAvailable()) {
Expand Down

0 comments on commit 507cc26

Please sign in to comment.