CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
XtoFFbarFilter.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 using namespace reco;
5 
7  src_(iConfig.getParameter<edm::InputTag>("src")),
8  idMotherX_(iConfig.getParameter<vector<int> >("idMotherX")),
9  idDaughterF_(iConfig.getParameter<vector<int> >("idDaughterF")),
10  idMotherY_(iConfig.getParameter<vector<int> >("idMotherY")),
11  idDaughterG_(iConfig.getParameter<vector<int> >("idDaughterG")),
12  xTotal_(0), xSumPt_(0.), xSumR_(0.), xSumCtau_(0.), totalEvents_(0),rejectedEvents_(0)
13 {
14  // Note if if not searching for Y --> g-gbar.
15  requireY_ = (idMotherY_.size() > 0 && idDaughterG_.size() > 0);
16 }
17 
18 
20 
21  iEvent.getByLabel(src_, genParticles_);
22 
23  totalEvents_++;
24 
25  unsigned int numX = 0;
26  unsigned int numY = 0;
27  unsigned int numXorY = 0;
28 
29  for (unsigned int j = 0; j < genParticles_->size(); j++) {
31 
32  // Is it X -> f fbar ?
33  bool isXtoFFbar = this->foundXtoFFbar(moth, idMotherX_, idDaughterF_);
34  if (isXtoFFbar) numX++;
35 
36  if (!requireY_) {
37 
38  // Has X been found already ?
39  if (numX >= 1) return true;
40 
41  } else {
42 
43  // Is it Y -> g gbar ?
44  bool isYtoGGbar = this->foundXtoFFbar(moth, idMotherY_, idDaughterG_);
45  if (isYtoGGbar) numY++;
46  if (isXtoFFbar || isYtoGGbar) numXorY++;
47 
48  // Have X and Y been found already ?
49  if (numX >= 1 && numY >= 1 && numXorY >= 2) return true;
50  }
51  }
52 
54  // cout<<"REJECTED "<<totalEvents_<<endl;
55  return false;
56 }
57 
58 
60  const vector<int>& idMother,
61  const vector<int>& idDaughter) {
62  // Check if given particle "moth" is X-->f fbar
63  bool isXtoFFbar = false;
64  int pdgIdMoth = moth->pdgId();
65  double rho = -9.9e9;
66 
67  if (this->found(idMother, pdgIdMoth)) {
68  bool foundF = false;
69  bool foundFbar = false;
70  unsigned int nDau = moth->numberOfDaughters();
71 
72  for (unsigned int i = 0; i < nDau; i++) {
73  GenParticleRef dau = moth->daughterRef(i);
74  int pdgIdDau = dau->pdgId();
75  if (this->found(idDaughter, -pdgIdDau)) foundFbar = true;
76  if (this->found(idDaughter, pdgIdDau)) {foundF = true;
77 
78  // Just for statistics, get transverse decay length.
79  // (To be really accurate, should do it w.r.t. P.V., but couldn't be bothered ...)
80  // This is the normal case
81  rho = dau->vertex().Rho();
82  // Unfortunately, duplicate particles can appear in the event record. Handle this as follows:
83  for (unsigned int j = 0; j < dau->numberOfDaughters(); j++) {
84  GenParticleRef granddau = dau->daughterRef(j);
85  if (granddau->pdgId() == pdgIdDau) rho = granddau->vertex().Rho();
86  }
87  }
88  }
89  if (foundF && foundFbar) isXtoFFbar = true;
90  }
91 
92  if (isXtoFFbar) {
93  // Get statistics
94  xTotal_++;
95  xSumPt_ += moth->pt();
96  xSumR_ += rho;
97  xSumCtau_ += rho*(moth->mass()/(moth->pt()+0.01)); // protection against unlikely case Pt = 0.
98  }
99 
100  return isXtoFFbar;
101 }
102 
104  cout<<endl;
105  cout<<"=== XtoFFbarFilter statistics of selected X->ffbar or Y->ggbar"<<endl;
106  if (xTotal_ > 0) {
107  cout<<"=== mean X & Y Pt = "<<xSumPt_/xTotal_<<" GeV and transverse decay length = "<<xSumR_/xTotal_<<" cm"<<endl;
108  cout<<"=== mean c*tau = "<<xSumCtau_/xTotal_<<" cm"<<endl;
109  } else {
110  cout<<"=== WARNING: NONE FOUND !"<<endl;
111  }
112  cout<<"=== events rejected = "<<rejectedEvents_<<"/"<<totalEvents_<<endl;
113 }
bool found(const std::vector< int > &v, int j)
int i
Definition: DBlmapReader.cc:9
XtoFFbarFilter(const edm::ParameterSet &)
virtual void endJob()
edm::InputTag src_
unsigned int rejectedEvents_
std::vector< int > idMotherX_
int iEvent
Definition: GenABIO.cc:230
std::vector< int > idMotherY_
unsigned int totalEvents_
std::vector< int > idDaughterG_
edm::Handle< reco::GenParticleCollection > genParticles_
int j
Definition: DBlmapReader.cc:9
unsigned int xTotal_
std::vector< int > idDaughterF_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
bool foundXtoFFbar(const reco::GenParticleRef &moth, const std::vector< int > &idMotherX, const std::vector< int > &idDaughterF)
virtual bool filter(edm::Event &iEvent, const edm::EventSetup &iSetup)
tuple cout
Definition: gather_cfg.py:121