Skip to content

Commit

Permalink
removing cout;using esconsume
Browse files Browse the repository at this point in the history
  • Loading branch information
sroychow committed Oct 9, 2020
1 parent 66cc135 commit 14b04a8
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 75 deletions.
56 changes: 23 additions & 33 deletions DQM/SiTrackerPhase2/plugins/Phase2ITMonitorRecHit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "Geometry/CommonDetUnit/interface/TrackerGeomDet.h"
#include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
#include "Geometry/CommonDetUnit/interface/PixelGeomDetType.h"
#include "Geometry/Records/interface/TrackerTopologyRcd.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "DataFormats/GeometrySurface/interface/LocalError.h"
Expand All @@ -31,30 +33,19 @@
//
Phase2ITMonitorRecHit::Phase2ITMonitorRecHit(const edm::ParameterSet& iConfig)
: config_(iConfig),
tokenRecHitsIT_(consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("rechitsSrc"))) {
tokenRecHitsIT_(consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("rechitsSrc"))),
geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
edm::LogInfo("Phase2ITMonitorRecHit") << ">>> Construct Phase2ITMonitorRecHit ";
}

Phase2ITMonitorRecHit::~Phase2ITMonitorRecHit() {
edm::LogInfo("Phase2ITMonitorRecHit") << ">>> Destroy Phase2ITMonitorRecHit ";
}
// -- Analyze
void Phase2ITMonitorRecHit::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
// Get the geometry
edm::ESHandle<TrackerGeometry> geomHandle;
iSetup.get<TrackerDigiGeometryRecord>().get(geomHandle);
const TrackerGeometry* tkGeom = &(*geomHandle);

edm::ESHandle<TrackerTopology> tTopoHandle;
iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
const TrackerTopology* tTopo = tTopoHandle.product();

fillITHistos(iEvent, tTopo, tkGeom);
}
void Phase2ITMonitorRecHit::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) { fillITHistos(iEvent); }

void Phase2ITMonitorRecHit::fillITHistos(const edm::Event& iEvent,
const TrackerTopology* tTopo,
const TrackerGeometry* tkGeom) {
void Phase2ITMonitorRecHit::fillITHistos(const edm::Event& iEvent) {
// Get the RecHits
edm::Handle<SiPixelRecHitCollection> rechits;
iEvent.getByToken(tokenRecHitsIT_, rechits);
Expand All @@ -69,10 +60,10 @@ void Phase2ITMonitorRecHit::fillITHistos(const edm::Event& iEvent,
unsigned int rawid(DSViter->detId());
DetId detId(rawid);
// Get the geomdet
const GeomDetUnit* geomDetunit(tkGeom->idToDetUnit(detId));
const GeomDetUnit* geomDetunit(tkGeom_->idToDetUnit(detId));
if (!geomDetunit)
continue;
std::string key = Phase2TkUtil::getITHistoId(detId.rawId(), tTopo);
std::string key = Phase2TkUtil::getITHistoId(detId.rawId(), tTopo_);
nTotrechitsinevt += DSViter->size();
if (nrechitLayerMap.find(key) == nrechitLayerMap.end()) {
nrechitLayerMap.insert(std::make_pair(key, DSViter->size()));
Expand Down Expand Up @@ -127,6 +118,14 @@ void Phase2ITMonitorRecHit::fillITHistos(const edm::Event& iEvent,
if (layerMEs_[lme.first].numberRecHits)
layerMEs_[lme.first].numberRecHits->Fill(lme.second);
}

void Phase2ITMonitorRecHit::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
edm::ESHandle<TrackerGeometry> geomHandle = iSetup.getHandle(geomToken_);
tkGeom_ = &(*geomHandle);
edm::ESHandle<TrackerTopology> tTopoHandle = iSetup.getHandle(topoToken_);
tTopo_ = tTopoHandle.product();
}

void Phase2ITMonitorRecHit::bookHistograms(DQMStore::IBooker& ibooker,
edm::Run const& iRun,
edm::EventSetup const& iSetup) {
Expand Down Expand Up @@ -160,39 +159,30 @@ void Phase2ITMonitorRecHit::bookHistograms(DQMStore::IBooker& ibooker,

//Now book layer wise histos
edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
edm::ESHandle<TrackerTopology> tTopoHandle;
iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
const TrackerTopology* const tTopo = tTopoHandle.product();
if (theTkDigiGeomWatcher.check(iSetup)) {
edm::ESHandle<TrackerGeometry> geom_handle;
iSetup.get<TrackerDigiGeometryRecord>().get(geomType_, geom_handle);
const TrackerGeometry* tGeom = geom_handle.product();
for (auto const& det_u : tGeom->detUnits()) {
edm::ESHandle<TrackerGeometry> geomHandle = iSetup.getHandle(geomToken_);
for (auto const& det_u : tkGeom_->detUnits()) {
//Always check TrackerNumberingBuilder before changing this part
if (!(det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC))
continue;
unsigned int detId_raw = det_u->geographicalId().rawId();
edm::LogInfo("Phase2ITMonitorRecHit") << "Detid:" << detId_raw << "\tsubdet=" << det_u->subDetector()
<< "\t key=" << Phase2TkUtil::getITHistoId(detId_raw, tTopo) << std::endl;
bookLayerHistos(ibooker, detId_raw, tTopo, dir);
<< "\t key=" << Phase2TkUtil::getITHistoId(detId_raw, tTopo_) << std::endl;
bookLayerHistos(ibooker, detId_raw, dir);
}
}
}
// -- Book Layer Histograms
void Phase2ITMonitorRecHit::bookLayerHistos(DQMStore::IBooker& ibooker,
unsigned int det_id,
const TrackerTopology* tTopo,
std::string& subdir) {
std::string key = Phase2TkUtil::getITHistoId(det_id, tTopo);
void Phase2ITMonitorRecHit::bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, std::string& subdir) {
std::string key = Phase2TkUtil::getITHistoId(det_id, tTopo_);
if (key.empty())
return;
if (layerMEs_.find(key) == layerMEs_.end()) {
ibooker.cd();
RecHitME local_histos;
std::ostringstream histoName;
ibooker.setCurrentFolder(subdir + "/" + key);
std::cout << "Setting subfolder>>>" << subdir << "\t" << key << std::endl;
edm::LogInfo("Phase2ITMonitorRecHit") << " Booking Histograms in : " << (subdir + "/" + key);
histoName.str("");
histoName << "Number_RecHits";
Expand Down
15 changes: 9 additions & 6 deletions DQM/SiTrackerPhase2/plugins/Phase2ITMonitorRecHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,28 @@
// DQM Histograming
class TrackerTopology;
class TrackerGeometry;

class TrackerDigiGeometryRecord;
class TrackerTopologyRcd;
class Phase2ITMonitorRecHit : public DQMEDAnalyzer {
public:
explicit Phase2ITMonitorRecHit(const edm::ParameterSet&);
~Phase2ITMonitorRecHit() override;
void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup);

private:
void fillITHistos(const edm::Event& iEvent, const TrackerTopology* tTopo, const TrackerGeometry* tkGeom);
void fillITHistos(const edm::Event& iEvent);

void bookLayerHistos(DQMStore::IBooker& ibooker,
unsigned int det_id,
const TrackerTopology* tTopo,
std::string& subdir);
void bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, std::string& subdir);

edm::ParameterSet config_;
std::string geomType_;
const edm::EDGetTokenT<SiPixelRecHitCollection> tokenRecHitsIT_;
const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
const TrackerGeometry* tkGeom_ = nullptr;
const TrackerTopology* tTopo_ = nullptr;

MonitorElement* numberRecHits_;
MonitorElement* globalXY_barrel_;
Expand Down
52 changes: 25 additions & 27 deletions Validation/SiTrackerPhase2V/plugins/Phase2ITValidateRecHit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "Geometry/CommonDetUnit/interface/TrackerGeomDet.h"
#include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
#include "Geometry/CommonDetUnit/interface/PixelGeomDetType.h"
#include "Geometry/Records/interface/TrackerTopologyRcd.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "DataFormats/GeometrySurface/interface/LocalError.h"
Expand All @@ -39,7 +41,9 @@ Phase2ITValidateRecHit::Phase2ITValidateRecHit(const edm::ParameterSet& iConfig)
trackerHitAssociatorConfig_(iConfig, consumesCollector()),
simtrackminpt_(iConfig.getParameter<double>("SimTrackMinPt")),
tokenRecHitsIT_(consumes<SiPixelRecHitCollection>(iConfig.getParameter<edm::InputTag>("rechitsSrc"))),
simTracksToken_(consumes<edm::SimTrackContainer>(iConfig.getParameter<edm::InputTag>("simTracksSrc"))) {
simTracksToken_(consumes<edm::SimTrackContainer>(iConfig.getParameter<edm::InputTag>("simTracksSrc"))),
geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
edm::LogInfo("Phase2ITValidateRecHit") << ">>> Construct Phase2ITValidateRecHit ";
for (const auto& itag : config_.getParameter<std::vector<edm::InputTag>>("PSimHitSource"))
simHitTokens_.push_back(consumes<edm::PSimHitContainer>(itag));
Expand All @@ -50,14 +54,14 @@ Phase2ITValidateRecHit::~Phase2ITValidateRecHit() {
}
void Phase2ITValidateRecHit::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
// Get the geometry
edm::ESHandle<TrackerGeometry> geomHandle;
iSetup.get<TrackerDigiGeometryRecord>().get(geomHandle);
/* edm::ESHandle<TrackerGeometry> geomHandle = iSetup.getHandle(geomToken_);
//iSetup.get<TrackerDigiGeometryRecord>().get(geomHandle);
const TrackerGeometry* tkGeom = &(*geomHandle);
edm::ESHandle<TrackerTopology> tTopoHandle;
iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
edm::ESHandle<TrackerTopology> tTopoHandle = iSetup.getHandle(topoToken_);
//iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
const TrackerTopology* tTopo = tTopoHandle.product();

*/
std::vector<edm::Handle<edm::PSimHitContainer>> simHits;
for (const auto& itoken : simHitTokens_) {
edm::Handle<edm::PSimHitContainer> simHitHandle;
Expand All @@ -78,12 +82,10 @@ void Phase2ITValidateRecHit::analyze(const edm::Event& iEvent, const edm::EventS
}
}
TrackerHitAssociator associateRecHit(iEvent, trackerHitAssociatorConfig_);
fillITHistos(iEvent, tTopo, tkGeom, associateRecHit, simHits, selectedSimTrackMap);
fillITHistos(iEvent, associateRecHit, simHits, selectedSimTrackMap);
}

void Phase2ITValidateRecHit::fillITHistos(const edm::Event& iEvent,
const TrackerTopology* tTopo,
const TrackerGeometry* tkGeom,
const TrackerHitAssociator& associateRecHit,
const std::vector<edm::Handle<edm::PSimHitContainer>>& simHits,
const std::map<unsigned int, SimTrack>& selectedSimTrackMap) {
Expand All @@ -100,11 +102,11 @@ void Phase2ITValidateRecHit::fillITHistos(const edm::Event& iEvent,
unsigned int rawid(DSViter->detId());
DetId detId(rawid);
// Get the geomdet
const GeomDetUnit* geomDetunit(tkGeom->idToDetUnit(detId));
const GeomDetUnit* geomDetunit(tkGeom_->idToDetUnit(detId));
if (!geomDetunit)
continue;
// determine the detector we are in
std::string key = Phase2TkUtil::getITHistoId(detId.rawId(), tTopo);
std::string key = Phase2TkUtil::getITHistoId(detId.rawId(), tTopo_);
if (nrechitLayerMap_primary.find(key) == nrechitLayerMap_primary.end()) {
nrechitLayerMap_primary.insert(std::make_pair(key, DSViter->size()));
} else {
Expand Down Expand Up @@ -176,6 +178,13 @@ void Phase2ITValidateRecHit::fillITHistos(const edm::Event& iEvent,
layerMEs_[lme.first].numberRecHitsprimary->Fill(nrechitLayerMap_primary[lme.first]);
}
}

void Phase2ITValidateRecHit::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
edm::ESHandle<TrackerGeometry> geomHandle = iSetup.getHandle(geomToken_);
tkGeom_ = &(*geomHandle);
edm::ESHandle<TrackerTopology> tTopoHandle = iSetup.getHandle(topoToken_);
tTopo_ = tTopoHandle.product();
}
//
// -- Book Histograms
//
Expand All @@ -185,40 +194,29 @@ void Phase2ITValidateRecHit::bookHistograms(DQMStore::IBooker& ibooker,
std::string top_folder = config_.getParameter<std::string>("TopFolderName");
edm::LogInfo("Phase2ITValidateRecHit") << " Booking Histograms in : " << top_folder;
edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
edm::ESHandle<TrackerTopology> tTopoHandle;
iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
const TrackerTopology* const tTopo = tTopoHandle.product();
if (theTkDigiGeomWatcher.check(iSetup)) {
edm::ESHandle<TrackerGeometry> geom_handle;
iSetup.get<TrackerDigiGeometryRecord>().get(geomType_, geom_handle);
const TrackerGeometry* tGeom = geom_handle.product();
for (auto const& det_u : tGeom->detUnits()) {
for (auto const& det_u : tkGeom_->detUnits()) {
//Always check TrackerNumberingBuilder before changing this part
if (!(det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXB ||
det_u->subDetector() == GeomDetEnumerators::SubDetector::P2PXEC))
continue;
unsigned int detId_raw = det_u->geographicalId().rawId();
bookLayerHistos(ibooker, detId_raw, tTopo, top_folder);
bookLayerHistos(ibooker, detId_raw, top_folder);
}
}
}
//
void Phase2ITValidateRecHit::bookLayerHistos(DQMStore::IBooker& ibooker,
unsigned int det_id,
const TrackerTopology* tTopo,
std::string& subdir) {
void Phase2ITValidateRecHit::bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, std::string& subdir) {
ibooker.cd();
std::string key = Phase2TkUtil::getITHistoId(det_id, tTopo);
std::string key = Phase2TkUtil::getITHistoId(det_id, tTopo_);
if (key.empty())
return;
if (layerMEs_.find(key) == layerMEs_.end()) {
ibooker.cd();
RecHitME local_histos;
std::ostringstream histoName;
ibooker.setCurrentFolder(subdir + "/" + key);
std::cout << "Setting subfolder>>>" << subdir << "\t" << key << std::endl;
edm::LogInfo("Phase2ITValidateRecHit") << " Booking Histograms in : " << key;

edm::LogInfo("Phase2ITValidateRecHit") << " Booking Histograms in : " << (subdir + "/" + key);
histoName.str("");
histoName << "Delta_X";
local_histos.deltaX =
Expand Down
17 changes: 8 additions & 9 deletions Validation/SiTrackerPhase2V/plugins/Phase2ITValidateRecHit.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,35 @@ class SimTrack;
class SimHit;
class TrackerTopology;
class TrackerGeometry;

class TrackerDigiGeometryRecord;
class TrackerTopologyRcd;
class Phase2ITValidateRecHit : public DQMEDAnalyzer {
public:
explicit Phase2ITValidateRecHit(const edm::ParameterSet&);
~Phase2ITValidateRecHit() override;
void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;

private:
void fillITHistos(const edm::Event& iEvent,
const TrackerTopology* tTopo,
const TrackerGeometry* tkGeom,
const TrackerHitAssociator& associateRecHit,
const std::vector<edm::Handle<edm::PSimHitContainer>>& simHits,
const std::map<unsigned int, SimTrack>& selectedSimTrackMap);

void bookLayerHistos(DQMStore::IBooker& ibooker,
unsigned int det_id,
const TrackerTopology* tTopo,
std::string& subdir);
void bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, std::string& subdir);

edm::ParameterSet config_;
bool pixelFlag_;
TrackerHitAssociator::Config trackerHitAssociatorConfig_;
const double simtrackminpt_;
std::string geomType_;
const edm::EDGetTokenT<SiPixelRecHitCollection> tokenRecHitsIT_;
const edm::EDGetTokenT<edm::SimTrackContainer> simTracksToken_;
std::vector<edm::EDGetTokenT<edm::PSimHitContainer>> simHitTokens_;

const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
const TrackerGeometry* tkGeom_ = nullptr;
const TrackerTopology* tTopo_ = nullptr;
struct RecHitME {
// use TH1D instead of TH1F to avoid stauration at 2^31
// above this increments with +1 don't work for float, need double
Expand Down

0 comments on commit 14b04a8

Please sign in to comment.