CMS 3D CMS Logo

AlignmentMonitorAsAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: AlignmentMonitorAsAnalyzer
4 // Class: AlignmentMonitorAsAnalyzer
5 //
13 //
14 // Original Author: Jim Pivarski
15 // Created: Sat Apr 26 12:36:13 CDT 2008
16 // $Id: AlignmentMonitorAsAnalyzer.cc,v 1.9 2012/07/13 09:18:40 yana Exp $
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
31 
37 
58 
60 
61 //
62 // class decleration
63 //
64 
66 public:
68  ~AlignmentMonitorAsAnalyzer() override = default;
69 
70  typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
71  typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
72 
73 private:
74  void beginJob() override;
75  void analyze(const edm::Event&, const edm::EventSetup&) override;
76  void endJob() override;
77 
78  // ----------member data ---------------------------
81 
82  std::unique_ptr<AlignableTracker> m_alignableTracker;
83  std::unique_ptr<AlignableMuon> m_alignableMuon;
84  std::unique_ptr<AlignmentParameterStore> m_alignmentParameterStore;
85 
86  std::vector<std::unique_ptr<AlignmentMonitorBase>> m_monitors;
87 
89 };
90 
91 //
92 // constants, enums and typedefs
93 //
94 
95 //
96 // static data member definitions
97 //
98 
99 //
100 // constructors and destructor
101 //
103  : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag")),
104  m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore")) {
105  std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string>>("monitors");
106 
107  for (auto const& mon : monitors) {
108  m_monitors.emplace_back(
110  }
111 }
112 
113 //
114 // member functions
115 //
116 
117 // ------------ method called to for each event ------------
119  //Retrieve tracker topology from geometry
120  edm::ESHandle<TrackerTopology> tTopoHandle;
121  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
122  const TrackerTopology* const tTopo = tTopoHandle.product();
123 
124  if (m_firstEvent) {
125  GeometryAligner aligner;
126 
128  iSetup.get<IdealGeometryRecord>().get(cpv);
129 
130  edm::ESHandle<GeometricDet> theGeometricDet;
131  iSetup.get<IdealGeometryRecord>().get(theGeometricDet);
133  iSetup.get<PTrackerParametersRcd>().get(ptp);
134  TrackerGeomBuilderFromGeometricDet trackerBuilder;
135  std::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(&(*theGeometricDet), *ptp, tTopo));
136 
138  iSetup.get<MuonNumberingRecord>().get(mdc);
141  auto theMuonDT = std::make_shared<DTGeometry>();
142  DTGeometryBuilder.build(*theMuonDT, &(*cpv), *mdc);
143  auto theMuonCSC = std::make_shared<CSCGeometry>();
144  CSCGeometryBuilder.build(*theMuonCSC, &(*cpv), *mdc);
145 
146  edm::ESHandle<Alignments> globalPositionRcd;
147  iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
148 
149  edm::ESHandle<Alignments> alignments;
150  iSetup.get<TrackerAlignmentRcd>().get(alignments);
152  iSetup.get<TrackerAlignmentErrorExtendedRcd>().get(alignmentErrors);
153  aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
154  &(*alignments),
155  &(*alignmentErrors),
156  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
157 
158  edm::ESHandle<Alignments> dtAlignments;
159  iSetup.get<DTAlignmentRcd>().get(dtAlignments);
160  edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended;
161  iSetup.get<DTAlignmentErrorExtendedRcd>().get(dtAlignmentErrorsExtended);
162  aligner.applyAlignments<DTGeometry>(&(*theMuonDT),
163  &(*dtAlignments),
164  &(*dtAlignmentErrorsExtended),
165  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
166 
167  edm::ESHandle<Alignments> cscAlignments;
168  iSetup.get<CSCAlignmentRcd>().get(cscAlignments);
169  edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended;
170  iSetup.get<CSCAlignmentErrorExtendedRcd>().get(cscAlignmentErrorsExtended);
171  aligner.applyAlignments<CSCGeometry>(&(*theMuonCSC),
172  &(*cscAlignments),
173  &(*cscAlignmentErrorsExtended),
174  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
175 
176  // within an analyzer, modules can't expect to see any selected alignables!
177  align::Alignables empty_alignables;
178 
179  m_alignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
180  m_alignableMuon = std::make_unique<AlignableMuon>(&(*theMuonDT), &(*theMuonCSC));
181  m_alignmentParameterStore = std::make_unique<AlignmentParameterStore>(empty_alignables, m_aliParamStoreCfg);
182 
183  for (auto const& monitor : m_monitors) {
184  monitor->beginOfJob(m_alignableTracker.get(), m_alignableMuon.get(), m_alignmentParameterStore.get());
185  }
186  for (auto const& monitor : m_monitors) {
187  monitor->startingNewLoop();
188  }
189 
190  m_firstEvent = false;
191  }
192 
193  // Retrieve trajectories and tracks from the event
195  iEvent.getByLabel(m_tjTag, trajTracksMap);
196 
197  // Form pairs of trajectories and tracks
198  ConstTrajTrackPairCollection trajTracks;
199  for (const auto& iPair : *trajTracksMap) {
200  trajTracks.push_back(ConstTrajTrackPair(&(*iPair.key), &(*iPair.val)));
201  }
202 
203  // Run the monitors
204  for (const auto& monitor : m_monitors) {
205  monitor->duringLoop(iEvent, iSetup, trajTracks);
206  }
207 }
208 
209 // ------------ method called once each job just before starting event loop ------------
211 
212 // ------------ method called once each job just after ending the event loop ------------
214  for (auto const& monitor : m_monitors) {
215  monitor->endOfLoop();
216  }
217  for (auto const& monitor : m_monitors) {
218  monitor->endOfJob();
219  }
220 }
221 
222 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
AlignmentMonitorAsAnalyzer(const edm::ParameterSet &)
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
def create(alignables, pedeDump, additionalData, outputFile, config)
Class to update a given geometry with a set of alignments.
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
~AlignmentMonitorAsAnalyzer() override=default
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void build(CSCGeometry &geom, const DDCompactView *fv, const MuonDDDConstants &muonConstants)
Build the geometry.
void build(DTGeometry &theGeometry, const DDCompactView *cview, const MuonDDDConstants &muonConstants)
std::unique_ptr< AlignableMuon > m_alignableMuon
std::unique_ptr< AlignableTracker > m_alignableTracker
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:488
Definition: DetId.h:17
void analyze(const edm::Event &, const edm::EventSetup &) override
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
std::vector< std::unique_ptr< AlignmentMonitorBase > > m_monitors
HLT enums.
T get() const
Definition: EventSetup.h:73
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
std::unique_ptr< AlignmentParameterStore > m_alignmentParameterStore
T const * product() const
Definition: ESHandle.h:86
std::pair< const Trajectory *, const reco::Track * > ConstTrajTrackPair