CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
ElectronRecalibSuperClusterAssociator Class Reference

#include <ElectronRecalibSuperClusterAssociator.h>

Inheritance diagram for ElectronRecalibSuperClusterAssociator:
edm::stream::EDProducer<>

Public Member Functions

 ElectronRecalibSuperClusterAssociator (const edm::ParameterSet &conf)
 
void produce (edm::Event &e, const edm::EventSetup &c) override
 
 ~ElectronRecalibSuperClusterAssociator () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

Private Attributes

edm::EDGetTokenT< reco::SuperClusterCollectionebScToken_
 
edm::EDGetTokenT< reco::SuperClusterCollectioneeScToken_
 
edm::InputTag electronSrc_
 
edm::EDGetTokenT< reco::GsfElectronCollectionelectronToken_
 
std::string outputLabel_
 
edm::InputTag superClusterCollectionEB_
 
edm::InputTag superClusterCollectionEE_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::RunSummaryCache
 

Detailed Description

Definition at line 23 of file ElectronRecalibSuperClusterAssociator.h.

Constructor & Destructor Documentation

◆ ElectronRecalibSuperClusterAssociator()

ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator ( const edm::ParameterSet conf)
explicit

Definition at line 15 of file ElectronRecalibSuperClusterAssociator.cc.

References gather_cfg::cout, edm::ParameterSet::getParameter(), and AlCaHLTBitMon_QueryRunRegistry::string.

15  {
16 #ifdef DEBUG
17  std::cout << "ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator" << std::endl;
18 #endif
19 
20  //register your products
21  produces<GsfElectronCollection>();
22  produces<GsfElectronCoreCollection>();
23 
24  superClusterCollectionEB_ = iConfig.getParameter<edm::InputTag>("superClusterCollectionEB");
25  superClusterCollectionEE_ = iConfig.getParameter<edm::InputTag>("superClusterCollectionEE");
26 
27  outputLabel_ = iConfig.getParameter<std::string>("outputLabel");
28  electronSrc_ = iConfig.getParameter<edm::InputTag>("electronSrc");
29 
30  electronToken_ = consumes<reco::GsfElectronCollection>(electronSrc_);
31  ebScToken_ = consumes<reco::SuperClusterCollection>(superClusterCollectionEB_);
32  eeScToken_ = consumes<reco::SuperClusterCollection>(superClusterCollectionEE_);
33 
34 #ifdef DEBUG
35  std::cout << "ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator::end" << std::endl;
36 #endif
37 }
edm::EDGetTokenT< reco::SuperClusterCollection > ebScToken_
edm::EDGetTokenT< reco::SuperClusterCollection > eeScToken_
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_

◆ ~ElectronRecalibSuperClusterAssociator()

ElectronRecalibSuperClusterAssociator::~ElectronRecalibSuperClusterAssociator ( )
override

Definition at line 39 of file ElectronRecalibSuperClusterAssociator.cc.

39 {}

Member Function Documentation

◆ produce()

void ElectronRecalibSuperClusterAssociator::produce ( edm::Event e,
const edm::EventSetup c 
)
override

Definition at line 42 of file ElectronRecalibSuperClusterAssociator.cc.

References gather_cfg::cout, reco::deltaR2(), MillePedeFileConverter_cfg::e, eostools::move(), reco::GsfElectron::P4_FROM_SUPER_CLUSTER, reco::GsfElectron::setCorrectedEcalEnergy(), reco::GsfElectron::setCorrectedEcalEnergyError(), reco::GsfElectron::setP4(), reco::GsfElectronCore::setParentSuperCluster(), reco::GsfElectronCore::setSuperCluster(), and mathSSE::sqrt().

42  {
43 #ifdef DEBUG
44  std::cout << "GEDElectronRecalibSuperClusterAssociator::produce" << std::endl;
45 #endif
46 
47  // Create the output collections
48  auto pOutEle = std::make_unique<GsfElectronCollection>();
49  auto pOutEleCore = std::make_unique<GsfElectronCoreCollection>();
50 
51  // Get SuperClusters in EB
52  Handle<reco::SuperClusterCollection> superClusterEBHandle;
53  e.getByToken(ebScToken_, superClusterEBHandle);
54 
55 #ifdef DEBUG
56  std::cout << "EB scCollection->size()" << superClusterEBHandle->size() << std::endl;
57 #endif
58 
59  // Get SuperClusters in EE
60  Handle<reco::SuperClusterCollection> superClusterEEHandle;
61  e.getByToken(eeScToken_, superClusterEEHandle);
62 
63 #ifdef DEBUG
64  std::cout << "EE scCollection->size()" << superClusterEEHandle->size() << std::endl;
65 #endif
66 
67  // Get Electrons
69  e.getByToken(electronToken_, eleHandle);
70 
71  GsfElectronCoreRefProd rEleCore = e.getRefBeforePut<GsfElectronCoreCollection>();
73 
74  for (reco::GsfElectronCollection::const_iterator eleIt = eleHandle->begin(); eleIt != eleHandle->end(); eleIt++) {
75  float DeltaRMineleSCbarrel(0.15); //initial minDeltaR
76  float DeltaRMineleSCendcap(0.15);
77  const reco::SuperCluster* nearestSCbarrel = nullptr;
78  const reco::SuperCluster* nearestSCendcap = nullptr;
79  int iscRef = -1, iscRefendcap = -1;
80  int iSC = 0;
81 
82  if (eleIt->trackerDrivenSeed()) {
83  edm::LogError("trackerDriven") << "skipping trackerDriven electrons";
84  continue;
85  }
86  // first loop is on EB superClusters
87  iSC = 0;
88  for (reco::SuperClusterCollection::const_iterator scIt = superClusterEBHandle->begin();
89  scIt != superClusterEBHandle->end();
90  scIt++, iSC++) {
91  double DeltaReleSC = sqrt(reco::deltaR2(eleIt->eta(), eleIt->phi(), scIt->eta(), scIt->phi()));
92 
93  if (DeltaReleSC < DeltaRMineleSCbarrel) //save the nearest SC
94  {
95  DeltaRMineleSCbarrel = DeltaReleSC;
96  nearestSCbarrel = &*scIt;
97  iscRef = iSC;
98  }
99 #ifdef DEBUG
100  std::cout << "EB: " << scIt - superClusterEBHandle->begin() << " " << iSC << " " << iscRef << "\t"
101  << std::setprecision(4) << scIt->energy() << " " << scIt->eta() << " " << scIt->phi() << "\t--\t"
102  << eleIt->energy() << " " << eleIt->eta() << " " << eleIt->phi() << "\t" << DeltaRMineleSCbarrel
103  << std::endl;
104 #endif
105  }
106 
107  // second loop is on EE superClusters
108  iSC = 0;
109  for (reco::SuperClusterCollection::const_iterator scIt = superClusterEEHandle->begin();
110  scIt != superClusterEEHandle->end();
111  scIt++, iSC++) {
112 #ifdef DEBUG
113  std::cout << "EE: " << scIt - superClusterEEHandle->begin() << " " << iSC << " " << iscRef << "\t"
114  << std::setprecision(4) << scIt->energy() << " " << scIt->eta() << " " << scIt->phi() << "\t--\t "
115  << eleIt->energy() << " " << eleIt->eta() << " " << eleIt->phi() << "\t" << DeltaRMineleSCendcap
116  << std::endl;
117 #endif
118 
119  double DeltaReleSC = sqrt(reco::deltaR2(eleIt->eta(), eleIt->phi(), scIt->eta(), scIt->phi()));
120 
121  if (DeltaReleSC < DeltaRMineleSCendcap) {
122  DeltaRMineleSCendcap = DeltaReleSC;
123  nearestSCendcap = &*scIt;
124  iscRefendcap = iSC;
125  }
126  }
127  if (eleIt->isEB() && DeltaRMineleSCbarrel > DeltaRMineleSCendcap) {
128  edm::LogError("ElectronRecalibAssociator") << "EB electron, but nearest SC is in EE";
129  ;
130  continue;
131  }
132 
133  if (eleIt->isEB() && nearestSCbarrel) {
134  pOutEleCore->push_back(*eleIt->core()); // clone the old core and add to the collection of new cores
135  reco::GsfElectronCoreRef newEleCoreRef(rEleCore,
136  idxEleCore++); // reference to the new electron core in the new collection
137  reco::GsfElectronCore& newEleCore = pOutEleCore->back(); // pick the clone
138  reco::SuperClusterRef scRef(reco::SuperClusterRef(superClusterEBHandle, iscRef)); // Reference to the new SC
139 #ifndef CMSSW_5_3_X
140  newEleCore.setParentSuperCluster(scRef); // mustache
141 #endif
142  newEleCore.setSuperCluster(scRef); // let's check this! if it is possible to recreate the pfSC
143 
144  pOutEle->push_back(reco::GsfElectron(*eleIt, newEleCoreRef));
145  reco::GsfElectron& newEle = pOutEle->back();
146 
147  //-- first possibility: set the new p4SC using refined SC
151  false); //*newEle.superCluster()->energy()/eleIt->superCluster()->energy());
152 
153  //-- second possibility: set the new p4SC using mustache SC
154  //newEle.setP4(reco::GsfElectron::P4_FROM_SUPER_CLUSTER, eleIt->p4(reco::GsfElectron::P4_FROM_SUPER_CLUSTER)*newEle.parentSuperCluster()->energy()/eleIt->parentSuperCluster()->energy(), eleIt->p4Error(reco::GsfElectron::P4_FROM_SUPER_CLUSTER), false);
155 
156  //-- update the correctedEcalEnergy
157  newEle.setCorrectedEcalEnergy(eleIt->ecalEnergy() *
158  (scRef->energy() / eleIt->p4(reco::GsfElectron::P4_FROM_SUPER_CLUSTER).energy()));
159  newEle.setCorrectedEcalEnergyError(eleIt->ecalEnergyError() * (scRef->energy() / eleIt->ecalEnergy()));
160 
161  } else if (!(eleIt->isEB()) && nearestSCendcap) {
162  pOutEleCore->push_back(*eleIt->core()); // clone the old core and add to the collection of new cores
163  reco::GsfElectronCoreRef newEleCoreRef(rEleCore,
164  idxEleCore++); // reference to the new electron core in the new collection
165  reco::GsfElectronCore& newEleCore = pOutEleCore->back(); // pick the clone
166  reco::SuperClusterRef scRef(
167  reco::SuperClusterRef(superClusterEEHandle, iscRefendcap)); // Reference to the new SC
168 #ifndef CMSSW_5_3_X
169  newEleCore.setParentSuperCluster(scRef); // mustache
170 #endif
171  newEleCore.setSuperCluster(scRef); // let's check this! if it is possible to recreate the pfSC
172 
173  pOutEle->push_back(reco::GsfElectron(*eleIt, newEleCoreRef));
174  reco::GsfElectron& newEle = pOutEle->back();
175 
176  //-- first possibility: set the new p4SC using refined SC
180  false); //*newEle.superCluster()->energy()/eleIt->superCluster()->energy());
181 
182  //-- second possibility: set the new p4SC using mustache SC
183  //newEle.setP4(reco::GsfElectron::P4_FROM_SUPER_CLUSTER, eleIt->p4(reco::GsfElectron::P4_FROM_SUPER_CLUSTER)*newEle.parentSuperCluster()->energy()/eleIt->parentSuperCluster()->energy(), eleIt->p4Error(reco::GsfElectron::P4_FROM_SUPER_CLUSTER), false);
184 
185  //-- update the correctedEcalEnergy
186  newEle.setCorrectedEcalEnergy(eleIt->ecalEnergy() *
187  (scRef->energy() / eleIt->p4(reco::GsfElectron::P4_FROM_SUPER_CLUSTER).energy()));
188  newEle.setCorrectedEcalEnergyError(eleIt->ecalEnergyError() * (scRef->energy() / eleIt->ecalEnergy()));
189  } else {
190  edm::LogError("Failed SC association") << "No SC to be associated to the electron";
191  }
192  }
193 
194 #ifdef DEBUG
195  std::cout << "Filled new electrons " << pOutEle->size() << std::endl;
196  std::cout << "Filled new electronsCore " << pOutEleCore->size() << std::endl;
197 #endif
198 
199  // put result into the Event
200 
201  e.put(std::move(pOutEle));
202  e.put(std::move(pOutEleCore));
203 }
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:194
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
edm::EDGetTokenT< reco::SuperClusterCollection > ebScToken_
edm::EDGetTokenT< reco::SuperClusterCollection > eeScToken_
Log< level::Error, false > LogError
void setSuperCluster(const SuperClusterRef &scl)
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:170
void setParentSuperCluster(const SuperClusterRef &scl)
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< GsfElectronCore > GsfElectronCoreCollection
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:174
edm::EDGetTokenT< reco::GsfElectronCollection > electronToken_
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ ebScToken_

edm::EDGetTokenT<reco::SuperClusterCollection> ElectronRecalibSuperClusterAssociator::ebScToken_
private

Definition at line 39 of file ElectronRecalibSuperClusterAssociator.h.

◆ eeScToken_

edm::EDGetTokenT<reco::SuperClusterCollection> ElectronRecalibSuperClusterAssociator::eeScToken_
private

Definition at line 40 of file ElectronRecalibSuperClusterAssociator.h.

◆ electronSrc_

edm::InputTag ElectronRecalibSuperClusterAssociator::electronSrc_
private

Definition at line 32 of file ElectronRecalibSuperClusterAssociator.h.

◆ electronToken_

edm::EDGetTokenT<reco::GsfElectronCollection> ElectronRecalibSuperClusterAssociator::electronToken_
private

Definition at line 38 of file ElectronRecalibSuperClusterAssociator.h.

◆ outputLabel_

std::string ElectronRecalibSuperClusterAssociator::outputLabel_
private

Definition at line 36 of file ElectronRecalibSuperClusterAssociator.h.

◆ superClusterCollectionEB_

edm::InputTag ElectronRecalibSuperClusterAssociator::superClusterCollectionEB_
private

Definition at line 33 of file ElectronRecalibSuperClusterAssociator.h.

◆ superClusterCollectionEE_

edm::InputTag ElectronRecalibSuperClusterAssociator::superClusterCollectionEE_
private

Definition at line 34 of file ElectronRecalibSuperClusterAssociator.h.