CMS 3D CMS Logo

HLTScoutingEgammaProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HLTrigger/Egamma
4 // Class: HLTScoutingEgammaProducer
5 //
11 //
12 // Original Author: David G. Sheffield (Rutgers)
13 // Created: Mon, 20 Jul 2015
14 //
15 //
16 
18 
19 #include <cstdint>
20 
21 // function to find rechhit associated to detid and return energy
22 float recHitE(const DetId id, const EcalRecHitCollection& recHits) {
23  if (id == DetId(0)) {
24  return 0;
25  } else {
27  if (it != recHits.end())
28  return (*it).energy();
29  }
30  return 0;
31 }
32 
33 float recHitT(const DetId id, const EcalRecHitCollection& recHits) {
34  if (id == DetId(0)) {
35  return 0;
36  } else {
38  if (it != recHits.end())
39  return (*it).time();
40  }
41  return 0;
42 }
43 
44 //
45 // constructors and destructor
46 //
48  : EgammaCandidateCollection_(
49  consumes<reco::RecoEcalCandidateCollection>(iConfig.getParameter<edm::InputTag>("EgammaCandidates"))),
50  EgammaGsfTrackCollection_(
51  consumes<reco::GsfTrackCollection>(iConfig.getParameter<edm::InputTag>("EgammaGsfTracks"))),
52  SigmaIEtaIEtaMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("SigmaIEtaIEtaMap"))),
53  R9Map_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("r9Map"))),
54  HoverEMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("HoverEMap"))),
55  DetaMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("DetaMap"))),
56  DphiMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("DphiMap"))),
57  MissingHitsMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("MissingHitsMap"))),
58  OneOEMinusOneOPMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("OneOEMinusOneOPMap"))),
59  EcalPFClusterIsoMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("EcalPFClusterIsoMap"))),
60  EleGsfTrackIsoMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("EleGsfTrackIsoMap"))),
61  HcalPFClusterIsoMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("HcalPFClusterIsoMap"))),
62  egammaPtCut(iConfig.getParameter<double>("egammaPtCut")),
63  egammaEtaCut(iConfig.getParameter<double>("egammaEtaCut")),
64  egammaHoverECut(iConfig.getParameter<double>("egammaHoverECut")),
65  mantissaPrecision(iConfig.getParameter<int>("mantissaPrecision")),
66  saveRecHitTiming(iConfig.getParameter<bool>("saveRecHitTiming")),
67  rechitMatrixSize(iConfig.getParameter<int>("rechitMatrixSize")), //(2n+1)^2
68  rechitZeroSuppression(iConfig.getParameter<bool>("rechitZeroSuppression")),
69  ecalRechitEB_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ecalRechitEB"))),
70  ecalRechitEE_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ecalRechitEE"))) {
71  //register products
72  produces<Run3ScoutingElectronCollection>();
73  produces<Run3ScoutingPhotonCollection>();
75 }
76 
78 
79 // ------------ method called to produce the data ------------
81  using namespace edm;
82 
83  auto outElectrons = std::make_unique<Run3ScoutingElectronCollection>();
84  auto outPhotons = std::make_unique<Run3ScoutingPhotonCollection>();
85 
86  // Get RecoEcalCandidate
87  Handle<reco::RecoEcalCandidateCollection> EgammaCandidateCollection;
88  if (!iEvent.getByToken(EgammaCandidateCollection_, EgammaCandidateCollection)) {
89  iEvent.put(std::move(outElectrons));
90  iEvent.put(std::move(outPhotons));
91  return;
92  }
93 
94  // Get GsfTrack
95  Handle<reco::GsfTrackCollection> EgammaGsfTrackCollection;
96  if (!iEvent.getByToken(EgammaGsfTrackCollection_, EgammaGsfTrackCollection)) {
97  iEvent.put(std::move(outElectrons));
98  iEvent.put(std::move(outPhotons));
99  return;
100  }
101 
102  // Get SigmaIEtaIEtaMap
104  if (!iEvent.getByToken(SigmaIEtaIEtaMap_, SigmaIEtaIEtaMap)) {
105  iEvent.put(std::move(outElectrons));
106  iEvent.put(std::move(outPhotons));
107  return;
108  }
109 
111  if (!iEvent.getByToken(R9Map_, R9Map)) {
112  iEvent.put(std::move(outElectrons));
113  iEvent.put(std::move(outPhotons));
114  return;
115  }
116 
117  // Get HoverEMap
119  if (!iEvent.getByToken(HoverEMap_, HoverEMap)) {
120  iEvent.put(std::move(outElectrons));
121  iEvent.put(std::move(outPhotons));
122  return;
123  }
124 
125  // Get DetaMap
127  if (!iEvent.getByToken(DetaMap_, DetaMap)) {
128  iEvent.put(std::move(outElectrons));
129  iEvent.put(std::move(outPhotons));
130  return;
131  }
132 
133  // Get DphiMap
135  if (!iEvent.getByToken(DphiMap_, DphiMap)) {
136  iEvent.put(std::move(outElectrons));
137  iEvent.put(std::move(outPhotons));
138  return;
139  }
140 
141  // Get MissingHitsMap
143  if (!iEvent.getByToken(MissingHitsMap_, MissingHitsMap)) {
144  iEvent.put(std::move(outElectrons));
145  iEvent.put(std::move(outPhotons));
146  return;
147  }
148 
149  // Get 1/E - 1/p Map
151  if (!iEvent.getByToken(OneOEMinusOneOPMap_, OneOEMinusOneOPMap)) {
152  iEvent.put(std::move(outElectrons));
153  iEvent.put(std::move(outPhotons));
154  return;
155  }
156 
157  // Get EcalPFClusterIsoMap
159  if (!iEvent.getByToken(EcalPFClusterIsoMap_, EcalPFClusterIsoMap)) {
160  iEvent.put(std::move(outElectrons));
161  iEvent.put(std::move(outPhotons));
162  return;
163  }
164 
165  // Get EleGsfTrackIsoMap
167  if (!iEvent.getByToken(EleGsfTrackIsoMap_, EleGsfTrackIsoMap)) {
168  iEvent.put(std::move(outElectrons));
169  iEvent.put(std::move(outPhotons));
170  return;
171  }
172 
173  // Get HcalPFClusterIsoMap
175  if (!iEvent.getByToken(HcalPFClusterIsoMap_, HcalPFClusterIsoMap)) {
176  iEvent.put(std::move(outElectrons));
177  iEvent.put(std::move(outPhotons));
178  return;
179  }
180 
183  iEvent.getByToken(ecalRechitEB_, rechitsEB);
184  iEvent.getByToken(ecalRechitEE_, rechitsEE);
185 
186  const CaloTopology* topology = &setup.getData(topologyToken_);
187 
188  // Produce electrons and photons
189  int index = 0;
190  for (auto& candidate : *EgammaCandidateCollection) {
191  reco::RecoEcalCandidateRef candidateRef = getRef(EgammaCandidateCollection, index);
192  ++index;
193  if (candidateRef.isNull() && !candidateRef.isAvailable())
194  continue;
195 
196  if (candidate.pt() < egammaPtCut)
197  continue;
198  if (fabs(candidate.eta()) > egammaEtaCut)
199  continue;
200 
201  reco::SuperClusterRef scRef = candidate.superCluster();
202  if (scRef.isNull() && !scRef.isAvailable())
203  continue;
204 
205  reco::CaloClusterPtr SCseed = candidate.superCluster()->seed();
206  const EcalRecHitCollection* rechits = (std::abs(scRef->eta()) < 1.479) ? rechitsEB.product() : rechitsEE.product();
207  Cluster2ndMoments moments = EcalClusterTools::cluster2ndMoments(*SCseed, *rechits);
208  float sMin = moments.sMin;
209  float sMaj = moments.sMaj;
210 
211  uint32_t seedId = (*SCseed).seed();
212 
213  std::vector<DetId> mDetIds = EcalClusterTools::matrixDetId((topology), (*SCseed).seed(), rechitMatrixSize);
214 
215  int detSize = mDetIds.size();
216  std::vector<uint32_t> mDetIdIds;
217  std::vector<float> mEnergies;
218  std::vector<float> mTimes;
219  mDetIdIds.reserve(detSize);
220  mEnergies.reserve(detSize);
221  mTimes.reserve(detSize);
222 
223  for (int i = 0; i < detSize; i++) {
224  auto const recHit_en = recHitE(mDetIds[i], *rechits);
225  if (not rechitZeroSuppression or recHit_en > 0) {
226  mDetIdIds.push_back(mDetIds[i]);
228  if (saveRecHitTiming) {
229  mTimes.push_back(
231  }
232  }
233  }
234 
235  float HoE = 999.;
236  if (candidate.superCluster()->energy() != 0.)
237  HoE = (*HoverEMap)[candidateRef] / candidate.superCluster()->energy();
238 
239  float d0 = 0.0;
240  float dz = 0.0;
241  int charge = -999;
242  for (auto& track : *EgammaGsfTrackCollection) {
243  RefToBase<TrajectorySeed> seed = track.extra()->seedRef();
245  RefToBase<reco::CaloCluster> caloCluster = elseed->caloCluster();
246  reco::SuperClusterRef scRefFromTrk = caloCluster.castTo<reco::SuperClusterRef>();
247  if (scRefFromTrk == scRef) {
248  d0 = track.d0();
249  dz = track.dz();
250  charge = track.charge();
251  }
252  }
253  if (charge == -999) { // No associated track. Candidate is a scouting photon
254  outPhotons->emplace_back(candidate.pt(),
255  candidate.eta(),
256  candidate.phi(),
257  candidate.mass(),
258  (*SigmaIEtaIEtaMap)[candidateRef],
259  HoE,
260  (*EcalPFClusterIsoMap)[candidateRef],
261  (*HcalPFClusterIsoMap)[candidateRef],
262  0.,
263  (*R9Map)[candidateRef],
264  sMin,
265  sMaj,
266  seedId,
267  mEnergies,
268  mDetIdIds,
269  mTimes,
270  rechitZeroSuppression); //read for(ieta){for(iphi){}}
271  } else { // Candidate is a scouting electron
272  outElectrons->emplace_back(candidate.pt(),
273  candidate.eta(),
274  candidate.phi(),
275  candidate.mass(),
276  d0,
277  dz,
278  (*DetaMap)[candidateRef],
279  (*DphiMap)[candidateRef],
280  (*SigmaIEtaIEtaMap)[candidateRef],
281  HoE,
282  (*OneOEMinusOneOPMap)[candidateRef],
283  (*MissingHitsMap)[candidateRef],
284  charge,
285  (*EcalPFClusterIsoMap)[candidateRef],
286  (*HcalPFClusterIsoMap)[candidateRef],
287  (*EleGsfTrackIsoMap)[candidateRef],
288  (*R9Map)[candidateRef],
289  sMin,
290  sMaj,
291  seedId,
292  mEnergies,
293  mDetIdIds,
294  mTimes,
295  rechitZeroSuppression); //read for(ieta){for(iphi){}}
296  }
297  }
298 
299  // Put output
300  iEvent.put(std::move(outElectrons));
301  iEvent.put(std::move(outPhotons));
302 }
303 
304 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
307  desc.add<edm::InputTag>("EgammaCandidates", edm::InputTag("hltEgammaCandidates"));
308  desc.add<edm::InputTag>("EgammaGsfTracks", edm::InputTag("hltEgammaGsfTracks"));
309  desc.add<edm::InputTag>("SigmaIEtaIEtaMap", edm::InputTag("hltEgammaClusterShape:sigmaIEtaIEta5x5"));
310  desc.add<edm::InputTag>("r9Map", edm::InputTag("hltEgammaR9ID:r95x5"));
311  desc.add<edm::InputTag>("HoverEMap", edm::InputTag("hltEgammaHoverE"));
312  desc.add<edm::InputTag>("DetaMap", edm::InputTag("hltEgammaGsfTrackVars:DetaSeed"));
313  desc.add<edm::InputTag>("DphiMap", edm::InputTag("hltEgammaGsfTrackVars:Dphi"));
314  desc.add<edm::InputTag>("MissingHitsMap", edm::InputTag("hltEgammaGsfTrackVars:MissingHits"));
315  desc.add<edm::InputTag>("OneOEMinusOneOPMap", edm::InputTag("hltEgammaGsfTrackVars:OneOESuperMinusOneOP"));
316  desc.add<edm::InputTag>("EcalPFClusterIsoMap", edm::InputTag("hltEgammaEcalPFClusterIso"));
317  desc.add<edm::InputTag>("EleGsfTrackIsoMap", edm::InputTag("hltEgammaEleGsfTrackIso"));
318  desc.add<edm::InputTag>("HcalPFClusterIsoMap", edm::InputTag("hltEgammaHcalPFClusterIso"));
319  desc.add<double>("egammaPtCut", 4.0);
320  desc.add<double>("egammaEtaCut", 2.5);
321  desc.add<double>("egammaHoverECut", 1.0);
322  desc.add<bool>("saveRecHitTiming", false);
323  desc.add<int>("mantissaPrecision", 10)->setComment("default float16, change to 23 for float32");
324  desc.add<int>("rechitMatrixSize", 10);
325  desc.add<bool>("rechitZeroSuppression", true);
326  desc.add<edm::InputTag>("ecalRechitEB", edm::InputTag("hltEcalRecHit:EcalRecHitsEB"));
327  desc.add<edm::InputTag>("ecalRechitEE", edm::InputTag("hltEcalRecHit:EcalRecHitsEE"));
328  descriptions.add("hltScoutingEgammaProducer", desc);
329 }
330 
331 // declare this class as a framework plugin
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
const edm::EDGetTokenT< RecoEcalCandMap > SigmaIEtaIEtaMap_
const edm::EDGetTokenT< EcalRecHitCollection > ecalRechitEE_
edm::ESGetToken< CaloTopology, CaloTopologyRecord > topologyToken_
const edm::EDGetTokenT< RecoEcalCandMap > R9Map_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T const * product() const
Definition: Handle.h:70
std::vector< EcalRecHit >::const_iterator const_iterator
const edm::EDGetTokenT< reco::GsfTrackCollection > EgammaGsfTrackCollection_
const edm::EDGetTokenT< RecoEcalCandMap > EleGsfTrackIsoMap_
const edm::EDGetTokenT< RecoEcalCandMap > HoverEMap_
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > EgammaCandidateCollection_
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< RecoEcalCandMap > DetaMap_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
bool isAvailable() const
Definition: Ref.h:537
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isNull() const
Checks for null.
Definition: Ref.h:235
float recHitT(const DetId id, const EcalRecHitCollection &recHits)
const edm::EDGetTokenT< RecoEcalCandMap > OneOEMinusOneOPMap_
const edm::EDGetTokenT< RecoEcalCandMap > MissingHitsMap_
const edm::EDGetTokenT< RecoEcalCandMap > DphiMap_
Definition: DetId.h:17
static constexpr float d0
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< RecoEcalCandidate > RecoEcalCandidateCollection
collectin of RecoEcalCandidate objects
void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const final
static float reduceMantissaToNbitsRounding(const float &f)
Definition: libminifloat.h:79
fixed size matrix
HLT enums.
const edm::EDGetTokenT< EcalRecHitCollection > ecalRechitEB_
float recHitE(const DetId id, const EcalRecHitCollection &recHits)
~HLTScoutingEgammaProducer() override
const edm::EDGetTokenT< RecoEcalCandMap > HcalPFClusterIsoMap_
def move(src, dest)
Definition: eostools.py:511
const edm::EDGetTokenT< RecoEcalCandMap > EcalPFClusterIsoMap_
HLTScoutingEgammaProducer(const edm::ParameterSet &)