CMS 3D CMS Logo

ElectronRecalibSuperClusterAssociator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // user include files
6 
8 #include <iostream>
11 
12 using namespace reco;
13 using namespace edm;
14 
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 }
38 
40 
41 // ------------ method called to produce the data ------------
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 }
204 
void setP4(P4Kind kind, const LorentzVector &p4, float p4Error, bool setCandidate)
Definition: GsfElectron.cc:194
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
Log< level::Error, false > LogError
ElectronRecalibSuperClusterAssociator(const edm::ParameterSet &conf)
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:174
fixed size matrix
HLT enums.
void produce(edm::Event &e, const edm::EventSetup &c) override
def move(src, dest)
Definition: eostools.py:511