CMS 3D CMS Logo

GlobalMuonMatchAnalyzer.cc
Go to the documentation of this file.
1 
12 
13 // user include files
19 
22 
24 
28 
31 
32 #include <TH2.h>
33 
35 
36 {
37  iConfig = ps;
38  //now do what ever initialization is needed
41 
42  tkAssociatorToken_ = consumes<reco::TrackToTrackingParticleAssociator>(tkAssociatorName_);
43  muAssociatorToken_ = consumes<reco::TrackToTrackingParticleAssociator>(muAssociatorName_);
44 
45  subsystemname_ = iConfig.getUntrackedParameter<std::string>("subSystemFolder", "YourSubsystem");
50 
52  dbe_ = edm::Service<DQMStore>().operator->();
53 
54  tpToken_ = consumes<edm::View<reco::Track> >(tpName_);
55  tkToken_ = consumes<edm::View<reco::Track> >(tkName_);
56  staToken_ = consumes<edm::View<reco::Track> >(staName_);
57  glbToken_ = consumes<edm::View<reco::Track> >(glbName_);
58 }
59 
61  // do anything here that needs to be done at desctruction time
62  // (e.g. close files, deallocate resources etc.)
63 }
64 
65 //
66 // member functions
67 //
68 
69 // ------------ method called to for each event ------------
71  using namespace edm;
72  using namespace reco;
73 
75  iEvent.getByToken(tpToken_, tpHandle);
76  const TrackingParticleCollection tpColl = *(tpHandle.product());
77 
79  iEvent.getByToken(glbToken_, muHandle);
80  const reco::MuonTrackLinksCollection muColl = *(muHandle.product());
81 
82  Handle<View<Track> > staHandle;
83  iEvent.getByToken(staToken_, staHandle);
84 
85  Handle<View<Track> > glbHandle;
86  iEvent.getByToken(glbToken_, glbHandle);
87 
88  Handle<View<Track> > tkHandle;
89  iEvent.getByToken(tkToken_, tkHandle);
90 
92  iEvent.getByToken(tkAssociatorToken_, tkAssociator);
93 
94  // Mu Associator
96  iEvent.getByToken(muAssociatorToken_, muAssociator);
97 
98  reco::RecoToSimCollection tkrecoToSimCollection = tkAssociator->associateRecoToSim(tkHandle, tpHandle);
99  reco::SimToRecoCollection tksimToRecoCollection = tkAssociator->associateSimToReco(tkHandle, tpHandle);
100 
101  reco::RecoToSimCollection starecoToSimCollection = muAssociator->associateRecoToSim(staHandle, tpHandle);
102  reco::SimToRecoCollection stasimToRecoCollection = muAssociator->associateSimToReco(staHandle, tpHandle);
103 
104  reco::RecoToSimCollection glbrecoToSimCollection = muAssociator->associateRecoToSim(glbHandle, tpHandle);
105  reco::SimToRecoCollection glbsimToRecoCollection = muAssociator->associateSimToReco(glbHandle, tpHandle);
106 
107  for (TrackingParticleCollection::size_type i = 0; i < tpColl.size(); ++i) {
108  TrackingParticleRef tp(tpHandle, i);
109 
110  std::vector<std::pair<RefToBase<Track>, double> > rvGlb;
111  RefToBase<Track> rGlb;
112  if (glbsimToRecoCollection.find(tp) != glbsimToRecoCollection.end()) {
113  rvGlb = glbsimToRecoCollection[tp];
114  if (!rvGlb.empty()) {
115  rGlb = rvGlb.begin()->first;
116  }
117  }
118 
119  std::vector<std::pair<RefToBase<Track>, double> > rvSta;
120  RefToBase<Track> rSta;
121  if (stasimToRecoCollection.find(tp) != stasimToRecoCollection.end()) {
122  rvSta = stasimToRecoCollection[tp];
123  if (!rvSta.empty()) {
124  rSta = rvSta.begin()->first;
125  }
126  }
127 
128  std::vector<std::pair<RefToBase<Track>, double> > rvTk;
129  RefToBase<Track> rTk;
130  if (tksimToRecoCollection.find(tp) != tksimToRecoCollection.end()) {
131  rvTk = tksimToRecoCollection[tp];
132  if (!rvTk.empty()) {
133  rTk = rvTk.begin()->first;
134  }
135  }
136 
137  if (!rvSta.empty() && !rvTk.empty()) {
138  //should have matched
139  h_shouldMatch->Fill(rTk->eta(), rTk->pt());
140  }
141 
142  for (reco::MuonTrackLinksCollection::const_iterator links = muHandle->begin(); links != muHandle->end(); ++links) {
143  if (rGlb == RefToBase<Track>(links->globalTrack())) {
144  if (RefToBase<Track>(links->trackerTrack()) == rTk && RefToBase<Track>(links->standAloneTrack()) == rSta) {
145  //goodMatch
146  h_goodMatchSim->Fill(rGlb->eta(), rGlb->pt());
147  }
148  if (RefToBase<Track>(links->trackerTrack()) == rTk && RefToBase<Track>(links->standAloneTrack()) != rSta) {
149  //tkOnlyMatch
150  h_tkOnlySim->Fill(rGlb->eta(), rGlb->pt());
151  }
152  if (RefToBase<Track>(links->standAloneTrack()) == rSta && RefToBase<Track>(links->trackerTrack()) != rTk) {
153  //staOnlyMatch
154  h_staOnlySim->Fill(rGlb->eta(), rGlb->pt());
155  }
156  }
157  }
158  }
159 
161 
162  for (reco::MuonTrackLinksCollection::const_iterator links = muHandle->begin(); links != muHandle->end(); ++links) {
163  RefToBase<Track> glbRef = RefToBase<Track>(links->globalTrack());
164  RefToBase<Track> staRef = RefToBase<Track>(links->standAloneTrack());
165  RefToBase<Track> tkRef = RefToBase<Track>(links->trackerTrack());
166 
167  std::vector<std::pair<TrackingParticleRef, double> > tp1;
168  TrackingParticleRef tp1r;
169  if (glbrecoToSimCollection.find(glbRef) != glbrecoToSimCollection.end()) {
170  tp1 = glbrecoToSimCollection[glbRef];
171  if (!tp1.empty()) {
172  tp1r = tp1.begin()->first;
173  }
174  }
175 
176  std::vector<std::pair<TrackingParticleRef, double> > tp2;
177  TrackingParticleRef tp2r;
178  if (starecoToSimCollection.find(staRef) != starecoToSimCollection.end()) {
179  tp2 = starecoToSimCollection[staRef];
180  if (!tp2.empty()) {
181  tp2r = tp2.begin()->first;
182  }
183  }
184 
185  std::vector<std::pair<TrackingParticleRef, double> > tp3;
186  TrackingParticleRef tp3r;
187  if (tkrecoToSimCollection.find(tkRef) != tkrecoToSimCollection.end()) {
188  tp3 = tkrecoToSimCollection[tkRef];
189  if (!tp3.empty()) {
190  tp3r = tp3.begin()->first;
191  }
192  }
193 
194  if (!tp1.empty()) {
195  //was reconstructed
196  h_totReco->Fill(glbRef->eta(), glbRef->pt());
197  if (tp2r == tp3r) { // && tp1r == tp3r) {
198  //came from same TP
199  h_goodMatch->Fill(glbRef->eta(), glbRef->pt());
200  } else {
201  //mis-match
202  h_fakeMatch->Fill(glbRef->eta(), glbRef->pt());
203  }
204  }
205  }
206 }
207 
208 // ------------ method called once each job just after ending the event loop ------------
212 
215 
216  if (!out.empty() && dbe_)
217  dbe_->save(out);
218 }
219 
220 //void GlobalMuonMatchAnalyzer::beginRun(const edm::Run&, const edm::EventSetup& setup)
221 
223  edm::Run const &iRun,
224  edm::EventSetup const &iSetup) {
225  // Tk Associator
226 
227  ibooker.cd();
228  // Run histos only for dqmEndRun handling
229  ibooker.setScope(MonitorElementData::Scope::RUN);
230 
231  std::string dirName = "Matcher/";
232  // ibooker.setCurrentFolder("RecoMuonV/Matcher");
233  ibooker.setCurrentFolder(dirName);
234 
235  h_shouldMatch = ibooker.book2D("h_shouldMatch", "SIM associated to Tk and Sta", 50, -2.5, 2.5, 100, 0., 500.);
236  h_goodMatchSim = ibooker.book2D("h_goodMatchSim", "SIM associated to Glb Sta Tk", 50, -2.5, 2.5, 100, 0., 500.);
237  h_tkOnlySim = ibooker.book2D("h_tkOnlySim", "SIM associated to Glb Tk", 50, -2.5, 2.5, 100, 0., 500.);
238  h_staOnlySim = ibooker.book2D("h_staOnlySim", "SIM associated to Glb Sta", 50, -2.5, 2.5, 100, 0., 500.);
239 
240  h_totReco = ibooker.book2D("h_totReco", "Total Glb Reconstructed", 50, -2.5, 2.5, 100, 0., 500.);
241  h_goodMatch = ibooker.book2D("h_goodMatch", "Sta and Tk from same SIM", 50, -2.5, 2.5, 100, 0., 500.);
242  h_fakeMatch = ibooker.book2D("h_fakeMatch", "Sta and Tk not from same SIM", 50, -2.5, 2.5, 100, 0., 500.);
243 
244  h_effic = ibooker.book1D("h_effic", "Efficiency vs #eta", 50, -2.5, 2.5);
245  h_efficPt = ibooker.book1D("h_efficPt", "Efficiency vs p_{T}", 100, 0., 100.);
246 
247  h_fake = ibooker.book1D("h_fake", "Fake fraction vs #eta", 50, -2.5, 2.5);
248  h_fakePt = ibooker.book1D("h_fakePt", "Fake fraction vs p_{T}", 100, 0., 100.);
249 }
250 
252  MonitorElement *recoTH2,
253  MonitorElement *simTH2) {
254  TH2F *h1 = recoTH2->getTH2F();
255  TH1D *reco = h1->ProjectionX();
256 
257  TH2F *h2 = simTH2->getTH2F();
258  TH1D *sim = h2->ProjectionX();
259 
260  TH1F *hEff = (TH1F *)reco->Clone();
261 
262  hEff->Divide(sim);
263 
264  hEff->SetName("tmp_" + TString(reco->GetName()));
265 
266  // Set the error accordingly to binomial statistics
267  int nBinsEta = hEff->GetNbinsX();
268  for (int bin = 1; bin <= nBinsEta; bin++) {
269  float nSimHit = sim->GetBinContent(bin);
270  float eff = hEff->GetBinContent(bin);
271  float error = 0;
272  if (nSimHit != 0 && eff <= 1) {
273  error = sqrt(eff * (1 - eff) / nSimHit);
274  }
275  hEff->SetBinError(bin, error);
276  effHist->setBinContent(bin, eff);
277  effHist->setBinError(bin, error);
278  }
279 }
280 
282  MonitorElement *recoTH2,
283  MonitorElement *simTH2) {
284  TH2F *h1 = recoTH2->getTH2F();
285  TH1D *reco = h1->ProjectionY();
286 
287  TH2F *h2 = simTH2->getTH2F();
288  TH1D *sim = h2->ProjectionY();
289 
290  TH1F *hEff = (TH1F *)reco->Clone();
291 
292  hEff->Divide(sim);
293 
294  hEff->SetName("tmp_" + TString(reco->GetName()));
295 
296  // Set the error accordingly to binomial statistics
297  int nBinsPt = hEff->GetNbinsX();
298  for (int bin = 1; bin <= nBinsPt; bin++) {
299  float nSimHit = sim->GetBinContent(bin);
300  float eff = hEff->GetBinContent(bin);
301  float error = 0;
302  if (nSimHit != 0 && eff <= 1) {
303  error = sqrt(eff * (1 - eff) / nSimHit);
304  }
305  hEff->SetBinError(bin, error);
306  effHist->setBinContent(bin, eff);
307  effHist->setBinError(bin, error);
308  }
309 }
GlobalMuonMatchAnalyzer::h_fakePt
MonitorElement * h_fakePt
Definition: GlobalMuonMatchAnalyzer.h:60
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
GlobalMuonMatchAnalyzer::h_effic
MonitorElement * h_effic
Definition: GlobalMuonMatchAnalyzer.h:59
edm::AssociationMap::find
const_iterator find(const key_type &k) const
find element with specified reference key
Definition: AssociationMap.h:173
mps_fire.i
i
Definition: mps_fire.py:428
GlobalMuonMatchAnalyzer::h_goodMatch
MonitorElement * h_goodMatch
Definition: GlobalMuonMatchAnalyzer.h:58
GlobalMuonMatchAnalyzer.h
GlobalMuonMatchAnalyzer::computeEfficiencyEta
void computeEfficiencyEta(MonitorElement *, MonitorElement *recoTH2, MonitorElement *simTH2)
Definition: GlobalMuonMatchAnalyzer.cc:251
edm::Handle::product
T const * product() const
Definition: Handle.h:70
dqm::implementation::IBooker::setScope
virtual MonitorElementData::Scope setScope(MonitorElementData::Scope newscope)
Definition: DQMStore.cc:46
ESHandle.h
GlobalMuonMatchAnalyzer::h_tkOnlySim
MonitorElement * h_tkOnlySim
Definition: GlobalMuonMatchAnalyzer.h:57
edm::Run
Definition: Run.h:45
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::TrackToTrackingParticleAssociator::associateRecoToSim
reco::RecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
Definition: TrackToTrackingParticleAssociator.h:64
GlobalMuonMatchAnalyzer::tkName_
edm::InputTag tkName_
Definition: GlobalMuonMatchAnalyzer.h:64
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
DQMStore.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
GlobalMuonMatchAnalyzer::muAssociatorToken_
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > muAssociatorToken_
Definition: GlobalMuonMatchAnalyzer.h:66
EDAnalyzer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
GlobalMuonMatchAnalyzer::h_fakeMatch
MonitorElement * h_fakeMatch
Definition: GlobalMuonMatchAnalyzer.h:58
GlobalMuonMatchAnalyzer::dqmEndRun
void dqmEndRun(const edm::Run &, const edm::EventSetup &) override
Definition: GlobalMuonMatchAnalyzer.cc:209
edm::Handle< TrackingParticleCollection >
relativeConstraints.error
error
Definition: relativeConstraints.py:53
edm::Ref< TrackingParticleCollection >
reco::TrackBase::pt
double pt() const
track transverse momentum
Definition: TrackBase.h:637
edm::AssociationMap::end
const_iterator end() const
last iterator over the map (read only)
Definition: AssociationMap.h:171
dqm::impl::MonitorElement::getTH2F
virtual TH2F * getTH2F()
Definition: MonitorElement.cc:1004
MakerMacros.h
GlobalMuonMatchAnalyzer::tpName_
edm::InputTag tpName_
Definition: GlobalMuonMatchAnalyzer.h:64
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
GlobalMuonMatchAnalyzer::iConfig
edm::ParameterSet iConfig
Definition: GlobalMuonMatchAnalyzer.h:55
reco::MuonTrackLinksCollection
std::vector< MuonTrackLinks > MuonTrackLinksCollection
collection of MuonTrackLinks
Definition: MuonFwd.h:22
GlobalMuonMatchAnalyzer::staName_
edm::InputTag staName_
Definition: GlobalMuonMatchAnalyzer.h:64
Service.h
GlobalMuonMatchAnalyzer::glbToken_
edm::EDGetTokenT< edm::View< reco::Track > > glbToken_
Definition: GlobalMuonMatchAnalyzer.h:65
MuonFwd.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
hgcalTowerMapProducer_cfi.nBinsEta
nBinsEta
Definition: hgcalTowerMapProducer_cfi.py:9
GlobalMuonMatchAnalyzer::computeEfficiencyPt
void computeEfficiencyPt(MonitorElement *, MonitorElement *recoTH2, MonitorElement *simTH2)
Definition: GlobalMuonMatchAnalyzer.cc:281
dqm::implementation::NavigatorBase::cd
virtual void cd()
Definition: DQMStore.cc:29
GlobalMuonMatchAnalyzer::out
std::string out
Definition: GlobalMuonMatchAnalyzer.h:53
GlobalMuonMatchAnalyzer::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: GlobalMuonMatchAnalyzer.cc:222
dqm::implementation::DQMStore::save
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
Definition: DQMStore.cc:761
GlobalMuonMatchAnalyzer::h_staOnlySim
MonitorElement * h_staOnlySim
Definition: GlobalMuonMatchAnalyzer.h:57
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
GlobalMuonMatchAnalyzer::dbe_
DQMStore * dbe_
Definition: GlobalMuonMatchAnalyzer.h:54
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GlobalMuonMatchAnalyzer::~GlobalMuonMatchAnalyzer
~GlobalMuonMatchAnalyzer() override
Definition: GlobalMuonMatchAnalyzer.cc:60
GlobalMuonMatchAnalyzer::h_fake
MonitorElement * h_fake
Definition: GlobalMuonMatchAnalyzer.h:60
GlobalMuonMatchAnalyzer::muAssociatorName_
edm::InputTag muAssociatorName_
Definition: GlobalMuonMatchAnalyzer.h:63
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
sim
Definition: GeometryProducer.h:20
reco::TrackBase::eta
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
GlobalMuonMatchAnalyzer::h_totReco
MonitorElement * h_totReco
Definition: GlobalMuonMatchAnalyzer.h:58
GlobalMuonMatchAnalyzer::subsystemname_
std::string subsystemname_
Definition: GlobalMuonMatchAnalyzer.h:56
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
GlobalMuonMatchAnalyzer::GlobalMuonMatchAnalyzer
GlobalMuonMatchAnalyzer(const edm::ParameterSet &)
Definition: GlobalMuonMatchAnalyzer.cc:34
edm::EventSetup
Definition: EventSetup.h:58
InputTag.h
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
GlobalMuonMatchAnalyzer::staToken_
edm::EDGetTokenT< edm::View< reco::Track > > staToken_
Definition: GlobalMuonMatchAnalyzer.h:65
GlobalMuonMatchAnalyzer::h_efficPt
MonitorElement * h_efficPt
Definition: GlobalMuonMatchAnalyzer.h:59
TrackingParticle.h
dqm::impl::MonitorElement::setBinContent
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
Definition: MonitorElement.cc:691
GlobalMuonMatchAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: GlobalMuonMatchAnalyzer.cc:70
GlobalMuonMatchAnalyzer::glbName_
edm::InputTag glbName_
Definition: GlobalMuonMatchAnalyzer.h:64
Frameworkfwd.h
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
GlobalMuonMatchAnalyzer::tkAssociatorToken_
edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > tkAssociatorToken_
Definition: GlobalMuonMatchAnalyzer.h:66
electronStore.links
links
Definition: electronStore.py:149
dqm::impl::MonitorElement::setBinError
virtual void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
Definition: MonitorElement.cc:709
GlobalMuonMatchAnalyzer::tkAssociatorName_
edm::InputTag tkAssociatorName_
Definition: GlobalMuonMatchAnalyzer.h:63
TrackerOfflineValidation_Dqm_cff.dirName
dirName
Definition: TrackerOfflineValidation_Dqm_cff.py:55
TrackingParticleCollection
std::vector< TrackingParticle > TrackingParticleCollection
Definition: TrackingParticleFwd.h:9
edm::RefToBase
Definition: AssociativeIterator.h:54
reco::TrackToTrackingParticleAssociator::associateSimToReco
reco::SimToRecoCollection associateSimToReco(const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
Definition: TrackToTrackingParticleAssociator.h:71
dqm::implementation::IBooker
Definition: DQMStore.h:43
ParameterSet.h
edm::Event
Definition: Event.h:73
GlobalMuonMatchAnalyzer::tkToken_
edm::EDGetTokenT< edm::View< reco::Track > > tkToken_
Definition: GlobalMuonMatchAnalyzer.h:65
SimTrackContainer.h
edm::InputTag
Definition: InputTag.h:15
GlobalMuonMatchAnalyzer::h_shouldMatch
MonitorElement * h_shouldMatch
Definition: GlobalMuonMatchAnalyzer.h:57
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
GlobalMuonMatchAnalyzer::tpToken_
edm::EDGetTokenT< edm::View< reco::Track > > tpToken_
Definition: GlobalMuonMatchAnalyzer.h:65
GlobalMuonMatchAnalyzer::h_goodMatchSim
MonitorElement * h_goodMatchSim
Definition: GlobalMuonMatchAnalyzer.h:57