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 
71  std::string list;
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 }
Combo::SetLepb_disc
void SetLepb_disc(double disc)
Definition: JetCombinatorics.h:58
JetCombinatorics::verbosef
bool verbosef
Definition: JetCombinatorics.h:319
JetCombinatorics::maxMassLepW_
double maxMassLepW_
Definition: JetCombinatorics.h:335
JetCombinatorics::GetCombination
Combo GetCombination(int n=0)
Definition: JetCombinatorics.cc:324
JetCombinatorics::GetCombinationSumEt
Combo GetCombinationSumEt(int n=0)
Definition: JetCombinatorics.cc:336
Combo::GetLepW
TLorentzVector GetLepW()
Definition: JetCombinatorics.h:175
Combo::SetFlvCorrHadb
void SetFlvCorrHadb(double corr)
Definition: JetCombinatorics.h:52
mps_fire.i
i
Definition: mps_fire.py:428
JetCombinatorics::minPhi_
Double_t minPhi_
Definition: JetCombinatorics.h:344
Combo::ApplyFlavorCorrections
void ApplyFlavorCorrections(bool option=true)
Definition: JetCombinatorics.h:49
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
Combo::SetFlvCorrLepb
void SetFlvCorrLepb(double corr)
Definition: JetCombinatorics.h:53
JetCombinatorics::Template4jCombos_
std::map< int, std::string > Template4jCombos_
Definition: JetCombinatorics.h:320
JetCombinatorics::UseFlv_
bool UseFlv_
Definition: JetCombinatorics.h:330
JetCombinatorics::minMassLepTop_
double minMassLepTop_
Definition: JetCombinatorics.h:338
JetCombinatorics::theLepW_
TLorentzVector theLepW_
Definition: JetCombinatorics.h:332
gather_cfg.cout
cout
Definition: gather_cfg.py:144
bJetOperatingPointsParameters_cfi.bdiscriminators
bdiscriminators
Definition: bJetOperatingPointsParameters_cfi.py:34
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
Combo::SetHadb_disc
void SetHadb_disc(double disc)
Definition: JetCombinatorics.h:57
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
JetCombinatorics::minMassLepW_
double minMassLepW_
Definition: JetCombinatorics.h:334
Combo::SetIdLepb
void SetIdLepb(int id)
Definition: JetCombinatorics.h:191
fileCollector.seed
seed
Definition: fileCollector.py:127
JetCombinatorics::Template6jCombos_
std::map< int, std::string > Template6jCombos_
Definition: JetCombinatorics.h:322
JetCombinatorics::Clear
void Clear()
Definition: JetCombinatorics.cc:53
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
JetCombinatorics::~JetCombinatorics
~JetCombinatorics()
Definition: JetCombinatorics.cc:50
Combo::SetIdWp
void SetIdWp(int id)
Definition: JetCombinatorics.h:189
dqmdumpme.k
k
Definition: dqmdumpme.py:60
JetCombinatorics::minMassHadW_
double minMassHadW_
Definition: JetCombinatorics.h:336
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Combo::SetFlvCorrWp
void SetFlvCorrWp(double corr)
Definition: JetCombinatorics.h:50
Combo::SetbDiscPdf
void SetbDiscPdf(const TString &filename)
Definition: JetCombinatorics.h:59
Combo::GetHadW
TLorentzVector GetHadW()
Definition: JetCombinatorics.h:174
Combo::GetLepTop
TLorentzVector GetLepTop()
Definition: JetCombinatorics.h:179
Combo::analyze
void analyze()
Definition: JetCombinatorics.h:94
a
double a
Definition: hdecay.h:119
JetCombinatorics.h
JetCombinatorics::removeDuplicates_
bool removeDuplicates_
Definition: JetCombinatorics.h:347
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Combo
Definition: JetCombinatorics.h:24
Combo::SetLepb
void SetLepb(const TLorentzVector &Lepb)
Definition: JetCombinatorics.h:47
JetCombinatorics::maxMassLepTop_
double maxMassLepTop_
Definition: JetCombinatorics.h:339
createfilelist.int
int
Definition: createfilelist.py:10
itoa
std::string itoa(int i)
Definition: JetCombinatorics.cc:17
Combo::SetWp_disc
void SetWp_disc(double disc)
Definition: JetCombinatorics.h:55
Combo::SetLepW
void SetLepW(const TLorentzVector &LepW)
Definition: JetCombinatorics.h:46
Combo::SetFlvCorrWq
void SetFlvCorrWq(double corr)
Definition: JetCombinatorics.h:51
JetCombinatorics::FourJetsCombinations
void FourJetsCombinations(const std::vector< TLorentzVector > &jets, const std::vector< double > &bdiscriminators)
Definition: JetCombinatorics.cc:194
Combo::SetSigmas
void SetSigmas(int type=0)
Definition: JetCombinatorics.h:64
Combo::SetWq
void SetWq(const TLorentzVector &Wq)
Definition: JetCombinatorics.h:44
JetCombinatorics::allCombosSumEt_
std::map< Combo, int, maxSumEt > allCombosSumEt_
Definition: JetCombinatorics.h:342
JetCombinatorics::cand1_
std::vector< TLorentzVector > cand1_
Definition: JetCombinatorics.h:349
Combo::SetHadb
void SetHadb(const TLorentzVector &Hadb)
Definition: JetCombinatorics.h:45
JetCombinatorics::JetCombinatorics
JetCombinatorics()
Definition: JetCombinatorics.cc:24
JetCombinatorics::SigmasTypef
int SigmasTypef
Definition: JetCombinatorics.h:318
JetCombinatorics::Template7jCombos_
std::map< int, std::string > Template7jCombos_
Definition: JetCombinatorics.h:323
JetCombinatorics::flavorCorrections_
std::vector< double > flavorCorrections_
Definition: JetCombinatorics.h:325
Combo::Print
void Print()
Definition: JetCombinatorics.h:192
JetCombinatorics::maxMassHadW_
double maxMassHadW_
Definition: JetCombinatorics.h:337
Combo::SetIdWq
void SetIdWq(int id)
Definition: JetCombinatorics.h:190
Combo::SetIdHadb
void SetIdHadb(int id)
Definition: JetCombinatorics.h:188
Combo::SetWp
void SetWp(const TLorentzVector &Wp)
Definition: JetCombinatorics.h:43
JetCombinatorics::bTagPdffilename_
TString bTagPdffilename_
Definition: JetCombinatorics.h:329
JetCombinatorics::maxNJets_
int maxNJets_
Definition: JetCombinatorics.h:326
JetCombinatorics::UseMtop_
bool UseMtop_
Definition: JetCombinatorics.h:328
JetCombinatorics::NestedCombinatorics
std::map< int, std::string > NestedCombinatorics()
Definition: JetCombinatorics.cc:171
Combo::UseMtopConstraint
void UseMtopConstraint(bool option=true)
Definition: JetCombinatorics.h:92
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
JetCombinatorics::Combinatorics
std::map< int, std::string > Combinatorics(int k, int max=6)
Definition: JetCombinatorics.cc:64
JetCombinatorics::Template5jCombos_
std::map< int, std::string > Template5jCombos_
Definition: JetCombinatorics.h:321
Combo::Usebtagging
void Usebtagging(bool option=true)
Definition: JetCombinatorics.h:85
JetCombinatorics::UsebTagging_
bool UsebTagging_
Definition: JetCombinatorics.h:327
JetCombinatorics::allCombos_
std::map< Combo, int, minChi2 > allCombos_
Definition: JetCombinatorics.h:341
Combo::SetWq_disc
void SetWq_disc(double disc)
Definition: JetCombinatorics.h:56