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_) {
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 }
StEvtSolutionMaker::lepParam_
int lepParam_
Definition: StEvtSolutionMaker.h:38
StEvtSolutionMaker::metSrcToken_
edm::EDGetTokenT< std::vector< pat::MET > > metSrcToken_
Definition: StEvtSolutionMaker.h:28
StEvtSolutionMaker::genEvtSrcToken_
edm::EDGetTokenT< StGenEvent > genEvtSrcToken_
Definition: StEvtSolutionMaker.h:30
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
StEvtSolutionMaker.h
StEvtSolutionMaker::electronSrcToken_
edm::EDGetTokenT< std::vector< pat::Electron > > electronSrcToken_
Definition: StEvtSolutionMaker.h:26
gather_cfg.cout
cout
Definition: gather_cfg.py:144
StEvtSolution::setJetCorrectionScheme
void setJetCorrectionScheme(int scheme)
Definition: StEvtSolution.h:103
StEvtSolutionMaker::addLRJetComb_
bool addLRJetComb_
Definition: StEvtSolutionMaker.h:35
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
singleTopDQM_cfi.mets
mets
Definition: singleTopDQM_cfi.py:43
StEvtSolutionMaker::leptonFlavour_
std::string leptonFlavour_
Definition: StEvtSolutionMaker.h:31
edm::Handle
Definition: AssociativeIterator.h:50
StEvtSolutionMaker::muonSrcToken_
edm::EDGetTokenT< std::vector< pat::Muon > > muonSrcToken_
Definition: StEvtSolutionMaker.h:27
StEvtSolutionMaker::doKinFit_
bool doKinFit_
Definition: StEvtSolutionMaker.h:35
StEvtSolution::setLight
void setLight(const edm::Handle< std::vector< pat::Jet > > &jet, int i)
Definition: StEvtSolution.h:107
StEvtSolutionMaker::myKinFitter
StKinFitter * myKinFitter
Definition: StEvtSolutionMaker.h:24
StEvtSolutionMaker::jetCorrScheme_
int jetCorrScheme_
Definition: StEvtSolutionMaker.h:32
b
double b
Definition: hdecay.h:118
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:36
StEvtSolution::setMuon
void setMuon(const edm::Handle< std::vector< pat::Muon > > &muon, int i)
Definition: StEvtSolution.h:110
StEvtSolutionMaker::constraints_
std::vector< int > constraints_
Definition: StEvtSolutionMaker.h:39
iEvent
int iEvent
Definition: GenABIO.cc:224
StEvtSolution::setElectron
void setElectron(const edm::Handle< std::vector< pat::Electron > > &elec, int i)
Definition: StEvtSolution.h:114
StEvtSolutionMaker::jetSrcToken_
edm::EDGetTokenT< std::vector< pat::Jet > > jetSrcToken_
Definition: StEvtSolutionMaker.h:29
StEvtSolution::setNeutrino
void setNeutrino(const edm::Handle< std::vector< pat::MET > > &met, int i)
Definition: StEvtSolution.h:118
StEvtSolutionMaker::maxF_
double maxF_
Definition: StEvtSolutionMaker.h:37
edm::EventSetup
Definition: EventSetup.h:57
StKinFitter::addKinFitInfo
StEvtSolution addKinFitInfo(StEvtSolution *asol)
Definition: StKinFitter.cc:69
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
StEvtSolutionMaker::maxDeltaS_
double maxDeltaS_
Definition: StEvtSolutionMaker.h:37
StEvtSolution::setBottom
void setBottom(const edm::Handle< std::vector< pat::Jet > > &jet, int i)
Definition: StEvtSolution.h:104
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
StEvtSolutionMaker::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: StEvtSolutionMaker.cc:42
pwdgSkimBPark_cfi.electrons
electrons
Definition: pwdgSkimBPark_cfi.py:6
StEvtSolutionMaker::maxNrIter_
int maxNrIter_
Definition: StEvtSolutionMaker.h:36
StEvtSolutionMaker::jetParam_
int jetParam_
Definition: StEvtSolutionMaker.h:38
StEvtSolutionMaker::metParam_
int metParam_
Definition: StEvtSolutionMaker.h:38
edm::Event
Definition: Event.h:73
StKinFitter
Definition: StKinFitter.h:19
edm::InputTag
Definition: InputTag.h:15
StEvtSolutionMaker::~StEvtSolutionMaker
~StEvtSolutionMaker() override
Definition: StEvtSolutionMaker.cc:37
StEvtSolutionMaker::matchToGenEvt_
bool matchToGenEvt_
Definition: StEvtSolutionMaker.h:35
StEvtSolutionMaker::StEvtSolutionMaker
StEvtSolutionMaker(const edm::ParameterSet &)
Definition: StEvtSolutionMaker.cc:8
StEvtSolution
Definition: StEvtSolution.h:21