CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TtHadEvtSolutionMaker.cc
Go to the documentation of this file.
1 // $Id: TtHadEvtSolutionMaker.cc,v 1.21 2010/03/30 14:04:44 snaumann Exp $
2 
14 
15 #include <memory>
16 
17 
20  // configurables
21  jetSrc_ = iConfig.getParameter<edm::InputTag> ("jetSource");
22  jetCorrScheme_ = iConfig.getParameter<int> ("jetCorrectionScheme");
23  doKinFit_ = iConfig.getParameter<bool> ("doKinFit");
24  addLRSignalSel_ = iConfig.getParameter<bool> ("addLRSignalSel");
25  lrSignalSelObs_ = iConfig.getParameter<std::vector<int> >("lrSignalSelObs");
26  lrSignalSelFile_ = iConfig.getParameter<std::string> ("lrSignalSelFile");
27  addLRJetComb_ = iConfig.getParameter<bool> ("addLRJetComb");
28  lrJetCombObs_ = iConfig.getParameter<std::vector<int> >("lrJetCombObs");
29  lrJetCombFile_ = iConfig.getParameter<std::string> ("lrJetCombFile");
30  maxNrIter_ = iConfig.getParameter<int> ("maxNrIter");
31  maxDeltaS_ = iConfig.getParameter<double> ("maxDeltaS");
32  maxF_ = iConfig.getParameter<double> ("maxF");
33  jetParam_ = iConfig.getParameter<int> ("jetParametrisation");
34  constraints_ = iConfig.getParameter<std::vector<unsigned int> >("constraints");
35  matchToGenEvt_ = iConfig.getParameter<bool> ("matchToGenEvt");
36  matchingAlgo_ = iConfig.getParameter<bool> ("matchingAlgorithm");
37  useMaxDist_ = iConfig.getParameter<bool> ("useMaximalDistance");
38  useDeltaR_ = iConfig.getParameter<bool> ("useDeltaR");
39  maxDist_ = iConfig.getParameter<double> ("maximalDistance");
40 
41  // define kinfitter
42  if(doKinFit_){
43  myKinFitter = new TtFullHadKinFitter(jetParam_, maxNrIter_, maxDeltaS_, maxF_, constraints_);
44  }
45 
46 
47  // define jet combinations related calculators
51  if (addLRJetComb_) myLRJetCombCalc = new TtHadLRJetCombCalc(lrJetCombFile_, lrJetCombObs_);
52 
53  // instantiate signal selection calculator
54  if (addLRSignalSel_) myLRSignalSelCalc = new TtHadLRSignalSelCalc(lrSignalSelFile_, lrSignalSelObs_);
55 
56  // define what will be produced
57  produces<std::vector<TtHadEvtSolution> >();
58 
59 }
60 
61 
64 {
65  if (doKinFit_) {
66  delete myKinFitter;
67  }
68  delete mySimpleBestJetComb;
72  if(addLRJetComb_) delete myLRJetCombCalc;
73 }
74 
75 
77  // TopObject Selection
78  // Select Jets
79 
80  bool jetsFound = false;
82  iEvent.getByLabel(jetSrc_, jets);
83 
84  if (jets->size() >= 6) jetsFound = true;
85 
86  // Build Event solutions according to the ambiguity in the jet combination
87  // Note, hardcoded to only run through the 6 most energetic jets - could be changed ....
88 
89  std::vector<TtHadEvtSolution> * evtsols = new std::vector<TtHadEvtSolution>();
90  if(jetsFound){
91  for (unsigned int p=0; p<3; p++) { // loop over light jet p
92  for (unsigned int q=p+1; q<4; q++) { // loop over light jet q
93  for (unsigned int j=q+1; j<5; j++) { // loop over light jet j
94  for (unsigned int k=j+1; k<6; k++) { // loop over light jet k
95  for (unsigned int bh=0; bh!=jets->size(); bh++) { //loop over hadronic b-jet1
96  if(!(bh==p || bh==q || bh==j || bh==k)) {
97  for (unsigned int bbarh=0; bbarh!=jets->size(); bbarh++) { //loop over hadronic b-jet2
98  if (!(bbarh==p || bbarh==q || bbarh==j || bbarh==k) && !(bbarh==bh)) {
99  // Make event solutions for all possible combinations of the 4 light
100  // jets and 2 possible b-jets, not including the option of the b's being swapped.
101  // Hadp,Hadq is one pair, Hadj,Hadk the other
102  std::vector<TtHadEvtSolution> asol;
103  asol.resize(3);
104  //[p][q][b] and [j][k][bbar]
105  asol[0].setJetCorrectionScheme(jetCorrScheme_);
106  asol[0].setHadp(jets, p);
107  asol[0].setHadq(jets, q);
108  asol[0].setHadj(jets, j);
109  asol[0].setHadk(jets, k);
110  asol[0].setHadb(jets, bh);
111  asol[0].setHadbbar(jets, bbarh);
112 
113  //[p][j][b] and [q][k][bbar]
114  asol[1].setJetCorrectionScheme(jetCorrScheme_);
115  asol[1].setHadp(jets, p);
116  asol[1].setHadq(jets, j);
117  asol[1].setHadj(jets, q);
118  asol[1].setHadk(jets, k);
119  asol[1].setHadb(jets, bh);
120  asol[1].setHadbbar(jets, bbarh);
121 
122  //[p][k][b] and [j][q][bbar]
123  asol[2].setJetCorrectionScheme(jetCorrScheme_);
124  asol[2].setHadp(jets, p);
125  asol[2].setHadq(jets, k);
126  asol[2].setHadj(jets, j);
127  asol[2].setHadk(jets, q);
128  asol[2].setHadb(jets, bh);
129  asol[2].setHadbbar(jets, bbarh);
130 
131  if(doKinFit_){
132  for(unsigned int i=0;i!=asol.size();i++){
133  asol[i] = myKinFitter->addKinFitInfo(&(asol[i]));
135  }
136 
137  }else{
138  std::cout<<"Fitting needed to decide on best solution, enable fitting!"<<std::endl;
139  }
140  // these lines calculate the observables to be used in the TtHadSignalSelection LR
141 
142  for(unsigned int i=0;i!=asol.size();i++){
143  (*myLRSignalSelObservables)(asol[i]);
144  }
145  // if asked for, calculate with these observable values the LRvalue and
146  // (depending on the configuration) probability this event is signal
147  if(addLRSignalSel_){
148  for(unsigned int i=0;i!=asol.size();i++){
149  (*myLRSignalSelCalc)(asol[i]);
150  }
151  }
152 
153  // these lines calculate the observables to be used in the TtHadJetCombination LR
154  for(unsigned int i=0;i!=asol.size();i++){
155  (*myLRJetCombObservables)(asol[i]);
156  }
157  // if asked for, calculate with these observable values the LRvalue and
158  // (depending on the configuration) probability a jet combination is correct
159  if(addLRJetComb_){
160  for(unsigned int i=0;i!=asol.size();i++){
161  (*myLRJetCombCalc)(asol[i]);
162  }
163  }
164  //std::cout<<"SignalSelLRval = "<<asol.getLRSignalEvtLRval()<<" JetCombProb = "<<asol.getLRSignalEvtProb()<<std::endl;
165  //std::cout<<"JetCombLRval = "<<asol.getLRJetCombLRval()<<" JetCombProb = "<<asol.getLRJetCombProb()<<std::endl;
166 
167  // fill solution to vector with all possible solutions
168  for(unsigned int i=0;i!=asol.size();i++){
169  evtsols->push_back(asol[i]);
170  }
171  }
172  }
173  }
174  }
175  }
176  }
177  }
178  }
179 
180 
181  // add TtHadSimpleBestJetComb to solutions
182  int simpleBestJetComb = (*mySimpleBestJetComb)(*evtsols);
183 
184  for(size_t s=0; s<evtsols->size(); s++){
185  (*evtsols)[s].setSimpleBestJetComb(simpleBestJetComb);
186  // if asked for, match the event solutions to the gen Event
187  if(matchToGenEvt_){
188  int bestSolution = -999;
189  int bestSolutionChangeW1Q = -999;
190  int bestSolutionChangeW2Q = -999;
192  iEvent.getByLabel ("genEvt",genEvt);
193  std::vector<const reco::Candidate*> quarks;
194  const reco::Candidate & genp = *(genEvt->daughterQuarkOfWPlus());
195  const reco::Candidate & genq = *(genEvt->daughterQuarkBarOfWPlus());
196  const reco::Candidate & genb = *(genEvt->b());
197  const reco::Candidate & genj = *(genEvt->daughterQuarkOfWMinus());
198  const reco::Candidate & genk = *(genEvt->daughterQuarkBarOfWMinus());
199  const reco::Candidate & genbbar = *(genEvt->bBar());
200  quarks.push_back( &genp );
201  quarks.push_back( &genq );
202  quarks.push_back( &genb );
203  quarks.push_back( &genj );
204  quarks.push_back( &genk );
205  quarks.push_back( &genbbar );
206  std::vector<const reco::Candidate*> jets;
207  for(size_t s=0; s<evtsols->size(); s++) {
208  jets.clear();
209  const reco::Candidate & jetp = (*evtsols)[s].getRecHadp();
210  const reco::Candidate & jetq = (*evtsols)[s].getRecHadq();
211  const reco::Candidate & jetbh = (*evtsols)[s].getRecHadb();
212  const reco::Candidate & jetj = (*evtsols)[s].getRecHadj();
213  const reco::Candidate & jetk = (*evtsols)[s].getRecHadk();
214  const reco::Candidate & jetbbar = (*evtsols)[s].getRecHadbbar();
215  jets.push_back( &jetp );
216  jets.push_back( &jetq );
217  jets.push_back( &jetbh );
218  jets.push_back( &jetj );
219  jets.push_back( &jetk );
220  jets.push_back( &jetbbar );
222  (*evtsols)[s].setGenEvt(genEvt);
223  (*evtsols)[s].setMCBestSumAngles(aMatch.getSumDistances());
224  (*evtsols)[s].setMCBestAngleHadp(aMatch.getDistanceForParton(0));
225  (*evtsols)[s].setMCBestAngleHadq(aMatch.getDistanceForParton(1));
226  (*evtsols)[s].setMCBestAngleHadb(aMatch.getDistanceForParton(2));
227  (*evtsols)[s].setMCBestAngleHadb(aMatch.getDistanceForParton(2));
228  (*evtsols)[s].setMCBestAngleHadj(aMatch.getDistanceForParton(3));
229  (*evtsols)[s].setMCBestAngleHadk(aMatch.getDistanceForParton(4));
230  (*evtsols)[s].setMCBestAngleHadbbar(aMatch.getDistanceForParton(5));
231 
232  // Check match - checking if two light quarks are swapped wrt matched gen particle
233  if((aMatch.getMatchForParton(2) == 2 && aMatch.getMatchForParton(5) == 5)
234  || (aMatch.getMatchForParton(2) == 5 && aMatch.getMatchForParton(5) == 2)){ // check b-jets
235 
236  if(aMatch.getMatchForParton(3) == 3 && aMatch.getMatchForParton(4) == 4){ //check light jets
237  bestSolutionChangeW2Q = 0;
238  if(aMatch.getMatchForParton(0) == 0 && aMatch.getMatchForParton(1) == 1) {
239  bestSolution = s;
240  bestSolutionChangeW1Q = 0;
241  }else{
242  if(aMatch.getMatchForParton(0) == 1 && aMatch.getMatchForParton(1) == 0){
243  bestSolution = s;
244  bestSolutionChangeW1Q = 1;
245  }
246  }
247  }else{
248  if(aMatch.getMatchForParton(2) == 3 && aMatch.getMatchForParton(3) == 2){ // or check if swapped
249  bestSolutionChangeW2Q = 1;
250  if(aMatch.getMatchForParton(0) == 1 && aMatch.getMatchForParton(1) == 0){
251  bestSolution = s;
252  bestSolutionChangeW1Q = 1;
253  }else{
254  if(aMatch.getMatchForParton(0) == 0 && aMatch.getMatchForParton(1) == 1) {
255  bestSolution = s;
256  bestSolutionChangeW1Q = 0;
257  }
258  }
259  }
260  if(aMatch.getMatchForParton(2) == 2 && aMatch.getMatchForParton(3) == 3){
261  bestSolutionChangeW2Q = 0;
262  if(aMatch.getMatchForParton(0) == 0 && aMatch.getMatchForParton(1) == 1) {
263  bestSolution = s;
264  bestSolutionChangeW1Q = 0;
265  } else if(aMatch.getMatchForParton(0) == 1 && aMatch.getMatchForParton(1) == 0) {
266  bestSolution = s;
267  bestSolutionChangeW1Q = 1;
268  }
269  }
270  }
271  }
272  for(size_t s=0; s<evtsols->size(); s++) {
273  (*evtsols)[s].setMCBestJetComb(bestSolution);
274  (*evtsols)[s].setMCChangeW1Q(bestSolutionChangeW1Q);
275  (*evtsols)[s].setMCChangeW2Q(bestSolutionChangeW2Q);
276  }
277  }
278  } // end matchEvt
279  }
280  //store the vector of solutions to the event
281 
282  std::auto_ptr<std::vector<TtHadEvtSolution> > pOut(evtsols);
283  iEvent.put(pOut);
284  }else { //end loop jet/MET found
285  std::cout<<"No calibrated solutions built, because only "<<jets->size()<<" were present";
286 
287  std::auto_ptr<std::vector<TtHadEvtSolution> > pOut(evtsols);
288  iEvent.put(pOut);
289  }
290 }
291 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
TtHadLRSignalSelObservables * myLRSignalSelObservables
TtHadSimpleBestJetComb * mySimpleBestJetComb
TtFullHadKinFitter * myKinFitter
std::vector< int > lrJetCombObs_
TtHadEvtSolution addKinFitInfo(TtHadEvtSolution *asol)
add kin fit information to the old event solution (in for legacy reasons)
Steering class for the overall hadronic top likelihood.
TtHadLRJetCombCalc * myLRJetCombCalc
std::vector< unsigned int > constraints_
Class to calculate the jet combination LR value and purity from a root-file with fit functions...
Based on the TtSemiSimpleBestJetComb.by: Jan Heyninck version: TtSemiSimpleBestJetComb.cc,v 1.2 2007/06/09 01:17:40 lowette Exp.
int iEvent
Definition: GenABIO.cc:243
TtHadEvtSolutionMaker(const edm::ParameterSet &iConfig)
constructor
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
vector< PseudoJet > jets
int j
Definition: DBlmapReader.cc:9
TtHadLRJetCombObservables * myLRJetCombObservables
tuple genp
produce generated paricles in acceptance #
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
int k[5][pyjets_maxn]
int getMatchForParton(const unsigned int part, const unsigned int comb=0)
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
void setJetParametrisation(int jp)
TtHadLRSignalSelCalc * myLRSignalSelCalc
tuple cout
Definition: gather_cfg.py:121
double getSumDistances(const unsigned int comb=0)
double getDistanceForParton(const unsigned int part, const unsigned int comb=0)
std::vector< int > lrSignalSelObs_