CMS 3D CMS Logo

TTbarSpinCorrHepMCAnalyzer.cc
Go to the documentation of this file.
3 //
4 // constructors and destructor
5 //
7  genEventInfoProductTag_(iConfig.getParameter<edm::InputTag>("genEventInfoProductTag")),
8  genParticlesTag_(iConfig.getParameter<edm::InputTag>("genParticlesTag"))
9 {
10 
11  genEventInfoProductTagToken_=consumes<GenEventInfoProduct>(genEventInfoProductTag_);
12  genParticlesTagToken_=consumes<reco::GenParticleCollection>(genParticlesTag_);
13 
14 }
15 
16 
18 
19 //
20 // member functions
21 //
22 
23 // ------------ method called for each event ------------
25  using namespace edm;
26 
27  // --- the MC weights ---
29  iEvent.getByToken(genEventInfoProductTagToken_, evt_info);
30  if (evt_info.failedToGet())
31  return;
32 
33  weight = evt_info->weight() ;
34 
35  // --- get genParticles ---
37  iEvent.getByToken(genParticlesTagToken_, genParticles);
38 
39  const reco::GenParticle * _lepton (nullptr) ;
40  const reco::GenParticle * _leptonBar(nullptr) ;
41 
42  bool hasTop(false), hasTopbar(false);
43  for(size_t i = 0; i < genParticles->size(); ++ i) {
44  const reco::GenParticle & p = (*genParticles)[i];
45  if(p.pdgId() == 6) hasTop=true;
46  if(p.pdgId() == -6) hasTopbar=true;
47  }
48 
49  if(hasTop && hasTopbar){
50  // --- get status 3 leptons
51  for(size_t i = 0; i < genParticles->size(); ++ i) {
52  const reco::GenParticle & p = (*genParticles)[i];
53  if ( (p.pdgId() == 11 ||
54  p.pdgId() == 13 ||
55  p.pdgId() == 15) && p.status() == 3) { _lepton = &p ; }
56  if ( (p.pdgId() == -11 ||
57  p.pdgId() == -13 ||
58  p.pdgId() == -15) && p.status() == 3) { _leptonBar = &p ; }
59 
60  if (_lepton && _leptonBar) break;
61  }
62 
63  if (_lepton && _leptonBar) {
64 
65  const math::XYZTLorentzVector& lepton = _lepton ->p4() ;
66  const math::XYZTLorentzVector& leptonBar = _leptonBar->p4() ;
67 
68  double deltaPhi = fabs(TVector2::Phi_mpi_pi(lepton.phi() - leptonBar.phi())) ;
69  _h_deltaPhi->Fill(deltaPhi, weight) ;
70 
71  double asym = ( deltaPhi > CLHEP::halfpi ) ? 0.5 : -0.5 ;
72  _h_asym->Fill(asym, weight) ;
73 
74  math::XYZTLorentzVector llpair = lepton + leptonBar ;
75 
76  double llpairPt = llpair.pt() ;
77  _h_llpairPt->Fill(llpairPt, weight) ;
78 
79  double llpairM = llpair.M() ;
80  _h_llpairM ->Fill(llpairM , weight) ;
81 
82  }
83  nEvt->Fill(0.5 , weight) ;
84  }
85 }
86 
87 
88 // ------------ method called once each job just before starting event loop ------------
91  std::string dir="Generator/";
92  dir+="TTbarSpinCorr";
93  DQMHelper dqm(&i); i.setCurrentFolder(dir);
94 
95  // Number of analyzed events
96  nEvt = dqm.book1dHisto("nEvt", "n analyzed Events", 1, 0., 1.,"bin","Number of Events");
97  _h_asym = dqm.book1dHisto("TTbar_asym","Asymmetr", 2, -1., 1.,"Asymmetry","Number of Events");
98  _h_deltaPhi = dqm.book1dHisto("TTbar_deltaPhi","#Delta#phi(ll)", 320, 0, 3.2,"#Delta#phi_{ll} (rad)","Number of Events");
99  _h_llpairPt = dqm.book1dHisto("TTbar_llpairPt","Lepton pair transverse momentum", 1000, 0, 1000,"p_{T}^{ll} (GeV)","Number of Events");
100  _h_llpairM = dqm.book1dHisto("TTbar_llpairM","Lepton pair invariant mass", 1000, 0, 1000,"M_{ll} (GeV)","Number of Events");
101 }
102 
int pdgId() const final
PDG identifier.
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesTagToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
Definition: weight.py:1
double weight() const
MonitorElement * book1dHisto(std::string name, std::string title, int n, double xmin, double xmax, std::string xaxis, std::string yaxis)
Definition: DQMHelper.cc:12
void Fill(long long x)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:224
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
TTbarSpinCorrHepMCAnalyzer(const edm::ParameterSet &)
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
void analyze(const edm::Event &, const edm::EventSetup &) override
bool failedToGet() const
Definition: HandleBase.h:78
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
HLT enums.
int status() const final
status word
dbl *** dir
Definition: mlp_gen.cc:35
edm::EDGetTokenT< GenEventInfoProduct > genEventInfoProductTagToken_
Definition: Run.h:45