CMS 3D CMS Logo

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