00001
00002
00003
00004
00005
00006
00007 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00008 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00009 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
00010 #include "Calibration/EcalCalibAlgos/interface/ElectronRecalibSuperClusterAssociator.h"
00011
00012 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00013 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00014 #include "DataFormats/EgammaCandidates/interface/GsfElectronCoreFwd.h"
00015 #include "DataFormats/EgammaCandidates/interface/GsfElectronCore.h"
00016
00017 #include <iostream>
00018
00019
00020
00021 using namespace reco;
00022 using namespace edm;
00023
00024 ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator(const edm::ParameterSet& iConfig)
00025 {
00026 #ifdef DEBUG
00027 std::cout<< "ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator" << std::endl;
00028 #endif
00029
00030
00031 produces<GsfElectronCollection>();
00032 produces<GsfElectronCoreCollection>() ;
00033 produces<SuperClusterCollection>();
00034
00035 scProducer_ = iConfig.getParameter<std::string>("scProducer");
00036 scCollection_ = iConfig.getParameter<std::string>("scCollection");
00037
00038 scIslandProducer_ = iConfig.getParameter<std::string>("scIslandProducer");
00039 scIslandCollection_ = iConfig.getParameter<std::string>("scIslandCollection");
00040
00041 electronProducer_ = iConfig.getParameter<std::string > ("electronProducer");
00042 electronCollection_ = iConfig.getParameter<std::string > ("electronCollection");
00043 #ifdef DEBUG
00044 std::cout<< "ElectronRecalibSuperClusterAssociator::ElectronRecalibSuperClusterAssociator::end" << std::endl;
00045 #endif
00046 }
00047
00048 ElectronRecalibSuperClusterAssociator::~ElectronRecalibSuperClusterAssociator()
00049 {
00050 }
00051
00052
00053 void ElectronRecalibSuperClusterAssociator::produce(edm::Event& e, const edm::EventSetup& iSetup)
00054 {
00055 #ifdef DEBUG
00056 std::cout<< "ElectronRecalibSuperClusterAssociator::produce" << std::endl;
00057 #endif
00058
00059 std::auto_ptr<GsfElectronCollection> pOutEle(new GsfElectronCollection);
00060 std::auto_ptr<GsfElectronCoreCollection> pOutEleCore(new GsfElectronCoreCollection);
00061 std::auto_ptr<SuperClusterCollection> pOutNewEndcapSC(new SuperClusterCollection);
00062
00063 reco::SuperClusterRefProd rSC = e.getRefBeforePut<SuperClusterCollection>();
00064 edm::Ref<SuperClusterCollection>::key_type idxSC = 0;
00065
00066
00067 Handle<reco::SuperClusterCollection> pSuperClusters;
00068 e.getByLabel(scProducer_, scCollection_, pSuperClusters);
00069 if (!pSuperClusters.isValid()) {
00070 std::cerr << "Error! can't get the product SuperClusterCollection "<< std::endl;
00071 }
00072 const reco::SuperClusterCollection* scCollection = pSuperClusters.product();
00073
00074 #ifdef DEBUG
00075 std::cout<<"scCollection->size()"<<scCollection->size()<<std::endl;
00076 #endif
00077
00078
00079 Handle<reco::SuperClusterCollection> pIslandSuperClusters;
00080 e.getByLabel(scIslandProducer_, scIslandCollection_, pIslandSuperClusters);
00081 if (!pIslandSuperClusters.isValid()) {
00082 std::cerr << "Error! can't get the product IslandSuperClusterCollection "<< std::endl;
00083 }
00084 const reco::SuperClusterCollection* scIslandCollection = pIslandSuperClusters.product();
00085
00086 #ifdef DEBUG
00087 std::cout<<"scEECollection->size()"<<scIslandCollection->size()<<std::endl;
00088 #endif
00089
00090
00091 Handle<reco::GsfElectronCollection> pElectrons;
00092 e.getByLabel(electronProducer_, electronCollection_, pElectrons);
00093 if (!pElectrons.isValid()) {
00094 std::cerr << "Error! can't get the product ElectronCollection "<< std::endl;
00095 }
00096 const reco::GsfElectronCollection* electronCollection = pElectrons.product();
00097
00098 for(reco::GsfElectronCollection::const_iterator eleIt = electronCollection->begin(); eleIt != electronCollection->end(); eleIt++)
00099 {
00100 float DeltaRMineleSCbarrel(0.15);
00101 float DeltaRMineleSCendcap(0.15);
00102 const reco::SuperCluster* nearestSCbarrel=0;
00103 const reco::SuperCluster* nearestSCendcap=0;
00104 int iscRef=-1;
00105 int iSC=0;
00106
00107
00108 for(reco::SuperClusterCollection::const_iterator scIt = scCollection->begin();
00109 scIt != scCollection->end(); scIt++){
00110 #ifdef DEBUG
00111 std::cout << scIt->energy() << " " << scIt->eta() << " " << scIt->phi() << " " << eleIt->eta() << " " << eleIt->phi() << std::endl;
00112 #endif
00113
00114 double DeltaReleSC = sqrt ( pow( eleIt->eta() - scIt->eta(),2) + pow(eleIt->phi() - scIt->phi(),2));
00115
00116 if(DeltaReleSC<DeltaRMineleSCbarrel)
00117 {
00118 DeltaRMineleSCbarrel = DeltaReleSC;
00119 nearestSCbarrel = &*scIt;
00120 iscRef = iSC;
00121 }
00122 iSC++;
00123 }
00124 iSC = 0;
00125
00126
00127 int iscRefendcap=-1;
00128
00129 for(reco::SuperClusterCollection::const_iterator scItEndcap = scIslandCollection->begin();
00130 scItEndcap != scIslandCollection->end(); scItEndcap++){
00131 #ifdef DEBUG
00132 std::cout << "EE " << scItEndcap->energy() << " " << scItEndcap->eta() << " " << scItEndcap->phi() << " " << eleIt->eta() << " " << eleIt->phi() << std::endl;
00133 #endif
00134
00135 double DeltaReleSC = sqrt ( pow( eleIt->eta() - scItEndcap->eta(),2) + pow(eleIt->phi() - scItEndcap->phi(),2));
00136
00137 if(DeltaReleSC<DeltaRMineleSCendcap)
00138 {
00139 DeltaRMineleSCendcap = DeltaReleSC;
00140 nearestSCendcap = &*scItEndcap;
00141 iscRefendcap = iSC;
00142 }
00143 iSC++;
00144 }
00146
00147 GsfElectronCoreRefProd rEleCore=e.getRefBeforePut<GsfElectronCoreCollection>();
00148 edm::Ref<GsfElectronCoreCollection>::key_type idxEleCore = 0;
00149
00150 if(nearestSCbarrel && !nearestSCendcap){
00151 reco::GsfElectronCore newEleCore(*(eleIt->core()));
00152 newEleCore.setGsfTrack(eleIt->gsfTrack());
00153 reco::SuperClusterRef scRef(reco::SuperClusterRef(pSuperClusters, iscRef));
00154 newEleCore.setSuperCluster(scRef);
00155 reco::GsfElectronCoreRef newEleCoreRef(reco::GsfElectronCoreRef(rEleCore, idxEleCore ++));
00156 pOutEleCore->push_back(newEleCore);
00157 reco::GsfElectron newEle(*eleIt,newEleCoreRef,CaloClusterPtr(),
00158
00159 TrackRef(),TrackBaseRef(), GsfTrackRefVector());
00160 newEle.setP4(eleIt->p4()*(nearestSCbarrel->energy()/eleIt->ecalEnergy()));
00161
00162 pOutEle->push_back(newEle);
00163 #ifdef DEBUG
00164 std::cout << "Association is with EB superCluster "<< std::endl;
00165 #endif
00166 }
00167
00168 if(!nearestSCbarrel && nearestSCendcap)
00169 {
00170 #ifdef DEBUG
00171 std::cout << "Starting Association is with EE superCluster "<< std::endl;
00172 #endif
00173
00174 float preshowerEnergy=eleIt->superCluster()->preshowerEnergy();
00175 #ifdef DEBUG
00176 std::cout << "preshowerEnergy"<< preshowerEnergy << std::endl;
00177 #endif
00178
00179 CaloClusterPtrVector newBCRef;
00180 for (CaloCluster_iterator bcRefIt=nearestSCendcap->clustersBegin();bcRefIt!=nearestSCendcap->clustersEnd();++bcRefIt){
00181 CaloClusterPtr cPtr(*bcRefIt);
00182 newBCRef.push_back(cPtr);
00183 }
00184
00185
00186 reco::SuperCluster newSC(nearestSCendcap->energy() + preshowerEnergy, nearestSCendcap->position() , nearestSCendcap->seed(),newBCRef , preshowerEnergy );
00187 pOutNewEndcapSC->push_back(newSC);
00188 reco::SuperClusterRef scRef(reco::SuperClusterRef(rSC, idxSC ++));
00189
00190 reco::GsfElectronCore newEleCore(*(eleIt->core()));
00191 newEleCore.setGsfTrack(eleIt->gsfTrack());
00192 newEleCore.setSuperCluster(scRef);
00193 reco::GsfElectronCoreRef newEleCoreRef(reco::GsfElectronCoreRef(rEleCore, idxEleCore ++));
00194 pOutEleCore->push_back(newEleCore);
00195 reco::GsfElectron newEle(*eleIt,newEleCoreRef,CaloClusterPtr(),
00196
00197 TrackRef(),TrackBaseRef(), GsfTrackRefVector());
00198
00199 newEle.setP4(eleIt->p4()*(newSC.energy()/eleIt->ecalEnergy())) ;
00200 pOutEle->push_back(newEle);
00201
00202 #ifdef DEBUG
00203 std::cout << "Association is with EE superCluster "<< std::endl;
00204 #endif
00205 }
00206
00207 if(nearestSCbarrel && nearestSCendcap){
00208 reco::GsfElectronCore newEleCore(*(eleIt->core()));
00209 newEleCore.setGsfTrack(eleIt->gsfTrack());
00210
00211
00212 if(DeltaRMineleSCendcap>=DeltaRMineleSCbarrel)
00213 {
00214 reco::SuperClusterRef scRef(reco::SuperClusterRef(pSuperClusters, iscRef));
00215 newEleCore.setSuperCluster(scRef);
00216 reco::GsfElectronCoreRef newEleCoreRef(reco::GsfElectronCoreRef(rEleCore, idxEleCore ++));
00217 pOutEleCore->push_back(newEleCore);
00218 reco::GsfElectron newEle(*eleIt,newEleCoreRef,CaloClusterPtr(),
00219
00220 TrackRef(),TrackBaseRef(), GsfTrackRefVector());
00221 newEle.setP4(eleIt->p4()*(nearestSCbarrel->energy()/eleIt->ecalEnergy()));
00222 pOutEle->push_back(newEle);
00223
00224
00225 #ifdef DEBUG
00226 std::cout << "Association is with EB superCluster, after quarrel "<< std::endl;
00227 #endif
00228 }
00229 else if(DeltaRMineleSCendcap<DeltaRMineleSCbarrel)
00230 {
00231 float preshowerEnergy=eleIt->superCluster()->preshowerEnergy();
00232 CaloClusterPtrVector newBCRef;
00233 for (CaloCluster_iterator bcRefIt=nearestSCendcap->clustersBegin();bcRefIt!=nearestSCendcap->clustersEnd();++bcRefIt){
00234 CaloClusterPtr cPtr(*bcRefIt);
00235 newBCRef.push_back(*bcRefIt);}
00236 reco::SuperCluster newSC(nearestSCendcap->energy() + preshowerEnergy, nearestSCendcap->position() , nearestSCendcap->seed(), newBCRef , preshowerEnergy );
00237 pOutNewEndcapSC->push_back(newSC);
00238 reco::SuperClusterRef scRef(reco::SuperClusterRef(rSC, idxSC ++));
00239 newEleCore.setSuperCluster(scRef);
00240 reco::GsfElectronCoreRef newEleCoreRef(reco::GsfElectronCoreRef(rEleCore, idxEleCore ++));
00241 pOutEleCore->push_back(newEleCore);
00242 reco::GsfElectron newEle(*eleIt,newEleCoreRef,CaloClusterPtr(),
00243
00244 TrackRef(),TrackBaseRef(), GsfTrackRefVector());
00245 newEle.setP4(eleIt->p4()*(newSC.energy()/eleIt->ecalEnergy())) ;
00246 pOutEle->push_back(newEle);
00247 #ifdef DEBUG
00248 std::cout << "Association is with EE superCluster, after quarrel "<< std::endl;
00249 #endif
00250 }
00251
00252 }
00253
00254
00255 }
00256
00257
00258
00259 #ifdef DEBUG
00260 std::cout << "Filled new electrons " << pOutEle->size() << std::endl;
00261 std::cout << "Filled new electronsCore " << pOutEleCore->size() << std::endl;
00262 std::cout << "Filled new endcapSC " << pOutNewEndcapSC->size() << std::endl;
00263 #endif
00264
00265
00266
00267 e.put(pOutEle);
00268 e.put(pOutEleCore);
00269 e.put(pOutNewEndcapSC);
00270
00271 }
00272
00273