CMS 3D CMS Logo

DiJetVarProducer.cc
Go to the documentation of this file.
2 
4 
7 
10 
12 
14 
15 #include "TLorentzVector.h"
16 #include "TVector3.h"
17 
18 #include <memory>
19 #include <vector>
20 
21 //
22 // constructors and destructor
23 //
25  : inputJetTag_(iConfig.getParameter<edm::InputTag>("inputJetTag")),
26  wideJetDeltaR_(iConfig.getParameter<double>("wideJetDeltaR")) {
27  // register your products
28  // produces<std::vector<double> >("dijetvariables");
29  produces<std::vector<math::PtEtaPhiMLorentzVector>>("widejets");
30 
31  // set Token(-s)
32  inputJetTagToken_ = consumes<reco::CaloJetCollection>(iConfig.getParameter<edm::InputTag>("inputJetTag"));
33 
34  LogDebug("") << "Input Jet Tag: " << inputJetTag_.encode() << " ";
35  LogDebug("") << "Radius Parameter Wide Jet: " << wideJetDeltaR_ << ".";
36 }
37 
38 // ------------ method called to produce the data ------------
40  using namespace std;
41  using namespace edm;
42  using namespace reco;
43 
44  // ## The output collections
45  // std::unique_ptr<std::vector<double> > dijetvariables(new
46  // std::vector<double>);
47  std::unique_ptr<std::vector<math::PtEtaPhiMLorentzVector>> widejets(new std::vector<math::PtEtaPhiMLorentzVector>);
48 
49  // ## Get jet collection
51  iEvent.getByToken(inputJetTagToken_, calojets_handle);
52  // cout << "size: " << calojets_handle->size() << endl;
53 
54  // ## Wide Jet Algorithm
55  // At least two jets
56  if (calojets_handle->size() >= 2) {
57  TLorentzVector wj1_tmp;
58  TLorentzVector wj2_tmp;
59  TLorentzVector wj1;
60  TLorentzVector wj2;
61  TLorentzVector wdijet;
62 
63  // // Loop over all the input jets
64  // for(reco::CaloJetCollection::const_iterator it =
65  // calojets_handle->begin(); it != calojets_handle->end(); ++it)
66  // {
67  // cout << "jet: " << it->pt() << " " << it->eta() << " " << it->phi()
68  // << endl;
69  // }
70 
71  // Find two leading jets
72  TLorentzVector jet1, jet2;
73 
74  reco::CaloJetCollection::const_iterator j1 = calojets_handle->begin();
75  reco::CaloJetCollection::const_iterator j2 = j1;
76  ++j2;
77 
78  jet1.SetPtEtaPhiM(j1->pt(), j1->eta(), j1->phi(), j1->mass());
79  jet2.SetPtEtaPhiM(j2->pt(), j2->eta(), j2->phi(), j2->mass());
80 
81  // cout << "j1: " << jet1.Pt() << " " << jet1.Eta() << " " << jet1.Phi() <<
82  // endl; cout << "j2: " << jet2.Pt() << " " << jet2.Eta() << " " <<
83  // jet2.Phi() << endl;
84 
85  // Create wide jets (radiation recovery algorithm)
86  for (reco::CaloJetCollection::const_iterator it = calojets_handle->begin(); it != calojets_handle->end(); ++it) {
87  TLorentzVector currentJet;
88  currentJet.SetPtEtaPhiM(it->pt(), it->eta(), it->phi(), it->mass());
89 
90  double DeltaR1 = currentJet.DeltaR(jet1);
91  double DeltaR2 = currentJet.DeltaR(jet2);
92 
93  if (DeltaR1 < DeltaR2 && DeltaR1 < wideJetDeltaR_) {
94  wj1_tmp += currentJet;
95  } else if (DeltaR2 < wideJetDeltaR_) {
96  wj2_tmp += currentJet;
97  }
98  }
99 
100  // Re-order the wide jets in pT
101  if (wj1_tmp.Pt() > wj2_tmp.Pt()) {
102  wj1 = wj1_tmp;
103  wj2 = wj2_tmp;
104  } else {
105  wj1 = wj2_tmp;
106  wj2 = wj1_tmp;
107  }
108 
109  // Create dijet system
110  wdijet = wj1 + wj2;
111 
112  // cout << "j1 wide: " << wj1.Pt() << " " << wj1.Eta() << " " <<
113  // wj1.Phi() << " " << wj1.M() << endl; cout << "j2 wide: " <<
114  // wj2.Pt() << " " << wj2.Eta() << " " << wj2.Phi() << " " << wj2.M()
115  // << endl; cout << "MJJWide: " << wdijet.M() << endl; cout <<
116  // "DeltaEtaJJWide: " << fabs(wj1.Eta()-wj2.Eta()) << endl; cout <<
117  // "DeltaPhiJJWide: " << fabs(wj1.DeltaPhi(wj2)) << endl;
118 
119  // // Put variables in the container
120  // dijetvariables->push_back( wdijet.M() ); //0 =
121  // MJJWide dijetvariables->push_back( fabs(wj1.Eta()-wj2.Eta()) );
122  // //1 = DeltaEtaJJWide dijetvariables->push_back(
123  // fabs(wj1.DeltaPhi(wj2)) ); //2 = DeltaPhiJJWide
124 
125  // Put widejets in the container
126  math::PtEtaPhiMLorentzVector wj1math(wj1.Pt(), wj1.Eta(), wj1.Phi(), wj1.M());
127  math::PtEtaPhiMLorentzVector wj2math(wj2.Pt(), wj2.Eta(), wj2.Phi(), wj2.M());
128  widejets->push_back(wj1math);
129  widejets->push_back(wj2math);
130  }
131  // else
132  // {
133  // // Put variables in the container
134  // dijetvariables->push_back( -1 ); //0 = MJJWide
135  // dijetvariables->push_back( -1 ); //1 = DeltaEtaJJWide
136  // dijetvariables->push_back( -1 ); //2 = DeltaPhiJJWide
137  // }
138 
139  // ## Put objects in the Event
140  // iEvent.put(std::move(dijetvariables), "dijetvariables");
141  iEvent.put(std::move(widejets), "widejets");
142 }
143 
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::string encode() const
Definition: InputTag.cc:159
edm::EDGetTokenT< reco::CaloJetCollection > inputJetTagToken_
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
int iEvent
Definition: GenABIO.cc:224
edm::InputTag inputJetTag_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
fixed size matrix
HLT enums.
DiJetVarProducer(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)