CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
59 
61 
62 //
63 // class decleration
64 //
65 
67 public:
69  ~AlignmentMonitorAsAnalyzer() override = default;
70 
71  typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
72  typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
73 
74 private:
75  void beginJob() override;
76  void analyze(const edm::Event&, const edm::EventSetup&) override;
77  void endJob() override;
78 
79  // ----------member data ---------------------------
82 
83  std::unique_ptr<AlignableTracker> m_alignableTracker;
84  std::unique_ptr<AlignableMuon> m_alignableMuon;
85  std::unique_ptr<AlignmentParameterStore> m_alignmentParameterStore;
86 
87  std::vector<std::unique_ptr<AlignmentMonitorBase>> m_monitors;
88 
106 };
107 
108 //
109 // constants, enums and typedefs
110 //
111 
112 //
113 // static data member definitions
114 //
115 
116 //
117 // constructors and destructor
118 //
120  : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag")),
121  m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore")),
122  esTokenTTopo_(esConsumes()),
123  esTokenGeomDet_(esConsumes()),
124  esTokenPTP_(esConsumes()),
125  esTokenPtitp_(esConsumes()),
126  esTokenDT_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
127  esTokenCSC_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
128  esTokenGEM_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
129  esTokenGPR_(esConsumes()),
130  esTokenTkAl_(esConsumes()),
131  esTokenTkAPE_(esConsumes()),
132  esTokenDTAl_(esConsumes()),
133  esTokenDTAPE_(esConsumes()),
134  esTokenCSCAl_(esConsumes()),
135  esTokenCSCAPE_(esConsumes()),
136  esTokenGEMAl_(esConsumes()),
137  esTokenGEMAPE_(esConsumes()) {
138  edm::ConsumesCollector consumeCollector = consumesCollector();
139  std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string>>("monitors");
140 
141  for (auto const& mon : monitors) {
143  mon, iConfig.getUntrackedParameter<edm::ParameterSet>(mon), consumeCollector));
144  }
145 }
146 
147 //
148 // member functions
149 //
150 
151 // ------------ method called to for each event ------------
153  //Retrieve tracker topology from geometry
154  const TrackerTopology* const tTopo = &iSetup.getData(esTokenTTopo_);
155 
156  if (m_firstEvent) {
157  GeometryAligner aligner;
158 
159  const GeometricDet* geom = &iSetup.getData(esTokenGeomDet_);
160  const PTrackerParameters& ptp = iSetup.getData(esTokenPTP_);
162  TrackerGeomBuilderFromGeometricDet trackerBuilder;
163  std::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(geom, ptitp, ptp, tTopo));
164 
165  edm::ESHandle<DTGeometry> theMuonDT = iSetup.getHandle(esTokenDT_);
166  edm::ESHandle<CSCGeometry> theMuonCSC = iSetup.getHandle(esTokenCSC_);
167  edm::ESHandle<GEMGeometry> theMuonGEM = iSetup.getHandle(esTokenGEM_);
168  edm::ESHandle<Alignments> globalPositionRcd = iSetup.getHandle(esTokenGPR_);
169 
170  const Alignments* alignments = &iSetup.getData(esTokenTkAl_);
171  const AlignmentErrorsExtended* alignmentErrors = &iSetup.getData(esTokenTkAPE_);
172  aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
173  alignments,
174  alignmentErrors,
175  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
176 
177  edm::ESHandle<Alignments> dtAlignments = iSetup.getHandle(esTokenDTAl_);
178  edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended = iSetup.getHandle(esTokenDTAPE_);
179  aligner.applyAlignments<DTGeometry>(&(*theMuonDT),
180  &(*dtAlignments),
181  &(*dtAlignmentErrorsExtended),
182  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
183 
184  edm::ESHandle<Alignments> cscAlignments = iSetup.getHandle(esTokenCSCAl_);
185  edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended = iSetup.getHandle(esTokenCSCAPE_);
186  aligner.applyAlignments<CSCGeometry>(&(*theMuonCSC),
187  &(*cscAlignments),
188  &(*cscAlignmentErrorsExtended),
189  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
190 
191  edm::ESHandle<Alignments> gemAlignments = iSetup.getHandle(esTokenGEMAl_);
192  edm::ESHandle<AlignmentErrorsExtended> gemAlignmentErrorsExtended = iSetup.getHandle(esTokenGEMAPE_);
193  aligner.applyAlignments<GEMGeometry>(&(*theMuonGEM),
194  &(*gemAlignments),
195  &(*gemAlignmentErrorsExtended),
196  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
197 
198  // within an analyzer, modules can't expect to see any selected alignables!
199  align::Alignables empty_alignables;
200 
201  m_alignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
202  m_alignableMuon = std::make_unique<AlignableMuon>(&(*theMuonDT), &(*theMuonCSC), &(*theMuonGEM));
203  m_alignmentParameterStore = std::make_unique<AlignmentParameterStore>(empty_alignables, m_aliParamStoreCfg);
204 
205  for (auto const& monitor : m_monitors) {
206  monitor->beginOfJob(m_alignableTracker.get(), m_alignableMuon.get(), m_alignmentParameterStore.get());
207  }
208  for (auto const& monitor : m_monitors) {
209  monitor->startingNewLoop();
210  }
211 
212  m_firstEvent = false;
213  }
214 
215  // Retrieve trajectories and tracks from the event
217  iEvent.getByLabel(m_tjTag, trajTracksMap);
218 
219  // Form pairs of trajectories and tracks
220  ConstTrajTrackPairCollection trajTracks;
221  for (const auto& iPair : *trajTracksMap) {
222  trajTracks.push_back(ConstTrajTrackPair(&(*iPair.key), &(*iPair.val)));
223  }
224 
225  // Run the monitors
226  for (const auto& monitor : m_monitors) {
227  monitor->duringLoop(iEvent, iSetup, trajTracks);
228  }
229 }
230 
231 // ------------ method called once each job just before starting event loop ------------
233 
234 // ------------ method called once each job just after ending the event loop ------------
236  for (auto const& monitor : m_monitors) {
237  monitor->endOfLoop();
238  }
239  for (auto const& monitor : m_monitors) {
240  monitor->endOfJob();
241  }
242 }
243 
244 //define this as a plug-in
const edm::ESGetToken< PTrackerParameters, PTrackerParametersRcd > esTokenPTP_
T getUntrackedParameter(std::string const &, T const &) const
const edm::ESGetToken< GeometricDet, IdealGeometryRecord > esTokenGeomDet_
const edm::ESGetToken< AlignmentErrorsExtended, TrackerAlignmentErrorExtendedRcd > esTokenTkAPE_
AlignmentMonitorAsAnalyzer(const edm::ParameterSet &)
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
const edm::ESGetToken< Alignments, GlobalPositionRcd > esTokenGPR_
Class to update a given geometry with a set of alignments.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrackerGeometry * build(const GeometricDet *gd, const PTrackerAdditionalParametersPerDet *ptitp, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
const edm::ESGetToken< AlignmentErrorsExtended, CSCAlignmentErrorExtendedRcd > esTokenCSCAPE_
const edm::ESGetToken< GEMGeometry, MuonGeometryRecord > esTokenGEM_
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > esTokenCSC_
~AlignmentMonitorAsAnalyzer() override=default
const edm::ESGetToken< PTrackerAdditionalParametersPerDet, PTrackerAdditionalParametersPerDetRcd > esTokenPtitp_
void applyAlignments(const C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
const edm::ESGetToken< Alignments, DTAlignmentRcd > esTokenDTAl_
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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_
std::unique_ptr< AlignableTracker > m_alignableTracker
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > esTokenDT_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
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
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
std::unique_ptr< AlignmentParameterStore > m_alignmentParameterStore
#define get
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
const edm::ESGetToken< AlignmentErrorsExtended, DTAlignmentErrorExtendedRcd > esTokenDTAPE_
const edm::ESGetToken< Alignments, TrackerAlignmentRcd > esTokenTkAl_
std::pair< const Trajectory *, const reco::Track * > ConstTrajTrackPair
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< Alignments, GEMAlignmentRcd > esTokenGEMAl_