Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-01 22:41:03

0001 #ifndef RecoTracker_TkTrackingRegions_GlobalTrackingRegionProducerFromBeamSpot_H
0002 #define RecoTracker_TkTrackingRegions_GlobalTrackingRegionProducerFromBeamSpot_H
0003 
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegionProducer.h"
0007 #include "RecoTracker/TkTrackingRegions/interface/GlobalTrackingRegion.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0011 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 #include "FWCore/Utilities/interface/Exception.h"
0014 #include "FWCore/Framework/interface/ConsumesCollector.h"
0015 #include "RecoTracker/Record/interface/TrackerMultipleScatteringRecord.h"
0016 #include "RecoTracker/TkMSParametrization/interface/MultipleScatteringParametrisationMaker.h"
0017 
0018 class GlobalTrackingRegionProducerFromBeamSpot : public TrackingRegionProducer {
0019 public:
0020   GlobalTrackingRegionProducerFromBeamSpot(const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC)
0021       : GlobalTrackingRegionProducerFromBeamSpot(cfg, iC) {}
0022   GlobalTrackingRegionProducerFromBeamSpot(const edm::ParameterSet& cfg, edm::ConsumesCollector& iC) {
0023     edm::ParameterSet regionPSet = cfg.getParameter<edm::ParameterSet>("RegionPSet");
0024     thePtMin = regionPSet.getParameter<double>("ptMin");
0025     theOriginRadius = regionPSet.getParameter<double>("originRadius");
0026     if (!regionPSet.existsAs<double>("nSigmaZ") && !regionPSet.existsAs<double>("originHalfLength")) {
0027       throw cms::Exception("Configuration") << "GlobalTrackingRegionProducerFromBeamSpot: at least one of nSigmaZ, "
0028                                                "originHalfLength must be present in the cfg.\n";
0029     }
0030     theNSigmaZ = (regionPSet.existsAs<double>("nSigmaZ") ? regionPSet.getParameter<double>("nSigmaZ") : 0.0);
0031     theOriginHalfLength =
0032         (regionPSet.existsAs<double>("originHalfLength") ? regionPSet.getParameter<double>("originHalfLength") : 0.0);
0033     token_beamSpot = iC.consumes<reco::BeamSpot>(regionPSet.getParameter<edm::InputTag>("beamSpot"));
0034     thePrecise = regionPSet.getParameter<bool>("precise");
0035     theUseMS =
0036         (regionPSet.existsAs<bool>("useMultipleScattering") ? regionPSet.getParameter<bool>("useMultipleScattering")
0037                                                             : false);
0038     if (theUseMS) {
0039       token_msmaker = iC.esConsumes();
0040     }
0041   }
0042 
0043   ~GlobalTrackingRegionProducerFromBeamSpot() override = default;
0044 
0045   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0046     {
0047       edm::ParameterSetDescription desc;
0048 
0049       desc.add<bool>("precise", true);
0050       desc.add<bool>("useMultipleScattering", false);
0051       desc.add<double>("nSigmaZ", 4.0);
0052       desc.add<double>("originHalfLength", 0.0);  // this is the default in constructor
0053       desc.add<double>("originRadius", 0.2);
0054       desc.add<double>("ptMin", 0.9);
0055       desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
0056 
0057       // Only for backwards-compatibility
0058       edm::ParameterSetDescription descRegion;
0059       descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
0060 
0061       descriptions.add("globalTrackingRegionFromBeamSpot", descRegion);
0062     }
0063 
0064     {
0065       edm::ParameterSetDescription desc;
0066 
0067       desc.add<bool>("precise", true);
0068       desc.add<bool>("useMultipleScattering", false);
0069       desc.add<double>("nSigmaZ", 0.0);  // this is the default in constructor
0070       desc.add<double>("originHalfLength", 21.2);
0071       desc.add<double>("originRadius", 0.2);
0072       desc.add<double>("ptMin", 0.9);
0073       desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
0074 
0075       // Only for backwards-compatibility
0076       edm::ParameterSetDescription descRegion;
0077       descRegion.add<edm::ParameterSetDescription>("RegionPSet", desc);
0078 
0079       descriptions.add("globalTrackingRegionFromBeamSpotFixedZ", descRegion);
0080     }
0081   }
0082 
0083   std::vector<std::unique_ptr<TrackingRegion> > regions(const edm::Event& ev,
0084                                                         const edm::EventSetup& es) const override {
0085     std::vector<std::unique_ptr<TrackingRegion> > result;
0086     edm::Handle<reco::BeamSpot> bsHandle;
0087     ev.getByToken(token_beamSpot, bsHandle);
0088     if (bsHandle.isValid()) {
0089       const reco::BeamSpot& bs = *bsHandle;
0090 
0091       GlobalPoint origin(bs.x0(), bs.y0(), bs.z0());
0092 
0093       const MultipleScatteringParametrisationMaker* msmaker = nullptr;
0094       if (theUseMS) {
0095         msmaker = &es.getData(token_msmaker);
0096       }
0097 
0098       result.push_back(std::make_unique<GlobalTrackingRegion>(thePtMin,
0099                                                               origin,
0100                                                               theOriginRadius,
0101                                                               std::max(theNSigmaZ * bs.sigmaZ(), theOriginHalfLength),
0102                                                               thePrecise,
0103                                                               theUseMS,
0104                                                               msmaker));
0105     }
0106     return result;
0107   }
0108 
0109 private:
0110   double thePtMin;
0111   double theOriginRadius;
0112   double theOriginHalfLength;
0113   double theNSigmaZ;
0114   edm::EDGetTokenT<reco::BeamSpot> token_beamSpot;
0115   edm::ESGetToken<MultipleScatteringParametrisationMaker, TrackerMultipleScatteringRecord> token_msmaker;
0116   bool thePrecise;
0117   bool theUseMS;
0118 };
0119 
0120 #endif