Skip to content

Commit

Permalink
use esToken in ED modules
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunyong committed Mar 5, 2021
1 parent 72eb9cf commit 67aeadb
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ class AlignmentMonitorAsAnalyzer : public edm::EDAnalyzer {
std::unique_ptr<AlignmentParameterStore> m_alignmentParameterStore;

std::vector<std::unique_ptr<AlignmentMonitorBase>> m_monitors;
std::string idealGeometryLabel;
edm::ESGetToken<DTGeometry, MuonGeometryRecord> esTokenDT_;
edm::ESGetToken<CSCGeometry, MuonGeometryRecord> esTokenCSC_;
edm::ESGetToken<GEMGeometry, MuonGeometryRecord> esTokenGEM_;
edm::ESGetToken<Alignments, GlobalPositionRcd> esTokenGPR_;
edm::ESGetToken<Alignments, DTAlignmentRcd> esTokenDTAl_;
edm::ESGetToken<AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd> esTokenDTAPE_;
edm::ESGetToken<Alignments, CSCAlignmentRcd> esTokenCSCAl_;
edm::ESGetToken<AlignmentErrorsExtended, CSCAlignmentErrorExtendedRcd> esTokenCSCAPE_;
edm::ESGetToken<Alignments, GEMAlignmentRcd> esTokenGEMAl_;
edm::ESGetToken<AlignmentErrorsExtended, GEMAlignmentErrorExtendedRcd> esTokenGEMAPE_;
bool m_firstEvent;
};

Expand All @@ -102,7 +111,9 @@ class AlignmentMonitorAsAnalyzer : public edm::EDAnalyzer {
AlignmentMonitorAsAnalyzer::AlignmentMonitorAsAnalyzer(const edm::ParameterSet& iConfig)
: m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag")),
m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore")),
idealGeometryLabel("idealForAlignmentMonitorAsAnalyzer") {
esTokenDT_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
esTokenCSC_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
esTokenGEM_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))) {
std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string>>("monitors");

for (auto const& mon : monitors) {
Expand Down Expand Up @@ -132,15 +143,11 @@ void AlignmentMonitorAsAnalyzer::analyze(const edm::Event& iEvent, const edm::Ev
TrackerGeomBuilderFromGeometricDet trackerBuilder;
std::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(&(*theGeometricDet), *ptp, tTopo));

edm::ESHandle<DTGeometry> theMuonDT;
edm::ESHandle<CSCGeometry> theMuonCSC;
edm::ESHandle<GEMGeometry> theMuonGEM;
iSetup.get<MuonGeometryRecord>().get(idealGeometryLabel, theMuonDT);
iSetup.get<MuonGeometryRecord>().get(idealGeometryLabel, theMuonCSC);
iSetup.get<MuonGeometryRecord>().get(idealGeometryLabel, theMuonGEM);
edm::ESHandle<DTGeometry> theMuonDT = iSetup.getHandle(esTokenDT_);
edm::ESHandle<CSCGeometry> theMuonCSC = iSetup.getHandle(esTokenCSC_);
edm::ESHandle<GEMGeometry> theMuonGEM = iSetup.getHandle(esTokenGEM_);

edm::ESHandle<Alignments> globalPositionRcd;
iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
edm::ESHandle<Alignments> globalPositionRcd = iSetup.getHandle(esTokenGPR_);

edm::ESHandle<Alignments> alignments;
iSetup.get<TrackerAlignmentRcd>().get(alignments);
Expand All @@ -151,28 +158,23 @@ void AlignmentMonitorAsAnalyzer::analyze(const edm::Event& iEvent, const edm::Ev
&(*alignmentErrors),
align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));

edm::ESHandle<Alignments> dtAlignments;
iSetup.get<DTAlignmentRcd>().get(dtAlignments);
edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended;
iSetup.get<DTAlignmentErrorExtendedRcd>().get(dtAlignmentErrorsExtended);
edm::ESHandle<Alignments> dtAlignments = iSetup.getHandle(esTokenDTAl_);
;
edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended = iSetup.getHandle(esTokenDTAPE_);
aligner.applyAlignments<DTGeometry>(&(*theMuonDT),
&(*dtAlignments),
&(*dtAlignmentErrorsExtended),
align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));

edm::ESHandle<Alignments> cscAlignments;
iSetup.get<CSCAlignmentRcd>().get(cscAlignments);
edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended;
iSetup.get<CSCAlignmentErrorExtendedRcd>().get(cscAlignmentErrorsExtended);
edm::ESHandle<Alignments> cscAlignments = iSetup.getHandle(esTokenCSCAl_);
edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended = iSetup.getHandle(esTokenCSCAPE_);
aligner.applyAlignments<CSCGeometry>(&(*theMuonCSC),
&(*cscAlignments),
&(*cscAlignmentErrorsExtended),
align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));

edm::ESHandle<Alignments> gemAlignments;
iSetup.get<GEMAlignmentRcd>().get(gemAlignments);
edm::ESHandle<AlignmentErrorsExtended> gemAlignmentErrorsExtended;
iSetup.get<GEMAlignmentErrorExtendedRcd>().get(gemAlignmentErrorsExtended);
edm::ESHandle<Alignments> gemAlignments = iSetup.getHandle(esTokenGEMAl_);
edm::ESHandle<AlignmentErrorsExtended> gemAlignmentErrorsExtended = iSetup.getHandle(esTokenGEMAPE_);
aligner.applyAlignments<GEMGeometry>(&(*theMuonGEM),
&(*gemAlignments),
&(*gemAlignmentErrorsExtended),
Expand Down
7 changes: 6 additions & 1 deletion Alignment/MuonAlignment/interface/MuonAlignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Alignment/MuonAlignment/interface/AlignableMuon.h"
#include <FWCore/Framework/interface/Frameworkfwd.h>
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "Alignment/CommonAlignment/interface/AlignableNavigator.h"
#include "Alignment/MuonAlignment/interface/MuonAlignmentInputMethod.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"

class MuonAlignment {
public:
Expand Down Expand Up @@ -65,6 +66,10 @@ class MuonAlignment {
std::string theDTSurveyRecordName, theDTSurveyErrorRecordName;
std::string theCSCSurveyRecordName, theCSCSurveyErrorRecordName;

edm::ESGetToken<DTGeometry, MuonGeometryRecord> esTokenDT_;
edm::ESGetToken<CSCGeometry, MuonGeometryRecord> esTokenCSC_;
edm::ESGetToken<GEMGeometry, MuonGeometryRecord> esTokenGEM_;

align::Scalars displacements;

align::Scalars rotations;
Expand Down
18 changes: 10 additions & 8 deletions Alignment/MuonAlignment/plugins/MuonMisalignedProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ class MuonMisalignedProducer : public edm::one::EDAnalyzer<> {
std::string theDTAlignRecordName, theDTErrorRecordName;
std::string theCSCAlignRecordName, theCSCErrorRecordName;
std::string theGEMAlignRecordName, theGEMErrorRecordName;
std::string theIdealGeometryLabel;

edm::ESGetToken<DTGeometry, MuonGeometryRecord> esTokenDT_;
edm::ESGetToken<CSCGeometry, MuonGeometryRecord> esTokenCSC_;
edm::ESGetToken<GEMGeometry, MuonGeometryRecord> esTokenGEM_;

Alignments* dt_Alignments;
AlignmentErrorsExtended* dt_AlignmentErrorsExtended;
Expand All @@ -76,7 +79,9 @@ MuonMisalignedProducer::MuonMisalignedProducer(const edm::ParameterSet& p)
theCSCErrorRecordName("CSCAlignmentErrorExtendedRcd"),
theGEMAlignRecordName("GEMAlignmentRcd"),
theGEMErrorRecordName("GEMAlignmentErrorExtendedRcd"),
theIdealGeometryLabel("idealForMuonMisalignedProducer") {}
esTokenDT_(esConsumes(edm::ESInputTag("", "idealForMuonMisalignedProducer"))),
esTokenCSC_(esConsumes(edm::ESInputTag("", "idealForMuonMisalignedProducer"))),
esTokenGEM_(esConsumes(edm::ESInputTag("", "idealForMuonMisalignedProducer"))) {}

//__________________________________________________________________________________________________
MuonMisalignedProducer::~MuonMisalignedProducer() {}
Expand All @@ -85,12 +90,9 @@ MuonMisalignedProducer::~MuonMisalignedProducer() {}
void MuonMisalignedProducer::analyze(const edm::Event& event, const edm::EventSetup& eventSetup) {
edm::LogInfo("MisalignedMuon") << "Producer called";
// Create the Muon geometry from ideal geometry
edm::ESHandle<DTGeometry> theDTGeometry;
edm::ESHandle<CSCGeometry> theCSCGeometry;
edm::ESHandle<GEMGeometry> theGEMGeometry;
eventSetup.get<MuonGeometryRecord>().get(theIdealGeometryLabel, theDTGeometry);
eventSetup.get<MuonGeometryRecord>().get(theIdealGeometryLabel, theCSCGeometry);
eventSetup.get<MuonGeometryRecord>().get(theIdealGeometryLabel, theGEMGeometry);
edm::ESHandle<DTGeometry> theDTGeometry = eventSetup.getHandle(esTokenDT_);
edm::ESHandle<CSCGeometry> theCSCGeometry = eventSetup.getHandle(esTokenCSC_);
edm::ESHandle<GEMGeometry> theGEMGeometry = eventSetup.getHandle(esTokenGEM_);

// Create the alignable hierarchy
AlignableMuon* theAlignableMuon = new AlignableMuon(&(*theDTGeometry), &(*theCSCGeometry), &(*theGEMGeometry));
Expand Down
12 changes: 3 additions & 9 deletions Alignment/MuonAlignment/src/MuonAlignment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "CondCore/DBOutputService/interface/PoolDBOutputService.h"

// Muon geom
#include "Geometry/Records/interface/MuonGeometryRecord.h"

// Alignment
#include "CondFormats/Alignment/interface/Alignments.h"
#include "CondFormats/Alignment/interface/AlignmentErrorsExtended.h"
Expand Down Expand Up @@ -46,12 +43,9 @@ void MuonAlignment::init() {
MuonAlignment::MuonAlignment(const edm::EventSetup& iSetup) {
init();

edm::ESHandle<DTGeometry> dtGeometry;
edm::ESHandle<CSCGeometry> cscGeometry;
edm::ESHandle<GEMGeometry> gemGeometry;
iSetup.get<MuonGeometryRecord>().get(dtGeometry);
iSetup.get<MuonGeometryRecord>().get(cscGeometry);
iSetup.get<MuonGeometryRecord>().get(gemGeometry);
edm::ESHandle<DTGeometry> dtGeometry = iSetup.getHandle(esTokenDT_);
edm::ESHandle<CSCGeometry> cscGeometry = iSetup.getHandle(esTokenCSC_);
edm::ESHandle<GEMGeometry> gemGeometry = iSetup.getHandle(esTokenGEM_);

theAlignableMuon = new AlignableMuon(&(*dtGeometry), &(*cscGeometry), &(*gemGeometry));
theAlignableNavigator = new AlignableNavigator(theAlignableMuon);
Expand Down
Empty file.
13 changes: 7 additions & 6 deletions Alignment/MuonAlignment/test/TestMuonHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ class TestMuonHierarchy : public edm::EDAnalyzer {

std::unique_ptr<AlignableMuon> alignableMuon_;
std::string leaders_, blank_, filled_;

edm::ESGetToken<DTGeometry, MuonGeometryRecord> esTokenDT_;
edm::ESGetToken<CSCGeometry, MuonGeometryRecord> esTokenCSC_;
edm::ESGetToken<GEMGeometry, MuonGeometryRecord> esTokenGEM_;
};

void TestMuonHierarchy::analyze(const edm::Event&, const edm::EventSetup& setup) {
edm::LogInfo("MuonHierarchy") << "Starting!";
edm::ESHandle<DTGeometry> dtGeometry;
edm::ESHandle<CSCGeometry> cscGeometry;
edm::ESHandle<GEMGeometry> gemGeometry;
setup.get<MuonGeometryRecord>().get(dtGeometry);
setup.get<MuonGeometryRecord>().get(cscGeometry);
setup.get<MuonGeometryRecord>().get(gemGeometry);
edm::ESHandle<DTGeometry> dtGeometry = setup.getHandle(esTokenDT_);
edm::ESHandle<CSCGeometry> cscGeometry = setup.getHandle(esTokenCSC_);
edm::ESHandle<GEMGeometry> gemGeometry = setup.getHandle(esTokenGEM_);

alignableMuon_ = std::make_unique<AlignableMuon>(&(*dtGeometry), &(*cscGeometry), &(*gemGeometry));

Expand Down
18 changes: 10 additions & 8 deletions Alignment/MuonAlignment/test/TestReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class TestMuonReader : public edm::EDAnalyzer {
TFile* theFile;
float x, y, z, phi, theta, length, thick, width;
TRotMatrix* rot;
std::string idealGeometryLabel;

edm::ESGetToken<DTGeometry, MuonGeometryRecord> esTokenDT_;
edm::ESGetToken<CSCGeometry, MuonGeometryRecord> esTokenCSC_;
edm::ESGetToken<GEMGeometry, MuonGeometryRecord> esTokenGEM_;
};

//
Expand All @@ -77,7 +80,9 @@ TestMuonReader::TestMuonReader(const edm::ParameterSet& iConfig)
thick(0.),
width(0.),
rot(0),
idealGeometryLabel("idealForTestReader") {}
esTokenDT_(esConsumes(edm::ESInputTag("", "idealForTestReader"))),
esTokenCSC_(esConsumes(edm::ESInputTag("", "idealForTestReader"))),
esTokenGEM_(esConsumes(edm::ESInputTag("", "idealForTestReader"))) {}

TestMuonReader::~TestMuonReader() {}

Expand Down Expand Up @@ -105,12 +110,9 @@ align::EulerAngles TestMuonReader::toPhiXYZ(const align::RotationType& rot) {

void TestMuonReader::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
// first, get chamber alignables from ideal geometry:
edm::ESHandle<DTGeometry> dtGeometry;
edm::ESHandle<CSCGeometry> cscGeometry;
edm::ESHandle<GEMGeometry> gemGeometry;
iSetup.get<MuonGeometryRecord>().get(idealGeometryLabel, dtGeometry);
iSetup.get<MuonGeometryRecord>().get(idealGeometryLabel, cscGeometry);
iSetup.get<MuonGeometryRecord>().get(idealGeometryLabel, gemGeometry);
edm::ESHandle<DTGeometry> dtGeometry = iSetup.getHandle(esTokenDT_);
edm::ESHandle<CSCGeometry> cscGeometry = iSetup.getHandle(esTokenCSC_);
edm::ESHandle<GEMGeometry> gemGeometry = iSetup.getHandle(esTokenGEM_);

AlignableMuon ideal_alignableMuon(&(*dtGeometry), &(*cscGeometry), &(*gemGeometry));

Expand Down
14 changes: 6 additions & 8 deletions Alignment/MuonAlignment/test/TestRotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ class TestRotation : public edm::EDAnalyzer {
float x, y, z, phi, theta, length, thick, width;
TRotMatrix* dir;

// typedef Surface::RotationType RotationType;
// typedef Surface::PositionType PositionType;
edm::ESGetToken<DTGeometry, MuonGeometryRecord> esTokenDT_;
edm::ESGetToken<CSCGeometry, MuonGeometryRecord> esTokenCSC_;
edm::ESGetToken<GEMGeometry, MuonGeometryRecord> esTokenGEM_;
};

//
Expand Down Expand Up @@ -105,12 +106,9 @@ void TestRotation::analyze(const edm::Event& iEvent, const edm::EventSetup& iSet
//
// Retrieve ideal geometry from event setup
//
edm::ESHandle<DTGeometry> dtGeometry;
edm::ESHandle<CSCGeometry> cscGeometry;
edm::ESHandle<GEMGeometry> gemGeometry;
iSetup.get<MuonGeometryRecord>().get(dtGeometry);
iSetup.get<MuonGeometryRecord>().get(cscGeometry);
iSetup.get<MuonGeometryRecord>().get(gemGeometry);
edm::ESHandle<DTGeometry> dtGeometry = iSetup.getHandle(esTokenDT_);
edm::ESHandle<CSCGeometry> cscGeometry = iSetup.getHandle(esTokenCSC_);
edm::ESHandle<GEMGeometry> gemGeometry = iSetup.getHandle(esTokenGEM_);

AlignableMuon* theAlignableMuon = new AlignableMuon(&(*dtGeometry), &(*cscGeometry), &(*gemGeometry));

Expand Down
15 changes: 9 additions & 6 deletions Geometry/CommonTopologies/interface/GeometryAligner.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,21 @@ void GeometryAligner::applyAlignments(const C* geometry,
const AlignTransform::Rotation inverseGlobalRotation = globalRotation.inverse();

// Parallel loop on alignments, alignment errors and geomdets
std::vector<AlignTransform>::const_iterator iAlign = alignments->m_align.begin();
std::vector<AlignTransformErrorExtended>::const_iterator iAlignError = alignmentErrors->m_alignError.begin();
//copy geometry->theMap to a real map to order it....
std::map<unsigned int, GeomDet const*> theMap;
std::copy(geometry->theMap.begin(), geometry->theMap.end(), std::inserter(theMap, theMap.begin()));
unsigned int nAPE = 0;
for (auto iAlign = alignments->m_align.begin(); iAlign != alignments->m_align.end(); ++iAlign, ++iAlignError) {
for (auto iPair = theMap.begin(); iPair != theMap.end(); ++iPair, ++iAlign, ++iAlignError) {
// Check DetIds
if (theMap.find((*iAlign).rawId()) == theMap.end())
throw cms::Exception("GeometryMismatch") << "Can't find rawId=" << (*iAlign).rawId();
if ((*iPair).first != (*iAlign).rawId())
throw cms::Exception("GeometryMismatch") << "DetId mismatch between geometry (rawId=" << (*iPair).first
<< ") and alignments (rawId=" << (*iAlign).rawId();

if (theMap.find((*iAlignError).rawId()) == theMap.end())
throw cms::Exception("GeometryMismatch") << "Can't find rawId=" << (*iAlignError).rawId();
if ((*iPair).first != (*iAlignError).rawId())
throw cms::Exception("GeometryMismatch") << "DetId mismatch between geometry (rawId=" << (*iPair).first
<< ") and alignment errors (rawId=" << (*iAlignError).rawId();

// Apply global correction
CLHEP::Hep3Vector positionHep = globalRotation * CLHEP::Hep3Vector((*iAlign).translation()) + globalShift;
Expand All @@ -98,7 +101,7 @@ void GeometryAligner::applyAlignments(const C* geometry,
rotationHep.zx(),
rotationHep.zy(),
rotationHep.zz());
GeomDet* iGeomDet = const_cast<GeomDet*>(theMap[(*iAlign).rawId()]);
GeomDet* iGeomDet = const_cast<GeomDet*>((*iPair).second);
this->setGeomDetPosition(*iGeomDet, position, rotation);

// Alignment Position Error only if non-zero to save memory
Expand Down

0 comments on commit 67aeadb

Please sign in to comment.