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 
105 };
106 
107 //
108 // constants, enums and typedefs
109 //
110 
111 //
112 // static data member definitions
113 //
114 
115 //
116 // constructors and destructor
117 //
119  : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag")),
120  m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore")),
121  esTokenTTopo_(esConsumes()),
122  esTokenGeomDet_(esConsumes()),
123  esTokenPTP_(esConsumes()),
124  esTokenDT_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
125  esTokenCSC_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
126  esTokenGEM_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
127  esTokenGPR_(esConsumes()),
128  esTokenTkAl_(esConsumes()),
129  esTokenTkAPE_(esConsumes()),
130  esTokenDTAl_(esConsumes()),
131  esTokenDTAPE_(esConsumes()),
132  esTokenCSCAl_(esConsumes()),
133  esTokenCSCAPE_(esConsumes()),
134  esTokenGEMAl_(esConsumes()),
135  esTokenGEMAPE_(esConsumes()),
136  trajTrackToken_(consumes<TrajTrackAssociationCollection>(m_tjTag)) {
137  edm::ConsumesCollector consumeCollector = consumesCollector();
138  std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string>>("monitors");
139 
140  for (auto const& mon : monitors) {
142  mon, iConfig.getUntrackedParameter<edm::ParameterSet>(mon), consumeCollector));
143  }
144 }
145 
146 //
147 // member functions
148 //
149 
150 // ------------ method called to for each event ------------
152  //Retrieve tracker topology from geometry
153  const TrackerTopology* const tTopo = &iSetup.getData(esTokenTTopo_);
154 
155  if (m_firstEvent) {
156  GeometryAligner aligner;
157 
158  const GeometricDet* geom = &iSetup.getData(esTokenGeomDet_);
159  const PTrackerParameters& ptp = iSetup.getData(esTokenPTP_);
160  TrackerGeomBuilderFromGeometricDet trackerBuilder;
161  std::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(geom, ptp, tTopo));
162 
163  edm::ESHandle<DTGeometry> theMuonDT = iSetup.getHandle(esTokenDT_);
164  edm::ESHandle<CSCGeometry> theMuonCSC = iSetup.getHandle(esTokenCSC_);
165  edm::ESHandle<GEMGeometry> theMuonGEM = iSetup.getHandle(esTokenGEM_);
166  edm::ESHandle<Alignments> globalPositionRcd = iSetup.getHandle(esTokenGPR_);
167 
168  const Alignments* alignments = &iSetup.getData(esTokenTkAl_);
169  const AlignmentErrorsExtended* alignmentErrors = &iSetup.getData(esTokenTkAPE_);
170  aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
171  alignments,
172  alignmentErrors,
173  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
174 
175  edm::ESHandle<Alignments> dtAlignments = iSetup.getHandle(esTokenDTAl_);
176  edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended = iSetup.getHandle(esTokenDTAPE_);
177  aligner.applyAlignments<DTGeometry>(&(*theMuonDT),
178  &(*dtAlignments),
179  &(*dtAlignmentErrorsExtended),
180  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
181 
182  edm::ESHandle<Alignments> cscAlignments = iSetup.getHandle(esTokenCSCAl_);
183  edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended = iSetup.getHandle(esTokenCSCAPE_);
184  aligner.applyAlignments<CSCGeometry>(&(*theMuonCSC),
185  &(*cscAlignments),
186  &(*cscAlignmentErrorsExtended),
187  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
188 
189  edm::ESHandle<Alignments> gemAlignments = iSetup.getHandle(esTokenGEMAl_);
190  edm::ESHandle<AlignmentErrorsExtended> gemAlignmentErrorsExtended = iSetup.getHandle(esTokenGEMAPE_);
191  aligner.applyAlignments<GEMGeometry>(&(*theMuonGEM),
192  &(*gemAlignments),
193  &(*gemAlignmentErrorsExtended),
194  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
195 
196  // within an analyzer, modules can't expect to see any selected alignables!
197  align::Alignables empty_alignables;
198 
199  m_alignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
200  m_alignableMuon = std::make_unique<AlignableMuon>(&(*theMuonDT), &(*theMuonCSC), &(*theMuonGEM));
201  m_alignmentParameterStore = std::make_unique<AlignmentParameterStore>(empty_alignables, m_aliParamStoreCfg);
202 
203  for (auto const& monitor : m_monitors) {
204  monitor->beginOfJob(m_alignableTracker.get(), m_alignableMuon.get(), m_alignmentParameterStore.get());
205  }
206  for (auto const& monitor : m_monitors) {
207  monitor->startingNewLoop();
208  }
209 
210  m_firstEvent = false;
211  }
212 
213  // Retrieve trajectories and tracks from the event
214  const edm::Handle<TrajTrackAssociationCollection>& trajTracksMap = iEvent.getHandle(trajTrackToken_);
215 
216  // Form pairs of trajectories and tracks
217  ConstTrajTrackPairCollection trajTracks;
218  for (const auto& iPair : *trajTracksMap) {
219  trajTracks.push_back(ConstTrajTrackPair(&(*iPair.key), &(*iPair.val)));
220  }
221 
222  // Run the monitors
223  for (const auto& monitor : m_monitors) {
224  monitor->duringLoop(iEvent, iSetup, trajTracks);
225  }
226 }
227 
228 // ------------ method called once each job just before starting event loop ------------
230 
231 // ------------ method called once each job just after ending the event loop ------------
233  for (auto const& monitor : m_monitors) {
234  monitor->endOfLoop();
235  }
236  for (auto const& monitor : m_monitors) {
237  monitor->endOfJob();
238  }
239 }
240 
241 //define this as a plug-in
const edm::ESGetToken< PTrackerParameters, PTrackerParametersRcd > esTokenPTP_
const edm::ESGetToken< GeometricDet, IdealGeometryRecord > esTokenGeomDet_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd > esTokenTkAPE_
AlignmentMonitorAsAnalyzer(const edm::ParameterSet &)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
const edm::ESGetToken< Alignments, GlobalPositionRcd > esTokenGPR_
def create(alignables, pedeDump, additionalData, outputFile, config)
Class to update a given geometry with a set of alignments.
const edm::ESGetToken< AlignmentErrorsExtended, CSCAlignmentErrorExtendedRcd > esTokenCSCAPE_
const edm::EDGetTokenT< TrajTrackAssociationCollection > trajTrackToken_
const edm::ESGetToken< GEMGeometry, MuonGeometryRecord > esTokenGEM_
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > esTokenCSC_
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
~AlignmentMonitorAsAnalyzer() override=default
void applyAlignments(const C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
T getUntrackedParameter(std::string const &, T const &) const
const edm::ESGetToken< Alignments, DTAlignmentRcd > esTokenDTAl_
int iEvent
Definition: GenABIO.cc:224
const edm::ESGetToken< Alignments, CSCAlignmentRcd > esTokenCSCAl_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::unique_ptr< AlignableMuon > m_alignableMuon
const edm::ESGetToken< AlignmentErrorsExtended, GEMAlignmentErrorExtendedRcd > esTokenGEMAPE_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< AlignableTracker > m_alignableTracker
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > esTokenDT_
Definition: DetId.h:17
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > esTokenTTopo_
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
std::vector< std::unique_ptr< AlignmentMonitorBase > > m_monitors
HLT enums.
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
std::unique_ptr< AlignmentParameterStore > m_alignmentParameterStore
#define get
const edm::ESGetToken< AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd > esTokenDTAPE_
const edm::ESGetToken< Alignments, TrackerAlignmentRcd > esTokenTkAl_
std::pair< const Trajectory *, const reco::Track * > ConstTrajTrackPair
const edm::ESGetToken< Alignments, GEMAlignmentRcd > esTokenGEMAl_