CMS 3D CMS Logo

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