1414#include " FWCore/Framework/interface/Event.h"
1515#include " FWCore/Framework/interface/MakerMacros.h"
1616#include " FWCore/Framework/interface/EventSetup.h"
17-
18- #include " DataFormats/Common/interface/Handle.h"
17+ #include " FWCore/ParameterSet/interface/ParameterSet.h"
1918#include " FWCore/Utilities/interface/InputTag.h"
2019
21- #include " FWCore/ParameterSet /interface/ParameterSet .h"
20+ #include " DataFormats/Common /interface/Handle .h"
2221
2322#include " DataFormats/L1TCorrelator/interface/TkEm.h"
2423#include " DataFormats/L1TCorrelator/interface/TkEmFwd.h"
25-
2624#include " DataFormats/L1TCorrelator/interface/TkPrimaryVertex.h"
2725
2826#include " DataFormats/Math/interface/LorentzVector.h"
27+ #include " DataFormats/Math/interface/deltaR.h"
2928
3029// for L1Tracks:
3130#include " DataFormats/L1TrackTrigger/interface/TTTypes.h"
3231
33- #include " DataFormats/Math/interface/deltaR.h"
34-
3532#include < string>
3633#include < cmath>
3734
@@ -60,55 +57,43 @@ class L1TkEmParticleProducer : public edm::global::EDProducer<> {
6057
6158 // ----------member data ---------------------------
6259
63- std::string label_;
64-
65- float etMin_; // min ET in GeV of L1EG objects
66-
67- float zMax_; // |z_track| < zMax_ in cm
68- float chi2Max_;
69- float dRMin_;
70- float dRMax_;
71- float pTMinTra_;
72- bool primaryVtxConstrain_; // use the primary vertex (default = false)
73- // bool DeltaZConstrain; // use z = z of the leading track within DR < dRMax_;
74- float deltaZMax_; // | z_track - z_primaryvtx | < deltaZMax_ in cm.
75- // Used only when primaryVtxConstrain_ = True.
76- float isoCut_;
77- bool relativeIsolation_;
78-
7960 const edm::EDGetTokenT<EGammaBxCollection> egToken_;
80- const edm::EDGetTokenT<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > > trackToken_;
61+ const edm::EDGetTokenT<L1TTTrackCollectionType > trackToken_;
8162 const edm::EDGetTokenT<TkPrimaryVertexCollection> vertexToken_;
63+
64+ const std::string label_;
65+
66+ const float etMin_; // min ET in GeV of L1EG objects
67+ const float zMax_; // |z_track| < zMax_ in cm
68+ const float chi2Max_;
69+ const float pTMinTra_;
70+ const float dR2Min_;
71+ const float dR2Max_;
72+ const bool primaryVtxConstrain_; // use the primary vertex (default = false)
73+ const float deltaZMax_; // | z_track - z_primaryvtx | < deltaZMax_ in cm.
74+ // Used only when primaryVtxConstrain_ = True.
75+ const float isoCut_;
76+ const bool relativeIsolation_;
8277};
8378
8479//
8580// constructors and destructor
8681//
8782L1TkEmParticleProducer::L1TkEmParticleProducer (const edm::ParameterSet& iConfig)
8883 : egToken_(consumes<EGammaBxCollection>(iConfig.getParameter<edm::InputTag>(" L1EGammaInputTag" ))),
89- trackToken_(consumes<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > >(
90- iConfig.getParameter<edm::InputTag>(" L1TrackInputTag" ))),
91- vertexToken_(consumes<TkPrimaryVertexCollection>(iConfig.getParameter<edm::InputTag>(" L1VertexInputTag" ))) {
92- label_ = iConfig.getParameter <std::string>(" label" ); // label of the collection produced
93- // e.g. EG or IsoEG if all objects are kept
94- // EGIsoTrk or IsoEGIsoTrk if only the EG or IsoEG
95- // objects that pass a cut RelIso < isoCut_ are written
96- // in the new collection.
97-
98- etMin_ = (float )iConfig.getParameter <double >(" ETmin" );
99-
100- // parameters for the calculation of the isolation :
101- zMax_ = (float )iConfig.getParameter <double >(" ZMAX" );
102- chi2Max_ = (float )iConfig.getParameter <double >(" CHI2MAX" );
103- pTMinTra_ = (float )iConfig.getParameter <double >(" PTMINTRA" );
104- dRMin_ = (float )iConfig.getParameter <double >(" DRmin" );
105- dRMax_ = (float )iConfig.getParameter <double >(" DRmax" );
106- primaryVtxConstrain_ = iConfig.getParameter <bool >(" PrimaryVtxConstrain" );
107- deltaZMax_ = (float )iConfig.getParameter <double >(" DeltaZMax" );
108- // cut applied on the isolation (if this number is <= 0, no cut is applied)
109- isoCut_ = (float )iConfig.getParameter <double >(" IsoCut" );
110- relativeIsolation_ = iConfig.getParameter <bool >(" RelativeIsolation" );
111-
84+ trackToken_(consumes<L1TTTrackCollectionType>(iConfig.getParameter<edm::InputTag>(" L1TrackInputTag" ))),
85+ vertexToken_(consumes<TkPrimaryVertexCollection>(iConfig.getParameter<edm::InputTag>(" L1VertexInputTag" ))),
86+ label_(iConfig.getParameter<std::string>(" label" )),
87+ etMin_((float )iConfig.getParameter<double>(" ETmin" )),
88+ zMax_((float )iConfig.getParameter<double>(" ZMAX" )),
89+ chi2Max_((float )iConfig.getParameter<double>(" CHI2MAX" )),
90+ pTMinTra_((float )iConfig.getParameter<double>(" PTMINTRA" )),
91+ dR2Min_((float )iConfig.getParameter<double>(" DRmin" ) * (float )iConfig.getParameter<double>(" DRmin" )),
92+ dR2Max_((float )iConfig.getParameter<double>(" DRmax" ) * (float )iConfig.getParameter<double>(" DRmax" )),
93+ primaryVtxConstrain_(iConfig.getParameter<bool >(" PrimaryVtxConstrain" )),
94+ deltaZMax_((float )iConfig.getParameter<double>(" DeltaZMax" )),
95+ isoCut_((float )iConfig.getParameter<double>(" IsoCut" )),
96+ relativeIsolation_(iConfig.getParameter<bool >(" RelativeIsolation" )) {
11297 produces<TkEmCollection>(label_);
11398}
11499
@@ -120,21 +105,20 @@ void L1TkEmParticleProducer::produce(edm::StreamID, edm::Event& iEvent, const ed
120105
121106 auto result = std::make_unique<TkEmCollection>();
122107
123- // the L1EGamma objects
124- edm::Handle<EGammaBxCollection> eGammaHandle;
125- iEvent.getByToken (egToken_, eGammaHandle);
126- EGammaBxCollection eGammaCollection = (*eGammaHandle.product ());
127- EGammaBxCollection::const_iterator egIter;
128-
129108 // the L1Tracks
130- edm::Handle<std::vector<TTTrack<Ref_Phase2TrackerDigi_> > > L1TTTrackHandle;
109+ edm::Handle<L1TTTrackCollectionType > L1TTTrackHandle;
131110 iEvent.getByToken (trackToken_, L1TTTrackHandle);
111+ if (!L1TTTrackHandle.isValid ()) {
112+ LogError (" L1TkEmParticleProducer" ) << " \n Warning: L1TTTrackCollectionType not found in the event. Exit."
113+ << std::endl;
114+ return ;
115+ }
132116
133117 // the primary vertex (used only if primaryVtxConstrain_ = true)
134118 float zvtxL1tk = -999 ;
119+ bool primaryVtxConstrain = primaryVtxConstrain_;
135120 edm::Handle<TkPrimaryVertexCollection> L1VertexHandle;
136121 iEvent.getByToken (vertexToken_, L1VertexHandle);
137- bool primaryVtxConstrain = primaryVtxConstrain_;
138122 if (!L1VertexHandle.isValid ()) {
139123 LogWarning (" L1TkEmParticleProducer" )
140124 << " Warning: TkPrimaryVertexCollection not found in the event. Won't use any PrimaryVertex constraint."
@@ -147,44 +131,40 @@ void L1TkEmParticleProducer::produce(edm::StreamID, edm::Event& iEvent, const ed
147131 zvtxL1tk = vtxIter->zvertex ();
148132 }
149133
150- if (!L1TTTrackHandle.isValid ()) {
151- LogError (" L1TkEmParticleProducer" ) << " \n Warning: L1TTTrackCollectionType not found in the event. Exit."
152- << std::endl;
153- return ;
154- }
155-
156134 // Now loop over the L1EGamma objects
157135
136+ edm::Handle<EGammaBxCollection> eGammaHandle;
137+ iEvent.getByToken (egToken_, eGammaHandle);
158138 if (!eGammaHandle.isValid ()) {
159139 LogError (" L1TkEmParticleProducer" ) << " \n Warning: L1EmCollection not found in the event. Exit." << std::endl;
160140 return ;
161141 }
142+ EGammaBxCollection eGammaCollection = (*eGammaHandle.product ());
143+ EGammaBxCollection::const_iterator egIter;
162144
163145 int ieg = 0 ;
164146 for (egIter = eGammaCollection.begin (0 ); egIter != eGammaCollection.end (0 ); ++egIter) // considering BX = only
165147 {
166148 edm::Ref<EGammaBxCollection> EGammaRef (eGammaHandle, ieg);
167149 ieg++;
168150
151+ float et = egIter->et ();
152+ if (et < etMin_)
153+ continue ;
154+
169155 float eta = egIter->eta ();
170156 // The eta of the L1EG object is seen from (0,0,0).
171157 // if primaryVtxConstrain_ = true, and for the PV constrained iso, use the zvtxL1tk to correct the eta(L1EG)
172158 // that is used in the calculation of DeltaR.
173- float etaPV = CorrectedEta (( float ) eta, zvtxL1tk);
159+ float etaPV = CorrectedEta (eta, zvtxL1tk);
174160
175161 float phi = egIter->phi ();
176- float et = egIter->et ();
177-
178- if (et < etMin_)
179- continue ;
180162
181163 // calculate the isolation of the L1EG object with
182164 // respect to L1Tracks.
183165
184- float trkisol = -999 ;
185166 float sumPt = 0 ;
186167 float sumPtPV = 0 ;
187- float trkisolPV = -999 ;
188168
189169 for (const auto & track : *L1TTTrackHandle) {
190170 float Pt = track.momentum ().perp ();
@@ -199,21 +179,22 @@ void L1TkEmParticleProducer::produce(edm::StreamID, edm::Event& iEvent, const ed
199179 if (chi2 > chi2Max_)
200180 continue ;
201181
202- float dr = reco::deltaR (Eta, Phi, eta, phi);
203- if (dr < dRMax_ && dr >= dRMin_ ) {
182+ float dr2 = reco::deltaR2 (Eta, Phi, eta, phi);
183+ if (dr2 < dR2Max_ && dr2 >= dR2Min_ ) {
204184 sumPt += Pt;
205185 }
206186
207187 if (zvtxL1tk > -999 && std::abs (z - zvtxL1tk) >= deltaZMax_)
208188 continue ; // Now, PV constrained trackSum:
209189
210- dr = reco::deltaR (Eta, Phi, etaPV, phi); // recompute using the corrected eta
211-
212- if (dr < dRMax_ && dr >= dRMin_) {
190+ dr2 = reco::deltaR2 (Eta, Phi, etaPV, phi); // recompute using the corrected eta
191+ if (dr2 < dR2Max_ && dr2 >= dR2Min_) {
213192 sumPtPV += Pt;
214193 }
215194 } // end loop over tracks
216195
196+ float trkisol = -999 ;
197+ float trkisolPV = -999 ;
217198 if (relativeIsolation_) {
218199 if (et > 0 ) {
219200 trkisol = sumPt / et;
@@ -224,10 +205,7 @@ void L1TkEmParticleProducer::produce(edm::StreamID, edm::Event& iEvent, const ed
224205 trkisolPV = sumPtPV;
225206 }
226207
227- float isolation = trkisol;
228- if (primaryVtxConstrain) {
229- isolation = trkisolPV;
230- }
208+ float isolation = primaryVtxConstrain ? trkisolPV : trkisol;
231209
232210 const math::XYZTLorentzVector P4 = egIter->p4 ();
233211 TkEm trkEm (P4, EGammaRef, trkisol, trkisolPV);
@@ -253,30 +231,39 @@ void L1TkEmParticleProducer::produce(edm::StreamID, edm::Event& iEvent, const ed
253231float L1TkEmParticleProducer::CorrectedEta (float eta, float zv) const {
254232 // Correct the eta of the L1EG object once we know the zvertex
255233
234+ if (zv == 0 .)
235+ return eta;
236+
237+ if (eta == 0 ) {
238+ float thetaprime = atan (-REcal / zv);
239+ if (thetaprime < 0 )
240+ thetaprime = thetaprime + M_PI;
241+ float etaprime = -log (tan (0.5 * thetaprime));
242+ return etaprime;
243+ }
244+
256245 bool IsBarrel = (std::abs (eta) < EtaECal);
257246
258- float theta = 2 . * atan (exp (-eta));
259- if (theta < 0 )
260- theta = theta + M_PI;
261- float tantheta = tan (theta);
247+ float tanhalftheta = exp (-eta);
248+ float tantheta = 2 . * tanhalftheta / (1 . - tanhalftheta * tanhalftheta);
262249
263250 float delta;
264- if (IsBarrel) {
251+ if (IsBarrel)
265252 delta = REcal / tantheta;
253+ else
254+ delta = eta > 0 ? ZEcal : -ZEcal;
255+
256+ float etaprime;
257+ if (delta == zv) {
258+ etaprime = 0 .;
266259 } else {
267- if (theta > 0 )
268- delta = ZEcal;
269- if (theta < 0 )
270- delta = -ZEcal;
260+ float tanthetaprime = delta * tantheta / (delta - zv);
261+ float thetaprime = atan (tanthetaprime);
262+ if (thetaprime < 0 )
263+ thetaprime = thetaprime + M_PI;
264+ etaprime = -log (tan (0.5 * thetaprime));
271265 }
272266
273- float tanthetaprime = delta * tantheta / (delta - zv);
274-
275- float thetaprime = atan (tanthetaprime);
276- if (thetaprime < 0 )
277- thetaprime = thetaprime + M_PI;
278-
279- float etaprime = -log (tan (thetaprime / 2 .));
280267 return etaprime;
281268}
282269
@@ -285,8 +272,21 @@ void L1TkEmParticleProducer::fillDescriptions(edm::ConfigurationDescriptions& de
285272 // The following says we do not know what parameters are allowed so do no validation
286273 // Please change this to state exactly what you do use, even if it is no parameters
287274 edm::ParameterSetDescription desc;
288- desc.setUnknown ();
289- descriptions.addDefault (desc);
275+ desc.add <string>(" label" , " EG" );
276+ desc.add <edm::InputTag>(" L1EGammaInputTag" , edm::InputTag (" simCaloStage2Digis" ));
277+ desc.add <edm::InputTag>(" L1TrackInputTag" , edm::InputTag (" TTTracksFromTrackletEmulation" , " Level1TTTracks" ));
278+ desc.add <edm::InputTag>(" L1VertexInputTag" , edm::InputTag (" L1TkPrimaryVertex" ));
279+ desc.add <double >(" ETmin" , -1 .);
280+ desc.add <bool >(" RelativeIsolation" , true );
281+ desc.add <double >(" IsoCut" , 0.23 );
282+ desc.add <double >(" ZMAX" , 25 .);
283+ desc.add <double >(" CHI2MAX" , 100 .);
284+ desc.add <double >(" PTMINTRA" , 2 .);
285+ desc.add <double >(" DRmin" , 0.07 );
286+ desc.add <double >(" DRmax" , 0.30 );
287+ desc.add <bool >(" PrimaryVtxConstrain" , false );
288+ desc.add <double >(" DeltaZMax" , 0.6 );
289+ descriptions.add (" l1TkEmParticleProducer" , desc);
290290}
291291
292292// define this as a plug-in
0 commit comments