CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ZMuMuAnalyzer.cc
Go to the documentation of this file.
1 /* \class ZMuMuAnalyzer
2  *
3  * Z->mu+m- standard analysis for cross section
4  * measurements. Take as input the output of the
5  * standard EWK skim: zToMuMu
6  *
7  * Produces mass spectra and other histograms for
8  * the samples in input:
9  *
10  * + Z -> mu+mu-, both muons are "global" muons
11  * + Z -> mu+mu-, one muons is "global" muons, one unmatched tracks
12  * + Z -> mu+mu-, one muons is "global" muons, one unmatched stand-alone muon
13  *
14  *
15  * \author Michele de Gruttola, INFN Naples
16  *
17  *
18  */
31 #include "TH1.h"
32 #include <iostream>
33 #include <iterator>
34 using namespace edm;
35 using namespace std;
36 using namespace reco;
37 
39 
41 public:
42  ZMuMuAnalyzer(const edm::ParameterSet& pset);
43 private:
44  virtual void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
45  virtual void endJob() override;
46 
51  InputTag muIso_, trackIso_, standAloneIso_;
52  InputTag zMuMuMap_ ,zMuTrackMap_, zMuStandAloneMap_;
53  double isocut_, etacut_, ptcut_,ptSTAcut_, minZmass_, maxZmass_;
54  TH1D * h_zMuMu_mass_, * h_zMuSingleTrack_mass_, * h_zMuSingleStandAlone_mass_,* h_zMuSingleStandAloneOverlap_mass_,
55  * h_zMuMuMatched_mass_,
57  * h_zMuSingleStandAloneMatched_mass_,
58  * h_zMuSingleStandAloneOverlapMatched_mass_;
59 };
60 
62  zMuMu_( pset.getParameter<InputTag>( "zMuMu" ) ),
63  zMuTrack_( pset.getParameter<InputTag>( "zMuTrack" ) ),
64  zMuStandAlone_( pset.getParameter<InputTag>( "zMuStandAlone" ) ),
65  muIso_( pset.getParameter<InputTag>( "muIso" ) ),
66  trackIso_( pset.getParameter<InputTag>( "trackIso" ) ),
67  standAloneIso_( pset.getParameter<InputTag>( "standAloneIso" ) ),
68  zMuMuMap_( pset.getParameter<InputTag>( "zMuMuMap" ) ),
69  zMuTrackMap_( pset.getParameter<InputTag>( "zMuTrackMap" ) ),
70  zMuStandAloneMap_( pset.getParameter<InputTag>( "zMuStandAloneMap" ) ),
71  isocut_( pset.getParameter<double>( "isocut" ) ),
72  etacut_( pset.getParameter<double>( "etacut" ) ),
73  ptcut_( pset.getParameter<double>( "ptcut" ) ),
74  ptSTAcut_( pset.getParameter<double>( "ptSTAcut" ) ),
75 
76  minZmass_( pset.getParameter<double>( "minZmass" )),
77  maxZmass_( pset.getParameter<double>( "maxZmass" )) {
78 
80  h_zMuMu_mass_ = fs->make<TH1D>( "ZMuMumass", "ZMuMu mass(GeV)", 200, 0., 200. );
81  h_zMuSingleTrack_mass_ = fs->make<TH1D>( "ZMuSingleTrackmass", "ZMuSingleTrack mass(GeV)", 100, 0., 200. );
82  h_zMuSingleStandAlone_mass_ = fs->make<TH1D>( "ZMuSingleStandAlonemass", "ZMuSingleStandAlone mass(GeV)", 50, 0., 200. );
83  h_zMuSingleStandAloneOverlap_mass_ = fs->make<TH1D>( "ZMuSingleStandAloneOverlapmass", "ZMuSingleStandAloneOverlap mass(GeV)", 50, 0., 200. );
84 
85 
86  h_zMuMuMatched_mass_ = fs->make<TH1D>( "ZMuMuMatchedmass", "ZMuMu Matched mass(GeV)", 200, 0., 200. );
87  h_zMuSingleTrackMatched_mass_ = fs->make<TH1D>( "ZMuSingleTrackmassMatched", "ZMuSingleTrackMatched mass(GeV)", 100, 0., 200. );
88  h_zMuSingleStandAloneMatched_mass_ = fs->make<TH1D>( "ZMuSingleStandAlonemassMatched", "ZMuSingleStandAloneMatched mass(GeV)", 50, 0., 200. );
89  h_zMuSingleStandAloneOverlapMatched_mass_ = fs->make<TH1D>( "ZMuSingleStandAloneOverlapmassMatched", "ZMuSingleStandAloneMatched Overlap mass(GeV)", 50, 0., 200. );
90 }
91 
94  event.getByLabel(zMuMu_, zMuMu);
96  event.getByLabel( zMuTrack_, zMuTrack );
97  Handle<CandidateCollection> zMuStandAlone;
98  event.getByLabel( zMuStandAlone_, zMuStandAlone );
99 
100  unsigned int nZMuMu = zMuMu->size();
101  unsigned int nZTrackMu = zMuTrack->size();
102  unsigned int nZStandAloneMu = zMuStandAlone->size();
103  static const double zMass = 91.1876; // PDG Z mass
104 
105  // cout << "nZMuMu = " << nZMuMu << endl;
106  // cout << "nZTrackMu = " << nZTrackMu << endl;
107  // cout << "nZStandAloneMu = " << nZStandAloneMu << endl;
108 
109  Handle<CandMatchMap> zMuMuMap;
110  if( nZMuMu > 0 ) {
111  event.getByLabel(zMuMuMap_, zMuMuMap);
112  }
113 
114  Handle<CandMatchMap> zMuTrackMap;
115  if( nZTrackMu > 0 ) {
116  event.getByLabel( zMuTrackMap_, zMuTrackMap );
117  }
118 
119  Handle<CandMatchMap> zMuStandAloneMap;
120  if( nZStandAloneMu > 0 ) {
121  event.getByLabel( zMuStandAloneMap_, zMuStandAloneMap );
122  }
123 
125  event.getByLabel(muIso_, muIso);
126  ProductID muIsoId = muIso->keyProduct().id();
128  event.getByLabel(trackIso_, trackIso);
129  ProductID trackIsoId = trackIso->keyProduct().id();
130 
131  Handle<IsolationCollection> standAloneIso;
132  event.getByLabel(standAloneIso_, standAloneIso);
133  ProductID standAloneIsoId = standAloneIso->keyProduct().id();
134 
135  if (nZMuMu > 0) {
136  double mass = 1000000.;
137  for( unsigned int i = 0; i < nZMuMu; i++ ) {
138  const Candidate & zmmCand = (*zMuMu)[ i ];
139  CandidateRef CandRef(zMuMu,i);
140  CandidateRef lep1 = zmmCand.daughter( 0 )->masterClone().castTo<CandidateRef>();
141  CandidateRef lep2 = zmmCand.daughter( 1 )->masterClone().castTo<CandidateRef>();
142 
143  const double iso1 = muIso->value( lep1.key() );
144  const double iso2 = muIso->value( lep2.key() );
145 
146  double m = zmmCand.mass();
147  if (lep1->pt()>ptcut_ && lep2->pt()>ptcut_ &&
148  fabs(lep1->eta())<etacut_ && fabs(lep2->eta())<etacut_ &&
149  m>minZmass_ && m<maxZmass_ && iso1 < isocut_ && iso2 <isocut_) {
150  if ( fabs( mass - zMass ) > fabs( m - zMass ) ) {
151  mass = m;
152  }
153 
154  h_zMuMu_mass_->Fill( mass );
155  CandMatchMap::const_iterator m0 = zMuMuMap->find(CandRef);
156  if( m0 != zMuMuMap->end()) {
157  h_zMuMuMatched_mass_->Fill( mass );
158  }
159  }
160  }
161  }
162 
163  //ZmuSingleTRack
164  if (nZMuMu ==0 && nZTrackMu>0) {
165  for( unsigned int j = 0; j < nZTrackMu; j++ ) {
166  const Candidate & ztmCand = (*zMuTrack)[ j ];
167  CandidateRef CandRef(zMuTrack,j);
168  CandidateRef lep1 = ztmCand.daughter( 0 )->masterClone().castTo<CandidateRef>();
169  CandidateRef lep2 = ztmCand.daughter( 1 )->masterClone().castTo<CandidateRef>();
170 
171  ProductID id1 = lep1.id();
172  ProductID id2 = lep2.id();
173  double iso1 = -1;
174  double iso2 = -1;
175 
176  if( id1 == muIsoId )
177  iso1 = muIso->value( lep1.key() );
178  else if ( id1 == trackIsoId )
179  iso1 = trackIso->value( lep1.key() );
180 
181  if( id2 == muIsoId )
182  iso2 = muIso->value( lep2.key() );
183  else if ( id2 == trackIsoId )
184  iso2 = trackIso->value( lep2.key() );
185 
186  double mt = ztmCand.mass();
187  if (lep1->pt()>ptcut_ && lep2->pt()>ptcut_ &&
188  fabs(lep1->eta())<etacut_ && fabs(lep2->eta())<etacut_ &&
189  mt>minZmass_ && mt<maxZmass_ && iso1<isocut_ && iso2 <isocut_) {
190  h_zMuSingleTrack_mass_->Fill( mt );
191  CandMatchMap::const_iterator m0 = zMuTrackMap->find(CandRef);
192  if( m0 != zMuTrackMap->end()) {
193  h_zMuSingleTrackMatched_mass_->Fill( mt );
194  }
195  }
196  }
197  }
198 
199  //ZmuSingleStandAlone
200  if (nZMuMu ==0 && nZStandAloneMu>0) {
201  // unsigned int index = 1000;
202  for( unsigned int j = 0; j < nZStandAloneMu; j++ ) {
203  const Candidate & zsmCand = (*zMuStandAlone)[ j ];
204  CandidateRef CandRef(zMuStandAlone,j);
205  CandidateRef lep1 = zsmCand.daughter( 0 )->masterClone().castTo<CandidateRef>();
206  CandidateRef lep2 = zsmCand.daughter( 1 )->masterClone().castTo<CandidateRef>();
207 
208  ProductID id1 = lep1.id();
209  ProductID id2 = lep2.id();
210  double iso1 = -1;
211  double iso2 = -1;
212 
213  if( id1 == muIsoId )
214  iso1 = muIso->value( lep1.key() );
215  else if ( id1 == standAloneIsoId )
216  iso1 = standAloneIso->value( lep1.key() );
217 
218  if( id2 == muIsoId )
219  iso2 = muIso->value( lep2.key() );
220  else if ( id2 == standAloneIsoId )
221  iso2 = standAloneIso->value( lep2.key() );
222 
223  double ms = zsmCand.mass();
224  if (lep1->pt()>ptSTAcut_ && lep2->pt()>ptSTAcut_ &&
225  fabs(lep1->eta())<etacut_ && fabs(lep2->eta())<etacut_ &&
226  ms>minZmass_ && ms<maxZmass_ && iso1<isocut_ && iso2 <isocut_) {
227  h_zMuSingleStandAlone_mass_->Fill( ms );
228  CandMatchMap::const_iterator m0 = zMuStandAloneMap->find(CandRef);
229  if( m0 != zMuStandAloneMap->end()) {
231  }
232 
233  bool noOverlap = true;
234  for( unsigned int j = 0; j < zMuTrack->size(); j++ ) {
235  const Candidate & ztmCand = (*zMuTrack)[ j ];
236  CandidateRef CandReft(zMuTrack,j);
237 
238  CandidateRef lep1 = ztmCand.daughter( 0 )->masterClone().castTo<CandidateRef>();
239  CandidateRef lep2 = ztmCand.daughter( 1 )->masterClone().castTo<CandidateRef>();
240 
241  ProductID id1 = lep1.id();
242  ProductID id2 = lep2.id();
243  double iso1 = -1;
244  double iso2 = -1;
245 
246  if( id1 == muIsoId )
247  iso1 = muIso->value( lep1.key() );
248  else if ( id1 == trackIsoId )
249  iso1 = trackIso->value( lep1.key() );
250 
251  if( id2 == muIsoId )
252  iso2 = muIso->value( lep2.key() );
253  else if ( id2 == trackIsoId )
254  iso2 = trackIso->value( lep2.key() );
255 
256  double mt = ztmCand.mass();
257  if (lep1->pt()>ptcut_ && lep2->pt()>ptcut_ &&
258  fabs(lep1->eta())<etacut_ && fabs(lep2->eta())<etacut_ &&
259  mt>minZmass_ && mt<maxZmass_ && iso1<isocut_ && iso2 <isocut_) {
260 
261  if ( overlap_( ztmCand, zsmCand ) ) {
262  noOverlap = false;
263  break;
264  }
265  if (!noOverlap ) {
267  CandMatchMap::const_iterator m1 = zMuTrackMap->find(CandReft);
268  CandMatchMap::const_iterator m2 = zMuStandAloneMap->find(CandRef);
269 
270  if( m1 != zMuTrackMap->end() && m2 != zMuStandAloneMap->end() ) {
272  }
273  }
274  }
275  }
276  }
277  }
278  }
279 }
280 
282  double Nzmm = h_zMuMu_mass_->GetEntries() ;
283  double Nzsm = h_zMuSingleStandAlone_mass_->GetEntries() ;
284  double Nzsnom = h_zMuSingleStandAloneOverlap_mass_->GetEntries() ;
285  double Nztm = h_zMuSingleTrack_mass_->GetEntries();
286 
287  double NzmmMatch = h_zMuMuMatched_mass_->GetEntries() ;
288  double NzsmMatch = h_zMuSingleStandAloneMatched_mass_->GetEntries() ;
289  double NzsnomMatch = h_zMuSingleStandAloneOverlapMatched_mass_->GetEntries() ;
290  double NztmMatch = h_zMuSingleTrackMatched_mass_->GetEntries();
291 
292  cout<<"-- N SingleTrackMu = "<<Nztm<<endl;
293  cout<<"-----N SinglStandAloneMu = "<<Nzsm<<endl;
294  cout<<"-----N SingleStandAloneOverlapMu = "<<Nzsnom<<endl;
295  cout<<"------- N MuMu = "<<Nzmm<<endl;
296 
297  cout<<"-- N SingleTrackMuMatched = "<<NztmMatch<<endl;
298  cout<<"-----N SinglStandAloneMuMatched = "<<NzsmMatch<<endl;
299  cout<<"-----N SingleStandAloneOverlapMuMatched = "<<NzsnomMatch<<endl;
300  cout<<"------- N MuMu Matched = "<<NzmmMatch<<endl;
301 }
302 
304 
306 
InputTag trackIso_
int i
Definition: DBlmapReader.cc:9
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
InputTag zMuStandAlone_
virtual float mass() const =0
mass
ProductID id() const
Definition: HandleBase.cc:15
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
InputTag muIso_
TH1D * h_zMuMu_mass_
InputTag zMuTrack_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
virtual void analyze(const edm::Event &event, const edm::EventSetup &setup) override
ZMuMuAnalyzer(const edm::ParameterSet &pset)
InputTag zMuStandAloneMap_
edm::ValueMap< float > IsolationCollection
InputTag zMuMu_
int j
Definition: DBlmapReader.cc:9
TH1D * h_zMuSingleStandAloneOverlap_mass_
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
InputTag zMuMuMap_
OverlapChecker overlap_
TH1D * h_zMuSingleTrack_mass_
TH1D * h_zMuMuMatched_mass_
virtual void endJob() override
REF castTo() const
cast to a concrete type
Definition: RefToBase.h:241
key_type key() const
Accessor for product key.
Definition: Ref.h:266
TH1D * h_zMuSingleStandAlone_mass_
susybsm::MuonSegment ms
Definition: classes.h:31
TH1D * h_zMuSingleStandAloneOverlapMatched_mass_
InputTag standAloneIso_
TH1D * h_zMuSingleTrackMatched_mass_
tuple cout
Definition: gather_cfg.py:121
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
ProductIndex id() const
Definition: ProductID.h:38
TH1D * h_zMuSingleStandAloneMatched_mass_
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple zMuMu
zMuMu vector of PSet is common to all categories except zMuTrk category
InputTag zMuTrackMap_
virtual const CandidateBaseRef & masterClone() const =0