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 // 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>();
72 }
73 
75 
76 // ------------ method called to produce the data ------------
78  using namespace edm;
79 
80  auto outElectrons = std::make_unique<Run3ScoutingElectronCollection>();
81  auto outPhotons = std::make_unique<Run3ScoutingPhotonCollection>();
82 
83  // Get RecoEcalCandidate
84  Handle<reco::RecoEcalCandidateCollection> EgammaCandidateCollection;
85  if (!iEvent.getByToken(EgammaCandidateCollection_, EgammaCandidateCollection)) {
86  iEvent.put(std::move(outElectrons));
87  iEvent.put(std::move(outPhotons));
88  return;
89  }
90 
91  // Get GsfTrack
92  Handle<reco::GsfTrackCollection> EgammaGsfTrackCollection;
93  if (!iEvent.getByToken(EgammaGsfTrackCollection_, EgammaGsfTrackCollection)) {
94  iEvent.put(std::move(outElectrons));
95  iEvent.put(std::move(outPhotons));
96  return;
97  }
98 
99  // Get SigmaIEtaIEtaMap
102  iEvent.put(std::move(outElectrons));
103  iEvent.put(std::move(outPhotons));
104  return;
105  }
106 
108  if (!iEvent.getByToken(R9Map_, R9Map)) {
109  iEvent.put(std::move(outElectrons));
110  iEvent.put(std::move(outPhotons));
111  return;
112  }
113 
114  // Get HoverEMap
116  if (!iEvent.getByToken(HoverEMap_, HoverEMap)) {
117  iEvent.put(std::move(outElectrons));
118  iEvent.put(std::move(outPhotons));
119  return;
120  }
121 
122  // Get DetaMap
124  if (!iEvent.getByToken(DetaMap_, DetaMap)) {
125  iEvent.put(std::move(outElectrons));
126  iEvent.put(std::move(outPhotons));
127  return;
128  }
129 
130  // Get DphiMap
132  if (!iEvent.getByToken(DphiMap_, DphiMap)) {
133  iEvent.put(std::move(outElectrons));
134  iEvent.put(std::move(outPhotons));
135  return;
136  }
137 
138  // Get MissingHitsMap
140  if (!iEvent.getByToken(MissingHitsMap_, MissingHitsMap)) {
141  iEvent.put(std::move(outElectrons));
142  iEvent.put(std::move(outPhotons));
143  return;
144  }
145 
146  // Get 1/E - 1/p Map
149  iEvent.put(std::move(outElectrons));
150  iEvent.put(std::move(outPhotons));
151  return;
152  }
153 
154  // Get EcalPFClusterIsoMap
157  iEvent.put(std::move(outElectrons));
158  iEvent.put(std::move(outPhotons));
159  return;
160  }
161 
162  // Get EleGsfTrackIsoMap
165  iEvent.put(std::move(outElectrons));
166  iEvent.put(std::move(outPhotons));
167  return;
168  }
169 
170  // Get HcalPFClusterIsoMap
173  iEvent.put(std::move(outElectrons));
174  iEvent.put(std::move(outPhotons));
175  return;
176  }
177 
180  iEvent.getByToken(ecalRechitEB_, rechitsEB);
181  iEvent.getByToken(ecalRechitEE_, rechitsEE);
182 
183  const CaloTopology* topology = &setup.getData(topologyToken_);
184 
185  // Produce electrons and photons
186  int index = 0;
187  for (auto& candidate : *EgammaCandidateCollection) {
188  reco::RecoEcalCandidateRef candidateRef = getRef(EgammaCandidateCollection, index);
189  ++index;
190  if (candidateRef.isNull() && !candidateRef.isAvailable())
191  continue;
192 
193  if (candidate.pt() < egammaPtCut)
194  continue;
195  if (fabs(candidate.eta()) > egammaEtaCut)
196  continue;
197 
198  reco::SuperClusterRef scRef = candidate.superCluster();
199  if (scRef.isNull() && !scRef.isAvailable())
200  continue;
201 
202  reco::CaloClusterPtr SCseed = candidate.superCluster()->seed();
203  const EcalRecHitCollection* rechits = (std::abs(scRef->eta()) < 1.479) ? rechitsEB.product() : rechitsEE.product();
204  Cluster2ndMoments moments = EcalClusterTools::cluster2ndMoments(*SCseed, *rechits);
205  float sMin = moments.sMin;
206  float sMaj = moments.sMaj;
207 
208  unsigned int seedId = (*SCseed).seed();
209 
210  std::vector<DetId> mDetIds = EcalClusterTools::matrixDetId((topology), (*SCseed).seed(), rechitMatrixSize);
211 
212  int detSize = mDetIds.size();
213  std::vector<float> mEnergies(detSize, 0.);
214  std::vector<float> mTimes(detSize, 0.);
215 
216  for (int i = 0; i < detSize; i++) {
217  mEnergies[i] =
219  if (saveRecHitTiming)
220  mTimes[i] =
222  }
223 
224  float HoE = 999.;
225  if (candidate.superCluster()->energy() != 0.)
226  HoE = (*HoverEMap)[candidateRef] / candidate.superCluster()->energy();
227 
228  float d0 = 0.0;
229  float dz = 0.0;
230  int charge = -999;
231  for (auto& track : *EgammaGsfTrackCollection) {
232  RefToBase<TrajectorySeed> seed = track.extra()->seedRef();
234  RefToBase<reco::CaloCluster> caloCluster = elseed->caloCluster();
235  reco::SuperClusterRef scRefFromTrk = caloCluster.castTo<reco::SuperClusterRef>();
236  if (scRefFromTrk == scRef) {
237  d0 = track.d0();
238  dz = track.dz();
239  charge = track.charge();
240  }
241  }
242  if (charge == -999) { // No associated track. Candidate is a scouting photon
243  outPhotons->emplace_back(candidate.pt(),
244  candidate.eta(),
245  candidate.phi(),
246  candidate.mass(),
247  (*SigmaIEtaIEtaMap)[candidateRef],
248  HoE,
249  (*EcalPFClusterIsoMap)[candidateRef],
250  (*HcalPFClusterIsoMap)[candidateRef],
251  0.,
252  (*R9Map)[candidateRef],
253  sMin,
254  sMaj,
255  seedId,
256  mEnergies,
257  mTimes); //read for(ieta){for(iphi){}}
258  } else { // Candidate is a scouting electron
259  outElectrons->emplace_back(candidate.pt(),
260  candidate.eta(),
261  candidate.phi(),
262  candidate.mass(),
263  d0,
264  dz,
265  (*DetaMap)[candidateRef],
266  (*DphiMap)[candidateRef],
267  (*SigmaIEtaIEtaMap)[candidateRef],
268  HoE,
269  (*OneOEMinusOneOPMap)[candidateRef],
270  (*MissingHitsMap)[candidateRef],
271  charge,
272  (*EcalPFClusterIsoMap)[candidateRef],
273  (*HcalPFClusterIsoMap)[candidateRef],
274  (*EleGsfTrackIsoMap)[candidateRef],
275  (*R9Map)[candidateRef],
276  sMin,
277  sMaj,
278  seedId,
279  mEnergies,
280  mTimes); //read for(ieta){for(iphi){}}
281  }
282  }
283 
284  // Put output
285  iEvent.put(std::move(outElectrons));
286  iEvent.put(std::move(outPhotons));
287 }
288 
289 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
292  desc.add<edm::InputTag>("EgammaCandidates", edm::InputTag("hltEgammaCandidates"));
293  desc.add<edm::InputTag>("EgammaGsfTracks", edm::InputTag("hltEgammaGsfTracks"));
294  desc.add<edm::InputTag>("SigmaIEtaIEtaMap", edm::InputTag("hltEgammaClusterShape:sigmaIEtaIEta5x5"));
295  desc.add<edm::InputTag>("r9Map", edm::InputTag("hltEgammaR9ID:r95x5"));
296  desc.add<edm::InputTag>("HoverEMap", edm::InputTag("hltEgammaHoverE"));
297  desc.add<edm::InputTag>("DetaMap", edm::InputTag("hltEgammaGsfTrackVars:DetaSeed"));
298  desc.add<edm::InputTag>("DphiMap", edm::InputTag("hltEgammaGsfTrackVars:Dphi"));
299  desc.add<edm::InputTag>("MissingHitsMap", edm::InputTag("hltEgammaGsfTrackVars:MissingHits"));
300  desc.add<edm::InputTag>("OneOEMinusOneOPMap", edm::InputTag("hltEgammaGsfTrackVars:OneOESuperMinusOneOP"));
301  desc.add<edm::InputTag>("EcalPFClusterIsoMap", edm::InputTag("hltEgammaEcalPFClusterIso"));
302  desc.add<edm::InputTag>("EleGsfTrackIsoMap", edm::InputTag("hltEgammaEleGsfTrackIso"));
303  desc.add<edm::InputTag>("HcalPFClusterIsoMap", edm::InputTag("hltEgammaHcalPFClusterIso"));
304  desc.add<double>("egammaPtCut", 4.0);
305  desc.add<double>("egammaEtaCut", 2.5);
306  desc.add<double>("egammaHoverECut", 1.0);
307  desc.add<bool>("saveRecHitTiming", false);
308  desc.add<int>("mantissaPrecision", 10)->setComment("default float16, change to 23 for float32");
309  desc.add<int>("rechitMatrixSize", 10);
310  desc.add<edm::InputTag>("ecalRechitEB", edm::InputTag("hltEcalRecHit:EcalRecHitsEB"));
311  desc.add<edm::InputTag>("ecalRechitEE", edm::InputTag("hltEcalRecHit:EcalRecHitsEE"));
312  descriptions.add("hltScoutingEgammaProducer", desc);
313 }
314 
315 // 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_
bool getData(T &iHolder) const
Definition: EventSetup.h:128
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)
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 &)