CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HLTRHemisphere.cc
Go to the documentation of this file.
4 
7 
9 
12 
13 #include "TVector3.h"
14 #include "TLorentzVector.h"
15 
19 
21 
23 
24 #include <vector>
25 
26 //
27 // constructors and destructor
28 //
30  : inputTag_(iConfig.getParameter<edm::InputTag>("inputTag")),
31  muonTag_(iConfig.getParameter<edm::InputTag>("muonTag")),
32  doMuonCorrection_(iConfig.getParameter<bool>("doMuonCorrection")),
33  muonEta_(iConfig.getParameter<double>("maxMuonEta")),
34  min_Jet_Pt_(iConfig.getParameter<double>("minJetPt")),
35  max_Eta_(iConfig.getParameter<double>("maxEta")),
36  max_NJ_(iConfig.getParameter<int>("maxNJ")),
37  accNJJets_(iConfig.getParameter<bool>("acceptNJ")) {
38  LogDebug("") << "Input/minJetPt/maxEta/maxNJ/acceptNJ : " << inputTag_.encode() << " " << min_Jet_Pt_ << "/"
39  << max_Eta_ << "/" << max_NJ_ << "/" << accNJJets_ << ".";
40 
41  m_theJetToken = consumes<edm::View<reco::Jet>>(inputTag_);
42  m_theMuonToken = consumes<std::vector<reco::RecoChargedCandidate>>(muonTag_);
43  //register your products
44  produces<std::vector<math::XYZTLorentzVector>>();
45 }
46 
48 
51  desc.add<edm::InputTag>("inputTag", edm::InputTag("hltMCJetCorJetIcone5HF07"));
52  desc.add<edm::InputTag>("muonTag", edm::InputTag(""));
53  desc.add<bool>("doMuonCorrection", false);
54  desc.add<double>("maxMuonEta", 2.1);
55  desc.add<double>("minJetPt", 30.0);
56  desc.add<double>("maxEta", 3.0);
57  desc.add<int>("maxNJ", 7);
58  desc.add<bool>("acceptNJ", true);
59  descriptions.add("hltRHemisphere", desc);
60 }
61 
62 //
63 // member functions
64 //
65 
66 // ------------ method called to produce the data ------------
68  using namespace std;
69  using namespace edm;
70  using namespace reco;
71  using namespace math;
72  using namespace trigger;
73 
75 
76  // get hold of collection of objects
77  // Handle<CaloJetCollection> jets;
79  iEvent.getByToken(m_theJetToken, jets);
80 
81  // get hold of the muons, if necessary
85 
86  // The output Collection
87  std::unique_ptr<vector<math::XYZTLorentzVector>> Hemispheres(new vector<math::XYZTLorentzVector>);
88 
89  // look at all objects, check cuts and add to filter object
90  int n(0);
91  vector<math::XYZTLorentzVector> JETS;
92  for (auto const& i : *jets) {
93  if (std::abs(i.eta()) < max_Eta_ && i.pt() >= min_Jet_Pt_) {
94  JETS.push_back(i.p4());
95  n++;
96  }
97  }
98 
99  if (n > max_NJ_ && max_NJ_ != -1) {
100  iEvent.put(std::move(Hemispheres));
101  return accNJJets_; // too many jets, accept for timing
102  }
103 
104  if (doMuonCorrection_) {
105  const int nMu = 2;
106  int muonIndex[nMu] = {-1, -1};
107  std::vector<reco::RecoChargedCandidate>::const_iterator muonIt;
108  int index = 0;
109  int nPassMu = 0;
110  for (muonIt = muons->begin(); muonIt != muons->end(); muonIt++, index++) {
111  if (std::abs(muonIt->eta()) > muonEta_ || muonIt->pt() < min_Jet_Pt_)
112  continue; // skip muons out of eta range or too low pT
113  if (nPassMu >= 2) { // if we have already accepted two muons, accept the event
114  iEvent.put(std::move(Hemispheres)); // too many muons, accept for timing
115  return true;
116  }
117  muonIndex[nPassMu++] = index;
118  }
119  //muons as MET
120  this->ComputeHemispheres(Hemispheres, JETS);
121  //lead muon as jet
122  if (nPassMu > 0) {
123  std::vector<math::XYZTLorentzVector> muonJets;
124  reco::RecoChargedCandidate leadMu = muons->at(muonIndex[0]);
125  muonJets.push_back(leadMu.p4());
126  Hemispheres->push_back(leadMu.p4());
127  this->ComputeHemispheres(Hemispheres, JETS, &muonJets); // lead muon as jet
128  if (nPassMu > 1) { // two passing muons
129  muonJets.pop_back();
130  reco::RecoChargedCandidate secondMu = muons->at(muonIndex[1]);
131  muonJets.push_back(secondMu.p4());
132  Hemispheres->push_back(secondMu.p4());
133  this->ComputeHemispheres(Hemispheres, JETS, &muonJets); // lead muon as v, second muon as jet
134  muonJets.push_back(leadMu.p4());
135  this->ComputeHemispheres(Hemispheres, JETS, &muonJets); // both muon as jets
136  }
137  }
138  } else { // do MuonCorrection==false
139  if (n < 2)
140  return false; // not enough jets and not adding in muons
141  this->ComputeHemispheres(Hemispheres, JETS); // don't do the muon isolation, just run once and done
142  }
143  //Format:
144  // 0 muon: 2 hemispheres (2)
145  // 1 muon: 2 hemisheress + leadMuP4 + 2 hemispheres (5)
146  // 2 muon: 2 hemispheres + leadMuP4 + 2 hemispheres + 2ndMuP4 + 4 Hemispheres (10)
147  iEvent.put(std::move(Hemispheres));
148  return true;
149 }
150 
151 void HLTRHemisphere::ComputeHemispheres(std::unique_ptr<std::vector<math::XYZTLorentzVector>>& hlist,
152  const std::vector<math::XYZTLorentzVector>& JETS,
153  std::vector<math::XYZTLorentzVector>* extraJets) {
154  using namespace math;
155  using namespace reco;
156  XYZTLorentzVector j1R(0.1, 0., 0., 0.1);
157  XYZTLorentzVector j2R(0.1, 0., 0., 0.1);
158  int nJets = JETS.size();
159  if (extraJets)
160  nJets += extraJets->size();
161 
162  if (nJets < 2) { // put empty hemispheres if not enough jets
163  hlist->push_back(j1R);
164  hlist->push_back(j2R);
165  return;
166  }
167  unsigned int N_comb = pow(2, nJets); // compute the number of combinations of jets possible
168  //Make the hemispheres
169  double M_minR = 9999999999.0;
170  unsigned int j_count;
171  for (unsigned int i = 0; i < N_comb; i++) {
172  XYZTLorentzVector j_temp1, j_temp2;
173  unsigned int itemp = i;
174  j_count = N_comb / 2;
175  unsigned int count = 0;
176  while (j_count > 0) {
177  if (itemp / j_count == 1) {
178  if (count < JETS.size())
179  j_temp1 += JETS.at(count);
180  else
181  j_temp1 += extraJets->at(count - JETS.size());
182  } else {
183  if (count < JETS.size())
184  j_temp2 += JETS.at(count);
185  else
186  j_temp2 += extraJets->at(count - JETS.size());
187  }
188  itemp -= j_count * (itemp / j_count);
189  j_count /= 2;
190  count++;
191  }
192  double M_temp = j_temp1.M2() + j_temp2.M2();
193  if (M_temp < M_minR) {
194  M_minR = M_temp;
195  j1R = j_temp1;
196  j2R = j_temp2;
197  }
198  }
199 
200  hlist->push_back(j1R);
201  hlist->push_back(j2R);
202  return;
203 }
204 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLTRHemisphere(const edm::ParameterSet &)
edm::EDGetTokenT< std::vector< reco::RecoChargedCandidate > > m_theMuonToken
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
edm::EDGetTokenT< edm::View< reco::Jet > > m_theJetToken
std::string encode() const
Definition: InputTag.cc:159
void ComputeHemispheres(std::unique_ptr< std::vector< math::XYZTLorentzVector >> &hlist, const std::vector< math::XYZTLorentzVector > &JETS, std::vector< math::XYZTLorentzVector > *extraJets=nullptr)
int iEvent
Definition: GenABIO.cc:224
vector< PseudoJet > jets
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::InputTag muonTag_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool filter(edm::Event &, const edm::EventSetup &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
tuple muons
Definition: patZpeak.py:39
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
edm::InputTag inputTag_
math::PtEtaPhiELorentzVectorF LorentzVector
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:25
~HLTRHemisphere() override
#define LogDebug(id)