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 
56 //
57 // class decleration
58 //
59 
61  public:
64 
65  typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
66  typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
67 
68  private:
69  virtual void beginJob() override;
70  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
71  virtual void endJob() override;
72 
73  // ----------member data ---------------------------
77 
81 
82  std::vector<AlignmentMonitorBase*> m_monitors;
84 
86 };
87 
88 //
89 // constants, enums and typedefs
90 //
91 
92 //
93 // static data member definitions
94 //
95 
96 //
97 // constructors and destructor
98 //
100  : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag"))
101  , m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore")),
102  m_pSet(iConfig)
103  , m_alignableTracker(NULL)
104  , m_alignableMuon(NULL)
105  , m_alignmentParameterStore(NULL)
106 {
107  std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
108 
109  for (std::vector<std::string>::const_iterator miter = monitors.begin(); miter != monitors.end(); ++miter) {
111 
112  if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
113 
114  m_monitors.push_back(newMonitor);
115  }
116 }
117 
118 
120 {
121  delete m_alignableTracker;
122  delete m_alignableMuon;
124 }
125 
126 
127 //
128 // member functions
129 //
130 
131 // ------------ method called to for each event ------------
132 void
134 {
135  //Retrieve tracker topology from geometry
136  edm::ESHandle<TrackerTopology> tTopoHandle;
137  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
138  const TrackerTopology* const tTopo = tTopoHandle.product();
139 
140  if (m_firstEvent) {
141  GeometryAligner aligner;
142 
144  iSetup.get<IdealGeometryRecord>().get( cpv );
145 
146  edm::ESHandle<GeometricDet> theGeometricDet;
147  iSetup.get<IdealGeometryRecord>().get( theGeometricDet );
148  TrackerGeomBuilderFromGeometricDet trackerBuilder;
149  boost::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(&(*theGeometricDet), m_pSet ));
150 
152  iSetup.get<MuonNumberingRecord>().get(mdc);
153  DTGeometryBuilderFromDDD DTGeometryBuilder;
155  boost::shared_ptr<DTGeometry> theMuonDT(new DTGeometry);
156  DTGeometryBuilder.build(theMuonDT, &(*cpv), *mdc);
157  boost::shared_ptr<CSCGeometry> theMuonCSC(new CSCGeometry);
158  CSCGeometryBuilder.build(theMuonCSC, &(*cpv), *mdc);
159 
160  edm::ESHandle<Alignments> globalPositionRcd;
161  iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
162 
163  edm::ESHandle<Alignments> alignments;
164  iSetup.get<TrackerAlignmentRcd>().get( alignments );
166  iSetup.get<TrackerAlignmentErrorExtendedRcd>().get( alignmentErrors );
167  aligner.applyAlignments<TrackerGeometry>( &(*theTracker), &(*alignments), &(*alignmentErrors),
168  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)) );
169 
170  edm::ESHandle<Alignments> dtAlignments;
171  iSetup.get<DTAlignmentRcd>().get( dtAlignments );
172  edm::ESHandle<AlignmentErrorsExtended> dtAlignmentErrorsExtended;
173  iSetup.get<DTAlignmentErrorExtendedRcd>().get( dtAlignmentErrorsExtended );
174  aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrorsExtended),
175  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
176 
177  edm::ESHandle<Alignments> cscAlignments;
178  iSetup.get<CSCAlignmentRcd>().get( cscAlignments );
179  edm::ESHandle<AlignmentErrorsExtended> cscAlignmentErrorsExtended;
180  iSetup.get<CSCAlignmentErrorExtendedRcd>().get( cscAlignmentErrorsExtended );
181  aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrorsExtended),
182  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
183 
184  // within an analyzer, modules can't expect to see any selected alignables!
185  std::vector<Alignable*> empty_alignables;
186 
187  m_alignableTracker = new AlignableTracker( &(*theTracker), tTopo );
188  m_alignableMuon = new AlignableMuon( &(*theMuonDT), &(*theMuonCSC) );
190 
191  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
193  }
194  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
195  (*monitor)->startingNewLoop();
196  }
197 
198  m_firstEvent = false;
199  }
200 
201  // Retrieve trajectories and tracks from the event
203  iEvent.getByLabel(m_tjTag, trajTracksMap);
204 
205  // Form pairs of trajectories and tracks
206  ConstTrajTrackPairCollection trajTracks;
207  for (TrajTrackAssociationCollection::const_iterator iPair = trajTracksMap->begin(); iPair != trajTracksMap->end(); ++iPair) {
208  trajTracks.push_back(ConstTrajTrackPair(&(*(*iPair).key), &(*(*iPair).val)));
209  }
210 
211  // Run the monitors
212  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
213  (*monitor)->duringLoop(iEvent, iSetup, trajTracks);
214  }
215 
216  // Keep this for endOfLoop (why does endOfLoop want iSetup???)
217  m_lastSetup = &iSetup;
218 }
219 
220 
221 // ------------ method called once each job just before starting event loop ------------
222 void
224 {
225  m_firstEvent = true;
226 }
227 
228 // ------------ method called once each job just after ending the event loop ------------
229 void
231 {
232  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
233  (*monitor)->endOfLoop(*m_lastSetup);
234  }
235  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
236  (*monitor)->endOfJob();
237  }
238 }
239 
240 //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
TrackerGeometry * build(const GeometricDet *gd, const edm::ParameterSet &pSet)
#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:405
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:55
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