CMS 3D CMS Logo

StEvtSolutionMaker.cc
Go to the documentation of this file.
1 //
2 //
3 
4 #include <memory>
5 #include <string>
6 #include <vector>
7 #include <iostream>
8 #include <fstream>
9 
16 
18 public:
19  explicit StEvtSolutionMaker(const edm::ParameterSet&);
20 
21  void produce(edm::Event&, const edm::EventSetup&) override;
22 
23 private:
24  std::unique_ptr<StKinFitter> myKinFitter;
32  // std::string jetInput_;
33  // bool addJetCombProb_,
36  double maxDeltaS_, maxF_;
38  std::vector<int> constraints_;
39 };
40 
42  // configurables
43  leptonFlavour_ = iConfig.getParameter<std::string>("leptonFlavour");
44  if (leptonFlavour_ == "electron") {
45  electronSrcToken_ = consumes<std::vector<pat::Electron>>(iConfig.getParameter<edm::InputTag>("electronSource"));
46  } else if (leptonFlavour_ == "muon") {
47  muonSrcToken_ = consumes<std::vector<pat::Muon>>(iConfig.getParameter<edm::InputTag>("muonSource"));
48  }
49  metSrcToken_ = consumes<std::vector<pat::MET>>(iConfig.getParameter<edm::InputTag>("metSource"));
50  jetSrcToken_ = consumes<std::vector<pat::Jet>>(iConfig.getParameter<edm::InputTag>("jetSource"));
51  genEvtSrcToken_ = mayConsume<StGenEvent>(edm::InputTag("genEvt"));
52  jetCorrScheme_ = iConfig.getParameter<int>("jetCorrectionScheme");
53  //jetInput_ = iConfig.getParameter< std::string > ("jetInput");
54  doKinFit_ = iConfig.getParameter<bool>("doKinFit");
55  addLRJetComb_ = iConfig.getParameter<bool>("addLRJetComb");
56  maxNrIter_ = iConfig.getParameter<int>("maxNrIter");
57  maxDeltaS_ = iConfig.getParameter<double>("maxDeltaS");
58  maxF_ = iConfig.getParameter<double>("maxF");
59  jetParam_ = iConfig.getParameter<int>("jetParametrisation");
60  lepParam_ = iConfig.getParameter<int>("lepParametrisation");
61  metParam_ = iConfig.getParameter<int>("metParametrisation");
62  constraints_ = iConfig.getParameter<std::vector<int>>("constraints");
63  matchToGenEvt_ = iConfig.getParameter<bool>("matchToGenEvt");
64 
65  // define kinfitter
66  if (doKinFit_) {
67  myKinFitter =
68  std::make_unique<StKinFitter>(jetParam_, lepParam_, metParam_, maxNrIter_, maxDeltaS_, maxF_, constraints_);
69  }
70  // define what will be produced
71  produces<std::vector<StEvtSolution>>();
72 }
73 
75  //
76  // TopObject Selection
77  //
78 
79  // select lepton (the TtLepton vectors are, for the moment, sorted on pT)
80  bool leptonFound = false;
82  if (leptonFlavour_ == "muon") {
83  iEvent.getByToken(muonSrcToken_, muons);
84  if (!muons->empty())
85  leptonFound = true;
86  }
88  if (leptonFlavour_ == "electron") {
89  iEvent.getByToken(electronSrcToken_, electrons);
90  if (!electrons->empty())
91  leptonFound = true;
92  }
93 
94  // select MET (TopMET vector is sorted on ET)
95  bool metFound = false;
97  iEvent.getByToken(metSrcToken_, mets);
98  if (!mets->empty())
99  metFound = true;
100 
101  // select Jets
102  bool jetsFound = false;
104  iEvent.getByToken(jetSrcToken_, jets);
105  unsigned int maxJets = 2; //this has to become a custom-defined parameter (we may want 2 or 3 jets)
106  if (jets->size() >= 2)
107  jetsFound = true;
108 
109  auto evtsols = std::make_unique<std::vector<StEvtSolution>>();
110  if (leptonFound && metFound && jetsFound) {
111  std::cout << "constructing solutions" << std::endl;
112  for (unsigned int b = 0; b < maxJets; b++) {
113  for (unsigned int l = 0; l < maxJets; l++) {
114  if (b != l) { // to avoid double counting
115  StEvtSolution asol;
117  if (leptonFlavour_ == "muon")
118  asol.setMuon(muons, 0);
119  if (leptonFlavour_ == "electron")
120  asol.setElectron(electrons, 0);
121  asol.setNeutrino(mets, 0);
122  asol.setBottom(jets, b);
123  asol.setLight(jets, l);
124 
125  if (doKinFit_)
126  asol = myKinFitter->addKinFitInfo(&asol);
127 
128  /* to be adapted to ST (Andrea)
129  if(addLRJetComb_){
130  asol.setPtrueCombExist(jetCombProbs[m].getPTrueCombExist(&afitsol));
131  asol.setPtrueBJetSel(jetCombProbs[m].getPTrueBJetSel(&afitsol));
132  asol.setPtrueBhadrSel(jetCombProbs[m].getPTrueBhadrSel(&afitsol));
133  asol.setPtrueJetComb(afitsol.getPtrueCombExist()*afitsol.getPtrueBJetSel()*afitsol.getPtrueBhadrSel());
134  }
135  */
136  evtsols->push_back(asol);
137  }
138  }
139  }
140 
141  // if asked for, match the event solutions to the gen Event
142  if (matchToGenEvt_) {
143  /*
144  edm::Handle<StGenEvent> genEvt;
145  iEvent.getByToken (genEvtSrcToken_,genEvt);
146  double bestSolDR = 9999.;
147  int bestSol = 0;
148  for(size_t s=0; s<evtsols->size(); s++) {
149  (*evtsols)[s].setGenEvt(genEvt->particles());
150  vector<double> bm = BestMatch((*evtsols)[s], false); //false to use DR, true SpaceAngles
151  (*evtsols)[s].setSumDeltaRjp(bm[0]); // dRBB + dRLL
152  (*evtsols)[s].setChangeBL((int) bm[1]); // has swapped or not
153  (*evtsols)[s].setDeltaRB(bm[2]);
154  (*evtsols)[s].setDeltaRL(bm[3]);
155  if(bm[0]<bestSolDR) { bestSolDR = bm[0]; bestSol = s; }
156  }
157  (*evtsols)[bestSol].setBestSol(true);
158  */
159  }
160 
161  //store the vector of solutions to the event
162  iEvent.put(std::move(evtsols));
163  } else {
164  std::cout << "@@@ No calibrated solutions built, because: " << std::endl;
165  ;
166  if (jets->size() < maxJets)
167  std::cout << "@ nr jets = " << jets->size() << " < " << maxJets << std::endl;
168  if (leptonFlavour_ == "muon" && !leptonFound)
169  std::cout << "@ no good muon candidate" << std::endl;
170  if (leptonFlavour_ == "electron" && !leptonFound)
171  std::cout << "@ no good electron candidate" << std::endl;
172  if (mets->empty())
173  std::cout << "@ no MET reconstruction" << std::endl;
174 
175  StEvtSolution asol;
176  evtsols->push_back(asol);
177  }
178  iEvent.put(std::move(evtsols));
179 }
180 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void setMuon(const edm::Handle< std::vector< pat::Muon > > &muon, int i)
void setLight(const edm::Handle< std::vector< pat::Jet > > &jet, int i)
void setNeutrino(const edm::Handle< std::vector< pat::MET > > &met, int i)
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
edm::EDGetTokenT< std::vector< pat::Jet > > jetSrcToken_
std::vector< int > constraints_
edm::EDGetTokenT< std::vector< pat::Muon > > muonSrcToken_
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< StKinFitter > myKinFitter
void produce(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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:120
void setBottom(const edm::Handle< std::vector< pat::Jet > > &jet, int i)
def move(src, dest)
Definition: eostools.py:511
void setElectron(const edm::Handle< std::vector< pat::Electron > > &elec, int i)