CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
STFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: STFilter
3 // Class: STFilter
17 // Original Author: Julia Weinelt
18 // Created: Wed Jan 23 15:12:46 CET 2008
19 
20 #include <memory>
21 
23 
25 
27 #include "HepMC/GenEvent.h"
28 
29 
31  hepMCProductTag_(iConfig.getParameter<edm::InputTag>("hepMCProductTag")) {
32 
33  pTMax_ = iConfig.getParameter<double>("pTMax");
34  edm::LogInfo("SingleTopMatchingFilter")<<"+++ maximum pt of associated-b pTMax = "<<pTMax_;
35  DEBUGLVL = iConfig.getUntrackedParameter<int>("debuglvl", 0); // get debug level
36  input_events=0; accepted_events=0; // counters
37  m_produceHistos = iConfig.getParameter<bool>("produceHistos"); // produce histograms?
38  fOutputFileName = iConfig.getUntrackedParameter<std::string>("histOutFile"); // get name of output file with histograms
39  conf_ = iConfig;
40 }
41 
42 
44 
46  using namespace edm;
47 
48  bool accEvt = false;
49  bool lo = false;
50 
51  int secBcount = 0;
52  double pTSecB = 100;
53  double etaSecB = 100;
54 
55  ++input_events;
56 
58  iEvent.getByLabel(hepMCProductTag_, evt);
59  const HepMC::GenEvent * myEvt = evt->GetEvent(); // GET EVENT FROM HANDLE
60 
61  bool bQuarksOpposite = false;
62  for(HepMC::GenEvent::particle_const_iterator i = myEvt->particles_begin();
63  (*i)->status() == 3; ++i) { // abort after status 3 particles
64  // logic:
65  // - in 2->2 matrix elements, the incoming (top production)
66  // b quark and the outgoing (top decay) b quark have same sign,
67  // so we flip the bQuarksOpposite flag twice -> false
68  // (opposite-sign b quark comes from the shower and has status 2)
69  // - in 2->3 matrix elements, we have two outgoing b quarks with status
70  // 3 and opposite signs -> true
71  if ((*i)->pdg_id() == -5)
72  bQuarksOpposite = !bQuarksOpposite;
73  }
74 
75  // ---- 22 or 23? ----
76  if (!bQuarksOpposite) // 22
77  lo = true;
78  else
79  accEvt = true; // 23
80 
81  // ---- filter only 22 events ----
82  if (lo){
83  for (HepMC::GenEvent::particle_const_iterator p = myEvt->particles_begin(); p!=myEvt->particles_end(); ++p){
84  // ---- look in shower for 2nd b quark ----
85  if ((*p)->status() == 2 && abs((*p)->pdg_id()) == 5){
86  // ---- if b quark is found, loop over its parents ----
87  for (HepMC::GenVertex::particle_iterator m = (*p)->production_vertex()->particles_begin(HepMC::parents);
88  m != (*p)->production_vertex()->particles_end(HepMC::parents); ++m){
89  // ---- found 2ndb-candidate in shower ---- // ---- check mother of this candidate ----
90  if(abs((*m)->barcode()) < 5){
91  if(secBcount == 1) break;
92  secBcount ++;
93  pTSecB = (*p)->operator HepMC::FourVector().perp();
94  etaSecB = (*p)->operator HepMC::FourVector().eta();
95  }
96  }
97  }
98  }
99  if(pTSecB < pTMax_) accEvt = true;
100  // fill histos if requested
101  if(m_produceHistos){
102  hbPt->Fill(pTSecB);
103  hbEta->Fill(etaSecB);
104  if(accEvt){
105  hbPtFiltered->Fill(pTSecB);
106  hbEtaFiltered->Fill(etaSecB);
107  }
108  }
109  }
110  if(accEvt) ++accepted_events;
111  return accEvt;
112 }
113 
114 
116  if(m_produceHistos){ // initialize histogram output file
118  edm::LogInfo("SingleTopMatchingFilter)")<<"beginJob : creating histogram file: "<<fOutputFileName.c_str()<<std::endl;
119  hOutputFile = new TFile( fOutputFileName.c_str(), "RECREATE" ) ; hOutputFile->cd();
120  // book histograms
121  Parameters = conf_.getParameter<edm::ParameterSet>("TH1bPt");
122  hbPt = new TH1D( "bPt", "Pt of 2nd b quark", Parameters.getParameter<int32_t>("Nbinx"), Parameters.getParameter<double>("xmin"), Parameters.getParameter<double>("xmax"));
123  Parameters = conf_.getParameter<edm::ParameterSet>("TH1bEta");
124  hbEta = new TH1D( "bEta", "Eta of 2nd b quark", Parameters.getParameter<int32_t>("Nbinx"), Parameters.getParameter<double>("xmin"), Parameters.getParameter<double>("xmax"));
125  Parameters = conf_.getParameter<edm::ParameterSet>("TH1bPtFiltered");
126  hbPtFiltered = new TH1D( "bPtFiltered", "Pt of 2nd b quark filtered", Parameters.getParameter<int32_t>("Nbinx"), Parameters.getParameter<double>("xmin"), Parameters.getParameter<double>("xmax"));
127  Parameters = conf_.getParameter<edm::ParameterSet>("TH1bEtaFiltered");
128  hbEtaFiltered = new TH1D( "bEtaFiltered", "Eta of 2nd b quark filtered", Parameters.getParameter<int32_t>("Nbinx"), Parameters.getParameter<double>("xmin"), Parameters.getParameter<double>("xmax"));
129  }
130 }
131 
133  if(m_produceHistos){
134  hOutputFile->cd();
135  hbPt->Write(); hbEta->Write(); hbPtFiltered->Write(); hbEtaFiltered->Write();
136  hOutputFile->Write() ; hOutputFile->Close() ;} // Write out histograms to file, then close it
137  double fraction = (double) accepted_events / (double) input_events;
138  double percent = 100. * fraction; double error = 100. * sqrt( fraction*(1-fraction) / (double) input_events );
139  std::cout<<"STFilter ++ accepted_events/input_events = "<<accepted_events<<"/"<<input_events<<" = "<<fraction<<std::endl;
140  std::cout<<"STFilter ++ efficiency = "<<percent<<" % +/- "<<error<<" %"<<std::endl;
141 }
142 
143 //DEFINE_FWK_MODULE(STFilter);
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
TPRegexp parents
Definition: eve_filter.cc:21
TH1D * hbEta
Definition: STFilter.h:31
virtual bool filter(edm::Event &, const edm::EventSetup &)
Definition: STFilter.cc:45
edm::ParameterSet conf_
Definition: STFilter.h:36
STFilter(const edm::ParameterSet &)
Definition: STFilter.cc:30
virtual void beginJob()
Definition: STFilter.cc:115
int iEvent
Definition: GenABIO.cc:230
vector< ParameterSet > Parameters
int DEBUGLVL
Definition: STFilter.h:24
virtual void endJob()
Definition: STFilter.cc:132
T sqrt(T t)
Definition: SSEVec.h:48
TH1D * hbPt
Definition: STFilter.h:30
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
TH1D * hbEtaFiltered
Definition: STFilter.h:31
double pTMax_
Definition: STFilter.h:22
unsigned int accepted_events
Definition: STFilter.h:27
unsigned int input_events
Definition: STFilter.h:26
~STFilter()
Definition: STFilter.cc:43
edm::InputTag hepMCProductTag_
Definition: STFilter.h:37
bool m_produceHistos
Definition: STFilter.h:29
tuple cout
Definition: gather_cfg.py:121
TFile * hOutputFile
Definition: STFilter.h:34
TH1D * hbPtFiltered
Definition: STFilter.h:30
std::string fOutputFileName
Definition: STFilter.h:33