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 
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 
107 };
108 
109 //
110 // constants, enums and typedefs
111 //
112 
113 //
114 // static data member definitions
115 //
116 
117 //
118 // constructors and destructor
119 //
121  : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag")),
122  m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore")),
123  esTokenTTopo_(esConsumes()),
124  esTokenGeomDet_(esConsumes()),
125  esTokenPTP_(esConsumes()),
126  esTokenPtitp_(esConsumes()),
127  esTokenDT_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
128  esTokenCSC_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
129  esTokenGEM_(esConsumes(edm::ESInputTag("", "idealForAlignmentMonitorAsAnalyzer"))),
130  esTokenGPR_(esConsumes()),
131  esTokenTkAl_(esConsumes()),
132  esTokenTkAPE_(esConsumes()),
133  esTokenDTAl_(esConsumes()),
134  esTokenDTAPE_(esConsumes()),
135  esTokenCSCAl_(esConsumes()),
136  esTokenCSCAPE_(esConsumes()),
137  esTokenGEMAl_(esConsumes()),
138  esTokenGEMAPE_(esConsumes()),
139  trajTrackToken_(consumes<TrajTrackAssociationCollection>(m_tjTag)) {
140  edm::ConsumesCollector consumeCollector = consumesCollector();
141  std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string>>("monitors");
142 
143  for (auto const& mon : monitors) {
145  mon, iConfig.getUntrackedParameter<edm::ParameterSet>(mon), consumeCollector));
146  }
147 }
148 
149 //
150 // member functions
151 //
152 
153 // ------------ method called to for each event ------------
155  //Retrieve tracker topology from geometry
156  const TrackerTopology* const tTopo = &iSetup.getData(esTokenTTopo_);
157 
158  if (m_firstEvent) {
159  GeometryAligner aligner;
160 
161  const GeometricDet* geom = &iSetup.getData(esTokenGeomDet_);
162  const PTrackerParameters& ptp = iSetup.getData(esTokenPTP_);
164  TrackerGeomBuilderFromGeometricDet trackerBuilder;
165  std::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(geom, ptitp, ptp, tTopo));
166 
167  edm::ESHandle<DTGeometry> theMuonDT = iSetup.getHandle(esTokenDT_);
168  edm::ESHandle<CSCGeometry> theMuonCSC = iSetup.getHandle(esTokenCSC_);
169  edm::ESHandle<GEMGeometry> theMuonGEM = iSetup.getHandle(esTokenGEM_);
170  edm::ESHandle<Alignments> globalPositionRcd = iSetup.getHandle(esTokenGPR_);
171 
172  const Alignments* alignments = &iSetup.getData(esTokenTkAl_);
173  const AlignmentErrorsExtended* alignmentErrors = &iSetup.getData(esTokenTkAPE_);
174  aligner.applyAlignments<TrackerGeometry>(&(*theTracker),
175  alignments,
176  alignmentErrors,
177  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)));
178 
179  edm::ESHandle<Alignments> dtAlignments = iSetup.getHandle(esTokenDTAl_);
180  edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended = iSetup.getHandle(esTokenDTAPE_);
181  aligner.applyAlignments<DTGeometry>(&(*theMuonDT),
182  &(*dtAlignments),
183  &(*dtAlignmentErrorsExtended),
184  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
185 
186  edm::ESHandle<Alignments> cscAlignments = iSetup.getHandle(esTokenCSCAl_);
187  edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended = iSetup.getHandle(esTokenCSCAPE_);
188  aligner.applyAlignments<CSCGeometry>(&(*theMuonCSC),
189  &(*cscAlignments),
190  &(*cscAlignmentErrorsExtended),
191  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
192 
193  edm::ESHandle<Alignments> gemAlignments = iSetup.getHandle(esTokenGEMAl_);
194  edm::ESHandle<AlignmentErrorsExtended> gemAlignmentErrorsExtended = iSetup.getHandle(esTokenGEMAPE_);
195  aligner.applyAlignments<GEMGeometry>(&(*theMuonGEM),
196  &(*gemAlignments),
197  &(*gemAlignmentErrorsExtended),
198  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)));
199 
200  // within an analyzer, modules can't expect to see any selected alignables!
201  align::Alignables empty_alignables;
202 
203  m_alignableTracker = std::make_unique<AlignableTracker>(&(*theTracker), tTopo);
204  m_alignableMuon = std::make_unique<AlignableMuon>(&(*theMuonDT), &(*theMuonCSC), &(*theMuonGEM));
205  m_alignmentParameterStore = std::make_unique<AlignmentParameterStore>(empty_alignables, m_aliParamStoreCfg);
206 
207  for (auto const& monitor : m_monitors) {
208  monitor->beginOfJob(m_alignableTracker.get(), m_alignableMuon.get(), m_alignmentParameterStore.get());
209  }
210  for (auto const& monitor : m_monitors) {
211  monitor->startingNewLoop();
212  }
213 
214  m_firstEvent = false;
215  }
216 
217  // Retrieve trajectories and tracks from the event
218  const edm::Handle<TrajTrackAssociationCollection>& trajTracksMap = iEvent.getHandle(trajTrackToken_);
219 
220  // Form pairs of trajectories and tracks
221  ConstTrajTrackPairCollection trajTracks;
222  for (const auto& iPair : *trajTracksMap) {
223  trajTracks.push_back(ConstTrajTrackPair(&(*iPair.key), &(*iPair.val)));
224  }
225 
226  // Run the monitors
227  for (const auto& monitor : m_monitors) {
228  monitor->duringLoop(iEvent, iSetup, trajTracks);
229  }
230 }
231 
232 // ------------ method called once each job just before starting event loop ------------
234 
235 // ------------ method called once each job just after ending the event loop ------------
237  for (auto const& monitor : m_monitors) {
238  monitor->endOfLoop();
239  }
240  for (auto const& monitor : m_monitors) {
241  monitor->endOfJob();
242  }
243 }
244 
245 //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 &)
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.
TrackerGeometry * build(const GeometricDet *gd, const PTrackerAdditionalParametersPerDet *ptitp, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
const edm::ESGetToken< AlignmentErrorsExtended, CSCAlignmentErrorExtendedRcd > esTokenCSCAPE_
const edm::EDGetTokenT< TrajTrackAssociationCollection > trajTrackToken_
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)
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
bool getData(T &iHolder) const
Definition: EventSetup.h:122
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
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_