CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
119  bool primaryVtxConstrain = primaryVtxConstrain_;
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
static constexpr float EtaECal
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
static std::vector< std::string > checklist log
edm::Ref< EGammaBxCollection > EGammaRef
Definition: TkEGTau.h:35
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
float *__restrict__ zv
const edm::EDGetTokenT< EGammaBxCollection > egToken_
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
Log< level::Error, false > LogError
static constexpr float REcal
const edm::EDGetTokenT< TkPrimaryVertexCollection > vertexToken_
tuple result
Definition: mps_fire.py:311
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
const edm::EDGetTokenT< L1TTTrackCollectionType > trackToken_
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
int iEvent
Definition: GenABIO.cc:224
Definition: TkEm.h:19
def move
Definition: eostools.py:511
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
#define M_PI
L1TkEmParticleProducer(const edm::ParameterSet &)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
std::vector< TkPrimaryVertex > TkPrimaryVertexCollection
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static constexpr float ZEcal
std::vector< L1TTTrackType > L1TTTrackCollectionType
float CorrectedEta(float eta, float zv) const
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Log< level::Warning, false > LogWarning