CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GlobalMuonMatchAnalyzer.cc
Go to the documentation of this file.
1 
14 
15 // user include files
21 
24 
28 
35 
39 
40 #include <TH2.h>
41 
42 
44 
45 {
46  //now do what ever initialization is needed
47  tkAssociatorName_ = iConfig.getUntrackedParameter<std::string>("tkAssociator");
48  muAssociatorName_ = iConfig.getUntrackedParameter<std::string>("muAssociator");
49 
50  tpName_ = iConfig.getUntrackedParameter<edm::InputTag>("tpLabel");
51  tkName_ = iConfig.getUntrackedParameter<edm::InputTag>("tkLabel");
52  staName_ = iConfig.getUntrackedParameter<edm::InputTag>("muLabel");
53  glbName_ = iConfig.getUntrackedParameter<edm::InputTag>("glbLabel");
54 
55  out = iConfig.getUntrackedParameter<std::string>("out");
57 }
58 
59 
61 {
62 
63  // do anything here that needs to be done at desctruction time
64  // (e.g. close files, deallocate resources etc.)
65 
66 }
67 
68 
69 //
70 // member functions
71 //
72 
73 // ------------ method called to for each event ------------
74 void
76 {
77  using namespace edm;
78  using namespace reco;
79 
81  iEvent.getByLabel(tpName_,tpHandle);
82  const TrackingParticleCollection tpColl = *(tpHandle.product());
83 
85  iEvent.getByLabel(glbName_,muHandle);
86  const reco::MuonTrackLinksCollection muColl = *(muHandle.product());
87 
88  Handle<View<Track> > staHandle;
89  iEvent.getByLabel(staName_,staHandle);
90  // const reco::TrackCollection staColl = *(staHandle.product());
91 
92  Handle<View<Track> > glbHandle;
93  iEvent.getByLabel(glbName_,glbHandle);
94  // const reco::TrackCollection glbColl = *(glbHandle.product());
95 
96  Handle<View<Track> > tkHandle;
97  iEvent.getByLabel(tkName_,tkHandle);
98  // const reco::TrackCollection mtkColl = *(tkHandle.product());
99 
100  reco::RecoToSimCollection tkrecoToSimCollection;
101  reco::SimToRecoCollection tksimToRecoCollection;
102  tkrecoToSimCollection = tkAssociator_->associateRecoToSim(tkHandle,tpHandle,&iEvent);
103  tksimToRecoCollection = tkAssociator_->associateSimToReco(tkHandle,tpHandle,&iEvent);
104 
105  reco::RecoToSimCollection starecoToSimCollection;
106  reco::SimToRecoCollection stasimToRecoCollection;
107  starecoToSimCollection = muAssociator_->associateRecoToSim(staHandle,tpHandle,&iEvent);
108  stasimToRecoCollection = muAssociator_->associateSimToReco(staHandle,tpHandle,&iEvent);
109 
110  reco::RecoToSimCollection glbrecoToSimCollection;
111  reco::SimToRecoCollection glbsimToRecoCollection;
112  glbrecoToSimCollection = muAssociator_->associateRecoToSim(glbHandle,tpHandle,&iEvent);
113  glbsimToRecoCollection = muAssociator_->associateSimToReco(glbHandle,tpHandle,&iEvent);
114 
115 
116  for (TrackingParticleCollection::size_type i=0; i<tpColl.size(); ++i){
117  TrackingParticleRef tp(tpHandle,i);
118 
119  std::vector<std::pair<RefToBase<Track>, double> > rvGlb;
120  RefToBase<Track> rGlb;
121  if(glbsimToRecoCollection.find(tp) != glbsimToRecoCollection.end()){
122  rvGlb = glbsimToRecoCollection[tp];
123  if(rvGlb.size() != 0) {
124  rGlb = rvGlb.begin()->first;
125  }
126  }
127 
128  std::vector<std::pair<RefToBase<Track>, double> > rvSta;
129  RefToBase<Track> rSta;
130  if(stasimToRecoCollection.find(tp) != stasimToRecoCollection.end()){
131  rvSta = stasimToRecoCollection[tp];
132  if(rvSta.size() != 0) {
133  rSta = rvSta.begin()->first;
134  }
135  }
136 
137  std::vector<std::pair<RefToBase<Track>, double> > rvTk;
138  RefToBase<Track> rTk;
139  if(tksimToRecoCollection.find(tp) != tksimToRecoCollection.end()){
140  rvTk = tksimToRecoCollection[tp];
141  if(rvTk.size() != 0) {
142  rTk = rvTk.begin()->first;
143  }
144  }
145 
146  if( rvSta.size() != 0 && rvTk.size() != 0 ){
147  //should have matched
148  h_shouldMatch->Fill(rTk->eta(),rTk->pt());
149  }
150 
151  for ( reco::MuonTrackLinksCollection::const_iterator links = muHandle->begin(); links != muHandle->end(); ++links ) {
152  if( rGlb == RefToBase<Track>(links->globalTrack() ) ) {
153  if( RefToBase<Track>(links->trackerTrack() ) == rTk &&
154  RefToBase<Track>(links->standAloneTrack() ) == rSta ) {
155  //goodMatch
156  h_goodMatchSim->Fill(rGlb->eta(),rGlb->pt());
157  }
158  if ( RefToBase<Track>(links->trackerTrack() ) == rTk &&
159  RefToBase<Track>(links->standAloneTrack() ) != rSta ) {
160  //tkOnlyMatch
161  h_tkOnlySim->Fill(rGlb->eta(),rGlb->pt());
162  }
163  if ( RefToBase<Track>(links->standAloneTrack() ) == rSta &&
164  RefToBase<Track>(links->trackerTrack() ) != rTk ) {
165  //staOnlyMatch
166  h_staOnlySim->Fill(rGlb->eta(),rGlb->pt());
167  }
168  }
169  }
170 
171  }
172 
174 
175  for ( reco::MuonTrackLinksCollection::const_iterator links = muHandle->begin(); links != muHandle->end(); ++links ) {
176  RefToBase<Track> glbRef = RefToBase<Track>(links->globalTrack() );
177  RefToBase<Track> staRef = RefToBase<Track>(links->standAloneTrack() );
178  RefToBase<Track> tkRef = RefToBase<Track>(links->trackerTrack() );
179 
180  std::vector<std::pair<TrackingParticleRef, double> > tp1;
181  TrackingParticleRef tp1r;
182  if(glbrecoToSimCollection.find(glbRef) != glbrecoToSimCollection.end()){
183  tp1 = glbrecoToSimCollection[glbRef];
184  if(tp1.size() != 0) {
185  tp1r = tp1.begin()->first;
186  }
187  }
188 
189  std::vector<std::pair<TrackingParticleRef, double> > tp2;
190  TrackingParticleRef tp2r;
191  if(starecoToSimCollection.find(staRef) != starecoToSimCollection.end()){
192  tp2 = starecoToSimCollection[staRef];
193  if(tp2.size() != 0) {
194  tp2r = tp2.begin()->first;
195  }
196  }
197 
198  std::vector<std::pair<TrackingParticleRef, double> > tp3;
199  TrackingParticleRef tp3r;
200  if(tkrecoToSimCollection.find(tkRef) != tkrecoToSimCollection.end()){
201  tp3 = tkrecoToSimCollection[tkRef];
202  if(tp3.size() != 0) {
203  tp3r = tp3.begin()->first;
204  }
205  }
206 
207 
208  if(tp1.size() != 0) {
209  //was reconstructed
210  h_totReco->Fill(glbRef->eta(),glbRef->pt());
211  if(tp2r == tp3r) { // && tp1r == tp3r) {
212  //came from same TP
213  h_goodMatch->Fill(glbRef->eta(),glbRef->pt());
214  } else {
215  //mis-match
216  h_fakeMatch->Fill(glbRef->eta(),glbRef->pt());
217  }
218  }
219 
220  }
221 
222 
223 }
224 
225 
226 // ------------ method called once each job just before starting event loop ------------
227 void
229 {
230  dbe_->cd();
231  std::string dirName="Matcher/";
232  dbe_->setCurrentFolder("RecoMuonV/Matcher");
233 
234  h_shouldMatch = dbe_->book2D("h_shouldMatch","SIM associated to Tk and Sta",50,-2.5,2.5,100,0.,500.);
235  h_goodMatchSim = dbe_->book2D("h_goodMatchSim","SIM associated to Glb Sta Tk",50,-2.5,2.5,100,0.,500.);
236  h_tkOnlySim = dbe_->book2D("h_tkOnlySim","SIM associated to Glb Tk",50,-2.5,2.5,100,0.,500.);
237  h_staOnlySim = dbe_->book2D("h_staOnlySim","SIM associated to Glb Sta",50,-2.5,2.5,100,0.,500.);
238 
239  h_totReco = dbe_->book2D("h_totReco","Total Glb Reconstructed",50,-2.5,2.5,100,0.,500.);
240  h_goodMatch = dbe_->book2D("h_goodMatch","Sta and Tk from same SIM",50,-2.5,2.5,100, 0., 500.);
241  h_fakeMatch = dbe_->book2D("h_fakeMatch","Sta and Tk not from same SIM",50,-2.5,2.5,100,0.,500.);
242 
243  h_effic = dbe_->book1D("h_effic","Efficiency vs #eta",50,-2.5,2.5);
244  h_efficPt = dbe_->book1D("h_efficPt","Efficiency vs p_{T}",100,0.,100.);
245 
246  h_fake = dbe_->book1D("h_fake","Fake fraction vs #eta",50,-2.5,2.5);
247  h_fakePt = dbe_->book1D("h_fakePt","Fake fraction vs p_{T}",100,0.,100.);
248 }
249 
250 // ------------ method called once each job just after ending the event loop ------------
251 void
255 
258 
259  if( out.size() != 0 && dbe_ ) dbe_->save(out);
260 }
261 
263 {
264  // Tk Associator
265  edm::ESHandle<TrackAssociatorBase> tkassociatorHandle;
266  setup.get<TrackAssociatorRecord>().get(tkAssociatorName_,tkassociatorHandle);
267  tkAssociator_ = tkassociatorHandle.product();
268 
269  // Mu Associator
270  edm::ESHandle<TrackAssociatorBase> muassociatorHandle;
271  setup.get<TrackAssociatorRecord>().get(muAssociatorName_,muassociatorHandle);
272  muAssociator_ = muassociatorHandle.product();
273 }
274 
275 
276 
278  TH2F * h1 = recoTH2->getTH2F();
279  TH1D* reco = h1->ProjectionX();
280 
281  TH2F * h2 =simTH2->getTH2F();
282  TH1D* sim = h2 ->ProjectionX();
283 
284 
285  TH1F *hEff = (TH1F*) reco->Clone();
286 
287  hEff->Divide(sim);
288 
289  hEff->SetName("tmp_"+TString(reco->GetName()));
290 
291  // Set the error accordingly to binomial statistics
292  int nBinsEta = hEff->GetNbinsX();
293  for(int bin = 1; bin <= nBinsEta; bin++) {
294  float nSimHit = sim->GetBinContent(bin);
295  float eff = hEff->GetBinContent(bin);
296  float error = 0;
297  if(nSimHit != 0 && eff <= 1) {
298  error = sqrt(eff*(1-eff)/nSimHit);
299  }
300  hEff->SetBinError(bin, error);
301  effHist->setBinContent(bin,eff);
302  effHist->setBinError(bin,error);
303  }
304 
305 }
306 
308  TH2F * h1 = recoTH2->getTH2F();
309  TH1D* reco = h1->ProjectionY();
310 
311  TH2F * h2 = simTH2->getTH2F();
312  TH1D* sim = h2 ->ProjectionY();
313 
314 
315  TH1F *hEff = (TH1F*) reco->Clone();
316 
317  hEff->Divide(sim);
318 
319  hEff->SetName("tmp_"+TString(reco->GetName()));
320 
321  // Set the error accordingly to binomial statistics
322  int nBinsPt = hEff->GetNbinsX();
323  for(int bin = 1; bin <= nBinsPt; bin++) {
324  float nSimHit = sim->GetBinContent(bin);
325  float eff = hEff->GetBinContent(bin);
326  float error = 0;
327  if(nSimHit != 0 && eff <= 1) {
328  error = sqrt(eff*(1-eff)/nSimHit);
329  }
330  hEff->SetBinError(bin, error);
331  effHist->setBinContent(bin,eff);
332  effHist->setBinError(bin,error);
333  }
334 
335 }
336 
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
const TrackAssociatorBase * muAssociator_
void setBinContent(int binx, double content)
set content of bin (1-D)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
std::vector< TrackingParticle > TrackingParticleCollection
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:406
virtual reco::SimToRecoCollection associateSimToReco(edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event=0, const edm::EventSetup *setup=0) const
compare reco to sim the handle of reco::Track and TrackingParticle collections
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2113
Definition: sim.h:19
uint16_t size_type
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::vector< MuonTrackLinks > MuonTrackLinksCollection
collection of MuonTrackLinks
Definition: MuonFwd.h:22
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:243
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
T sqrt(T t)
Definition: SSEVec.h:46
void computeEfficiencyPt(MonitorElement *, MonitorElement *recoTH2, MonitorElement *simTH2)
double pt() const
track transverse momentum
Definition: TrackBase.h:131
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual reco::RecoToSimCollection associateRecoToSim(edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event=0, const edm::EventSetup *setup=0) const
compare reco to sim the handle of reco::Track and TrackingParticle collections
GlobalMuonMatchAnalyzer(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
const TrackAssociatorBase * tkAssociator_
TH2F * getTH2F(void) const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
void computeEfficiencyEta(MonitorElement *, MonitorElement *recoTH2, MonitorElement *simTH2)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
Definition: Run.h:33