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 
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;
89 
91 };
92 
93 //
94 // constants, enums and typedefs
95 //
96 
97 //
98 // static data member definitions
99 //
100 
101 //
102 // constructors and destructor
103 //
105  : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag"))
106  , m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore"))
107  , m_alignableTracker(NULL)
108  , m_alignableMuon(NULL)
109  , m_alignmentParameterStore(NULL)
110 {
111  std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
112 
113  for (std::vector<std::string>::const_iterator miter = monitors.begin(); miter != monitors.end(); ++miter) {
115 
116  if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
117 
118  m_monitors.push_back(newMonitor);
119  }
120 }
121 
122 
124 {
125  delete m_alignableTracker;
126  delete m_alignableMuon;
128 }
129 
130 
131 //
132 // member functions
133 //
134 
135 // ------------ method called to for each event ------------
136 void
138 {
139  //Retrieve tracker topology from geometry
140  edm::ESHandle<TrackerTopology> tTopoHandle;
141  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
142  const TrackerTopology* const tTopo = tTopoHandle.product();
143 
144  if (m_firstEvent) {
145  GeometryAligner aligner;
146 
148  iSetup.get<IdealGeometryRecord>().get( cpv );
149 
150  edm::ESHandle<GeometricDet> theGeometricDet;
151  iSetup.get<IdealGeometryRecord>().get( theGeometricDet );
153  iSetup.get<PTrackerParametersRcd>().get( ptp );
154  TrackerGeomBuilderFromGeometricDet trackerBuilder;
155  boost::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(&(*theGeometricDet), *ptp, tTopo ));
156 
158  iSetup.get<MuonNumberingRecord>().get(mdc);
159  DTGeometryBuilderFromDDD DTGeometryBuilder;
161  boost::shared_ptr<DTGeometry> theMuonDT(new DTGeometry);
162  DTGeometryBuilder.build(theMuonDT, &(*cpv), *mdc);
163  boost::shared_ptr<CSCGeometry> theMuonCSC(new CSCGeometry);
164  CSCGeometryBuilder.build(theMuonCSC, &(*cpv), *mdc);
165 
166  edm::ESHandle<Alignments> globalPositionRcd;
167  iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
168 
169  edm::ESHandle<Alignments> alignments;
170  iSetup.get<TrackerAlignmentRcd>().get( alignments );
172  iSetup.get<TrackerAlignmentErrorExtendedRcd>().get( alignmentErrors );
173  aligner.applyAlignments<TrackerGeometry>( &(*theTracker), &(*alignments), &(*alignmentErrors),
174  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)) );
175 
176  edm::ESHandle<Alignments> dtAlignments;
177  iSetup.get<DTAlignmentRcd>().get( dtAlignments );
178  edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended;
179  iSetup.get<DTAlignmentErrorExtendedRcd>().get( dtAlignmentErrorsExtended );
180  aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrorsExtended),
181  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
182 
183  edm::ESHandle<Alignments> cscAlignments;
184  iSetup.get<CSCAlignmentRcd>().get( cscAlignments );
185  edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended;
186  iSetup.get<CSCAlignmentErrorExtendedRcd>().get( cscAlignmentErrorsExtended );
187  aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrorsExtended),
188  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
189 
190  // within an analyzer, modules can't expect to see any selected alignables!
191  std::vector<Alignable*> empty_alignables;
192 
193  m_alignableTracker = new AlignableTracker( &(*theTracker), tTopo );
194  m_alignableMuon = new AlignableMuon( &(*theMuonDT), &(*theMuonCSC) );
196 
197  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
199  }
200  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
201  (*monitor)->startingNewLoop();
202  }
203 
204  m_firstEvent = false;
205  }
206 
207  // Retrieve trajectories and tracks from the event
209  iEvent.getByLabel(m_tjTag, trajTracksMap);
210 
211  // Form pairs of trajectories and tracks
212  ConstTrajTrackPairCollection trajTracks;
213  for (TrajTrackAssociationCollection::const_iterator iPair = trajTracksMap->begin(); iPair != trajTracksMap->end(); ++iPair) {
214  trajTracks.push_back(ConstTrajTrackPair(&(*(*iPair).key), &(*(*iPair).val)));
215  }
216 
217  // Run the monitors
218  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
219  (*monitor)->duringLoop(iEvent, iSetup, trajTracks);
220  }
221 
222  // Keep this for endOfLoop (why does endOfLoop want iSetup???)
223  m_lastSetup = &iSetup;
224 }
225 
226 
227 // ------------ method called once each job just before starting event loop ------------
228 void
230 {
231  m_firstEvent = true;
232 }
233 
234 // ------------ method called once each job just after ending the event loop ------------
235 void
237 {
238  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
239  (*monitor)->endOfLoop(*m_lastSetup);
240  }
241  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
242  (*monitor)->endOfJob();
243  }
244 }
245 
246 //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
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
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:418
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
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