CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/Cosmics/src/HLTMuonPointingFilter.cc

Go to the documentation of this file.
00001 
00008 /* This Class Header */
00009 #include "EventFilter/Cosmics/interface/HLTMuonPointingFilter.h"
00010 
00011 /* Collaborating Class Header */
00012 #include "FWCore/Framework/interface/MakerMacros.h"
00013 #include "FWCore/Framework/interface/Frameworkfwd.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/Framework/interface/EventSetupRecord.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 #include "DataFormats/TrackReco/interface/Track.h"
00019 
00020 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00021 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00022 #include "MagneticField/Engine/interface/MagneticField.h"
00023 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00024 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00025 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00026 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00027 
00028 
00029 
00030 /* C++ Headers */
00031 using namespace std;
00032 using namespace edm;
00033 
00034 /* ====================================================================== */
00035 
00037 HLTMuonPointingFilter::HLTMuonPointingFilter(const edm::ParameterSet& pset): m_cacheRecordId(0) {
00038 
00039   // the name of the STA rec hits collection
00040   theSTAMuonLabel = pset.getParameter<string>("SALabel");
00041 
00042   thePropagatorName = pset.getParameter<std::string>("PropagatorName");
00043   thePropagator = 0;
00044 
00045   theRadius = pset.getParameter<double>("radius"); // cyl's radius (cm)
00046   theMaxZ = pset.getParameter<double>("maxZ"); // cyl's half lenght (cm)
00047 
00048 
00049   // Get a surface (here a cylinder of radius 1290mm) ECAL
00050   Cylinder::PositionType pos0;
00051   Cylinder::RotationType rot0;
00052   theCyl = Cylinder::build(pos0, rot0, theRadius);
00053     
00054   Plane::PositionType posPos(0,0,theMaxZ);
00055   Plane::PositionType posNeg(0,0,-theMaxZ);
00056 
00057   thePosPlane = Plane::build(posPos,rot0);
00058   theNegPlane = Plane::build(posNeg,rot0);
00059 
00060   LogDebug("HLTMuonPointing") << " SALabel : " << theSTAMuonLabel 
00061     << " Radius : " << theRadius
00062     << " Half lenght : " << theMaxZ;
00063 }
00064 
00066 HLTMuonPointingFilter::~HLTMuonPointingFilter() {
00067 }
00068 
00069 /* Operations */ 
00070 bool HLTMuonPointingFilter::filter(edm::Event& event, const edm::EventSetup& eventSetup) {
00071   bool accept = false;
00072 
00073   const TrackingComponentsRecord & tkRec = eventSetup.get<TrackingComponentsRecord>();
00074   if (not thePropagator or tkRec.cacheIdentifier() != m_cacheRecordId) {
00075     ESHandle<Propagator> prop;
00076     tkRec.get(thePropagatorName, prop);
00077     thePropagator = prop->clone();
00078     thePropagator->setPropagationDirection(anyDirection);
00079     m_cacheRecordId = tkRec.cacheIdentifier();
00080   }
00081 
00082   ESHandle<MagneticField> theMGField;
00083   eventSetup.get<IdealMagneticFieldRecord>().get(theMGField);
00084 
00085   ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
00086   eventSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
00087 
00088   // Get the RecTrack collection from the event
00089   Handle<reco::TrackCollection> staTracks;
00090   event.getByLabel(theSTAMuonLabel, staTracks);
00091 
00092   reco::TrackCollection::const_iterator staTrack;
00093 
00094   for (staTrack = staTracks->begin(); staTrack != staTracks->end(); ++staTrack){
00095     reco::TransientTrack track(*staTrack,&*theMGField,theTrackingGeometry);
00096 
00097     TrajectoryStateOnSurface innerTSOS = track.innermostMeasurementState();
00098 
00099     LogDebug("HLTMuonPointing") << " InnerTSOS " << innerTSOS;
00100 
00101     TrajectoryStateOnSurface tsosAtCyl =
00102       thePropagator->propagate(*innerTSOS.freeState(), *theCyl);
00103 
00104     if ( tsosAtCyl.isValid() ) {
00105       LogDebug("HLTMuonPointing") << " extrap TSOS " << tsosAtCyl;
00106       if (fabs(tsosAtCyl.globalPosition().z())<theMaxZ ) {
00107         accept=true;
00108         return accept;
00109       }
00110       else { 
00111         LogDebug("HLTMuonPointing") << " extrap TSOS z too big " << tsosAtCyl.globalPosition().z();
00112         TrajectoryStateOnSurface tsosAtPlane;
00113         if (tsosAtCyl.globalPosition().z()>0)
00114           tsosAtPlane=thePropagator->propagate(*innerTSOS.freeState(), *thePosPlane);
00115         else
00116           tsosAtPlane=thePropagator->propagate(*innerTSOS.freeState(), *theNegPlane);
00117 
00118         if (tsosAtPlane.isValid()){
00119           if (tsosAtPlane.globalPosition().perp()< theRadius){
00120             accept=true;
00121             return accept;
00122           }
00123         }
00124         else
00125           LogDebug("HLTMuonPointing") << " extrap to plane failed ";
00126       }
00127     } else {
00128       LogDebug("HLTMuonPointing") << " extrap to cyl failed ";
00129     }
00130 
00131   }
00132 
00133   return accept;
00134 
00135 
00136 }
00137 
00138 // define this as a plug-in
00139 DEFINE_FWK_MODULE(HLTMuonPointingFilter);