CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HypDilepMaker.cc
Go to the documentation of this file.
3 
4 
6 using namespace reco;
7 using namespace edm;
8 using namespace std;
9 
10 bool testJetForLeptons(const LorentzVector& jetP4, const LorentzVector& lepp4) {
11 
12 
13  bool matched = false;
14  float lepphi = lepp4.Phi();
15  float jetphi = jetP4.Phi();
16 
17  float lepeta = lepp4.Eta();
18  float jeteta = jetP4.Eta();
19 
20  float dphi = lepphi - jetphi;
21  float deta = lepeta - jeteta;
22  if(fabs(dphi) > TMath::Pi() ) dphi = 2*TMath::Pi() - fabs(dphi);
23 
24  double dR = sqrt(dphi*dphi + deta*deta);
25  if (dR < 0.4)
26  matched = true;
27 
28  return !matched;
29 }
30 
31 void HypDilepMaker::SetVars(HWW& hww, const edm::Event& iEvent, const edm::EventSetup& iSetup) {
32 
33  hww.Load_hyp_jets_p4();
34  hww.Load_hyp_type();
35  hww.Load_hyp_p4();
36  hww.Load_hyp_lt_charge();
37  hww.Load_hyp_lt_index();
38  hww.Load_hyp_lt_id();
39  hww.Load_hyp_lt_p4();
40  hww.Load_hyp_ll_charge();
41  hww.Load_hyp_ll_index();
42  hww.Load_hyp_ll_id();
43  hww.Load_hyp_ll_p4();
44 
45  double looseptcut = 10.0;
46  double tightptcut = 20.0;
47  double hypJetMaxEtaCut = 5.0;
48  double hypJetMinPtCut = 30.0;
49 
50  // muon charge
51  vector<int> *mus_charge = new vector<int>;
52  *mus_charge = hww.mus_charge();
53 
54  //muon p4
55  vector<LorentzVector> *mus_p4 = new vector<LorentzVector>;
56  *mus_p4 = hww.mus_p4();
57 
58  //muon type
59  vector<int> *mus_type = new vector<int>;
60  *mus_type = hww.mus_type();
61 
62  //-----------------------------------------------------------
63  // electron variables
64  //-----------------------------------------------------------
65  vector<int> *els_charge = new vector<int>;
66  *els_charge = hww.els_charge();
67 
68  // electron p4
69  vector<LorentzVector> *els_p4 = new vector<LorentzVector>;
70  *els_p4 = hww.els_p4();
71 
72  unsigned int nmus = mus_p4->size();
73  unsigned int nels = els_p4->size();
74 
75 
76  vector<LorentzVector> *jets_p4 = new vector<LorentzVector>;
77  *jets_p4 = hww.pfjets_p4();
78 
79  //------------------------------------------------------------
80  // loop over the muons
81  //------------------------------------------------------------
82  //get the candidates and make hypotheses
83  for(unsigned int mus_index_1 = 0; mus_index_1 < nmus; mus_index_1++) {//first muon loop
84  for(unsigned int mus_index_2 = 0; mus_index_2 < nmus; mus_index_2++) {//second muon loop
85 
86  if(mus_index_1 == mus_index_2) continue;
87  if(mus_index_2 < mus_index_1) continue; //avoid double counting
88 
89  //don't look at standalone muons
90  if(mus_type->at(mus_index_1) == 8) continue;
91  if(mus_type->at(mus_index_2) == 8) continue;
92 
93  float mu_pt1 = mus_p4->at(mus_index_1).Pt();
94  float mu_pt2 = mus_p4->at(mus_index_2).Pt();
95 
96  //if either fail the loose cut, go to the next muon
97  if(mu_pt1 < looseptcut || mu_pt2 < looseptcut) continue;
98 
99  //if neither one passes the tight cut, go to the next muon
100  if(mu_pt1 < tightptcut && mu_pt2 < tightptcut) continue;
101 
102  int tight_index = mus_index_1;
103  int loose_index = mus_index_2;
104 
105  /*
106  figure out which one should be tight and which should
107  be loose in case one passes the tight cut and the other
108  does not
109  */
110  if(mu_pt1 < tightptcut && mu_pt2 > tightptcut) {
111  tight_index = mus_index_2;
112  loose_index = mus_index_1;
113  }
114  if(mu_pt2 < tightptcut && mu_pt1 > tightptcut) {
115  tight_index = mus_index_1;
116  loose_index = mus_index_2;
117  }
118 
119 
120  //fill the Jet vars
121  vector<int> temp_jets_idx;
122  vector<LorentzVector> temp_jets_p4;
123 
124 
125  for(unsigned int i = 0; i<jets_p4->size(); i++) {
126 
127  // we don't want jets that overlap with electrons
128  bool overlapsWithLepton = false;
129  if(!testJetForLeptons(jets_p4->at(i), mus_p4->at(loose_index)))
130  overlapsWithLepton = true;
131  if(!testJetForLeptons(jets_p4->at(i), mus_p4->at(tight_index)))
132  overlapsWithLepton = true;
133 
134  double jet_eta = jets_p4->at(i).eta();
135  double jet_pt = jets_p4->at(i).Pt();
136 
137  if( fabs(jet_eta) < hypJetMaxEtaCut && jet_pt > hypJetMinPtCut && !overlapsWithLepton) { //hyp jetas
138  temp_jets_idx.push_back(i);
139  temp_jets_p4 .push_back(jets_p4 ->at(i));
140  }
141  }
142 
143  hww.hyp_jets_p4() .push_back(temp_jets_p4 );
144  hww.hyp_type() .push_back(0 );
145  hww.hyp_p4() .push_back(mus_p4->at(tight_index)+mus_p4->at(loose_index));
146  hww.hyp_lt_charge() .push_back(mus_charge ->at(tight_index) );
147  hww.hyp_lt_index() .push_back(tight_index );
148  hww.hyp_lt_id() .push_back(-13*(mus_charge ->at(tight_index)));
149  hww.hyp_lt_p4() .push_back(mus_p4 ->at(tight_index) );
150  hww.hyp_ll_charge() .push_back(mus_charge ->at(loose_index) );
151  hww.hyp_ll_index() .push_back(loose_index );
152  hww.hyp_ll_id() .push_back(-13*(mus_charge ->at(loose_index)));
153  hww.hyp_ll_p4() .push_back(mus_p4 ->at(loose_index) );
154  }
155  }
156 
157  //------------------------------------------------------------
158  // loop over the elecrons
159  //------------------------------------------------------------
160  //get the candidates and make hypotheses
161  for(unsigned int els_index_1 = 0; els_index_1 < nels; els_index_1++) {
162  for(unsigned int els_index_2 = 0; els_index_2 < nels; els_index_2++) {
163 
164  if(els_index_1 == els_index_2) continue;
165  if(els_index_2 < els_index_1) continue; //avoid double counting
166 
167  float el_pt1 = els_p4->at(els_index_1).Pt();
168  float el_pt2 = els_p4->at(els_index_2).Pt();
169 
170  //if either fail the loose cut, go to the next muon
171  if(el_pt1 < looseptcut || el_pt2 < looseptcut) continue;
172 
173  //if neither one passes the tight cut, continue
174  if(el_pt1 < tightptcut && el_pt2 < tightptcut) continue;
175 
176  int tight_index = els_index_1;
177  int loose_index = els_index_2;
178 
179  /*
180  figure out which one should be tight and which should
181  be loose in case one passes the tight cut and the other
182  does not
183  */
184  if(el_pt1 < tightptcut && el_pt2 > tightptcut) {
185  tight_index = els_index_2;
186  loose_index = els_index_1;
187  }
188  if(el_pt2 < tightptcut && el_pt1 > tightptcut) {
189  tight_index = els_index_1;
190  loose_index = els_index_2;
191  }
192 
193 
194  //fill the Jet vars
195  vector<int> temp_jets_idx;
196  vector<LorentzVector> temp_jets_p4;
197 
198 
199  for(unsigned int i = 0; i<jets_p4->size(); i++) {
200 
201  // we don't want jets that overlap with electrons
202  bool overlapsWithLepton = false;
203  if(!testJetForLeptons(jets_p4->at(i), els_p4->at(loose_index)))
204  overlapsWithLepton = true;
205  if(!testJetForLeptons(jets_p4->at(i), els_p4->at(tight_index)))
206  overlapsWithLepton = true;
207 
208  double jet_eta = jets_p4->at(i).eta();
209  double jet_pt = jets_p4->at(i).Pt();
210 
211  if( fabs(jet_eta) < hypJetMaxEtaCut && jet_pt > hypJetMinPtCut && !overlapsWithLepton) { //hyp jetas
212  temp_jets_idx.push_back(i);
213  temp_jets_p4 .push_back(jets_p4 ->at(i));
214  }
215  }
216 
217  hww.hyp_jets_p4() .push_back(temp_jets_p4 );
218  hww.hyp_type() .push_back(3);
219  hww.hyp_p4() .push_back(els_p4->at(tight_index)+els_p4->at(loose_index));
220  hww.hyp_lt_charge() .push_back(els_charge ->at(tight_index) );
221  hww.hyp_lt_index() .push_back(tight_index );
222  hww.hyp_lt_id() .push_back(-11*(els_charge ->at(tight_index)));
223  hww.hyp_lt_p4() .push_back(els_p4 ->at(tight_index) );
224  hww.hyp_ll_charge() .push_back(els_charge ->at(loose_index) );
225  hww.hyp_ll_index() .push_back(loose_index );
226  hww.hyp_ll_id() .push_back(-11*(els_charge ->at(loose_index)));
227  hww.hyp_ll_p4() .push_back(els_p4 ->at(loose_index) );
228  }
229  }
230 
231  /*------------------------------------------------------------
232  The EMu, MuE cases
233  To avoid double counting, only make MuE if Mu is tight and E is loose
234  */
235 
236  for(unsigned int els_index = 0; els_index < nels; els_index++) {
237  for(unsigned int mus_index = 0; mus_index < nmus; mus_index++) {
238 
239  if(mus_type->at(mus_index) == 8) continue;
240 
241  float el_pt = els_p4->at(els_index).Pt();
242  float mu_pt = mus_p4->at(mus_index).Pt();
243 
244  //if either fail the loose cut, go to the next muon
245  if(el_pt < looseptcut || mu_pt < looseptcut) continue;
246 
247  //if both fail the tight cut, continue
248  if(el_pt < tightptcut && mu_pt < tightptcut) continue;
249 
250  //fill the Jet vars
251  vector<int> temp_jets_idx;
252  vector<LorentzVector> temp_jets_p4;
253 
254 
255  for(unsigned int i = 0; i<jets_p4->size(); i++) {
256 
257  // we don't want jets that overlap with electrons
258  bool overlapsWithLepton = false;
259  if(!testJetForLeptons(jets_p4->at(i), els_p4->at(els_index)))
260  overlapsWithLepton = true;
261  if(!testJetForLeptons(jets_p4->at(i), mus_p4->at(mus_index)))
262  overlapsWithLepton = true;
263 
264  double jet_eta = jets_p4->at(i).eta();
265  double jet_pt = jets_p4->at(i).Pt();
266 
267  if( fabs(jet_eta) < hypJetMaxEtaCut && jet_pt > hypJetMinPtCut && !overlapsWithLepton) { //hyp jetas
268  temp_jets_idx.push_back(i);
269  temp_jets_p4 .push_back(jets_p4 ->at(i));
270  }
271  }
272 
273  hww.hyp_jets_p4() .push_back(temp_jets_p4 );
274  hww.hyp_p4() .push_back(mus_p4->at(mus_index)+els_p4->at(els_index) );
275 
276  if(el_pt < tightptcut && mu_pt > tightptcut) {
277  hww.hyp_type() .push_back(1);
278  hww.hyp_lt_charge() .push_back(mus_charge ->at(mus_index) );
279  hww.hyp_lt_index() .push_back(mus_index );
280  hww.hyp_lt_id() .push_back(-13*(mus_charge ->at(mus_index)));
281  hww.hyp_lt_p4() .push_back(mus_p4 ->at(mus_index) );
282  hww.hyp_ll_charge() .push_back(els_charge ->at(els_index) );
283  hww.hyp_ll_index() .push_back(els_index );
284  hww.hyp_ll_id() .push_back(-11*(els_charge ->at(els_index)));
285  hww.hyp_ll_p4() .push_back(els_p4 ->at(els_index) );
286 
287 
288  } else {
289  hww.hyp_type() .push_back(2);
290  hww.hyp_lt_charge() .push_back(els_charge ->at(els_index) );
291  hww.hyp_lt_index() .push_back(els_index );
292  hww.hyp_lt_id() .push_back(-11*(els_charge ->at(els_index)));
293  hww.hyp_lt_p4() .push_back(els_p4 ->at(els_index) );
294  hww.hyp_ll_charge() .push_back(mus_charge ->at(mus_index) );
295  hww.hyp_ll_index() .push_back(mus_index );
296  hww.hyp_ll_id() .push_back(-13*(mus_charge ->at(mus_index)));
297  hww.hyp_ll_p4() .push_back(mus_p4 ->at(mus_index) );
298 
299  }
300  }
301  }
302 }
303 
void Load_hyp_type()
Definition: HWW.cc:1241
const double Pi
void Load_hyp_lt_id()
Definition: HWW.cc:1232
int i
Definition: DBlmapReader.cc:9
std::vector< int > & hyp_ll_id()
Definition: HWW.cc:585
void Load_hyp_lt_index()
Definition: HWW.cc:1226
void Load_hyp_ll_p4()
Definition: HWW.cc:1217
void Load_hyp_p4()
Definition: HWW.cc:1214
void Load_hyp_lt_p4()
Definition: HWW.cc:1220
std::vector< int > & hyp_lt_index()
Definition: HWW.cc:581
std::vector< LorentzVector > & mus_p4()
Definition: HWW.cc:367
std::vector< int > & hyp_lt_charge()
Definition: HWW.cc:597
void Load_hyp_jets_p4()
Definition: HWW.cc:1211
std::vector< LorentzVector > & hyp_ll_p4()
Definition: HWW.cc:569
int iEvent
Definition: GenABIO.cc:230
T sqrt(T t)
Definition: SSEVec.h:48
void Load_hyp_ll_id()
Definition: HWW.cc:1229
std::vector< int > & mus_charge()
Definition: HWW.cc:527
std::vector< std::vector< LorentzVector > > & hyp_jets_p4()
Definition: HWW.cc:561
void SetVars(HWW &, const edm::Event &, const edm::EventSetup &)
std::vector< int > & hyp_type()
Definition: HWW.cc:601
void Load_hyp_lt_charge()
Definition: HWW.cc:1238
void Load_hyp_ll_charge()
Definition: HWW.cc:1235
std::vector< LorentzVector > & els_p4()
Definition: HWW.cc:101
Definition: HWW.h:12
bool testJetForLeptons(const LorentzVector &jetP4, const LorentzVector &lepp4)
std::vector< int > & els_charge()
Definition: HWW.cc:329
void Load_hyp_ll_index()
Definition: HWW.cc:1223
std::vector< LorentzVector > & hyp_p4()
Definition: HWW.cc:565
std::vector< int > & hyp_lt_id()
Definition: HWW.cc:589
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > LorentzVector
Definition: analysisEnums.h:9
std::vector< LorentzVector > & hyp_lt_p4()
Definition: HWW.cc:573
std::vector< int > & hyp_ll_charge()
Definition: HWW.cc:593
std::vector< LorentzVector > & pfjets_p4()
Definition: HWW.cc:769
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > XYZTLorentzVectorF
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:22
math::PtEtaPhiELorentzVectorF LorentzVector
list at
Definition: asciidump.py:428
std::vector< int > & mus_type()
Definition: HWW.cc:555
std::vector< int > & hyp_ll_index()
Definition: HWW.cc:577