CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetCombinatorics.cc
Go to the documentation of this file.
1 
14 #include "TMath.h"
15 
16 #include <iostream>
17 
18 std::string itoa(int i) {
19  char temp[20];
20  sprintf(temp,"%d",i);
21  return((std::string)temp);
22 }
23 
24 
25 
26 //_______________________________________________________________
28 
29  this->Clear();
30 
31  minMassLepW_ = -999999.;
32  maxMassLepW_ = 999999.;
33  minMassHadW_ = -999999.;
34  maxMassHadW_ = 999999.;
35  minMassLepTop_ = -999999.;
36  maxMassLepTop_ = 999999.;
37 
38  minPhi_ = -1.;
39  removeDuplicates_ = true;
40  maxNJets_ = 9999;
41  verbosef = false;
42  UsebTagging_ = false;
43  UseMtop_ = true;
44  SigmasTypef = 0;
45  UseFlv_ = false;
46 
47  Template4jCombos_ = NestedCombinatorics(); // 12 combinations
48  Template5jCombos_ = Combinatorics(4,5); // 5 combinations of 4 combos
49  Template6jCombos_ = Combinatorics(4,6); // 15 combinations of 4 combos
50  Template7jCombos_ = Combinatorics(4,7); // xx combinations of 4 combos
51 
52 }
53 
54 //_______________________________________________________________
56  this->Clear();
57 }
58 
59 //_______________________________________________________________
61 
62  allCombos_.clear();
63  allCombosSumEt_.clear();
64  Template4jCombos_.clear();
65  Template5jCombos_.clear();
66  Template6jCombos_.clear();
67  Template7jCombos_.clear();
68  cand1_.clear();
69 
70 }
71 
72 
73 //_______________________________________________________________
74 std::map< int, std::string > JetCombinatorics::Combinatorics(int n, int max) {
75 
76  // find a combinatorics template
77  // This is a simple stupid function to make algebratic combinatorics
78 
79  int kcombos = n;
80  int maxcombos = max;
81 
82  std::string list;
83 
84  for ( int m=0; m<maxcombos; m++) { list = list + (itoa(m));}
85 
86  std::string seed;
87  for ( int m=0; m<kcombos; m++) { seed = seed + (itoa(m));}
88 
89 
90  std::map< int, std::string > aTemplateCombos;
91  aTemplateCombos.clear();
92 
93  aTemplateCombos[0] = seed;
94 
95  int i = 0;
96  int totalmatches = seed.size();
97  int totalIte = list.size();
98 
99  for ( int ite = 0; ite < ((int)totalIte); ite++) {
100 
101  //cout << "iteration " << ite << endl;
102  //i = 0;
103  //for ( Itevec = seed.begin(); Itevec != seed.end(); ++Itevec) {
104  for ( i=0; i< (int) totalmatches; i++) {
105 
106  std::string newseed = aTemplateCombos[ite];
107  std::string newseed2;
108  /*
109  cout << "newseed size= " << newseed.size() << " : ";
110  for (std::vector< std::string>::iterator iite = newseed.begin();
111  iite != newseed.end(); ++iite) {
112 
113  cout << *iite << " ";
114  }
115  cout << endl;
116  */
117  for ( int itemp=0; itemp<(int)newseed.size(); itemp++) {
118  if (itemp!=i) newseed2 = newseed2 + (newseed[itemp]);
119  }
120  /*
121  cout << "newseed2: ";
122  for (std::vector< std::string>::iterator iite = newseed2.begin();
123  iite != newseed2.end(); ++iite) {
124 
125  cout << *iite << " ";
126  }
127  cout << endl;
128  */
129  for ( int j=0; j<(int) list.size(); j++) {
130  //cout << " j = " << j << endl;
131  bool Isnewelement = true;
132  std::string newelement = "0";
133  //bool Isnewcombo = true;
134  for (int k=0; k< (int)newseed2.size(); k++) {
135  if ( list[j] == newseed2[k] ) Isnewelement = false;
136  }
137  if (Isnewelement) {
138 
139  newelement = list[j];
140  //cout << "new element: " << newelement << endl;
141 
142  std::string candseed = newseed2;
143  candseed = candseed + newelement;
144 
145  bool IsnewCombo = true;
146  for (int ic=0; ic<(int)aTemplateCombos.size(); ++ic ) {
147 
148  int nmatch = 0;
149  for ( int ij=0; ij<(int)(aTemplateCombos[ic]).size(); ij++) {
150 
151  for (int ik=0; ik<(int)candseed.size(); ik++) {
152  if ( candseed[ik] == aTemplateCombos[ic][ij] ) nmatch++;
153  }
154  }
155  if (nmatch == (int)totalmatches)
156  IsnewCombo = false;
157 
158  }
159  if (IsnewCombo) {
160  //cout << "new combo"<< " before combo size=" << aTemplateCombos.size() << endl;
161  aTemplateCombos[(int)aTemplateCombos.size()] = candseed;
162  //cout << " after size = " << aTemplateCombos.size() << endl;
163  }
164  }
165 
166  }
167  }
168  }//close iterations
169 
170  // debug info
171 
172  //std::cout << " build templates for total combos = " << aTemplateCombos.size() << std::endl;
173  //std::cout << " template combos: " << std::endl;
174  //for (size_t ic=0; ic != aTemplateCombos.size(); ++ic) {
175 
176  //std::cout << aTemplateCombos[ic] << std::endl;
177  //}
178 
179  return aTemplateCombos;
180 
181 
182 
183 }
184 
185 
186 //______________________________________________________________
187 std::map< int, std::string > JetCombinatorics::NestedCombinatorics() {
188 
189  // build by hand 12 combinations for semileptonic top decays
190 
191  std::map< int, std::string > aTemplateCombos;
192  aTemplateCombos.clear();
193 
194  aTemplateCombos[0] = "0123";
195  aTemplateCombos[1] = "0132";
196  aTemplateCombos[2] = "0213";
197  aTemplateCombos[3] = "0231";
198  aTemplateCombos[4] = "0312";
199  aTemplateCombos[5] = "0321";
200  aTemplateCombos[6] = "1203";
201  aTemplateCombos[7] = "1230";
202  aTemplateCombos[8] = "1302";
203  aTemplateCombos[9] = "1320";
204  aTemplateCombos[10] = "2301";
205  aTemplateCombos[11] = "2310";
206 
207  return aTemplateCombos;
208 
209 }
210 
211 //______________________________________________________________
212 void JetCombinatorics::FourJetsCombinations(std::vector<TLorentzVector> jets, std::vector<double> bdiscriminators ) {
213 
214 
215  int n = 0; // total number of combos
216  std::map< Combo, int, minChi2 > allCombos;
217  std::map< Combo, int, maxSumEt > allCombosSumEt;
218 
219  std::map< int, std::string > aTemplateCombos;
220  aTemplateCombos.clear();
221 
222  if ( jets.size() == 4 ) aTemplateCombos[0] = std::string("0123");
223  if ( jets.size() == 5 ) aTemplateCombos = Template5jCombos_;
224  if ( jets.size() == 6 ) aTemplateCombos = Template6jCombos_;
225  if ( jets.size() == 7 ) aTemplateCombos = Template7jCombos_;
226 
227  // force to use only 4 jets
228  if ( maxNJets_ == 4 ) aTemplateCombos[0] = std::string("0123");
229 
230  if (verbosef) std::cout << "[JetCombinatorics] size of vector of jets = " << jets.size() << std::endl;
231 
232  for (size_t ic=0; ic != aTemplateCombos.size(); ++ic) {
233 
234  if (verbosef) std::cout << "[JetCombinatorics] get 4 jets from the list, cluster # " << ic << "/"<< aTemplateCombos.size()-1 << std::endl;
235 
236  // get a template
237  std::string aTemplate = aTemplateCombos[ic];
238 
239  if (verbosef) std::cout << "[JetCombinatorics] template of 4 jets = " << aTemplate << std::endl;
240 
241  // make a list of 4 jets
242  std::vector< TLorentzVector > the4jets;
243  std::vector< int > the4Ids;
244  std::vector< double > thebdisc;
245  std::vector< double > theFlvCorr;
246  //the4jets[0] = jets[0];
247 
248  for (int ij=0; ij<4; ij++) {
249  //std::cout << "ij= " << ij << std::endl;
250  //std::cout << "atoi = " << atoi((aTemplate.substr(0,1)).c_str()) << std::endl;
251  //std::cout << "jets[].Pt = " << jets[ij].Pt() << std::endl;
252  int tmpi = atoi((aTemplate.substr(ij,1)).c_str());
253  //std::cout << "tmpi= " << tmpi << std::endl;
254  the4jets.push_back(jets[tmpi]);
255  the4Ids.push_back(tmpi);
256  if ( UsebTagging_ ) thebdisc.push_back( bdiscriminators[tmpi] );
257  if ( UseFlv_ ) theFlvCorr.push_back( flavorCorrections_[tmpi] );
258  }
259 
260  if (verbosef) std::cout<< "[JetCombinatorics] with these 4 jets, make 12 combinations: " <<std::endl;
261 
262  //std::cout << " the4jets[ij].size = " << the4jets.size() << std::endl;
263 
264  for (size_t itemplate=0; itemplate!= Template4jCombos_.size(); ++itemplate) {
265 
266  std::string a4template = Template4jCombos_[itemplate];
267 
268  if (verbosef) std::cout << "[JetCombinatorics] ==> combination: " << a4template << " is # " << itemplate << "/"<< Template4jCombos_.size()-1 << std::endl;
269 
270  Combo acombo;
271 
272  acombo.SetWp( the4jets[atoi((a4template.substr(0,1)).c_str())] );
273  acombo.SetWq( the4jets[atoi((a4template.substr(1,1)).c_str())] );
274  acombo.SetHadb( the4jets[atoi((a4template.substr(2,1)).c_str())] );
275  acombo.SetLepb( the4jets[atoi((a4template.substr(3,1)).c_str())] );
276  acombo.SetLepW( theLepW_ );
277 
278  acombo.SetIdWp( the4Ids[atoi((a4template.substr(0,1)).c_str())] );
279  acombo.SetIdWq( the4Ids[atoi((a4template.substr(1,1)).c_str())] );
280  acombo.SetIdHadb( the4Ids[atoi((a4template.substr(2,1)).c_str())] );
281  acombo.SetIdLepb( the4Ids[atoi((a4template.substr(3,1)).c_str())] );
282  //std::cout << " acombo setup" << std::endl;
283 
284  if ( UseFlv_ ) {
285  acombo.SetFlvCorrWp( theFlvCorr[atoi((a4template.substr(0,1)).c_str())] );
286  acombo.SetFlvCorrWq( theFlvCorr[atoi((a4template.substr(1,1)).c_str())] );
287  acombo.SetFlvCorrHadb( theFlvCorr[atoi((a4template.substr(2,1)).c_str())] );
288  acombo.SetFlvCorrLepb( theFlvCorr[atoi((a4template.substr(3,1)).c_str())] );
289  acombo.ApplyFlavorCorrections();
290  }
291  if ( UsebTagging_ ) {
292 
293  acombo.Usebtagging();
295  acombo.SetWp_disc( thebdisc[atoi((a4template.substr(0,1)).c_str())] );
296  acombo.SetWq_disc( thebdisc[atoi((a4template.substr(1,1)).c_str())] );
297  acombo.SetHadb_disc( thebdisc[atoi((a4template.substr(2,1)).c_str())] );
298  acombo.SetLepb_disc( thebdisc[atoi((a4template.substr(3,1)).c_str())] );
299 
300  }
301 
302  acombo.UseMtopConstraint(UseMtop_);
303  // choose value of sigmas
304  acombo.SetSigmas(SigmasTypef);
305 
306  acombo.analyze();
307 
308  if (verbosef) {
309 
310  std::cout << "[JetCombinatorics] ==> combination done:" << std::endl;
311  acombo.Print();
312  }
313 
314  // invariant mass cuts
315  TLorentzVector aHadWP4 = acombo.GetHadW();
316  TLorentzVector aLepWP4 = acombo.GetLepW();
317  TLorentzVector aLepTopP4=acombo.GetLepTop();
318 
319  if ( ( aHadWP4.M() > minMassHadW_ && aHadWP4.M() < maxMassHadW_ ) &&
320  ( aLepWP4.M() > minMassLepW_ && aLepWP4.M() < maxMassLepW_ ) &&
321  ( aLepTopP4.M() > minMassLepTop_ && aLepTopP4.M() < maxMassLepTop_) ) {
322 
323  allCombos[acombo] = n;
324  allCombosSumEt[acombo] = n;
325 
326  n++;
327  }
328 
329  }
330  }
331 
332  allCombos_ = allCombos;
333  allCombosSumEt_ = allCombosSumEt;
334 
335 }
336 
338 
339  int j = 0;
340  Combo a;
341  for ( std::map<Combo,int,minChi2>::const_iterator ite=allCombos_.begin();
342  ite!=allCombos_.end(); ++ite) {
343 
344  if (j == n) a = ite->first;
345  j++;
346  }
347 
348  return a;
349 
350 
351 }
352 
354 
355  int j = 0;
356  Combo a;
357  for ( std::map<Combo,int,maxSumEt>::const_iterator ite=allCombosSumEt_.begin();
358  ite!=allCombosSumEt_.end(); ++ite) {
359 
360  if (j == n) a = ite->first;
361  j++;
362  }
363 
364  return a;
365 
366 
367 }
int i
Definition: DBlmapReader.cc:9
void SetLepb(TLorentzVector Lepb)
void UseMtopConstraint(bool option=true)
void SetIdHadb(int id)
void SetLepW(TLorentzVector LepW)
void FourJetsCombinations(std::vector< TLorentzVector > jets, std::vector< double > bdiscriminators)
std::vector< double > flavorCorrections_
void SetLepb_disc(double disc)
std::map< int, std::string > Template5jCombos_
std::string itoa(int current)
void SetIdWp(int id)
std::map< int, std::string > Combinatorics(int k, int max=6)
void ApplyFlavorCorrections(bool option=true)
std::map< Combo, int, minChi2 > allCombos_
void SetFlvCorrLepb(double corr)
void SetWp_disc(double disc)
void SetHadb_disc(double disc)
void SetFlvCorrWq(double corr)
void SetWp(TLorentzVector Wp)
std::vector< TLorentzVector > cand1_
std::map< int, std::string > NestedCombinatorics()
const T & max(const T &a, const T &b)
vector< PseudoJet > jets
Combo GetCombination(int n=0)
int j
Definition: DBlmapReader.cc:9
void Print()
void SetIdWq(int id)
void SetIdLepb(int id)
TLorentzVector theLepW_
int k[5][pyjets_maxn]
std::map< Combo, int, maxSumEt > allCombosSumEt_
std::map< int, std::string > Template4jCombos_
void SetFlvCorrWp(double corr)
TLorentzVector GetHadW()
Combo GetCombinationSumEt(int n=0)
void SetWq_disc(double disc)
void SetWq(TLorentzVector Wq)
void SetHadb(TLorentzVector Hadb)
TLorentzVector GetLepW()
void SetFlvCorrHadb(double corr)
TLorentzVector GetLepTop()
void analyze()
double a
Definition: hdecay.h:121
void Usebtagging(bool option=true)
std::map< int, std::string > Template7jCombos_
tuple cout
Definition: gather_cfg.py:121
void SetbDiscPdf(TString filename)
std::map< int, std::string > Template6jCombos_
void SetSigmas(int type=0)
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 list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run