CMS 3D CMS Logo

ElectronRecalibSuperClusterAssociator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 //
4 
5 // user include files
7 //#include "DataFormats/EgammaReco/interface/SuperCluster.h"
8 //#include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
10 
11 //#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
12 //#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
13 //#include "DataFormats/EgammaCandidates/interface/GsfElectronCoreFwd.h"
14 //#include "DataFormats/EgammaCandidates/interface/GsfElectronCore.h"
16 #include <iostream>
19 //#define DEBUG
20 
21 using namespace reco;
22 using namespace edm;
23 
25 #ifdef DEBUG
26  std::cout << "ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator" << std::endl;
27 #endif
28 
29  //register your products
30  produces<GsfElectronCollection>();
31  produces<GsfElectronCoreCollection>();
32  // produces<SuperClusterCollection>();
33 
34  superClusterCollectionEB_ = iConfig.getParameter<edm::InputTag>("superClusterCollectionEB");
35  superClusterCollectionEE_ = iConfig.getParameter<edm::InputTag>("superClusterCollectionEE");
36 
37  outputLabel_ = iConfig.getParameter<std::string>("outputLabel");
38  electronSrc_ = iConfig.getParameter<edm::InputTag>("electronSrc");
39 
40  electronToken_ = consumes<reco::GsfElectronCollection>(electronSrc_);
41  ebScToken_ = consumes<reco::SuperClusterCollection>(superClusterCollectionEB_);
42  eeScToken_ = consumes<reco::SuperClusterCollection>(superClusterCollectionEE_);
43 
44 #ifdef DEBUG
45  std::cout << "ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator::end" << std::endl;
46 #endif
47 }
48 
50 
51 // ------------ method called to produce the data ------------
53 #ifdef DEBUG
54  std::cout << "GEDElectronRecalibSuperClusterAssociator::produce" << std::endl;
55 #endif
56 
57  // Create the output collections
58  auto pOutEle = std::make_unique<GsfElectronCollection>();
59  auto pOutEleCore = std::make_unique<GsfElectronCoreCollection>();
60 
61  // Get SuperClusters in EB
62  Handle<reco::SuperClusterCollection> superClusterEBHandle;
63  e.getByToken(ebScToken_, superClusterEBHandle);
64  //const reco::SuperClusterCollection* scCollection = superClusterEBHandle.product();
65 
66 #ifdef DEBUG
67  std::cout << "EB scCollection->size()" << superClusterEBHandle->size() << std::endl;
68 #endif
69 
70  // Get SuperClusters in EE
71  Handle<reco::SuperClusterCollection> superClusterEEHandle;
72  e.getByToken(eeScToken_, superClusterEEHandle);
73  // const reco::SuperClusterCollection* eeScCollection = superClusterEEHandle.product();
74 
75 #ifdef DEBUG
76  std::cout << "EE scCollection->size()" << superClusterEEHandle->size() << std::endl;
77 #endif
78 
79  // Get Electrons
81  e.getByToken(electronToken_, eleHandle);
82  // const reco::GsfElectronCollection* electronCollection = eleHandle.product();
83 
84  // GsfElectronCoreRefProd rEleCore = const_cast<edm::Event&>(iEvent).getRefBeforePut<GsfElectronCoreCollection>();
85  GsfElectronCoreRefProd rEleCore = e.getRefBeforePut<GsfElectronCoreCollection>();
87 
88  for (reco::GsfElectronCollection::const_iterator eleIt = eleHandle->begin(); eleIt != eleHandle->end(); eleIt++) {
89  float DeltaRMineleSCbarrel(0.15); //initial minDeltaR
90  float DeltaRMineleSCendcap(0.15);
91  const reco::SuperCluster* nearestSCbarrel = nullptr;
92  const reco::SuperCluster* nearestSCendcap = nullptr;
93  int iscRef = -1, iscRefendcap = -1;
94  int iSC = 0;
95 
96  if (eleIt->trackerDrivenSeed()) {
97  edm::LogError("trackerDriven") << "skipping trackerDriven electrons";
98  continue;
99  }
100  // first loop is on EB superClusters
101  iSC = 0;
102  for (reco::SuperClusterCollection::const_iterator scIt = superClusterEBHandle->begin();
103  scIt != superClusterEBHandle->end();
104  scIt++, iSC++) {
105  double DeltaReleSC = sqrt(reco::deltaR2(eleIt->eta(), eleIt->phi(), scIt->eta(), scIt->phi()));
106 
107  if (DeltaReleSC < DeltaRMineleSCbarrel) //save the nearest SC
108  {
109  DeltaRMineleSCbarrel = DeltaReleSC;
110  nearestSCbarrel = &*scIt;
111  iscRef = iSC;
112  }
113 #ifdef DEBUG
114  std::cout << "EB: " << scIt - superClusterEBHandle->begin() << " " << iSC << " " << iscRef << "\t"
115  << std::setprecision(4) << scIt->energy() << " " << scIt->eta() << " " << scIt->phi() << "\t--\t"
116  << eleIt->energy() << " " << eleIt->eta() << " " << eleIt->phi() << "\t" << DeltaRMineleSCbarrel
117  << std::endl;
118 #endif
119  }
120 
121  // second loop is on EE superClusters
122  iSC = 0;
123  for (reco::SuperClusterCollection::const_iterator scIt = superClusterEEHandle->begin();
124  scIt != superClusterEEHandle->end();
125  scIt++, iSC++) {
126 #ifdef DEBUG
127  std::cout << "EE: " << scIt - superClusterEEHandle->begin() << " " << iSC << " " << iscRef << "\t"
128  << std::setprecision(4) << scIt->energy() << " " << scIt->eta() << " " << scIt->phi() << "\t--\t "
129  << eleIt->energy() << " " << eleIt->eta() << " " << eleIt->phi() << "\t" << DeltaRMineleSCendcap
130  << std::endl;
131 #endif
132 
133  double DeltaReleSC = sqrt(reco::deltaR2(eleIt->eta(), eleIt->phi(), scIt->eta(), scIt->phi()));
134 
135  if (DeltaReleSC < DeltaRMineleSCendcap) {
136  DeltaRMineleSCendcap = DeltaReleSC;
137  nearestSCendcap = &*scIt;
138  iscRefendcap = iSC;
139  }
140  }
142  // if(eleIt->isEB()) assert(DeltaRMineleSCbarrel < DeltaRMineleSCendcap);
143  //else assert(DeltaRMineleSCbarrel > DeltaRMineleSCendcap);
144  if (eleIt->isEB() && DeltaRMineleSCbarrel > DeltaRMineleSCendcap) {
145  edm::LogError("ElectronRecalibAssociator") << "EB electron, but nearest SC is in EE";
146  ;
147  continue;
148  }
149 
150  if (eleIt->isEB() && nearestSCbarrel) {
151  pOutEleCore->push_back(*eleIt->core()); // clone the old core and add to the collection of new cores
152  reco::GsfElectronCoreRef newEleCoreRef(rEleCore,
153  idxEleCore++); // reference to the new electron core in the new collection
154  reco::GsfElectronCore& newEleCore = pOutEleCore->back(); // pick the clone
155  //newEleCore.setGsfTrack(eleIt->gsfTrack()); // set the gsf track (not needed since it is not changed)
156  reco::SuperClusterRef scRef(reco::SuperClusterRef(superClusterEBHandle, iscRef)); // Reference to the new SC
157 #ifndef CMSSW_5_3_X
158  newEleCore.setParentSuperCluster(scRef); // mustache
159 #endif
160  newEleCore.setSuperCluster(scRef); // let's check this! if it is possible to recreate the pfSC
161 
162  pOutEle->push_back(reco::GsfElectron(*eleIt, newEleCoreRef));
163  reco::GsfElectron& newEle = pOutEle->back();
164 
165  //-- first possibility: set the new p4SC using refined SC
169  false); //*newEle.superCluster()->energy()/eleIt->superCluster()->energy());
170 
171  //-- second possibility: set the new p4SC using mustache SC
172  //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);
173 
174  //-- update the correctedEcalEnergy
175  newEle.setCorrectedEcalEnergy(eleIt->ecalEnergy() *
176  (scRef->energy() / eleIt->p4(reco::GsfElectron::P4_FROM_SUPER_CLUSTER).energy()));
177  newEle.setCorrectedEcalEnergyError(eleIt->ecalEnergyError() * (scRef->energy() / eleIt->ecalEnergy()));
178 
179  } else if (!(eleIt->isEB()) && nearestSCendcap) {
180  pOutEleCore->push_back(*eleIt->core()); // clone the old core and add to the collection of new cores
181  reco::GsfElectronCoreRef newEleCoreRef(rEleCore,
182  idxEleCore++); // reference to the new electron core in the new collection
183  reco::GsfElectronCore& newEleCore = pOutEleCore->back(); // pick the clone
184  //newEleCore.setGsfTrack(eleIt->gsfTrack()); // set the gsf track (not needed since it is not changed)
185  reco::SuperClusterRef scRef(
186  reco::SuperClusterRef(superClusterEEHandle, iscRefendcap)); // Reference to the new SC
187 #ifndef CMSSW_5_3_X
188  newEleCore.setParentSuperCluster(scRef); // mustache
189 #endif
190  newEleCore.setSuperCluster(scRef); // let's check this! if it is possible to recreate the pfSC
191 
192  pOutEle->push_back(reco::GsfElectron(*eleIt, newEleCoreRef));
193  reco::GsfElectron& newEle = pOutEle->back();
194 
195  //-- first possibility: set the new p4SC using refined SC
199  false); //*newEle.superCluster()->energy()/eleIt->superCluster()->energy());
200 
201  //-- second possibility: set the new p4SC using mustache SC
202  //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);
203 
204  //-- update the correctedEcalEnergy
205  newEle.setCorrectedEcalEnergy(eleIt->ecalEnergy() *
206  (scRef->energy() / eleIt->p4(reco::GsfElectron::P4_FROM_SUPER_CLUSTER).energy()));
207  newEle.setCorrectedEcalEnergyError(eleIt->ecalEnergyError() * (scRef->energy() / eleIt->ecalEnergy()));
208  } else {
209  edm::LogError("Failed SC association") << "No SC to be associated to the electron";
210  }
211  }
212 
213 #ifdef DEBUG
214  std::cout << "Filled new electrons " << pOutEle->size() << std::endl;
215  std::cout << "Filled new electronsCore " << pOutEleCore->size() << std::endl;
216  // std::cout << "Filled new endcapSC " << pOutNewEndcapSC->size() << std::endl;
217 #endif
218 
219  // put result into the Event
220 
221  e.put(std::move(pOutEle));
222  e.put(std::move(pOutEleCore));
223 
224  // e.put(std::move(pOutNewEndcapSC));
225 }
226 
edm::RefProd
Definition: EDProductfwd.h:25
reco::SuperCluster
Definition: SuperCluster.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ElectronRecalibSuperClusterAssociator.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref< GsfElectronCoreCollection >
deltaR.h
MakerMacros.h
reco::GsfElectron::setP4
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:188
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::GsfElectronCoreCollection
std::vector< GsfElectronCore > GsfElectronCoreCollection
Definition: GsfElectronCoreFwd.h:12
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
ElectronRecalibSuperClusterAssociator
Definition: ElectronRecalibSuperClusterAssociator.h:25
reco::GsfElectronCore::setSuperCluster
void setSuperCluster(const SuperClusterRef &scl)
Definition: GsfElectronCore.h:68
reco::GsfElectron
Definition: GsfElectron.h:35
reco::GsfElectron::P4_FROM_SUPER_CLUSTER
Definition: GsfElectron.h:769
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::GsfElectron::setCorrectedEcalEnergyError
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:170
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
reco::GsfElectronCore::setParentSuperCluster
void setParentSuperCluster(const SuperClusterRef &scl)
Definition: GsfElectronCore.h:81
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
reco::GsfElectronCore
Definition: GsfElectronCore.h:32
LorentzVector.h
GsfTrack.h
edm::EventSetup
Definition: EventSetup.h:57
ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator
ElectronRecalibSuperClusterAssociator(const edm::ParameterSet &conf)
Definition: ElectronRecalibSuperClusterAssociator.cc:24
edm::Ref::key_type
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
ElectronRecalibSuperClusterAssociator::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: ElectronRecalibSuperClusterAssociator.cc:52
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
ElectronRecalibSuperClusterAssociator::~ElectronRecalibSuperClusterAssociator
~ElectronRecalibSuperClusterAssociator() override
Definition: ElectronRecalibSuperClusterAssociator.cc:49
reco::GsfElectron::setCorrectedEcalEnergy
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:174
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37