Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:00:42

0001 #include "CalibFormats/SiStripObjects/interface/SiStripDetInfo.h"
0002 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0003 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
0004 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0005 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0006 #include "DataFormats/Common/interface/DetSetVector.h"
0007 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0008 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
0009 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0010 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0011 #include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
0012 #include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"
0013 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0014 #include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h"
0015 #include "DataFormats/TrackReco/interface/Track.h"
0016 #include "DataFormats/TrackReco/interface/TrackBase.h"
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 #include "FWCore/Framework/interface/stream/EDProducer.h"
0020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0021 #include "FWCore/ParameterSet/interface/FileInPath.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0024 #include "FWCore/Utilities/interface/ESInputTag.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0027 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
0028 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0029 #include "RecoTracker/PixelLowPtUtilities/interface/ClusterShapeHitFilter.h"
0030 #include "RecoTracker/PixelLowPtUtilities/interface/SlidingPeakFinder.h"
0031 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
0032 
0033 #include <vector>
0034 #include <memory>
0035 
0036 class SiStripClusters2ApproxClusters : public edm::stream::EDProducer<> {
0037 public:
0038   explicit SiStripClusters2ApproxClusters(const edm::ParameterSet& conf);
0039   void produce(edm::Event&, const edm::EventSetup&) override;
0040 
0041   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0042 
0043 private:
0044   edm::InputTag inputClusters;
0045   edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > clusterToken;
0046 
0047   unsigned int maxNSat;
0048   static constexpr double subclusterWindow_ = .7;
0049   static constexpr double seedCutMIPs_ = .35;
0050   static constexpr double seedCutSN_ = 7.;
0051   static constexpr double subclusterCutMIPs_ = .45;
0052   static constexpr double subclusterCutSN_ = 12.;
0053 
0054   edm::InputTag beamSpot_;
0055   edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
0056 
0057   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0058 
0059   edm::FileInPath fileInPath_;
0060   SiStripDetInfo detInfo_;
0061 
0062   std::string csfLabel_;
0063   edm::ESGetToken<ClusterShapeHitFilter, CkfComponentsRecord> csfToken_;
0064 
0065   edm::ESGetToken<SiStripNoises, SiStripNoisesRcd> stripNoiseToken_;
0066   edm::ESHandle<SiStripNoises> theNoise_;
0067 };
0068 
0069 SiStripClusters2ApproxClusters::SiStripClusters2ApproxClusters(const edm::ParameterSet& conf) {
0070   inputClusters = conf.getParameter<edm::InputTag>("inputClusters");
0071   maxNSat = conf.getParameter<unsigned int>("maxSaturatedStrips");
0072 
0073   clusterToken = consumes<edmNew::DetSetVector<SiStripCluster> >(inputClusters);
0074 
0075   beamSpot_ = conf.getParameter<edm::InputTag>("beamSpot");
0076   beamSpotToken_ = consumes<reco::BeamSpot>(beamSpot_);
0077 
0078   tkGeomToken_ = esConsumes();
0079 
0080   fileInPath_ = edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile);
0081   detInfo_ = SiStripDetInfoFileReader::read(fileInPath_.fullPath());
0082 
0083   csfLabel_ = conf.getParameter<std::string>("clusterShapeHitFilterLabel");
0084   csfToken_ = esConsumes(edm::ESInputTag("", csfLabel_));
0085 
0086   stripNoiseToken_ = esConsumes();
0087   produces<SiStripApproximateClusterCollection>();
0088 }
0089 
0090 void SiStripClusters2ApproxClusters::produce(edm::Event& event, edm::EventSetup const& iSetup) {
0091   const auto& clusterCollection = event.get(clusterToken);
0092   auto result = std::make_unique<SiStripApproximateClusterCollection>();
0093   result->reserve(clusterCollection.size(), clusterCollection.dataSize());
0094 
0095   auto const beamSpotHandle = event.getHandle(beamSpotToken_);
0096   auto const& bs = beamSpotHandle.isValid() ? *beamSpotHandle : reco::BeamSpot();
0097   if (not beamSpotHandle.isValid()) {
0098     edm::LogError("SiStripClusters2ApproxClusters")
0099         << "didn't find a valid beamspot with label \"" << beamSpot_.encode() << "\" -> using (0,0,0)";
0100   }
0101 
0102   const auto& tkGeom = &iSetup.getData(tkGeomToken_);
0103   const auto& theFilter = &iSetup.getData(csfToken_);
0104   const auto& theNoise_ = &iSetup.getData(stripNoiseToken_);
0105 
0106   for (const auto& detClusters : clusterCollection) {
0107     auto ff = result->beginDet(detClusters.id());
0108 
0109     unsigned int detId = detClusters.id();
0110     const GeomDet* det = tkGeom->idToDet(detId);
0111     double nApvs = detInfo_.getNumberOfApvsAndStripLength(detId).first;
0112     double stripLength = detInfo_.getNumberOfApvsAndStripLength(detId).second;
0113     double barycenter_ypos = 0.5 * stripLength;
0114 
0115     const StripGeomDetUnit* stripDet = dynamic_cast<const StripGeomDetUnit*>(det);
0116     float mip = 3.9 / (sistrip::MeVperADCStrip / stripDet->surface().bounds().thickness());
0117 
0118     for (const auto& cluster : detClusters) {
0119       const LocalPoint& lp = LocalPoint(((cluster.barycenter() * 10 / (sistrip::STRIPS_PER_APV * nApvs)) -
0120                                          ((stripDet->surface().bounds().width()) * 0.5f)),
0121                                         barycenter_ypos - (0.5f * stripLength),
0122                                         0.);
0123       const GlobalPoint& gpos = det->surface().toGlobal(lp);
0124       GlobalPoint beamspot(bs.position().x(), bs.position().y(), bs.position().z());
0125       const GlobalVector& gdir = gpos - beamspot;
0126       const LocalVector& ldir = det->toLocal(gdir);
0127 
0128       int hitStrips;
0129       float hitPredPos;
0130       bool usable = theFilter->getSizes(detId, cluster, lp, ldir, hitStrips, hitPredPos);
0131       // (almost) same logic as in StripSubClusterShapeTrajectoryFilter
0132       bool isTrivial = (std::abs(hitPredPos) < 2.f && hitStrips <= 2);
0133 
0134       if (!usable || isTrivial) {
0135         ff.push_back(SiStripApproximateCluster(cluster, maxNSat, hitPredPos, true));
0136       } else {
0137         bool peakFilter = false;
0138         SlidingPeakFinder pf(std::max<int>(2, std::ceil(std::abs(hitPredPos) + subclusterWindow_)));
0139         float mipnorm = mip / std::abs(ldir.z());
0140         PeakFinderTest test(mipnorm,
0141                             detId,
0142                             cluster.firstStrip(),
0143                             theNoise_,
0144                             seedCutMIPs_,
0145                             seedCutSN_,
0146                             subclusterCutMIPs_,
0147                             subclusterCutSN_);
0148         peakFilter = pf.apply(cluster.amplitudes(), test);
0149 
0150         ff.push_back(SiStripApproximateCluster(cluster, maxNSat, hitPredPos, peakFilter));
0151       }
0152     }
0153   }
0154 
0155   event.put(std::move(result));
0156 }
0157 
0158 void SiStripClusters2ApproxClusters::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0159   edm::ParameterSetDescription desc;
0160   desc.add<edm::InputTag>("inputClusters", edm::InputTag("siStripClusters"));
0161   desc.add<unsigned int>("maxSaturatedStrips", 3);
0162   desc.add<std::string>("clusterShapeHitFilterLabel", "ClusterShapeHitFilter");  // add CSF label
0163   desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));         // add BeamSpot tag
0164   descriptions.add("SiStripClusters2ApproxClusters", desc);
0165 }
0166 
0167 DEFINE_FWK_MODULE(SiStripClusters2ApproxClusters);