CMS 3D CMS Logo

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 {
39  LogDebug("") << "Input/minJetPt/maxEta/maxNJ/acceptNJ : "
40  << inputTag_.encode() << " "
41  << min_Jet_Pt_ << "/"
42  << max_Eta_ << "/"
43  << max_NJ_ << "/"
44  << accNJJets_ << ".";
45 
46  m_theJetToken = consumes<edm::View<reco::Jet>>(inputTag_);
47  m_theMuonToken = consumes<std::vector<reco::RecoChargedCandidate>>(muonTag_);
48  //register your products
49  produces<std::vector<math::XYZTLorentzVector> >();
50 }
51 
53 
54 void
57  desc.add<edm::InputTag>("inputTag",edm::InputTag("hltMCJetCorJetIcone5HF07"));
58  desc.add<edm::InputTag>("muonTag",edm::InputTag(""));
59  desc.add<bool>("doMuonCorrection",false);
60  desc.add<double>("maxMuonEta",2.1);
61  desc.add<double>("minJetPt",30.0);
62  desc.add<double>("maxEta",3.0);
63  desc.add<int>("maxNJ",7);
64  desc.add<bool>("acceptNJ",true);
65  descriptions.add("hltRHemisphere",desc);
66 }
67 
68 //
69 // member functions
70 //
71 
72 // ------------ method called to produce the data ------------
73 bool
75 {
76  using namespace std;
77  using namespace edm;
78  using namespace reco;
79  using namespace math;
80  using namespace trigger;
81 
83 
84  // get hold of collection of objects
85  // Handle<CaloJetCollection> jets;
87  iEvent.getByToken (m_theJetToken,jets);
88 
89  // get hold of the muons, if necessary
91  if(doMuonCorrection_) iEvent.getByToken( m_theMuonToken,muons );
92 
93  // The output Collection
94  std::unique_ptr<vector<math::XYZTLorentzVector> > Hemispheres(new vector<math::XYZTLorentzVector> );
95 
96  // look at all objects, check cuts and add to filter object
97  int n(0);
98  vector<math::XYZTLorentzVector> JETS;
99  for (auto const & i : *jets) {
100  if(std::abs(i.eta()) < max_Eta_ && i.pt() >= min_Jet_Pt_){
101  JETS.push_back(i.p4());
102  n++;
103  }
104  }
105 
106  if(n>max_NJ_ && max_NJ_!=-1){
107  iEvent.put(std::move(Hemispheres));
108  return accNJJets_; // too many jets, accept for timing
109  }
110 
111  if(doMuonCorrection_){
112  const int nMu = 2;
113  int muonIndex[nMu] = { -1, -1 };
114  std::vector<reco::RecoChargedCandidate>::const_iterator muonIt;
115  int index = 0;
116  int nPassMu = 0;
117  for(muonIt = muons->begin(); muonIt!=muons->end(); muonIt++,index++){
118  if(std::abs(muonIt->eta()) > muonEta_ || muonIt->pt() < min_Jet_Pt_) continue; // skip muons out of eta range or too low pT
119  if(nPassMu >= 2){ // if we have already accepted two muons, accept the event
120  iEvent.put(std::move(Hemispheres)); // too many muons, accept for timing
121  return true;
122  }
123  muonIndex[nPassMu++] = index;
124  }
125  //muons as MET
126  this->ComputeHemispheres(Hemispheres,JETS);
127  //lead muon as jet
128  if(nPassMu>0){
129  std::vector<math::XYZTLorentzVector> muonJets;
130  reco::RecoChargedCandidate leadMu = muons->at(muonIndex[0]);
131  muonJets.push_back(leadMu.p4());
132  Hemispheres->push_back(leadMu.p4());
133  this->ComputeHemispheres(Hemispheres,JETS,&muonJets); // lead muon as jet
134  if(nPassMu>1){ // two passing muons
135  muonJets.pop_back();
136  reco::RecoChargedCandidate secondMu = muons->at(muonIndex[1]);
137  muonJets.push_back(secondMu.p4());
138  Hemispheres->push_back(secondMu.p4());
139  this->ComputeHemispheres(Hemispheres,JETS,&muonJets); // lead muon as v, second muon as jet
140  muonJets.push_back(leadMu.p4());
141  this->ComputeHemispheres(Hemispheres,JETS,&muonJets); // both muon as jets
142  }
143  }
144  }else{ // do MuonCorrection==false
145  if(n<2) return false; // not enough jets and not adding in muons
146  this->ComputeHemispheres(Hemispheres,JETS); // don't do the muon isolation, just run once and done
147  }
148  //Format:
149  // 0 muon: 2 hemispheres (2)
150  // 1 muon: 2 hemisheress + leadMuP4 + 2 hemispheres (5)
151  // 2 muon: 2 hemispheres + leadMuP4 + 2 hemispheres + 2ndMuP4 + 4 Hemispheres (10)
152  iEvent.put(std::move(Hemispheres));
153  return true;
154 }
155 
156 void
157 HLTRHemisphere::ComputeHemispheres(std::unique_ptr<std::vector<math::XYZTLorentzVector> >& hlist, const std::vector<math::XYZTLorentzVector>& JETS,
158  std::vector<math::XYZTLorentzVector>* extraJets){
159  using namespace math;
160  using namespace reco;
161  XYZTLorentzVector j1R(0.1, 0., 0., 0.1);
162  XYZTLorentzVector j2R(0.1, 0., 0., 0.1);
163  int nJets = JETS.size();
164  if(extraJets) nJets+=extraJets->size();
165 
166  if(nJets<2){ // put empty hemispheres if not enough jets
167  hlist->push_back(j1R);
168  hlist->push_back(j2R);
169  return;
170  }
171  unsigned int N_comb = pow(2,nJets); // compute the number of combinations of jets possible
172  //Make the hemispheres
173  double M_minR = 9999999999.0;
174  unsigned int j_count;
175  for (unsigned int i = 0; i < N_comb; i++) {
176  XYZTLorentzVector j_temp1, j_temp2;
177  unsigned int itemp = i;
178  j_count = N_comb/2;
179  unsigned int count = 0;
180  while (j_count > 0) {
181  if (itemp/j_count == 1){
182  if(count<JETS.size()) j_temp1 += JETS.at(count);
183  else j_temp1 +=extraJets->at(count-JETS.size());
184  } else {
185  if(count<JETS.size()) j_temp2 += JETS.at(count);
186  else 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 
#define LogDebug(id)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
HLTRHemisphere(const edm::ParameterSet &)
edm::EDGetTokenT< std::vector< reco::RecoChargedCandidate > > m_theMuonToken
edm::EDGetTokenT< edm::View< reco::Jet > > m_theJetToken
std::string encode() const
Definition: InputTag.cc:166
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:230
vector< PseudoJet > jets
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
edm::InputTag muonTag_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: Error.h:16
void ComputeHemispheres(std::unique_ptr< std::vector< math::XYZTLorentzVector > > &hlist, const std::vector< math::XYZTLorentzVector > &JETS, std::vector< math::XYZTLorentzVector > *extraJets=0)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool filter(edm::Event &, const edm::EventSetup &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
edm::InputTag inputTag_
def move(src, dest)
Definition: eostools.py:510
math::PtEtaPhiELorentzVectorF LorentzVector
~HLTRHemisphere() override