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 // function to find rechhit associated to detid and return energy
20 float recHitE(const DetId id, const EcalRecHitCollection& recHits) {
21  if (id == DetId(0)) {
22  return 0;
23  } else {
25  if (it != recHits.end())
26  return (*it).energy();
27  }
28  return 0;
29 }
30 
31 float recHitT(const DetId id, const EcalRecHitCollection& recHits) {
32  if (id == DetId(0)) {
33  return 0;
34  } else {
36  if (it != recHits.end())
37  return (*it).time();
38  }
39  return 0;
40 }
41 
42 //
43 // constructors and destructor
44 //
46  : EgammaCandidateCollection_(
47  consumes<reco::RecoEcalCandidateCollection>(iConfig.getParameter<edm::InputTag>("EgammaCandidates"))),
48  EgammaGsfTrackCollection_(
49  consumes<reco::GsfTrackCollection>(iConfig.getParameter<edm::InputTag>("EgammaGsfTracks"))),
50  SigmaIEtaIEtaMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("SigmaIEtaIEtaMap"))),
51  R9Map_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("r9Map"))),
52  HoverEMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("HoverEMap"))),
53  DetaMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("DetaMap"))),
54  DphiMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("DphiMap"))),
55  MissingHitsMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("MissingHitsMap"))),
56  OneOEMinusOneOPMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("OneOEMinusOneOPMap"))),
57  EcalPFClusterIsoMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("EcalPFClusterIsoMap"))),
58  EleGsfTrackIsoMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("EleGsfTrackIsoMap"))),
59  HcalPFClusterIsoMap_(consumes<RecoEcalCandMap>(iConfig.getParameter<edm::InputTag>("HcalPFClusterIsoMap"))),
60  egammaPtCut(iConfig.getParameter<double>("egammaPtCut")),
61  egammaEtaCut(iConfig.getParameter<double>("egammaEtaCut")),
62  egammaHoverECut(iConfig.getParameter<double>("egammaHoverECut")),
63  mantissaPrecision(iConfig.getParameter<int>("mantissaPrecision")),
64  saveRecHitTiming(iConfig.getParameter<bool>("saveRecHitTiming")),
65  rechitMatrixSize(iConfig.getParameter<int>("rechitMatrixSize")), //(2n+1)^2
66  ecalRechitEB_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ecalRechitEB"))),
67  ecalRechitEE_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("ecalRechitEE"))) {
68  //register products
69  produces<Run3ScoutingElectronCollection>();
70  produces<Run3ScoutingPhotonCollection>();
71 }
72 
74 
75 // ------------ method called to produce the data ------------
77  using namespace edm;
78 
79  auto outElectrons = std::make_unique<Run3ScoutingElectronCollection>();
80  auto outPhotons = std::make_unique<Run3ScoutingPhotonCollection>();
81 
82  // Get RecoEcalCandidate
83  Handle<reco::RecoEcalCandidateCollection> EgammaCandidateCollection;
84  if (!iEvent.getByToken(EgammaCandidateCollection_, EgammaCandidateCollection)) {
85  iEvent.put(std::move(outElectrons));
86  iEvent.put(std::move(outPhotons));
87  return;
88  }
89 
90  // Get GsfTrack
91  Handle<reco::GsfTrackCollection> EgammaGsfTrackCollection;
92  if (!iEvent.getByToken(EgammaGsfTrackCollection_, EgammaGsfTrackCollection)) {
93  iEvent.put(std::move(outElectrons));
94  iEvent.put(std::move(outPhotons));
95  return;
96  }
97 
98  // Get SigmaIEtaIEtaMap
100  if (!iEvent.getByToken(SigmaIEtaIEtaMap_, SigmaIEtaIEtaMap)) {
101  iEvent.put(std::move(outElectrons));
102  iEvent.put(std::move(outPhotons));
103  return;
104  }
105 
107  if (!iEvent.getByToken(R9Map_, R9Map)) {
108  iEvent.put(std::move(outElectrons));
109  iEvent.put(std::move(outPhotons));
110  return;
111  }
112 
113  // Get HoverEMap
115  if (!iEvent.getByToken(HoverEMap_, HoverEMap)) {
116  iEvent.put(std::move(outElectrons));
117  iEvent.put(std::move(outPhotons));
118  return;
119  }
120 
121  // Get DetaMap
123  if (!iEvent.getByToken(DetaMap_, DetaMap)) {
124  iEvent.put(std::move(outElectrons));
125  iEvent.put(std::move(outPhotons));
126  return;
127  }
128 
129  // Get DphiMap
131  if (!iEvent.getByToken(DphiMap_, DphiMap)) {
132  iEvent.put(std::move(outElectrons));
133  iEvent.put(std::move(outPhotons));
134  return;
135  }
136 
137  // Get MissingHitsMap
139  if (!iEvent.getByToken(MissingHitsMap_, MissingHitsMap)) {
140  iEvent.put(std::move(outElectrons));
141  iEvent.put(std::move(outPhotons));
142  return;
143  }
144 
145  // Get 1/E - 1/p Map
147  if (!iEvent.getByToken(OneOEMinusOneOPMap_, OneOEMinusOneOPMap)) {
148  iEvent.put(std::move(outElectrons));
149  iEvent.put(std::move(outPhotons));
150  return;
151  }
152 
153  // Get EcalPFClusterIsoMap
155  if (!iEvent.getByToken(EcalPFClusterIsoMap_, EcalPFClusterIsoMap)) {
156  iEvent.put(std::move(outElectrons));
157  iEvent.put(std::move(outPhotons));
158  return;
159  }
160 
161  // Get EleGsfTrackIsoMap
163  if (!iEvent.getByToken(EleGsfTrackIsoMap_, EleGsfTrackIsoMap)) {
164  iEvent.put(std::move(outElectrons));
165  iEvent.put(std::move(outPhotons));
166  return;
167  }
168 
169  // Get HcalPFClusterIsoMap
171  if (!iEvent.getByToken(HcalPFClusterIsoMap_, HcalPFClusterIsoMap)) {
172  iEvent.put(std::move(outElectrons));
173  iEvent.put(std::move(outPhotons));
174  return;
175  }
176 
179  iEvent.getByToken(ecalRechitEB_, rechitsEB);
180  iEvent.getByToken(ecalRechitEE_, rechitsEE);
181 
182  edm::ESHandle<CaloTopology> pTopology;
183  setup.get<CaloTopologyRecord>().get(pTopology);
184  const CaloTopology* topology = pTopology.product();
185 
186  // Produce electrons and photons
187  int index = 0;
188  for (auto& candidate : *EgammaCandidateCollection) {
189  reco::RecoEcalCandidateRef candidateRef = getRef(EgammaCandidateCollection, index);
190  ++index;
191  if (candidateRef.isNull() && !candidateRef.isAvailable())
192  continue;
193 
194  if (candidate.pt() < egammaPtCut)
195  continue;
196  if (fabs(candidate.eta()) > egammaEtaCut)
197  continue;
198 
199  reco::SuperClusterRef scRef = candidate.superCluster();
200  if (scRef.isNull() && !scRef.isAvailable())
201  continue;
202 
203  reco::CaloClusterPtr SCseed = candidate.superCluster()->seed();
204  const EcalRecHitCollection* rechits = (std::abs(scRef->eta()) < 1.479) ? rechitsEB.product() : rechitsEE.product();
205  Cluster2ndMoments moments = EcalClusterTools::cluster2ndMoments(*SCseed, *rechits);
206  float sMin = moments.sMin;
207  float sMaj = moments.sMaj;
208 
209  unsigned int seedId = (*SCseed).seed();
210 
211  std::vector<DetId> mDetIds = EcalClusterTools::matrixDetId((topology), (*SCseed).seed(), rechitMatrixSize);
212 
213  int detSize = mDetIds.size();
214  std::vector<float> mEnergies(detSize, 0.);
215  std::vector<float> mTimes(detSize, 0.);
216 
217  for (int i = 0; i < detSize; i++) {
218  mEnergies[i] =
220  if (saveRecHitTiming)
221  mTimes[i] =
223  }
224 
225  float HoE = 999.;
226  if (candidate.superCluster()->energy() != 0.)
227  HoE = (*HoverEMap)[candidateRef] / candidate.superCluster()->energy();
228 
229  float d0 = 0.0;
230  float dz = 0.0;
231  int charge = -999;
232  for (auto& track : *EgammaGsfTrackCollection) {
233  RefToBase<TrajectorySeed> seed = track.extra()->seedRef();
235  RefToBase<reco::CaloCluster> caloCluster = elseed->caloCluster();
236  reco::SuperClusterRef scRefFromTrk = caloCluster.castTo<reco::SuperClusterRef>();
237  if (scRefFromTrk == scRef) {
238  d0 = track.d0();
239  dz = track.dz();
240  charge = track.charge();
241  }
242  }
243  if (charge == -999) { // No associated track. Candidate is a scouting photon
244  outPhotons->emplace_back(candidate.pt(),
245  candidate.eta(),
246  candidate.phi(),
247  candidate.mass(),
248  (*SigmaIEtaIEtaMap)[candidateRef],
249  HoE,
250  (*EcalPFClusterIsoMap)[candidateRef],
251  (*HcalPFClusterIsoMap)[candidateRef],
252  0.,
253  (*R9Map)[candidateRef],
254  sMin,
255  sMaj,
256  seedId,
257  mEnergies,
258  mTimes); //read for(ieta){for(iphi){}}
259  } else { // Candidate is a scouting electron
260  outElectrons->emplace_back(candidate.pt(),
261  candidate.eta(),
262  candidate.phi(),
263  candidate.mass(),
264  d0,
265  dz,
266  (*DetaMap)[candidateRef],
267  (*DphiMap)[candidateRef],
268  (*SigmaIEtaIEtaMap)[candidateRef],
269  HoE,
270  (*OneOEMinusOneOPMap)[candidateRef],
271  (*MissingHitsMap)[candidateRef],
272  charge,
273  (*EcalPFClusterIsoMap)[candidateRef],
274  (*HcalPFClusterIsoMap)[candidateRef],
275  (*EleGsfTrackIsoMap)[candidateRef],
276  (*R9Map)[candidateRef],
277  sMin,
278  sMaj,
279  seedId,
280  mEnergies,
281  mTimes); //read for(ieta){for(iphi){}}
282  }
283  }
284 
285  // Put output
286  iEvent.put(std::move(outElectrons));
287  iEvent.put(std::move(outPhotons));
288 }
289 
290 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
293  desc.add<edm::InputTag>("EgammaCandidates", edm::InputTag("hltEgammaCandidates"));
294  desc.add<edm::InputTag>("EgammaGsfTracks", edm::InputTag("hltEgammaGsfTracks"));
295  desc.add<edm::InputTag>("SigmaIEtaIEtaMap", edm::InputTag("hltEgammaClusterShape:sigmaIEtaIEta5x5"));
296  desc.add<edm::InputTag>("r9Map", edm::InputTag("hltEgammaR9ID:r95x5"));
297  desc.add<edm::InputTag>("HoverEMap", edm::InputTag("hltEgammaHoverE"));
298  desc.add<edm::InputTag>("DetaMap", edm::InputTag("hltEgammaGsfTrackVars:DetaSeed"));
299  desc.add<edm::InputTag>("DphiMap", edm::InputTag("hltEgammaGsfTrackVars:Dphi"));
300  desc.add<edm::InputTag>("MissingHitsMap", edm::InputTag("hltEgammaGsfTrackVars:MissingHits"));
301  desc.add<edm::InputTag>("OneOEMinusOneOPMap", edm::InputTag("hltEgammaGsfTrackVars:OneOESuperMinusOneOP"));
302  desc.add<edm::InputTag>("EcalPFClusterIsoMap", edm::InputTag("hltEgammaEcalPFClusterIso"));
303  desc.add<edm::InputTag>("EleGsfTrackIsoMap", edm::InputTag("hltEgammaEleGsfTrackIso"));
304  desc.add<edm::InputTag>("HcalPFClusterIsoMap", edm::InputTag("hltEgammaHcalPFClusterIso"));
305  desc.add<double>("egammaPtCut", 4.0);
306  desc.add<double>("egammaEtaCut", 2.5);
307  desc.add<double>("egammaHoverECut", 1.0);
308  desc.add<bool>("saveRecHitTiming", false);
309  desc.add<int>("mantissaPrecision", 10)->setComment("default float16, change to 23 for float32");
310  desc.add<int>("rechitMatrixSize", 10);
311  desc.add<edm::InputTag>("ecalRechitEB", edm::InputTag("hltEcalRecHit:EcalRecHitsEB"));
312  desc.add<edm::InputTag>("ecalRechitEE", edm::InputTag("hltEcalRecHit:EcalRecHitsEE"));
313  descriptions.add("hltScoutingEgammaProducer", desc);
314 }
315 
316 // declare this class as a framework plugin
HLTScoutingEgammaProducer::ecalRechitEB_
const edm::EDGetTokenT< EcalRecHitCollection > ecalRechitEB_
Definition: HLTScoutingEgammaProducer.h:89
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
edm::StreamID
Definition: StreamID.h:30
reco::RecoEcalCandidateCollection
std::vector< RecoEcalCandidate > RecoEcalCandidateCollection
collectin of RecoEcalCandidate objects
Definition: RecoEcalCandidateFwd.h:9
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
HLT_2018_cff.DetaMap
DetaMap
Definition: HLT_2018_cff.py:88481
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
HLT_2018_cff.MissingHitsMap
MissingHitsMap
Definition: HLT_2018_cff.py:88477
edm::Handle::product
T const * product() const
Definition: Handle.h:70
HLTScoutingEgammaProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HLTScoutingEgammaProducer.cc:291
HLT_2018_cff.HcalPFClusterIsoMap
HcalPFClusterIsoMap
Definition: HLT_2018_cff.py:88460
HLTScoutingEgammaProducer::HcalPFClusterIsoMap_
const edm::EDGetTokenT< RecoEcalCandMap > HcalPFClusterIsoMap_
Definition: HLTScoutingEgammaProducer.h:78
edm::Ref::isAvailable
bool isAvailable() const
Definition: Ref.h:537
HLTScoutingEgammaProducer::OneOEMinusOneOPMap_
const edm::EDGetTokenT< RecoEcalCandMap > OneOEMinusOneOPMap_
Definition: HLTScoutingEgammaProducer.h:75
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm
HLT enums.
Definition: AlignableModifier.h:19
HLTScoutingEgammaProducer.h
HLT_2018_cff.egammaPtCut
egammaPtCut
Definition: HLT_2018_cff.py:88474
HLTScoutingEgammaProducer::DetaMap_
const edm::EDGetTokenT< RecoEcalCandMap > DetaMap_
Definition: HLTScoutingEgammaProducer.h:72
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HLT_2018_cff.EleGsfTrackIsoMap
EleGsfTrackIsoMap
Definition: HLT_2018_cff.py:88483
edm::SortedCollection< EcalRecHit >
HLT_2018_cff.OneOEMinusOneOPMap
OneOEMinusOneOPMap
Definition: HLT_2018_cff.py:88480
HLTScoutingEgammaProducer::produce
void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const final
Definition: HLTScoutingEgammaProducer.cc:76
HLTScoutingEgammaProducer::HoverEMap_
const edm::EDGetTokenT< RecoEcalCandMap > HoverEMap_
Definition: HLTScoutingEgammaProducer.h:71
CaloTopologyRecord
Definition: CaloTopologyRecord.h:10
HLT_2018_cff.mantissaPrecision
mantissaPrecision
Definition: HLT_2018_cff.py:88452
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
CaloTopology
Definition: CaloTopology.h:19
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
edm::Ref
Definition: AssociativeIterator.h:58
HLTScoutingEgammaProducer::egammaPtCut
const double egammaPtCut
Definition: HLTScoutingEgammaProducer.h:82
DetId
Definition: DetId.h:17
MakerMacros.h
HLTScoutingEgammaProducer::saveRecHitTiming
const bool saveRecHitTiming
Definition: HLTScoutingEgammaProducer.h:86
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
ecaldqm::topology
const CaloTopology * topology(nullptr)
HLT_2018_cff.EcalPFClusterIsoMap
EcalPFClusterIsoMap
Definition: HLT_2018_cff.py:88461
edm::ESHandle< CaloTopology >
recHitT
float recHitT(const DetId id, const EcalRecHitCollection &recHits)
Definition: HLTScoutingEgammaProducer.cc:31
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
HLT_2018_cff.SigmaIEtaIEtaMap
SigmaIEtaIEtaMap
Definition: HLT_2018_cff.py:88476
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
MiniFloatConverter::reduceMantissaToNbitsRounding
static float reduceMantissaToNbitsRounding(const float &f)
Definition: libminifloat.h:102
edm::ParameterSet
Definition: ParameterSet.h:36
Cluster2ndMoments::sMaj
float sMaj
Definition: EcalClusterTools.h:65
edm::getRef
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
edm::AssociationMap
Definition: AssociationMap.h:48
HLTScoutingEgammaProducer::DphiMap_
const edm::EDGetTokenT< RecoEcalCandMap > DphiMap_
Definition: HLTScoutingEgammaProducer.h:73
TrackInfoProducer_cfi.rechits
rechits
Definition: TrackInfoProducer_cfi.py:9
HLTScoutingEgammaProducer::SigmaIEtaIEtaMap_
const edm::EDGetTokenT< RecoEcalCandMap > SigmaIEtaIEtaMap_
Definition: HLTScoutingEgammaProducer.h:69
HLTScoutingEgammaProducer::ecalRechitEE_
const edm::EDGetTokenT< EcalRecHitCollection > ecalRechitEE_
Definition: HLTScoutingEgammaProducer.h:90
HLTScoutingEgammaProducer::EleGsfTrackIsoMap_
const edm::EDGetTokenT< RecoEcalCandMap > EleGsfTrackIsoMap_
Definition: HLTScoutingEgammaProducer.h:77
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
HLTScoutingEgammaProducer::EcalPFClusterIsoMap_
const edm::EDGetTokenT< RecoEcalCandMap > EcalPFClusterIsoMap_
Definition: HLTScoutingEgammaProducer.h:76
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
HLTScoutingEgammaProducer::HLTScoutingEgammaProducer
HLTScoutingEgammaProducer(const edm::ParameterSet &)
Definition: HLTScoutingEgammaProducer.cc:45
HLTScoutingEgammaProducer
Definition: HLTScoutingEgammaProducer.h:54
edm::Ptr< CaloCluster >
HLT_2018_cff.egammaHoverECut
egammaHoverECut
Definition: HLT_2018_cff.py:88482
HLTScoutingEgammaProducer::EgammaGsfTrackCollection_
const edm::EDGetTokenT< reco::GsfTrackCollection > EgammaGsfTrackCollection_
Definition: HLTScoutingEgammaProducer.h:68
reco::GsfTrackCollection
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
eostools.move
def move(src, dest)
Definition: eostools.py:511
HLTScoutingEgammaProducer::~HLTScoutingEgammaProducer
~HLTScoutingEgammaProducer() override
PVValHelper::dz
Definition: PVValidationHelpers.h:50
HLTScoutingEgammaProducer::MissingHitsMap_
const edm::EDGetTokenT< RecoEcalCandMap > MissingHitsMap_
Definition: HLTScoutingEgammaProducer.h:74
HLTScoutingEgammaProducer::EgammaCandidateCollection_
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > EgammaCandidateCollection_
Definition: HLTScoutingEgammaProducer.h:67
HLT_2018_cff.egammaEtaCut
egammaEtaCut
Definition: HLT_2018_cff.py:88471
recHitE
float recHitE(const DetId id, const EcalRecHitCollection &recHits)
Definition: HLTScoutingEgammaProducer.cc:20
edm::RefToBase< TrajectorySeed >
HLTScoutingEgammaProducer::egammaEtaCut
const double egammaEtaCut
Definition: HLTScoutingEgammaProducer.h:83
Cluster2ndMoments::sMin
float sMin
Definition: EcalClusterTools.h:66
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
HLT_2018_cff.DphiMap
DphiMap
Definition: HLT_2018_cff.py:88484
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HLT_2018_cff.HoverEMap
HoverEMap
Definition: HLT_2018_cff.py:88478
edm::Event
Definition: Event.h:73
HLTScoutingEgammaProducer::rechitMatrixSize
const int rechitMatrixSize
Definition: HLTScoutingEgammaProducer.h:87
d0
static constexpr float d0
Definition: L1EGammaCrystalsEmulatorProducer.cc:85
Cluster2ndMoments
Definition: EcalClusterTools.h:63
edm::InputTag
Definition: InputTag.h:15
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
HLTScoutingEgammaProducer::R9Map_
const edm::EDGetTokenT< RecoEcalCandMap > R9Map_
Definition: HLTScoutingEgammaProducer.h:70
HLTScoutingEgammaProducer::mantissaPrecision
const int mantissaPrecision
Definition: HLTScoutingEgammaProducer.h:85