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 
change_name.diff
diff
Definition: change_name.py:13
CaloJetCollection.h
Handle.h
CaloJet.h
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
AlphaTVarProducer::alphaT
static double alphaT(const double, const double, const double)
Definition: AlphaTVarProducer.cc:104
AlphaTVarProducer::inputJetTag_
edm::InputTag inputJetTag_
Definition: AlphaTVarProducer.h:29
min
T min(T a, T b)
Definition: MathUtil.h:58
AlphaTVarProducer::CalcMHT
static double CalcMHT(const std::vector< TLorentzVector > &)
Definition: AlphaTVarProducer.cc:118
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
AlphaTVarProducer::AlphaTVarProducer
AlphaTVarProducer(const edm::ParameterSet &)
Definition: AlphaTVarProducer.cc:26
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle< reco::CaloJetCollection >
CaloMETCollection.h
tmtt::Utility::HT
Definition: Utility.h:28
MakerMacros.h
HT
Definition: HT.h:21
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
AlphaTVarProducer::CalcAlphaT
double CalcAlphaT(const std::vector< TLorentzVector > &)
Definition: AlphaTVarProducer.cc:68
AlphaTVarProducer::~AlphaTVarProducer
~AlphaTVarProducer() override
Definition: AlphaTVarProducer.cc:36
CaloMET.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
nanoDQM_cfi.MHT
MHT
Definition: nanoDQM_cfi.py:738
AlphaTVarProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: AlphaTVarProducer.cc:39
AlphaTVarProducer
Definition: AlphaTVarProducer.h:16
AlphaTVarProducer::inputJetTagToken_
edm::EDGetTokenT< reco::CaloJetCollection > inputJetTagToken_
Definition: AlphaTVarProducer.h:32
iEvent
int iEvent
Definition: GenABIO.cc:224
AlphaTVarProducer::CalcHT
static double CalcHT(const std::vector< TLorentzVector > &)
Definition: AlphaTVarProducer.cc:108
edm::InputTag::encode
std::string encode() const
Definition: InputTag.cc:159
edm::EventSetup
Definition: EventSetup.h:57
InputTag.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
AlphaTVarProducer::deltaHt
static double deltaHt(const std::vector< double > &)
Definition: AlphaTVarProducer.cc:89
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
AlphaTVarProducer.h
edm::InputTag
Definition: InputTag.h:15