CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TtFullHadKinFitProducer.cc
Go to the documentation of this file.
4 
7 
8 /*
9  \class TtFullHadKinFitProducer TtFullHadKinFitProducer.h "TopQuarkAnalysis/TopKinFitter/plugins/TtFullHadKinFitProducer.h"
10 
11  \brief Retrieve kinFit result from TtFullHadKinFitter and put it into the event
12 
13  Get jet collection and if wanted match from the event content and do the kinematic fit
14  of the event with this objects using the kinFit class from TtFullHadKinFitter and put
15  the result into the event content
16 
17 **/
18 
20 public:
23 
24 private:
26  void produce(edm::Event& event, const edm::EventSetup& setup) override;
27 
28 private:
45  unsigned int bTags_;
49  int maxNJets_;
51  int maxNComb_;
53  unsigned int maxNrIter_;
55  double maxDeltaS_;
57  double maxF_;
59  unsigned int jetParam_;
61  std::vector<unsigned> constraints_;
63  double mW_;
65  double mTop_;
67  std::vector<edm::ParameterSet> udscResolutions_, bResolutions_;
69  std::vector<double> jetEnergyResolutionScaleFactors_;
70  std::vector<double> jetEnergyResolutionEtaBinning_;
71 
72 public:
74  std::unique_ptr<TtFullHadKinFitter::KinFit> kinFitter;
75 };
76 
77 static const unsigned int nPartons = 6;
78 
81  : jetsToken_(consumes<std::vector<pat::Jet> >(cfg.getParameter<edm::InputTag>("jets"))),
82  matchToken_(mayConsume<std::vector<std::vector<int> > >(cfg.getParameter<edm::InputTag>("match"))),
83  useOnlyMatch_(cfg.getParameter<bool>("useOnlyMatch")),
84  bTagAlgo_(cfg.getParameter<std::string>("bTagAlgo")),
85  minBTagValueBJet_(cfg.getParameter<double>("minBTagValueBJet")),
86  maxBTagValueNonBJet_(cfg.getParameter<double>("maxBTagValueNonBJet")),
87  useBTagging_(cfg.getParameter<bool>("useBTagging")),
88  bTags_(cfg.getParameter<unsigned int>("bTags")),
89  jetCorrectionLevel_(cfg.getParameter<std::string>("jetCorrectionLevel")),
90  maxNJets_(cfg.getParameter<int>("maxNJets")),
91  maxNComb_(cfg.getParameter<int>("maxNComb")),
92  maxNrIter_(cfg.getParameter<unsigned int>("maxNrIter")),
93  maxDeltaS_(cfg.getParameter<double>("maxDeltaS")),
94  maxF_(cfg.getParameter<double>("maxF")),
95  jetParam_(cfg.getParameter<unsigned>("jetParametrisation")),
96  constraints_(cfg.getParameter<std::vector<unsigned> >("constraints")),
97  mW_(cfg.getParameter<double>("mW")),
98  mTop_(cfg.getParameter<double>("mTop")),
99  jetEnergyResolutionScaleFactors_(cfg.getParameter<std::vector<double> >("jetEnergyResolutionScaleFactors")),
100  jetEnergyResolutionEtaBinning_(cfg.getParameter<std::vector<double> >("jetEnergyResolutionEtaBinning")) {
101  if (cfg.exists("udscResolutions") && cfg.exists("bResolutions")) {
102  udscResolutions_ = cfg.getParameter<std::vector<edm::ParameterSet> >("udscResolutions");
103  bResolutions_ = cfg.getParameter<std::vector<edm::ParameterSet> >("bResolutions");
104  } else if (cfg.exists("udscResolutions") || cfg.exists("bResolutions")) {
105  if (cfg.exists("udscResolutions"))
106  throw cms::Exception("Configuration")
107  << "Parameter 'bResolutions' is needed if parameter 'udscResolutions' is defined!\n";
108  else
109  throw cms::Exception("Configuration")
110  << "Parameter 'udscResolutions' is needed if parameter 'bResolutions' is defined!\n";
111  }
112 
113  // define kinematic fit interface
114  kinFitter = std::make_unique<TtFullHadKinFitter::KinFit>(useBTagging_,
115  bTags_,
116  bTagAlgo_,
124  maxNJets_,
125  maxNComb_,
126  maxNrIter_,
127  maxDeltaS_,
128  maxF_,
129  jetParam_,
130  constraints_,
131  mW_,
132  mTop_);
133 
134  // produces the following collections
135  produces<std::vector<pat::Particle> >("PartonsB");
136  produces<std::vector<pat::Particle> >("PartonsBBar");
137  produces<std::vector<pat::Particle> >("PartonsLightQ");
138  produces<std::vector<pat::Particle> >("PartonsLightQBar");
139  produces<std::vector<pat::Particle> >("PartonsLightP");
140  produces<std::vector<pat::Particle> >("PartonsLightPBar");
141 
142  produces<std::vector<std::vector<int> > >();
143  produces<std::vector<double> >("Chi2");
144  produces<std::vector<double> >("Prob");
145  produces<std::vector<int> >("Status");
146 }
147 
150  // get jet collection
152  event.getByToken(jetsToken_, jets);
153 
154  // get match in case that useOnlyMatch_ is true
155  std::vector<int> match;
156  bool invalidMatch = false;
157  if (useOnlyMatch_) {
158  kinFitter->setUseOnlyMatch(true);
159  // in case that only a ceratin match should be used, get match here
161  event.getByToken(matchToken_, matches);
162  match = *(matches->begin());
163  // check if match is valid
164  if (match.size() != nPartons) {
165  invalidMatch = true;
166  } else {
167  for (unsigned int idx = 0; idx < match.size(); ++idx) {
168  if (match[idx] < 0 || match[idx] >= (int)jets->size()) {
169  invalidMatch = true;
170  break;
171  }
172  }
173  }
175  kinFitter->setMatch(match);
176  }
177 
179  kinFitter->setMatchInvalidity(invalidMatch);
180 
181  std::list<TtFullHadKinFitter::KinFitResult> fitResults = kinFitter->fit(*jets);
182 
183  // pointer for output collections
184  std::unique_ptr<std::vector<pat::Particle> > pPartonsB(new std::vector<pat::Particle>);
185  std::unique_ptr<std::vector<pat::Particle> > pPartonsBBar(new std::vector<pat::Particle>);
186  std::unique_ptr<std::vector<pat::Particle> > pPartonsLightQ(new std::vector<pat::Particle>);
187  std::unique_ptr<std::vector<pat::Particle> > pPartonsLightQBar(new std::vector<pat::Particle>);
188  std::unique_ptr<std::vector<pat::Particle> > pPartonsLightP(new std::vector<pat::Particle>);
189  std::unique_ptr<std::vector<pat::Particle> > pPartonsLightPBar(new std::vector<pat::Particle>);
190  // pointer for meta information
191  std::unique_ptr<std::vector<std::vector<int> > > pCombi(new std::vector<std::vector<int> >);
192  std::unique_ptr<std::vector<double> > pChi2(new std::vector<double>);
193  std::unique_ptr<std::vector<double> > pProb(new std::vector<double>);
194  std::unique_ptr<std::vector<int> > pStatus(new std::vector<int>);
195 
196  unsigned int iComb = 0;
197  for (std::list<TtFullHadKinFitter::KinFitResult>::const_iterator res = fitResults.begin(); res != fitResults.end();
198  ++res) {
199  if (maxNComb_ >= 1 && iComb == (unsigned int)maxNComb_) {
200  break;
201  }
202  ++iComb;
203 
204  pPartonsB->push_back(res->B);
205  pPartonsBBar->push_back(res->BBar);
206  pPartonsLightQ->push_back(res->LightQ);
207  pPartonsLightQBar->push_back(res->LightQBar);
208  pPartonsLightP->push_back(res->LightP);
209  pPartonsLightPBar->push_back(res->LightPBar);
210 
211  pCombi->push_back(res->JetCombi);
212  pChi2->push_back(res->Chi2);
213  pProb->push_back(res->Prob);
214  pStatus->push_back(res->Status);
215  }
216 
217  event.put(std::move(pCombi));
218  event.put(std::move(pPartonsB), "PartonsB");
219  event.put(std::move(pPartonsBBar), "PartonsBBar");
220  event.put(std::move(pPartonsLightQ), "PartonsLightQ");
221  event.put(std::move(pPartonsLightQBar), "PartonsLightQBar");
222  event.put(std::move(pPartonsLightP), "PartonsLightP");
223  event.put(std::move(pPartonsLightPBar), "PartonsLightPBar");
224  event.put(std::move(pChi2), "Chi2");
225  event.put(std::move(pProb), "Prob");
226  event.put(std::move(pStatus), "Status");
227 }
228 
static const unsigned int nPartons
tuple cfg
Definition: looper.py:296
edm::EDGetTokenT< std::vector< std::vector< int > > > matchToken_
input tag for matches (in case the fit should be performed on certain matches)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &event, const edm::EventSetup &setup) override
produce fitted object collections and meta data describing fit quality
bool exists(std::string const &parameterName) const
checks if a parameter exists
unsigned int jetParam_
numbering of different possible jet parametrizations
double mTop_
top mass value used for constraints
std::vector< unsigned > constraints_
numbering of different possible kinematic constraints
double mW_
W mass value used for constraints.
std::vector< edm::ParameterSet > udscResolutions_
store the resolutions for the jets
bool useBTagging_
switch to tell whether to use b-tagging or not
std::unique_ptr< TtFullHadKinFitter::KinFit > kinFitter
kinematic fit interface
std::vector< edm::ParameterSet > bResolutions_
vector< PseudoJet > jets
def move
Definition: eostools.py:511
int maxNComb_
maximal number of combinations to be written to the event
std::string jetCorrectionLevel_
correction level for jets
double maxF_
maximal deviation for contstraints
double maxDeltaS_
maximal chi2 equivalent
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< std::vector< pat::Jet > > jetsToken_
input tag for jets
constexpr char Jet[]
Definition: modules.cc:9
unsigned int maxNrIter_
maximal number of iterations to be performed for the fit
std::string bTagAlgo_
input tag for b-tagging algorithm
std::vector< double > jetEnergyResolutionScaleFactors_
scale factors for jet energy resolution
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
int maxNJets_
maximal number of jets (-1 possible to indicate &#39;all&#39;)
double maxBTagValueNonBJet_
max value of bTag for a non-b-jet
unsigned int bTags_
minimal number of b-jets
std::vector< double > jetEnergyResolutionEtaBinning_
double minBTagValueBJet_
min value of bTag for a b-jet
TtFullHadKinFitProducer(const edm::ParameterSet &cfg)
default constructor