CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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 
103  edm::LogInfo("TrackCollection") << "Using collection "
104  << iConfig.getParameter<edm::InputTag>("trackCollection").label().c_str();
105 
107 
108  m_nduplicate = tfserv->make<TH1F>("nduplicate", "Number of duplicated clusters per track", 10, -0.5, 9.5);
109  m_nduplmod = tfserv->make<TH1F>("nduplmod", "Number of duplicated clusters per module", 10, -0.5, 9.5);
110  m_nduplmod->SetCanExtend(TH1::kXaxis);
111 }
112 
114  // do anything here that needs to be done at desctruction time
115  // (e.g. close files, deallocate resources etc.)
116 }
117 
118 //
119 // member functions
120 //
121 
122 // ------------ method called to for each event ------------
124  using namespace edm;
126 
129 
130  for (reco::TrackCollection::const_iterator it = tracks->begin(); it != tracks->end(); it++) {
131  std::set<SiPixelRecHit::ClusterRef::key_type> clusters;
132  int nduplicate = 0;
133  for (trackingRecHit_iterator rh = it->recHitsBegin(); rh != it->recHitsEnd(); ++rh) {
135  const SiPixelRecHit* pxrh = dynamic_cast<const SiPixelRecHit*>(ttrh->hit());
136  if (pxrh) {
137  // LogTrace("DuplicateHitFinder") << ttrh->det()->geographicalId() << " " << pxrh->cluster().index();
138  if (clusters.find(pxrh->cluster().index()) != clusters.end()) {
139  nduplicate++;
140  std::stringstream detidstr;
141  detidstr << ttrh->det()->geographicalId().rawId();
142  m_nduplmod->Fill(detidstr.str().c_str(), 1.);
143  LogDebug("DuplicateHitFinder") << "Track with " << it->recHitsSize() << " RecHits";
144  LogTrace("DuplicateHitFinder") << "Duplicate found " << ttrh->det()->geographicalId().rawId() << " "
145  << pxrh->cluster().index();
146  }
147  clusters.insert(pxrh->cluster().index());
148  }
149  m_nduplicate->Fill(nduplicate);
150  }
151  }
152 }
153 
154 void DuplicateRecHits::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
155  m_builder = &iSetup.getData(m_builderToken);
156 }
157 
159 
160 // ------------ method called once each job just before starting event loop ------------
162 
163 // ------------ method called once each job just after ending the event loop ------------
165 
166 //define this as a plug-in
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
key_type index() const
Definition: Ref.h:253
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
auto const & tracks
cannot be loose
~DuplicateRecHits() override
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > m_builderToken
const TransientTrackingRecHitBuilder * m_builder
#define LogTrace(id)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
char const * label
int iEvent
Definition: GenABIO.cc:224
const GeomDet * det() const
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
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
ClusterRef cluster() const
Definition: SiPixelRecHit.h:47
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::TrackCollection > m_trkcollToken
DuplicateRecHits(const edm::ParameterSet &)
void analyze(const edm::Event &, const edm::EventSetup &) override
void beginRun(const edm::Run &, const edm::EventSetup &) override
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: Run.h:45
Our base class.
Definition: SiPixelRecHit.h:23
#define LogDebug(id)