Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:20:42

0001 /** \file
0002  *
0003  * \author Stefano Lacaprara - INFN Legnaro <stefano.lacaprara@pd.infn.it>
0004  */
0005 
0006 /* This Class Header */
0007 #include "HLTMuonPointingFilter.h"
0008 
0009 /* Collaborating Class Header */
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/ESHandle.h"
0013 #include "FWCore/Framework/interface/EventSetupRecord.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0016 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018 #include "FWCore/Utilities/interface/Exception.h"
0019 
0020 #include "DataFormats/TrackReco/interface/Track.h"
0021 
0022 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0023 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0024 
0025 /* C++ Headers */
0026 using namespace std;
0027 using namespace edm;
0028 
0029 /* ====================================================================== */
0030 
0031 /// Constructor
0032 HLTMuonPointingFilter::HLTMuonPointingFilter(const edm::ParameterSet& pset)
0033     : theSTAMuonToken(
0034           consumes<reco::TrackCollection>(pset.getParameter<edm::InputTag>("SALabel"))),  // token to read the muons
0035       thePropagatorName(pset.getParameter<std::string>("PropagatorName")),
0036       thePropagatorToken(esConsumes<Propagator, TrackingComponentsRecord>(edm::ESInputTag("", thePropagatorName))),
0037       theMGFieldToken(esConsumes<MagneticField, IdealMagneticFieldRecord>()),
0038       theTrackingGeometryToken(esConsumes<GlobalTrackingGeometry, GlobalTrackingGeometryRecord>()),
0039       theRadius(pset.getParameter<double>("radius")),            // cyl's radius (cm)
0040       theMaxZ(pset.getParameter<double>("maxZ")),                // cyl's half lenght (cm)
0041       thePixHits(pset.getParameter<unsigned int>("PixHits")),    // pixel hits
0042       theTkLayers(pset.getParameter<unsigned int>("TkLayers")),  // tracker layers with measurements
0043       theMuonHits(pset.getParameter<unsigned int>("MuonHits")),  // muon hits
0044       // Get a surface (here a cylinder of radius 1290mm) ECAL
0045       theCyl(Cylinder::build(theRadius, Cylinder::PositionType{}, Cylinder::RotationType{})),
0046       thePosPlane(Plane::build(Plane::PositionType{0, 0, static_cast<float>(theMaxZ)}, Plane::RotationType{})),
0047       theNegPlane(Plane::build(Plane::PositionType{0, 0, static_cast<float>(-theMaxZ)}, Plane::RotationType{})) {
0048   LogDebug("HLTMuonPointing") << " SALabel : " << pset.getParameter<edm::InputTag>("SALabel")
0049                               << " Radius : " << theRadius << " Half lenght : " << theMaxZ
0050                               << " Min pixel hits : " << thePixHits << " Min tk layers measurements : " << theTkLayers
0051                               << " Min muon hits : " << theMuonHits;
0052 }
0053 
0054 /// Destructor
0055 HLTMuonPointingFilter::~HLTMuonPointingFilter() = default;
0056 
0057 /* Operations */
0058 bool HLTMuonPointingFilter::filter(edm::StreamID, edm::Event& event, const edm::EventSetup& eventSetup) const {
0059   bool accept = false;
0060 
0061   auto const& propagator = eventSetup.getData(thePropagatorToken);
0062 
0063   if (propagator.propagationDirection() != anyDirection) {
0064     throw cms::Exception("Configuration")
0065         << "the propagator " << thePropagatorName
0066         << " should be configured with PropagationDirection = \"anyDirection\"" << std::endl;
0067   }
0068 
0069   ESHandle<MagneticField> theMGField = eventSetup.getHandle(theMGFieldToken);
0070 
0071   ESHandle<GlobalTrackingGeometry> theTrackingGeometry = eventSetup.getHandle(theTrackingGeometryToken);
0072 
0073   // Get the RecTrack collection from the event
0074   Handle<reco::TrackCollection> staTracks;
0075   event.getByToken(theSTAMuonToken, staTracks);
0076 
0077   reco::TrackCollection::const_iterator staTrack;
0078 
0079   for (staTrack = staTracks->begin(); staTrack != staTracks->end(); ++staTrack) {
0080     reco::TransientTrack track(*staTrack, &*theMGField, theTrackingGeometry);
0081 
0082     const reco::HitPattern& p = track.hitPattern();
0083 
0084     const unsigned int pixelHits = p.numberOfValidPixelHits();
0085     const unsigned int trkLayers = p.trackerLayersWithMeasurement();
0086     const unsigned int nMuonHits = p.numberOfValidMuonHits();
0087 
0088     TrajectoryStateOnSurface innerTSOS = track.innermostMeasurementState();
0089 
0090     LogDebug("HLTMuonPointing") << " InnerTSOS " << innerTSOS;
0091 
0092     TrajectoryStateOnSurface tsosAtCyl = propagator.propagate(*innerTSOS.freeState(), *theCyl);
0093 
0094     if (tsosAtCyl.isValid()) {
0095       LogDebug("HLTMuonPointing") << " extrap TSOS " << tsosAtCyl << " number of pixel hits " << pixelHits
0096                                   << " number of tracker layers with interactions " << trkLayers
0097                                   << " number of muon hits " << nMuonHits;
0098       if (fabs(tsosAtCyl.globalPosition().z()) < theMaxZ) {
0099         if (pixelHits >= thePixHits) {
0100           if (trkLayers >= theTkLayers) {
0101             if (nMuonHits >= theMuonHits) {
0102               accept = true;
0103               return accept;
0104             }
0105           }
0106         }
0107       } else {
0108         LogDebug("HLTMuonPointing") << " extrap TSOS z too big " << tsosAtCyl.globalPosition().z()
0109                                     << " number of pixel hits " << pixelHits
0110                                     << " number of tracker layers with interactions " << trkLayers
0111                                     << " number of muon hits " << nMuonHits;
0112         TrajectoryStateOnSurface tsosAtPlane;
0113         if (tsosAtCyl.globalPosition().z() > 0)
0114           tsosAtPlane = propagator.propagate(*innerTSOS.freeState(), *thePosPlane);
0115         else
0116           tsosAtPlane = propagator.propagate(*innerTSOS.freeState(), *theNegPlane);
0117 
0118         if (tsosAtPlane.isValid()) {
0119           if (tsosAtPlane.globalPosition().perp() < theRadius) {
0120             if (pixelHits >= thePixHits) {
0121               if (trkLayers >= theTkLayers) {
0122                 if (nMuonHits >= theMuonHits) {
0123                   accept = true;
0124                   return accept;
0125                 }
0126               }
0127             }
0128           }
0129         } else
0130           LogDebug("HLTMuonPointing") << " extrap to plane failed ";
0131       }
0132     } else {
0133       LogDebug("HLTMuonPointing") << " extrap to cyl failed ";
0134     }
0135   }
0136 
0137   return accept;
0138 }
0139 
0140 void HLTMuonPointingFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0141   edm::ParameterSetDescription desc;
0142 
0143   desc.add<edm::InputTag>("SALabel", edm::InputTag("hltCosmicMuonBarrelOnly"));
0144   desc.add<std::string>("PropagatorName", "SteppingHelixPropagatorAny");
0145   desc.add<double>("radius", 90.0);
0146   desc.add<double>("maxZ", 280.0);
0147   desc.add<unsigned int>("PixHits", 0);
0148   desc.add<unsigned int>("TkLayers", 0);
0149   desc.add<unsigned int>("MuonHits", 0);
0150 
0151   descriptions.add("hltMuonPointingFilter", desc);
0152 }
0153 
0154 // declare this class as a framework plugin
0155 #include "FWCore/Framework/interface/MakerMacros.h"
0156 DEFINE_FWK_MODULE(HLTMuonPointingFilter);