CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  ecalRechitEB_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ecalRechitEB"))),
69  ecalRechitEE_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ecalRechitEE"))) {
70  //register products
71  produces<Run3ScoutingElectronCollection>();
72  produces<Run3ScoutingPhotonCollection>();
74 }
75 
77 
78 // ------------ method called to produce the data ------------
80  using namespace edm;
81 
82  auto outElectrons = std::make_unique<Run3ScoutingElectronCollection>();
83  auto outPhotons = std::make_unique<Run3ScoutingPhotonCollection>();
84 
85  // Get RecoEcalCandidate
86  Handle<reco::RecoEcalCandidateCollection> EgammaCandidateCollection;
87  if (!iEvent.getByToken(EgammaCandidateCollection_, EgammaCandidateCollection)) {
88  iEvent.put(std::move(outElectrons));
89  iEvent.put(std::move(outPhotons));
90  return;
91  }
92 
93  // Get GsfTrack
94  Handle<reco::GsfTrackCollection> EgammaGsfTrackCollection;
95  if (!iEvent.getByToken(EgammaGsfTrackCollection_, EgammaGsfTrackCollection)) {
96  iEvent.put(std::move(outElectrons));
97  iEvent.put(std::move(outPhotons));
98  return;
99  }
100 
101  // Get SigmaIEtaIEtaMap
104  iEvent.put(std::move(outElectrons));
105  iEvent.put(std::move(outPhotons));
106  return;
107  }
108 
110  if (!iEvent.getByToken(R9Map_, R9Map)) {
111  iEvent.put(std::move(outElectrons));
112  iEvent.put(std::move(outPhotons));
113  return;
114  }
115 
116  // Get HoverEMap
118  if (!iEvent.getByToken(HoverEMap_, HoverEMap)) {
119  iEvent.put(std::move(outElectrons));
120  iEvent.put(std::move(outPhotons));
121  return;
122  }
123 
124  // Get DetaMap
126  if (!iEvent.getByToken(DetaMap_, DetaMap)) {
127  iEvent.put(std::move(outElectrons));
128  iEvent.put(std::move(outPhotons));
129  return;
130  }
131 
132  // Get DphiMap
134  if (!iEvent.getByToken(DphiMap_, DphiMap)) {
135  iEvent.put(std::move(outElectrons));
136  iEvent.put(std::move(outPhotons));
137  return;
138  }
139 
140  // Get MissingHitsMap
142  if (!iEvent.getByToken(MissingHitsMap_, MissingHitsMap)) {
143  iEvent.put(std::move(outElectrons));
144  iEvent.put(std::move(outPhotons));
145  return;
146  }
147 
148  // Get 1/E - 1/p Map
151  iEvent.put(std::move(outElectrons));
152  iEvent.put(std::move(outPhotons));
153  return;
154  }
155 
156  // Get EcalPFClusterIsoMap
159  iEvent.put(std::move(outElectrons));
160  iEvent.put(std::move(outPhotons));
161  return;
162  }
163 
164  // Get EleGsfTrackIsoMap
167  iEvent.put(std::move(outElectrons));
168  iEvent.put(std::move(outPhotons));
169  return;
170  }
171 
172  // Get HcalPFClusterIsoMap
175  iEvent.put(std::move(outElectrons));
176  iEvent.put(std::move(outPhotons));
177  return;
178  }
179 
182  iEvent.getByToken(ecalRechitEB_, rechitsEB);
183  iEvent.getByToken(ecalRechitEE_, rechitsEE);
184 
185  const CaloTopology* topology = &setup.getData(topologyToken_);
186 
187  // Produce electrons and photons
188  int index = 0;
189  for (auto& candidate : *EgammaCandidateCollection) {
190  reco::RecoEcalCandidateRef candidateRef = getRef(EgammaCandidateCollection, index);
191  ++index;
192  if (candidateRef.isNull() && !candidateRef.isAvailable())
193  continue;
194 
195  if (candidate.pt() < egammaPtCut)
196  continue;
197  if (fabs(candidate.eta()) > egammaEtaCut)
198  continue;
199 
200  reco::SuperClusterRef scRef = candidate.superCluster();
201  if (scRef.isNull() && !scRef.isAvailable())
202  continue;
203 
204  reco::CaloClusterPtr SCseed = candidate.superCluster()->seed();
205  const EcalRecHitCollection* rechits = (std::abs(scRef->eta()) < 1.479) ? rechitsEB.product() : rechitsEE.product();
206  Cluster2ndMoments moments = EcalClusterTools::cluster2ndMoments(*SCseed, *rechits);
207  float sMin = moments.sMin;
208  float sMaj = moments.sMaj;
209 
210  uint32_t seedId = (*SCseed).seed();
211 
212  std::vector<DetId> mDetIds = EcalClusterTools::matrixDetId((topology), (*SCseed).seed(), rechitMatrixSize);
213 
214  int detSize = mDetIds.size();
215  std::vector<uint32_t> mDetIdIds(detSize, 0);
216  std::vector<float> mEnergies(detSize, 0.);
217  std::vector<float> mTimes(detSize, 0.);
218 
219  for (int i = 0; i < detSize; i++) {
220  mDetIdIds[i] = mDetIds[i];
221  mEnergies[i] =
223  if (saveRecHitTiming)
225  }
226 
227  float HoE = 999.;
228  if (candidate.superCluster()->energy() != 0.)
229  HoE = (*HoverEMap)[candidateRef] / candidate.superCluster()->energy();
230 
231  float d0 = 0.0;
232  float dz = 0.0;
233  int charge = -999;
234  for (auto& track : *EgammaGsfTrackCollection) {
235  RefToBase<TrajectorySeed> seed = track.extra()->seedRef();
237  RefToBase<reco::CaloCluster> caloCluster = elseed->caloCluster();
238  reco::SuperClusterRef scRefFromTrk = caloCluster.castTo<reco::SuperClusterRef>();
239  if (scRefFromTrk == scRef) {
240  d0 = track.d0();
241  dz = track.dz();
242  charge = track.charge();
243  }
244  }
245  if (charge == -999) { // No associated track. Candidate is a scouting photon
246  outPhotons->emplace_back(candidate.pt(),
247  candidate.eta(),
248  candidate.phi(),
249  candidate.mass(),
250  (*SigmaIEtaIEtaMap)[candidateRef],
251  HoE,
252  (*EcalPFClusterIsoMap)[candidateRef],
253  (*HcalPFClusterIsoMap)[candidateRef],
254  0.,
255  (*R9Map)[candidateRef],
256  sMin,
257  sMaj,
258  seedId,
259  mEnergies,
260  mDetIdIds,
261  mTimes); //read for(ieta){for(iphi){}}
262  } else { // Candidate is a scouting electron
263  outElectrons->emplace_back(candidate.pt(),
264  candidate.eta(),
265  candidate.phi(),
266  candidate.mass(),
267  d0,
268  dz,
269  (*DetaMap)[candidateRef],
270  (*DphiMap)[candidateRef],
271  (*SigmaIEtaIEtaMap)[candidateRef],
272  HoE,
273  (*OneOEMinusOneOPMap)[candidateRef],
274  (*MissingHitsMap)[candidateRef],
275  charge,
276  (*EcalPFClusterIsoMap)[candidateRef],
277  (*HcalPFClusterIsoMap)[candidateRef],
278  (*EleGsfTrackIsoMap)[candidateRef],
279  (*R9Map)[candidateRef],
280  sMin,
281  sMaj,
282  seedId,
283  mEnergies,
284  mDetIdIds,
285  mTimes); //read for(ieta){for(iphi){}}
286  }
287  }
288 
289  // Put output
290  iEvent.put(std::move(outElectrons));
291  iEvent.put(std::move(outPhotons));
292 }
293 
294 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
297  desc.add<edm::InputTag>("EgammaCandidates", edm::InputTag("hltEgammaCandidates"));
298  desc.add<edm::InputTag>("EgammaGsfTracks", edm::InputTag("hltEgammaGsfTracks"));
299  desc.add<edm::InputTag>("SigmaIEtaIEtaMap", edm::InputTag("hltEgammaClusterShape:sigmaIEtaIEta5x5"));
300  desc.add<edm::InputTag>("r9Map", edm::InputTag("hltEgammaR9ID:r95x5"));
301  desc.add<edm::InputTag>("HoverEMap", edm::InputTag("hltEgammaHoverE"));
302  desc.add<edm::InputTag>("DetaMap", edm::InputTag("hltEgammaGsfTrackVars:DetaSeed"));
303  desc.add<edm::InputTag>("DphiMap", edm::InputTag("hltEgammaGsfTrackVars:Dphi"));
304  desc.add<edm::InputTag>("MissingHitsMap", edm::InputTag("hltEgammaGsfTrackVars:MissingHits"));
305  desc.add<edm::InputTag>("OneOEMinusOneOPMap", edm::InputTag("hltEgammaGsfTrackVars:OneOESuperMinusOneOP"));
306  desc.add<edm::InputTag>("EcalPFClusterIsoMap", edm::InputTag("hltEgammaEcalPFClusterIso"));
307  desc.add<edm::InputTag>("EleGsfTrackIsoMap", edm::InputTag("hltEgammaEleGsfTrackIso"));
308  desc.add<edm::InputTag>("HcalPFClusterIsoMap", edm::InputTag("hltEgammaHcalPFClusterIso"));
309  desc.add<double>("egammaPtCut", 4.0);
310  desc.add<double>("egammaEtaCut", 2.5);
311  desc.add<double>("egammaHoverECut", 1.0);
312  desc.add<bool>("saveRecHitTiming", false);
313  desc.add<int>("mantissaPrecision", 10)->setComment("default float16, change to 23 for float32");
314  desc.add<int>("rechitMatrixSize", 10);
315  desc.add<edm::InputTag>("ecalRechitEB", edm::InputTag("hltEcalRecHit:EcalRecHitsEB"));
316  desc.add<edm::InputTag>("ecalRechitEE", edm::InputTag("hltEcalRecHit:EcalRecHitsEE"));
317  descriptions.add("hltScoutingEgammaProducer", desc);
318 }
319 
320 // declare this class as a framework plugin
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
bool isAvailable() const
Definition: Ref.h:537
const edm::EDGetTokenT< RecoEcalCandMap > SigmaIEtaIEtaMap_
const edm::EDGetTokenT< EcalRecHitCollection > ecalRechitEE_
edm::ESGetToken< CaloTopology, CaloTopologyRecord > topologyToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
tuple mantissaPrecision
const edm::EDGetTokenT< RecoEcalCandMap > R9Map_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< EcalRecHit >::const_iterator const_iterator
const edm::EDGetTokenT< reco::GsfTrackCollection > EgammaGsfTrackCollection_
const edm::EDGetTokenT< RecoEcalCandMap > EleGsfTrackIsoMap_
tuple saveRecHitTiming
const edm::EDGetTokenT< RecoEcalCandMap > HoverEMap_
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > EgammaCandidateCollection_
tuple MissingHitsMap
bool getData(T &iHolder) const
Definition: EventSetup.h:122
tuple EcalPFClusterIsoMap
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< RecoEcalCandMap > DetaMap_
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
tuple rechitMatrixSize
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isNull() const
Checks for null.
Definition: Ref.h:235
float recHitT(const DetId id, const EcalRecHitCollection &recHits)
tuple EleGsfTrackIsoMap
const edm::EDGetTokenT< RecoEcalCandMap > OneOEMinusOneOPMap_
const edm::EDGetTokenT< RecoEcalCandMap > MissingHitsMap_
const edm::EDGetTokenT< RecoEcalCandMap > DphiMap_
const_iterator end() const
Definition: DetId.h:17
tuple SigmaIEtaIEtaMap
static constexpr float d0
REF castTo() const
Definition: RefToBase.h:257
void add(std::string const &label, ParameterSetDescription const &psetDescription)
tuple HcalPFClusterIsoMap
tuple OneOEMinusOneOPMap
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
iterator find(key_type k)
tuple egammaHoverECut
const edm::EDGetTokenT< EcalRecHitCollection > ecalRechitEB_
float recHitE(const DetId id, const EcalRecHitCollection &recHits)
~HLTScoutingEgammaProducer() override
const edm::EDGetTokenT< RecoEcalCandMap > HcalPFClusterIsoMap_
const edm::EDGetTokenT< RecoEcalCandMap > EcalPFClusterIsoMap_
HLTScoutingEgammaProducer(const edm::ParameterSet &)