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.5 2010/05/12 09:43:40 mussgill 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();
70  virtual void analyze(const edm::Event&, const edm::EventSetup&);
71  virtual void endJob();
72 
73  // ----------member data ---------------------------
76 
80 
81  std::vector<AlignmentMonitorBase*> m_monitors;
83 
85 };
86 
87 //
88 // constants, enums and typedefs
89 //
90 
91 //
92 // static data member definitions
93 //
94 
95 //
96 // constructors and destructor
97 //
99  : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag"))
100  , m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore"))
101  , m_alignableTracker(NULL)
102  , m_alignableMuon(NULL)
103  , m_alignmentParameterStore(NULL)
104 {
105  std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
106 
107  for (std::vector<std::string>::const_iterator miter = monitors.begin(); miter != monitors.end(); ++miter) {
109 
110  if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
111 
112  m_monitors.push_back(newMonitor);
113  }
114 }
115 
116 
118 {
119  delete m_alignableTracker;
120  delete m_alignableMuon;
122 }
123 
124 
125 //
126 // member functions
127 //
128 
129 // ------------ method called to for each event ------------
130 void
132 {
133  if (m_firstEvent) {
134  GeometryAligner aligner;
135 
137  iSetup.get<IdealGeometryRecord>().get( cpv );
138 
139  edm::ESHandle<GeometricDet> theGeometricDet;
140  iSetup.get<IdealGeometryRecord>().get( theGeometricDet );
141  TrackerGeomBuilderFromGeometricDet trackerBuilder;
142  boost::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(&(*theGeometricDet)));
143 
145  iSetup.get<MuonNumberingRecord>().get(mdc);
146  DTGeometryBuilderFromDDD DTGeometryBuilder;
148  boost::shared_ptr<DTGeometry> theMuonDT(new DTGeometry);
149  DTGeometryBuilder.build(theMuonDT, &(*cpv), *mdc);
150  boost::shared_ptr<CSCGeometry> theMuonCSC(new CSCGeometry);
151  CSCGeometryBuilder.build(theMuonCSC, &(*cpv), *mdc);
152 
153  edm::ESHandle<Alignments> globalPositionRcd;
154  iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
155 
156  edm::ESHandle<Alignments> alignments;
157  iSetup.get<TrackerAlignmentRcd>().get( alignments );
158  edm::ESHandle<AlignmentErrors> alignmentErrors;
159  iSetup.get<TrackerAlignmentErrorRcd>().get( alignmentErrors );
160  aligner.applyAlignments<TrackerGeometry>( &(*theTracker), &(*alignments), &(*alignmentErrors),
161  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)) );
162 
163  edm::ESHandle<Alignments> dtAlignments;
164  iSetup.get<DTAlignmentRcd>().get( dtAlignments );
165  edm::ESHandle<AlignmentErrors> dtAlignmentErrors;
166  iSetup.get<DTAlignmentErrorRcd>().get( dtAlignmentErrors );
167  aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrors),
168  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
169 
170  edm::ESHandle<Alignments> cscAlignments;
171  iSetup.get<CSCAlignmentRcd>().get( cscAlignments );
172  edm::ESHandle<AlignmentErrors> cscAlignmentErrors;
173  iSetup.get<CSCAlignmentErrorRcd>().get( cscAlignmentErrors );
174  aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrors),
175  align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
176 
177  // within an analyzer, modules can't expect to see any selected alignables!
178  std::vector<Alignable*> empty_alignables;
179 
180  m_alignableTracker = new AlignableTracker( &(*theTracker) );
181  m_alignableMuon = new AlignableMuon( &(*theMuonDT), &(*theMuonCSC) );
183 
184  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
186  }
187  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
188  (*monitor)->startingNewLoop();
189  }
190 
191  m_firstEvent = false;
192  }
193 
194  // Retrieve trajectories and tracks from the event
196  iEvent.getByLabel(m_tjTag, trajTracksMap);
197 
198  // Form pairs of trajectories and tracks
199  ConstTrajTrackPairCollection trajTracks;
200  for (TrajTrackAssociationCollection::const_iterator iPair = trajTracksMap->begin(); iPair != trajTracksMap->end(); ++iPair) {
201  trajTracks.push_back(ConstTrajTrackPair(&(*(*iPair).key), &(*(*iPair).val)));
202  }
203 
204  // Run the monitors
205  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
206  (*monitor)->duringLoop(iEvent, iSetup, trajTracks);
207  }
208 
209  // Keep this for endOfLoop (why does endOfLoop want iSetup???)
210  m_lastSetup = &iSetup;
211 }
212 
213 
214 // ------------ method called once each job just before starting event loop ------------
215 void
217 {
218  m_firstEvent = true;
219 }
220 
221 // ------------ method called once each job just after ending the event loop ------------
222 void
224 {
225  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
226  (*monitor)->endOfLoop(*m_lastSetup);
227  }
228  for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
229  (*monitor)->endOfJob();
230  }
231 }
232 
233 //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.
virtual void analyze(const edm::Event &, const edm::EventSetup &)
#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:243
std::vector< AlignmentMonitorBase * > m_monitors
void applyAlignments(C *geometry, const Alignments *alignments, const AlignmentErrors *alignmentErrors, const AlignTransform &globalCoordinates)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
AlignmentParameterStore * m_alignmentParameterStore
Definition: DetId.h:20
void build(boost::shared_ptr< DTGeometry > theGeometry, const DDCompactView *cview, const MuonDDDConstants &muonConstants)
const T & get() const
Definition: EventSetup.h:55
TrackerGeometry * build(const GeometricDet *gd)
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:56