CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/RecoTracker/SpecialSeedGenerators/src/MuonReSeeder.cc

Go to the documentation of this file.
00001 
00002 //
00003 // $Id: MuonReSeeder.cc,v 1.1 2012/09/12 15:58:08 gpetrucc 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/SiPixelDetId/interface/PXBDetId.h"
00030 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00031 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00032 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00033 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00034 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00035 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00036 
00037 
00038 class MuonReSeeder : public edm::EDProducer {
00039     public:
00040       explicit MuonReSeeder(const edm::ParameterSet & iConfig);
00041       virtual ~MuonReSeeder() { }
00042 
00043       virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
00044 
00045     private:
00047       edm::InputTag src_;
00048 
00050       StringCutObjectSelector<reco::Muon> selector_;
00051 
00053       int layersToKeep_;
00054 
00056       bool insideOut_;
00057 
00059       bool debug_;
00060 
00062       TrackTransformer refitter_;
00063 
00064       // utility
00065       int layer(DetId detid) const ;
00066 };
00067 
00068 MuonReSeeder::MuonReSeeder(const edm::ParameterSet & iConfig) :
00069     src_(iConfig.getParameter<edm::InputTag>("src")),
00070     selector_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : "", true),
00071     layersToKeep_(iConfig.getParameter<int32_t>("layersToKeep")),
00072     insideOut_(iConfig.getParameter<bool>("insideOut")),
00073     debug_(iConfig.getUntrackedParameter<bool>("debug",false)),
00074     refitter_(iConfig)
00075 {
00076     produces<std::vector<TrajectorySeed> >(); 
00077 }
00078 
00079 void 
00080 MuonReSeeder::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
00081     using namespace edm;
00082     using namespace std;
00083 
00084     refitter_.setServices(iSetup);
00085 
00086     Handle<View<reco::Muon> > src;
00087     iEvent.getByLabel(src_, src);
00088 
00089 
00090     auto_ptr<vector<TrajectorySeed> > out(new vector<TrajectorySeed>());
00091     unsigned int nsrc = src->size();
00092     out->reserve(nsrc);
00093 
00094     for (View<reco::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
00095         const reco::Muon &mu = *it;
00096         if (mu.track().isNull() || !selector_(mu)) continue;
00097         std::vector<Trajectory> traj  = refitter_.transform(*mu.track());
00098         if (traj.size() != 1) continue;
00099         edm::OwnVector<TrackingRecHit> seedHits;
00100         const std::vector<TrajectoryMeasurement> & tms = traj.front().measurements();
00101         TrajectoryStateOnSurface tsos; const TrackingRecHit *hit  = 0;
00102         bool fromInside = (insideOut_ == (traj.front().direction() == alongMomentum));
00103         if (debug_) {
00104             std::cout << "Considering muon of pt " << mu.pt() << ", eta = " << mu.eta() << ", phi = " << mu.phi() << std::endl;
00105             std::cout << "Trajectory is " << (traj.front().direction() == alongMomentum ? "along" : "opposite") << " to momentum, so will start from " << (fromInside ? "inside" : "outside") << std::endl;
00106         }
00107         const TrajectoryMeasurement & tin = (fromInside ? tms.front() : tms.back());
00108         const TrajectoryMeasurement & tou = (fromInside ? tms.front() : tms.back());
00109         if (debug_) {
00110             std::cout << "IN state: subdetector   = " << tin.recHit()->geographicalId().subdetId() << std::endl;
00111             std::cout << "          global pos Rho  " << tin.updatedState().globalPosition().perp() << ", Z   " << tin.updatedState().globalPosition().z() << std::endl;
00112             std::cout << "OU state: subdetector   = " << tou.recHit()->geographicalId().subdetId() << std::endl;
00113             std::cout << "          global pos Rho  " << tou.updatedState().globalPosition().perp() << ", Z   " << tou.updatedState().globalPosition().z() << std::endl;
00114         }
00115         int lastSubdet = 0, lastLayer = -1;
00116         for (int i    = (fromInside ? 0 : tms.size()-1),
00117                  end  = (fromInside ? tms.size() : -1),
00118                  step = (fromInside ? +1 : -1),
00119                  taken = 0; (end-i)*step > 0; i += step) {
00120             const TrackingRecHit *lastHit = hit;
00121             hit = tms[i].recHit()->hit();
00122             if (debug_) std::cout << "  considering hit " << i << ": rechit on " << (hit ? hit->geographicalId().rawId() : -1) << std::endl;
00123             if (!hit) continue;
00124             int subdet = hit->geographicalId().subdetId(), lay = layer(hit->geographicalId());
00125             if (subdet != lastSubdet || lay != lastLayer) {
00126                 // I'm on a new layer
00127                 if (lastHit != 0 && taken == layersToKeep_) {
00128                     // I've had enough layers, I can stop here
00129                     hit = lastHit;
00130                     break;
00131                 } 
00132                 lastSubdet = subdet; lastLayer = lay;
00133                 taken++;
00134             }
00135             seedHits.push_back(*hit); 
00136             tsos = tms[i].updatedState().isValid() ? tms[i].updatedState() :
00137                           (abs(i-end) < abs(i) ? tms[i].forwardPredictedState() : tms[i].backwardPredictedState());
00138             if (debug_) {
00139                 std::cout << "     hit  : subdetector   = " << tms[i].recHit()->geographicalId().subdetId() << std::endl;
00140                 if (hit->isValid()) {
00141                     std::cout << "            global pos Rho  " << tms[i].recHit()->globalPosition().perp() << ", Z   " << tms[i].recHit()->globalPosition().z() << std::endl;
00142                 } else {
00143                     std::cout << "            invalid tracking rec hit, so no global position" << std::endl;
00144                 }
00145                 std::cout << "     state: global pos Rho  " << tsos.globalPosition().perp() << ", Z   " << tsos.globalPosition().z() << std::endl;
00146             }
00147         }
00148         if (!tsos.isValid()) continue;
00149         PTrajectoryStateOnDet const & PTraj = trajectoryStateTransform::persistentState(tsos, hit->geographicalId().rawId());
00150         TrajectorySeed seed(PTraj,std::move(seedHits),insideOut_ ? alongMomentum : oppositeToMomentum); 
00151         out->push_back(seed);
00152     }
00153 
00154     iEvent.put(out);
00155 }
00156 
00157 int 
00158 MuonReSeeder::layer(DetId detid) const {
00159     switch (detid.subdetId()) {
00160         case PixelSubdetector::PixelBarrel: return PXBDetId(detid).layer();
00161         case PixelSubdetector::PixelEndcap: return PXFDetId(detid).disk();
00162         case StripSubdetector::TIB:         return TIBDetId(detid).layer();
00163         case StripSubdetector::TID:         return TIDDetId(detid).wheel();
00164         case StripSubdetector::TOB:         return TOBDetId(detid).layer();
00165         case StripSubdetector::TEC:         return TECDetId(detid).wheel();
00166     }
00167     return -1; // never match
00168 }
00169 
00170 
00171 #include "FWCore/Framework/interface/MakerMacros.h"
00172 DEFINE_FWK_MODULE(MuonReSeeder);