Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023
00024
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 #include "FWCore/Framework/interface/Event.h"
00028 #include "FWCore/Framework/interface/MakerMacros.h"
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 #include "FWCore/Framework/interface/ESTransientHandle.h"
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032
00033 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorBase.h"
00034 #include "Alignment/CommonAlignmentMonitor/interface/AlignmentMonitorPluginFactory.h"
00035 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00036 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignmentParameterStore.h"
00037 #include "Alignment/CommonAlignment/interface/Alignable.h"
00038
00039 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00040 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeomBuilderFromGeometricDet.h"
00041 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00042 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00043 #include "Geometry/Records/interface/MuonNumberingRecord.h"
00044 #include "Geometry/MuonNumbering/interface/MuonDDDConstants.h"
00045 #include "Geometry/DTGeometryBuilder/src/DTGeometryBuilderFromDDD.h"
00046 #include "Geometry/CSCGeometryBuilder/src/CSCGeometryBuilderFromDDD.h"
00047 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00048 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentRcd.h"
00049 #include "CondFormats/AlignmentRecord/interface/TrackerAlignmentErrorRcd.h"
00050 #include "CondFormats/AlignmentRecord/interface/DTAlignmentRcd.h"
00051 #include "CondFormats/AlignmentRecord/interface/DTAlignmentErrorRcd.h"
00052 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentRcd.h"
00053 #include "CondFormats/AlignmentRecord/interface/CSCAlignmentErrorRcd.h"
00054 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00055 #include "CondFormats/Alignment/interface/DetectorGlobalPosition.h"
00056
00057
00058
00059
00060 class AlignmentMonitorAsAnalyzer : public edm::EDAnalyzer {
00061 public:
00062 explicit AlignmentMonitorAsAnalyzer(const edm::ParameterSet&);
00063 ~AlignmentMonitorAsAnalyzer();
00064
00065 typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
00066 typedef std::vector<ConstTrajTrackPair> ConstTrajTrackPairCollection;
00067
00068 private:
00069 virtual void beginJob();
00070 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00071 virtual void endJob();
00072
00073
00074 edm::InputTag m_tjTag;
00075 edm::ParameterSet m_aliParamStoreCfg;
00076
00077 AlignableTracker *m_alignableTracker;
00078 AlignableMuon *m_alignableMuon;
00079 AlignmentParameterStore *m_alignmentParameterStore;
00080
00081 std::vector<AlignmentMonitorBase*> m_monitors;
00082 const edm::EventSetup *m_lastSetup;
00083
00084 bool m_firstEvent;
00085 };
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 AlignmentMonitorAsAnalyzer::AlignmentMonitorAsAnalyzer(const edm::ParameterSet& iConfig)
00099 : m_tjTag(iConfig.getParameter<edm::InputTag>("tjTkAssociationMapTag"))
00100 , m_aliParamStoreCfg(iConfig.getParameter<edm::ParameterSet>("ParameterStore"))
00101 , m_alignableTracker(NULL)
00102 , m_alignableMuon(NULL)
00103 , m_alignmentParameterStore(NULL)
00104 {
00105 std::vector<std::string> monitors = iConfig.getUntrackedParameter<std::vector<std::string> >( "monitors" );
00106
00107 for (std::vector<std::string>::const_iterator miter = monitors.begin(); miter != monitors.end(); ++miter) {
00108 AlignmentMonitorBase* newMonitor = AlignmentMonitorPluginFactory::get()->create(*miter, iConfig.getUntrackedParameter<edm::ParameterSet>(*miter));
00109
00110 if (!newMonitor) throw cms::Exception("BadConfig") << "Couldn't find monitor named " << *miter;
00111
00112 m_monitors.push_back(newMonitor);
00113 }
00114 }
00115
00116
00117 AlignmentMonitorAsAnalyzer::~AlignmentMonitorAsAnalyzer()
00118 {
00119 delete m_alignableTracker;
00120 delete m_alignableMuon;
00121 delete m_alignmentParameterStore;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130 void
00131 AlignmentMonitorAsAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00132 {
00133 if (m_firstEvent) {
00134 GeometryAligner aligner;
00135
00136 edm::ESTransientHandle<DDCompactView> cpv;
00137 iSetup.get<IdealGeometryRecord>().get( cpv );
00138
00139 edm::ESHandle<GeometricDet> theGeometricDet;
00140 iSetup.get<IdealGeometryRecord>().get( theGeometricDet );
00141 TrackerGeomBuilderFromGeometricDet trackerBuilder;
00142 boost::shared_ptr<TrackerGeometry> theTracker(trackerBuilder.build(&(*theGeometricDet)));
00143
00144 edm::ESHandle<MuonDDDConstants> mdc;
00145 iSetup.get<MuonNumberingRecord>().get(mdc);
00146 DTGeometryBuilderFromDDD DTGeometryBuilder;
00147 CSCGeometryBuilderFromDDD CSCGeometryBuilder;
00148 boost::shared_ptr<DTGeometry> theMuonDT(new DTGeometry);
00149 DTGeometryBuilder.build(theMuonDT, &(*cpv), *mdc);
00150 boost::shared_ptr<CSCGeometry> theMuonCSC(new CSCGeometry);
00151 CSCGeometryBuilder.build(theMuonCSC, &(*cpv), *mdc);
00152
00153 edm::ESHandle<Alignments> globalPositionRcd;
00154 iSetup.get<GlobalPositionRcd>().get(globalPositionRcd);
00155
00156 edm::ESHandle<Alignments> alignments;
00157 iSetup.get<TrackerAlignmentRcd>().get( alignments );
00158 edm::ESHandle<AlignmentErrors> alignmentErrors;
00159 iSetup.get<TrackerAlignmentErrorRcd>().get( alignmentErrors );
00160 aligner.applyAlignments<TrackerGeometry>( &(*theTracker), &(*alignments), &(*alignmentErrors),
00161 align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Tracker)) );
00162
00163 edm::ESHandle<Alignments> dtAlignments;
00164 iSetup.get<DTAlignmentRcd>().get( dtAlignments );
00165 edm::ESHandle<AlignmentErrors> dtAlignmentErrors;
00166 iSetup.get<DTAlignmentErrorRcd>().get( dtAlignmentErrors );
00167 aligner.applyAlignments<DTGeometry>( &(*theMuonDT), &(*dtAlignments), &(*dtAlignmentErrors),
00168 align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
00169
00170 edm::ESHandle<Alignments> cscAlignments;
00171 iSetup.get<CSCAlignmentRcd>().get( cscAlignments );
00172 edm::ESHandle<AlignmentErrors> cscAlignmentErrors;
00173 iSetup.get<CSCAlignmentErrorRcd>().get( cscAlignmentErrors );
00174 aligner.applyAlignments<CSCGeometry>( &(*theMuonCSC), &(*cscAlignments), &(*cscAlignmentErrors),
00175 align::DetectorGlobalPosition(*globalPositionRcd, DetId(DetId::Muon)) );
00176
00177
00178 std::vector<Alignable*> empty_alignables;
00179
00180 m_alignableTracker = new AlignableTracker( &(*theTracker) );
00181 m_alignableMuon = new AlignableMuon( &(*theMuonDT), &(*theMuonCSC) );
00182 m_alignmentParameterStore = new AlignmentParameterStore(empty_alignables, m_aliParamStoreCfg);
00183
00184 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
00185 (*monitor)->beginOfJob(m_alignableTracker, m_alignableMuon, m_alignmentParameterStore);
00186 }
00187 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
00188 (*monitor)->startingNewLoop();
00189 }
00190
00191 m_firstEvent = false;
00192 }
00193
00194
00195 edm::Handle<TrajTrackAssociationCollection> trajTracksMap;
00196 iEvent.getByLabel(m_tjTag, trajTracksMap);
00197
00198
00199 ConstTrajTrackPairCollection trajTracks;
00200 for (TrajTrackAssociationCollection::const_iterator iPair = trajTracksMap->begin(); iPair != trajTracksMap->end(); ++iPair) {
00201 trajTracks.push_back(ConstTrajTrackPair(&(*(*iPair).key), &(*(*iPair).val)));
00202 }
00203
00204
00205 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
00206 (*monitor)->duringLoop(iEvent, iSetup, trajTracks);
00207 }
00208
00209
00210 m_lastSetup = &iSetup;
00211 }
00212
00213
00214
00215 void
00216 AlignmentMonitorAsAnalyzer::beginJob()
00217 {
00218 m_firstEvent = true;
00219 }
00220
00221
00222 void
00223 AlignmentMonitorAsAnalyzer::endJob()
00224 {
00225 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
00226 (*monitor)->endOfLoop(*m_lastSetup);
00227 }
00228 for (std::vector<AlignmentMonitorBase*>::const_iterator monitor = m_monitors.begin(); monitor != m_monitors.end(); ++monitor) {
00229 (*monitor)->endOfJob();
00230 }
00231 }
00232
00233
00234 DEFINE_FWK_MODULE(AlignmentMonitorAsAnalyzer);