File indexing completed on 2024-04-06 12:06:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022
0023
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/Run.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030
0031 #include "FWCore/Framework/interface/ESHandle.h"
0032
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034
0035
0036
0037 #include <string>
0038 #include <set>
0039 #include <numeric>
0040
0041 #include "TH1F.h"
0042
0043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0044
0045 #include "FWCore/ServiceRegistry/interface/Service.h"
0046 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0047
0048 #include "FWCore/Utilities/interface/InputTag.h"
0049
0050 #include "DataFormats/TrackReco/interface/Track.h"
0051 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0052
0053 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
0054 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0055 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
0056 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
0057 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0058
0059
0060
0061
0062 class DuplicateRecHits : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
0063 public:
0064 explicit DuplicateRecHits(const edm::ParameterSet&);
0065 ~DuplicateRecHits() override;
0066
0067 private:
0068 void beginJob() override;
0069 void beginRun(const edm::Run&, const edm::EventSetup&) override;
0070 void endRun(const edm::Run&, const edm::EventSetup&) override;
0071 void analyze(const edm::Event&, const edm::EventSetup&) override;
0072 void endJob() override;
0073
0074
0075
0076 edm::EDGetTokenT<reco::TrackCollection> m_trkcollToken;
0077 edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> m_builderToken;
0078 const TransientTrackingRecHitBuilder* m_builder = nullptr;
0079
0080 TH1F* m_nduplicate;
0081 TH1F* m_nduplmod;
0082 };
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 DuplicateRecHits::DuplicateRecHits(const edm::ParameterSet& iConfig)
0096 : m_trkcollToken(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trackCollection"))),
0097 m_builderToken(esConsumes<edm::Transition::BeginRun>(
0098 edm::ESInputTag{"", iConfig.getParameter<std::string>("TTRHBuilder")})) {
0099
0100
0101
0102 usesResource(TFileService::kSharedResource);
0103
0104 edm::LogInfo("TrackCollection") << "Using collection "
0105 << iConfig.getParameter<edm::InputTag>("trackCollection").label().c_str();
0106
0107 edm::Service<TFileService> tfserv;
0108
0109 m_nduplicate = tfserv->make<TH1F>("nduplicate", "Number of duplicated clusters per track", 10, -0.5, 9.5);
0110 m_nduplmod = tfserv->make<TH1F>("nduplmod", "Number of duplicated clusters per module", 10, -0.5, 9.5);
0111 m_nduplmod->SetCanExtend(TH1::kXaxis);
0112 }
0113
0114 DuplicateRecHits::~DuplicateRecHits() {
0115
0116
0117 }
0118
0119
0120
0121
0122
0123
0124 void DuplicateRecHits::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0125 using namespace edm;
0126 edm::Service<TFileService> tfserv;
0127
0128 Handle<reco::TrackCollection> tracks;
0129 iEvent.getByToken(m_trkcollToken, tracks);
0130
0131 for (reco::TrackCollection::const_iterator it = tracks->begin(); it != tracks->end(); it++) {
0132 std::set<SiPixelRecHit::ClusterRef::key_type> clusters;
0133 int nduplicate = 0;
0134 for (trackingRecHit_iterator rh = it->recHitsBegin(); rh != it->recHitsEnd(); ++rh) {
0135 TransientTrackingRecHit::RecHitPointer ttrh = m_builder->build(&**rh);
0136 const SiPixelRecHit* pxrh = dynamic_cast<const SiPixelRecHit*>(ttrh->hit());
0137 if (pxrh) {
0138
0139 if (clusters.find(pxrh->cluster().index()) != clusters.end()) {
0140 nduplicate++;
0141 std::stringstream detidstr;
0142 detidstr << ttrh->det()->geographicalId().rawId();
0143 m_nduplmod->Fill(detidstr.str().c_str(), 1.);
0144 LogDebug("DuplicateHitFinder") << "Track with " << it->recHitsSize() << " RecHits";
0145 LogTrace("DuplicateHitFinder") << "Duplicate found " << ttrh->det()->geographicalId().rawId() << " "
0146 << pxrh->cluster().index();
0147 }
0148 clusters.insert(pxrh->cluster().index());
0149 }
0150 m_nduplicate->Fill(nduplicate);
0151 }
0152 }
0153 }
0154
0155 void DuplicateRecHits::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0156 m_builder = &iSetup.getData(m_builderToken);
0157 }
0158
0159 void DuplicateRecHits::endRun(const edm::Run& iRun, const edm::EventSetup&) {}
0160
0161
0162 void DuplicateRecHits::beginJob() {}
0163
0164
0165 void DuplicateRecHits::endJob() {}
0166
0167
0168 DEFINE_FWK_MODULE(DuplicateRecHits);