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