CMS 3D CMS Logo

StEvtSolutionMaker.cc
Go to the documentation of this file.
1 //
2 //
3 
4 #include <memory>
5 
7 
9  // configurables
10  electronSrcToken_ = mayConsume<std::vector<pat::Electron> >(iConfig.getParameter<edm::InputTag>("electronSource"));
11  muonSrcToken_ = mayConsume<std::vector<pat::Muon> >(iConfig.getParameter<edm::InputTag>("muonSource"));
12  metSrcToken_ = consumes<std::vector<pat::MET> >(iConfig.getParameter<edm::InputTag>("metSource"));
13  jetSrcToken_ = consumes<std::vector<pat::Jet> >(iConfig.getParameter<edm::InputTag>("jetSource"));
14  genEvtSrcToken_ = mayConsume<StGenEvent>(edm::InputTag("genEvt"));
15  leptonFlavour_ = iConfig.getParameter<std::string>("leptonFlavour");
16  jetCorrScheme_ = iConfig.getParameter<int>("jetCorrectionScheme");
17  //jetInput_ = iConfig.getParameter< std::string > ("jetInput");
18  doKinFit_ = iConfig.getParameter<bool>("doKinFit");
19  addLRJetComb_ = iConfig.getParameter<bool>("addLRJetComb");
20  maxNrIter_ = iConfig.getParameter<int>("maxNrIter");
21  maxDeltaS_ = iConfig.getParameter<double>("maxDeltaS");
22  maxF_ = iConfig.getParameter<double>("maxF");
23  jetParam_ = iConfig.getParameter<int>("jetParametrisation");
24  lepParam_ = iConfig.getParameter<int>("lepParametrisation");
25  metParam_ = iConfig.getParameter<int>("metParametrisation");
26  constraints_ = iConfig.getParameter<std::vector<int> >("constraints");
27  matchToGenEvt_ = iConfig.getParameter<bool>("matchToGenEvt");
28 
29  // define kinfitter
30  if (doKinFit_) {
31  myKinFitter = new StKinFitter(jetParam_, lepParam_, metParam_, maxNrIter_, maxDeltaS_, maxF_, constraints_);
32  }
33  // define what will be produced
34  produces<std::vector<StEvtSolution> >();
35 }
36 
38  if (doKinFit_)
39  delete myKinFitter;
40 }
41 
43  //
44  // TopObject Selection
45  //
46 
47  // select lepton (the TtLepton vectors are, for the moment, sorted on pT)
48  bool leptonFound = false;
50  if (leptonFlavour_ == "muon") {
51  iEvent.getByToken(muonSrcToken_, muons);
52  if (!muons->empty())
53  leptonFound = true;
54  }
56  if (leptonFlavour_ == "electron") {
57  iEvent.getByToken(electronSrcToken_, electrons);
58  if (!electrons->empty())
59  leptonFound = true;
60  }
61 
62  // select MET (TopMET vector is sorted on ET)
63  bool metFound = false;
65  iEvent.getByToken(metSrcToken_, mets);
66  if (!mets->empty())
67  metFound = true;
68 
69  // select Jets
70  bool jetsFound = false;
72  iEvent.getByToken(jetSrcToken_, jets);
73  unsigned int maxJets = 2; //this has to become a custom-defined parameter (we may want 2 or 3 jets)
74  if (jets->size() >= 2)
75  jetsFound = true;
76 
77  std::vector<StEvtSolution>* evtsols = new std::vector<StEvtSolution>();
78  if (leptonFound && metFound && jetsFound) {
79  std::cout << "constructing solutions" << std::endl;
80  for (unsigned int b = 0; b < maxJets; b++) {
81  for (unsigned int l = 0; l < maxJets; l++) {
82  if (b != l) { // to avoid double counting
83  StEvtSolution asol;
85  if (leptonFlavour_ == "muon")
86  asol.setMuon(muons, 0);
87  if (leptonFlavour_ == "electron")
88  asol.setElectron(electrons, 0);
89  asol.setNeutrino(mets, 0);
90  asol.setBottom(jets, b);
91  asol.setLight(jets, l);
92 
93  if (doKinFit_)
94  asol = myKinFitter->addKinFitInfo(&asol);
95 
96  /* to be adapted to ST (Andrea)
97  if(addLRJetComb_){
98  asol.setPtrueCombExist(jetCombProbs[m].getPTrueCombExist(&afitsol));
99  asol.setPtrueBJetSel(jetCombProbs[m].getPTrueBJetSel(&afitsol));
100  asol.setPtrueBhadrSel(jetCombProbs[m].getPTrueBhadrSel(&afitsol));
101  asol.setPtrueJetComb(afitsol.getPtrueCombExist()*afitsol.getPtrueBJetSel()*afitsol.getPtrueBhadrSel());
102  }
103  */
104  evtsols->push_back(asol);
105  }
106  }
107  }
108 
109  // if asked for, match the event solutions to the gen Event
110  if (matchToGenEvt_) {
111  /*
112  edm::Handle<StGenEvent> genEvt;
113  iEvent.getByToken (genEvtSrcToken_,genEvt);
114  double bestSolDR = 9999.;
115  int bestSol = 0;
116  for(size_t s=0; s<evtsols->size(); s++) {
117  (*evtsols)[s].setGenEvt(genEvt->particles());
118  vector<double> bm = BestMatch((*evtsols)[s], false); //false to use DR, true SpaceAngles
119  (*evtsols)[s].setSumDeltaRjp(bm[0]); // dRBB + dRLL
120  (*evtsols)[s].setChangeBL((int) bm[1]); // has swapped or not
121  (*evtsols)[s].setDeltaRB(bm[2]);
122  (*evtsols)[s].setDeltaRL(bm[3]);
123  if(bm[0]<bestSolDR) { bestSolDR = bm[0]; bestSol = s; }
124  }
125  (*evtsols)[bestSol].setBestSol(true);
126  */
127  }
128 
129  //store the vector of solutions to the event
130  std::unique_ptr<std::vector<StEvtSolution> > pOut(evtsols);
131  iEvent.put(std::move(pOut));
132  } else {
133  std::cout << "@@@ No calibrated solutions built, because: " << std::endl;
134  ;
135  if (jets->size() < maxJets)
136  std::cout << "@ nr jets = " << jets->size() << " < " << maxJets << std::endl;
137  if (leptonFlavour_ == "muon" && !leptonFound)
138  std::cout << "@ no good muon candidate" << std::endl;
139  if (leptonFlavour_ == "electron" && !leptonFound)
140  std::cout << "@ no good electron candidate" << std::endl;
141  if (mets->empty())
142  std::cout << "@ no MET reconstruction" << std::endl;
143 
144  StEvtSolution asol;
145  evtsols->push_back(asol);
146  std::unique_ptr<std::vector<StEvtSolution> > pOut(evtsols);
147  iEvent.put(std::move(pOut));
148  }
149 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
void setMuon(const edm::Handle< std::vector< pat::Muon > > &muon, int i)
StKinFitter * myKinFitter
void setLight(const edm::Handle< std::vector< pat::Jet > > &jet, int i)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setNeutrino(const edm::Handle< std::vector< pat::MET > > &met, int i)
std::string leptonFlavour_
edm::EDGetTokenT< std::vector< pat::Jet > > jetSrcToken_
std::vector< int > constraints_
edm::EDGetTokenT< std::vector< pat::Muon > > muonSrcToken_
~StEvtSolutionMaker() override
int iEvent
Definition: GenABIO.cc:224
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< StGenEvent > genEvtSrcToken_
StEvtSolutionMaker(const edm::ParameterSet &)
edm::EDGetTokenT< std::vector< pat::Electron > > electronSrcToken_
edm::EDGetTokenT< std::vector< pat::MET > > metSrcToken_
void setJetCorrectionScheme(int scheme)
double b
Definition: hdecay.h:118
void setBottom(const edm::Handle< std::vector< pat::Jet > > &jet, int i)
StEvtSolution addKinFitInfo(StEvtSolution *asol)
Definition: StKinFitter.cc:69
def move(src, dest)
Definition: eostools.py:511
void setElectron(const edm::Handle< std::vector< pat::Electron > > &elec, int i)