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 
17 
20 
22 
25 
27 
29 
30 // for L1Tracks:
32 
34 
35 #include <string>
36 #include <cmath>
37 
38 static constexpr float EtaECal = 1.479;
39 static constexpr float REcal = 129.;
40 static constexpr float ZEcal = 315.4;
41 using namespace l1t;
42 //
43 // class declaration
44 //
45 
47 public:
49  typedef std::vector<L1TTTrackType> L1TTTrackCollectionType;
50 
52  ~L1TkEmParticleProducer() override;
53 
54  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
55 
56  float CorrectedEta(float eta, float zv) const;
57 
58 private:
59  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
60 
61  // ----------member data ---------------------------
62 
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_;
78 
82 };
83 
84 //
85 // constructors and destructor
86 //
88  : 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 
112  produces<TkEmCollection>(label_);
113 }
114 
116 
117 // ------------ method called to produce the data ------------
119  using namespace edm;
120 
121  auto result = std::make_unique<TkEmCollection>();
122 
123  // the L1EGamma objects
124  edm::Handle<EGammaBxCollection> eGammaHandle;
125  iEvent.getByToken(egToken_, eGammaHandle);
126  EGammaBxCollection eGammaCollection = (*eGammaHandle.product());
128 
129  // the L1Tracks
131  iEvent.getByToken(trackToken_, L1TTTrackHandle);
132 
133  // the primary vertex (used only if primaryVtxConstrain_ = true)
134  float zvtxL1tk = -999;
136  iEvent.getByToken(vertexToken_, L1VertexHandle);
137  bool primaryVtxConstrain = primaryVtxConstrain_;
138  if (!L1VertexHandle.isValid()) {
139  LogWarning("L1TkEmParticleProducer")
140  << "Warning: TkPrimaryVertexCollection not found in the event. Won't use any PrimaryVertex constraint."
141  << std::endl;
142  primaryVtxConstrain = false;
143  } else {
144  std::vector<TkPrimaryVertex>::const_iterator vtxIter = L1VertexHandle->begin();
145  // by convention, the first vertex in the collection is the one that should
146  // be used by default
147  zvtxL1tk = vtxIter->zvertex();
148  }
149 
150  if (!L1TTTrackHandle.isValid()) {
151  LogError("L1TkEmParticleProducer") << "\nWarning: L1TTTrackCollectionType not found in the event. Exit."
152  << std::endl;
153  return;
154  }
155 
156  // Now loop over the L1EGamma objects
157 
158  if (!eGammaHandle.isValid()) {
159  LogError("L1TkEmParticleProducer") << "\nWarning: L1EmCollection not found in the event. Exit." << std::endl;
160  return;
161  }
162 
163  int ieg = 0;
164  for (egIter = eGammaCollection.begin(0); egIter != eGammaCollection.end(0); ++egIter) // considering BX = only
165  {
166  edm::Ref<EGammaBxCollection> EGammaRef(eGammaHandle, ieg);
167  ieg++;
168 
169  float eta = egIter->eta();
170  // The eta of the L1EG object is seen from (0,0,0).
171  // if primaryVtxConstrain_ = true, and for the PV constrained iso, use the zvtxL1tk to correct the eta(L1EG)
172  // that is used in the calculation of DeltaR.
173  float etaPV = CorrectedEta((float)eta, zvtxL1tk);
174 
175  float phi = egIter->phi();
176  float et = egIter->et();
177 
178  if (et < etMin_)
179  continue;
180 
181  // calculate the isolation of the L1EG object with
182  // respect to L1Tracks.
183 
184  float trkisol = -999;
185  float sumPt = 0;
186  float sumPtPV = 0;
187  float trkisolPV = -999;
188 
189  for (const auto& track : *L1TTTrackHandle) {
190  float Pt = track.momentum().perp();
191  float Eta = track.momentum().eta();
192  float Phi = track.momentum().phi();
193  float z = track.POCA().z();
194  if (fabs(z) > zMax_)
195  continue;
196  if (Pt < pTMinTra_)
197  continue;
198  float chi2 = track.chi2();
199  if (chi2 > chi2Max_)
200  continue;
201 
202  float dr = reco::deltaR(Eta, Phi, eta, phi);
203  if (dr < dRMax_ && dr >= dRMin_) {
204  sumPt += Pt;
205  }
206 
207  if (zvtxL1tk > -999 && std::abs(z - zvtxL1tk) >= deltaZMax_)
208  continue; // Now, PV constrained trackSum:
209 
210  dr = reco::deltaR(Eta, Phi, etaPV, phi); // recompute using the corrected eta
211 
212  if (dr < dRMax_ && dr >= dRMin_) {
213  sumPtPV += Pt;
214  }
215  } // end loop over tracks
216 
217  if (relativeIsolation_) {
218  if (et > 0) {
219  trkisol = sumPt / et;
220  trkisolPV = sumPtPV / et;
221  } // relative isolation
222  } else { // absolute isolation
223  trkisol = sumPt;
224  trkisolPV = sumPtPV;
225  }
226 
227  float isolation = trkisol;
228  if (primaryVtxConstrain) {
229  isolation = trkisolPV;
230  }
231 
232  const math::XYZTLorentzVector P4 = egIter->p4();
233  TkEm trkEm(P4, EGammaRef, trkisol, trkisolPV);
234 
235  if (isoCut_ <= 0) {
236  // write the L1TkEm particle to the collection,
237  // irrespective of its relative isolation
238  result->push_back(trkEm);
239  } else {
240  // the object is written to the collection only
241  // if it passes the isolation cut
242  if (isolation <= isoCut_)
243  result->push_back(trkEm);
244  }
245 
246  } // end loop over EGamma objects
247 
248  iEvent.put(std::move(result), label_);
249 }
250 
251 // --------------------------------------------------------------------------------------
252 
253 float L1TkEmParticleProducer::CorrectedEta(float eta, float zv) const {
254  // Correct the eta of the L1EG object once we know the zvertex
255 
256  bool IsBarrel = (std::abs(eta) < EtaECal);
257 
258  float theta = 2. * atan(exp(-eta));
259  if (theta < 0)
260  theta = theta + M_PI;
261  float tantheta = tan(theta);
262 
263  float delta;
264  if (IsBarrel) {
265  delta = REcal / tantheta;
266  } else {
267  if (theta > 0)
268  delta = ZEcal;
269  if (theta < 0)
270  delta = -ZEcal;
271  }
272 
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.));
280  return etaprime;
281 }
282 
283 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
285  //The following says we do not know what parameters are allowed so do no validation
286  // Please change this to state exactly what you do use, even if it is no parameters
288  desc.setUnknown();
289  descriptions.addDefault(desc);
290 }
291 
292 //define this as a plug-in
L1TkEmParticleProducer::L1TTTrackType
TTTrack< Ref_Phase2TrackerDigi_ > L1TTTrackType
Definition: L1TkEmParticleProducer.cc:48
edm::StreamID
Definition: StreamID.h:30
L1TkEmParticleProducer::deltaZMax_
float deltaZMax_
Definition: L1TkEmParticleProducer.cc:74
TkEmFwd.h
Handle.h
L1TkEmParticleProducer::relativeIsolation_
bool relativeIsolation_
Definition: L1TkEmParticleProducer.cc:77
TkPrimaryVertex.h
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
L1TkEmParticleProducer::CorrectedEta
float CorrectedEta(float eta, float zv) const
Definition: L1TkEmParticleProducer.cc:253
edm::Handle::product
T const * product() const
Definition: Handle.h:70
L1TkEmParticleProducer::L1TkEmParticleProducer
L1TkEmParticleProducer(const edm::ParameterSet &)
Definition: L1TkEmParticleProducer.cc:87
L1TkEmParticleProducer::dRMax_
float dRMax_
Definition: L1TkEmParticleProducer.cc:70
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
L1TkEmParticleProducer::etMin_
float etMin_
Definition: L1TkEmParticleProducer.cc:65
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
L1TkEmParticleProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: L1TkEmParticleProducer.cc:284
TTTrack
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:26
L1TkEmParticleProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: L1TkEmParticleProducer.cc:118
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
L1TkEmParticleProducer::zMax_
float zMax_
Definition: L1TkEmParticleProducer.cc:67
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
L1TkEmParticleProducer::chi2Max_
float chi2Max_
Definition: L1TkEmParticleProducer.cc:68
edm::Ref
Definition: AssociativeIterator.h:58
TtFullHadEvtBuilder_cfi.sumPt
sumPt
Definition: TtFullHadEvtBuilder_cfi.py:38
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:38
L1TkEmParticleProducer::L1TTTrackCollectionType
std::vector< L1TTTrackType > L1TTTrackCollectionType
Definition: L1TkEmParticleProducer.cc:49
L1TkEmParticleProducer::pTMinTra_
float pTMinTra_
Definition: L1TkEmParticleProducer.cc:71
l1t::TkPrimaryVertexCollection
std::vector< TkPrimaryVertex > TkPrimaryVertexCollection
Definition: TkPrimaryVertex.h:28
PVValHelper::eta
Definition: PVValidationHelpers.h:69
L1TkEmParticleProducer::primaryVtxConstrain_
bool primaryVtxConstrain_
Definition: L1TkEmParticleProducer.cc:72
l1t::EGammaRef
edm::Ref< EGammaBxCollection > EGammaRef
Definition: TkEGTau.h:35
L1TkEmParticleProducer::dRMin_
float dRMin_
Definition: L1TkEmParticleProducer.cc:69
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
DDAxes::z
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
VtxSmearedParameters_cfi.Phi
Phi
Definition: VtxSmearedParameters_cfi.py:112
BXVector::begin
const_iterator begin(int bx) const
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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
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
L1TkEmParticleProducer::label_
std::string label_
Definition: L1TkEmParticleProducer.cc:63
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
L1TkEmParticleProducer::isoCut_
float isoCut_
Definition: L1TkEmParticleProducer.cc:76
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
TkEm.h
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
REcal
static constexpr float REcal
Definition: L1TkEmParticleProducer.cc:39
edm::EventSetup
Definition: EventSetup.h:57
L1TkEmParticleProducer::~L1TkEmParticleProducer
~L1TkEmParticleProducer() override
Definition: L1TkEmParticleProducer.cc:115
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
L1TkEmParticleProducer::vertexToken_
const edm::EDGetTokenT< TkPrimaryVertexCollection > vertexToken_
Definition: L1TkEmParticleProducer.cc:81
L1TkEmParticleProducer
Definition: L1TkEmParticleProducer.cc:46
InputTag.h
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
flavorHistoryFilter_cfi.dr
dr
Definition: flavorHistoryFilter_cfi.py:37
EventSetup.h
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
mps_fire.result
result
Definition: mps_fire.py:311
L1TkEmParticleProducer::trackToken_
const edm::EDGetTokenT< std::vector< TTTrack< Ref_Phase2TrackerDigi_ > > > trackToken_
Definition: L1TkEmParticleProducer.cc:80
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1TkEmParticleProducer::egToken_
const edm::EDGetTokenT< EGammaBxCollection > egToken_
Definition: L1TkEmParticleProducer.cc:79
ParameterSet.h
EDProducer.h
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
ZEcal
static constexpr float ZEcal
Definition: L1TkEmParticleProducer.cc:40
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
isolation
double isolation
Definition: AssociatedVariableMaxCutCandRefSelector.cc:25