CMS 3D CMS Logo

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