CMS 3D CMS Logo

AlphaTVarProducer.cc
Go to the documentation of this file.
2 
4 
7 
10 
13 
15 
17 
18 #include "TVector3.h"
19 
20 #include <memory>
21 #include <vector>
22 
23 //
24 // constructors and destructor
25 //
27  : inputJetTag_(iConfig.getParameter<edm::InputTag>("inputJetTag")) {
28  produces<std::vector<double>>();
29 
30  // set Token(-s)
31  inputJetTagToken_ = consumes<reco::CaloJetCollection>(iConfig.getParameter<edm::InputTag>("inputJetTag"));
32 
33  LogDebug("") << "Inputs: " << inputJetTag_.encode() << " ";
34 }
35 
37 
38 // ------------ method called to produce the data ------------
40  using namespace std;
41  using namespace edm;
42  using namespace reco;
43 
44  // get hold of collection of objects
46  iEvent.getByToken(inputJetTagToken_, calojet_handle);
47 
48  std::unique_ptr<std::vector<double>> result(new std::vector<double>);
49  // check the the input collections are available
50  if (calojet_handle.isValid()) {
51  std::vector<TLorentzVector> myJets;
52  reco::CaloJetCollection::const_iterator jetIt;
53  for (jetIt = calojet_handle->begin(); jetIt != calojet_handle->end(); jetIt++) {
54  TLorentzVector j;
55  j.SetPtEtaPhiE(jetIt->pt(), jetIt->eta(), jetIt->phi(), jetIt->energy());
56  myJets.push_back(j);
57  }
58 
59  double alphaT = CalcAlphaT(myJets);
60  double HT = CalcHT(myJets);
61 
62  result->push_back(alphaT);
63  result->push_back(HT);
64  }
65  iEvent.put(std::move(result));
66 }
67 
68 double AlphaTVarProducer::CalcAlphaT(const std::vector<TLorentzVector> &jets) {
69  std::vector<double> ETs;
70  TVector3 MHT{CalcMHT(jets), 0.0, 0.0};
71  float HT = CalcHT(jets);
72  // float HT = 0;
73  for (unsigned int i = 0; i < jets.size(); i++) {
74  if (jets[i].Et() > 50. && fabs(jets[i].Eta()) < 2.5)
75  ETs.push_back(jets[i].Et());
76  // HT += jets[i].Et();
77  }
78  if (ETs.size() < 2.)
79  return 0.0;
80  if (ETs.size() > 16.)
81  return 0.0;
82  float DHT = deltaHt(ETs);
83 
84  float AlphaT = alphaT(HT, DHT, MHT.Mag());
85 
86  return AlphaT;
87 }
88 
89 double AlphaTVarProducer::deltaHt(const std::vector<double> &ETs) {
90  if (ETs.size() > 16.)
91  return 9999999;
92  std::vector<double> diff(1 << (ETs.size() - 1), 0.);
93  for (unsigned i = 0; i < diff.size(); i++)
94  for (unsigned j = 0; j < ETs.size(); j++)
95  diff[i] += ETs[j] * (1 - 2 * (int(i >> j) & 1));
96  std::vector<double>::const_iterator it;
97  double min = 9999999;
98  for (it = diff.begin(); it != diff.end(); it++)
99  if (*it < min)
100  min = *it;
101  return min;
102 }
103 
104 double AlphaTVarProducer::alphaT(const double HT, const double DHT, const double MHT) {
105  return 0.5 * (HT - DHT) / sqrt(HT * HT - MHT * MHT);
106 }
107 
108 double AlphaTVarProducer::CalcHT(const std::vector<TLorentzVector> &jets) {
109  double HT = 0;
110  for (unsigned int i = 0; i < jets.size(); i++) {
111  if (jets[i].Et() > 50. && fabs(jets[i].Eta()) < 2.5)
112  HT += jets[i].Et();
113  }
114 
115  return HT;
116 }
117 
118 double AlphaTVarProducer::CalcMHT(const std::vector<TLorentzVector> &jets) {
119  TVector3 MHT;
120  for (unsigned int i = 0; i < jets.size(); i++) {
121  if (jets[i].Et() > 50. && fabs(jets[i].Eta()) < 2.5)
122  MHT -= jets[i].Vect();
123  }
124  MHT.SetZ(0.0);
125  return MHT.Mag();
126 }
127 
#define LogDebug(id)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
static double CalcMHT(const std::vector< TLorentzVector > &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static double alphaT(const double, const double, const double)
edm::InputTag inputJetTag_
double CalcAlphaT(const std::vector< TLorentzVector > &)
std::string encode() const
Definition: InputTag.cc:159
AlphaTVarProducer(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T sqrt(T t)
Definition: SSEVec.h:18
vector< PseudoJet > jets
~AlphaTVarProducer() override
T min(T a, T b)
Definition: MathUtil.h:58
edm::EDGetTokenT< reco::CaloJetCollection > inputJetTagToken_
bool isValid() const
Definition: HandleBase.h:74
void produce(edm::Event &, const edm::EventSetup &) override
static double deltaHt(const std::vector< double > &)
static double CalcHT(const std::vector< TLorentzVector > &)
fixed size matrix
HLT enums.
Definition: HTMonitor.h:44
Definition: HT.h:21
def move(src, dest)
Definition: eostools.py:511