CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/TrackingTools/TrackRefitter/src/TrackTransformerForGlobalCosmicMuons.cc

Go to the documentation of this file.
00001 #include "TrackingTools/TrackRefitter/interface/TrackTransformerForGlobalCosmicMuons.h"
00002 
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00008 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00009 
00010 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00011 #include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h"
00012 #include "TrackingTools/PatternTools/interface/TrajectorySmoother.h"
00013 
00014 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00015 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00016 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
00017 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00018 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00019 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00020 
00021 #include "DataFormats/TrackReco/interface/Track.h"
00022 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00023 #include "DataFormats/DetId/interface/DetId.h"
00024 
00025 
00026 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00027 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00028 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00029 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00030 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00031 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00032 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00033 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00034 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00035 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00036 
00037 
00038 using namespace std;
00039 using namespace edm;
00040 
00042 TrackTransformerForGlobalCosmicMuons::TrackTransformerForGlobalCosmicMuons(const ParameterSet& parameterSet){
00043   
00044   theTrackerRecHitBuilderName = parameterSet.getParameter<string>("TrackerRecHitBuilder");
00045   theMuonRecHitBuilderName = parameterSet.getParameter<string>("MuonRecHitBuilder");
00046 
00047   theRPCInTheFit = parameterSet.getParameter<bool>("RefitRPCHits");
00048 
00049   theCacheId_TC = theCacheId_GTG = theCacheId_MG = theCacheId_TRH = 0;
00050   theSkipStationDT      = parameterSet.getParameter<int>("SkipStationDT");
00051   theSkipStationCSC     = parameterSet.getParameter<int>("SkipStationCSC");
00052   theSkipWheelDT                = parameterSet.getParameter<int>("SkipWheelDT");
00053   theTrackerSkipSystem  = parameterSet.getParameter<int>("TrackerSkipSystem");
00054   theTrackerSkipSection = parameterSet.getParameter<int>("TrackerSkipSection");//layer, wheel, or disk depending on the system 
00055 }
00056 
00058 TrackTransformerForGlobalCosmicMuons::~TrackTransformerForGlobalCosmicMuons(){}
00059 
00060 
00061 void TrackTransformerForGlobalCosmicMuons::setServices(const EventSetup& setup){
00062   
00063   const std::string metname = "Reco|TrackingTools|TrackTransformer";
00064 
00065   setup.get<TrajectoryFitter::Record>().get("KFFitterForRefitInsideOut",theFitterIO);
00066   setup.get<TrajectoryFitter::Record>().get("KFSmootherForRefitInsideOut",theSmootherIO);
00067   setup.get<TrajectoryFitter::Record>().get("KFFitterForRefitOutsideIn",theFitterOI);
00068   setup.get<TrajectoryFitter::Record>().get("KFSmootherForRefitOutsideIn",theSmootherOI);
00069   
00070   unsigned long long newCacheId_TC = setup.get<TrackingComponentsRecord>().cacheIdentifier();
00071 
00072   if ( newCacheId_TC != theCacheId_TC ){
00073     LogTrace(metname) << "Tracking Component changed!";
00074     theCacheId_TC = newCacheId_TC;
00075     setup.get<TrackingComponentsRecord>().get("SmartPropagatorRK",thePropagatorIO);
00076     setup.get<TrackingComponentsRecord>().get("SmartPropagatorRKOpposite",thePropagatorOI);
00077 
00078   }
00079 
00080   // Global Tracking Geometry
00081   unsigned long long newCacheId_GTG = setup.get<GlobalTrackingGeometryRecord>().cacheIdentifier();
00082   if ( newCacheId_GTG != theCacheId_GTG ) {
00083     LogTrace(metname) << "GlobalTrackingGeometry changed!";
00084     theCacheId_GTG = newCacheId_GTG;
00085     setup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry); 
00086   }
00087   
00088   // Magfield Field
00089   unsigned long long newCacheId_MG = setup.get<IdealMagneticFieldRecord>().cacheIdentifier();
00090   if ( newCacheId_MG != theCacheId_MG ) {
00091     LogTrace(metname) << "Magnetic Field changed!";
00092     theCacheId_MG = newCacheId_MG;
00093     setup.get<IdealMagneticFieldRecord>().get(theMGField);
00094   }
00095   
00096   // Transient Rechit Builders
00097   unsigned long long newCacheId_TRH = setup.get<TransientRecHitRecord>().cacheIdentifier();
00098   if ( newCacheId_TRH != theCacheId_TRH ) {
00099     theCacheId_TRH = newCacheId_TRH;
00100     LogTrace(metname) << "TransientRecHitRecord changed!";
00101     setup.get<TransientRecHitRecord>().get(theTrackerRecHitBuilderName,theTrackerRecHitBuilder);
00102     setup.get<TransientRecHitRecord>().get(theMuonRecHitBuilderName,theMuonRecHitBuilder);
00103   }
00104 }
00105 
00106 
00107 TransientTrackingRecHit::ConstRecHitContainer
00108 TrackTransformerForGlobalCosmicMuons::getTransientRecHits(const reco::TransientTrack& track) const {
00109 
00110   TransientTrackingRecHit::ConstRecHitContainer tkHits;
00111   TransientTrackingRecHit::ConstRecHitContainer staHits;
00112 
00113   for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit) {
00114     if((*hit)->isValid()) {
00115       if ( (*hit)->geographicalId().det() == DetId::Tracker && TrackerKeep((*hit)->geographicalId())) {
00116                 tkHits.push_back(theTrackerRecHitBuilder->build(&**hit));
00117       } else if ( (*hit)->geographicalId().det() == DetId::Muon && MuonKeep((*hit)->geographicalId())){
00118                 if( (*hit)->geographicalId().subdetId() == 3 && !theRPCInTheFit){
00119                 LogTrace("Reco|TrackingTools|TrackTransformer") << "RPC Rec Hit discarged"; 
00120                 continue;
00121                 }
00122                 staHits.push_back(theMuonRecHitBuilder->build(&**hit));
00123       }
00124     }
00125   }
00126   
00127   if(staHits.empty()) return staHits;
00128 
00129 /*
00130   bool up = staHits.front()->globalPosition().y()>0 ? true : false;
00131 
00132   if(up){
00133     reverse(staHits.begin(),staHits.end());
00134     reverse(tkHits.begin(),tkHits.end());
00135   }
00136 */
00137   copy(staHits.begin(),staHits.end(),back_inserter(tkHits));
00138 
00139   for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator hit = tkHits.begin();
00140       hit !=tkHits.end(); ++hit){
00141 
00142     DetId hitId = (*hit)->geographicalId();
00143     GlobalPoint glbpoint = trackingGeometry()->idToDet(hitId)->position();
00144 
00145     if(hitId.det() == DetId::Tracker) {
00146       if (hitId.subdetId() == StripSubdetector::TIB )  
00147         LogTrace("TrackFitters") << glbpoint << " I am TIB " << TIBDetId(hitId).layer();
00148       else if (hitId.subdetId() == StripSubdetector::TOB ) 
00149         LogTrace("TrackFitters") << glbpoint << " I am TOB " << TOBDetId(hitId).layer();
00150       else if (hitId.subdetId() == StripSubdetector::TEC ) 
00151         LogTrace("TrackFitters") << glbpoint << " I am TEC " << TECDetId(hitId).wheel();
00152       else if (hitId.subdetId() == StripSubdetector::TID ) 
00153         LogTrace("TrackFitters") << glbpoint << " I am TID " << TIDDetId(hitId).wheel();
00154       else if (hitId.subdetId() == StripSubdetector::TID ) 
00155         LogTrace("TrackFitters") << glbpoint << " I am TID " << TIDDetId(hitId).wheel();
00156       else if (hitId.subdetId() == (int) PixelSubdetector::PixelBarrel ) 
00157         LogTrace("TrackFitters") << glbpoint << " I am PixBar " << PXBDetId(hitId).layer();
00158       else if (hitId.subdetId() == (int) PixelSubdetector::PixelEndcap )
00159         LogTrace("TrackFitters") << glbpoint << " I am PixFwd " << PXFDetId(hitId).disk();
00160       else 
00161         LogTrace("TrackFitters") << " UNKNOWN TRACKER HIT TYPE ";
00162     } else if(hitId.det() == DetId::Muon) {
00163       if(hitId.subdetId() == MuonSubdetId::DT)
00164         LogTrace("TrackFitters") << glbpoint << " I am DT " << DTWireId(hitId);
00165       else if (hitId.subdetId() == MuonSubdetId::CSC )
00166         LogTrace("TrackFitters") << glbpoint << " I am CSC " << CSCDetId(hitId);
00167       else if (hitId.subdetId() == MuonSubdetId::RPC )
00168         LogTrace("TrackFitters") << glbpoint << " I am RPC " << RPCDetId(hitId);
00169       else 
00170         LogTrace("TrackFitters") << " UNKNOWN MUON HIT TYPE ";
00171     } else
00172       LogTrace("TrackFitters") << " UNKNOWN HIT TYPE ";
00173   } 
00174   
00175   return tkHits;
00176 }
00177 
00178 
00180 ESHandle<TrajectoryFitter> TrackTransformerForGlobalCosmicMuons::fitter(bool up) const{
00181   if(up) return theFitterOI;
00182   else return theFitterIO;
00183 }
00184   
00186 ESHandle<TrajectorySmoother> TrackTransformerForGlobalCosmicMuons::smoother(bool up) const{
00187   if(up) return theSmootherOI;
00188   else return theSmootherIO;
00189 }
00190 
00191 ESHandle<Propagator> TrackTransformerForGlobalCosmicMuons::propagator(bool up) const{
00192   if(up) return thePropagatorIO;
00193   else return thePropagatorOI;
00194 }
00195 
00196 
00197 
00199 vector<Trajectory> TrackTransformerForGlobalCosmicMuons::transform(const reco::Track& tr) const {
00200 
00201   const std::string metname = "Reco|TrackingTools|TrackTransformer";
00202   
00203   reco::TransientTrack track(tr,magneticField(),trackingGeometry());   
00204 
00205   // Build the transient Rechits
00206   TransientTrackingRecHit::ConstRecHitContainer recHitsForReFit = getTransientRecHits(track);
00207 
00208   if(recHitsForReFit.size() < 2) return vector<Trajectory>();
00209 
00210   bool up = recHitsForReFit.back()->globalPosition().y()>0 ? true : false;
00211   LogTrace(metname) << "Up ? " << up;
00212 
00213   PropagationDirection propagationDirection = up ? oppositeToMomentum : alongMomentum;
00214   TrajectoryStateOnSurface firstTSOS = up ? track.outermostMeasurementState() : track.innermostMeasurementState();
00215   unsigned int innerId = up ? track.track().outerDetId() : track.track().innerDetId();
00216 
00217   LogTrace(metname) << "Prop Dir: " << propagationDirection << " FirstId " << innerId << " firstTSOS " << firstTSOS;
00218 
00219   TrajectorySeed seed(PTrajectoryStateOnDet(),TrajectorySeed::recHitContainer(),propagationDirection);
00220 
00221 
00222   if(recHitsForReFit.front()->geographicalId() != DetId(innerId)){
00223     LogTrace(metname)<<"Propagation occurring"<<endl;
00224     firstTSOS = propagator(up)->propagate(firstTSOS, recHitsForReFit.front()->det()->surface());
00225     LogTrace(metname)<<"Final destination: " << recHitsForReFit.front()->det()->surface().position() << endl;
00226     if(!firstTSOS.isValid()){
00227       LogTrace(metname)<<"Propagation error!"<<endl;
00228       return vector<Trajectory>();
00229     }
00230   }
00231   
00232 
00233   vector<Trajectory> trajectories = fitter(up)->fit(seed,recHitsForReFit,firstTSOS);
00234   
00235   if(trajectories.empty()){
00236     LogTrace(metname)<<"No Track refitted!"<<endl;
00237     return vector<Trajectory>();
00238   }
00239   
00240   Trajectory trajectoryBW = trajectories.front();
00241     
00242   vector<Trajectory> trajectoriesSM = smoother(up)->trajectories(trajectoryBW);
00243 
00244   if(trajectoriesSM.empty()){
00245     LogTrace(metname)<<"No Track smoothed!"<<endl;
00246     return vector<Trajectory>();
00247   }
00248   
00249   return trajectoriesSM;
00250 
00251 }
00252 
00253 //
00254 // Selection for Tracker Hits
00255 //
00256 bool TrackTransformerForGlobalCosmicMuons::TrackerKeep(DetId id) const{
00257         
00258         bool retVal = true;
00259         if (id.det() != DetId::Tracker ) return false;
00260         if (theTrackerSkipSystem < 0 ) return true;
00261         
00262 
00263     int layer = -999;
00264     int disk  = -999;
00265     int wheel = -999;
00266 
00267       if ( id.subdetId() == theTrackerSkipSystem){
00268 
00269                 if (theTrackerSkipSystem == PixelSubdetector::PixelBarrel) {
00270                         PXBDetId did(id.rawId());
00271                         layer = did.layer();
00272                 }
00273 
00274                 if (theTrackerSkipSystem == StripSubdetector::TIB) {
00275                         TIBDetId did(id.rawId());
00276                         layer = did.layer();
00277                 }       
00278 
00279                 if (theTrackerSkipSystem == StripSubdetector::TOB) {
00280                         TOBDetId did(id.rawId());
00281                         layer = did.layer();
00282                 }
00283                 if (theTrackerSkipSystem == PixelSubdetector::PixelEndcap) {
00284                         PXFDetId did(id.rawId());
00285                         disk = did.disk();
00286                 }
00287                 if (theTrackerSkipSystem == StripSubdetector::TID) {
00288                         TIDDetId did(id.rawId());
00289                         wheel = did.wheel();
00290                 }
00291                 if (theTrackerSkipSystem == StripSubdetector::TEC) {
00292                         TECDetId did(id.rawId());
00293                         wheel = did.wheel();
00294                 }
00295         }
00296 
00297         if (theTrackerSkipSection > -998 && layer == theTrackerSkipSection) retVal = false;
00298         if (theTrackerSkipSection > -998 && disk  == theTrackerSkipSection) retVal = false;
00299         if (theTrackerSkipSection > -998 && wheel == theTrackerSkipSection) retVal = false;
00300 
00301         return retVal;
00302 }
00303 //
00304 // Selection for Muon hits
00305 //
00306 bool TrackTransformerForGlobalCosmicMuons::MuonKeep(DetId id) const {
00307 
00308         if (id.det() != DetId::Muon) return false;
00309         if (theSkipStationDT < 0 && theSkipStationCSC < 0) return true;
00310 
00311         int station = -999;
00312         int wheel       = -999;
00313         bool isRPC      = false;
00314         bool isDT       = false;
00315         bool isCSC      = false;
00316                 
00317     if ( id.subdetId() == MuonSubdetId::DT ) {
00318                 DTChamberId did(id.rawId());
00319                 station = did.station();
00320                 wheel = did.wheel();
00321                 isDT = true;
00322     } else if ( id.subdetId() == MuonSubdetId::CSC ) {
00323                 CSCDetId did(id.rawId());
00324                 station = did.station();
00325                 isCSC = true;
00326     } else if ( id.subdetId() == MuonSubdetId::RPC ) {
00327                 RPCDetId rpcid(id.rawId());
00328                 station = rpcid.station();
00329                 isRPC = true;
00330     }
00331         
00332         if (isRPC       && (station     == theSkipStationCSC || station == theSkipStationDT)) return false;
00333         if (isDT        && station      == theSkipStationDT             ) return false;
00334         if (isCSC       && station      == theSkipStationCSC    ) return false;
00335 
00336         if (isDT && theSkipWheelDT > -998 && wheel == theSkipWheelDT) return false;
00337         
00338         return true;
00339 }