CMS 3D CMS Logo

L1TkEmParticleProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 // dummy producer for a TkEm
5 //
6 
7 // system include files
8 #include <memory>
9 
10 // user include files
13 
19 
21 
25 
28 
29 // for L1Tracks:
31 
32 #include <string>
33 #include <cmath>
34 
35 static constexpr float EtaECal = 1.479;
36 static constexpr float REcal = 129.;
37 static constexpr float ZEcal = 315.4;
38 using namespace l1t;
39 //
40 // class declaration
41 //
42 
44 public:
46  typedef std::vector<L1TTTrackType> L1TTTrackCollectionType;
47 
49  ~L1TkEmParticleProducer() override;
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53  float CorrectedEta(float eta, float zv) const;
54 
55 private:
56  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
57 
58  // ----------member data ---------------------------
59 
63 
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_;
77 };
78 
79 //
80 // constructors and destructor
81 //
83  : egToken_(consumes<EGammaBxCollection>(iConfig.getParameter<edm::InputTag>("L1EGammaInputTag"))),
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")) {
97  produces<TkEmCollection>(label_);
98 }
99 
101 
102 // ------------ method called to produce the data ------------
104  using namespace edm;
105 
106  auto result = std::make_unique<TkEmCollection>();
107 
108  // the L1Tracks
109  edm::Handle<L1TTTrackCollectionType> L1TTTrackHandle;
110  iEvent.getByToken(trackToken_, L1TTTrackHandle);
111  if (!L1TTTrackHandle.isValid()) {
112  LogError("L1TkEmParticleProducer") << "\nWarning: L1TTTrackCollectionType not found in the event. Exit."
113  << std::endl;
114  return;
115  }
116 
117  // the primary vertex (used only if primaryVtxConstrain_ = true)
118  float zvtxL1tk = -999;
121  iEvent.getByToken(vertexToken_, L1VertexHandle);
122  if (!L1VertexHandle.isValid()) {
123  LogWarning("L1TkEmParticleProducer")
124  << "Warning: TkPrimaryVertexCollection not found in the event. Won't use any PrimaryVertex constraint."
125  << std::endl;
126  primaryVtxConstrain = false;
127  } else {
128  std::vector<TkPrimaryVertex>::const_iterator vtxIter = L1VertexHandle->begin();
129  // by convention, the first vertex in the collection is the one that should
130  // be used by default
131  zvtxL1tk = vtxIter->zvertex();
132  }
133 
134  // Now loop over the L1EGamma objects
135 
136  edm::Handle<EGammaBxCollection> eGammaHandle;
137  iEvent.getByToken(egToken_, eGammaHandle);
138  if (!eGammaHandle.isValid()) {
139  LogError("L1TkEmParticleProducer") << "\nWarning: L1EmCollection not found in the event. Exit." << std::endl;
140  return;
141  }
142  EGammaBxCollection eGammaCollection = (*eGammaHandle.product());
144 
145  int ieg = 0;
146  for (egIter = eGammaCollection.begin(0); egIter != eGammaCollection.end(0); ++egIter) // considering BX = only
147  {
148  edm::Ref<EGammaBxCollection> EGammaRef(eGammaHandle, ieg);
149  ieg++;
150 
151  float et = egIter->et();
152  if (et < etMin_)
153  continue;
154 
155  float eta = egIter->eta();
156  // The eta of the L1EG object is seen from (0,0,0).
157  // if primaryVtxConstrain_ = true, and for the PV constrained iso, use the zvtxL1tk to correct the eta(L1EG)
158  // that is used in the calculation of DeltaR.
159  float etaPV = CorrectedEta(eta, zvtxL1tk);
160 
161  float phi = egIter->phi();
162 
163  // calculate the isolation of the L1EG object with
164  // respect to L1Tracks.
165 
166  float sumPt = 0;
167  float sumPtPV = 0;
168 
169  for (const auto& track : *L1TTTrackHandle) {
170  float Pt = track.momentum().perp();
171  float Eta = track.momentum().eta();
172  float Phi = track.momentum().phi();
173  float z = track.POCA().z();
174  if (fabs(z) > zMax_)
175  continue;
176  if (Pt < pTMinTra_)
177  continue;
178  float chi2 = track.chi2();
179  if (chi2 > chi2Max_)
180  continue;
181 
182  float dr2 = reco::deltaR2(Eta, Phi, eta, phi);
183  if (dr2 < dR2Max_ && dr2 >= dR2Min_) {
184  sumPt += Pt;
185  }
186 
187  if (zvtxL1tk > -999 && std::abs(z - zvtxL1tk) >= deltaZMax_)
188  continue; // Now, PV constrained trackSum:
189 
190  dr2 = reco::deltaR2(Eta, Phi, etaPV, phi); // recompute using the corrected eta
191  if (dr2 < dR2Max_ && dr2 >= dR2Min_) {
192  sumPtPV += Pt;
193  }
194  } // end loop over tracks
195 
196  float trkisol = -999;
197  float trkisolPV = -999;
198  if (relativeIsolation_) {
199  if (et > 0) {
200  trkisol = sumPt / et;
201  trkisolPV = sumPtPV / et;
202  } // relative isolation
203  } else { // absolute isolation
204  trkisol = sumPt;
205  trkisolPV = sumPtPV;
206  }
207 
208  float isolation = primaryVtxConstrain ? trkisolPV : trkisol;
209 
210  const math::XYZTLorentzVector P4 = egIter->p4();
211  TkEm trkEm(P4, EGammaRef, trkisol, trkisolPV);
212 
213  if (isoCut_ <= 0) {
214  // write the L1TkEm particle to the collection,
215  // irrespective of its relative isolation
216  result->push_back(trkEm);
217  } else {
218  // the object is written to the collection only
219  // if it passes the isolation cut
220  if (isolation <= isoCut_)
221  result->push_back(trkEm);
222  }
223 
224  } // end loop over EGamma objects
225 
226  iEvent.put(std::move(result), label_);
227 }
228 
229 // --------------------------------------------------------------------------------------
230 
231 float L1TkEmParticleProducer::CorrectedEta(float eta, float zv) const {
232  // Correct the eta of the L1EG object once we know the zvertex
233 
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 
245  bool IsBarrel = (std::abs(eta) < EtaECal);
246 
247  float tanhalftheta = exp(-eta);
248  float tantheta = 2. * tanhalftheta / (1. - tanhalftheta * tanhalftheta);
249 
250  float delta;
251  if (IsBarrel)
252  delta = REcal / tantheta;
253  else
254  delta = eta > 0 ? ZEcal : -ZEcal;
255 
256  float etaprime;
257  if (delta == zv) {
258  etaprime = 0.;
259  } else {
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));
265  }
266 
267  return etaprime;
268 }
269 
270 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
272  //The following says we do not know what parameters are allowed so do no validation
273  // Please change this to state exactly what you do use, even if it is no parameters
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);
290 }
291 
292 //define this as a plug-in
L1TkEmParticleProducer::etMin_
const float etMin_
Definition: L1TkEmParticleProducer.cc:66
L1TkEmParticleProducer::L1TTTrackType
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
Definition: L1TkEmParticleProducer.cc:45
edm::StreamID
Definition: StreamID.h:30
TkEmFwd.h
L1TkEmParticleProducer::trackToken_
const edm::EDGetTokenT< L1TTTrackCollectionType > trackToken_
Definition: L1TkEmParticleProducer.cc:61
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
TkPrimaryVertex.h
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
L1TkEmParticleProducer::CorrectedEta
float CorrectedEta(float eta, float zv) const
Definition: L1TkEmParticleProducer.cc:231
edm::Handle::product
T const * product() const
Definition: Handle.h:70
L1TkEmParticleProducer::L1TkEmParticleProducer
L1TkEmParticleProducer(const edm::ParameterSet &)
Definition: L1TkEmParticleProducer.cc:82
TTTypes.h
edm::EDGetTokenT< EGammaBxCollection >
BXVector::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
L1TkEmParticleProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TkEmParticleProducer.cc:271
TTTrack
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
L1TkEmParticleProducer::label_
const std::string label_
Definition: L1TkEmParticleProducer.cc:64
L1TkEmParticleProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: L1TkEmParticleProducer.cc:103
gpuVertexFinder::zv
float *__restrict__ zv
Definition: gpuFitVertices.h:26
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
L1TkEmParticleProducer::deltaZMax_
const float deltaZMax_
Definition: L1TkEmParticleProducer.cc:73
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
edm::Ref
Definition: AssociativeIterator.h:58
TtFullHadEvtBuilder_cfi.sumPt
sumPt
Definition: TtFullHadEvtBuilder_cfi.py:38
L1TkEmParticleProducer::chi2Max_
const float chi2Max_
Definition: L1TkEmParticleProducer.cc:68
BXVector
Definition: BXVector.h:15
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
EtaECal
static constexpr float EtaECal
Definition: L1TkEmParticleProducer.cc:35
L1TkEmParticleProducer::L1TTTrackCollectionType
std::vector< L1TTTrackType > L1TTTrackCollectionType
Definition: L1TkEmParticleProducer.cc:46
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
l1t::TkPrimaryVertexCollection
std::vector< TkPrimaryVertex > TkPrimaryVertexCollection
Definition: TkPrimaryVertex.h:30
PVValHelper::eta
Definition: PVValidationHelpers.h:70
l1t::EGammaRef
edm::Ref< EGammaBxCollection > EGammaRef
Definition: TkEGTau.h:35
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
DDAxes::z
VtxSmearedParameters_cfi.Phi
Phi
Definition: VtxSmearedParameters_cfi.py:112
L1TkEmParticleProducer::pTMinTra_
const float pTMinTra_
Definition: L1TkEmParticleProducer.cc:69
BXVector::begin
const_iterator begin(int bx) const
L1TkEmParticleProducer::dR2Max_
const float dR2Max_
Definition: L1TkEmParticleProducer.cc:71
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
l1t::TkEm
Definition: TkEm.h:19
BXVector::end
const_iterator end(int bx) const
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
deltaR.h
l1t
delete x;
Definition: CaloConfig.h:22
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
LorentzVector.h
iEvent
int iEvent
Definition: GenABIO.cc:224
L1TkHTMissProducer_cfi.primaryVtxConstrain
primaryVtxConstrain
Definition: L1TkHTMissProducer_cfi.py:14
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
TkEm.h
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
REcal
static constexpr float REcal
Definition: L1TkEmParticleProducer.cc:36
edm::EventSetup
Definition: EventSetup.h:58
L1TkEmParticleProducer::~L1TkEmParticleProducer
~L1TkEmParticleProducer() override
Definition: L1TkEmParticleProducer.cc:100
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
L1TkEmParticleProducer::vertexToken_
const edm::EDGetTokenT< TkPrimaryVertexCollection > vertexToken_
Definition: L1TkEmParticleProducer.cc:62
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1TkEmParticleProducer
Definition: L1TkEmParticleProducer.cc:43
InputTag.h
L1TkEmParticleProducer::zMax_
const float zMax_
Definition: L1TkEmParticleProducer.cc:67
DDAxes::phi
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
L1TkEmParticleProducer::primaryVtxConstrain_
const bool primaryVtxConstrain_
Definition: L1TkEmParticleProducer.cc:72
EventSetup.h
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
mps_fire.result
result
Definition: mps_fire.py:311
L1TkEmParticleProducer::isoCut_
const float isoCut_
Definition: L1TkEmParticleProducer.cc:75
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1TkEmParticleProducer::egToken_
const edm::EDGetTokenT< EGammaBxCollection > egToken_
Definition: L1TkEmParticleProducer.cc:60
ParameterSet.h
EDProducer.h
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
ZEcal
static constexpr float ZEcal
Definition: L1TkEmParticleProducer.cc:37
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
L1TkEmParticleProducer::dR2Min_
const float dR2Min_
Definition: L1TkEmParticleProducer.cc:70
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
isolation
double isolation
Definition: AssociatedVariableMaxCutCandRefSelector.cc:25
L1TkEmParticleProducer::relativeIsolation_
const bool relativeIsolation_
Definition: L1TkEmParticleProducer.cc:76