CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1TkHTMissProducer.cc
Go to the documentation of this file.
1 // Original Author: Emmanuelle Perez,40 1-A28,+41227671915,
2 // Created: Tue Nov 12 17:03:19 CET 2013
3 
4 // system include files
5 #include <memory>
6 
7 // user include files
20 
21 using namespace l1t;
22 
24 public:
25  explicit L1TkHTMissProducer(const edm::ParameterSet&);
26  ~L1TkHTMissProducer() override;
27 
28 private:
29  //void beginJob() override;
30  void produce(edm::Event&, const edm::EventSetup&) override;
31  //void endJob() override;
32 
33  // ----------member data ---------------------------
34  float jetMinPt_; // [GeV]
35  float jetMaxEta_; // [rad]
36  bool doVtxConstrain_; // require vertex constraint
37  bool primaryVtxConstrain_; // use event primary vertex instead of leading jet (if doVtxConstrain)
38  bool useCaloJets_; // Determines whether or not calo jets are used
39  float deltaZ_; // for jets [cm] (if DoTvxConstrain)
40  float minJetEtLowPt_; // for track jets, minimum et required, depending on number of low pT tracks
42  bool displaced_; // Use prompt/displaced tracks
43  unsigned int minNtracksHighPt_;
44  unsigned int minNtracksLowPt_;
47 };
48 
50  : pvToken_(consumes<TkPrimaryVertexCollection>(iConfig.getParameter<edm::InputTag>("L1VertexInputTag"))),
51  jetToken_(consumes<TkJetCollection>(iConfig.getParameter<edm::InputTag>("L1TkJetInputTag"))) {
52  jetMinPt_ = (float)iConfig.getParameter<double>("jet_minPt");
53  jetMaxEta_ = (float)iConfig.getParameter<double>("jet_maxEta");
54  doVtxConstrain_ = iConfig.getParameter<bool>("doVtxConstrain");
55  useCaloJets_ = iConfig.getParameter<bool>("useCaloJets");
56  primaryVtxConstrain_ = iConfig.getParameter<bool>("primaryVtxConstrain");
57  deltaZ_ = (float)iConfig.getParameter<double>("deltaZ");
58  minNtracksHighPt_ = iConfig.getParameter<int>("jet_minNtracksHighPt");
59  minNtracksLowPt_ = iConfig.getParameter<int>("jet_minNtracksLowPt");
60  minJetEtLowPt_ = iConfig.getParameter<double>("jet_minJetEtLowPt");
61  minJetEtHighPt_ = iConfig.getParameter<double>("jet_minJetEtHighPt");
62  displaced_ = iConfig.getParameter<bool>("displaced");
63 
64  if (useCaloJets_)
65  produces<TkHTMissCollection>("TkCaloHTMiss");
66  else if (displaced_)
67  produces<TkHTMissCollection>("L1TrackerHTMissExtended");
68  else
69  produces<TkHTMissCollection>("L1TrackerHTMiss");
70 }
71 
73 
75  using namespace edm;
76  std::unique_ptr<TkHTMissCollection> MHTCollection(new TkHTMissCollection);
77 
78  // L1 primary vertex
80  iEvent.getByToken(pvToken_, L1VertexHandle);
81 
82  // L1 track-trigger jets
83  edm::Handle<TkJetCollection> L1TkJetsHandle;
84  iEvent.getByToken(jetToken_, L1TkJetsHandle);
85  std::vector<TkJet>::const_iterator jetIter;
86 
87  if (!L1TkJetsHandle.isValid() && !displaced_) {
88  LogError("TkHTMissProducer") << "\nWarning: TkJetCollection not found in the event. Exit\n";
89  return;
90  }
91 
92  if (!L1TkJetsHandle.isValid() && displaced_) {
93  LogError("TkHTMissProducer") << "\nWarning: TkJetExtendedCollection not found in the event. Exit\n";
94  return;
95  }
96 
97  // ----------------------------------------------------------------------------------------------
98  // if primaryVtxConstrain_, use the primary vertex instead of z position from leading jet
99  // ----------------------------------------------------------------------------------------------
100  float evtZVtx = 999;
101  bool foundVtx = false;
102  edm::Ref<TkPrimaryVertexCollection> L1VtxRef; // null reference
103 
104  if (useCaloJets_) {
106  if (!L1VertexHandle.isValid()) {
107  LogError("L1TkHTMissProducer") << "\nWarning: TkPrimaryVertexCollection not found in the event. Exit\n";
108  return;
109  } else {
110  std::vector<TkPrimaryVertex>::const_iterator vtxIter = L1VertexHandle->begin();
111  // by convention, the first vertex in the collection is the one that should
112  // be used by default
113  evtZVtx = vtxIter->zvertex();
114  foundVtx = true;
115  int ivtx = 0;
116  edm::Ref<TkPrimaryVertexCollection> vtxRef(L1VertexHandle, ivtx);
117  L1VtxRef = vtxRef;
118  }
119  } //endif primaryVtxConstrain_
120 
121  // ----------------------------------------------------------------------------------------------
122  // using z position of leading jet to define "event vertex"
123  // ----------------------------------------------------------------------------------------------
124  float zvtx_jetpt = -1.0; //pt of jet determining the event vertex
125  float jetVtxMax = 99.; //find z position of leading jet that has a z vertex!
126 
128  for (jetIter = L1TkJetsHandle->begin(); jetIter != L1TkJetsHandle->end(); ++jetIter) {
129  int ibx = jetIter->bx(); // only consider jets from the central BX
130  if (ibx != 0)
131  continue;
132 
133  float tmp_jet_vtx = jetIter->jetVtx();
134  float tmp_jet_pt = jetIter->pt();
135  float tmp_jet_eta = jetIter->eta();
136  if (tmp_jet_pt < jetMinPt_)
137  continue;
138  if (fabs(tmp_jet_eta) > jetMaxEta_)
139  continue;
140  if (fabs(tmp_jet_vtx) > jetVtxMax)
141  continue;
142 
143  // find vertex position of leading jet
144  if (tmp_jet_pt > zvtx_jetpt) {
145  evtZVtx = tmp_jet_vtx;
146  zvtx_jetpt = tmp_jet_pt;
147  foundVtx = true;
148  }
149  } //end loop over jets
150  } //endif z position from leading jet
151 
152  float sumPx_calo = 0;
153  float sumPy_calo = 0;
154  float HT_calo = 0;
155 
156  if (doVtxConstrain_ && !foundVtx)
157  LogWarning("L1TkHTMissProducer") << "Didn't find any z vertex (based on jet vertices) for this event!\n";
158 
159  // loop over jets
160  for (jetIter = L1TkJetsHandle->begin(); jetIter != L1TkJetsHandle->end(); ++jetIter) {
161  int ibx = jetIter->bx(); // only consider jets from the central BX
162  if (ibx != 0)
163  continue;
164 
165  float tmp_jet_px = jetIter->px();
166  float tmp_jet_py = jetIter->py();
167  float tmp_jet_et = jetIter->et();
168  float tmp_jet_vtx = jetIter->jetVtx();
169  if (jetIter->pt() < jetMinPt_)
170  continue;
171  if (fabs(jetIter->eta()) > jetMaxEta_)
172  continue;
173 
174  // vertex consistency requirement
175  bool VtxRequirement = false;
176  if (foundVtx)
177  VtxRequirement = fabs(tmp_jet_vtx - evtZVtx) < deltaZ_;
178 
179  if (!doVtxConstrain_ || VtxRequirement) {
180  sumPx_calo += tmp_jet_px;
181  sumPy_calo += tmp_jet_py;
182  HT_calo += tmp_jet_et;
183  }
184  } //end loop over jets
185 
186  // define missing HT
187  float et = sqrt(sumPx_calo * sumPx_calo + sumPy_calo * sumPy_calo);
188  math::XYZTLorentzVector missingEt(-sumPx_calo, -sumPy_calo, 0, et);
189  edm::RefProd<TkJetCollection> jetCollRef(L1TkJetsHandle);
190  TkHTMiss tkHTM(missingEt, HT_calo, jetCollRef, L1VtxRef);
191 
193  tkHTM.setVtx(evtZVtx);
194  }
195 
196  MHTCollection->push_back(tkHTM);
197  iEvent.put(std::move(MHTCollection), "L1TkCaloHTMiss");
198  }
199 
200  else { // Using standalone jets
201  float sumPx = 0;
202  float sumPy = 0;
203  float HT = 0;
204 
205  // loop over jets
206  for (jetIter = L1TkJetsHandle->begin(); jetIter != L1TkJetsHandle->end(); ++jetIter) {
207  float tmp_jet_px = jetIter->px();
208  float tmp_jet_py = jetIter->py();
209  float tmp_jet_et = jetIter->et();
210  float tmp_jet_pt = jetIter->pt();
211  if (tmp_jet_pt < jetMinPt_)
212  continue;
213  if (fabs(jetIter->eta()) > jetMaxEta_)
214  continue;
215  if (jetIter->ntracks() < minNtracksLowPt_ && tmp_jet_et > minJetEtLowPt_)
216  continue;
217  if (jetIter->ntracks() < minNtracksHighPt_ && tmp_jet_et > minJetEtHighPt_)
218  continue;
219  sumPx += tmp_jet_px;
220  sumPy += tmp_jet_py;
221  HT += tmp_jet_pt;
222  } // end jet loop
223 
224  // define missing HT
225  float et = sqrt(sumPx * sumPx + sumPy * sumPy);
226  math::XYZTLorentzVector missingEt(-sumPx, -sumPy, 0, et);
227  edm::RefProd<TkJetCollection> jetCollRef(L1TkJetsHandle);
228  TkHTMiss tkHTM(missingEt, HT, jetCollRef, L1VtxRef);
229 
230  MHTCollection->push_back(tkHTM);
231  if (displaced_)
232  iEvent.put(std::move(MHTCollection), "L1TrackerHTMissExtended");
233  else
234  iEvent.put(std::move(MHTCollection), "L1TrackerHTMiss");
235  }
236 } //end producer
237 
238 //void L1TkHTMissProducer::beginJob() {}
239 
240 //void L1TkHTMissProducer::endJob() {}
241 
~L1TkHTMissProducer() override
void produce(edm::Event &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EDGetTokenT< TkJetCollection > jetToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1TkHTMissProducer(const edm::ParameterSet &)
std::vector< TkHTMiss > TkHTMissCollection
Definition: TkHTMissFwd.h:10
Log< level::Error, false > LogError
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
def move
Definition: eostools.py:511
std::vector< pat::MHT > MHTCollection
Definition: MHT.h:39
unsigned int minNtracksLowPt_
unsigned int minNtracksHighPt_
void setVtx(const float &zvtx)
Definition: TkHTMiss.h:41
const edm::EDGetTokenT< TkPrimaryVertexCollection > pvToken_
std::vector< TkPrimaryVertex > TkPrimaryVertexCollection
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Log< level::Warning, false > LogWarning
std::vector< TkJet > TkJetCollection
Definition: TkJetFwd.h:20
Definition: HT.h:21