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 
21 // system include files
22 #include <memory>
23 
24 // user include files
32 
38 
59 
61 
62 //
63 // class decleration
64 //
65 
67  public:
70 
71  typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
72  typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
73 
74  private:
75  virtual void beginJob() override;
76  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
77  virtual void endJob() override;
78 
79  // ----------member data ---------------------------
82 
86 
87  std::vector<AlignmentMonitorBase*> m_monitors;
88 
90 };
91 
92 //
93 // constants, enums and typedefs
94 //
95 
96 //
97 // static data member definitions
98 //
99 
100 //
101 // constructors and destructor
102 //
104  : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag"))
105  , m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore"))
109 {
110  std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
111 
112  for (std::vector<std::string>::const_iterator miter = monitors.begin(); miter != monitors.end(); ++miter) {
114 
115  if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
116 
117  m_monitors.push_back(newMonitor);
118  }
119 }
120 
121 
123 {
124  delete m_alignableTracker;
125  delete m_alignableMuon;
127 }
128 
129 
130 //
131 // member functions
132 //
133 
134 // ------------ method called to for each event ------------
135 void
137 {
138  //Retrieve tracker topology from geometry
139  edm::ESHandle<TrackerTopology> tTopoHandle;
140  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
141  const TrackerTopology* const tTopo = tTopoHandle.product();
142 
143  if (m_firstEvent) {
144  GeometryAligner aligner;
145 
147  iSetup.get<IdealGeometryRecord>().get( cpv );
148 
149  edm::ESHandle<GeometricDet> theGeometricDet;
150  iSetup.get<IdealGeometryRecord>().get( theGeometricDet );
152  iSetup.get<PTrackerParametersRcd>().get( ptp );
153  TrackerGeomBuilderFromGeometricDet trackerBuilder;
154  boost::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(&(*theGeometricDet), *ptp, tTopo ));
155 
157  iSetup.get<MuonNumberingRecord>().get(mdc);
158  DTGeometryBuilderFromDDD DTGeometryBuilder;
160  auto theMuonDT = std::make_shared<DTGeometry>();
161  DTGeometryBuilder.build(theMuonDT, &(*cpv), *mdc);
162  auto theMuonCSC = std::make_shared<CSCGeometry>();
163  CSCGeometryBuilder.build(theMuonCSC, &(*cpv), *mdc);
164 
165  edm::ESHandle<Alignments> globalPositionRcd;
166  iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
167 
168  edm::ESHandle<Alignments> alignments;
169  iSetup.get<TrackerAlignmentRcd>().get( alignments );
171  iSetup.get<TrackerAlignmentErrorExtendedRcd>().get( alignmentErrors );
172  aligner.applyAlignments<TrackerGeometry>( &(*theTracker), &(*alignments), &(*alignmentErrors),
173  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)) );
174 
175  edm::ESHandle<Alignments> dtAlignments;
176  iSetup.get<DTAlignmentRcd>().get( dtAlignments );
177  edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended;
178  iSetup.get<DTAlignmentErrorExtendedRcd>().get( dtAlignmentErrorsExtended );
179  aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrorsExtended),
180  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
181 
182  edm::ESHandle<Alignments> cscAlignments;
183  iSetup.get<CSCAlignmentRcd>().get( cscAlignments );
184  edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended;
185  iSetup.get<CSCAlignmentErrorExtendedRcd>().get( cscAlignmentErrorsExtended );
186  aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrorsExtended),
187  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
188 
189  // within an analyzer, modules can't expect to see any selected alignables!
190  std::vector<Alignable*> empty_alignables;
191 
192  m_alignableTracker = new AlignableTracker( &(*theTracker), tTopo );
193  m_alignableMuon = new AlignableMuon( &(*theMuonDT), &(*theMuonCSC) );
195 
196  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
198  }
199  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
200  (*monitor)->startingNewLoop();
201  }
202 
203  m_firstEvent = false;
204  }
205 
206  // Retrieve trajectories and tracks from the event
208  iEvent.getByLabel(m_tjTag, trajTracksMap);
209 
210  // Form pairs of trajectories and tracks
211  ConstTrajTrackPairCollection trajTracks;
212  for (TrajTrackAssociationCollection::const_iterator iPair = trajTracksMap->begin(); iPair != trajTracksMap->end(); ++iPair) {
213  trajTracks.push_back(ConstTrajTrackPair(&(*(*iPair).key), &(*(*iPair).val)));
214  }
215 
216  // Run the monitors
217  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
218  (*monitor)->duringLoop(iEvent, iSetup, trajTracks);
219  }
220 
221 }
222 
223 
224 // ------------ method called once each job just before starting event loop ------------
225 void
227 {
228  m_firstEvent = true;
229 }
230 
231 // ------------ method called once each job just after ending the event loop ------------
232 void
234 {
235  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
236  (*monitor)->endOfLoop();
237  }
238  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
239  (*monitor)->endOfJob();
240  }
241 }
242 
243 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
AlignmentMonitorAsAnalyzer(const edm::ParameterSet &)
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
const_iterator end() const
last iterator over the map (read only)
Class to update a given geometry with a set of alignments.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
#define NULL
Definition: scimark2.h:8
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
int iEvent
Definition: GenABIO.cc:230
std::vector< AlignmentMonitorBase * > m_monitors
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:416
AlignmentParameterStore * m_alignmentParameterStore
Definition: DetId.h:18
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrorsExtended *alignmentErrors, const AlignTransform &globalCoordinates)
const T & get() const
Definition: EventSetup.h:55
void build(std::shared_ptr< CSCGeometry > geom, const DDCompactView *fv, const MuonDDDConstants &muonConstants)
Build the geometry.
HLT enums.
void build(std::shared_ptr< DTGeometry > theGeometry, const DDCompactView *cview, const MuonDDDConstants &muonConstants)
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
const_iterator begin() const
first iterator over the map (read only)
Constructor of the full muon geometry.
Definition: AlignableMuon.h:37
T const * product() const
Definition: ESHandle.h:86
std::pair< const Trajectory *, const reco::Track * > ConstTrajTrackPair
T get(const Candidate &c)
Definition: component.h:55