CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoTracker/SpecialSeedGenerators/src/MuonReSeeder.cc

Go to the documentation of this file.
00001 
00002 //
00003 // $Id: MuonReSeeder.cc,v 1.3 2013/02/27 14:58:17 muzaffar Exp $
00004 //
00005 
00015 #include "FWCore/Framework/interface/EDProducer.h"
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00018 #include "FWCore/Utilities/interface/InputTag.h"
00019 
00020 #include "DataFormats/Math/interface/deltaR.h"
00021 
00022 #include "DataFormats/MuonReco/interface/Muon.h"
00023 #include "TrackingTools/TrackRefitter/interface/TrackTransformer.h"
00024 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00025 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00026 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00027 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00028 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00029 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00030 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00031 
00032 
00033 class MuonReSeeder : public edm::EDProducer {
00034     public:
00035       explicit MuonReSeeder(const edm::ParameterSet & iConfig);
00036       virtual ~MuonReSeeder() { }
00037 
00038       virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
00039 
00040     private:
00042       edm::InputTag src_;
00043 
00045       StringCutObjectSelector<reco::Muon> selector_;
00046 
00048       int layersToKeep_;
00049 
00051       bool insideOut_;
00052 
00054       bool debug_;
00055 
00057       TrackTransformer refitter_;
00058 
00059 };
00060 
00061 MuonReSeeder::MuonReSeeder(const edm::ParameterSet & iConfig) :
00062     src_(iConfig.getParameter<edm::InputTag>("src")),
00063     selector_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : "", true),
00064     layersToKeep_(iConfig.getParameter<int32_t>("layersToKeep")),
00065     insideOut_(iConfig.getParameter<bool>("insideOut")),
00066     debug_(iConfig.getUntrackedParameter<bool>("debug",false)),
00067     refitter_(iConfig)
00068 {
00069     produces<std::vector<TrajectorySeed> >(); 
00070 }
00071 
00072 void 
00073 MuonReSeeder::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
00074     using namespace edm;
00075     using namespace std;
00076 
00077     refitter_.setServices(iSetup);
00078 
00079     Handle<View<reco::Muon> > src;
00080     iEvent.getByLabel(src_, src);
00081 
00082     //Retrieve tracker topology from geometry
00083     edm::ESHandle<TrackerTopology> tTopo;
00084     iSetup.get<IdealGeometryRecord>().get(tTopo);
00085 
00086     auto_ptr<vector<TrajectorySeed> > out(new vector<TrajectorySeed>());
00087     unsigned int nsrc = src->size();
00088     out->reserve(nsrc);
00089 
00090     for (View<reco::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
00091         const reco::Muon &mu = *it;
00092         if (mu.track().isNull() || !selector_(mu)) continue;
00093         std::vector<Trajectory> traj  = refitter_.transform(*mu.track());
00094         if (traj.size() != 1) continue;
00095         edm::OwnVector<TrackingRecHit> seedHits;
00096         const std::vector<TrajectoryMeasurement> & tms = traj.front().measurements();
00097         TrajectoryStateOnSurface tsos; const TrackingRecHit *hit  = 0;
00098         bool fromInside = (insideOut_ == (traj.front().direction() == alongMomentum));
00099         if (debug_) {
00100             std::cout << "Considering muon of pt " << mu.pt() << ", eta = " << mu.eta() << ", phi = " << mu.phi() << std::endl;
00101             std::cout << "Trajectory is " << (traj.front().direction() == alongMomentum ? "along" : "opposite") << " to momentum, so will start from " << (fromInside ? "inside" : "outside") << std::endl;
00102         }
00103         const TrajectoryMeasurement & tin = (fromInside ? tms.front() : tms.back());
00104         const TrajectoryMeasurement & tou = (fromInside ? tms.front() : tms.back());
00105         if (debug_) {
00106             std::cout << "IN state: subdetector   = " << tin.recHit()->geographicalId().subdetId() << std::endl;
00107             std::cout << "          global pos Rho  " << tin.updatedState().globalPosition().perp() << ", Z   " << tin.updatedState().globalPosition().z() << std::endl;
00108             std::cout << "OU state: subdetector   = " << tou.recHit()->geographicalId().subdetId() << std::endl;
00109             std::cout << "          global pos Rho  " << tou.updatedState().globalPosition().perp() << ", Z   " << tou.updatedState().globalPosition().z() << std::endl;
00110         }
00111         int lastSubdet = 0, lastLayer = -1;
00112         for (int i    = (fromInside ? 0 : tms.size()-1),
00113                  end  = (fromInside ? tms.size() : -1),
00114                  step = (fromInside ? +1 : -1),
00115                  taken = 0; (end-i)*step > 0; i += step) {
00116             const TrackingRecHit *lastHit = hit;
00117             hit = tms[i].recHit()->hit();
00118             if (debug_) std::cout << "  considering hit " << i << ": rechit on " << (hit ? hit->geographicalId().rawId() : -1) << std::endl;
00119             if (!hit) continue;
00120             int subdet = hit->geographicalId().subdetId();
00121             int lay = tTopo->layer(hit->geographicalId());
00122             if (subdet != lastSubdet || lay != lastLayer) {
00123                 // I'm on a new layer
00124                 if (lastHit != 0 && taken == layersToKeep_) {
00125                     // I've had enough layers, I can stop here
00126                     hit = lastHit;
00127                     break;
00128                 } 
00129                 lastSubdet = subdet; lastLayer = lay;
00130                 taken++;
00131             }
00132             seedHits.push_back(*hit); 
00133             tsos = tms[i].updatedState().isValid() ? tms[i].updatedState() :
00134                           (abs(i-end) < abs(i) ? tms[i].forwardPredictedState() : tms[i].backwardPredictedState());
00135             if (debug_) {
00136                 std::cout << "     hit  : subdetector   = " << tms[i].recHit()->geographicalId().subdetId() << std::endl;
00137                 if (hit->isValid()) {
00138                     std::cout << "            global pos Rho  " << tms[i].recHit()->globalPosition().perp() << ", Z   " << tms[i].recHit()->globalPosition().z() << std::endl;
00139                 } else {
00140                     std::cout << "            invalid tracking rec hit, so no global position" << std::endl;
00141                 }
00142                 std::cout << "     state: global pos Rho  " << tsos.globalPosition().perp() << ", Z   " << tsos.globalPosition().z() << std::endl;
00143             }
00144         }
00145         if (!tsos.isValid()) continue;
00146         PTrajectoryStateOnDet const & PTraj = trajectoryStateTransform::persistentState(tsos, hit->geographicalId().rawId());
00147         TrajectorySeed seed(PTraj,std::move(seedHits),insideOut_ ? alongMomentum : oppositeToMomentum); 
00148         out->push_back(seed);
00149     }
00150 
00151     iEvent.put(out);
00152 }
00153 
00154 
00155 #include "FWCore/Framework/interface/MakerMacros.h"
00156 DEFINE_FWK_MODULE(MuonReSeeder);