00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <memory>
00023 #include <map>
00024 #include <fstream>
00025
00026
00027 #include "FWCore/Framework/interface/Frameworkfwd.h"
00028 #include "FWCore/Framework/interface/EDProducer.h"
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "FWCore/ParameterSet/interface/InputTag.h"
00033 #include "FWCore/Framework/interface/Event.h"
00034 #include "FWCore/Framework/interface/EventSetup.h"
00035
00036 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00037 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00038 #include "DataFormats/TrackReco/interface/Track.h"
00039 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00040 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00041 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00042 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00043 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00044 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00045 #include "DataFormats/DetId/interface/DetId.h"
00046 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00047 #include "FWCore/ServiceRegistry/interface/Service.h"
00048 #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
00049 #include "TH1F.h"
00050
00051
00052
00053
00054
00055 class AlignmentMuonHIPTrajectorySelector : public edm::EDProducer {
00056 public:
00057 explicit AlignmentMuonHIPTrajectorySelector(const edm::ParameterSet&);
00058 ~AlignmentMuonHIPTrajectorySelector();
00059
00060 private:
00061 virtual void beginJob(const edm::EventSetup&);
00062 virtual void produce(edm::Event&, const edm::EventSetup&);
00063 virtual void endJob();
00064
00065
00066 edm::InputTag m_input;
00067 double m_minPt;
00068 double m_maxTrackerForwardRedChi2;
00069 int m_minTrackerDOF;
00070 double m_maxMuonResidual;
00071
00072 bool m_hists;
00073 TH1F *m_pt, *m_tracker_forwardredchi2, *m_tracker_dof;
00074 TH1F *m_resid_before, *m_resid_after;
00075 };
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 AlignmentMuonHIPTrajectorySelector::AlignmentMuonHIPTrajectorySelector(const edm::ParameterSet& iConfig)
00090 : m_input(iConfig.getParameter<edm::InputTag>("input"))
00091 , m_minPt(iConfig.getParameter<double>("minPt"))
00092 , m_maxTrackerForwardRedChi2(iConfig.getParameter<double>("maxTrackerForwardRedChi2"))
00093 , m_minTrackerDOF(iConfig.getParameter<int>("minTrackerDOF"))
00094 , m_maxMuonResidual(iConfig.getParameter<double>("maxMuonResidual"))
00095 , m_hists(iConfig.getParameter<bool>("hists"))
00096 , m_pt(NULL), m_tracker_forwardredchi2(NULL), m_tracker_dof(NULL)
00097 {
00098 produces<TrajTrackAssociationCollection>();
00099
00100 if (m_hists) {
00101 edm::Service<TFileService> fs;
00102 m_pt = fs->make<TH1F>("pt", "Transverse momentum (GeV)", 100, 0., 100.);
00103 m_tracker_forwardredchi2 = fs->make<TH1F>("trackerForwardRedChi2", "forward-biased reduced chi2 in tracker", 100, 0., 5.);
00104 m_tracker_dof = fs->make<TH1F>("trackerDOF", "DOF in tracker", 61, -0.5, 60.5);
00105 m_resid_before = fs->make<TH1F>("residBefore", "muon residuals before cut (cm)", 100, -20, 20);
00106 m_resid_after = fs->make<TH1F>("residAfter", "muon residuals after cut (cm)", 100, -20, 20);
00107 }
00108 }
00109
00110
00111 AlignmentMuonHIPTrajectorySelector::~AlignmentMuonHIPTrajectorySelector() {}
00112
00113
00114
00115
00116
00117
00118
00119 void
00120 AlignmentMuonHIPTrajectorySelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00121 {
00122
00123 edm::Handle<TrajTrackAssociationCollection> originalTrajTrackMap;
00124 iEvent.getByLabel(m_input, originalTrajTrackMap);
00125
00126
00127 std::auto_ptr<TrajTrackAssociationCollection> newTrajTrackMap(new TrajTrackAssociationCollection());
00128
00129 TrajectoryStateCombiner tsoscomb;
00130
00131 for (TrajTrackAssociationCollection::const_iterator iPair = originalTrajTrackMap->begin(); iPair != originalTrajTrackMap->end(); ++iPair) {
00132 if (m_hists) {
00133 m_pt->Fill((*(*iPair).val).pt());
00134 }
00135
00136 if ((*(*iPair).val).pt() > m_minPt) {
00137
00138 std::vector<TrajectoryMeasurement> measurements = (*(*iPair).key).measurements();
00139
00140 bool has_bad_residual = false;
00141
00142 double tracker_forwardchi2 = 0.;
00143 double tracker_dof = 0.;
00144 for (std::vector<TrajectoryMeasurement>::const_iterator im = measurements.begin(); im != measurements.end(); ++im) {
00145 const TrajectoryMeasurement meas = *im;
00146 const TransientTrackingRecHit* hit = &(*meas.recHit());
00147 const DetId id = hit->geographicalId();
00148
00149 if (hit->isValid() && id.det() == DetId::Tracker) {
00150 if (hit->dimension() == 1) {
00151 double residual = meas.forwardPredictedState().localPosition().x() - hit->localPosition().x();
00152 double error2 = meas.forwardPredictedState().localError().positionError().xx() + hit->localPositionError().xx();
00153
00154 tracker_forwardchi2 += residual * residual / error2;
00155 tracker_dof += 1.;
00156 }
00157 else if (hit->dimension() == 2) {
00158 double residualx = meas.forwardPredictedState().localPosition().x() - hit->localPosition().x();
00159 double residualy = meas.forwardPredictedState().localPosition().y() - hit->localPosition().y();
00160 double errorxx2 = meas.forwardPredictedState().localError().positionError().xx() + hit->localPositionError().xx();
00161 double errorxy2 = meas.forwardPredictedState().localError().positionError().xy() + hit->localPositionError().xy();
00162 double erroryy2 = meas.forwardPredictedState().localError().positionError().yy() + hit->localPositionError().yy();
00163
00164 tracker_forwardchi2 += (residualx * residualx + residualy * residualy) / (errorxx2 + 2.*errorxy2 + erroryy2);
00165 tracker_dof += 2.;
00166 }
00167 }
00168
00169 if (hit->isValid() && id.det() == DetId::Muon && (id.subdetId() == MuonSubdetId::DT || id.subdetId() == MuonSubdetId::CSC)) {
00170 TrajectoryStateOnSurface tsosc = tsoscomb.combine(meas.forwardPredictedState(), meas.backwardPredictedState());
00171 double residual = tsosc.localPosition().x() - hit->localPosition().x();
00172 m_resid_before->Fill(residual);
00173 if (fabs(residual) > m_maxMuonResidual) {
00174 has_bad_residual = true;
00175 }
00176 }
00177
00178 }
00179 tracker_dof -= 5.;
00180 double tracker_forwardredchi2 = tracker_forwardchi2 / tracker_dof;
00181
00182 if (m_hists) {
00183 m_tracker_forwardredchi2->Fill(tracker_forwardredchi2);
00184 m_tracker_dof->Fill(tracker_dof);
00185
00186 for (std::vector<TrajectoryMeasurement>::const_iterator im = measurements.begin(); im != measurements.end(); ++im) {
00187 const TrajectoryMeasurement meas = *im;
00188 const TransientTrackingRecHit* hit = &(*meas.recHit());
00189 const DetId id = hit->geographicalId();
00190
00191 if (!has_bad_residual) {
00192 if (hit->isValid() && id.det() == DetId::Muon && (id.subdetId() == MuonSubdetId::DT || id.subdetId() == MuonSubdetId::CSC)) {
00193 TrajectoryStateOnSurface tsosc = tsoscomb.combine(meas.forwardPredictedState(), meas.backwardPredictedState());
00194 double residual = tsosc.localPosition().x() - hit->localPosition().x();
00195 m_resid_after->Fill(residual);
00196 }
00197 }
00198 }
00199 }
00200
00201 if (tracker_forwardredchi2 < m_maxTrackerForwardRedChi2 && tracker_dof >= m_minTrackerDOF && !has_bad_residual) {
00202 newTrajTrackMap->insert((*iPair).key, (*iPair).val);
00203 }
00204 }
00205 }
00206
00207
00208 iEvent.put(newTrajTrackMap);
00209 }
00210
00211
00212 void
00213 AlignmentMuonHIPTrajectorySelector::beginJob(const edm::EventSetup&) {}
00214
00215
00216 void
00217 AlignmentMuonHIPTrajectorySelector::endJob() {}
00218
00219
00220 DEFINE_FWK_MODULE(AlignmentMuonHIPTrajectorySelector);