From c5ff11917b9de6de439aebbbe4b9819dbc95e5d4 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Sat, 12 Sep 2015 09:29:45 +0200 Subject: [PATCH 1/6] add in protection for Electron regression to appropriately function on top of MiniAOD --- .../ElectronRegressionValueMapProducer.cc | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc b/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc index 9553265d647b3..9f7fd3bcb5b56 100644 --- a/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc +++ b/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc @@ -174,6 +174,9 @@ inline void calculateValues(EcalClusterLazyToolsBase* tools_tocast, const auto& the_sc = iEle->superCluster(); const auto& theseed = the_sc->seed(); + const int numberOfClusters = the_sc->clusters().size(); + const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].isAvailable(); + std::vector vCov = tools->localCovariances( *theseed ); const float eMax = tools->eMax( *theseed ); @@ -215,11 +218,7 @@ inline void calculateValues(EcalClusterLazyToolsBase* tools_tocast, veleIEta.push_back(iEta); veleCryPhi.push_back(cryPhi); veleCryEta.push_back(cryEta); - - // loop over all clusters that aren't the seed - auto clusend = the_sc->clustersEnd(); - int numberOfClusters = the_sc->clusters().size(); - + std::vector _clusterRawEnergy; _clusterRawEnergy.resize(std::max(3, numberOfClusters), 0); std::vector _clusterDEtaToSeed; @@ -234,25 +233,28 @@ inline void calculateValues(EcalClusterLazyToolsBase* tools_tocast, size_t iclus = 0; float maxDR = 0; edm::Ptr pclus; - for( auto clus = the_sc->clustersBegin(); clus != clusend; ++clus ) { - pclus = *clus; - - if(theseed == pclus ) - continue; - _clusterRawEnergy.push_back(pclus->energy()); - _clusterDPhiToSeed.push_back(reco::deltaPhi(pclus->phi(),theseed->phi())); - _clusterDEtaToSeed.push_back(pclus->eta() - theseed->eta()); - - // find cluster with max dR - if(reco::deltaR(*pclus, *theseed) > maxDR) { - maxDR = reco::deltaR(*pclus, *theseed); - _clusterMaxDR = maxDR; - _clusterMaxDRDPhi = _clusterDPhiToSeed[iclus]; - _clusterMaxDRDEta = _clusterDEtaToSeed[iclus]; - _clusterMaxDRRawEnergy = _clusterRawEnergy[iclus]; + if( !missing_clusters ) { + // loop over all clusters that aren't the seed + auto clusend = the_sc->clustersEnd(); + for( auto clus = the_sc->clustersBegin(); clus != clusend; ++clus ) { + pclus = *clus; + + if(theseed == pclus ) + continue; + _clusterRawEnergy.push_back(pclus->energy()); + _clusterDPhiToSeed.push_back(reco::deltaPhi(pclus->phi(),theseed->phi())); + _clusterDEtaToSeed.push_back(pclus->eta() - theseed->eta()); + + // find cluster with max dR + if(reco::deltaR(*pclus, *theseed) > maxDR) { + maxDR = reco::deltaR(*pclus, *theseed); + _clusterMaxDR = maxDR; + _clusterMaxDRDPhi = _clusterDPhiToSeed[iclus]; + _clusterMaxDRDEta = _clusterDEtaToSeed[iclus]; + _clusterMaxDRRawEnergy = _clusterRawEnergy[iclus]; + } + ++iclus; } - - ++iclus; } vclusterMaxDR.push_back(_clusterMaxDR); From 0c3e115fc539ac5062d76b16e1c4be5a913a753e Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Sat, 12 Sep 2015 11:11:24 +0200 Subject: [PATCH 2/6] clean up code in electron regression value map producer --- .../ElectronRegressionValueMapProducer.cc | 527 ++++++++---------- 1 file changed, 227 insertions(+), 300 deletions(-) diff --git a/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc b/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc index 9f7fd3bcb5b56..b491666c78256 100644 --- a/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc +++ b/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc @@ -20,32 +20,190 @@ #include #include +#include namespace { - constexpr char sigmaIEtaIPhi_[] = "sigmaIEtaIPhi"; - constexpr char eMax_[] = "eMax"; - constexpr char e2nd_[] = "e2nd"; - constexpr char eTop_[] = "eTop"; - constexpr char eBottom_[] = "eBottom"; - constexpr char eLeft_[] = "eLeft"; - constexpr char eRight_[] = "eRight"; - constexpr char clusterMaxDR_[] = "clusterMaxDR"; - constexpr char clusterMaxDRDPhi_[] = "clusterMaxDRDPhi"; - constexpr char clusterMaxDRDEta_[] = "clusterMaxDRDEta"; - constexpr char clusterMaxDRRawEnergy_[] = "clusterMaxDRRawEnergy"; - constexpr char clusterRawEnergy0_[] = "clusterRawEnergy0"; - constexpr char clusterRawEnergy1_[] = "clusterRawEnergy1"; - constexpr char clusterRawEnergy2_[] = "clusterRawEnergy2"; - constexpr char clusterDPhiToSeed0_[] = "clusterDPhiToSeed0"; - constexpr char clusterDPhiToSeed1_[] = "clusterDPhiToSeed1"; - constexpr char clusterDPhiToSeed2_[] = "clusterDPhiToSeed2"; - constexpr char clusterDEtaToSeed0_[] = "clusterDEtaToSeed0"; - constexpr char clusterDEtaToSeed1_[] = "clusterDEtaToSeed1"; - constexpr char clusterDEtaToSeed2_[] = "clusterDEtaToSeed2"; - constexpr char eleIPhi_[] = "iPhi"; - constexpr char eleIEta_[] = "iEta"; - constexpr char eleCryPhi_[] = "cryPhi"; - constexpr char eleCryEta_[] = "cryEta"; + enum reg_float_vars { k_sigmaIEtaIPhi = 0, + k_eMax, + k_e2nd, + k_eTop, + k_eBottom, + k_eLeft, + k_eRight, + k_clusterMaxDR, + k_clusterMaxDRDPhi, + k_clusterMaxDRDEta, + k_clusterMaxDRRawEnergy, + k_clusterRawEnergy0, + k_clusterRawEnergy1, + k_clusterRawEnergy2, + k_clusterDPhiToSeed0, + k_clusterDPhiToSeed1, + k_clusterDPhiToSeed2, + k_clusterDEtaToSeed0, + k_clusterDEtaToSeed1, + k_clusterDEtaToSeed2, + k_cryPhi, + k_cryEta, + k_NFloatVars }; + + enum reg_int_vars { k_iPhi = 0, + k_iEta, + k_NIntVars }; + + static const std::vector float_var_names( { "sigmaIEtaIPhi", + "eMax", + "e2nd", + "eTop", + "eBottom", + "eLeft", + "eRight", + "clusterMaxDR", + "clusterMaxDRDPhi", + "clusterMaxDRDEta", + "clusterMaxDRRawEnergy", + "clusterRawEnergy0", + "clusterRawEnergy1", + "clusterRawEnergy2", + "clusterDPhiToSeed0", + "clusterDPhiToSeed1", + "clusterDPhiToSeed2", + "clusterDEtaToSeed0", + "clusterDEtaToSeed1", + "clusterDEtaToSeed2", + "cryPhi", + "cryEta" } ); + + static const std::vector integer_var_names( { "iPhi", "iEta" } ); + + inline void set_map_val( const reg_float_vars index, const float value, + std::unordered_map& map) { + map[float_var_names[index]] = value; + } + inline void set_map_val( const reg_int_vars index, const int value, + std::unordered_map& map) { + map[integer_var_names[index]] = value; + } + + template + inline void check_map(const std::unordered_map& map, unsigned exp_size) { + if( map.size() != exp_size ) { + throw cms::Exception("ElectronRegressionWeirdConfig") + << "variable map size: " << map.size() + << " not equal to expected size: " << exp_size << " !" + << " The regression variable calculation code definitely has a bug, fix it!"; + } + } + + template + void calculateValues(EcalClusterLazyToolsBase* tools_tocast, + const edm::Ptr& iEle, + const edm::EventSetup& iSetup, + std::unordered_map& float_vars, + std::unordered_map& int_vars ) { + LazyTools* tools = static_cast(tools_tocast); + + const auto& the_sc = iEle->superCluster(); + const auto& theseed = the_sc->seed(); + + const int numberOfClusters = the_sc->clusters().size(); + const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].isAvailable(); + + std::vector vCov = tools->localCovariances( *theseed ); + + const float eMax = tools->eMax( *theseed ); + const float e2nd = tools->e2nd( *theseed ); + const float eTop = tools->eTop( *theseed ); + const float eLeft = tools->eLeft( *theseed ); + const float eRight = tools->eRight( *theseed ); + const float eBottom = tools->eBottom( *theseed ); + + float dummy; + int iPhi; + int iEta; + float cryPhi; + float cryEta; + EcalClusterLocal _ecalLocal; + if (iEle->isEB()) + _ecalLocal.localCoordsEB(*theseed, iSetup, cryEta, cryPhi, iEta, iPhi, dummy, dummy); + else + _ecalLocal.localCoordsEE(*theseed, iSetup, cryEta, cryPhi, iEta, iPhi, dummy, dummy); + + double see = (isnan(vCov[0]) ? 0. : sqrt(vCov[0])); + double spp = (isnan(vCov[2]) ? 0. : sqrt(vCov[2])); + double sep; + if (see*spp > 0) + sep = vCov[1] / (see * spp); + else if (vCov[1] > 0) + sep = 1.0; + else + sep = -1.0; + + set_map_val(k_sigmaIEtaIPhi,sep,float_vars); + set_map_val(k_eMax,eMax,float_vars); + set_map_val(k_e2nd,e2nd,float_vars); + set_map_val(k_eTop,eTop,float_vars); + set_map_val(k_eBottom,eBottom,float_vars); + set_map_val(k_eLeft,eLeft,float_vars); + set_map_val(k_eRight,eRight,float_vars); + set_map_val(k_cryPhi,cryPhi,float_vars); + set_map_val(k_cryEta,cryEta,float_vars); + + set_map_val(k_iPhi,iPhi,int_vars); + set_map_val(k_iEta,iEta,int_vars); + + std::vector _clusterRawEnergy; + _clusterRawEnergy.resize(std::max(3, numberOfClusters), 0); + std::vector _clusterDEtaToSeed; + _clusterDEtaToSeed.resize(std::max(3, numberOfClusters), 0); + std::vector _clusterDPhiToSeed; + _clusterDPhiToSeed.resize(std::max(3, numberOfClusters), 0); + float _clusterMaxDR = 999.; + float _clusterMaxDRDPhi = 999.; + float _clusterMaxDRDEta = 999.; + float _clusterMaxDRRawEnergy = 0.; + + size_t iclus = 0; + float maxDR = 0; + edm::Ptr pclus; + if( !missing_clusters ) { + // loop over all clusters that aren't the seed + auto clusend = the_sc->clustersEnd(); + for( auto clus = the_sc->clustersBegin(); clus != clusend; ++clus ) { + pclus = *clus; + + if(theseed == pclus ) + continue; + _clusterRawEnergy.push_back(pclus->energy()); + _clusterDPhiToSeed.push_back(reco::deltaPhi(pclus->phi(),theseed->phi())); + _clusterDEtaToSeed.push_back(pclus->eta() - theseed->eta()); + + // find cluster with max dR + if(reco::deltaR(*pclus, *theseed) > maxDR) { + maxDR = reco::deltaR(*pclus, *theseed); + _clusterMaxDR = maxDR; + _clusterMaxDRDPhi = _clusterDPhiToSeed[iclus]; + _clusterMaxDRDEta = _clusterDEtaToSeed[iclus]; + _clusterMaxDRRawEnergy = _clusterRawEnergy[iclus]; + } + ++iclus; + } + } + + set_map_val(k_clusterMaxDR,_clusterMaxDR,float_vars); + set_map_val(k_clusterMaxDRDPhi,_clusterMaxDRDPhi,float_vars); + set_map_val(k_clusterMaxDRDEta,_clusterMaxDRDEta,float_vars); + set_map_val(k_clusterMaxDRRawEnergy,_clusterMaxDRRawEnergy,float_vars); + set_map_val(k_clusterRawEnergy0,_clusterRawEnergy[0],float_vars); + set_map_val(k_clusterRawEnergy1,_clusterRawEnergy[1],float_vars); + set_map_val(k_clusterRawEnergy2,_clusterRawEnergy[2],float_vars); + set_map_val(k_clusterDPhiToSeed0,_clusterDPhiToSeed[0],float_vars); + set_map_val(k_clusterDPhiToSeed1,_clusterDPhiToSeed[1],float_vars); + set_map_val(k_clusterDPhiToSeed2,_clusterDPhiToSeed[2],float_vars); + set_map_val(k_clusterDEtaToSeed0,_clusterDEtaToSeed[0],float_vars); + set_map_val(k_clusterDEtaToSeed1,_clusterDEtaToSeed[1],float_vars); + set_map_val(k_clusterDEtaToSeed2,_clusterDEtaToSeed[2],float_vars); + } } class ElectronRegressionValueMapProducer : public edm::stream::EDProducer<> { @@ -61,15 +219,11 @@ class ElectronRegressionValueMapProducer : public edm::stream::EDProducer<> { virtual void produce(edm::Event&, const edm::EventSetup&) override; + template void writeValueMap(edm::Event &iEvent, const edm::Handle > & handle, - const std::vector & values, - const std::string & label) const ; - - void writeValueMap(edm::Event &iEvent, - const edm::Handle > & handle, - const std::vector & values, - const std::string & label) const ; + const std::vector & values, + const std::string & label) const ; std::unique_ptr lazyTools; @@ -112,164 +266,16 @@ ElectronRegressionValueMapProducer::ElectronRegressionValueMapProducer(const edm src_ = mayConsume >(iConfig.getParameter("src")); srcMiniAOD_ = mayConsume >(iConfig.getParameter("srcMiniAOD")); - produces >(sigmaIEtaIPhi_); - produces >(eMax_); - produces >(e2nd_); - produces >(eTop_); - produces >(eBottom_); - produces >(eLeft_); - produces >(eRight_); - produces >(clusterMaxDR_); - produces >(clusterMaxDRDPhi_); - produces >(clusterMaxDRDEta_); - produces >(clusterMaxDRRawEnergy_); - produces >(clusterRawEnergy0_); - produces >(clusterRawEnergy1_); - produces >(clusterRawEnergy2_); - produces >(clusterDPhiToSeed0_); - produces >(clusterDPhiToSeed1_); - produces >(clusterDPhiToSeed2_); - produces >(clusterDEtaToSeed0_); - produces >(clusterDEtaToSeed1_); - produces >(clusterDEtaToSeed2_); - produces >(eleIPhi_); - produces >(eleIEta_); - produces >(eleCryPhi_); - produces >(eleCryEta_); -} + for( const std::string& name : float_var_names ) { + produces >(name); + } -ElectronRegressionValueMapProducer::~ElectronRegressionValueMapProducer() { + for( const std::string& name : integer_var_names ) { + produces >(name); + } } -template -inline void calculateValues(EcalClusterLazyToolsBase* tools_tocast, - const edm::Ptr& iEle, - const edm::EventSetup& iSetup, - std::vector& vsigmaIEtaIPhi, - std::vector& veMax, - std::vector& ve2nd, - std::vector& veTop, - std::vector& veBottom, - std::vector& veLeft, - std::vector& veRight, - std::vector& vclusterMaxDR, - std::vector& vclusterMaxDRDPhi, - std::vector& vclusterMaxDRDEta, - std::vector& vclusterMaxDRRawEnergy, - std::vector& vclusterRawEnergy0, - std::vector& vclusterRawEnergy1, - std::vector& vclusterRawEnergy2, - std::vector& vclusterDPhiToSeed0, - std::vector& vclusterDPhiToSeed1, - std::vector& vclusterDPhiToSeed2, - std::vector& vclusterDEtaToSeed0, - std::vector& vclusterDEtaToSeed1, - std::vector& vclusterDEtaToSeed2, - std::vector& veleIPhi, - std::vector& veleIEta, - std::vector& veleCryPhi, - std::vector& veleCryEta) { - LazyTools* tools = static_cast(tools_tocast); - - const auto& the_sc = iEle->superCluster(); - const auto& theseed = the_sc->seed(); - - const int numberOfClusters = the_sc->clusters().size(); - const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].isAvailable(); - - std::vector vCov = tools->localCovariances( *theseed ); - - const float eMax = tools->eMax( *theseed ); - const float e2nd = tools->e2nd( *theseed ); - const float eTop = tools->eTop( *theseed ); - const float eLeft = tools->eLeft( *theseed ); - const float eRight = tools->eRight( *theseed ); - const float eBottom = tools->eBottom( *theseed ); - - float dummy; - int iPhi; - int iEta; - float cryPhi; - float cryEta; - EcalClusterLocal _ecalLocal; - if (iEle->isEB()) - _ecalLocal.localCoordsEB(*theseed, iSetup, cryEta, cryPhi, iEta, iPhi, dummy, dummy); - else - _ecalLocal.localCoordsEE(*theseed, iSetup, cryEta, cryPhi, iEta, iPhi, dummy, dummy); - - double see = (isnan(vCov[0]) ? 0. : sqrt(vCov[0])); - double spp = (isnan(vCov[2]) ? 0. : sqrt(vCov[2])); - double sep; - if (see*spp > 0) - sep = vCov[1] / (see * spp); - else if (vCov[1] > 0) - sep = 1.0; - else - sep = -1.0; - - vsigmaIEtaIPhi.push_back(sep); - veMax.push_back(eMax); - ve2nd.push_back(e2nd); - veTop.push_back(eTop); - veBottom.push_back(eBottom); - veLeft.push_back(eLeft); - veRight.push_back(eRight); - veleIPhi.push_back(iPhi); - veleIEta.push_back(iEta); - veleCryPhi.push_back(cryPhi); - veleCryEta.push_back(cryEta); - - std::vector _clusterRawEnergy; - _clusterRawEnergy.resize(std::max(3, numberOfClusters), 0); - std::vector _clusterDEtaToSeed; - _clusterDEtaToSeed.resize(std::max(3, numberOfClusters), 0); - std::vector _clusterDPhiToSeed; - _clusterDPhiToSeed.resize(std::max(3, numberOfClusters), 0); - float _clusterMaxDR = 999.; - float _clusterMaxDRDPhi = 999.; - float _clusterMaxDRDEta = 999.; - float _clusterMaxDRRawEnergy = 0.; - - size_t iclus = 0; - float maxDR = 0; - edm::Ptr pclus; - if( !missing_clusters ) { - // loop over all clusters that aren't the seed - auto clusend = the_sc->clustersEnd(); - for( auto clus = the_sc->clustersBegin(); clus != clusend; ++clus ) { - pclus = *clus; - - if(theseed == pclus ) - continue; - _clusterRawEnergy.push_back(pclus->energy()); - _clusterDPhiToSeed.push_back(reco::deltaPhi(pclus->phi(),theseed->phi())); - _clusterDEtaToSeed.push_back(pclus->eta() - theseed->eta()); - - // find cluster with max dR - if(reco::deltaR(*pclus, *theseed) > maxDR) { - maxDR = reco::deltaR(*pclus, *theseed); - _clusterMaxDR = maxDR; - _clusterMaxDRDPhi = _clusterDPhiToSeed[iclus]; - _clusterMaxDRDEta = _clusterDEtaToSeed[iclus]; - _clusterMaxDRRawEnergy = _clusterRawEnergy[iclus]; - } - ++iclus; - } - } - - vclusterMaxDR.push_back(_clusterMaxDR); - vclusterMaxDRDPhi.push_back(_clusterMaxDRDPhi); - vclusterMaxDRDEta.push_back(_clusterMaxDRDEta); - vclusterMaxDRRawEnergy.push_back(_clusterMaxDRRawEnergy); - vclusterRawEnergy0.push_back(_clusterRawEnergy[0]); - vclusterRawEnergy1.push_back(_clusterRawEnergy[1]); - vclusterRawEnergy2.push_back(_clusterRawEnergy[2]); - vclusterDPhiToSeed0.push_back(_clusterDPhiToSeed[0]); - vclusterDPhiToSeed1.push_back(_clusterDPhiToSeed[1]); - vclusterDPhiToSeed2.push_back(_clusterDPhiToSeed[2]); - vclusterDEtaToSeed0.push_back(_clusterDEtaToSeed[0]); - vclusterDEtaToSeed1.push_back(_clusterDEtaToSeed[1]); - vclusterDEtaToSeed2.push_back(_clusterDEtaToSeed[2]); +ElectronRegressionValueMapProducer::~ElectronRegressionValueMapProducer() { } void ElectronRegressionValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { @@ -310,30 +316,11 @@ void ElectronRegressionValueMapProducer::produce(edm::Event& iEvent, const edm:: ebrh, eerh, esrh ); } - std::vector sigmaIEtaIPhi; - std::vector eMax; - std::vector e2nd; - std::vector eTop; - std::vector eBottom; - std::vector eLeft; - std::vector eRight; - std::vector clusterMaxDR; - std::vector clusterMaxDRDPhi; - std::vector clusterMaxDRDEta; - std::vector clusterMaxDRRawEnergy; - std::vector clusterRawEnergy0; - std::vector clusterRawEnergy1; - std::vector clusterRawEnergy2; - std::vector clusterDPhiToSeed0; - std::vector clusterDPhiToSeed1; - std::vector clusterDPhiToSeed2; - std::vector clusterDEtaToSeed0; - std::vector clusterDEtaToSeed1; - std::vector clusterDEtaToSeed2; - std::vector eleIPhi; - std::vector eleIEta; - std::vector eleCryPhi; - std::vector eleCryEta; + std::vector > float_vars(k_NFloatVars); + std::vector > int_vars(k_NIntVars); + + std::unordered_map float_vars_map; + std::unordered_map int_vars_map; // reco::GsfElectron::superCluster() is virtual so we can exploit polymorphism for (size_t i = 0; i < src->size(); ++i){ @@ -343,111 +330,51 @@ void ElectronRegressionValueMapProducer::produce(edm::Event& iEvent, const edm:: calculateValues(lazyTools.get(), iEle, iSetup, - sigmaIEtaIPhi, - eMax, - e2nd, - eTop, - eBottom, - eLeft, - eRight, - clusterMaxDR, - clusterMaxDRDPhi, - clusterMaxDRDEta, - clusterMaxDRRawEnergy, - clusterRawEnergy0, - clusterRawEnergy1, - clusterRawEnergy2, - clusterDPhiToSeed0, - clusterDPhiToSeed1, - clusterDPhiToSeed2, - clusterDEtaToSeed0, - clusterDEtaToSeed1, - clusterDEtaToSeed2, - eleIPhi, - eleIEta, - eleCryPhi, - eleCryEta); + float_vars_map, + int_vars_map); } else { calculateValues(lazyTools.get(), iEle, iSetup, - sigmaIEtaIPhi, - eMax, - e2nd, - eTop, - eBottom, - eLeft, - eRight, - clusterMaxDR, - clusterMaxDRDPhi, - clusterMaxDRDEta, - clusterMaxDRRawEnergy, - clusterRawEnergy0, - clusterRawEnergy1, - clusterRawEnergy2, - clusterDPhiToSeed0, - clusterDPhiToSeed1, - clusterDPhiToSeed2, - clusterDEtaToSeed0, - clusterDEtaToSeed1, - clusterDEtaToSeed2, - eleIPhi, - eleIEta, - eleCryPhi, - eleCryEta); + float_vars_map, + int_vars_map); + } + + check_map(float_vars_map, k_NFloatVars); + check_map(int_vars_map, k_NIntVars); + + for( unsigned i = 0; i < float_vars.size(); ++i ) { + float_vars[i].emplace_back(float_vars_map.at(float_var_names[i])); + } + + for( unsigned i = 0; i < int_vars.size(); ++i ) { + int_vars[i].emplace_back(int_vars_map.at(integer_var_names[i])); } } - writeValueMap(iEvent, src, sigmaIEtaIPhi, sigmaIEtaIPhi_); - writeValueMap(iEvent, src, eMax ,eMax_); - writeValueMap(iEvent, src, e2nd ,e2nd_); - writeValueMap(iEvent, src, eTop ,eTop_); - writeValueMap(iEvent, src, eBottom ,eBottom_); - writeValueMap(iEvent, src, eLeft ,eLeft_); - writeValueMap(iEvent, src, eRight ,eRight_); - writeValueMap(iEvent, src, clusterMaxDR, clusterMaxDR_); - writeValueMap(iEvent, src, clusterMaxDRDPhi, clusterMaxDRDPhi_); - writeValueMap(iEvent, src, clusterMaxDRDEta, clusterMaxDRDEta_); - writeValueMap(iEvent, src, clusterMaxDRRawEnergy,clusterMaxDRRawEnergy_); - writeValueMap(iEvent, src, clusterRawEnergy0, clusterRawEnergy0_); - writeValueMap(iEvent, src, clusterRawEnergy1, clusterRawEnergy1_); - writeValueMap(iEvent, src, clusterRawEnergy2, clusterRawEnergy2_); - writeValueMap(iEvent, src, clusterDPhiToSeed0, clusterDPhiToSeed0_); - writeValueMap(iEvent, src, clusterDPhiToSeed1, clusterDPhiToSeed1_); - writeValueMap(iEvent, src, clusterDPhiToSeed2, clusterDPhiToSeed2_); - writeValueMap(iEvent, src, clusterDEtaToSeed0, clusterDEtaToSeed0_); - writeValueMap(iEvent, src, clusterDEtaToSeed1, clusterDEtaToSeed1_); - writeValueMap(iEvent, src, clusterDEtaToSeed2, clusterDEtaToSeed2_); - writeValueMap(iEvent, src, eleIPhi ,eleIPhi_); - writeValueMap(iEvent, src, eleIEta ,eleIEta_); - writeValueMap(iEvent, src, eleCryPhi ,eleCryPhi_); - writeValueMap(iEvent, src, eleCryEta ,eleCryEta_); + for( unsigned i = 0; i < float_vars.size(); ++i ) { + writeValueMap(iEvent, src, float_vars[i], float_var_names[i]); + } + + for( unsigned i = 0; i < int_vars.size(); ++i ) { + writeValueMap(iEvent, src, int_vars[i], integer_var_names[i]); + } + lazyTools.reset(); } +template void ElectronRegressionValueMapProducer::writeValueMap(edm::Event &iEvent, - const edm::Handle > & handle, - const std::vector & values, - const std::string & label) const + const edm::Handle > & handle, + const std::vector & values, + const std::string & label) const { using namespace edm; using namespace std; - auto_ptr > valMap(new ValueMap()); - edm::ValueMap::Filler filler(*valMap); - filler.insert(handle, values.begin(), values.end()); - filler.fill(); - iEvent.put(valMap, label); -} + typedef ValueMap TValueMap; -void ElectronRegressionValueMapProducer::writeValueMap(edm::Event &iEvent, - const edm::Handle > & handle, - const std::vector & values, - const std::string & label) const -{ - using namespace edm; - using namespace std; - auto_ptr > valMap(new ValueMap()); - edm::ValueMap::Filler filler(*valMap); + auto_ptr valMap(new TValueMap()); + typename TValueMap::Filler filler(*valMap); filler.insert(handle, values.begin(), values.end()); filler.fill(); iEvent.put(valMap, label); From 89cb06debc3cdd37947a60b13109be7321534358 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Sat, 12 Sep 2015 11:38:25 +0200 Subject: [PATCH 3/6] clean up code in photon regression value map producer --- .../PhotonRegressionValueMapProducer.cc | 183 +++++++++++------- 1 file changed, 108 insertions(+), 75 deletions(-) diff --git a/RecoEgamma/PhotonIdentification/plugins/PhotonRegressionValueMapProducer.cc b/RecoEgamma/PhotonIdentification/plugins/PhotonRegressionValueMapProducer.cc index 2883767a6852e..483716f5e8fae 100644 --- a/RecoEgamma/PhotonIdentification/plugins/PhotonRegressionValueMapProducer.cc +++ b/RecoEgamma/PhotonIdentification/plugins/PhotonRegressionValueMapProducer.cc @@ -18,16 +18,71 @@ #include #include +#include namespace { // Cluster shapes - constexpr char sigmaIPhiIPhi_[] = "sigmaIPhiIPhi"; - constexpr char sigmaIEtaIPhi_[] = "sigmaIEtaIPhi"; - constexpr char e2x5Max_[] = "e2x5Max"; - constexpr char e2x5Left_[] = "e2x5Left"; - constexpr char e2x5Right_[] = "e2x5Right"; - constexpr char e2x5Top_[] = "e2x5Top"; - constexpr char e2x5Bottom_[] = "e2x5Bottom"; + enum reg_float_vars { k_sigmaIPhiIPhi = 0, + k_sigmaIEtaIPhi, + k_e2x5Max, + k_e2x5Left, + k_e2x5Right, + k_e2x5Top, + k_e2x5Bottom, + k_NFloatVars }; + + enum reg_int_vars { k_NIntVars = 0 }; + + static const std::vector float_var_names( { "sigmaIPhiIPhi", + "sigmaIEtaIPhi", + "e2x5Max", + "e2x5Left", + "e2x5Right", + "e2x5Top", + "e2x5Bottom" } ); + + static const std::vector integer_var_names( { } ); + + inline void set_map_val( const reg_float_vars index, const float value, + std::unordered_map& map) { + map[float_var_names[index]] = value; + } + inline void set_map_val( const reg_int_vars index, const int value, + std::unordered_map& map) { + map[integer_var_names[index]] = value; + } + + template + inline void check_map(const std::unordered_map& map, unsigned exp_size) { + if( map.size() != exp_size ) { + throw cms::Exception("PhotonRegressionWeirdConfig") + << "variable map size: " << map.size() + << " not equal to expected size: " << exp_size << " !" + << " The regression variable calculation code definitely has a bug, fix it!"; + } + } + + template + inline void calculateValues(EcalClusterLazyToolsBase* tools_tocast, + const SeedType& the_seed, + std::unordered_map& float_vars, + std::unordered_map& /*int_vars*/ ) { + LazyTools* tools = static_cast(tools_tocast); + + float spp = -999; + std::vector vCov = tools->localCovariances( the_seed ); + spp = (isnan(vCov[2]) ? 0. : sqrt(vCov[2])); + float sep = vCov[1]; + + set_map_val(k_sigmaIPhiIPhi, spp, float_vars); + set_map_val(k_sigmaIEtaIPhi, sep, float_vars); + + set_map_val(k_e2x5Max, tools->e2x5Max(the_seed), float_vars); + set_map_val(k_e2x5Left, tools->e2x5Left(the_seed), float_vars); + set_map_val(k_e2x5Right, tools->e2x5Right(the_seed), float_vars); + set_map_val(k_e2x5Top, tools->e2x5Top(the_seed), float_vars); + set_map_val(k_e2x5Bottom, tools->e2x5Bottom(the_seed), float_vars); + } } class PhotonRegressionValueMapProducer : public edm::stream::EDProducer<> { @@ -43,9 +98,10 @@ class PhotonRegressionValueMapProducer : public edm::stream::EDProducer<> { virtual void produce(edm::Event&, const edm::EventSetup&) override; + template void writeValueMap(edm::Event &iEvent, const edm::Handle > & handle, - const std::vector & values, + const std::vector & values, const std::string & label) const ; // The object that will compute 5x5 quantities @@ -95,43 +151,18 @@ PhotonRegressionValueMapProducer::PhotonRegressionValueMapProducer(const edm::Pa // Declare producibles // // Cluster shapes - produces >(sigmaIPhiIPhi_); - produces >(sigmaIEtaIPhi_); - produces >(e2x5Max_); - produces >(e2x5Left_); - produces >(e2x5Right_); - produces >(e2x5Top_); - produces >(e2x5Bottom_); + for( const std::string& name : float_var_names ) { + produces >(name); + } + + for( const std::string& name : integer_var_names ) { + produces >(name); + } } PhotonRegressionValueMapProducer::~PhotonRegressionValueMapProducer() {} -template -inline void calculateValues(EcalClusterLazyToolsBase* tools_tocast, - const SeedType& the_seed, - std::vector& sigmaIPhiIPhi, - std::vector& sigmaIEtaIPhi, - std::vector& e2x5Max, - std::vector& e2x5Left, - std::vector& e2x5Right, - std::vector& e2x5Top, - std::vector& e2x5Bottom) { - LazyTools* tools = static_cast(tools_tocast); - - float spp = -999; - std::vector vCov = tools->localCovariances( the_seed ); - spp = (isnan(vCov[2]) ? 0. : sqrt(vCov[2])); - float sep = vCov[1]; - sigmaIPhiIPhi.push_back(spp); - sigmaIEtaIPhi.push_back(sep); - e2x5Max .push_back(tools->e2x5Max(the_seed) ); - e2x5Left .push_back(tools->e2x5Left(the_seed) ); - e2x5Right .push_back(tools->e2x5Right(the_seed) ); - e2x5Top .push_back(tools->e2x5Top(the_seed) ); - e2x5Bottom.push_back(tools->e2x5Bottom(the_seed) ); -} - void PhotonRegressionValueMapProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; @@ -179,14 +210,11 @@ void PhotonRegressionValueMapProducer::produce(edm::Event& iEvent, const edm::Ev } } - // Cluster shapes - std::vector sigmaIPhiIPhi; - std::vector sigmaIEtaIPhi; - std::vector e2x5Max; - std::vector e2x5Left; - std::vector e2x5Right; - std::vector e2x5Top; - std::vector e2x5Bottom; + std::vector > float_vars(k_NFloatVars); + std::vector > int_vars(k_NIntVars); + + std::unordered_map float_vars_map; + std::unordered_map int_vars_map; // reco::Photon::superCluster() is virtual so we can exploit polymorphism for (unsigned idxpho = 0; idxpho < src->size(); ++idxpho) { @@ -200,47 +228,52 @@ void PhotonRegressionValueMapProducer::produce(edm::Event& iEvent, const edm::Ev if( use_full5x5_ ) { calculateValues(lazyTools.get(), theseed, - sigmaIPhiIPhi, - sigmaIEtaIPhi, - e2x5Max, - e2x5Left, - e2x5Right, - e2x5Top, - e2x5Bottom); + float_vars_map, + int_vars_map); } else { calculateValues(lazyTools.get(), theseed, - sigmaIPhiIPhi, - sigmaIEtaIPhi, - e2x5Max, - e2x5Left, - e2x5Right, - e2x5Top, - e2x5Bottom); - } + float_vars_map, + int_vars_map); + } + + check_map(float_vars_map, k_NFloatVars); + check_map(int_vars_map, k_NIntVars); + + for( unsigned i = 0; i < float_vars.size(); ++i ) { + float_vars[i].emplace_back(float_vars_map.at(float_var_names[i])); + } + + + for( unsigned i = 0; i < int_vars.size(); ++i ) { + int_vars[i].emplace_back(int_vars_map.at(integer_var_names[i])); + } + + } + + for( unsigned i = 0; i < float_vars.size(); ++i ) { + writeValueMap(iEvent, src, float_vars[i], float_var_names[i]); + } + + for( unsigned i = 0; i < int_vars.size(); ++i ) { + writeValueMap(iEvent, src, int_vars[i], integer_var_names[i]); } - // Cluster shapes - writeValueMap(iEvent, src, sigmaIPhiIPhi, sigmaIPhiIPhi_); - writeValueMap(iEvent, src, sigmaIEtaIPhi, sigmaIEtaIPhi_); - writeValueMap(iEvent, src, e2x5Max, e2x5Max_); - writeValueMap(iEvent, src, e2x5Left, e2x5Left_); - writeValueMap(iEvent, src, e2x5Right, e2x5Right_); - writeValueMap(iEvent, src, e2x5Top, e2x5Top_); - writeValueMap(iEvent, src, e2x5Bottom, e2x5Bottom_); - lazyTools.reset(nullptr); } +template void PhotonRegressionValueMapProducer::writeValueMap(edm::Event &iEvent, const edm::Handle > & handle, - const std::vector & values, + const std::vector & values, const std::string & label) const { using namespace edm; using namespace std; - auto_ptr > valMap(new ValueMap()); - edm::ValueMap::Filler filler(*valMap); + typedef ValueMap TValueMap; + + auto_ptr valMap(new TValueMap()); + typename TValueMap::Filler filler(*valMap); filler.insert(handle, values.begin(), values.end()); filler.fill(); iEvent.put(valMap, label); From 85237cf3c288534438ca61afe904264fe384bcac Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Sat, 12 Sep 2015 12:35:02 +0200 Subject: [PATCH 4/6] unit tests for electron VID --- .../ElectronIdentification/test/BuildFile.xml | 9 ++ .../test/runElectron_VID.py | 82 +++++++++++++++++++ ...untestRecoEgammaElectronIdentification.cpp | 3 + .../ElectronIdentification/test/runtests.sh | 15 ++++ 4 files changed, 109 insertions(+) create mode 100644 RecoEgamma/ElectronIdentification/test/runElectron_VID.py create mode 100644 RecoEgamma/ElectronIdentification/test/runtestRecoEgammaElectronIdentification.cpp create mode 100755 RecoEgamma/ElectronIdentification/test/runtests.sh diff --git a/RecoEgamma/ElectronIdentification/test/BuildFile.xml b/RecoEgamma/ElectronIdentification/test/BuildFile.xml index 21cd10519db7c..1a03c5de4ded7 100644 --- a/RecoEgamma/ElectronIdentification/test/BuildFile.xml +++ b/RecoEgamma/ElectronIdentification/test/BuildFile.xml @@ -6,10 +6,19 @@ + + + + + + + + + diff --git a/RecoEgamma/ElectronIdentification/test/runElectron_VID.py b/RecoEgamma/ElectronIdentification/test/runElectron_VID.py new file mode 100644 index 0000000000000..3d12ffadd1289 --- /dev/null +++ b/RecoEgamma/ElectronIdentification/test/runElectron_VID.py @@ -0,0 +1,82 @@ +import FWCore.ParameterSet.Config as cms +import sys + +process = cms.Process("TestElectrons") + +process.load("FWCore.MessageService.MessageLogger_cfi") +process.MessageLogger.cerr.FwkReport.reportEvery = 100 + +process.load("Configuration.StandardSequences.GeometryDB_cff") + +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") +# NOTE: the pick the right global tag! +# for PHYS14 scenario PU4bx50 : global tag is ??? +# for PHYS14 scenario PU20bx25: global tag is PHYS14_25_V1 +# as a rule, find the global tag in the DAS under the Configs for given dataset +#process.GlobalTag.globaltag = 'PHYS14_25_V1::All' +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '') + +# +# Define input data to read +# +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1000) ) + +inputFilesAOD = cms.untracked.vstring( + # AOD test files from /store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1 + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/3ADB5D32-DD4F-E511-AC01-002618943811.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/54B6CF34-DD4F-E511-9629-002590596490.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/8043D96A-6C4F-E511-81E7-003048FFD736.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/8E554BD2-6D4F-E511-BFD2-0025905A60DE.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/98EB5C3F-6D4F-E511-910B-0025905A6056.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/9C8CF66A-6C4F-E511-BD02-00259059391E.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/D015FB85-6C4F-E511-88FE-002618943902.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/D873CC62-6C4F-E511-ABBA-0025905B855E.root' + ) + +inputFilesMiniAOD = cms.untracked.vstring( + # MiniAOD test files from /store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/MINIAODSIM/PU25ns_76X_mcRun2_asymptotic_v1-v1 + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/MINIAODSIM/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/BE21962F-DD4F-E511-B681-002354EF3BDF.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValZEE_13/MINIAODSIM/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/D2B5E032-DD4F-E511-96A4-0025905A610C.root' + ) + +# Set up input/output depending on the format +# You can list here either AOD or miniAOD files, but not both types mixed +# + +print sys.argv[2] +useAOD = bool(int(sys.argv[2])) + +if useAOD == True : + inputFiles = inputFilesAOD + outputFile = "electron_ntuple.root" + print("AOD input files are used") +else : + inputFiles = inputFilesMiniAOD + outputFile = "electron_ntuple_mini.root" + print("MiniAOD input files are used") +process.source = cms.Source ("PoolSource", fileNames = inputFiles ) + +# +# Set up electron ID (VID framework) +# + +from PhysicsTools.SelectorUtils.tools.vid_id_tools import * +# turn on VID producer, indicate data format to be +# DataFormat.AOD or DataFormat.MiniAOD, as appropriate +if useAOD == True : + dataFormat = DataFormat.AOD +else : + dataFormat = DataFormat.MiniAOD + +switchOnVIDElectronIdProducer(process, dataFormat) + +# define which IDs we want to produce +my_id_modules = [sys.argv[3]] + +#add them to the VID producer +for idmod in my_id_modules: + setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection) + +# Make sure to add the ID sequence upstream from the user analysis module +process.p = cms.Path(process.egmGsfElectronIDSequence) diff --git a/RecoEgamma/ElectronIdentification/test/runtestRecoEgammaElectronIdentification.cpp b/RecoEgamma/ElectronIdentification/test/runtestRecoEgammaElectronIdentification.cpp new file mode 100644 index 0000000000000..b2991bd18ae57 --- /dev/null +++ b/RecoEgamma/ElectronIdentification/test/runtestRecoEgammaElectronIdentification.cpp @@ -0,0 +1,3 @@ +#include "FWCore/Utilities/interface/TestHelper.h" + +RUNTEST() diff --git a/RecoEgamma/ElectronIdentification/test/runtests.sh b/RecoEgamma/ElectronIdentification/test/runtests.sh new file mode 100755 index 0000000000000..d678321462770 --- /dev/null +++ b/RecoEgamma/ElectronIdentification/test/runtests.sh @@ -0,0 +1,15 @@ +function die { echo $1: status $2 ; exit $2; } + +ids_to_test=( +"RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_PHYS14_PU20bx25_V2_cff" +"RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Spring15_25ns_V1_cff" +"RecoEgamma.ElectronIdentification.Identification.cutBasedElectronID_Spring15_50ns_V1_cff" +"RecoEgamma.ElectronIdentification.Identification.heepElectronID_HEEPV60_cff" +"RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring15_25ns_nonTrig_V1_cff" +) + +for id_set in "${ids_to_test[@]}"; do + echo Checking: $id_set + cmsRun ${LOCAL_TEST_DIR}/runElectron_VID.py 1 $id_set || die "Failure using runElectron_VID.py on AOD $id_set" $? + cmsRun ${LOCAL_TEST_DIR}/runElectron_VID.py 0 $id_set || die "Failure using runElectron_VID.py on MiniAOD $id_set" $? +done \ No newline at end of file From 209865c2f8738567a4ae240141b1352e69fa4983 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Sat, 12 Sep 2015 14:12:40 +0200 Subject: [PATCH 5/6] unit tests for photon VID --- .../PhotonIdentification/test/BuildFile.xml | 6 ++ .../test/runPhoton_VID.py | 82 +++++++++++++++++++ .../runtestRecoEgammaPhotonIdentification.cpp | 3 + .../PhotonIdentification/test/runtests.sh | 14 ++++ 4 files changed, 105 insertions(+) create mode 100644 RecoEgamma/PhotonIdentification/test/BuildFile.xml create mode 100644 RecoEgamma/PhotonIdentification/test/runPhoton_VID.py create mode 100644 RecoEgamma/PhotonIdentification/test/runtestRecoEgammaPhotonIdentification.cpp create mode 100755 RecoEgamma/PhotonIdentification/test/runtests.sh diff --git a/RecoEgamma/PhotonIdentification/test/BuildFile.xml b/RecoEgamma/PhotonIdentification/test/BuildFile.xml new file mode 100644 index 0000000000000..a0888612613e2 --- /dev/null +++ b/RecoEgamma/PhotonIdentification/test/BuildFile.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/RecoEgamma/PhotonIdentification/test/runPhoton_VID.py b/RecoEgamma/PhotonIdentification/test/runPhoton_VID.py new file mode 100644 index 0000000000000..5f374122fcf22 --- /dev/null +++ b/RecoEgamma/PhotonIdentification/test/runPhoton_VID.py @@ -0,0 +1,82 @@ +import FWCore.ParameterSet.Config as cms +import sys + +process = cms.Process("TestPhotons") + +process.load("FWCore.MessageService.MessageLogger_cfi") +process.MessageLogger.cerr.FwkReport.reportEvery = 100 + +process.load("Configuration.StandardSequences.GeometryDB_cff") + +process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff") +# NOTE: the pick the right global tag! +# for PHYS14 scenario PU4bx50 : global tag is ??? +# for PHYS14 scenario PU20bx25: global tag is PHYS14_25_V1 +# as a rule, find the global tag in the DAS under the Configs for given dataset +#process.GlobalTag.globaltag = 'PHYS14_25_V1::All' +from Configuration.AlCa.GlobalTag import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '') + +# +# Define input data to read +# +process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(1000) ) + +inputFilesAOD = cms.untracked.vstring( + # AOD test files from /store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1 + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/0E37A324-714F-E511-B658-003048FFD770.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/18C42D26-714F-E511-90A9-0025905B855C.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/2448F11B-734F-E511-99C8-0025905A608E.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/3A648F28-E64F-E511-9291-0026189438E1.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/5211471B-724F-E511-9B00-0025905A613C.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/8C6C961C-734F-E511-92F5-003048FF9AC6.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/BC2BE168-E74F-E511-B126-0025905A60B0.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/BEA93A19-724F-E511-B0C0-0025905A60F4.root' + ) + +inputFilesMiniAOD = cms.untracked.vstring( + # MiniAOD test files from /store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/GEN-SIM-RECO/PU25ns_76X_mcRun2_asymptotic_v1-v1 + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/MINIAODSIM/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/14954967-E74F-E511-BEF2-0026189438EF.root', + '/store/relval/CMSSW_7_6_0_pre4/RelValH130GGgluonfusion_13/MINIAODSIM/PU25ns_76X_mcRun2_asymptotic_v1-v1/00000/2061DB66-E74F-E511-9531-0026189438DB.root' + ) + +# Set up input/output depending on the format +# You can list here either AOD or miniAOD files, but not both types mixed +# + +print sys.argv[2] +useAOD = bool(int(sys.argv[2])) + +if useAOD == True : + inputFiles = inputFilesAOD + outputFile = "photon_ntuple.root" + print("AOD input files are used") +else : + inputFiles = inputFilesMiniAOD + outputFile = "photon_ntuple_mini.root" + print("MiniAOD input files are used") +process.source = cms.Source ("PoolSource", fileNames = inputFiles ) + +# +# Set up electron ID (VID framework) +# + +from PhysicsTools.SelectorUtils.tools.vid_id_tools import * +# turn on VID producer, indicate data format to be +# DataFormat.AOD or DataFormat.MiniAOD, as appropriate +if useAOD == True : + dataFormat = DataFormat.AOD +else : + dataFormat = DataFormat.MiniAOD + +switchOnVIDPhotonIdProducer(process, dataFormat) + +# define which IDs we want to produce +my_id_modules = [sys.argv[3]] + +#add them to the VID producer +for idmod in my_id_modules: + setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection) + +# Make sure to add the ID sequence upstream from the user analysis module +process.p = cms.Path(process.egmPhotonIDSequence) diff --git a/RecoEgamma/PhotonIdentification/test/runtestRecoEgammaPhotonIdentification.cpp b/RecoEgamma/PhotonIdentification/test/runtestRecoEgammaPhotonIdentification.cpp new file mode 100644 index 0000000000000..b2991bd18ae57 --- /dev/null +++ b/RecoEgamma/PhotonIdentification/test/runtestRecoEgammaPhotonIdentification.cpp @@ -0,0 +1,3 @@ +#include "FWCore/Utilities/interface/TestHelper.h" + +RUNTEST() diff --git a/RecoEgamma/PhotonIdentification/test/runtests.sh b/RecoEgamma/PhotonIdentification/test/runtests.sh new file mode 100755 index 0000000000000..57286bfbbc456 --- /dev/null +++ b/RecoEgamma/PhotonIdentification/test/runtests.sh @@ -0,0 +1,14 @@ +function die { echo $1: status $2 ; exit $2; } + +ids_to_test=( +"RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_PHYS14_PU20bx25_V2_cff" +"RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring15_50ns_V1_cff" +"RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring15_25ns_nonTrig_V2_cff" +"RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring15_50ns_nonTrig_V2_cff" +) + +for id_set in "${ids_to_test[@]}"; do + echo Checking: $id_set + cmsRun ${LOCAL_TEST_DIR}/runPhoton_VID.py 1 $id_set || die "Failure using runPhoton_VID.py on AOD $id_set" $? + cmsRun ${LOCAL_TEST_DIR}/runPhoton_VID.py 0 $id_set || die "Failure using runPhoton_VID.py on MiniAOD $id_set" $? +done \ No newline at end of file From 8b65eb71babfe2a711f4d6ebde182acd14750a90 Mon Sep 17 00:00:00 2001 From: Lindsey Gray Date: Sun, 13 Sep 2015 12:53:24 +0200 Subject: [PATCH 6/6] use [iclus] instead of push_back on resized vectors --- .../plugins/ElectronRegressionValueMapProducer.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc b/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc index b491666c78256..2b4c926e2d732 100644 --- a/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc +++ b/RecoEgamma/ElectronIdentification/plugins/ElectronRegressionValueMapProducer.cc @@ -174,9 +174,9 @@ namespace { if(theseed == pclus ) continue; - _clusterRawEnergy.push_back(pclus->energy()); - _clusterDPhiToSeed.push_back(reco::deltaPhi(pclus->phi(),theseed->phi())); - _clusterDEtaToSeed.push_back(pclus->eta() - theseed->eta()); + _clusterRawEnergy[iclus] = pclus->energy(); + _clusterDPhiToSeed[iclus] = reco::deltaPhi(pclus->phi(),theseed->phi()); + _clusterDEtaToSeed[iclus] = pclus->eta() - theseed->eta(); // find cluster with max dR if(reco::deltaR(*pclus, *theseed) > maxDR) {