CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
21 // system include files
22 #include <memory>
23 
24 // user include files
32 
38 
59 //
60 // class decleration
61 //
62 
64  public:
67 
68  typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
69  typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
70 
71  private:
72  virtual void beginJob() override;
73  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
74  virtual void endJob() override;
75 
76  // ----------member data ---------------------------
79 
83 
84  std::vector<AlignmentMonitorBase*> m_monitors;
86 
88 };
89 
90 //
91 // constants, enums and typedefs
92 //
93 
94 //
95 // static data member definitions
96 //
97 
98 //
99 // constructors and destructor
100 //
102  : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag"))
103  , m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore"))
104  , m_alignableTracker(NULL)
105  , m_alignableMuon(NULL)
106  , m_alignmentParameterStore(NULL)
107 {
108  std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
109 
110  for (std::vector<std::string>::const_iterator miter = monitors.begin(); miter != monitors.end(); ++miter) {
112 
113  if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
114 
115  m_monitors.push_back(newMonitor);
116  }
117 }
118 
119 
121 {
122  delete m_alignableTracker;
123  delete m_alignableMuon;
125 }
126 
127 
128 //
129 // member functions
130 //
131 
132 // ------------ method called to for each event ------------
133 void
135 {
136  //Retrieve tracker topology from geometry
137  edm::ESHandle<TrackerTopology> tTopoHandle;
138  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
139  const TrackerTopology* const tTopo = tTopoHandle.product();
140 
141  if (m_firstEvent) {
142  GeometryAligner aligner;
143 
145  iSetup.get<IdealGeometryRecord>().get( cpv );
146 
147  edm::ESHandle<GeometricDet> theGeometricDet;
148  iSetup.get<IdealGeometryRecord>().get( theGeometricDet );
150  iSetup.get<PTrackerParametersRcd>().get( ptp );
151  TrackerGeomBuilderFromGeometricDet trackerBuilder;
152  boost::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(&(*theGeometricDet), *ptp ));
153 
155  iSetup.get<MuonNumberingRecord>().get(mdc);
156  DTGeometryBuilderFromDDD DTGeometryBuilder;
158  boost::shared_ptr<DTGeometry> theMuonDT(new DTGeometry);
159  DTGeometryBuilder.build(theMuonDT, &(*cpv), *mdc);
160  boost::shared_ptr<CSCGeometry> theMuonCSC(new CSCGeometry);
161  CSCGeometryBuilder.build(theMuonCSC, &(*cpv), *mdc);
162 
163  edm::ESHandle<Alignments> globalPositionRcd;
164  iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
165 
166  edm::ESHandle<Alignments> alignments;
167  iSetup.get<TrackerAlignmentRcd>().get( alignments );
169  iSetup.get<TrackerAlignmentErrorExtendedRcd>().get( alignmentErrors );
170  aligner.applyAlignments<TrackerGeometry>( &(*theTracker), &(*alignments), &(*alignmentErrors),
171  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)) );
172 
173  edm::ESHandle<Alignments> dtAlignments;
174  iSetup.get<DTAlignmentRcd>().get( dtAlignments );
175  edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended;
176  iSetup.get<DTAlignmentErrorExtendedRcd>().get( dtAlignmentErrorsExtended );
177  aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrorsExtended),
178  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
179 
180  edm::ESHandle<Alignments> cscAlignments;
181  iSetup.get<CSCAlignmentRcd>().get( cscAlignments );
182  edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended;
183  iSetup.get<CSCAlignmentErrorExtendedRcd>().get( cscAlignmentErrorsExtended );
184  aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrorsExtended),
185  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
186 
187  // within an analyzer, modules can't expect to see any selected alignables!
188  std::vector<Alignable*> empty_alignables;
189 
190  m_alignableTracker = new AlignableTracker( &(*theTracker), tTopo );
191  m_alignableMuon = new AlignableMuon( &(*theMuonDT), &(*theMuonCSC) );
193 
194  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
196  }
197  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
198  (*monitor)->startingNewLoop();
199  }
200 
201  m_firstEvent = false;
202  }
203 
204  // Retrieve trajectories and tracks from the event
206  iEvent.getByLabel(m_tjTag, trajTracksMap);
207 
208  // Form pairs of trajectories and tracks
209  ConstTrajTrackPairCollection trajTracks;
210  for (TrajTrackAssociationCollection::const_iterator iPair = trajTracksMap->begin(); iPair != trajTracksMap->end(); ++iPair) {
211  trajTracks.push_back(ConstTrajTrackPair(&(*(*iPair).key), &(*(*iPair).val)));
212  }
213 
214  // Run the monitors
215  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
216  (*monitor)->duringLoop(iEvent, iSetup, trajTracks);
217  }
218 
219  // Keep this for endOfLoop (why does endOfLoop want iSetup???)
220  m_lastSetup = &iSetup;
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(*m_lastSetup);
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
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
void build(boost::shared_ptr< CSCGeometry > geom, const DDCompactView *fv, const MuonDDDConstants &muonConstants)
Build the geometry.
int iEvent
Definition: GenABIO.cc:230
std::vector< AlignmentMonitorBase * > m_monitors
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
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)
void build(boost::shared_ptr< DTGeometry > theGeometry, const DDCompactView *cview, const MuonDDDConstants &muonConstants)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp)
const AlignTransform & DetectorGlobalPosition(const Alignments &allGlobals, const DetId &id)
Constructor of the full muon geometry.
Definition: AlignableMuon.h:36
std::pair< const Trajectory *, const reco::Track * > ConstTrajTrackPair
T get(const Candidate &c)
Definition: component.h:55