CMS 3D CMS Logo

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