Skip to content

Commit

Permalink
code speed-up, improve new modules finding and move SiPixelTemplate::…
Browse files Browse the repository at this point in the history
…pushfile to dqmBeginRun
  • Loading branch information
mmusich committed Dec 17, 2021
1 parent 4f5f7ac commit 47a4146
Showing 1 changed file with 23 additions and 14 deletions.
Expand Up @@ -119,6 +119,10 @@ class SiPixelLorentzAnglePCLWorker : public DQMEDAnalyzer {
// ------------ member data ------------
SiPixelLorentzAngleCalibrationHistograms iHists;

// template stuff
const SiPixelTemplateDBObject* templateDBobject_;
std::vector<SiPixelTemplateStore> thePixelTemp_;

std::string folder_;
bool notInPCL_;
std::string filename_;
Expand Down Expand Up @@ -210,7 +214,7 @@ SiPixelLorentzAnglePCLWorker::SiPixelLorentzAnglePCLWorker(const edm::ParameterS
hist_drift_(iConfig.getParameter<int>("binsDrift")),
geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
topoEsToken_(esConsumes<edm::Transition::BeginRun>()),
siPixelTemplateEsToken_(esConsumes()),
siPixelTemplateEsToken_(esConsumes<edm::Transition::BeginRun>()),
topoPerEventEsToken_(esConsumes()),
geomPerEventEsToken_(esConsumes()) {
t_trajTrack = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("src"));
Expand Down Expand Up @@ -305,15 +309,8 @@ SiPixelLorentzAnglePCLWorker::SiPixelLorentzAnglePCLWorker(const edm::ParameterS
// ------------ method called for each event ------------

void SiPixelLorentzAnglePCLWorker::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
// Retrieve template stuff
const SiPixelTemplateDBObject* templateDBobject_ = &iSetup.getData(siPixelTemplateEsToken_);
std::vector<SiPixelTemplateStore> thePixelTemp_;
// Retrieve template stuff (comes from dqmBeginRun)
SiPixelTemplate templ(thePixelTemp_);
if (!SiPixelTemplate::pushfile(*templateDBobject_, thePixelTemp_)) {
edm::LogError("SiPixelLorentzAnglePCLWorker")
<< "\nERROR: Templates not filled correctly. Check the sqlite file."
<< "Using SiPixelTemplateDBObject version " << (*templateDBobject_).version() << "\n\n";
}

// Retrieve tracker topology from geometry
const TrackerTopology* const tTopo = &iSetup.getData(topoPerEventEsToken_);
Expand Down Expand Up @@ -461,12 +458,13 @@ void SiPixelLorentzAnglePCLWorker::analyze(edm::Event const& iEvent, edm::EventS
locBz = -locBx;

auto detId = detIdObj.rawId();
bool Isnew = false;
int DetId_index = -1;
for (int i = 0; i < (int)iHists.BPixnewDetIds_.size(); i++) {
if (detId == (unsigned int)iHists.BPixnewDetIds_[i])
Isnew = true;
DetId_index = i;

const auto& newModIt = (std::find(iHists.BPixnewDetIds_.begin(), iHists.BPixnewDetIds_.end(), detId));
bool Isnew = (newModIt != iHists.BPixnewDetIds_.end());
if (Isnew) {
std::cout << detId << std::endl;
DetId_index = std::distance(iHists.BPixnewDetIds_.begin(), newModIt);
}

int TemplID = templateDBobject_->getTemplateID(detId);
Expand Down Expand Up @@ -545,6 +543,9 @@ void SiPixelLorentzAnglePCLWorker::analyze(edm::Event const& iEvent, edm::EventS
} else {
int new_index = iHists.nModules_[iHists.nlay - 1] +
(iHists.nlay - 1) * iHists.nModules_[iHists.nlay - 1] + 1 + DetId_index;

std::cout << "this is a new module with index: " << new_index << std::endl;

iHists.h_drift_depth_adc_.at(new_index)->Fill(drift, depth, pixinfo_.adc[j]);
iHists.h_drift_depth_adc2_.at(new_index)->Fill(drift, depth, pixinfo_.adc[j] * pixinfo_.adc[j]);
iHists.h_drift_depth_noadc_.at(new_index)->Fill(drift, depth);
Expand Down Expand Up @@ -649,6 +650,14 @@ void SiPixelLorentzAnglePCLWorker::dqmBeginRun(edm::Run const& run, edm::EventSe
const TrackerGeometry* geom = &iSetup.getData(geomEsToken_);
const TrackerTopology* tTopo = &iSetup.getData(topoEsToken_);

// Initialize 1D templates
templateDBobject_ = &iSetup.getData(siPixelTemplateEsToken_);
if (!SiPixelTemplate::pushfile(*templateDBobject_, thePixelTemp_)) {
edm::LogError("SiPixelLorentzAnglePCLWorker")
<< "Templates not filled correctly. Check the sqlite file. Using SiPixelTemplateDBObject version "
<< (*templateDBobject_).version() << std::endl;
}

PixelTopologyMap map = PixelTopologyMap(geom, tTopo);
iHists.nlay = geom->numberOfLayers(PixelSubdetector::PixelBarrel);
iHists.nModules_.resize(iHists.nlay);
Expand Down

0 comments on commit 47a4146

Please sign in to comment.