CMS 3D CMS Logo

DuplicateRecHits.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DuplicateRecHits
4 // Class: DuplicateRecHits
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Thu Sep 25 16:32:56 CEST 2008
16 // $Id: DuplicateRecHits.cc,v 1.15 2011/11/15 10:09:24 venturia Exp $
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
30 
32 
34 
35 // my includes
36 
37 #include <string>
38 #include <set>
39 #include <numeric>
40 
41 #include "TH1F.h"
42 
44 
47 
49 
52 
58 //
59 // class decleration
60 //
61 
62 class DuplicateRecHits : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
63 public:
64  explicit DuplicateRecHits(const edm::ParameterSet&);
65  ~DuplicateRecHits() override;
66 
67 private:
68  void beginJob() override;
69  void beginRun(const edm::Run&, const edm::EventSetup&) override;
70  void endRun(const edm::Run&, const edm::EventSetup&) override;
71  void analyze(const edm::Event&, const edm::EventSetup&) override;
72  void endJob() override;
73 
74  // ----------member data ---------------------------
75 
79 
80  TH1F* m_nduplicate;
81  TH1F* m_nduplmod;
82 };
83 
84 //
85 // constants, enums and typedefs
86 //
87 
88 //
89 // static data member definitions
90 //
91 
92 //
93 // constructors and destructor
94 //
96  : m_trkcollToken(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trackCollection"))),
97  m_builderToken(esConsumes<edm::Transition::BeginRun>(
98  edm::ESInputTag{"", iConfig.getParameter<std::string>("TTRHBuilder")})) {
99  //now do what ever initialization is needed
100 
101  // histogram parameters
102  usesResource(TFileService::kSharedResource);
103 
104  edm::LogInfo("TrackCollection") << "Using collection "
105  << iConfig.getParameter<edm::InputTag>("trackCollection").label().c_str();
106 
108 
109  m_nduplicate = tfserv->make<TH1F>("nduplicate", "Number of duplicated clusters per track", 10, -0.5, 9.5);
110  m_nduplmod = tfserv->make<TH1F>("nduplmod", "Number of duplicated clusters per module", 10, -0.5, 9.5);
111  m_nduplmod->SetCanExtend(TH1::kXaxis);
112 }
113 
115  // do anything here that needs to be done at desctruction time
116  // (e.g. close files, deallocate resources etc.)
117 }
118 
119 //
120 // member functions
121 //
122 
123 // ------------ method called to for each event ------------
125  using namespace edm;
127 
129  iEvent.getByToken(m_trkcollToken, tracks);
130 
131  for (reco::TrackCollection::const_iterator it = tracks->begin(); it != tracks->end(); it++) {
132  std::set<SiPixelRecHit::ClusterRef::key_type> clusters;
133  int nduplicate = 0;
134  for (trackingRecHit_iterator rh = it->recHitsBegin(); rh != it->recHitsEnd(); ++rh) {
136  const SiPixelRecHit* pxrh = dynamic_cast<const SiPixelRecHit*>(ttrh->hit());
137  if (pxrh) {
138  // LogTrace("DuplicateHitFinder") << ttrh->det()->geographicalId() << " " << pxrh->cluster().index();
139  if (clusters.find(pxrh->cluster().index()) != clusters.end()) {
140  nduplicate++;
141  std::stringstream detidstr;
142  detidstr << ttrh->det()->geographicalId().rawId();
143  m_nduplmod->Fill(detidstr.str().c_str(), 1.);
144  LogDebug("DuplicateHitFinder") << "Track with " << it->recHitsSize() << " RecHits";
145  LogTrace("DuplicateHitFinder") << "Duplicate found " << ttrh->det()->geographicalId().rawId() << " "
146  << pxrh->cluster().index();
147  }
148  clusters.insert(pxrh->cluster().index());
149  }
150  m_nduplicate->Fill(nduplicate);
151  }
152  }
153 }
154 
155 void DuplicateRecHits::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
156  m_builder = &iSetup.getData(m_builderToken);
157 }
158 
160 
161 // ------------ method called once each job just before starting event loop ------------
163 
164 // ------------ method called once each job just after ending the event loop ------------
166 
167 //define this as a plug-in
ClusterRef cluster() const
Definition: SiPixelRecHit.h:47
static const std::string kSharedResource
Definition: TFileService.h:76
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
~DuplicateRecHits() override
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > m_builderToken
const GeomDet * det() const
const TransientTrackingRecHitBuilder * m_builder
#define LogTrace(id)
char const * label
int iEvent
Definition: GenABIO.cc:224
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
void endRun(const edm::Run &, const edm::EventSetup &) override
void endJob() override
Transition
Definition: Transition.h:12
bool getData(T &iHolder) const
Definition: EventSetup.h:122
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
std::shared_ptr< TrackingRecHit const > RecHitPointer
void beginJob() override
Log< level::Info, false > LogInfo
auto const & tracks
cannot be loose
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
key_type index() const
Definition: Ref.h:253
edm::EDGetTokenT< reco::TrackCollection > m_trkcollToken
fixed size matrix
HLT enums.
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
DuplicateRecHits(const edm::ParameterSet &)
void analyze(const edm::Event &, const edm::EventSetup &) override
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:45
Our base class.
Definition: SiPixelRecHit.h:23
#define LogDebug(id)