CMS 3D CMS Logo

EgammaHLTPixelMatchVarProducer.cc
Go to the documentation of this file.
1 
2 
8 
13 
16 
21 
24 
28 
30 
31 namespace {
32  //first 4 bits are sub detect of each hit (0=barrel, 1 = endcap)
33  //next 8 bits are layer information (0=no hit, 1 = hit), first 4 are barrel, next 4 are endcap (theres an empty bit here
34  //next 4 bits are nr of layers info
35  int makeSeedInfo(const reco::ElectronSeed& seed) {
36  int info = 0;
37  for (size_t hitNr = 0; hitNr < seed.hitInfo().size(); hitNr++) {
38  int subDetBit = 0x1 << hitNr;
39  if (seed.subDet(hitNr) == PixelSubdetector::PixelEndcap)
40  info |= subDetBit;
41  int layerOffset = 3;
42  if (seed.subDet(hitNr) == PixelSubdetector::PixelEndcap)
43  layerOffset += 4;
44 
45  int layerOrDiskNr = seed.layerOrDiskNr(hitNr);
46  if (layerOrDiskNr == 0 || layerOrDiskNr > 4) {
47  if (layerOrDiskNr == std::numeric_limits<int>::max()) {
48  throw cms::Exception("LogicError")
49  << "The layerOrDiskNr of hitnr " << hitNr << " is " << layerOrDiskNr
50  << " which is equal to numeric_limits::max which implies it was not filled correctly.\nWhile this is "
51  "valid for the matching variables as it can signal the failure to find a postive or negative seed "
52  "trajectory,\nit is not valid for the layer number as that is always known.\nThus there is a logic "
53  "error in the code or possible corrupt data";
54  } else {
55  throw cms::Exception("InvalidData") << "The layerOrDiskNr of hitnr " << hitNr << " is " << layerOrDiskNr
56  << " and is not in the range of 1<=x<=4 which implies a new pixel "
57  "detector\nthis code does not support as the current one has only 4 "
58  "layers numbered 1-4 or corrupt data\n";
59  }
60  }
61  int layerBit = 0x1 << layerOffset << layerOrDiskNr;
62  info |= layerBit;
63 
64  int nrLayersAlongTrajShifted = seed.nrLayersAlongTraj() << 12;
65  info |= nrLayersAlongTrajShifted;
66  }
67  return info;
68  }
69 
70 } // namespace
71 
72 struct PixelData {
73 public:
75  size_t hitNr,
76  float (reco::ElectronSeed::*func)(size_t) const,
78  : name_(std::move(name)), hitNr_(hitNr), func_(func), val_(std::numeric_limits<float>::max()), valInfo_(0) {
79  valMap_ = std::make_unique<reco::RecoEcalCandidateIsolationMap>(candHandle);
80  valInfoMap_ = std::make_unique<reco::RecoEcalCandidateIsolationMap>(candHandle);
81  }
82  PixelData(PixelData&& rhs) = default;
83 
84  void resetVal() {
86  valInfo_ = 0;
87  }
88  void fill(const reco::ElectronSeed& seed) {
89  if (hitNr_ < seed.hitInfo().size()) {
90  float seedVal = (seed.*func_)(hitNr_);
91  if (std::abs(seedVal) < std::abs(val_)) {
92  val_ = seedVal;
93  valInfo_ = makeSeedInfo(seed);
94  }
95  }
96  }
97  void fill(const reco::RecoEcalCandidateRef& candRef) {
98  valMap_->insert(candRef, val_);
99  valInfoMap_->insert(candRef, valInfo_);
101  valInfo_ = 0;
102  }
103 
105  event.put(std::move(valMap_), name_ + std::to_string(hitNr_ + 1));
106  event.put(std::move(valInfoMap_), name_ + std::to_string(hitNr_ + 1) + "Info");
107  }
108 
109 private:
110  std::unique_ptr<reco::RecoEcalCandidateIsolationMap> valMap_;
111  std::unique_ptr<reco::RecoEcalCandidateIsolationMap> valInfoMap_;
113  size_t hitNr_;
114  float (reco::ElectronSeed::*func_)(size_t) const;
115  float val_;
116  float valInfo_;
117 };
118 
120 public:
123 
124  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
125  void produce(edm::Event&, const edm::EventSetup&) override;
126  std::array<float, 4> calS2(const reco::ElectronSeed& seed, int charge) const;
127 
128 private:
129  // ----------member data ---------------------------
130 
133 
137 
139  size_t nrHits_;
140 };
141 
143  : recoEcalCandidateToken_(
144  consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("recoEcalCandidateProducer"))),
145  pixelSeedsToken_(
146  consumes<reco::ElectronSeedCollection>(config.getParameter<edm::InputTag>("pixelSeedsProducer"))),
147  dPhi1Para_(config.getParameter<edm::ParameterSet>("dPhi1SParams")),
148  dPhi2Para_(config.getParameter<edm::ParameterSet>("dPhi2SParams")),
149  dRZ2Para_(config.getParameter<edm::ParameterSet>("dRZ2SParams")),
150  productsToWrite_(config.getParameter<int>("productsToWrite")),
151  nrHits_(4)
152 
153 {
154  //register your products
155  produces<reco::RecoEcalCandidateIsolationMap>("s2");
156  if (productsToWrite_ >= 1) {
157  produces<reco::RecoEcalCandidateIsolationMap>("dPhi1BestS2");
158  produces<reco::RecoEcalCandidateIsolationMap>("dPhi2BestS2");
159  produces<reco::RecoEcalCandidateIsolationMap>("dzBestS2");
160  }
161  if (productsToWrite_ >= 2) {
162  //note for product names we start from index 1
163  for (size_t hitNr = 1; hitNr <= nrHits_; hitNr++) {
164  produces<reco::RecoEcalCandidateIsolationMap>("dPhi" + std::to_string(hitNr));
165  produces<reco::RecoEcalCandidateIsolationMap>("dPhi" + std::to_string(hitNr) + "Info");
166  produces<reco::RecoEcalCandidateIsolationMap>("dRZ" + std::to_string(hitNr));
167  produces<reco::RecoEcalCandidateIsolationMap>("dRZ" + std::to_string(hitNr) + "Info");
168  }
169  produces<reco::RecoEcalCandidateIsolationMap>("nrClus");
170  produces<reco::RecoEcalCandidateIsolationMap>("seedClusEFrac");
171  produces<reco::RecoEcalCandidateIsolationMap>("phiWidth");
172  produces<reco::RecoEcalCandidateIsolationMap>("etaWidth");
173  }
174 }
175 
177 
180  desc.add<edm::InputTag>(("recoEcalCandidateProducer"), edm::InputTag("hltL1SeededRecoEcalCandidate"));
181  desc.add<edm::InputTag>(("pixelSeedsProducer"), edm::InputTag("electronPixelSeeds"));
182 
183  edm::ParameterSetDescription varParamDesc;
184  edm::ParameterSetDescription binParamDesc;
185 
186  auto binDescCases = "AbsEtaClus" >> (edm::ParameterDescription<double>("xMin", 0.0, true) and
187  edm::ParameterDescription<double>("xMax", 3.0, true) and
188  edm::ParameterDescription<int>("yMin", 0, true) and
189  edm::ParameterDescription<int>("yMax", 99999, true) and
190  edm::ParameterDescription<std::string>("funcType", "pol0", true) and
191  edm::ParameterDescription<std::vector<double>>("funcParams", {0.}, true)) or
192  "AbsEtaClusPhi" >> (edm::ParameterDescription<double>("xMin", 0.0, true) and
193  edm::ParameterDescription<double>("xMax", 3.0, true) and
194  edm::ParameterDescription<int>("yMin", 0, true) and
195  edm::ParameterDescription<int>("yMax", 99999, true) and
196  edm::ParameterDescription<std::string>("funcType", "pol0", true) and
197  edm::ParameterDescription<std::vector<double>>("funcParams", {0.}, true)) or
198  "AbsEtaClusEt" >> (edm::ParameterDescription<double>("xMin", 0.0, true) and
199  edm::ParameterDescription<double>("xMax", 3.0, true) and
200  edm::ParameterDescription<int>("yMin", 0, true) and
201  edm::ParameterDescription<int>("yMax", 99999, true) and
202  edm::ParameterDescription<std::string>("funcType", "pol0", true) and
203  edm::ParameterDescription<std::vector<double>>("funcParams", {0.}, true));
204 
205  binParamDesc.ifValue(edm::ParameterDescription<std::string>("binType", "AbsEtaClus", true), std::move(binDescCases));
206 
207  varParamDesc.addVPSet("bins", binParamDesc);
208  desc.add("dPhi1SParams", varParamDesc);
209  desc.add("dPhi2SParams", varParamDesc);
210  desc.add("dRZ2SParams", varParamDesc);
211  desc.add<int>("productsToWrite", 0);
212  descriptions.add(("hltEgammaHLTPixelMatchVarProducer"), desc);
213 }
214 
216  // Get the HLT filtered objects
217  auto recoEcalCandHandle = iEvent.getHandle(recoEcalCandidateToken_);
218 
219  auto pixelSeedsHandle = iEvent.getHandle(pixelSeedsToken_);
220 
221  if (!recoEcalCandHandle.isValid())
222  return;
223  else if (!pixelSeedsHandle.isValid()) {
224  auto s2Map = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
225  for (unsigned int candNr = 0; candNr < recoEcalCandHandle->size(); candNr++) {
226  reco::RecoEcalCandidateRef candRef(recoEcalCandHandle, candNr);
227  s2Map->insert(candRef, 0);
228  }
229  iEvent.put(std::move(s2Map), "s2");
230  return;
231  }
232 
233  auto dPhi1BestS2Map = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
234  auto dPhi2BestS2Map = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
235  auto dzBestS2Map = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
236  auto s2Map = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
237 
238  auto nrClusMap = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
239  auto seedClusEFracMap = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
240  auto phiWidthMap = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
241  auto etaWidthMap = std::make_unique<reco::RecoEcalCandidateIsolationMap>(recoEcalCandHandle);
242 
243  std::vector<PixelData> pixelData;
244  for (size_t hitNr = 0; hitNr < nrHits_; hitNr++) {
245  pixelData.emplace_back(PixelData("dPhi", hitNr, &reco::ElectronSeed::dPhiBest, recoEcalCandHandle));
246  pixelData.emplace_back(PixelData("dRZ", hitNr, &reco::ElectronSeed::dRZBest, recoEcalCandHandle));
247  }
248 
249  for (unsigned int candNr = 0; candNr < recoEcalCandHandle->size(); candNr++) {
250  reco::RecoEcalCandidateRef candRef(recoEcalCandHandle, candNr);
251  reco::SuperClusterRef candSCRef = candRef->superCluster();
252 
253  std::array<float, 4> bestS2{{std::numeric_limits<float>::max(),
257  for (auto& seed : *pixelSeedsHandle) {
258  const edm::RefToBase<reco::CaloCluster>& pixelClusterRef = seed.caloCluster();
259  reco::SuperClusterRef pixelSCRef = pixelClusterRef.castTo<reco::SuperClusterRef>();
260  if (&(*candSCRef) == &(*pixelSCRef)) {
261  std::array<float, 4> s2Data = calS2(seed, -1);
262  std::array<float, 4> s2DataPos = calS2(seed, +1);
263  if (s2Data[0] < bestS2[0])
264  bestS2 = s2Data;
265  if (s2DataPos[0] < bestS2[0])
266  bestS2 = s2DataPos;
267 
268  if (productsToWrite_ >= 2) {
269  for (auto& pixelDatum : pixelData) {
270  pixelDatum.fill(seed);
271  }
272  }
273  }
274  }
275 
276  s2Map->insert(candRef, bestS2[0]);
277  if (productsToWrite_ >= 1) {
278  dPhi1BestS2Map->insert(candRef, bestS2[1]);
279  dPhi2BestS2Map->insert(candRef, bestS2[2]);
280  dzBestS2Map->insert(candRef, bestS2[3]);
281  }
282  if (productsToWrite_ >= 2) {
283  nrClusMap->insert(candRef, candSCRef->clustersSize());
284  float seedClusEFrac = candSCRef->rawEnergy() > 0 ? candSCRef->seed()->energy() / candSCRef->rawEnergy() : 0.;
285  // std::cout <<"cand "<<candSCRef->energy()<<" E Corr "<<candSCRef->correctedEnergyUncertainty()<<" "<<candSCRef->correctedEnergy()<<" width "<<candSCRef->phiWidth()<<std::endl;
286  // float seedClusEFrac = candSCRef->phiWidth();
287  seedClusEFracMap->insert(candRef, seedClusEFrac);
288  float phiWidth = candSCRef->phiWidth();
289  float etaWidth = candSCRef->etaWidth();
290  phiWidthMap->insert(candRef, phiWidth);
291  etaWidthMap->insert(candRef, etaWidth);
292 
293  for (auto& pixelDatum : pixelData) {
294  pixelDatum.fill(candRef);
295  }
296  }
297  }
298 
299  iEvent.put(std::move(s2Map), "s2");
300  if (productsToWrite_ >= 1) {
301  iEvent.put(std::move(dPhi1BestS2Map), "dPhi1BestS2");
302  iEvent.put(std::move(dPhi2BestS2Map), "dPhi2BestS2");
303  iEvent.put(std::move(dzBestS2Map), "dzBestS2");
304  }
305  if (productsToWrite_ >= 2) {
306  for (auto& pixelDatum : pixelData) {
307  pixelDatum.putInto(iEvent);
308  }
309  iEvent.put(std::move(nrClusMap), "nrClus");
310  iEvent.put(std::move(seedClusEFracMap), "seedClusEFrac");
311  iEvent.put(std::move(phiWidthMap), "phiWidth");
312  iEvent.put(std::move(etaWidthMap), "etaWidth");
313  }
314 }
315 
316 std::array<float, 4> EgammaHLTPixelMatchVarProducer::calS2(const reco::ElectronSeed& seed, int charge) const {
317  const float dPhi1Const = dPhi1Para_(seed);
318  const float dPhi2Const = dPhi2Para_(seed);
319  const float dRZ2Const = dRZ2Para_(seed);
320 
321  float dPhi1 = (charge < 0 ? seed.dPhiNeg(0) : seed.dPhiPos(0)) / dPhi1Const;
322  float dPhi2 = (charge < 0 ? seed.dPhiNeg(1) : seed.dPhiPos(1)) / dPhi2Const;
323  float dRz2 = (charge < 0 ? seed.dRZNeg(1) : seed.dRZPos(1)) / dRZ2Const;
324 
325  float s2 = dPhi1 * dPhi1 + dPhi2 * dPhi2 + dRz2 * dRz2;
326  return std::array<float, 4>{{s2, dPhi1, dPhi2, dRz2}};
327 }
328 
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T >> cases)
void produce(edm::Event &, const edm::EventSetup &) override
static const TGPicture * info(bool iBackgroundIsBlack)
egPM::Param< reco::ElectronSeed > dPhi2Para_
egPM::Param< reco::ElectronSeed > dPhi1Para_
REF castTo() const
Definition: RefToBase.h:243
Definition: config.py:1
std::array< float, 4 > calS2(const reco::ElectronSeed &seed, int charge) const
static std::string to_string(const XMLCh *ch)
void putInto(edm::Event &event)
egPM::Param< reco::ElectronSeed > dRZ2Para_
int iEvent
Definition: GenABIO.cc:224
void fill(const reco::ElectronSeed &seed)
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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > recoEcalCandidateToken_
std::unique_ptr< reco::RecoEcalCandidateIsolationMap > valInfoMap_
float dPhiBest(size_t hitNr) const
Definition: ElectronSeed.h:104
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::unique_ptr< reco::RecoEcalCandidateIsolationMap > valMap_
std::vector< RecoEcalCandidate > RecoEcalCandidateCollection
collectin of RecoEcalCandidate objects
fixed size matrix
HLT enums.
const edm::EDGetTokenT< reco::ElectronSeedCollection > pixelSeedsToken_
EgammaHLTPixelMatchVarProducer(const edm::ParameterSet &)
PixelData(std::string name, size_t hitNr, float(reco::ElectronSeed::*func)(size_t) const, const edm::Handle< reco::RecoEcalCandidateCollection > &candHandle)
float dRZBest(size_t hitNr) const
Definition: ElectronSeed.h:107
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
float(reco::ElectronSeed::* func_)(size_t) const
void fill(const reco::RecoEcalCandidateRef &candRef)