From df878d9bbc19d830bad63abca5a792d4132bdce2 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 15:01:07 +0100 Subject: [PATCH 01/58] MCEmbeddingTools: update BuildFile --- TauAnalysis/MCEmbeddingTools/plugins/BuildFile.xml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/BuildFile.xml b/TauAnalysis/MCEmbeddingTools/plugins/BuildFile.xml index 33c623f453439..0a5bb71cd687a 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/BuildFile.xml +++ b/TauAnalysis/MCEmbeddingTools/plugins/BuildFile.xml @@ -1,12 +1,14 @@ - - - - + + + + + + From ff041baa287bbf6df5f268c0a7d012473021c0d3 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 15:04:39 +0100 Subject: [PATCH 02/58] MCEmbeddingTools: update CollectionMerger --- .../plugins/CollectionMerger.cc | 173 ++++++++++++++++-- .../plugins/CollectionMerger.h | 36 +++- 2 files changed, 191 insertions(+), 18 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc index a2bcde4d44df2..37c74eee9a518 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc @@ -7,6 +7,14 @@ #include "DataFormats/EcalRecHit/interface/EcalRecHit.h" #include "DataFormats/Common/interface/SortedCollection.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" +#include "DataFormats/EgammaReco/interface/SuperCluster.h" + +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" + +#include "DataFormats/CaloRecHit/interface/CaloCluster.h" + #include "DataFormats/MuonDetId/interface/DTLayerId.h" #include "DataFormats/DTRecHit/interface/DTSLRecCluster.h" #include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h" @@ -17,12 +25,28 @@ #include "DataFormats/RPCRecHit/interface/RPCRecHit.h" #include "DataFormats/HcalRecHit/interface/ZDCRecHit.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "DataFormats/TrackReco/interface/TrackToTrackMap.h" + +#include "DataFormats/EgammaReco/interface/ElectronSeed.h" +#include "DataFormats/ParticleFlowReco/interface/PreId.h" + +#include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h" + +#include "DataFormats/EgammaCandidates/interface/Conversion.h" + +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/Candidate/interface/VertexCompositeCandidate.h" + #include "DataFormats/Common/interface/RangeMap.h" #include "DataFormats/Common/interface/OwnVector.h" typedef CollectionMerger, SiPixelCluster> PixelColMerger; typedef CollectionMerger, SiStripCluster> StripColMerger; +typedef CollectionMerger, reco::ElectronSeed> ElectronSeedColMerger; +typedef CollectionMerger, reco::ElectronSeed> EcalDrivenElectronSeedColMerger; typedef CollectionMerger, EcalRecHit> EcalRecHitColMerger; typedef CollectionMerger, HBHERecHit> HBHERecHitColMerger; typedef CollectionMerger, HFRecHit> HFRecHitColMerger; @@ -34,6 +58,18 @@ typedef CollectionMerger typedef CollectionMerger >, CSCRecHit2D> CSCRecHitColMerger; typedef CollectionMerger >, RPCRecHit> RPCRecHitColMerger; +template +void CollectionMerger::willconsume(const edm::ParameterSet& iConfig) +{ + +} + +template +void CollectionMerger::willproduce(std::string instance, std::string alias) +{ + produces(instance); +} + // -------- Here Tracker Merger ----------- template void CollectionMerger::fill_output_obj_tracker(std::unique_ptr &output, @@ -111,9 +147,110 @@ void CollectionMerger::fill_output_obj_muonchamber( } } + +// -------- Here Electron Seed Merger ----------- +//TODO: move seed merger to TrackMerger class +template <> +void CollectionMerger, reco::ElectronSeed>::willconsume(const edm::ParameterSet& iConfig) +{ + //track refs for trackerdriven seeds + inputs_fixtrackrefs_ = consumes( edm::InputTag("generalTracks") ); + inputs_fixtrackcol_ = consumes( edm::InputTag("generalTracks") ); + + //sc refs for ecaldriven seeds + inputs_scEB_ = consumes(edm::InputTag("particleFlowSuperClusterECAL:particleFlowSuperClusterECALBarrel") ); + inputs_scEE_ = consumes(edm::InputTag("particleFlowSuperClusterECAL:particleFlowSuperClusterECALEndcapWithPreshower") ); +} + +template <> +void CollectionMerger, reco::ElectronSeed>::willproduce(std::string instance, std::string alias) +{ + produces(instance); +} + +template +void CollectionMerger::fill_output_obj_seed(edm::Event& iEvent, std::unique_ptr & output, std::vector > &inputCollections) +{ + //track to track map for trackerdriven seed fix + edm::Handle track_ref_map; + iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map); + + edm::Handle track_new_col; + iEvent.getByToken(inputs_fixtrackcol_, track_new_col); + std::map simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map + for (unsigned abc =0; abc < track_new_col->size(); ++abc) { + reco::TrackRef trackRef(track_new_col, abc); + simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; + } + + //ECAL barrel supercluster collection + edm::Handle scEB; + iEvent.getByToken(inputs_scEB_,scEB); + auto bScEB = scEB->cbegin(); + auto eScEB = scEB->cend(); + + //ECAL endcap supercluster collection + edm::Handle scEE; + iEvent.getByToken(inputs_scEE_,scEE); + auto bScEE = scEE->cbegin(); + auto eScEE = scEE->cend(); + + // First merge the two collections again + for (auto const & inputCollection : inputCollections){ + for ( typename MergeCollection::const_iterator seed = inputCollection->begin(); seed!= inputCollection->end(); ++seed ) { + T2 newSeed(*seed); + + //fix reference to supercluster if seed is ecal driven + if (seed->isEcalDriven()) { + const reco::ElectronSeed::CaloClusterRef & seedCcRef(seed->caloCluster()); + if( seedCcRef.isNonnull() ) { + + //find corresponding supercluster in ECAL barrel and endcap + float dx, dy, dz, dr; + float drMin = std::numeric_limits::infinity(); + reco::ElectronSeed::CaloClusterRef ccRefMin; + for( auto sc = bScEB; sc != eScEB; ++sc ) { + const reco::SuperClusterRef & scRef(reco::SuperClusterRef(scEB,std::distance(bScEB,sc))); + dx = fabs(scRef->x()-seedCcRef->x()); + dy = fabs(scRef->y()-seedCcRef->y()); + dz = fabs(scRef->z()-seedCcRef->z()); + dr = sqrt(dx*dx+dy*dy+dz*dz); + if ( dr < drMin ) { + drMin = dr; + ccRefMin = reco::ElectronSeed::CaloClusterRef(scRef); + } + } + for( auto sc = bScEE; sc != eScEE; ++sc ) { + const reco::SuperClusterRef & scRef(reco::SuperClusterRef(scEE,std::distance(bScEE,sc))); + dx = fabs(scRef->x()-seedCcRef->x()); + dy = fabs(scRef->y()-seedCcRef->y()); + dz = fabs(scRef->z()-seedCcRef->z()); + dr = sqrt(dx*dx+dy*dy+dz*dz); + if ( dr < drMin ) { + drMin = dr; + ccRefMin = reco::ElectronSeed::CaloClusterRef(scRef); + } + } + //set new calocluster if new ref was found + if (drMin < 10.0) { + newSeed.setCaloCluster(ccRefMin); + } + } + } + if (seed->isTrackerDriven()) { + const reco::ElectronSeed::CtfTrackRef & ctfTrackRef(seed->ctfTrack()); + if ( ctfTrackRef.isNonnull() ){ + newSeed.setCtfTrack(simple_track_to_track_map[ctfTrackRef]); + } + } + output->push_back(newSeed); + } + } +} + // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections template -void CollectionMerger::fill_output_obj(std::unique_ptr &output, +void CollectionMerger::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { assert(0); // CV: make sure general function never gets called; // always use template specializations @@ -121,76 +258,88 @@ void CollectionMerger::fill_output_obj(std::unique_ptr // Start with the Tracker collections template <> -void CollectionMerger, SiPixelCluster>::fill_output_obj( +void CollectionMerger, SiPixelCluster>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_tracker(output, inputCollections, true); } template <> -void CollectionMerger, SiStripCluster>::fill_output_obj( +void CollectionMerger, SiStripCluster>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_tracker(output, inputCollections); } // Next are the Calo entries template <> -void CollectionMerger, EcalRecHit>::fill_output_obj( +void CollectionMerger, EcalRecHit>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, HBHERecHit>::fill_output_obj( +void CollectionMerger, HBHERecHit>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, HFRecHit>::fill_output_obj( +void CollectionMerger, HFRecHit>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, HORecHit>::fill_output_obj( +void CollectionMerger, HORecHit>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, CastorRecHit>::fill_output_obj( +void CollectionMerger, CastorRecHit>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, ZDCRecHit>::fill_output_obj( +void CollectionMerger, ZDCRecHit>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_calo(output, inputCollections); } // Here the Muon Chamber template <> -void CollectionMerger >, DTRecHit1DPair>::fill_output_obj( +void CollectionMerger >, DTRecHit1DPair>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_muonchamber(output, inputCollections); } template <> -void CollectionMerger >, CSCRecHit2D>::fill_output_obj( +void CollectionMerger >, CSCRecHit2D>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_muonchamber(output, inputCollections); } template <> -void CollectionMerger >, RPCRecHit>::fill_output_obj( +void CollectionMerger >, RPCRecHit>::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, std::vector > &inputCollections) { fill_output_obj_muonchamber(output, inputCollections); } +// Here Electron Seeds +template <> +void CollectionMerger, reco::ElectronSeed>::fill_output_obj(edm::Event& iEvent,std::unique_ptr & output, std::vector > &inputCollections) +{ + fill_output_obj_seed(iEvent, output,inputCollections); +} + + + DEFINE_FWK_MODULE(PixelColMerger); DEFINE_FWK_MODULE(StripColMerger); +DEFINE_FWK_MODULE(ElectronSeedColMerger); +DEFINE_FWK_MODULE(EcalDrivenElectronSeedColMerger); + DEFINE_FWK_MODULE(EcalRecHitColMerger); DEFINE_FWK_MODULE(HBHERecHitColMerger); DEFINE_FWK_MODULE(HFRecHitColMerger); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h index 8b931d8ddcfd9..ba1b46c6e6dd3 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h @@ -1,12 +1,12 @@ /** \class CollectionMerger * - * + * * \author Stefan Wayand; * Christian Veelken, LLR * - * * - * + * + * * */ #ifndef TauAnalysis_MCEmbeddingTools_CollectionMerger_H @@ -20,6 +20,16 @@ #include "DataFormats/MuonReco/interface/MuonEnergy.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" +#include "DataFormats/EgammaReco/interface/SuperCluster.h" + +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" + +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "DataFormats/TrackReco/interface/TrackToTrackMap.h" + #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h" #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h" #include "TrackingTools/Records/interface/TrackingComponentsRecord.h" @@ -48,7 +58,13 @@ class CollectionMerger : public edm::stream::EDProducer<> { typedef T2 BaseHit; std::map > > inputs_; - void fill_output_obj(std::unique_ptr &output, + edm::EDGetTokenT inputs_scEB_,inputs_scEE_, inputs_SC_; + + typedef edm::ValueMap TrackToTrackMapnew; + edm::EDGetTokenT inputs_fixtrackrefs_; + edm::EDGetTokenT inputs_fixtrackcol_; + + void fill_output_obj(edm::Event&, std::unique_ptr &output, std::vector > &inputCollections); void fill_output_obj_tracker(std::unique_ptr &output, std::vector > &inputCollections, @@ -57,6 +73,12 @@ class CollectionMerger : public edm::stream::EDProducer<> { std::vector > &inputCollections); void fill_output_obj_muonchamber(std::unique_ptr &output, std::vector > &inputCollections); + //seed merger + void fill_output_obj_seed(edm::Event&, std::unique_ptr & output, std::vector > &inputCollections); + + void willproduce(std::string instance, std::string alias); + void willconsume(const edm::ParameterSet& iConfig); + }; template @@ -65,9 +87,11 @@ CollectionMerger::CollectionMerger(const edm::ParameterSet &iConfig) { for (auto const &inCollection : inCollections) { inputs_[inCollection.instance()].push_back(consumes(inCollection)); } + willconsume(iConfig); for (const auto &toproduce : inputs_) { + std::string alias( iConfig.getParameter( "@module_label" ) ); // std::cout<(toproduce.first); + willproduce(toproduce.first,alias); } } @@ -85,7 +109,7 @@ void CollectionMerger::produce(edm::Event &iEvent, const edm::EventSetup for (unsigned id = 0; id < input_.second.size(); id++) { iEvent.getByToken(input_.second[id], inputCollections[id]); } - fill_output_obj(output, inputCollections); + fill_output_obj(iEvent, output, inputCollections); iEvent.put(std::move(output), input_.first); } } From a2a267f3d6fb480285c603c44383a08733ce3971 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 15:18:08 +0100 Subject: [PATCH 03/58] MCEmbeddingTools: introducing other GenFilters --- .../plugins/DYToElElGenFilter.cc | 105 +++++++++++ .../plugins/DYToElTauGenFilter.cc | 165 ++++++++++++++++++ .../plugins/DYToMuTauGenFilter.cc | 165 ++++++++++++++++++ .../plugins/DYToTauTauGenFilter.cc | 155 ++++++++++++++++ 4 files changed, 590 insertions(+) create mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc create mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc create mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc create mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc new file mode 100644 index 0000000000000..46b25d12d7928 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc @@ -0,0 +1,105 @@ +#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" + +#include "FWCore/Framework/interface/stream/EDFilter.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + + +class DYToElElGenFilter: public edm::stream::EDFilter<> { + public: + explicit DYToElElGenFilter(const edm::ParameterSet&); + ~DYToElElGenFilter() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + void beginStream(edm::StreamID) override; + bool filter(edm::Event&, const edm::EventSetup&) override; + void endStream() override; + + edm::InputTag inputTag_; + edm::EDGetTokenT genParticleCollection_; + + edm::Handle gen_handle; + + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + // ----------member data --------------------------- +}; + + +DYToElElGenFilter::DYToElElGenFilter(const edm::ParameterSet& iConfig) +{ + inputTag_= iConfig.getParameter("inputTag"); + genParticleCollection_ = consumes(inputTag_); +} + + +DYToElElGenFilter::~DYToElElGenFilter() { +} + +bool DYToElElGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { + + + iEvent.getByToken(genParticleCollection_, gen_handle); + + for(unsigned int i = 0; i < gen_handle->size(); i++) + { + const reco::GenParticle gen_particle = (*gen_handle)[i]; + // Check if Z Boson decayed into two leptons + if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) + { + // Check if daugther particles are Electrons + if (std::abs(gen_particle.daughter(0)->pdgId()) == 11 + && std::abs(gen_particle.daughter(1)->pdgId()) == 11 + && std::abs(gen_particle.daughter(0)->eta())<2.6 + && std::abs(gen_particle.daughter(1)->eta())<2.6 + && gen_particle.daughter(0)->pt()>7 + && gen_particle.daughter(1)->pt()>7) + { + edm::LogPrint("") << "Electron Event ! "; + return true; + } + else + { + return false; + } + } + } + return false; +} +// ------------ method called once each stream before processing any runs, lumis or events ------------ +void +DYToElElGenFilter::beginStream(edm::StreamID) +{ +} + +// ------------ method called once each stream after processing all runs, lumis and events ------------ +void +DYToElElGenFilter::endStream() { +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +DYToElElGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + + + +DEFINE_FWK_MODULE(DYToElElGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc new file mode 100644 index 0000000000000..2bc0e845987ec --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc @@ -0,0 +1,165 @@ +#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" + +#include "FWCore/Framework/interface/stream/EDFilter.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + + +class DYToElTauGenFilter: public edm::stream::EDFilter<> { + public: + explicit DYToElTauGenFilter(const edm::ParameterSet&); + ~DYToElTauGenFilter() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + void beginStream(edm::StreamID) override; + bool filter(edm::Event&, const edm::EventSetup&) override; + void endStream() override; + bool leptondecay(const reco::Candidate *d, int depth); + bool electrondecay(const reco::Candidate *d, int depth); + + edm::InputTag inputTag_; + edm::EDGetTokenT genParticleCollection_; + edm::Handle gen_handle; + +}; + +DYToElTauGenFilter::DYToElTauGenFilter(const edm::ParameterSet& iConfig) +{ + inputTag_= iConfig.getParameter("inputTag"); + genParticleCollection_ = consumes(inputTag_); +} + + +DYToElTauGenFilter::~DYToElTauGenFilter() { +} + + +bool DYToElTauGenFilter::leptondecay(const reco::Candidate *d, int depth) +{ + //returns true if the event has an leptonic decay + // Debug Output + // std::cout << std::string(4*depth, '-') << "---Hadroncheck-" << std::endl; + // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; + // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; + // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; + // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; + bool check = false; + if (d->status()!= 1) + { + if(d->numberOfDaughters() == 3) + { + if(std::abs(d->daughter(0)->pdgId()) == 14 + || std::abs(d->daughter(1)->pdgId()) == 14 + || std::abs(d->daughter(2)->pdgId()) == 14 + || std::abs(d->daughter(0)->pdgId()) == 12 + || std::abs(d->daughter(1)->pdgId()) == 12 + || std::abs(d->daughter(2)->pdgId()) == 12) check = true; + } + else if (d->numberOfDaughters() > 3) return false; + if (d->numberOfDaughters() < 4) + { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) + { + // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; + int new_depth = depth + 1; + if(leptondecay(d->daughter(k), new_depth) == true) check = true; + } + } + } + return check; +} +bool DYToElTauGenFilter::electrondecay(const reco::Candidate *d, int depth) +{ + //returns true if the event has an electron decay + bool check = false; + if (d->status()!= 1) + { + if(d->numberOfDaughters() == 3) + { + if(std::abs(d->daughter(0)->pdgId()) == 12 + || std::abs(d->daughter(1)->pdgId()) == 12 + || std::abs(d->daughter(2)->pdgId()) == 12) check = true; + } + else if (d->numberOfDaughters() > 3) return false; + if (d->numberOfDaughters() < 4) + { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) + { + int new_depth = depth + 1; + if(electrondecay(d->daughter(k), new_depth) == true) check = true; + } + } + } + return check; +} + +bool DYToElTauGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { + + + iEvent.getByToken(genParticleCollection_, gen_handle); + + for(unsigned int i = 0; i < gen_handle->size(); i++) + { + const reco::GenParticle gen_particle = (*gen_handle)[i]; + // Check if Z Boson decayed into two leptons + if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) + { + // Check if daugther particles are taus + // From Generator: Mu.Pt > 18 && Had.Pt > 25 && Mu.Eta < 2.1 + if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 + && std::abs(gen_particle.daughter(0)->eta())<2.1 + && gen_particle.daughter(0)->pt()>25 + && gen_particle.daughter(1)->pt()>18) + { + bool had_1 = !DYToElTauGenFilter::leptondecay(gen_particle.daughter(0),1); + bool el_2 = DYToElTauGenFilter::electrondecay(gen_particle.daughter(1),1); + bool had_2 = !DYToElTauGenFilter::leptondecay(gen_particle.daughter(1),1); + bool el_1 = DYToElTauGenFilter::electrondecay(gen_particle.daughter(0),1); + + std::cout << had_1 << " & " << el_2 << " / " << had_2 << " & " << el_1 << " |" << std::endl; + if ((had_1 && el_2)||(had_2 && el_1)) + { + std::cout << "Hadronic Decay Check was positive" << std::endl; + return true; + } + std::cout << "Hadronic Decay Check was negative" << std::endl; + } + return false; + } + } + return false; +} +// ------------ method called once each stream before processing any runs, lumis or events ------------ +void +DYToElTauGenFilter::beginStream(edm::StreamID) +{ +} + +// ------------ method called once each stream after processing all runs, lumis and events ------------ +void +DYToElTauGenFilter::endStream() { +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +DYToElTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + + + +DEFINE_FWK_MODULE(DYToElTauGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc new file mode 100644 index 0000000000000..2ee48ab74745a --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc @@ -0,0 +1,165 @@ +#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" + +#include "FWCore/Framework/interface/stream/EDFilter.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + + +class DYToMuTauGenFilter: public edm::stream::EDFilter<> { + public: + explicit DYToMuTauGenFilter(const edm::ParameterSet&); + ~DYToMuTauGenFilter() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + void beginStream(edm::StreamID) override; + bool filter(edm::Event&, const edm::EventSetup&) override; + void endStream() override; + bool leptondecay(const reco::Candidate *d, int depth); + bool muondecay(const reco::Candidate *d, int depth); + + edm::InputTag inputTag_; + edm::EDGetTokenT genParticleCollection_; + edm::Handle gen_handle; + +}; + +DYToMuTauGenFilter::DYToMuTauGenFilter(const edm::ParameterSet& iConfig) +{ + inputTag_= iConfig.getParameter("inputTag"); + genParticleCollection_ = consumes(inputTag_); +} + + +DYToMuTauGenFilter::~DYToMuTauGenFilter() { +} + + +bool DYToMuTauGenFilter::leptondecay(const reco::Candidate *d, int depth) +{ + //returns true if the event has an leptonic decay + // Debug Output + // std::cout << std::string(4*depth, '-') << "---Hadroncheck-" << std::endl; + // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; + // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; + // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; + // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; + bool check = false; + if (d->status()!= 1) + { + if(d->numberOfDaughters() == 3) + { + if(std::abs(d->daughter(0)->pdgId()) == 14 + || std::abs(d->daughter(1)->pdgId()) == 14 + || std::abs(d->daughter(2)->pdgId()) == 14 + || std::abs(d->daughter(0)->pdgId()) == 12 + || std::abs(d->daughter(1)->pdgId()) == 12 + || std::abs(d->daughter(2)->pdgId()) == 12) check = true; + } + else if (d->numberOfDaughters() > 3) return false; + if (d->numberOfDaughters() < 4) + { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) + { + // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; + int new_depth = depth + 1; + if(leptondecay(d->daughter(k), new_depth) == true) check = true; + } + } + } + return check; +} +bool DYToMuTauGenFilter::muondecay(const reco::Candidate *d, int depth) +{ + //returns true if the event has an muon decay + bool check = false; + if (d->status()!= 1) + { + if(d->numberOfDaughters() == 3) + { + if(std::abs(d->daughter(0)->pdgId()) == 14 + || std::abs(d->daughter(1)->pdgId()) == 14 + || std::abs(d->daughter(2)->pdgId()) == 14) check = true; + } + else if (d->numberOfDaughters() > 3) return false; + if (d->numberOfDaughters() < 4) + { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) + { + int new_depth = depth + 1; + if(muondecay(d->daughter(k), new_depth) == true) check = true; + } + } + } + return check; +} + +bool DYToMuTauGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { + + + iEvent.getByToken(genParticleCollection_, gen_handle); + + for(unsigned int i = 0; i < gen_handle->size(); i++) + { + const reco::GenParticle gen_particle = (*gen_handle)[i]; + // Check if Z Boson decayed into two leptons + if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) + { + // Check if daugther particles are taus + // From Generator: Mu.Pt > 18 && Had.Pt > 25 && Mu.Eta < 2.1 + if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 + && std::abs(gen_particle.daughter(0)->eta())<2.1 + && gen_particle.daughter(0)->pt()>25 + && gen_particle.daughter(1)->pt()>18) + { + bool had_1 = !DYToMuTauGenFilter::leptondecay(gen_particle.daughter(0),1); + bool mu_2 = DYToMuTauGenFilter::muondecay(gen_particle.daughter(1),1); + bool had_2 = !DYToMuTauGenFilter::leptondecay(gen_particle.daughter(1),1); + bool mu_1 = DYToMuTauGenFilter::muondecay(gen_particle.daughter(0),1); + + std::cout << had_1 << " & " << mu_2 << " / " << had_2 << " & " << mu_1 << " |" << std::endl; + if ((had_1 && mu_2)||(had_2 && mu_1)) + { + std::cout << "Hadronic Decay Check was positive" << std::endl; + return true; + } + std::cout << "Hadronic Decay Check was negative" << std::endl; + } + return false; + } + } + return false; +} +// ------------ method called once each stream before processing any runs, lumis or events ------------ +void +DYToMuTauGenFilter::beginStream(edm::StreamID) +{ +} + +// ------------ method called once each stream after processing all runs, lumis and events ------------ +void +DYToMuTauGenFilter::endStream() { +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +DYToMuTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + + + +DEFINE_FWK_MODULE(DYToMuTauGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc new file mode 100644 index 0000000000000..285fcb0ef3a9f --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc @@ -0,0 +1,155 @@ +#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/HepMCCandidate/interface/GenParticle.h" +#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" + +#include "FWCore/Framework/interface/stream/EDFilter.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + + +class DYToTauTauGenFilter: public edm::stream::EDFilter<> { + public: + explicit DYToTauTauGenFilter(const edm::ParameterSet&); + ~DYToTauTauGenFilter() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + void beginStream(edm::StreamID) override; + bool filter(edm::Event&, const edm::EventSetup&) override; + void endStream() override; + + edm::InputTag inputTag_; + edm::EDGetTokenT genParticleCollection_; + + edm::Handle gen_handle; + + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + // ----------member data --------------------------- +}; + + + + +DYToTauTauGenFilter::DYToTauTauGenFilter(const edm::ParameterSet& iConfig) +{ + inputTag_= iConfig.getParameter("inputTag"); + genParticleCollection_ = consumes(inputTag_); +} + + +DYToTauTauGenFilter::~DYToTauTauGenFilter() { +} + +bool photoncheck(const reco::Candidate *d, int depth) +{ + // Debug Output + // std::cout << std::string(4*depth, '-') << "-----------------" << std::endl; + // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; + // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; + // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; + // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; + bool check = false; + if (d->status()!= 1) + { + if(d->numberOfDaughters() == 3) + { + if(std::abs(d->daughter(0)->pdgId()) == 14 + || std::abs(d->daughter(1)->pdgId()) == 14 + || std::abs(d->daughter(2)->pdgId()) == 14 + || std::abs(d->daughter(0)->pdgId()) == 12 + || std::abs(d->daughter(1)->pdgId()) == 12 + || std::abs(d->daughter(2)->pdgId()) == 12) + { + check = true; + } + } + else if (d->numberOfDaughters() > 3) return false; + if (d->numberOfDaughters() < 4) + { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) + { + // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; + int new_depth = depth + 1; + if(photoncheck(d->daughter(k), new_depth) == true) + check = true; + } + } + + } + return check; + +} + +bool DYToTauTauGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { + + + iEvent.getByToken(genParticleCollection_, gen_handle); + + for(unsigned int i = 0; i < gen_handle->size(); i++) + { + const reco::GenParticle gen_particle = (*gen_handle)[i]; + // Check if Z Boson decayed into two leptons + if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) + { + //Debug output + // std::cout << "pdgId" << gen_particle.pdgId() << std::endl; + // std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; + // std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; + // std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; + // std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; + + // Check if daugther particles are taus + if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 + && std::abs(gen_particle.daughter(0)->eta())<2.3 + && std::abs(gen_particle.daughter(1)->eta())<2.3 + && ((gen_particle.daughter(0)->pt()>30 + && gen_particle.daughter(1)->pt()>35)||(gen_particle.daughter(0)->pt()>35 + && gen_particle.daughter(1)->pt()>30))) + { + if (!photoncheck(gen_particle.daughter(0),1) && !photoncheck(gen_particle.daughter(1),1)) + { + //std::cout << "Hadronic Decay Check was positive" << std::endl; + return true; + } + //std::cout << "Hadronic Decay Check was negative" << std::endl; + } + return false; + } + } + return false; +} +// ------------ method called once each stream before processing any runs, lumis or events ------------ +void +DYToTauTauGenFilter::beginStream(edm::StreamID) +{ +} + +// ------------ method called once each stream after processing all runs, lumis and events ------------ +void +DYToTauTauGenFilter::endStream() { +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +DYToTauTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + + + +DEFINE_FWK_MODULE(DYToTauTauGenFilter); From bad12dd8a5d462a2b5fcb2b47e271eddf576a40d Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 15:19:59 +0100 Subject: [PATCH 04/58] MCEmbeddingTools: introducing EmbeddingBeamSpotOnlineProducer --- .../EmbeddingBeamSpotOnlineProducer.cc | 33 +++++++++++++++++++ .../plugins/EmbeddingBeamSpotOnlineProducer.h | 26 +++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.cc create mode 100644 TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.h diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.cc b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.cc new file mode 100644 index 0000000000000..9b1bf000f43e2 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.cc @@ -0,0 +1,33 @@ + +#include "TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.h" +#include "DataFormats/BeamSpot/interface/BeamSpot.h" + +#include "FWCore/Framework/interface/MakerMacros.h" + + +using namespace edm; + + +EmbeddingBeamSpotOnlineProducer::EmbeddingBeamSpotOnlineProducer(const ParameterSet& iconf) +{ + beamSpotInput_ = iconf.getParameter("src"); + consumes(beamSpotInput_); + produces(); + +} + +EmbeddingBeamSpotOnlineProducer::~EmbeddingBeamSpotOnlineProducer() {} + +void +EmbeddingBeamSpotOnlineProducer::produce(Event& iEvent, const EventSetup& iSetup) +{ + //copy beam spot from input data into HLT simulation sequence + edm::Handle beamSpotH; + iEvent.getByLabel(beamSpotInput_,beamSpotH); + auto result = std::make_unique(); + *result = *beamSpotH; + iEvent.put(std::move(result)); + +} + +DEFINE_FWK_MODULE(EmbeddingBeamSpotOnlineProducer); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.h b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.h new file mode 100644 index 0000000000000..f8a2b37937b64 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.h @@ -0,0 +1,26 @@ +#ifndef EmbeddingBeamSpotOnlineProducer_EmbeddingBeamSpotOnlineProducer_h +#define EmbeddingBeamSpotOnlineProducer_EmbeddingBeamSpotOnlineProducer_h + +/**_________________________________________________________________ + class: EmbeddingBeamSpotOnlineProducer.h + package: TauAnalysis/MCEmbeddingTools +________________________________________________________________**/ + +#include "FWCore/Framework/interface/stream/EDProducer.h" + +class EmbeddingBeamSpotOnlineProducer: public edm::stream::EDProducer<> { + + public: + /// constructor + explicit EmbeddingBeamSpotOnlineProducer(const edm::ParameterSet& iConf); + /// destructor + ~EmbeddingBeamSpotOnlineProducer() override; + + /// produce a beam spot class + void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override; + + private: + edm::InputTag beamSpotInput_; +}; + +#endif From 5257e127aa455314aba965bd72c0fa7644d19808 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 15:22:35 +0100 Subject: [PATCH 05/58] MCEmbeddingTools: introducing DoubleCollectionMerger --- .../plugins/DoubleCollectionMerger.cc | 120 ++++++++++++++++++ .../plugins/DoubleCollectionMerger.h | 116 +++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc create mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc new file mode 100644 index 0000000000000..345b9064b4502 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc @@ -0,0 +1,120 @@ +#include "TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "DataFormats/Common/interface/SortedCollection.h" + +#include "DataFormats/EcalDigi/interface/EcalSrFlag.h" +#include "DataFormats/EcalDigi/interface/EESrFlag.h" +#include "DataFormats/EcalDigi/interface/EBSrFlag.h" +#include "DataFormats/EcalDigi/src/EcalSrFlag.cc" + +#include "DataFormats/Common/interface/RangeMap.h" +#include "DataFormats/Common/interface/OwnVector.h" + + +typedef DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag> EcalSrFlagColMerger; + +// Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections +template +void DoubleCollectionMerger::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) +{ + assert(0); // CV: make sure general function never gets called; + // always use template specializations +} + +template +void DoubleCollectionMerger::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) +{ + assert(0); // CV: make sure general function never gets called; + // always use template specializations +} + +template +void DoubleCollectionMerger::fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections) +{ + std::map output_map; + + // First merge the two collections again + for (auto const & inputCollection : inputCollections){ + for ( typename MergeCollection1::const_iterator obj = inputCollection->begin(); obj!= inputCollection->end(); ++obj ) { + DetId detIdObject( obj->id().rawId() ); + + std::map::iterator it = output_map.find(detIdObject.rawId()); + if (it == output_map.end()) { + BaseHit1 *akt_flag_obj = &output_map[detIdObject.rawId()]; + T2 newSrFlag(*obj); + *akt_flag_obj = newSrFlag; + } else { + //re-determine flag + BaseHit1 preFlag = it->second; + BaseHit1 *akt_flag_obj = &output_map[detIdObject.rawId()]; + T2 newSrFlag(*obj); + + newSrFlag.setValue(std::max(obj->value(),preFlag.value())); + if (preFlag.value() == 3 or obj->value() == 3) newSrFlag.setValue(3); + if (preFlag.value() == 7 or obj->value() == 7) newSrFlag.setValue(7); + + *akt_flag_obj = newSrFlag; + } + } + } + + // Now save it into the standard CMSSW format + for (typename std::map::const_iterator outFlags = output_map.begin(); outFlags != output_map.end(); ++outFlags ) { + BaseHit1 currFlag = outFlags->second; + output->push_back(outFlags->second); + } + output->sort(); //Do a sort for this collection +} + +template +void DoubleCollectionMerger::fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections) +{ + std::map output_map; + + // First merge the two collections again + for (auto const & inputCollection : inputCollections){ + for ( typename MergeCollection2::const_iterator obj = inputCollection->begin(); obj!= inputCollection->end(); ++obj ) { + DetId detIdObject( obj->id().rawId() ); + + std::map::iterator it = output_map.find(detIdObject.rawId()); + if (it == output_map.end()) { + BaseHit2 *akt_flag_obj = &output_map[detIdObject.rawId()]; + T4 newSrFlag(*obj); + *akt_flag_obj = newSrFlag; + } else { + //re-determine flag + BaseHit2 preFlag = it->second; + BaseHit2 *akt_flag_obj = &output_map[detIdObject.rawId()]; + T4 newSrFlag(*obj); + + newSrFlag.setValue(std::max(obj->value(),preFlag.value())); + if (preFlag.value() == 3 or obj->value() == 3) newSrFlag.setValue(3); + if (preFlag.value() == 7 or obj->value() == 7) newSrFlag.setValue(7); + + *akt_flag_obj = newSrFlag; + } + } + } + + // Now save it into the standard CMSSW format + for (typename std::map::const_iterator outFlags = output_map.begin(); outFlags != output_map.end(); ++outFlags ) { + BaseHit2 currFlag = outFlags->second; + output->push_back(outFlags->second); + } + output->sort(); //Do a sort for this collection +} + +template <> +void DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag>::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) +{ + fill_output_obj_digiflag(output,inputCollections); +} + +template <> +void DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag>::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) +{ + fill_output_obj_digiflag(output,inputCollections); +} + +DEFINE_FWK_MODULE(EcalSrFlagColMerger); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h new file mode 100644 index 0000000000000..008c9a75b8f13 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h @@ -0,0 +1,116 @@ +/** \class DoubleCollectionMerger + * + * + * \author Per Ahrens + * + * + * + * + * + */ +#ifndef TauAnalysis_MCEmbeddingTools_DoubleCollectionMerger_H +#define TauAnalysis_MCEmbeddingTools_DoubleCollectionMerger_H + +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/Common/interface/Handle.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "DataFormats/Common/interface/SortedCollection.h" +#include "DataFormats/Common/interface/DetSetVectorNew.h" + + +//#include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h" +#include +#include +#include + + + +template +class DoubleCollectionMerger : public edm::stream::EDProducer<> +{ + public: + explicit DoubleCollectionMerger(const edm::ParameterSet&); + ~DoubleCollectionMerger(); + + private: + void produce(edm::Event&, const edm::EventSetup&) override; + + typedef T1 MergeCollection1; + typedef T2 BaseHit1; + typedef T3 MergeCollection2; + typedef T4 BaseHit2; + std::map > > inputs1_; + std::map > > inputs2_; + + void fill_output_obj(std::unique_ptr & output1, std::vector > &inputCollections1); + void fill_output_obj(std::unique_ptr & output2, std::vector > &inputCollections2); + void fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections); + void fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections); + +}; + +template +DoubleCollectionMerger::DoubleCollectionMerger(const edm::ParameterSet& iConfig) +{ + std::vector inCollections = iConfig.getParameter >("mergCollections"); + for (auto const & inCollection : inCollections){ + inputs1_[inCollection.instance()].push_back(consumes(inCollection)); + inputs2_[inCollection.instance()].push_back(consumes(inCollection)); + } + for (auto toproduce : inputs1_){ + //std::cout<(toproduce.first); + } + for (auto toproduce : inputs2_){ + //std::cout<(toproduce.first); + } +} + + +template +DoubleCollectionMerger::~DoubleCollectionMerger() +{ +// nothing to be done yet... +} + + +template +void DoubleCollectionMerger::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + //std::cout << "DoubleCollectionMerger::produce" << std::endl; + for (auto input_ : inputs1_){ + //std::cout << "input_.first()=" << input_.first << std::endl; + //std::cout << "input_.second.size()=" << input_.second.size() << std::endl; + std::unique_ptr output(new MergeCollection1()); + std::vector > inputCollections; + inputCollections.resize(input_.second.size()); + for (unsigned id = 0; id { + public: + explicit EmbeddingHltPixelVerticesProducer(const edm::ParameterSet&); + ~EmbeddingHltPixelVerticesProducer(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void beginStream(edm::StreamID) override; + virtual void produce(edm::Event&, const edm::EventSetup&) override; + virtual void endStream() override; + edm::InputTag vertexPositionLabel; + //edm::InputTag generalTracks; + + // ----------member data --------------------------- +}; + +EmbeddingHltPixelVerticesProducer::EmbeddingHltPixelVerticesProducer(const edm::ParameterSet& iConfig) +{ + + vertexPositionLabel = edm::InputTag("externalLHEProducer","vertexPosition"); + consumes(vertexPositionLabel); + produces(); + + // generalTracks = iConfig.getParameter("TrackLabel"); + // consumes(generalTracks); + // consumes(generalTracks); +} + + +EmbeddingHltPixelVerticesProducer::~EmbeddingHltPixelVerticesProducer() +{} + + +// ------------ method called to produce the data ------------ +void +EmbeddingHltPixelVerticesProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) +{ + using namespace edm; + std::unique_ptr embeddingVertex(new reco::VertexCollection); + Handle vertex_position; + iEvent.getByLabel(vertexPositionLabel, vertex_position); + // edm::LogPrint("") << "externalLHEProducer Vertex (" << vertex_position.product()->x() << "," << vertex_position.product()->y() << "," << vertex_position.product()->z() << ")"; + math::XYZPoint genVertex = math::XYZPoint(vertex_position.product()->x(),vertex_position.product()->y(),vertex_position.product()->z()); + math::Error<3>::type Error; + // additionally, get the general Tracks: + // edm::Handle tks; + // iEvent.getByLabel(generalTracks, tks); + // edm::LogPrint("") << "Loaded " << tks->size() << " tracks:"; + + // edm::Handle tks_ref; + // iEvent.getByLabel(generalTracks, tks_ref); + // std::vector > tks_base_; + // tks_base_.push_back(edm::RefToBase(tks_ref)); + //reco::Vertex saveVertex = reco::Vertex(genVertex, Error); + // Try to produce an nonfake Vertex + // constructor for a valid vertex, with all data + //Vertex( const Point &, const Error &, double chi2, double ndof, size_t size ); + // Need at least 5 ndof so the vertex Quality is considered good + reco::Vertex saveVertex = reco::Vertex(genVertex, Error,1.0,6.0,6); + + //for (auto track: *tks) + //{ + //edm::LogPrint("") << track.vertex(); + //saveVertex.add(track, 0.5); + //} + //if (saveVertex.isFake()) edm::LogPrint("") << " The produced Vertex is fake"; + //else edm::LogPrint("") << " The produced Vertex is not fake"; + //edm::LogPrint("") << "Vertex Properties: " << saveVertex.isFake() << " / " << saveVertex.ndof() << " / " << abs(saveVertex.z()) << " / " << abs(saveVertex.position().Rho()); + //if (!saveVertex.isFake() && saveVertex.ndof() >= 4.0 && abs(saveVertex.z()) <= 24.0 && abs(saveVertex.position().Rho()) <= 2.0) + // edm::LogPrint("") << "The Vertex is a goodOfflineVertex"; + embeddingVertex->push_back(saveVertex); + // iEvent.put(std::move(embeddingVertex), "embeddingVertex"); + iEvent.put(std::move(embeddingVertex)); + +} + +// ------------ method called once each stream before processing any runs, lumis or events ------------ +void EmbeddingHltPixelVerticesProducer::beginStream(edm::StreamID) +{ +} + +// ------------ method called once each stream after processing all runs, lumis and events ------------ +void EmbeddingHltPixelVerticesProducer::endStream() { +} + + +void EmbeddingHltPixelVerticesProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(EmbeddingHltPixelVerticesProducer); From 1756c376168c0fe43dcb284552b66c30c095872c Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 15:45:31 +0100 Subject: [PATCH 07/58] MCEmbeddingTools: updating EmbeddingLHEProducer --- .../plugins/EmbeddingLHEProducer.cc | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc index 13f26adf34ee8..ec4a9a3229797 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc @@ -89,6 +89,7 @@ class EmbeddingLHEProducer : public edm::one::EDProducer> muonsCollection_; edm::EDGetTokenT vertexCollection_; int particleToEmbed_; - bool mirror_, rotate180_; + bool mirror_, rotate180_,InitialRecoCorrection_; const double tauMass_ = 1.77682; + const double muonMass_ = 0.1057; const double elMass_ = 0.00051; const int embeddingParticles[3]{11, 13, 15}; @@ -123,6 +125,7 @@ EmbeddingLHEProducer::EmbeddingLHEProducer(const edm::ParameterSet &iConfig) { vertexCollection_ = consumes(iConfig.getParameter("vertices")); particleToEmbed_ = iConfig.getParameter("particleToEmbed"); mirror_ = iConfig.getParameter("mirror"); + InitialRecoCorrection_ = iConfig.getParameter("InitialRecoCorrection"); rotate180_ = iConfig.getParameter("rotate180"); studyFSRmode_ = iConfig.getUntrackedParameter("studyFSRmode", ""); @@ -188,6 +191,7 @@ void EmbeddingLHEProducer::produce(edm::Event &iEvent, const edm::EventSetup &iS } else if (mu_minus_found && mu_plus_found) break; } + InitialRecoCorrection(positiveLepton,negativeLepton); //corrects Z mass peak to take into account smearing happening due to first muon reconstruction in the selection step mirror(positiveLepton, negativeLepton); // if no mirror, function does nothing. rotate180(positiveLepton, negativeLepton); // if no rotate180, function does nothing transform_mumu_to_tautau(positiveLepton, negativeLepton); // if MuonEmbedding, function does nothing. @@ -424,6 +428,33 @@ void EmbeddingLHEProducer::rotate180(TLorentzVector &positiveLepton, TLorentzVec return; } +void EmbeddingLHEProducer::InitialRecoCorrection(TLorentzVector &positiveLepton, TLorentzVector &negativeLepton) +{ + if(!InitialRecoCorrection_) return; + edm::LogInfo("TauEmbedding")<< "Applying initial reconstruction correction" ; + TLorentzVector Z = positiveLepton + negativeLepton; + + edm::LogInfo("TauEmbedding") << "MuMinus before. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M() ; + //std::cout << " MuMinus before. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M() << " Energy: " << negativeLepton.E() << std::endl; + float diLeptonMass=(positiveLepton + negativeLepton).M(); + if(diLeptonMass>60.&&diLeptonMass<122.) { + //std::cout << "DiLeptonMass " << diLeptonMass << std::endl; + float zmass=91.1876; + float correction_deviation=5.; // to ensure only a correction that drops corresponding to a Gaussian with mean zmass and std. dev. 5 GeV + double EmbeddingCorrection = 1.138; // value derived by function fitting to fold embedded mass spectrum back to original selection when using mu -> mu embedding + EmbeddingCorrection=EmbeddingCorrection/(EmbeddingCorrection-(EmbeddingCorrection-1.)*exp(-pow((diLeptonMass-zmass),2.)/(2.*pow(correction_deviation,2.)))); + EmbeddingCorrection=((diLeptonMass + (EmbeddingCorrection - 1.)*zmass)/(diLeptonMass*EmbeddingCorrection)); + double correctedpositiveLeptonEnergy=std::sqrt(muonMass_*muonMass_+EmbeddingCorrection*positiveLepton.Px()*EmbeddingCorrection*positiveLepton.Px()+EmbeddingCorrection*positiveLepton.Py()*EmbeddingCorrection*positiveLepton.Py()+EmbeddingCorrection*positiveLepton.Pz()*EmbeddingCorrection*positiveLepton.Pz()); + double correctednegativeLeptonEnergy=std::sqrt(muonMass_*muonMass_+EmbeddingCorrection*negativeLepton.Px()*EmbeddingCorrection*negativeLepton.Px()+EmbeddingCorrection*negativeLepton.Py()*EmbeddingCorrection*negativeLepton.Py()+EmbeddingCorrection*negativeLepton.Pz()*EmbeddingCorrection*negativeLepton.Pz()); + positiveLepton.SetPxPyPzE(EmbeddingCorrection*positiveLepton.Px(),EmbeddingCorrection*positiveLepton.Py(),EmbeddingCorrection*positiveLepton.Pz(),correctedpositiveLeptonEnergy); + negativeLepton.SetPxPyPzE(EmbeddingCorrection*negativeLepton.Px(),EmbeddingCorrection*negativeLepton.Py(),EmbeddingCorrection*negativeLepton.Pz(),correctednegativeLeptonEnergy); + + edm::LogInfo("TauEmbedding") << "MuMinus after. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M() ; + //std::cout << " MuMinus after. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M() << " Energy: " << negativeLepton.E() << std::endl; + } + return; +} + void EmbeddingLHEProducer::mirror(TLorentzVector &positiveLepton, TLorentzVector &negativeLepton) { if (!mirror_) return; From 948f821491587a79dcfcbc56f656defe0c90bcce Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 16:11:07 +0100 Subject: [PATCH 08/58] MCEmbeddingTools: updating MuMuForEmbeddingSelector --- .../plugins/MuMuForEmbeddingSelector.cc | 103 +++++++++++++++--- 1 file changed, 90 insertions(+), 13 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc b/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc index f5c0eefd45e3a..d3e38c4d16f67 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc @@ -32,6 +32,13 @@ #include "DataFormats/Candidate/interface/CompositeCandidate.h" #include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/VertexReco/interface/Vertex.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/BeamSpot/interface/BeamSpot.h" + +#include "DataFormats/PatCandidates/interface/MET.h" +#include "DataFormats/METReco/interface/MET.h" + // // class declaration // @@ -47,6 +54,11 @@ class MuMuForEmbeddingSelector : public edm::stream::EDProducer<> { // ----------member data --------------------------- edm::EDGetTokenT> ZmumuCandidates_; + edm::EDGetTokenT theVertexLabel_; + edm::EDGetTokenT theBeamSpotLabel_; + edm::EDGetTokenT> theMETLabel_; + edm::EDGetTokenT> thePuppiMETLabel_; + bool use_zmass = false; double ZMass = 91.0; }; @@ -64,18 +76,23 @@ class MuMuForEmbeddingSelector : public edm::stream::EDProducer<> { MuMuForEmbeddingSelector::MuMuForEmbeddingSelector(const edm::ParameterSet& iConfig) : ZmumuCandidates_(consumes>( iConfig.getParameter("ZmumuCandidatesCollection"))) { - //register your products - /* Examples - produces(); - - //if do put with a label - produces("label"); - - //if you want to put into the Run - produces(); -*/ + use_zmass = iConfig.getParameter("use_zmass"); produces>(); - + produces("oldMass"); + produces("newMass"); + produces("nPairCandidates"); + produces("isMediumLeadingMuon"); + produces("isTightLeadingMuon"); + produces("isMediumTrailingMuon"); + produces("isTightTrailingMuon"); + produces("initialMETEt"); + produces("initialMETphi"); + produces("initialPuppiMETEt"); + produces("initialPuppiMETphi"); + theVertexLabel_ = consumes(iConfig.getParameter("inputTagVertex")); + theBeamSpotLabel_ = consumes(iConfig.getParameter("inputTagBeamSpot")); + theMETLabel_ = consumes< edm::View >(iConfig.getParameter("Met")); + thePuppiMETLabel_ = consumes< edm::View >(iConfig.getParameter("PuppiMet")); //now do what ever other initialization is needed } @@ -89,22 +106,82 @@ void MuMuForEmbeddingSelector::produce(edm::Event& iEvent, const edm::EventSetup edm::Handle> ZmumuCandidatesHandle; iEvent.getByToken(ZmumuCandidates_, ZmumuCandidatesHandle); edm::View ZmumuCandidates = *ZmumuCandidatesHandle; - const reco::CompositeCandidate* chosenZCand = nullptr; + const reco::CompositeCandidate* chosenZCand_zmass = nullptr; + const reco::CompositeCandidate* chosenZCand_largest = nullptr; double massDifference = -1.0; + edm::Handle beamSpot; + iEvent.getByToken(theBeamSpotLabel_, beamSpot); + edm::Handle vertex; + iEvent.getByToken(theVertexLabel_, vertex); + edm::Handle > met; + iEvent.getByToken(theMETLabel_, met); + edm::Handle > puppimet; + iEvent.getByToken(thePuppiMETLabel_, puppimet); + // get primary vertex + reco::Vertex::Point posVtx; + reco::Vertex::Error errVtx; + std::vector::const_iterator vertexIt = vertex->begin(); + std::vector::const_iterator vertexEnd = vertex->end(); + for (; vertexIt != vertexEnd; ++vertexIt) { + if (vertexIt->isValid() && !vertexIt->isFake()) { + posVtx = vertexIt->position(); + errVtx = vertexIt->error(); + break; + } + } + reco::Vertex primaryVertex(posVtx, errVtx); + + for (edm::View::const_iterator iZCand = ZmumuCandidates.begin(); iZCand != ZmumuCandidates.end(); ++iZCand) { if (std::abs(ZMass - iZCand->mass()) < massDifference || massDifference < 0) { massDifference = std::abs(ZMass - iZCand->mass()); - chosenZCand = &(*iZCand); + chosenZCand_zmass = &(*iZCand); + } + } + for (edm::View::const_iterator iZCand = ZmumuCandidates.begin(); iZCand != ZmumuCandidates.end(); ++iZCand) + { + if (chosenZCand_largest == nullptr) + { + chosenZCand_largest = &(*iZCand); + } + else + { + if (iZCand->mass() > chosenZCand_largest->mass()) + { + chosenZCand_largest = &(*iZCand); + } } } + if(use_zmass){ + // edm::LogDebug("MuMuForEmbeddingSelector") << "Using Z mass candidate" << chosenZCand_zmass->mass(); + chosenZCand = chosenZCand_zmass; + } + else { + // edm::LogDebug("MuMuForEmbeddingSelector") << "Using largest mass candidate" << chosenZCand_largest->mass(); + chosenZCand = chosenZCand_largest; + } + std::unique_ptr> prod(new edm::RefVector()); prod->reserve(2); prod->push_back(chosenZCand->daughter(0)->masterClone().castTo()); prod->push_back(chosenZCand->daughter(1)->masterClone().castTo()); iEvent.put(std::move(prod)); + iEvent.put(std::make_unique(chosenZCand_zmass->mass()), "oldMass"); + iEvent.put(std::make_unique(chosenZCand_largest->mass()), "newMass"); + iEvent.put(std::make_unique(ZmumuCandidates.size()), "nPairCandidates"); + iEvent.put(std::make_unique(chosenZCand->daughter(0)->masterClone().castTo()->isMediumMuon()), "isMediumLeadingMuon"); + iEvent.put(std::make_unique(chosenZCand->daughter(0)->masterClone().castTo()->isTightMuon(primaryVertex)), "isTightLeadingMuon"); + iEvent.put(std::make_unique(chosenZCand->daughter(1)->masterClone().castTo()->isMediumMuon()), "isMediumTrailingMuon"); + iEvent.put(std::make_unique(chosenZCand->daughter(1)->masterClone().castTo()->isTightMuon(primaryVertex)), "isTightTrailingMuon"); + iEvent.put(std::make_unique(met->at(0).et()), "initialMETEt"); + iEvent.put(std::make_unique(met->at(0).phi()), "initialMETphi"); + iEvent.put(std::make_unique(puppimet->at(0).et()), "initialPuppiMETEt"); + iEvent.put(std::make_unique(puppimet->at(0).phi()), "initialPuppiMETphi"); + // edm::LogDebug("MuMuForEmbeddingSelector") << "PuppiMet: " << puppimet->at(0).et() << " phi: " << puppimet->at(0).phi(); + // edm::LogDebug("MuMuForEmbeddingSelector") << "MET: " << met->at(0).et() << " phi: " << met->at(0).phi(); } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ From cfca6a7148f05846dbf418e1a8e4c4412b49316c Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 18:15:32 +0100 Subject: [PATCH 09/58] MCEmbeddingTools: updating TrackMergeremb --- .../plugins/TrackMergeremb.cc | 133 +++++++++++++++++- .../MCEmbeddingTools/plugins/TrackMergeremb.h | 30 +++- 2 files changed, 158 insertions(+), 5 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc index e7d283c8a0d67..beebb41d5cb5d 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc @@ -9,6 +9,9 @@ #include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" +#include "DataFormats/EgammaReco/interface/SuperCluster.h" + #include "DataFormats/EgammaTrackReco/interface/ConversionTrack.h" #include "DataFormats/EgammaTrackReco/interface/ConversionTrackFwd.h" @@ -40,9 +43,11 @@ #include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h" typedef TrackMergeremb TrackColMerger; +typedef TrackMergeremb GsfTrackColMerger; typedef TrackMergeremb MuonColMerger; typedef TrackMergeremb GsfElectronColMerger; typedef TrackMergeremb PhotonColMerger; +typedef TrackMergeremb ConversionColMerger; typedef TrackMergeremb PFColMerger; // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections @@ -127,12 +132,22 @@ void TrackMergeremb::merg_and_put( iEvent.put(std::move(outTracks_rh), instance); // not implemented so far } +template <> +void TrackMergeremb::willconsume(const edm::ParameterSet& iConfig) { + //track refs for trackerdriven seeds + inputs_fixtrackrefs_ = consumes( edm::InputTag("generalTracks") ); + inputs_fixtrackcol_ = consumes( edm::InputTag("generalTracks") ); + inputs_rElectronMergedSeeds_ = consumes(edm::InputTag("electronMergedSeeds") ); + inputs_rElectronMergedSeedViews_ = consumes>(edm::InputTag("electronMergedSeeds") ); +} + template <> void TrackMergeremb::willproduce(std::string instance, std::string alias) { produces(instance).setBranchAlias(alias + "GsfTracks"); produces(instance).setBranchAlias(alias + "TrackExtras"); produces(instance).setBranchAlias(alias + "GsfTrackExtras"); produces(instance).setBranchAlias(alias + "RecHits"); + produces(); } template <> @@ -142,11 +157,13 @@ void TrackMergeremb::merg_and_put( std::unique_ptr outTracks_ex = std::make_unique(); std::unique_ptr outTracks_exgsf = std::make_unique(); std::unique_ptr outTracks_rh = std::make_unique(); + std::unique_ptr outTracks_refs = std::unique_ptr(new GsfTrackToTrackMapnew()); auto rTrackExtras = iEvent.getRefBeforePut(); auto rTrackExtras_gsf = iEvent.getRefBeforePut(); auto rHits = iEvent.getRefBeforePut(); + std::vector trackRefColl; for (auto akt_collection : to_merge) { edm::Handle track_col_in; @@ -161,12 +178,80 @@ void TrackMergeremb::merg_and_put( outTracks->back().setExtra(reco::TrackExtraRef(rTrackExtras, outTracks_ex->size() - 1)); outTracks->back().setGsfExtra(reco::GsfTrackExtraRef(rTrackExtras_gsf, outTracks_exgsf->size() - 1)); + + reco::GsfTrackRef trackRefold(track_col_in, sedref_it); + reco::GsfTrackRefVector trackRefColl_helpvec; + trackRefColl_helpvec.push_back(trackRefold); + trackRefColl.push_back(trackRefColl_helpvec); } } // end merge - iEvent.put(std::move(outTracks), instance); - iEvent.put(std::move(outTracks_ex), instance); + edm::OrphanHandle trackHandle = iEvent.put(std::move(outTracks),instance); + GsfTrackToTrackMapnew::Filler filler(*outTracks_refs); + filler.insert(trackHandle, trackRefColl.begin(), trackRefColl.end() ); + filler.fill(); + + + //track to track map for trackerdriven seed fix + edm::Handle track_ref_map; + iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map); + + edm::Handle track_new_col; + iEvent.getByToken(inputs_fixtrackcol_, track_new_col); + std::map simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map + for (unsigned abc =0; abc < track_new_col->size(); ++abc) { + reco::TrackRef trackRef(track_new_col, abc); + simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; + } + + edm::Handle elSeeds; + iEvent.getByToken(inputs_rElectronMergedSeeds_,elSeeds); + auto bElSeeds = elSeeds->cbegin(); + auto eElSeeds = elSeeds->cend(); + + edm::Handle > seedViewsHandle; + iEvent.getByToken(inputs_rElectronMergedSeedViews_,seedViewsHandle); + + std::unique_ptr outTracks_ex_new = std::unique_ptr(new reco::TrackExtraCollection()); + + //fix track extras to new merged seeds + for ( typename reco::TrackExtraCollection::const_iterator tex = outTracks_ex->begin(); tex!= outTracks_ex->end(); ++tex ) { + reco::TrackExtra newTrackExtra(*tex); + + if (tex->seedRef().isAvailable()) { + const reco::ElectronSeedRef & trSeedRef (tex->seedRef().castTo()); + if( trSeedRef.isAvailable() ) { + + //find new seed with corresponding supercluster or ctfTrack + //note that seed can be both Ecal- and Tracker-driven + size_t sedref_it = 0; + for( auto tseed = bElSeeds; tseed != eElSeeds; ++tseed, ++sedref_it) { + const reco::ElectronSeedRef elSeedRef (elSeeds, sedref_it); + + if (trSeedRef->isEcalDriven() && elSeedRef->isEcalDriven()) { + //match seeds by pair of detIds + if ( trSeedRef->detId(0) == elSeedRef->detId(0) && trSeedRef->detId(1) == elSeedRef->detId(1)) { + edm::RefToBase traSeedRef(seedViewsHandle, sedref_it); + newTrackExtra.setSeedRef(traSeedRef); + } + } + if (trSeedRef->isTrackerDriven() && elSeedRef->isTrackerDriven()) { + //if tracker driven, check for same ctf track + if (simple_track_to_track_map[trSeedRef->ctfTrack()] == elSeedRef->ctfTrack()) { + edm::RefToBase traSeedRef(seedViewsHandle, sedref_it); + newTrackExtra.setSeedRef(traSeedRef); + } + } + } + } + } + + outTracks_ex_new->push_back(newTrackExtra); + } + + iEvent.put(std::move(outTracks_refs)); + iEvent.put(std::move(outTracks_ex_new),instance); iEvent.put(std::move(outTracks_exgsf), instance); iEvent.put(std::move(outTracks_rh), instance); } @@ -283,8 +368,11 @@ template <> void TrackMergeremb::willconsume(const edm::ParameterSet& iConfig) { inputs_fixtrackrefs_ = consumes(edm::InputTag("generalTracks")); inputs_fixtrackcol_ = consumes(edm::InputTag("generalTracks")); + inputs_fixgsftrackrefs_ = consumes( edm::InputTag("electronGsfTracks") ); + inputs_fixgsftrackcol_ = consumes( edm::InputTag("electronGsfTracks") ); inputs_fixmurefs_ = consumes(edm::InputTag("muons1stStep")); inputs_fixmucol_ = consumes(edm::InputTag("muons1stStep")); + inputs_SC_ = consumes(edm::InputTag("particleFlowEGamma") ); } template <> @@ -304,6 +392,17 @@ void TrackMergeremb::merg_and_put( simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; } + edm::Handle gsftrack_ref_map; + iEvent.getByToken(inputs_fixgsftrackrefs_, gsftrack_ref_map); + + edm::Handle gsftrack_new_col; + iEvent.getByToken(inputs_fixgsftrackcol_, gsftrack_new_col); + std::map simple_gsftrack_to_gsftrack_map; //I didn't find a more elegant way, so just build a good old fassion std::map + for (unsigned abc =0; abc < gsftrack_new_col->size(); ++abc) { + reco::GsfTrackRef gsfTrackRef(gsftrack_new_col, abc); + simple_gsftrack_to_gsftrack_map[((*gsftrack_ref_map)[gsfTrackRef])[0]] = gsfTrackRef; + } + edm::Handle muon_ref_map; iEvent.getByToken(inputs_fixmurefs_, muon_ref_map); @@ -316,6 +415,12 @@ void TrackMergeremb::merg_and_put( simple_mu_to_mu_map[(*muon_ref_map)[muRef]] = muRef; } + //used for photon matching + edm::Handle sCs; + iEvent.getByToken(inputs_SC_,sCs); + auto bSc = sCs->cbegin(); + auto eSc = sCs->cend(); + for (auto akt_collection : to_merge) { edm::Handle track_col_in; iEvent.getByToken(akt_collection, track_col_in); @@ -326,6 +431,28 @@ void TrackMergeremb::merg_and_put( //std::cout<<"pfmerge tr: "<trackRef().id()<< " "<< it->trackRef().key()<< " " << simple_track_to_track_map[it->trackRef()].id() << " " << simple_track_to_track_map[it->trackRef()].key() <back().setTrackRef(simple_track_to_track_map[it->trackRef()]); } + if(it->gsfTrackRef().isNonnull()) { + outTracks->back().setGsfTrackRef( simple_gsftrack_to_gsftrack_map[it->gsfTrackRef()] ); + } + if (it->superClusterRef().isNonnull()) { + const reco::SuperClusterRef & pfScRef(it->superClusterRef()); + + float dx, dy, dz, dr; + //float drMin = std::numeric_limits::infinity(); + float drMin = 10.0;//also used as treshold for matching + reco::SuperClusterRef ccrefMin; + for( auto sc = bSc; sc != eSc; ++sc ) { + const reco::SuperClusterRef & scRef(reco::SuperClusterRef(sCs,std::distance(bSc,sc))); + dx = fabs(scRef->x()-pfScRef->x()); + dy = fabs(scRef->y()-pfScRef->y()); + dz = fabs(scRef->z()-pfScRef->z()); + dr = sqrt(dx*dx+dy*dy+dz*dz); + if ( dr < drMin ) { + drMin = dr; + outTracks->back().setSuperClusterRef(scRef); + } + } + } if (it->muonRef().isNonnull()) { //std::cout<<"pfmerge mu: "<muonRef().id()<< " "<< it->muonRef().key()<< " " << simple_mu_to_mu_map[it->muonRef()].id() << " " << simple_mu_to_mu_map[it->muonRef()].key() <back().setMuonRef(simple_mu_to_mu_map[it->muonRef()]); @@ -339,7 +466,9 @@ void TrackMergeremb::merg_and_put( #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(TrackColMerger); +DEFINE_FWK_MODULE(GsfTrackColMerger); DEFINE_FWK_MODULE(MuonColMerger); DEFINE_FWK_MODULE(GsfElectronColMerger); DEFINE_FWK_MODULE(PhotonColMerger); +DEFINE_FWK_MODULE(ConversionColMerger); DEFINE_FWK_MODULE(PFColMerger); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h index 33b9e00ca7764..907b525817108 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h @@ -1,12 +1,12 @@ /** \class TrackMergeremb * - * + * * \author Stefan Wayand; * Christian Veelken, LLR * - * * - * + * + * * */ #ifndef TauAnalysis_MCEmbeddingTools_TrackMergeremb_H @@ -18,12 +18,27 @@ #include "DataFormats/Common/interface/Handle.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" +#include "DataFormats/EgammaReco/interface/SuperCluster.h" + +#include "DataFormats/EgammaReco/interface/ElectronSeed.h" +#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h" +#include "TrackingTools/PatternTools/interface/Trajectory.h" +#include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h" +#include "DataFormats/EgammaReco/interface/ElectronSeed.h" +#include "DataFormats/ParticleFlowReco/interface/PreId.h" + #include "DataFormats/MuonReco/interface/MuonQuality.h" #include "DataFormats/Common/interface/ValueMap.h" #include "DataFormats/MuonReco/interface/MuonToMuonMap.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" + +#include "DataFormats/GsfTrackReco/interface/GsfTrackExtra.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrackExtraFwd.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" #include "DataFormats/TrackReco/interface/TrackToTrackMap.h" #include @@ -50,12 +65,21 @@ class TrackMergeremb : public edm::stream::EDProducer<> { //typedef edm::ValueMap TrackToTrackMapnew; typedef edm::ValueMap TrackToTrackMapnew; + typedef edm::ValueMap GsfTrackToTrackMapnew; + edm::EDGetTokenT inputs_fixtrackrefs_; edm::EDGetTokenT inputs_fixtrackcol_; + edm::EDGetTokenT inputs_fixgsftrackrefs_; + edm::EDGetTokenT inputs_fixgsftrackcol_; + edm::EDGetTokenT inputs_fixmurefs_; edm::EDGetTokenT inputs_fixmucol_; + + edm::EDGetTokenT inputs_SC_; + edm::EDGetTokenT inputs_rElectronMergedSeeds_; + edm::EDGetTokenT> inputs_rElectronMergedSeedViews_; }; template From 4731fe59e3dc8d53b1139aa65e2653a495134c76 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 18:34:17 +0100 Subject: [PATCH 10/58] MCEmbeddingTools: adding configuration for all filters --- .../MCEmbeddingTools/python/DYToElElGenFilter_cfi.py | 7 +++++++ .../MCEmbeddingTools/python/DYToElTauGenFilter_cfi.py | 6 ++++++ .../MCEmbeddingTools/python/DYToMuTauGenFilter_cfi.py | 6 ++++++ .../MCEmbeddingTools/python/DYToTauTauGenFilter_cfi.py | 6 ++++++ 4 files changed, 25 insertions(+) create mode 100644 TauAnalysis/MCEmbeddingTools/python/DYToElElGenFilter_cfi.py create mode 100644 TauAnalysis/MCEmbeddingTools/python/DYToElTauGenFilter_cfi.py create mode 100644 TauAnalysis/MCEmbeddingTools/python/DYToMuTauGenFilter_cfi.py create mode 100644 TauAnalysis/MCEmbeddingTools/python/DYToTauTauGenFilter_cfi.py diff --git a/TauAnalysis/MCEmbeddingTools/python/DYToElElGenFilter_cfi.py b/TauAnalysis/MCEmbeddingTools/python/DYToElElGenFilter_cfi.py new file mode 100644 index 0000000000000..ca816bf1eaf72 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/python/DYToElElGenFilter_cfi.py @@ -0,0 +1,7 @@ +import FWCore.ParameterSet.Config as cms + + +dyToElElGenFilter = cms.EDFilter("DYToElElGenFilter", + inputTag = cms.InputTag("genParticles"), + #filter = cms.bool(True) + ) diff --git a/TauAnalysis/MCEmbeddingTools/python/DYToElTauGenFilter_cfi.py b/TauAnalysis/MCEmbeddingTools/python/DYToElTauGenFilter_cfi.py new file mode 100644 index 0000000000000..a48d967386197 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/python/DYToElTauGenFilter_cfi.py @@ -0,0 +1,6 @@ +import FWCore.ParameterSet.Config as cms + + +dyToElTauGenFilter = cms.EDFilter("DYToElTauGenFilter", + inputTag = cms.InputTag("genParticles"), + filter = cms.bool(True)) diff --git a/TauAnalysis/MCEmbeddingTools/python/DYToMuTauGenFilter_cfi.py b/TauAnalysis/MCEmbeddingTools/python/DYToMuTauGenFilter_cfi.py new file mode 100644 index 0000000000000..39aa66546d2ed --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/python/DYToMuTauGenFilter_cfi.py @@ -0,0 +1,6 @@ +import FWCore.ParameterSet.Config as cms + + +dyToMuTauGenFilter = cms.EDFilter("DYToMuTauGenFilter", + inputTag = cms.InputTag("genParticles"), + filter = cms.bool(True)) diff --git a/TauAnalysis/MCEmbeddingTools/python/DYToTauTauGenFilter_cfi.py b/TauAnalysis/MCEmbeddingTools/python/DYToTauTauGenFilter_cfi.py new file mode 100644 index 0000000000000..c3e547327f8e0 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/python/DYToTauTauGenFilter_cfi.py @@ -0,0 +1,6 @@ +import FWCore.ParameterSet.Config as cms + + +dyToTauTauGenFilter = cms.EDFilter("DYToTauTauGenFilter", + inputTag = cms.InputTag("genParticles"), + filter = cms.bool(True)) From 384bccf57ff7ca7a57326eca80a4a64936907116 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 18:38:51 +0100 Subject: [PATCH 11/58] MCEmbeddingTools: adding configuration for additional producers --- .../MCEmbeddingTools/python/EmbeddingBeamSpotOnline_cfi.py | 6 ++++++ .../python/EmbeddingHltPixelVerticesProducer_cfi.py | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 TauAnalysis/MCEmbeddingTools/python/EmbeddingBeamSpotOnline_cfi.py create mode 100644 TauAnalysis/MCEmbeddingTools/python/EmbeddingHltPixelVerticesProducer_cfi.py diff --git a/TauAnalysis/MCEmbeddingTools/python/EmbeddingBeamSpotOnline_cfi.py b/TauAnalysis/MCEmbeddingTools/python/EmbeddingBeamSpotOnline_cfi.py new file mode 100644 index 0000000000000..3a18d747069d5 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/python/EmbeddingBeamSpotOnline_cfi.py @@ -0,0 +1,6 @@ +import FWCore.ParameterSet.Config as cms + +onlineEmbeddingBeamSpotProducer = cms.EDProducer('EmbeddingBeamSpotOnlineProducer', + src = cms.InputTag('offlineBeamSpot'), +) + diff --git a/TauAnalysis/MCEmbeddingTools/python/EmbeddingHltPixelVerticesProducer_cfi.py b/TauAnalysis/MCEmbeddingTools/python/EmbeddingHltPixelVerticesProducer_cfi.py new file mode 100644 index 0000000000000..a9139d00b92e4 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/python/EmbeddingHltPixelVerticesProducer_cfi.py @@ -0,0 +1,4 @@ +import FWCore.ParameterSet.Config as cms + +embeddingHltPixelVertices = cms.EDProducer('EmbeddingHltPixelVerticesProducer' +) From 10eaeb2b45859a5f92f1968efd766218dacb6da3 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 18:43:50 +0100 Subject: [PATCH 12/58] MCEmbeddingTools: updating configuration for EmbeddingLHEProducer & MuMu Selection --- .../python/EmbeddingLHEProducer_cfi.py | 1 + .../python/SelectingProcedure_cff.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/EmbeddingLHEProducer_cfi.py b/TauAnalysis/MCEmbeddingTools/python/EmbeddingLHEProducer_cfi.py index dfc40b3513c0a..f441f66903760 100644 --- a/TauAnalysis/MCEmbeddingTools/python/EmbeddingLHEProducer_cfi.py +++ b/TauAnalysis/MCEmbeddingTools/python/EmbeddingLHEProducer_cfi.py @@ -7,6 +7,7 @@ particleToEmbed = cms.int32(15), rotate180 = cms.bool(False), mirror = cms.bool(False), + InitialRecoCorrection = cms.bool(True), studyFSRmode = cms.untracked.string("reco") ) diff --git a/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py b/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py index 806622e32fe7d..fd69ed4c25b13 100644 --- a/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py +++ b/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py @@ -10,7 +10,7 @@ hltResults = cms.InputTag("TriggerResults","","HLT"), l1tResults = cms.InputTag(""), throw = cms.bool(False), - triggerConditions = cms.vstring("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ_v*") + triggerConditions = cms.vstring("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass8_v*") ) @@ -64,11 +64,17 @@ ZmumuCandidatesFilter = cms.EDFilter("CandViewCountFilter", src = cms.InputTag("ZmumuCandidates"), - minNumber = cms.uint32(1), + minNumber = cms.uint32(1) + # filter = cms.bool(True) ) selectedMuonsForEmbedding = cms.EDProducer("MuMuForEmbeddingSelector", - ZmumuCandidatesCollection = cms.InputTag("ZmumuCandidates") + ZmumuCandidatesCollection = cms.InputTag("ZmumuCandidates"), + use_zmass = cms.bool(False), + inputTagVertex = cms.InputTag("offlinePrimaryVertices"), + inputTagBeamSpot = cms.InputTag("offlineBeamSpot"), + PuppiMet = cms.InputTag("slimmedMETsPuppi"), + Met = cms.InputTag("slimmedMETs"), ) makePatMuonsZmumuSelection = cms.Sequence( From 674e409f5e8d9f1f7b3cf0d83b82ca8e1b3192b4 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 19:17:53 +0100 Subject: [PATCH 13/58] MCEmbeddingTools: update customisers --- .../MCEmbeddingTools/python/customisers.py | 988 +++++++++++++----- 1 file changed, 752 insertions(+), 236 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 74e2ea833139f..2708b7b44474f 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -1,9 +1,11 @@ #!/usr/bin/env python -### Various set of customise functions needed for embedding -from __future__ import print_function +# Various set of customise functions needed for embedding import FWCore.ParameterSet.Config as cms +from FWCore.ParameterSet.Utilities import cleanUnscheduled + +from PhysicsTools.NanoAOD.common_cff import ExtVar ################################ Customizer for skimming ########################### ### There are four different parts. @@ -19,53 +21,201 @@ ## E.g What is needed for MERGE must be produce in the CLEAN and SIM step -class module_manipulate(): - def __init__(self, module_name, manipulator_name, steps = ["SELECT","CLEAN","SIM","MERGE"], instance=[""], merge_prefix = ""): +class module_manipulate: + def __init__( + self, + module_name, + manipulator_name, + steps=["SELECT", "CLEAN", "SIM", "MERGE"], + instance=[""], + merge_prefix="", + ): self.module_name = module_name self.manipulator_name = manipulator_name self.steps = steps self.instance = instance - self.merger_name = manipulator_name+"ColMerger" - self.cleaner_name = manipulator_name+"ColCleaner" + self.merger_name = manipulator_name + "ColMerger" + self.cleaner_name = manipulator_name + "ColCleaner" self.merge_prefix = merge_prefix - - to_bemanipulate = [] -to_bemanipulate.append(module_manipulate(module_name = 'siPixelClusters', manipulator_name = "Pixel", steps = ["SELECT","CLEAN"] )) -to_bemanipulate.append(module_manipulate(module_name = 'siStripClusters', manipulator_name = "Strip", steps = ["SELECT","CLEAN"] )) - -to_bemanipulate.append(module_manipulate(module_name = 'generalTracks', manipulator_name = "Track", steps = ["SIM", "MERGE"])) -to_bemanipulate.append(module_manipulate(module_name = 'muons1stStep', manipulator_name = "Muon", steps = ["SIM", "MERGE"])) -to_bemanipulate.append(module_manipulate(module_name = 'gedGsfElectronsTmp', manipulator_name = "GsfElectron", steps = ["SIM", "MERGE"])) -to_bemanipulate.append(module_manipulate(module_name = 'gedPhotonsTmp', manipulator_name = "Photon", steps = ["SIM", "MERGE"])) -to_bemanipulate.append(module_manipulate(module_name = 'particleFlowTmp', manipulator_name = "PF", steps = ["SIM", "MERGE"], instance=["","CleanedHF","CleanedCosmicsMuons","CleanedTrackerAndGlobalMuons","CleanedFakeMuons","CleanedPunchThroughMuons","CleanedPunchThroughNeutralHadrons","AddedMuonsAndHadrons"])) - - -to_bemanipulate.append(module_manipulate(module_name = 'ecalRecHit', manipulator_name = "EcalRecHit", instance= ["EcalRecHitsEB","EcalRecHitsEE"])) -to_bemanipulate.append(module_manipulate(module_name = 'ecalPreshowerRecHit', manipulator_name = "EcalRecHit", instance= ["EcalRecHitsES"])) - -to_bemanipulate.append(module_manipulate(module_name = 'hbheprereco', manipulator_name = "HBHERecHit")) -to_bemanipulate.append(module_manipulate(module_name = 'hbhereco', manipulator_name = "HBHERecHit")) -to_bemanipulate.append(module_manipulate(module_name = 'zdcreco', manipulator_name = "ZDCRecHit")) - -to_bemanipulate.append(module_manipulate(module_name = 'horeco', manipulator_name = "HORecHit")) -to_bemanipulate.append(module_manipulate(module_name = 'hfreco', manipulator_name = "HFRecHit")) -to_bemanipulate.append(module_manipulate(module_name = 'castorreco', manipulator_name = "CastorRecHit")) - - -to_bemanipulate.append(module_manipulate(module_name = 'dt1DRecHits', manipulator_name = "DTRecHit", steps = ["SELECT","CLEAN"] )) -to_bemanipulate.append(module_manipulate(module_name = 'dt1DCosmicRecHits', manipulator_name = "DTRecHit", steps = ["SELECT","CLEAN"] )) - -to_bemanipulate.append(module_manipulate(module_name = 'csc2DRecHits', manipulator_name = "CSCRecHit", steps = ["SELECT","CLEAN"] )) -to_bemanipulate.append(module_manipulate(module_name = 'rpcRecHits', manipulator_name = "RPCRecHit", steps = ["SELECT","CLEAN"] )) - - -def modify_outputModules(process, keep_drop_list = [], module_veto_list = [] ): - outputModulesList = [key for key,value in process.outputModules.items()] +to_bemanipulate.append( + module_manipulate( + module_name="siPixelClusters", + manipulator_name="Pixel", + steps=["SELECT", "CLEAN"], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="siStripClusters", + manipulator_name="Strip", + steps=["SELECT", "CLEAN"], + ) +) + +to_bemanipulate.append( + module_manipulate( + module_name="generalTracks", manipulator_name="Track", steps=["SIM", "MERGE"] + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="electronGsfTracks", + manipulator_name="GsfTrack", + steps=["SIM", "MERGE"], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="conversionStepTracks", + manipulator_name="Track", + steps=["SIM", "MERGE"], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="ckfInOutTracksFromConversions", + manipulator_name="Track", + steps=["SIM", "MERGE"], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="ckfOutInTracksFromConversions", + manipulator_name="Track", + steps=["SIM", "MERGE"], + ) +) + +to_bemanipulate.append( + module_manipulate( + module_name="muons1stStep", manipulator_name="Muon", steps=["SIM", "MERGE"] + ) +) +# to_bemanipulate.append(module_manipulate(module_name = 'gedGsfElectronsTmp', manipulator_name = "GsfElectron", steps = ["SIM", "MERGE"])) +# to_bemanipulate.append(module_manipulate(module_name = 'gedPhotonsTmp', manipulator_name = "Photon", steps = ["SIM", "MERGE"])) +to_bemanipulate.append( + module_manipulate( + module_name="conversions", manipulator_name="Conversion", steps=["SIM", "MERGE"] + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="allConversions", + manipulator_name="Conversion", + steps=["SIM", "MERGE"], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="particleFlowTmp", + manipulator_name="PF", + steps=["SIM", "MERGE"], + instance=[ + "", + "CleanedHF", + "CleanedCosmicsMuons", + "CleanedTrackerAndGlobalMuons", + "CleanedFakeMuons", + "CleanedPunchThroughMuons", + "CleanedPunchThroughNeutralHadrons", + "AddedMuonsAndHadrons", + ], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="ecalDigis", manipulator_name="EcalSrFlag", steps=["SIM", "MERGE"] + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="electronMergedSeeds", + manipulator_name="ElectronSeed", + steps=["SIM", "MERGE"], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="ecalDrivenElectronSeeds", + manipulator_name="EcalDrivenElectronSeed", + steps=["SIM", "MERGE"], + ) +) + +to_bemanipulate.append( + module_manipulate( + module_name="ecalRecHit", + manipulator_name="EcalRecHit", + instance=["EcalRecHitsEB", "EcalRecHitsEE"], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="ecalPreshowerRecHit", + manipulator_name="EcalRecHit", + instance=["EcalRecHitsES"], + ) +) + +to_bemanipulate.append( + module_manipulate(module_name="hbheprereco", manipulator_name="HBHERecHit") +) +to_bemanipulate.append( + module_manipulate(module_name="hbhereco", manipulator_name="HBHERecHit") +) +to_bemanipulate.append( + module_manipulate(module_name="zdcreco", manipulator_name="ZDCRecHit") +) + +to_bemanipulate.append( + module_manipulate(module_name="horeco", manipulator_name="HORecHit") +) +to_bemanipulate.append( + module_manipulate(module_name="hfreco", manipulator_name="HFRecHit") +) +to_bemanipulate.append( + module_manipulate(module_name="castorreco", manipulator_name="CastorRecHit") +) + + +to_bemanipulate.append( + module_manipulate( + module_name="dt1DRecHits", + manipulator_name="DTRecHit", + steps=["SELECT", "CLEAN"], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="dt1DCosmicRecHits", + manipulator_name="DTRecHit", + steps=["SELECT", "CLEAN"], + ) +) + +to_bemanipulate.append( + module_manipulate( + module_name="csc2DRecHits", + manipulator_name="CSCRecHit", + steps=["SELECT", "CLEAN"], + ) +) +to_bemanipulate.append( + module_manipulate( + module_name="rpcRecHits", + manipulator_name="RPCRecHit", + steps=["SELECT", "CLEAN"], + ) +) + + +def modify_outputModules(process, keep_drop_list=[], module_veto_list=[]): + outputModulesList = [key for key, value in process.outputModules.iteritems()] for outputModule in outputModulesList: if outputModule in module_veto_list: continue @@ -75,101 +225,157 @@ def modify_outputModules(process, keep_drop_list = [], module_veto_list = [] ): return process - ################################ Customizer for Selecting ########################### + def keepSelected(dataTier): ret_vstring = cms.untracked.vstring( - # "drop *_*_*_"+dataTier, - "keep *_patMuonsAfterID_*_"+dataTier, - "keep *_slimmedMuons_*_"+dataTier, - "keep *_selectedMuonsForEmbedding_*_"+dataTier, - "keep recoVertexs_offlineSlimmedPrimaryVertices_*_"+dataTier, - "keep *_firstStepPrimaryVertices_*_"+dataTier, - "keep *_offlineBeamSpot_*_"+dataTier - ) + # "drop *_*_*_"+dataTier, + "keep *_patMuonsAfterID_*_" + dataTier, + "keep *_slimmedMuons_*_" + dataTier, + "keep *_slimmedMuonTrackExtras_*_" + dataTier, + "keep *_selectedMuonsForEmbedding_*_" + dataTier, + "keep recoVertexs_offlineSlimmedPrimaryVertices_*_" + dataTier, + "keep *_firstStepPrimaryVertices_*_" + dataTier, + "keep *_offlineBeamSpot_*_" + dataTier, + "keep *_ecalDrivenElectronSeeds_*_" + dataTier, + ) for akt_manimod in to_bemanipulate: if "CLEAN" in akt_manimod.steps: - ret_vstring.append("keep *_"+akt_manimod.module_name+"_*_"+dataTier) + ret_vstring.append("keep *_" + akt_manimod.module_name + "_*_" + dataTier) return ret_vstring -def customiseSelecting(process,reselect=False): + +def customiseSelecting(process, reselect=False): if reselect: process._Process__name = "RESELECT" - dataTier="RESELECT" + dataTier = "RESELECT" + # process.source.inputCommands = cms.untracked.vstring("drop *", + # "keep *_*_*_LHC", + # "keep *_*_*_HLT", + # ) else: process._Process__name = "SELECT" - dataTier="SELECT" - - process.load('TauAnalysis.MCEmbeddingTools.SelectingProcedure_cff') - # don't rekey TrackExtra refs because the full original collections are anyways stored - process.slimmedMuons.trackExtraAssocs = [] - process.patMuonsAfterKinCuts.src = cms.InputTag("slimmedMuons","",dataTier) + dataTier = "SELECT" + + process.load("TauAnalysis.MCEmbeddingTools.SelectingProcedure_cff") + process.patMuonsAfterKinCuts.src = cms.InputTag("slimmedMuons", "", dataTier) + process.selectedMuonsForEmbedding.PuppiMet = cms.InputTag( + "slimmedMETsPuppi", "", dataTier + ) + process.selectedMuonsForEmbedding.Met = cms.InputTag("slimmedMETs", "", dataTier) process.patMuonsAfterID = process.patMuonsAfterLooseID.clone() process.selecting = cms.Path(process.makePatMuonsZmumuSelection) process.schedule.insert(-1, process.selecting) - outputModulesList = [key for key,value in process.outputModules.items()] + outputModulesList = [key for key, value in process.outputModules.iteritems()] for outputModule in outputModulesList: outputModule = getattr(process, outputModule) - outputModule.SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring("selecting")) + outputModule.SelectEvents = cms.untracked.PSet( + SelectEvents=cms.vstring("selecting") + ) outputModule.outputCommands.extend(keepSelected(dataTier)) process = customisoptions(process) - return modify_outputModules(process,[keepSelected(dataTier)]) + return modify_outputModules(process, [keepSelected(dataTier)]) + def customiseSelecting_Reselect(process): - return customiseSelecting(process,reselect=True) + return customiseSelecting(process, reselect=True) + -################################ Customizer for cleaining ########################### -def keepCleaned(): +################################ Customizer for cleaning ########################### + + +def keepCleaned(dataTier): ret_vstring = cms.untracked.vstring( -# "drop *_*_*_LHEembeddingCLEAN", -# "drop *_*_*_CLEAN" - ) + # "drop *_*_*_LHEembeddingCLEAN", + # "drop *_*_*_CLEAN" + "drop *_*_*_" + dataTier, + "keep *_patMuonsAfterID_*_" + dataTier, + "keep *_slimmedMuons_*_" + dataTier, + # "keep *_slimmedMuonTrackExtras_*_" + dataTier, + "keep *_selectedMuonsForEmbedding_*_" + dataTier, + "keep recoVertexs_offlineSlimmedPrimaryVertices_*_" + dataTier, + "keep *_firstStepPrimaryVertices_*_" + dataTier, + "keep *_offlineBeamSpot_*_" + dataTier, + "keep *_l1extraParticles_*_" + dataTier, + # "keep recoPFClusters_*_*_*", + # "keep recoPFRecHits_*_*_*" + ) for akt_manimod in to_bemanipulate: if "MERGE" in akt_manimod.steps: - ret_vstring.append("keep *_"+akt_manimod.module_name+"_*_LHEembeddingCLEAN") - ret_vstring.append("keep *_"+akt_manimod.module_name+"_*_CLEAN") + ret_vstring.append( + "keep *_" + akt_manimod.module_name + "_*_LHEembeddingCLEAN" + ) + ret_vstring.append("keep *_" + akt_manimod.module_name + "_*_CLEAN") ret_vstring.append("keep *_standAloneMuons_*_LHEembeddingCLEAN") ret_vstring.append("keep *_glbTrackQual_*_LHEembeddingCLEAN") return ret_vstring - -def customiseCleaning(process, changeProcessname=True,reselect=False): +def customiseCleaning(process, changeProcessname=True, reselect=False): if changeProcessname: process._Process__name = "CLEAN" if reselect: - dataTier="RESELECT" - else: - dataTier="SELECT" + dataTier = "RESELECT" + else: + dataTier = "SELECT" ## Needed for the Calo Cleaner, could also be put into a function wich fix the input parameters from TrackingTools.TrackAssociator.default_cfi import TrackAssociatorParameterBlock - TrackAssociatorParameterBlock.TrackAssociatorParameters.CSCSegmentCollectionLabel = cms.InputTag("cscSegments","",dataTier) - TrackAssociatorParameterBlock.TrackAssociatorParameters.CaloTowerCollectionLabel = cms.InputTag("towerMaker","",dataTier) - TrackAssociatorParameterBlock.TrackAssociatorParameters.DTRecSegment4DCollectionLabel = cms.InputTag("dt4DSegments","",dataTier) - TrackAssociatorParameterBlock.TrackAssociatorParameters.EBRecHitCollectionLabel = cms.InputTag("ecalRecHit","EcalRecHitsEB",dataTier) - TrackAssociatorParameterBlock.TrackAssociatorParameters.EERecHitCollectionLabel = cms.InputTag("ecalRecHit","EcalRecHitsEE",dataTier) - TrackAssociatorParameterBlock.TrackAssociatorParameters.HBHERecHitCollectionLabel = cms.InputTag("hbhereco","",dataTier) - TrackAssociatorParameterBlock.TrackAssociatorParameters.HORecHitCollectionLabel = cms.InputTag("horeco","",dataTier) - - MuonImput = cms.InputTag("selectedMuonsForEmbedding","","") ## This are the muon + TrackAssociatorParameterBlock.TrackAssociatorParameters.CSCSegmentCollectionLabel = cms.InputTag( + "cscSegments", "", dataTier + ) + TrackAssociatorParameterBlock.TrackAssociatorParameters.CaloTowerCollectionLabel = ( + cms.InputTag("towerMaker", "", dataTier) + ) + TrackAssociatorParameterBlock.TrackAssociatorParameters.DTRecSegment4DCollectionLabel = cms.InputTag( + "dt4DSegments", "", dataTier + ) + TrackAssociatorParameterBlock.TrackAssociatorParameters.EBRecHitCollectionLabel = ( + cms.InputTag("ecalRecHit", "EcalRecHitsEB", dataTier) + ) + TrackAssociatorParameterBlock.TrackAssociatorParameters.EERecHitCollectionLabel = ( + cms.InputTag("ecalRecHit", "EcalRecHitsEE", dataTier) + ) + TrackAssociatorParameterBlock.TrackAssociatorParameters.HBHERecHitCollectionLabel = cms.InputTag( + "hbhereco", "", dataTier + ) + TrackAssociatorParameterBlock.TrackAssociatorParameters.HORecHitCollectionLabel = ( + cms.InputTag("horeco", "", dataTier) + ) + + MuonImput = cms.InputTag("selectedMuonsForEmbedding", "", "") ## This are the muon for akt_manimod in to_bemanipulate: if "CLEAN" in akt_manimod.steps: oldCollections_in = cms.VInputTag() for instance in akt_manimod.instance: - oldCollections_in.append(cms.InputTag(akt_manimod.module_name,instance,dataTier)) - setattr(process, akt_manimod.module_name, cms.EDProducer(akt_manimod.cleaner_name,MuonCollection = MuonImput,TrackAssociatorParameters = TrackAssociatorParameterBlock.TrackAssociatorParameters,oldCollection = oldCollections_in)) + oldCollections_in.append( + cms.InputTag(akt_manimod.module_name, instance, dataTier) + ) + setattr( + process, + akt_manimod.module_name, + cms.EDProducer( + akt_manimod.cleaner_name, + MuonCollection=MuonImput, + TrackAssociatorParameters=TrackAssociatorParameterBlock.TrackAssociatorParameters, + oldCollection=oldCollections_in, + ), + ) process.ecalPreshowerRecHit.TrackAssociatorParameters.usePreshower = cms.bool(True) - process = customisoptions(process) - return modify_outputModules(process,[keepSelected(dataTier),keepCleaned()],["MINIAODoutput"]) + process = customisoptions(process) + return modify_outputModules( + process, [keepSelected(dataTier), keepCleaned(dataTier)], ["MINIAODoutput"] + ) + + +################################ Customizer for LHE ########################### -################################ Customizer for simulaton ########################### def keepLHE(): ret_vstring = cms.untracked.vstring() ret_vstring.append("keep *_externalLHEProducer_*_LHEembedding") @@ -177,53 +383,109 @@ def keepLHE(): return ret_vstring -def keepSimulated(): - ret_vstring = cms.untracked.vstring() - for akt_manimod in to_bemanipulate: - if "MERGE" in akt_manimod.steps: - ret_vstring.append("keep *_"+akt_manimod.module_name+"_*_SIMembedding") - ret_vstring.append("keep *_genParticles_*_SIMembedding") - ret_vstring.append("keep *_standAloneMuons_*_SIMembedding") - ret_vstring.append("keep *_glbTrackQual_*_SIMembedding") - ret_vstring.append("keep *_generator_*_SIMembedding") - ret_vstring.append("keep *_addPileupInfo_*_SIMembedding") - ret_vstring.append("keep *_slimmedAddPileupInfo_*_*") - return ret_vstring - - - - -def customiseLHE(process, changeProcessname=True,reselect=False): +def customiseLHE(process, changeProcessname=True, reselect=False): if reselect: - dataTier="RESELECT" - else: - dataTier="SELECT" + dataTier = "RESELECT" + else: + dataTier = "SELECT" if changeProcessname: process._Process__name = "LHEembedding" - process.load('TauAnalysis.MCEmbeddingTools.EmbeddingLHEProducer_cfi') + process.load("TauAnalysis.MCEmbeddingTools.EmbeddingLHEProducer_cfi") if reselect: - process.externalLHEProducer.vertices=cms.InputTag("offlineSlimmedPrimaryVertices","","RESELECT") + process.externalLHEProducer.vertices = cms.InputTag( + "offlineSlimmedPrimaryVertices", "", "RESELECT" + ) process.lheproduction = cms.Path(process.makeexternalLHEProducer) - process.schedule.insert(0,process.lheproduction) - + process.schedule.insert(0, process.lheproduction) process = customisoptions(process) - return modify_outputModules(process,[keepSelected(dataTier),keepCleaned(), keepLHE()],["MINIAODoutput"]) + return modify_outputModules( + process, + [keepSelected(dataTier), keepCleaned(dataTier), keepLHE()], + ["MINIAODoutput"], + ) + + +def customiseLHEandCleaning(process, reselect=False): + process._Process__name = "LHEembeddingCLEAN" + process = customiseCleaning(process, changeProcessname=False, reselect=reselect) + process = customiseLHE(process, changeProcessname=False, reselect=reselect) + return process + + +def customiseLHEandCleaning_Reselect(process): + return customiseLHEandCleaning(process, reselect=True) + + +################################ Customizer for simulaton ########################### + + +def keepSimulated(process, processname="SIMembedding"): + ret_vstring = cms.untracked.vstring() + for akt_manimod in to_bemanipulate: + if "MERGE" in akt_manimod.steps: + ret_vstring.append( + "keep *_" + akt_manimod.module_name + "_*_{}".format(processname) + ) + ret_vstring.append("keep *_genParticles_*_{}".format(processname)) + ret_vstring.append("keep *_standAloneMuons_*_{}".format(processname)) + ret_vstring.append("keep *_glbTrackQual_*_{}".format(processname)) + ret_vstring.append("keep *_generator_*_{}".format(processname)) + ret_vstring.append("keep *_addPileupInfo_*_{}".format(processname)) + ret_vstring.append("keep *_selectedMuonsForEmbedding_*_*") + ret_vstring.append("keep *_slimmedAddPileupInfo_*_*") + ret_vstring.append("keep *_embeddingHltPixelVertices_*_*") + ret_vstring.append("keep *_*_vertexPosition_*") + ret_vstring.append("keep recoMuons_muonsFromCosmics_*_*") + ret_vstring.append("keep recoTracks_cosmicMuons1Leg_*_*") + ret_vstring.append("keep recoMuons_muonsFromCosmics1Leg_*_*") + ret_vstring.append("keep *_muonDTDigis_*_*") + ret_vstring.append("keep *_muonCSCDigis_*_*") + # for those two steps, the output has to be modified + # to keep the information from the cleaning step in the output file + if processname == "SIMembeddingpreHLT" or processname == "SIMembeddingHLT": + rawreco_commands = set(process.RAWRECOEventContent.outputCommands) + rawreco_commands_excl = rawreco_commands - set( + process.RAWSIMEventContent.outputCommands + ) + for entry in rawreco_commands_excl: + if ( + processname == "SIMembeddingpreHLT" + and "muonReducedTrackExtras" in entry + ): + continue + if not any( + x in entry + for x in [ + "TotemTimingLocalTrack", + "ForwardProton", + "ctppsDiamondLocalTracks", + ] + ): + ret_vstring.append(entry) + return ret_vstring -def customiseGenerator(process, changeProcessname=True,reselect=False): +def customiseGenerator(process, changeProcessname=True, reselect=False): if reselect: - dataTier="RESELECT" + dataTier = "RESELECT" else: - dataTier="SELECT" + dataTier = "SELECT" if changeProcessname: process._Process__name = "SIMembedding" ## here correct the vertex collection - process.load('TauAnalysis.MCEmbeddingTools.EmbeddingVertexCorrector_cfi') + process.load("TauAnalysis.MCEmbeddingTools.EmbeddingVertexCorrector_cfi") process.VtxSmeared = process.VtxCorrectedToInput.clone() - print("Correcting Vertex in genEvent to one from input. Replaced 'VtxSmeared' with the Corrector.") + print( + "Correcting Vertex in genEvent to one from input. Replaced 'VtxSmeared' with the Corrector." + ) + process.load("TauAnalysis.MCEmbeddingTools.EmbeddingBeamSpotOnline_cfi") + process.hltOnlineBeamSpot = process.onlineEmbeddingBeamSpotProducer.clone() + print( + "Setting online beam spot in HLTSchedule to the one from input data. Replaced 'hltOnlineBeamSpot' with the offline beam spot." + ) # Remove BeamSpot Production, use the one from selected data instead. process.reconstruction.remove(process.offlineBeamSpot) @@ -243,233 +505,487 @@ def customiseGenerator(process, changeProcessname=True,reselect=False): process.mix.digitizers.strip.Noise = cms.bool(False) + # Replace HLT vertexing with vertex taken from LHE step + process.load("TauAnalysis.MCEmbeddingTools.EmbeddingHltPixelVerticesProducer_cfi") + process.hltPixelVertices = process.embeddingHltPixelVertices.clone() + process.offlinePrimaryVertices = process.embeddingHltPixelVertices.clone() + process.firstStepPrimaryVerticesUnsorted = process.embeddingHltPixelVertices.clone() + process.firstStepPrimaryVerticesPreSplitting = ( + process.embeddingHltPixelVertices.clone() + ) - process = customisoptions(process) + process = customisoptions(process) ##process = fix_input_tags(process) - return modify_outputModules(process,[keepSelected(dataTier),keepCleaned(),keepSimulated()],["AODSIMoutput"]) + return modify_outputModules( + process, + [keepSelected(dataTier), keepCleaned(dataTier), keepSimulated()], + ["AODSIMoutput"], + ) + def customiseGenerator_Reselect(process): - return customiseGenerator(process,reselect=True) + return customiseGenerator(process, reselect=True) + + +def customiseGenerator_preHLT(process, changeProcessname=True, reselect=False): + if reselect: + dataTier = "RESELECT" + else: + dataTier = "SELECT" + if changeProcessname: + process._Process__name = "SIMembeddingpreHLT" + + ## here correct the vertex collection + + process.load("TauAnalysis.MCEmbeddingTools.EmbeddingVertexCorrector_cfi") + process.VtxSmeared = process.VtxCorrectedToInput.clone() + print( + "Correcting Vertex in genEvent to one from input. Replaced 'VtxSmeared' with the Corrector." + ) + + # Disable noise simulation + process.mix.digitizers.castor.doNoise = cms.bool(False) + + process.mix.digitizers.ecal.doESNoise = cms.bool(False) + process.mix.digitizers.ecal.doENoise = cms.bool(False) + + process.mix.digitizers.hcal.doNoise = cms.bool(False) + process.mix.digitizers.hcal.doThermalNoise = cms.bool(False) + process.mix.digitizers.hcal.doHPDNoise = cms.bool(False) + + process.mix.digitizers.pixel.AddNoisyPixels = cms.bool(False) + process.mix.digitizers.pixel.AddNoise = cms.bool(False) + + process.mix.digitizers.strip.Noise = cms.bool(False) + + process = customisoptions(process) + ##process = fix_input_tags(process) + + return modify_outputModules( + process, + [ + keepSelected(dataTier), + keepCleaned(dataTier), + keepSimulated(process, processname="SIMembeddingpreHLT"), + ], + ["AODSIMoutput"], + ) + + +def customiseGenerator_preHLT_Reselect(process): + return customiseGenerator_preHLT(process, reselect=True) + + +def customiseGenerator_HLT(process, changeProcessname=True, reselect=False): + if reselect: + dataTier = "RESELECT" + else: + dataTier = "SELECT" + if changeProcessname: + process._Process__name = "SIMembeddingHLT" + + ## here correct the vertex collection + process.load("TauAnalysis.MCEmbeddingTools.EmbeddingBeamSpotOnline_cfi") + process.hltOnlineBeamSpot = process.onlineEmbeddingBeamSpotProducer.clone() + print( + "Setting online beam spot in HLTSchedule to the one from input data. Replaced 'hltOnlineBeamSpot' with the offline beam spot." + ) + + # Replace HLT vertexing with vertex taken from LHE step + process.load("TauAnalysis.MCEmbeddingTools.EmbeddingHltPixelVerticesProducer_cfi") + process.hltPixelVertices = process.embeddingHltPixelVertices.clone() + process.offlinePrimaryVertices = process.embeddingHltPixelVertices.clone() + process.firstStepPrimaryVerticesUnsorted = process.embeddingHltPixelVertices.clone() + process.firstStepPrimaryVerticesPreSplitting = ( + process.embeddingHltPixelVertices.clone() + ) + + process = customisoptions(process) + ##process = fix_input_tags(process) + + return modify_outputModules( + process, + [ + keepSelected(dataTier), + keepCleaned(dataTier), + keepLHE(), + keepSimulated(process, processname="SIMembeddingpreHLT"), + keepSimulated(process, processname="SIMembeddingHLT"), + ], + ["AODSIMoutput"], + ) + + +def customiseGenerator_HLT_Reselect(process): + return customiseGenerator_HLT(process, reselect=True) + + +def customiseGenerator_postHLT(process, changeProcessname=True, reselect=False): + if reselect: + dataTier = "RESELECT" + else: + dataTier = "SELECT" + if changeProcessname: + process._Process__name = "SIMembedding" + + ## here correct the vertex collection + + # process.load('TauAnalysis.MCEmbeddingTools.EmbeddingVertexCorrector_cfi') + # process.VtxSmeared = process.VtxCorrectedToInput.clone() + # print "Correcting Vertex in genEvent to one from input. Replaced 'VtxSmeared' with the Corrector." + # process.load('TauAnalysis.MCEmbeddingTools.EmbeddingBeamSpotOnline_cfi') + # process.hltOnlineBeamSpot = process.onlineEmbeddingBeamSpotProducer.clone() + # print "Setting online beam spot in HLTSchedule to the one from input data. Replaced 'hltOnlineBeamSpot' with the offline beam spot." + + # Remove BeamSpot Production, use the one from selected data instead. + process.reconstruction.remove(process.offlineBeamSpot) + + process = customisoptions(process) + ##process = fix_input_tags(process) + + return modify_outputModules( + process, + [ + keepSelected(dataTier), + keepCleaned(dataTier), + keepLHE(), + keepSimulated(process, processname="SIMembeddingpreHLT"), + keepSimulated(process, processname="SIMembeddingHLT"), + keepSimulated(process, processname="SIMembedding"), + ], + ["AODSIMoutput"], + ) + + +def customiseGenerator_postHLT_Reselect(process): + return customiseGenerator_postHLT(process, reselect=True) + ################################ Customizer for merging ########################### + + def keepMerged(dataTier="SELECT"): ret_vstring = cms.untracked.vstring() - ret_vstring.append("drop *_*_*_"+dataTier) + ret_vstring.append("drop *_*_*_" + dataTier) ret_vstring.append("keep *_prunedGenParticles_*_MERGE") + ret_vstring.append("keep *_generator_*_SIMembeddingpreHLT") + ret_vstring.append("keep *_generator_*_SIMembeddingHLT") ret_vstring.append("keep *_generator_*_SIMembedding") + ret_vstring.append("keep *_selectedMuonsForEmbedding_*_*") return ret_vstring -def customiseKeepPrunedGenParticles(process,reselect=False): +def customiseKeepPrunedGenParticles(process, reselect=False): if reselect: - dataTier="RESELECT" + dataTier = "RESELECT" else: - dataTier="SELECT" - - process.load('PhysicsTools.PatAlgos.slimming.genParticles_cff') - process.merge_step += process.prunedGenParticlesWithStatusOne - process.load('PhysicsTools.PatAlgos.slimming.prunedGenParticles_cfi') - process.merge_step += process.prunedGenParticles - process.load('PhysicsTools.PatAlgos.slimming.packedGenParticles_cfi') - process.merge_step += process.packedGenParticles - - process.load('PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi') - process.merge_step += process.muonMatch - process.load('PhysicsTools.PatAlgos.mcMatchLayer0.electronMatch_cfi') - process.merge_step += process.electronMatch - process.load('PhysicsTools.PatAlgos.mcMatchLayer0.photonMatch_cfi') - process.merge_step += process.photonMatch - process.load('PhysicsTools.PatAlgos.mcMatchLayer0.tauMatch_cfi') - process.merge_step += process.tauMatch - process.load('PhysicsTools.JetMCAlgos.TauGenJets_cfi') - process.merge_step += process.tauGenJets - process.load('PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff') - process.merge_step += process.patJetPartons - process.load('PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi') - process.merge_step += process.patJetPartonMatch + dataTier = "SELECT" + + process.keep_step = cms.Path() + + process.load("PhysicsTools.PatAlgos.slimming.genParticles_cff") + process.keep_step += process.prunedGenParticlesWithStatusOne + process.load("PhysicsTools.PatAlgos.slimming.prunedGenParticles_cfi") + process.keep_step += process.prunedGenParticles + process.load("PhysicsTools.PatAlgos.slimming.packedGenParticles_cfi") + process.keep_step += process.packedGenParticles + process.load("PhysicsTools.PatAlgos.slimming.slimmedGenJets_cfi") + process.keep_step += process.slimmedGenJets + + process.load("PhysicsTools.PatAlgos.mcMatchLayer0.muonMatch_cfi") + process.keep_step += process.muonMatch + process.load("PhysicsTools.PatAlgos.mcMatchLayer0.electronMatch_cfi") + process.keep_step += process.electronMatch + process.load("PhysicsTools.PatAlgos.mcMatchLayer0.photonMatch_cfi") + process.keep_step += process.photonMatch + process.load("PhysicsTools.PatAlgos.mcMatchLayer0.tauMatch_cfi") + process.keep_step += process.tauMatch + process.load("PhysicsTools.JetMCAlgos.TauGenJets_cfi") + process.keep_step += process.tauGenJets + process.load("PhysicsTools.PatAlgos.mcMatchLayer0.jetFlavourId_cff") + process.keep_step += process.patJetPartons + process.load("PhysicsTools.PatAlgos.mcMatchLayer0.jetMatch_cfi") + process.keep_step += process.patJetPartonMatch process.muonMatch.matched = "prunedGenParticles" process.electronMatch.matched = "prunedGenParticles" - process.electronMatch.src = cms.InputTag("reducedEgamma","reducedGedGsfElectrons") + process.electronMatch.src = cms.InputTag("reducedEgamma", "reducedGedGsfElectrons") process.photonMatch.matched = "prunedGenParticles" - process.photonMatch.src = cms.InputTag("reducedEgamma","reducedGedPhotons") + process.photonMatch.src = cms.InputTag("reducedEgamma", "reducedGedPhotons") process.tauMatch.matched = "prunedGenParticles" process.tauGenJets.GenParticles = "prunedGenParticles" ##Boosted taus - #process.tauMatchBoosted.matched = "prunedGenParticles" - #process.tauGenJetsBoosted.GenParticles = "prunedGenParticles" + # process.tauMatchBoosted.matched = "prunedGenParticles" + # process.tauGenJetsBoosted.GenParticles = "prunedGenParticles" process.patJetPartons.particles = "prunedGenParticles" process.patJetPartonMatch.matched = "prunedGenParticles" - process.patJetPartonMatch.mcStatus = [ 3, 23 ] + process.patJetPartonMatch.mcStatus = [3, 23] process.patJetGenJetMatch.matched = "slimmedGenJets" - process.patJetGenJetMatchAK8.matched = "slimmedGenJetsAK8" - process.patJetGenJetMatchAK8Puppi.matched = "slimmedGenJetsAK8" + process.patJetGenJetMatchAK8.matched = "slimmedGenJetsAK8" process.patMuons.embedGenMatch = False process.patElectrons.embedGenMatch = False process.patPhotons.embedGenMatch = False process.patTaus.embedGenMatch = False process.patTausBoosted.embedGenMatch = False process.patJets.embedGenPartonMatch = False - #also jet flavour must be switched + # also jet flavour must be switched process.patJetFlavourAssociation.rParam = 0.4 - process.schedule.insert(0,process.merge_step) - process = customisoptions(process) + process.schedule.insert(0, process.keep_step) + process = customisoptions(process) return modify_outputModules(process, [keepMerged(dataTier)]) -def customiseMerging(process, changeProcessname=True,reselect=False): +def customiseMerging(process, changeProcessname=True, reselect=False): if changeProcessname: process._Process__name = "MERGE" if reselect: - dataTier="RESELECT" + dataTier = "RESELECT" else: - dataTier="SELECT" - + dataTier = "SELECT" process.source.inputCommands = cms.untracked.vstring() process.source.inputCommands.append("keep *_*_*_*") - #process.source.inputCommands.append("drop *_*_*_SELECT") - #process.source.inputCommands.append("drop *_*_*_SIMembedding") - #process.source.inputCommands.append("drop *_*_*_LHEembeddingCLEAN") - #process.source.inputCommands.extend(keepSimulated()) - #process.source.inputCommands.extend(keepCleaned()) + # process.source.inputCommands.append("drop *_*_*_SELECT") + # process.source.inputCommands.append("drop *_*_*_SIMembedding") + # process.source.inputCommands.append("drop *_*_*_LHEembeddingCLEAN") + # process.source.inputCommands.extend(keepSimulated()) + # process.source.inputCommands.extend(keepCleaned()) - process.load('Configuration.StandardSequences.Reconstruction_Data_cff') + process.load("Configuration.StandardSequences.Reconstruction_Data_cff") process.merge_step = cms.Path() - + # produce local Calo + process.load("RecoLocalCalo.Configuration.RecoLocalCalo_cff") + process.merge_step += process.calolocalreco + process.merge_step += process.caloglobalreco + process.merge_step += process.reducedHcalRecHitsSequence + + # produce hcal towers + process.load("RecoLocalCalo.CaloTowersCreator.calotowermaker_cfi") + process.merge_step += process.calotowermaker + process.merge_step += process.towerMaker + + # produce clusters + process.load("RecoEcal.Configuration.RecoEcal_cff") + process.merge_step += process.ecalClusters + + # produce PFCluster Collections + process.load("RecoParticleFlow.PFClusterProducer.particleFlowCluster_cff") + process.merge_step += process.particleFlowCluster + process.load( + "RecoEcal.EgammaClusterProducers.particleFlowSuperClusteringSequence_cff" + ) + process.merge_step += process.particleFlowSuperClusteringSequence + + # muonEcalDetIds + process.load("RecoMuon.MuonIdentification.muons1stStep_cfi") + process.merge_step += process.muonEcalDetIds for akt_manimod in to_bemanipulate: if "MERGE" in akt_manimod.steps: - #if akt_manimod.module_name != 'particleFlowTmp': - # continue - print(akt_manimod.module_name) mergCollections_in = cms.VInputTag() for instance in akt_manimod.instance: - mergCollections_in.append(cms.InputTag(akt_manimod.merge_prefix+akt_manimod.module_name,instance,"SIMembedding")) - mergCollections_in.append(cms.InputTag(akt_manimod.merge_prefix+akt_manimod.module_name,instance,"LHEembeddingCLEAN"))## Mayb make some process history magic which finds out if it was CLEAN or LHEembeddingCLEAN step - setattr(process, akt_manimod.module_name, cms.EDProducer(akt_manimod.merger_name, - mergCollections = mergCollections_in - ) + mergCollections_in.append( + cms.InputTag( + akt_manimod.merge_prefix + akt_manimod.module_name, + instance, + "SIMembedding", + ) + ) + mergCollections_in.append( + cms.InputTag( + akt_manimod.merge_prefix + akt_manimod.module_name, + instance, + "LHEembeddingCLEAN", + ) + ) + setattr( + process, + akt_manimod.module_name, + cms.EDProducer( + akt_manimod.merger_name, mergCollections=mergCollections_in + ), ) - process.merge_step +=getattr(process, akt_manimod.module_name) - + process.merge_step += getattr(process, akt_manimod.module_name) process.merge_step += process.doAlldEdXEstimators process.merge_step += process.vertexreco - process.unsortedOfflinePrimaryVertices.beamSpotLabel = cms.InputTag("offlineBeamSpot","",dataTier) - process.ak4CaloJetsForTrk.srcPVs = cms.InputTag("firstStepPrimaryVertices","",dataTier) + process.unsortedOfflinePrimaryVertices.beamSpotLabel = cms.InputTag( + "offlineBeamSpot", "", dataTier + ) + process.ak4CaloJetsForTrk.srcPVs = cms.InputTag( + "firstStepPrimaryVertices", "", dataTier + ) process.muons.FillDetectorBasedIsolation = cms.bool(False) process.muons.FillSelectorMaps = cms.bool(False) process.muons.FillShoweringInfo = cms.bool(False) process.muons.FillCosmicsIdMap = cms.bool(False) - process.muonsFromCosmics.fillShowerDigis = cms.bool(False) - process.muonsFromCosmics1Leg.fillShowerDigis = cms.bool(False) + # seed configuration needed for seedmerger + process.load( + "RecoEgamma.EgammaElectronProducers.ecalDrivenElectronSeedsParameters_cff" + ) + process.ecalDrivenElectronSeeds.SeedConfiguration = cms.PSet( + process.ecalDrivenElectronSeedsParameters + ) process.merge_step += process.highlevelreco - - #process.merge_step.remove(process.reducedEcalRecHitsEE) - #process.merge_step.remove(process.reducedEcalRecHitsEB) + # process.merge_step.remove(process.reducedEcalRecHitsEE) + # process.merge_step.remove(process.reducedEcalRecHitsEB) process.merge_step.remove(process.ak4JetTracksAssociatorExplicit) - process.merge_step.remove(process.pfTrack) - process.merge_step.remove(process.pfConversions) - process.merge_step.remove(process.pfV0) - process.merge_step.remove(process.particleFlowDisplacedVertexCandidate) - process.merge_step.remove(process.particleFlowDisplacedVertex) - process.merge_step.remove(process.pfDisplacedTrackerVertex) - process.merge_step.remove(process.pfTrackElec) - process.merge_step.remove(process.electronsWithPresel) - process.merge_step.remove(process.mvaElectrons) - process.merge_step.remove(process.particleFlowBlock) - process.merge_step.remove(process.particleFlowEGamma) - process.merge_step.remove(process.gedGsfElectronCores) - # process.merge_step.remove(process.gedGsfElectronsTmp) - process.merge_step.remove(process.gedPhotonCore) - process.merge_step.remove(process.ecalDrivenGsfElectronCores) - process.merge_step.remove(process.ecalDrivenGsfElectrons) - process.merge_step.remove(process.uncleanedOnlyElectronSeeds) - process.merge_step.remove(process.uncleanedOnlyAllConversions) - process.merge_step.remove(process.uncleanedOnlyPfTrack) - process.merge_step.remove(process.uncleanedOnlyPfTrackElec) - process.merge_step.remove(process.uncleanedOnlyGsfElectrons) - process.merge_step.remove(process.uncleanedOnlyElectronCkfTrackCandidates) process.merge_step.remove(process.cosmicsVeto) process.merge_step.remove(process.cosmicsVetoTrackCandidates) - # process.merge_step.remove(process.ecalDrivenGsfElectronCores) - # process.merge_step.remove(process.ecalDrivenGsfElectrons) - # process.merge_step.remove(process.gedPhotonsTmp) - # process.merge_step.remove(process.particleFlowTmp) - process.merge_step.remove(process.hcalnoise) - process.merge_step.remove(process.lowPtGsfElectronTask) - process.merge_step.remove(process.gsfTracksOpenConversions) + # process.merge_step.remove(process.ecalDrivenGsfElectronCores) + # process.merge_step.remove(process.ecalDrivenGsfElectrons) + # process.merge_step.remove(process.gedPhotonsTmp) + # process.merge_step.remove(process.particleFlowTmp) - process.load('CommonTools.ParticleFlow.genForPF2PAT_cff') + process.merge_step.remove(process.hcalnoise) - process.merge_step += process.genForPF2PATSequence + process.load("CommonTools.ParticleFlow.genForPF2PAT_cff") - process.slimmingTask.remove(process.slimmedLowPtElectronsTask) + # process.muonsFromCosmics.ShowerDigiFillerParameters.dtDigiCollectionLabel = cms.InputTag("simMuonDTDigis") - process.schedule.insert(0,process.merge_step) + process.merge_step += process.genForPF2PATSequence + process.schedule.insert(0, process.merge_step) # process.load('PhysicsTools.PatAlgos.slimming.slimmedGenJets_cfi') - - process = customisoptions(process) + process = customisoptions(process) return modify_outputModules(process, [keepMerged(dataTier)]) + def customiseMerging_Reselect(process, changeProcessname=True): return customiseMerging(process, changeProcessname=changeProcessname, reselect=True) -################################ cross Customizers ########################### -def customiseLHEandCleaning(process,reselect=False): - process._Process__name = "LHEembeddingCLEAN" - process = customiseCleaning(process,changeProcessname=False,reselect=reselect) - process = customiseLHE(process,changeProcessname=False,reselect=reselect) +################################ Customize NanoAOD ################################ + + +def customiseNanoAOD(process): + + process.embeddingTable = cms.EDProducer( + "GlobalVariablesTableProducer", + name=cms.string("TauEmbedding"), + doc=cms.string("TauEmbedding"), + variables=cms.PSet( + nInitialPairCandidates=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "nPairCandidates"), + float, + doc="number of muons pairs suitable for selection (for internal studies only)", + ), + SelectionOldMass=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "oldMass"), + float, + doc="Mass of the Dimuon pair using the old selection algorithm (for internal studies only)", + ), + SelectionNewMass=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "newMass"), + float, + doc="Mass of the Dimuon pair using the new selection algorithm (for internal studies only)", + ), + isMediumLeadingMuon=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "isMediumLeadingMuon"), + bool, + doc="leading muon ID (medium)", + ), + isMediumTrailingMuon=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "isMediumTrailingMuon"), + bool, + doc="trailing muon ID (medium)", + ), + isTightLeadingMuon=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "isTightLeadingMuon"), + bool, + doc="leading muon ID (tight)", + ), + isTightTrailingMuon=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "isTightTrailingMuon"), + bool, + doc="trailing muon ID (tight)", + ), + initialMETEt=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "initialMETEt"), + float, + doc="MET Et of selected event", + ), + initialMETphi=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "initialMETphi"), + float, + doc="MET phi of selected event", + ), + initialPuppiMETEt=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "initialPuppiMETEt"), + float, + doc="PuppiMET Et of selected event", + ), + initialPuppiMETphi=ExtVar( + cms.InputTag("selectedMuonsForEmbedding", "initialPuppiMETphi"), + float, + doc="PuppiMET phi of selected event", + ), + ), + ) + process.embeddingTableTask = cms.Task(process.embeddingTable) + process.schedule.associate(process.embeddingTableTask) + return process -def customiseLHEandCleaning_Reselect(process): - return customiseLHEandCleaning(process,reselect=True) -################################ additionla Customizer ########################### +################################ cross Customizers ########################### + + +################################ additional Customizer ########################### + def customisoptions(process): if not hasattr(process, "options"): process.options = cms.untracked.PSet() - process.options.emptyRunLumiMode = cms.untracked.string('doNotHandleEmptyRunsAndLumis') + process.options.emptyRunLumiMode = cms.untracked.string( + "doNotHandleEmptyRunsAndLumis" + ) if not hasattr(process, "bunchSpacingProducer"): - process.load('RecoLuminosity.LumiProducer.bunchSpacingProducer_cfi') - process.bunchSpacingProducer = process.bunchSpacingProducer.clone(overrideBunchSpacing = True) + process.bunchSpacingProducer = cms.EDProducer("BunchSpacingProducer") + process.bunchSpacingProducer.bunchSpacingOverride = cms.uint32(25) + process.bunchSpacingProducer.overrideBunchSpacing = cms.bool(True) process.options.numberOfThreads = cms.untracked.uint32(1) process.options.numberOfStreams = cms.untracked.uint32(0) return process + ############################### MC specific Customizer ########################### + def customiseFilterZToMuMu(process): process.load("TauAnalysis.MCEmbeddingTools.DYToMuMuGenFilter_cfi") process.ZToMuMuFilter = cms.Path(process.dYToMuMuGenFilter) - process.schedule.insert(-1,process.ZToMuMuFilter) + process.schedule.insert(-1, process.ZToMuMuFilter) return process + def customiseFilterTTbartoMuMu(process): process.load("TauAnalysis.MCEmbeddingTools.TTbartoMuMuGenFilter_cfi") process.MCFilter = cms.Path(process.TTbartoMuMuGenFilter) return customiseMCFilter(process) + def customiseMCFilter(process): - process.schedule.insert(-1,process.MCFilter) - outputModulesList = [key for key,value in process.outputModules.items()] + process.schedule.insert(-1, process.MCFilter) + outputModulesList = [key for key, value in process.outputModules.iteritems()] for outputModule in outputModulesList: outputModule = getattr(process, outputModule) - outputModule.SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring("MCFilter")) + outputModule.SelectEvents = cms.untracked.PSet( + SelectEvents=cms.vstring("MCFilter") + ) return process -def fix_input_tags(process, formodules = ["generalTracks","cscSegments","dt4DSegments","rpcRecHits"]): + +def fix_input_tags( + process, formodules=["generalTracks", "cscSegments", "dt4DSegments", "rpcRecHits"] +): def change_tags_process(test_input): if isinstance(test_input, cms.InputTag): if test_input.getModuleLabel() in formodules: @@ -489,7 +1005,7 @@ def search_for_tags(pset): else: change_tags_process(pset[key]) else: - print("must be python dict not a ",type(pset)) + print("must be python dict not a {}".format(type(pset))) for module in process.producers_(): search_for_tags(getattr(process, module).__dict__) From c1b408f6f95a9db6dc0f51fb33922425f39c718f Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 19:35:08 +0100 Subject: [PATCH 14/58] customisers.py: remove cleanUnscheduled since deprecated --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 2708b7b44474f..3b4dbbf7e01c2 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -3,7 +3,6 @@ # Various set of customise functions needed for embedding import FWCore.ParameterSet.Config as cms -from FWCore.ParameterSet.Utilities import cleanUnscheduled from PhysicsTools.NanoAOD.common_cff import ExtVar From 2cba9850faef154c28966f1e52d909d13a6812da Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 19:53:44 +0100 Subject: [PATCH 15/58] customisers.py: fix remaining code bugs --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 3b4dbbf7e01c2..08479b2606f64 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -214,7 +214,7 @@ def __init__( def modify_outputModules(process, keep_drop_list=[], module_veto_list=[]): - outputModulesList = [key for key, value in process.outputModules.iteritems()] + outputModulesList = [key for key, value in process.outputModules.items()] for outputModule in outputModulesList: if outputModule in module_veto_list: continue @@ -268,7 +268,7 @@ def customiseSelecting(process, reselect=False): process.selecting = cms.Path(process.makePatMuonsZmumuSelection) process.schedule.insert(-1, process.selecting) - outputModulesList = [key for key, value in process.outputModules.iteritems()] + outputModulesList = [key for key, value in process.outputModules.items()] for outputModule in outputModulesList: outputModule = getattr(process, outputModule) outputModule.SelectEvents = cms.untracked.PSet( @@ -518,7 +518,7 @@ def customiseGenerator(process, changeProcessname=True, reselect=False): return modify_outputModules( process, - [keepSelected(dataTier), keepCleaned(dataTier), keepSimulated()], + [keepSelected(dataTier), keepCleaned(dataTier), keepSimulated(process)], ["AODSIMoutput"], ) @@ -973,7 +973,7 @@ def customiseFilterTTbartoMuMu(process): def customiseMCFilter(process): process.schedule.insert(-1, process.MCFilter) - outputModulesList = [key for key, value in process.outputModules.iteritems()] + outputModulesList = [key for key, value in process.outputModules.items()] for outputModule in outputModulesList: outputModule = getattr(process, outputModule) outputModule.SelectEvents = cms.untracked.PSet( From 89846afe24dfceedee8365bd775989f554be99ed Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 19:54:11 +0100 Subject: [PATCH 16/58] customisers.py: remove crashing modules for the time-being --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 08479b2606f64..296498dec3b24 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -758,7 +758,7 @@ def customiseMerging(process, changeProcessname=True, reselect=False): # produce local Calo process.load("RecoLocalCalo.Configuration.RecoLocalCalo_cff") process.merge_step += process.calolocalreco - process.merge_step += process.caloglobalreco + #process.merge_step += process.caloglobalreco process.merge_step += process.reducedHcalRecHitsSequence # produce hcal towers @@ -824,12 +824,12 @@ def customiseMerging(process, changeProcessname=True, reselect=False): process.muons.FillCosmicsIdMap = cms.bool(False) # seed configuration needed for seedmerger - process.load( - "RecoEgamma.EgammaElectronProducers.ecalDrivenElectronSeedsParameters_cff" - ) - process.ecalDrivenElectronSeeds.SeedConfiguration = cms.PSet( - process.ecalDrivenElectronSeedsParameters - ) + #process.load( + # "RecoEgamma.EgammaElectronProducers.ecalDrivenElectronSeedsParameters_cff" + #) + #process.ecalDrivenElectronSeeds.SeedConfiguration = cms.PSet( + # process.ecalDrivenElectronSeedsParameters + #) process.merge_step += process.highlevelreco # process.merge_step.remove(process.reducedEcalRecHitsEE) From 2c5adcaeb5e336779c0fe537a6e0d4740e345670 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 3 Feb 2022 20:21:54 +0100 Subject: [PATCH 17/58] DataFormats/EgammaCandidates/src/classes_def.xml: define maps required for embedding --- DataFormats/EgammaCandidates/src/classes_def.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/DataFormats/EgammaCandidates/src/classes_def.xml b/DataFormats/EgammaCandidates/src/classes_def.xml index b4f32e71cdae3..809d4baf6c9f7 100644 --- a/DataFormats/EgammaCandidates/src/classes_def.xml +++ b/DataFormats/EgammaCandidates/src/classes_def.xml @@ -239,6 +239,13 @@ + + + + + + + From 8d42003b766d246dda6a02a6e61dca6896c42dd4 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 4 Feb 2022 19:00:15 +0100 Subject: [PATCH 18/58] MCEmbeddingTools: fixing customise_Merging to avoid schdule deadlocks --- .../MCEmbeddingTools/python/customisers.py | 83 ++++++++++++------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 296498dec3b24..d9711f6d9177a 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -753,6 +753,7 @@ def customiseMerging(process, changeProcessname=True, reselect=False): # process.source.inputCommands.extend(keepSimulated()) # process.source.inputCommands.extend(keepCleaned()) + process.load('Configuration.StandardSequences.RawToDigi_cff') process.load("Configuration.StandardSequences.Reconstruction_Data_cff") process.merge_step = cms.Path() # produce local Calo @@ -782,33 +783,6 @@ def customiseMerging(process, changeProcessname=True, reselect=False): process.load("RecoMuon.MuonIdentification.muons1stStep_cfi") process.merge_step += process.muonEcalDetIds - for akt_manimod in to_bemanipulate: - if "MERGE" in akt_manimod.steps: - mergCollections_in = cms.VInputTag() - for instance in akt_manimod.instance: - mergCollections_in.append( - cms.InputTag( - akt_manimod.merge_prefix + akt_manimod.module_name, - instance, - "SIMembedding", - ) - ) - mergCollections_in.append( - cms.InputTag( - akt_manimod.merge_prefix + akt_manimod.module_name, - instance, - "LHEembeddingCLEAN", - ) - ) - setattr( - process, - akt_manimod.module_name, - cms.EDProducer( - akt_manimod.merger_name, mergCollections=mergCollections_in - ), - ) - process.merge_step += getattr(process, akt_manimod.module_name) - process.merge_step += process.doAlldEdXEstimators process.merge_step += process.vertexreco process.unsortedOfflinePrimaryVertices.beamSpotLabel = cms.InputTag( @@ -835,22 +809,69 @@ def customiseMerging(process, changeProcessname=True, reselect=False): # process.merge_step.remove(process.reducedEcalRecHitsEE) # process.merge_step.remove(process.reducedEcalRecHitsEB) - process.merge_step.remove(process.ak4JetTracksAssociatorExplicit) + # process.merge_step.remove(process.ak4JetTracksAssociatorExplicit) - process.merge_step.remove(process.cosmicsVeto) - process.merge_step.remove(process.cosmicsVetoTrackCandidates) + # process.merge_step.remove(process.cosmicsVeto) + # process.merge_step.remove(process.cosmicsVetoTrackCandidates) # process.merge_step.remove(process.ecalDrivenGsfElectronCores) # process.merge_step.remove(process.ecalDrivenGsfElectrons) # process.merge_step.remove(process.gedPhotonsTmp) # process.merge_step.remove(process.particleFlowTmp) - process.merge_step.remove(process.hcalnoise) + # process.merge_step.remove(process.hcalnoise) process.load("CommonTools.ParticleFlow.genForPF2PAT_cff") # process.muonsFromCosmics.ShowerDigiFillerParameters.dtDigiCollectionLabel = cms.InputTag("simMuonDTDigis") process.merge_step += process.genForPF2PATSequence + + # Replace manipulated modules contained in merg_step with Mergers, and + # put remaining ones into a list to be sorted to avoid deadlocks + modules_to_be_ordered = {} + # prepare reco list to determine indices + reconstruction_modules_list = str(process.RawToDigi).split(",") + reconstruction_modules_list += str(process.reconstruction).split(",") + for akt_manimod in to_bemanipulate: + if "MERGE" in akt_manimod.steps: + mergCollections_in = cms.VInputTag() + for instance in akt_manimod.instance: + mergCollections_in.append( + cms.InputTag( + akt_manimod.merge_prefix + akt_manimod.module_name, + instance, + "SIMembedding", + ) + ) + mergCollections_in.append( + cms.InputTag( + akt_manimod.merge_prefix + akt_manimod.module_name, + instance, + "LHEembeddingCLEAN", + ) + ) + setattr( + process, + akt_manimod.module_name, + cms.EDProducer( + akt_manimod.merger_name, mergCollections=mergCollections_in + ), + ) + if not process.merge_step.contains(getattr(process, akt_manimod.module_name)): + modules_to_be_ordered[akt_manimod.module_name] = -1 + # Determine indices and place them in right order into the list + for name,index in modules_to_be_ordered.items(): + if name in reconstruction_modules_list: + modules_to_be_ordered[name] = reconstruction_modules_list.index(name) + else: + print("ERROR:",name,"not prepared in modules list. Please adapt 'customiseMerging'") + sys.exit(1) + + modules_ordered = sorted(list(modules_to_be_ordered.items()), key=lambda x : -x[1]) + for m in modules_ordered: + process.merge_step.insert(0, getattr(process, m[0])) + + process.schedule.insert(0, process.merge_step) # process.load('PhysicsTools.PatAlgos.slimming.slimmedGenJets_cfi') process = customisoptions(process) From 2a4cd331dfc2c15970d116076dbfe93f75a88d23 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 10 Feb 2022 17:07:38 +0100 Subject: [PATCH 19/58] TauAnalysis/MCEmbeddingTools: create skeleton for hcalDigis merger --- .../plugins/DoubleCollectionMerger.cc | 30 +++++++++++++++++++ .../plugins/DoubleCollectionMerger.h | 2 ++ .../MCEmbeddingTools/python/customisers.py | 5 ++++ 3 files changed, 37 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc index 345b9064b4502..3d38f2aaf886e 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc @@ -7,12 +7,14 @@ #include "DataFormats/EcalDigi/interface/EESrFlag.h" #include "DataFormats/EcalDigi/interface/EBSrFlag.h" #include "DataFormats/EcalDigi/src/EcalSrFlag.cc" +#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h" #include "DataFormats/Common/interface/RangeMap.h" #include "DataFormats/Common/interface/OwnVector.h" typedef DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag> EcalSrFlagColMerger; +typedef DoubleCollectionMerger HcalDigiColMerger; // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections template @@ -105,6 +107,20 @@ void DoubleCollectionMerger::fill_output_obj_digiflag(std::unique_ output->sort(); //Do a sort for this collection } +template +void DoubleCollectionMerger::fill_output_obj_hcaldigi(std::unique_ptr & output, std::vector > &inputCollections) +{ + //TODO: implement proper merging, only skeleton for the time-being + return; +} + +template +void DoubleCollectionMerger::fill_output_obj_hcaldigi(std::unique_ptr & output, std::vector > &inputCollections) +{ + //TODO: implement proper merging, only skeleton for the time-being + return; +} + template <> void DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag>::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) { @@ -117,4 +133,18 @@ void DoubleCollectionMerger, EESrFlag, edm::Sor fill_output_obj_digiflag(output,inputCollections); } +template <> +void DoubleCollectionMerger::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) +{ + fill_output_obj_hcaldigi(output,inputCollections); +} + +template <> +void DoubleCollectionMerger::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) +{ + fill_output_obj_hcaldigi(output,inputCollections); +} + + DEFINE_FWK_MODULE(EcalSrFlagColMerger); +DEFINE_FWK_MODULE(HcalDigiColMerger); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h index 008c9a75b8f13..e3aa2a01939fb 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h @@ -49,6 +49,8 @@ class DoubleCollectionMerger : public edm::stream::EDProducer<> void fill_output_obj(std::unique_ptr & output2, std::vector > &inputCollections2); void fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections); void fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections); + void fill_output_obj_hcaldigi(std::unique_ptr & output, std::vector > &inputCollections); + void fill_output_obj_hcaldigi(std::unique_ptr & output, std::vector > &inputCollections); }; diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index d9711f6d9177a..8e73e5e572e55 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -131,6 +131,11 @@ def __init__( module_name="ecalDigis", manipulator_name="EcalSrFlag", steps=["SIM", "MERGE"] ) ) +to_bemanipulate.append( + module_manipulate( + module_name="hcalDigis", manipulator_name="HcalDigi", steps=["SIM", "MERGE"] + ) +) to_bemanipulate.append( module_manipulate( module_name="electronMergedSeeds", From 3fb467b245be432959b2cb70b197d6225e6a05f1 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 10 Feb 2022 18:12:17 +0100 Subject: [PATCH 20/58] TauAnalysis/MCEmbeddingTools: merging electron seeds also for low Pt electrons --- TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc | 2 ++ TauAnalysis/MCEmbeddingTools/python/customisers.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc index 37c74eee9a518..ef14000b8b4b1 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc @@ -47,6 +47,7 @@ typedef CollectionMerger, SiStripCluster> S typedef CollectionMerger, reco::ElectronSeed> ElectronSeedColMerger; typedef CollectionMerger, reco::ElectronSeed> EcalDrivenElectronSeedColMerger; +typedef CollectionMerger, reco::ElectronSeed> LowPtGsfElectronSeedColMerger; typedef CollectionMerger, EcalRecHit> EcalRecHitColMerger; typedef CollectionMerger, HBHERecHit> HBHERecHitColMerger; typedef CollectionMerger, HFRecHit> HFRecHitColMerger; @@ -339,6 +340,7 @@ DEFINE_FWK_MODULE(StripColMerger); DEFINE_FWK_MODULE(ElectronSeedColMerger); DEFINE_FWK_MODULE(EcalDrivenElectronSeedColMerger); +DEFINE_FWK_MODULE(LowPtGsfElectronSeedColMerger); DEFINE_FWK_MODULE(EcalRecHitColMerger); DEFINE_FWK_MODULE(HBHERecHitColMerger); diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 8e73e5e572e55..a0a1b1eeb8634 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -150,6 +150,13 @@ def __init__( steps=["SIM", "MERGE"], ) ) +to_bemanipulate.append( + module_manipulate( + module_name="lowPtGsfElectronSeeds", + manipulator_name="LowPtGsfElectronSeed", + steps=["SIM", "MERGE"], + ) +) to_bemanipulate.append( module_manipulate( From a4bd3f2c4ef3210e68768ff1638694a1fbcce698 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 4 Mar 2022 14:45:47 +0100 Subject: [PATCH 21/58] customisers.py: merge lowPtGsfEleGsfTracks --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index a0a1b1eeb8634..3a62d245d2229 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -89,6 +89,13 @@ def __init__( steps=["SIM", "MERGE"], ) ) +to_bemanipulate.append( + module_manipulate( + module_name="lowPtGsfEleGsfTracks", + manipulator_name="GsfTrack", + steps=["SIM", "MERGE"], + ) +) to_bemanipulate.append( module_manipulate( From 5385960cc815eb66db9c2c04f65fd7e2ac33c7f4 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 20 Apr 2023 10:13:32 +0200 Subject: [PATCH 22/58] merge also displaced Muons 1st Step collections --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 3a62d245d2229..0ba220512442b 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -102,6 +102,11 @@ def __init__( module_name="muons1stStep", manipulator_name="Muon", steps=["SIM", "MERGE"] ) ) +to_bemanipulate.append( + module_manipulate( + module_name="displacedMuons1stStep", manipulator_name="Muon", steps=["SIM", "MERGE"] + ) +) # to_bemanipulate.append(module_manipulate(module_name = 'gedGsfElectronsTmp', manipulator_name = "GsfElectron", steps = ["SIM", "MERGE"])) # to_bemanipulate.append(module_manipulate(module_name = 'gedPhotonsTmp', manipulator_name = "Photon", steps = ["SIM", "MERGE"])) to_bemanipulate.append( From 78bfe77dafe23a541790813e94e82d036b6f0d1c Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 20 Apr 2023 11:33:56 +0200 Subject: [PATCH 23/58] adapt displacedMuons configuration as for usual Muons --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 0ba220512442b..e96751d2be3d7 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -821,6 +821,11 @@ def customiseMerging(process, changeProcessname=True, reselect=False): process.muons.FillShoweringInfo = cms.bool(False) process.muons.FillCosmicsIdMap = cms.bool(False) + process.displacedMuons.FillDetectorBasedIsolation = cms.bool(False) + process.displacedMuons.FillSelectorMaps = cms.bool(False) + process.displacedMuons.FillShoweringInfo = cms.bool(False) + process.displacedMuons.FillCosmicsIdMap = cms.bool(False) + # seed configuration needed for seedmerger #process.load( # "RecoEgamma.EgammaElectronProducers.ecalDrivenElectronSeedsParameters_cff" From 25e798e294c47278073fe77e161faa49ab54258d Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 20 Apr 2023 13:40:01 +0200 Subject: [PATCH 24/58] Remove Low Pt Electron Seed Merger, since the producer creates not only seeds... --- .../plugins/CollectionMerger.cc | 2 -- .../MCEmbeddingTools/python/customisers.py | 19 ++++++------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc index ef14000b8b4b1..37c74eee9a518 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc @@ -47,7 +47,6 @@ typedef CollectionMerger, SiStripCluster> S typedef CollectionMerger, reco::ElectronSeed> ElectronSeedColMerger; typedef CollectionMerger, reco::ElectronSeed> EcalDrivenElectronSeedColMerger; -typedef CollectionMerger, reco::ElectronSeed> LowPtGsfElectronSeedColMerger; typedef CollectionMerger, EcalRecHit> EcalRecHitColMerger; typedef CollectionMerger, HBHERecHit> HBHERecHitColMerger; typedef CollectionMerger, HFRecHit> HFRecHitColMerger; @@ -340,7 +339,6 @@ DEFINE_FWK_MODULE(StripColMerger); DEFINE_FWK_MODULE(ElectronSeedColMerger); DEFINE_FWK_MODULE(EcalDrivenElectronSeedColMerger); -DEFINE_FWK_MODULE(LowPtGsfElectronSeedColMerger); DEFINE_FWK_MODULE(EcalRecHitColMerger); DEFINE_FWK_MODULE(HBHERecHitColMerger); diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index e96751d2be3d7..71a955e449c69 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -70,29 +70,29 @@ def __init__( ) to_bemanipulate.append( module_manipulate( - module_name="conversionStepTracks", - manipulator_name="Track", + module_name="lowPtGsfEleGsfTracks", + manipulator_name="GsfTrack", steps=["SIM", "MERGE"], ) ) to_bemanipulate.append( module_manipulate( - module_name="ckfInOutTracksFromConversions", + module_name="conversionStepTracks", manipulator_name="Track", steps=["SIM", "MERGE"], ) ) to_bemanipulate.append( module_manipulate( - module_name="ckfOutInTracksFromConversions", + module_name="ckfInOutTracksFromConversions", manipulator_name="Track", steps=["SIM", "MERGE"], ) ) to_bemanipulate.append( module_manipulate( - module_name="lowPtGsfEleGsfTracks", - manipulator_name="GsfTrack", + module_name="ckfOutInTracksFromConversions", + manipulator_name="Track", steps=["SIM", "MERGE"], ) ) @@ -162,13 +162,6 @@ def __init__( steps=["SIM", "MERGE"], ) ) -to_bemanipulate.append( - module_manipulate( - module_name="lowPtGsfElectronSeeds", - manipulator_name="LowPtGsfElectronSeed", - steps=["SIM", "MERGE"], - ) -) to_bemanipulate.append( module_manipulate( From ecb50b6a43f553a4e4146a841765365fbb08906a Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 21 Apr 2023 16:13:04 +0200 Subject: [PATCH 25/58] keeping all trajectory seeds now, since needed by lowPt electrons --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 71a955e449c69..be4d71e035604 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -317,6 +317,7 @@ def keepCleaned(dataTier): "keep *_firstStepPrimaryVertices_*_" + dataTier, "keep *_offlineBeamSpot_*_" + dataTier, "keep *_l1extraParticles_*_" + dataTier, + "keep TrajectorySeeds_*_*_*", # "keep recoPFClusters_*_*_*", # "keep recoPFRecHits_*_*_*" ) @@ -457,6 +458,7 @@ def keepSimulated(process, processname="SIMembedding"): ret_vstring.append("keep recoMuons_muonsFromCosmics1Leg_*_*") ret_vstring.append("keep *_muonDTDigis_*_*") ret_vstring.append("keep *_muonCSCDigis_*_*") + ret_vstring.append("keep TrajectorySeeds_*_*_*") # for those two steps, the output has to be modified # to keep the information from the cleaning step in the output file if processname == "SIMembeddingpreHLT" or processname == "SIMembeddingHLT": From e7b1817a658581e6fefe4b1911b56727f9333d13 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 28 Apr 2023 17:10:42 +0200 Subject: [PATCH 26/58] Fix Geometry records for Tracking Rec. Hits --- TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc | 6 ++++++ TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc index beebb41d5cb5d..a40ad6b7076a3 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc @@ -110,6 +110,12 @@ void TrackMergeremb::merg_and_put( for (reco::TrackCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it, ++sedref_it) { outTracks->push_back(reco::Track(*it)); + auto rechits = it->recHits(); + // Fixing geometry records of detector components for tracking rec. hits + for (auto ith = rechits.begin(); ith!= rechits.end(); ith++){ + auto hit = *(&(*ith)); + hit->setDet(*geometry_->idToDet(hit->rawId())); + } outTracks_ex->push_back(reco::TrackExtra(*it->extra())); outTracks->back().setExtra(reco::TrackExtraRef(rTrackExtras, outTracks_ex->size() - 1)); reco::TrackRef trackRefold(track_col_in, sedref_it); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h index 907b525817108..9a6b6d966ff81 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h @@ -41,6 +41,9 @@ #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" #include "DataFormats/TrackReco/interface/TrackToTrackMap.h" +#include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h" +#include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h" + #include #include #include @@ -67,6 +70,8 @@ class TrackMergeremb : public edm::stream::EDProducer<> { typedef edm::ValueMap TrackToTrackMapnew; typedef edm::ValueMap GsfTrackToTrackMapnew; + edm::ESGetToken globalGeomToken_; + const GlobalTrackingGeometry* geometry_ = nullptr; edm::EDGetTokenT inputs_fixtrackrefs_; edm::EDGetTokenT inputs_fixtrackcol_; @@ -86,6 +91,7 @@ template TrackMergeremb::TrackMergeremb(const edm::ParameterSet& iConfig) { std::string alias(iConfig.getParameter("@module_label")); std::vector inCollections = iConfig.getParameter >("mergCollections"); + globalGeomToken_ = esConsumes(); for (const auto& inCollection : inCollections) { inputs_[inCollection.instance()].push_back(consumes(inCollection)); } @@ -102,6 +108,7 @@ TrackMergeremb::~TrackMergeremb() { template void TrackMergeremb::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { + geometry_ = &iSetup.getData(globalGeomToken_); for (auto input_ : inputs_) { merg_and_put(iEvent, input_.first, input_.second); From 756aae271b1fe8d51322729976dde896a7d7e3f8 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 12 May 2023 14:19:20 +0200 Subject: [PATCH 27/58] Adding recoElectronSeeds to the collections to be kept for merging --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index be4d71e035604..eac5c86091cd0 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -318,6 +318,7 @@ def keepCleaned(dataTier): "keep *_offlineBeamSpot_*_" + dataTier, "keep *_l1extraParticles_*_" + dataTier, "keep TrajectorySeeds_*_*_*", + "keep recoElectronSeeds_*_*_*", # "keep recoPFClusters_*_*_*", # "keep recoPFRecHits_*_*_*" ) @@ -459,6 +460,7 @@ def keepSimulated(process, processname="SIMembedding"): ret_vstring.append("keep *_muonDTDigis_*_*") ret_vstring.append("keep *_muonCSCDigis_*_*") ret_vstring.append("keep TrajectorySeeds_*_*_*") + ret_vstring.append("keep recoElectronSeeds_*_*_*") # for those two steps, the output has to be modified # to keep the information from the cleaning step in the output file if processname == "SIMembeddingpreHLT" or processname == "SIMembeddingHLT": From 03907290cd79dd3807de4692065206095bf36ec6 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Mon, 15 May 2023 17:48:31 +0200 Subject: [PATCH 28/58] Fix Ctf track reference for lowPtGsfElectrons --- .../plugins/TrackMergeremb.cc | 28 +++++++++++-------- .../MCEmbeddingTools/plugins/TrackMergeremb.h | 4 ++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc index a40ad6b7076a3..b9a1aa1e110f2 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc @@ -171,6 +171,20 @@ void TrackMergeremb::merg_and_put( auto rHits = iEvent.getRefBeforePut(); std::vector trackRefColl; + //track to track map for trackerdriven seed fix + edm::Handle track_ref_map; + iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map); + + edm::Handle track_new_col; + iEvent.getByToken(inputs_fixtrackcol_, track_new_col); + + std::map simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map + for (unsigned abc =0; abc < track_new_col->size(); ++abc) { + reco::TrackRef trackRef(track_new_col, abc); + simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; + } + + // merge begin for (auto akt_collection : to_merge) { edm::Handle track_col_in; iEvent.getByToken(akt_collection, track_col_in); @@ -178,6 +192,8 @@ void TrackMergeremb::merg_and_put( size_t sedref_it = 0; for (reco::GsfTrackCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it, ++sedref_it) { + reco::ElectronSeedRef seed = it->seedRef().castTo(); + (const_cast(seed.get()))->setCtfTrack(simple_track_to_track_map[seed->ctfTrack()]); outTracks->push_back(reco::GsfTrack(*it)); outTracks_ex->push_back(reco::TrackExtra(*it->extra())); outTracks_exgsf->push_back(reco::GsfTrackExtra(*it->gsfExtra())); @@ -199,18 +215,6 @@ void TrackMergeremb::merg_and_put( filler.fill(); - //track to track map for trackerdriven seed fix - edm::Handle track_ref_map; - iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map); - - edm::Handle track_new_col; - iEvent.getByToken(inputs_fixtrackcol_, track_new_col); - std::map simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map - for (unsigned abc =0; abc < track_new_col->size(); ++abc) { - reco::TrackRef trackRef(track_new_col, abc); - simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; - } - edm::Handle elSeeds; iEvent.getByToken(inputs_rElectronMergedSeeds_,elSeeds); auto bElSeeds = elSeeds->cbegin(); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h index 9a6b6d966ff81..f7452ef025c3e 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h @@ -85,11 +85,13 @@ class TrackMergeremb : public edm::stream::EDProducer<> { edm::EDGetTokenT inputs_SC_; edm::EDGetTokenT inputs_rElectronMergedSeeds_; edm::EDGetTokenT> inputs_rElectronMergedSeedViews_; + + std::string alias; }; template TrackMergeremb::TrackMergeremb(const edm::ParameterSet& iConfig) { - std::string alias(iConfig.getParameter("@module_label")); + alias = iConfig.getParameter("@module_label"); std::vector inCollections = iConfig.getParameter >("mergCollections"); globalGeomToken_ = esConsumes(); for (const auto& inCollection : inCollections) { From 4069ab09d3d408e0fd627cffd5ecd0749f4fe8e5 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Tue, 16 May 2023 08:51:36 +0200 Subject: [PATCH 29/58] re-enable Filling of muons as done usually; merge track collection for muon ID's --- .../MCEmbeddingTools/python/customisers.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index eac5c86091cd0..c6bc15b30cd06 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -61,6 +61,11 @@ def __init__( module_name="generalTracks", manipulator_name="Track", steps=["SIM", "MERGE"] ) ) +to_bemanipulate.append( + module_manipulate( + module_name="cosmicsVetoTracksRaw", manipulator_name="Track", steps=["SIM", "MERGE"] + ) +) to_bemanipulate.append( module_manipulate( module_name="electronGsfTracks", @@ -813,15 +818,15 @@ def customiseMerging(process, changeProcessname=True, reselect=False): "firstStepPrimaryVertices", "", dataTier ) - process.muons.FillDetectorBasedIsolation = cms.bool(False) - process.muons.FillSelectorMaps = cms.bool(False) - process.muons.FillShoweringInfo = cms.bool(False) - process.muons.FillCosmicsIdMap = cms.bool(False) + # process.muons.FillDetectorBasedIsolation = cms.bool(False) + # process.muons.FillSelectorMaps = cms.bool(False) + # process.muons.FillShoweringInfo = cms.bool(False) + # process.muons.FillCosmicsIdMap = cms.bool(False) - process.displacedMuons.FillDetectorBasedIsolation = cms.bool(False) - process.displacedMuons.FillSelectorMaps = cms.bool(False) - process.displacedMuons.FillShoweringInfo = cms.bool(False) - process.displacedMuons.FillCosmicsIdMap = cms.bool(False) + # process.displacedMuons.FillDetectorBasedIsolation = cms.bool(False) + # process.displacedMuons.FillSelectorMaps = cms.bool(False) + # process.displacedMuons.FillShoweringInfo = cms.bool(False) + # process.displacedMuons.FillCosmicsIdMap = cms.bool(False) # seed configuration needed for seedmerger #process.load( From af160eb9215074c39ce2cd054f3d5e1be307d09d Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Wed, 17 May 2023 09:43:22 +0200 Subject: [PATCH 30/58] Fixing production sequence for isolation deposits --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index c6bc15b30cd06..a912eeb4b5a76 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -324,6 +324,8 @@ def keepCleaned(dataTier): "keep *_l1extraParticles_*_" + dataTier, "keep TrajectorySeeds_*_*_*", "keep recoElectronSeeds_*_*_*", + "drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*" , + "drop recoIsoDepositedmValueMap_muIsoDepositTkDisplaced_*_*", # "keep recoPFClusters_*_*_*", # "keep recoPFRecHits_*_*_*" ) @@ -466,6 +468,8 @@ def keepSimulated(process, processname="SIMembedding"): ret_vstring.append("keep *_muonCSCDigis_*_*") ret_vstring.append("keep TrajectorySeeds_*_*_*") ret_vstring.append("keep recoElectronSeeds_*_*_*") + ret_vstring.append("drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*") + ret_vstring.append("drop recoIsoDepositedmValueMap_muIsoDepositTkDisplaced_*_*") # for those two steps, the output has to be modified # to keep the information from the cleaning step in the output file if processname == "SIMembeddingpreHLT" or processname == "SIMembeddingHLT": @@ -808,6 +812,12 @@ def customiseMerging(process, changeProcessname=True, reselect=False): # muonEcalDetIds process.load("RecoMuon.MuonIdentification.muons1stStep_cfi") process.merge_step += process.muonEcalDetIds + process.merge_step += process.muonShowerInformation + + # muon Isolation tasks + process.load("RecoMuon.MuonIsolationProducers.muIsolation_cff") + process.merge_step += process.muIsolation + process.merge_step += process.muIsolationDisplaced process.merge_step += process.doAlldEdXEstimators process.merge_step += process.vertexreco From 26754e1f89cf3c7ca5fd2a8b2907e8dc455aaf07 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Wed, 17 May 2023 09:56:13 +0200 Subject: [PATCH 31/58] Fixing production sequence for id selection types --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index a912eeb4b5a76..8e3e0972a1280 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -814,11 +814,15 @@ def customiseMerging(process, changeProcessname=True, reselect=False): process.merge_step += process.muonEcalDetIds process.merge_step += process.muonShowerInformation - # muon Isolation tasks + # muon Isolation sequences process.load("RecoMuon.MuonIsolationProducers.muIsolation_cff") process.merge_step += process.muIsolation process.merge_step += process.muIsolationDisplaced + # muon ID selection type sequences + process.load("RecoMuon.MuonIdentification.muonSelectionTypeValueMapProducer_cff") + process.merge_step += process.muonSelectionTypeSequence + process.merge_step += process.doAlldEdXEstimators process.merge_step += process.vertexreco process.unsortedOfflinePrimaryVertices.beamSpotLabel = cms.InputTag( From cb48e66ebd82980ad3420f96cbabbb52f6b88a91 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Mon, 22 May 2023 13:00:18 +0200 Subject: [PATCH 32/58] Removing MC info not required for muons in embedded samples --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 8e3e0972a1280..5039106bb8dba 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -326,6 +326,7 @@ def keepCleaned(dataTier): "keep recoElectronSeeds_*_*_*", "drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*" , "drop recoIsoDepositedmValueMap_muIsoDepositTkDisplaced_*_*", + "drop *_muonSimClassifier_*_*", # "keep recoPFClusters_*_*_*", # "keep recoPFRecHits_*_*_*" ) @@ -470,6 +471,8 @@ def keepSimulated(process, processname="SIMembedding"): ret_vstring.append("keep recoElectronSeeds_*_*_*") ret_vstring.append("drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*") ret_vstring.append("drop recoIsoDepositedmValueMap_muIsoDepositTkDisplaced_*_*") + ret_vstring.append("drop *_muonSimClassifier_*_*") + # for those two steps, the output has to be modified # to keep the information from the cleaning step in the output file if processname == "SIMembeddingpreHLT" or processname == "SIMembeddingHLT": From f73346cd6e24c729f2755967dbb9dde0e6db60b9 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Mon, 22 May 2023 13:50:30 +0200 Subject: [PATCH 33/58] adding merging and production sequences for displaced muons --- .../MCEmbeddingTools/python/customisers.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 5039106bb8dba..286d34e192c38 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -87,6 +87,13 @@ def __init__( steps=["SIM", "MERGE"], ) ) +to_bemanipulate.append( + module_manipulate( + module_name="displacedTracks", + manipulator_name="Track", + steps=["SIM", "MERGE"], + ) +) to_bemanipulate.append( module_manipulate( module_name="ckfInOutTracksFromConversions", @@ -826,6 +833,14 @@ def customiseMerging(process, changeProcessname=True, reselect=False): process.load("RecoMuon.MuonIdentification.muonSelectionTypeValueMapProducer_cff") process.merge_step += process.muonSelectionTypeSequence + # displaced muons extras & tracks + process.load("RecoMuon.MuonIdentification.displacedMuonReducedTrackExtras_cfi") + process.merge_step += process.displacedMuonReducedTrackExtras + + process.load("RecoMuon.Configuration.MergeDisplacedTrackCollections_cff") + process.merge_step += process.displacedTracksSequence + + # Other things process.merge_step += process.doAlldEdXEstimators process.merge_step += process.vertexreco process.unsortedOfflinePrimaryVertices.beamSpotLabel = cms.InputTag( From cccdc99dc837a1d17913499dd9a08fd9359799a5 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 26 May 2023 14:14:42 +0200 Subject: [PATCH 34/58] Hotfix to cover displacedMuons after merging displacedTracks --- TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc index b9a1aa1e110f2..71a5236e142a7 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc @@ -286,8 +286,14 @@ void TrackMergeremb::willproduce(std::string instance, std template <> void TrackMergeremb::willconsume(const edm::ParameterSet& iConfig) { - inputs_fixtrackrefs_ = consumes(edm::InputTag("generalTracks")); - inputs_fixtrackcol_ = consumes(edm::InputTag("generalTracks")); + if(alias == "displacedMuons1stStep"){ + inputs_fixtrackrefs_ = consumes(edm::InputTag("displacedTracks")); + inputs_fixtrackcol_ = consumes(edm::InputTag("displacedTracks")); + } + else{ + inputs_fixtrackrefs_ = consumes(edm::InputTag("generalTracks")); + inputs_fixtrackcol_ = consumes(edm::InputTag("generalTracks")); + } } template <> From 41b8fb7e57f7b2fe7aa5c349a6c069465a8fc768 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 26 May 2023 14:42:25 +0200 Subject: [PATCH 35/58] This doc not needed anymore, since derived from name, it seems --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 286d34e192c38..eec9f03e50a9d 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -953,7 +953,7 @@ def customiseNanoAOD(process): process.embeddingTable = cms.EDProducer( "GlobalVariablesTableProducer", name=cms.string("TauEmbedding"), - doc=cms.string("TauEmbedding"), + # doc=cms.string("TauEmbedding"), variables=cms.PSet( nInitialPairCandidates=ExtVar( cms.InputTag("selectedMuonsForEmbedding", "nPairCandidates"), From fea22b803c61cfeba905a3593fbfec4d382e86c1 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Tue, 30 May 2023 22:19:58 +0200 Subject: [PATCH 36/58] Fix rec. hits geometry records also for gsf tracks --- TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc index 71a5236e142a7..33f654e2d62f0 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc @@ -195,6 +195,12 @@ void TrackMergeremb::merg_and_put( reco::ElectronSeedRef seed = it->seedRef().castTo(); (const_cast(seed.get()))->setCtfTrack(simple_track_to_track_map[seed->ctfTrack()]); outTracks->push_back(reco::GsfTrack(*it)); + auto rechits = it->recHits(); + // Fixing geometry records of detector components for tracking rec. hits + for (auto ith = rechits.begin(); ith!= rechits.end(); ith++){ + auto hit = *(&(*ith)); + hit->setDet(*geometry_->idToDet(hit->rawId())); + } outTracks_ex->push_back(reco::TrackExtra(*it->extra())); outTracks_exgsf->push_back(reco::GsfTrackExtra(*it->gsfExtra())); From 13c344beb70647371d03cea9a0647ac60873d9be Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 22 Jun 2023 13:19:07 +0200 Subject: [PATCH 37/58] adapt nanoAOD config to create correct TriggerResults and gen particles --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index eec9f03e50a9d..9bec94ec34f5f 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -950,6 +950,15 @@ def customiseMerging_Reselect(process, changeProcessname=True): def customiseNanoAOD(process): + process.load("PhysicsTools.NanoAOD.genparticles_cff") + process.nanoAOD_step.insert(0, process.genParticleTable) + process.nanoAOD_step.insert(0, process.finalGenParticles) + + process.unpackedPatTrigger.triggerResults = cms.InputTag("TriggerResults::SIMembeddingHLT") + process.NANOAODoutput.outputCommands.append("keep edmTriggerResults_*_*_SIMembeddingHLT") + process.NANOAODoutput.outputCommands.append("keep edmTriggerResults_*_*_MERGE") + process.NANOAODoutput.outputCommands.remove("keep edmTriggerResults_*_*_*") + process.embeddingTable = cms.EDProducer( "GlobalVariablesTableProducer", name=cms.string("TauEmbedding"), From 4b2dc52b5c0f55b3d1cf915b8d23c4aa8ebe4971 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 22 Jun 2023 14:59:24 +0200 Subject: [PATCH 38/58] Override MC matching removal for embedded samples --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 9bec94ec34f5f..2af5500d40d90 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -777,6 +777,15 @@ def customiseKeepPrunedGenParticles(process, reselect=False): def customiseMerging(process, changeProcessname=True, reselect=False): + + print("**** Attention: overriding behaviour of 'removeMCMatching' ****") + + def dontRemoveMCMatching(process, names, postfix, outputModules): + pass + + import PhysicsTools.PatAlgos.tools.coreTools + PhysicsTools.PatAlgos.tools.coreTools.removeMCMatching = dontRemoveMCMatching + if changeProcessname: process._Process__name = "MERGE" if reselect: From 8ee77ad39efb50c68041fc43157b5aa998972622 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 22 Jun 2023 16:18:14 +0200 Subject: [PATCH 39/58] fix trigger result creation --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 2af5500d40d90..0c6a171c5dbf8 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -712,6 +712,7 @@ def keepMerged(dataTier="SELECT"): ret_vstring.append("keep *_generator_*_SIMembeddingHLT") ret_vstring.append("keep *_generator_*_SIMembedding") ret_vstring.append("keep *_selectedMuonsForEmbedding_*_*") + ret_vstring.append("keep *_unpackedPatTrigger_*_*") return ret_vstring @@ -795,6 +796,8 @@ def dontRemoveMCMatching(process, names, postfix, outputModules): process.source.inputCommands = cms.untracked.vstring() process.source.inputCommands.append("keep *_*_*_*") + process.load("PhysicsTools.PatAlgos.slimming.unpackedPatTrigger_cfi") + process.unpackedPatTrigger.triggerResults = cms.InputTag("TriggerResults::SIMembeddingHLT") # process.source.inputCommands.append("drop *_*_*_SELECT") # process.source.inputCommands.append("drop *_*_*_SIMembedding") @@ -963,10 +966,10 @@ def customiseNanoAOD(process): process.nanoAOD_step.insert(0, process.genParticleTable) process.nanoAOD_step.insert(0, process.finalGenParticles) - process.unpackedPatTrigger.triggerResults = cms.InputTag("TriggerResults::SIMembeddingHLT") - process.NANOAODoutput.outputCommands.append("keep edmTriggerResults_*_*_SIMembeddingHLT") - process.NANOAODoutput.outputCommands.append("keep edmTriggerResults_*_*_MERGE") - process.NANOAODoutput.outputCommands.remove("keep edmTriggerResults_*_*_*") + for outputModule in process.outputModules.values(): + outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembeddingHLT") + outputModule.outputCommands.append("keep edmTriggerResults_*_*_MERGE") + outputModule.outputCommands.remove("keep edmTriggerResults_*_*_*") process.embeddingTable = cms.EDProducer( "GlobalVariablesTableProducer", From 1eebd03a76b8003662f30352b6f6227c59bf53ae Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Thu, 22 Jun 2023 17:22:23 +0200 Subject: [PATCH 40/58] Improve calculation for generator particles --- .../MCEmbeddingTools/python/customisers.py | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 0c6a171c5dbf8..7e4a29f335833 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -713,6 +713,27 @@ def keepMerged(dataTier="SELECT"): ret_vstring.append("keep *_generator_*_SIMembedding") ret_vstring.append("keep *_selectedMuonsForEmbedding_*_*") ret_vstring.append("keep *_unpackedPatTrigger_*_*") + ret_vstring.extend(cms.untracked.vstring( + 'keep patPackedGenParticles_packedGenParticles_*_*', + 'keep recoGenParticles_prunedGenParticles_*_*', + 'keep *_packedPFCandidateToGenAssociation_*_*', + 'keep *_lostTracksToGenAssociation_*_*', + 'keep LHEEventProduct_*_*_*', + 'keep GenFilterInfo_*_*_*', + 'keep GenLumiInfoHeader_generator_*_*', + 'keep GenLumiInfoProduct_*_*_*', + 'keep GenEventInfoProduct_generator_*_*', + 'keep recoGenParticles_genPUProtons_*_*', + 'keep *_slimmedGenJetsFlavourInfos_*_*', + 'keep *_slimmedGenJets__*', + 'keep *_slimmedGenJetsAK8__*', + 'keep *_slimmedGenJetsAK8SoftDropSubJets__*', + 'keep *_genMetTrue_*_*', + # RUN + 'keep LHERunInfoProduct_*_*_*', + 'keep GenRunInfoProduct_*_*_*', + 'keep *_genParticles_xyz0_*', + 'keep *_genParticles_t0_*')) return ret_vstring @@ -781,11 +802,12 @@ def customiseMerging(process, changeProcessname=True, reselect=False): print("**** Attention: overriding behaviour of 'removeMCMatching' ****") - def dontRemoveMCMatching(process, names, postfix, outputModules): - pass + from PhysicsTools.PatAlgos.slimming.miniAOD_tools import miniAOD_customizeMC + def performMCMatching(process, names, postfix, outputModules): + miniAOD_customizeMC(process) import PhysicsTools.PatAlgos.tools.coreTools - PhysicsTools.PatAlgos.tools.coreTools.removeMCMatching = dontRemoveMCMatching + PhysicsTools.PatAlgos.tools.coreTools.removeMCMatching = performMCMatching if changeProcessname: process._Process__name = "MERGE" @@ -962,9 +984,8 @@ def customiseMerging_Reselect(process, changeProcessname=True): def customiseNanoAOD(process): - process.load("PhysicsTools.NanoAOD.genparticles_cff") - process.nanoAOD_step.insert(0, process.genParticleTable) - process.nanoAOD_step.insert(0, process.finalGenParticles) + process.load("PhysicsTools.NanoAOD.nano_cff") + process.nanoAOD_step.insert(0, cms.Sequence(process.nanoTableTaskFS)) for outputModule in process.outputModules.values(): outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembeddingHLT") From 7351d1468b9957d9e8fc0172bb63816370f82ebe Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 23 Jun 2023 11:59:32 +0200 Subject: [PATCH 41/58] Add 3rd HLT path to fix behaviour for 2016 samples --- TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py b/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py index fd69ed4c25b13..8c5634f296526 100644 --- a/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py +++ b/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py @@ -10,7 +10,7 @@ hltResults = cms.InputTag("TriggerResults","","HLT"), l1tResults = cms.InputTag(""), throw = cms.bool(False), - triggerConditions = cms.vstring("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass8_v*") + triggerConditions = cms.vstring("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass8_v* OR HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ_v*") ) From f059c810efb0c42814e5885a2571be8b64639c26 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Mon, 26 Jun 2023 16:04:37 +0200 Subject: [PATCH 42/58] add L1 results & bits for full nanoAOD content --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 7e4a29f335833..36ff5718b4e4e 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -987,9 +987,12 @@ def customiseNanoAOD(process): process.load("PhysicsTools.NanoAOD.nano_cff") process.nanoAOD_step.insert(0, cms.Sequence(process.nanoTableTaskFS)) + for outputModule in process.outputModules.values(): outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembeddingHLT") + outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembedding") outputModule.outputCommands.append("keep edmTriggerResults_*_*_MERGE") + outputModule.outputCommands.append("keep edmTriggerResults_*_*_NANO") outputModule.outputCommands.remove("keep edmTriggerResults_*_*_*") process.embeddingTable = cms.EDProducer( From 311a3fc3de5eb0128c92bf93aeb38dd93fcb0fe5 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Mon, 26 Jun 2023 18:49:13 +0200 Subject: [PATCH 43/58] add SIMembeddingpreHLT to be able to include L1simulation in nanoAOD --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 36ff5718b4e4e..9efef2f293033 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -989,6 +989,7 @@ def customiseNanoAOD(process): for outputModule in process.outputModules.values(): + outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembeddingpreHLT") outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembeddingHLT") outputModule.outputCommands.append("keep edmTriggerResults_*_*_SIMembedding") outputModule.outputCommands.append("keep edmTriggerResults_*_*_MERGE") From 685d2a77782dedbff74bc5648bf443a3bac41705 Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Tue, 27 Jun 2023 23:23:03 +0200 Subject: [PATCH 44/58] fix the case where a ctf track could be shared by several seeds or same seed by several gsf tracks --- TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc index 33f654e2d62f0..1c137436fbbbb 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc @@ -181,6 +181,7 @@ void TrackMergeremb::merg_and_put( std::map simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map for (unsigned abc =0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); + simple_track_to_track_map[trackRef] = trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; } @@ -318,6 +319,7 @@ void TrackMergeremb::merg_and_put( simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); + simple_track_to_track_map[trackRef] = trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; } @@ -411,6 +413,7 @@ void TrackMergeremb::merg_and_put( simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); + simple_track_to_track_map[trackRef] = trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; } From fc0d112b87d00b677d60b88685a19219c4e70aba Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Wed, 28 Jun 2023 00:36:13 +0200 Subject: [PATCH 45/58] roll back the change, introduce explanationns into the cff file --- TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py b/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py index 8c5634f296526..b2a02f7f7eec5 100644 --- a/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py +++ b/TauAnalysis/MCEmbeddingTools/python/SelectingProcedure_cff.py @@ -10,7 +10,8 @@ hltResults = cms.InputTag("TriggerResults","","HLT"), l1tResults = cms.InputTag(""), throw = cms.bool(False), - triggerConditions = cms.vstring("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass8_v* OR HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ_v*") + triggerConditions = cms.vstring("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_Mass8_v*") # from 2017 on (up to Run 3, it seems) + # triggerConditions = cms.vstring("HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_DZ_v* OR HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_DZ_v*") # for 2016 ) From 5ddebdd089ba5053eb494e99259fa5185249ce8f Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 30 Jun 2023 11:16:29 +0200 Subject: [PATCH 46/58] fix the ct pps sequences to use _LHC raw data --- .../MCEmbeddingTools/python/customisers.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 9efef2f293033..73c9a9479c343 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -333,6 +333,20 @@ def keepCleaned(dataTier): "keep recoElectronSeeds_*_*_*", "drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*" , "drop recoIsoDepositedmValueMap_muIsoDepositTkDisplaced_*_*", + "drop *_ctppsProtons_*_*", + "drop *_ctppsLocalTrackLiteProducer_*_*", + "drop *_ctppsDiamondLocalTracks_*_*", + "drop *_ctppsDiamondRecHits_*_*", + "drop *_ctppsDiamondRawToDigi_*_*", + "drop *_ctppsPixelLocalTracks_*_*", + "drop *_ctppsPixelRecHits_*_*", + "drop *_ctppsPixelClusters_*_*", + "drop *_ctppsPixelDigis_*_*", + "drop *_totemRPLocalTrackFitter_*_*", + "drop *_totemRPUVPatternFinder_*_*", + "drop *_totemRPRecHitProducer_*_*", + "drop *_totemRPClusterProducer_*_*", + "drop *_totemRPRawToDigi_*_*", "drop *_muonSimClassifier_*_*", # "keep recoPFClusters_*_*_*", # "keep recoPFRecHits_*_*_*" @@ -478,6 +492,20 @@ def keepSimulated(process, processname="SIMembedding"): ret_vstring.append("keep recoElectronSeeds_*_*_*") ret_vstring.append("drop recoIsoDepositedmValueMap_muIsoDepositTk_*_*") ret_vstring.append("drop recoIsoDepositedmValueMap_muIsoDepositTkDisplaced_*_*") + ret_vstring.append("drop *_ctppsProtons_*_*") + ret_vstring.append("drop *_ctppsLocalTrackLiteProducer_*_*") + ret_vstring.append("drop *_ctppsDiamondLocalTracks_*_*") + ret_vstring.append("drop *_ctppsDiamondRecHits_*_*") + ret_vstring.append("drop *_ctppsDiamondRawToDigi_*_*") + ret_vstring.append("drop *_ctppsPixelLocalTracks_*_*") + ret_vstring.append("drop *_ctppsPixelRecHits_*_*") + ret_vstring.append("drop *_ctppsPixelClusters_*_*") + ret_vstring.append("drop *_ctppsPixelDigis_*_*") + ret_vstring.append("drop *_totemRPLocalTrackFitter_*_*") + ret_vstring.append("drop *_totemRPUVPatternFinder_*_*") + ret_vstring.append("drop *_totemRPRecHitProducer_*_*") + ret_vstring.append("drop *_totemRPClusterProducer_*_*") + ret_vstring.append("drop *_totemRPRawToDigi_*_*") ret_vstring.append("drop *_muonSimClassifier_*_*") # for those two steps, the output has to be modified @@ -830,6 +858,15 @@ def performMCMatching(process, names, postfix, outputModules): process.load('Configuration.StandardSequences.RawToDigi_cff') process.load("Configuration.StandardSequences.Reconstruction_Data_cff") process.merge_step = cms.Path() + # produce local CT PPS reco + process.load("RecoPPS.Configuration.recoCTPPS_cff") + process.totemRPRawToDigi.rawDataTag = cms.InputTag("rawDataCollector", "", "LHC") + process.ctppsDiamondRawToDigi.rawDataTag = cms.InputTag("rawDataCollector", "", "LHC") + process.ctppsPixelDigis.inputLabel = cms.InputTag("rawDataCollector", "", "LHC") + process.merge_step += process.totemRPRawToDigi + process.merge_step += process.ctppsDiamondRawToDigi + process.merge_step += process.ctppsPixelDigis + process.merge_step += cms.Sequence(process.recoCTPPSTask) # produce local Calo process.load("RecoLocalCalo.Configuration.RecoLocalCalo_cff") process.merge_step += process.calolocalreco From 68428e4b31e4d275097b466fba0b7eb543a9651c Mon Sep 17 00:00:00 2001 From: Artur Gottmann Date: Fri, 30 Jun 2023 11:27:27 +0200 Subject: [PATCH 47/58] add sequence to create L1 objects --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index 73c9a9479c343..d029de43caaf2 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -1033,6 +1033,9 @@ def customiseNanoAOD(process): outputModule.outputCommands.append("keep edmTriggerResults_*_*_NANO") outputModule.outputCommands.remove("keep edmTriggerResults_*_*_*") + process.load("PhysicsTools.NanoAOD.l1trig_cff") + process.nanoAOD_step.insert(0, cms.Sequence(process.l1TablesTask)) + process.embeddingTable = cms.EDProducer( "GlobalVariablesTableProducer", name=cms.string("TauEmbedding"), From 286e560c90daf717a14bc8b43657a846125a1239 Mon Sep 17 00:00:00 2001 From: cwinter Date: Thu, 23 Nov 2023 14:12:37 +0100 Subject: [PATCH 48/58] add improved muon cleaning see https://indico.cern.ch/event/1292247/contributions/5448635/attachments/2664808/4617498/Improved_cleaning_embedding_christian_winter.pdf --- .../plugins/MuonDetCleaner.cc | 40 ++++- .../MCEmbeddingTools/plugins/MuonDetCleaner.h | 161 +++++++++++++++++- .../MCEmbeddingTools/plugins/TrackerCleaner.h | 6 + .../MCEmbeddingTools/python/customisers.py | 28 +++ 4 files changed, 227 insertions(+), 8 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc index 544213bb97aa3..14166c081ae3d 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc @@ -10,11 +10,13 @@ #include "DataFormats/RPCRecHit/interface/RPCRecHit.h" typedef MuonDetCleaner CSCRecHitColCleaner; +typedef MuonDetCleaner CSCSegmentColCleaner; +typedef MuonDetCleaner DTRecSegment4DColCleaner; typedef MuonDetCleaner DTRecHitColCleaner; typedef MuonDetCleaner RPCRecHitColCleaner; //------------------------------------------------------------------------------- -// define 'getDetIds' functions used for different types of recHits +// define 'getRawDetId' functions used for different types of recHits //------------------------------------------------------------------------------- template @@ -60,6 +62,19 @@ bool MuonDetCleaner::checkrecHit(const TrackingRecHit& re return false; } +template <> +uint32_t MuonDetCleaner::getRawDetId(const CSCSegment& recHit) +{ + return recHit.cscDetId().rawId(); +} + +template <> +uint32_t MuonDetCleaner::getRawDetId(const DTRecSegment4D& recHit) +{ + return recHit.geographicalId().rawId(); +} + + template <> bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recHit) { const std::type_info& hit_type = typeid(recHit); @@ -87,6 +102,29 @@ bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recH return false; } +template <> +bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recHit) +{ + const std::type_info &hit_type = typeid(recHit); + if (hit_type == typeid(CSCSegment)) {return true;} // This should be the default one (which are included in the global (outer) muon track) + //else {std::cout<<"else "< +bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recHit) +{ + const std::type_info &hit_type = typeid(recHit); + if (hit_type == typeid(DTRecSegment4D)) {return true;} // This should be the default one (which are included in the global (outer) muon track) + else if (hit_type == typeid(DTRecHit1D)) {return true;} + else if (hit_type == typeid(DTSLRecCluster)) {return true; } + else if (hit_type == typeid(DTSLRecSegment2D)) {return true; } + // else {std::cout<<"else "< #include @@ -49,16 +58,34 @@ class MuonDetCleaner : public edm::stream::EDProducer<> { const edm::EDGetTokenT > mu_input_; std::map > inputs_; + + TrackAssociatorParameters parameters_; + TrackDetectorAssociator trackAssociator_; + edm::EDGetTokenT m_dtDigisToken; + edm::EDGetTokenT m_cscDigisToken; + edm::Handle m_dtDigis; + edm::Handle m_cscDigis; + + edm::ESHandle m_dtGeometry; + edm::ESHandle m_cscGeometry; + double m_digiMaxDistanceX; }; template -MuonDetCleaner::MuonDetCleaner(const edm::ParameterSet& iConfig) - : mu_input_(consumes >(iConfig.getParameter("MuonCollection"))) { +MuonDetCleaner::MuonDetCleaner(const edm::ParameterSet& iConfig): + mu_input_(consumes >(iConfig.getParameter("MuonCollection")), + m_dtDigisToken(consumes(iConfig.getParameter("dtDigiCollectionLabel"))), + m_cscDigisToken(consumes(iConfig.getParameter("cscDigiCollectionLabel"))), + m_digiMaxDistanceX(iConfig.getParameter("digiMaxDistanceX"))) { std::vector inCollections = iConfig.getParameter >("oldCollection"); for (const auto& inCollection : inCollections) { inputs_[inCollection.instance()] = consumes(inCollection); produces(inCollection.instance()); } + + edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); + edm::ConsumesCollector iC = consumesCollector(); + parameters_.loadParameters(parameters, iC); } template @@ -99,7 +126,127 @@ void MuonDetCleaner::produce(edm::Event& iEvent, const edm::EventSetup& continue; // Check if the hit belongs to a specifc detector section fillVetoHits(murechit, &vetoHits); // Go back to the very basic rechits } + + sort(vetoHits.begin(), vetoHits.end()); + vetoHits.erase(unique( vetoHits.begin(), vetoHits.end() ), vetoHits.end()); + iEvent.getByToken(m_dtDigisToken, m_dtDigis); + iEvent.getByToken(m_cscDigisToken, m_cscDigis); + iSetup.get().get(m_dtGeometry); + iSetup.get().get(m_cscGeometry); + edm::ESHandle propagator; + iSetup.get().get("SteppingHelixPropagatorAny", propagator); + trackAssociator_.setPropagator(propagator.product()); + TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any); + + // inspired from Muon Identification algorithm: https://github.com/cms-sw/cmssw/blob/3b943c0dbbdf4494cd66064a5a147301f38af295/RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc#L911 + for (const auto &chamber : info.chambers) + { + if (chamber.id.subdetId() == MuonSubdetId::RPC) //&& rpcHitHandle_.isValid()) + continue; // Skip RPC chambers, they are taken care of below) + + reco::MuonChamberMatch matchedChamber; + + const auto &lErr = chamber.tState.localError(); + const auto &lPos = chamber.tState.localPosition(); + const auto &lDir = chamber.tState.localDirection(); + const auto &localError = lErr.positionError(); + + matchedChamber.x = lPos.x(); + matchedChamber.y = lPos.y(); + matchedChamber.xErr = sqrt(localError.xx()); + matchedChamber.yErr = sqrt(localError.yy()); + matchedChamber.dXdZ = lDir.z() != 0 ? lDir.x() / lDir.z() : 9999; + matchedChamber.dYdZ = lDir.z() != 0 ? lDir.y() / lDir.z() : 9999; + + // DANGEROUS - compiler cannot guaranty parameters ordering + AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix(); + matchedChamber.dXdZErr = trajectoryCovMatrix(1, 1) > 0 ? sqrt(trajectoryCovMatrix(1, 1)) : 0; + matchedChamber.dYdZErr = trajectoryCovMatrix(2, 2) > 0 ? sqrt(trajectoryCovMatrix(2, 2)) : 0; + + matchedChamber.edgeX = chamber.localDistanceX; + matchedChamber.edgeY = chamber.localDistanceY; + + matchedChamber.id = chamber.id; + + // DT chamber + if (matchedChamber.detector() == MuonSubdetId::DT) + { + double xTrack = matchedChamber.x; + + for (int sl = 1; sl <= DTChamberId::maxSuperLayerId; sl += 2) + { + for (int layer = 1; layer <= DTChamberId::maxLayerId; ++layer) + { + const DTLayerId layerId(DTChamberId(matchedChamber.id.rawId()), sl, layer); + auto range = m_dtDigis->get(layerId); + + for (auto digiIt = range.first; digiIt != range.second; ++digiIt) + { + const auto topo = m_dtGeometry->layer(layerId)->specificTopology(); + double xWire = topo.wirePosition((*digiIt).wire()); + double dX = std::abs(xWire - xTrack); + + if (dX < m_digiMaxDistanceX) + { + vetoHits.push_back(matchedChamber.id.rawId()); + } + } + } + } + } + + else if (matchedChamber.detector() == MuonSubdetId::CSC) + { + double xTrack = matchedChamber.x; + double yTrack = matchedChamber.y; + + for (int iLayer = 1; iLayer <= CSCDetId::maxLayerId(); ++iLayer) + { + const CSCDetId chId(matchedChamber.id.rawId()); + const CSCDetId layerId(chId.endcap(), chId.station(), chId.ring(), chId.chamber(), iLayer); + auto range = m_cscDigis->get(layerId); + + for (auto digiIt = range.first; digiIt != range.second; ++digiIt) + { + std::vector adcVals = digiIt->getADCCounts(); + bool hasFired = false; + float pedestal = 0.5 * (float)(adcVals[0] + adcVals[1]); + float threshold = 13.3; + float diff = 0.; + for (const auto &adcVal : adcVals) + { + diff = (float)adcVal - pedestal; + if (diff > threshold) + { + hasFired = true; + break; + } + } + + if (!hasFired) + continue; + + const CSCLayerGeometry *layerGeom = m_cscGeometry->layer(layerId)->geometry(); + Float_t xStrip = layerGeom->xOfStrip(digiIt->getStrip(), yTrack); + float dX = std::abs(xStrip - xTrack); + + if (dX < m_digiMaxDistanceX) + { + vetoHits.push_back(matchedChamber.id.rawId()); + } + } + } + } + } + + // std::cout << "END CUSTOM MUON CLEANING" << std::endl; + + //----------------- } +} + + sort( vetoHits.begin(), vetoHits.end() ); + vetoHits.erase( unique( vetoHits.begin(), vetoHits.end() ), vetoHits.end() ); // Now this can also handle different instance for (auto input_ : inputs_) { diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h index 0302d077d46fc..cb52dfe60199e 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h @@ -29,6 +29,7 @@ #include "DataFormats/Common/interface/DetSetVectorNew.h" #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h" #include "DataFormats/TrackerRecHit2D/interface/OmniClusterRef.h" +#include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h" #include #include @@ -99,6 +100,11 @@ void TrackerCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetu auto const& cluster = thit.firstClusterRef(); vetodClusters[cluster.key()] = true; } + auto &thit = reinterpret_cast(murechit); + if (trackerHitRTTI::isMatched(thit)) + { + vetodClusters[reinterpret_cast(murechit).stereoClusterRef().key()] = true; + } } } std::unique_ptr output(new TrackClusterCollection()); diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index d029de43caaf2..f1d52763da4db 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -226,6 +226,22 @@ def __init__( ) ) +to_bemanipulate.append( + module_manipulate( + module_name="dt4DSegments", + manipulator_name="DTRecSegment4D", + steps=["SELECT", "CLEAN"], + ) +) + +to_bemanipulate.append( + module_manipulate( + module_name="dt4DCosmicSegments", + manipulator_name="DTRecSegment4D", + steps=["SELECT", "CLEAN"], + ) +) + to_bemanipulate.append( module_manipulate( module_name="csc2DRecHits", @@ -233,6 +249,15 @@ def __init__( steps=["SELECT", "CLEAN"], ) ) + +to_bemanipulate.append( + module_manipulate( + module_name="cscSegments", + manipulator_name="CSCSegment", + steps=["SELECT", "CLEAN"], + ) +) + to_bemanipulate.append( module_manipulate( module_name="rpcRecHits", @@ -411,6 +436,9 @@ def customiseCleaning(process, changeProcessname=True, reselect=False): MuonCollection=MuonImput, TrackAssociatorParameters=TrackAssociatorParameterBlock.TrackAssociatorParameters, oldCollection=oldCollections_in, + cscDigiCollectionLabel = cms.InputTag("muonCSCDigis","MuonCSCStripDigi"), + digiMaxDistanceX = cms.double(25.0), + dtDigiCollectionLabel = cms.InputTag("muonDTDigis"), ), ) process.ecalPreshowerRecHit.TrackAssociatorParameters.usePreshower = cms.bool(True) From 9226bc1476e4005fb2d007f1fef6934791c19712 Mon Sep 17 00:00:00 2001 From: cwinter Date: Thu, 23 Nov 2023 14:12:37 +0100 Subject: [PATCH 49/58] make the changes compatible with cmssw changes --- .../MCEmbeddingTools/plugins/MuonDetCleaner.h | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h index 580ee2754d1ab..902369aee89f9 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h @@ -16,6 +16,7 @@ #define TauAnalysis_MCEmbeddingTools_MuonDetCleaner_H #include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" @@ -35,7 +36,7 @@ #include "Geometry/DTGeometry/interface/DTGeometry.h" #include "Geometry/CSCGeometry/interface/CSCGeometry.h" - +// #include "Geometry/Records/interface/MuonGeometryRecord.h" #include #include #include @@ -68,15 +69,21 @@ class MuonDetCleaner : public edm::stream::EDProducer<> { edm::ESHandle m_dtGeometry; edm::ESHandle m_cscGeometry; + edm::ESGetToken m_dtGeometryToken; + edm::ESGetToken m_cscGeometryToken; + const edm::ESGetToken propagatorToken_; double m_digiMaxDistanceX; }; template MuonDetCleaner::MuonDetCleaner(const edm::ParameterSet& iConfig): - mu_input_(consumes >(iConfig.getParameter("MuonCollection")), + mu_input_(consumes >(iConfig.getParameter("MuonCollection"))), m_dtDigisToken(consumes(iConfig.getParameter("dtDigiCollectionLabel"))), m_cscDigisToken(consumes(iConfig.getParameter("cscDigiCollectionLabel"))), - m_digiMaxDistanceX(iConfig.getParameter("digiMaxDistanceX"))) { + m_dtGeometryToken(esConsumes()), + m_cscGeometryToken(esConsumes()), + propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), + m_digiMaxDistanceX(iConfig.getParameter("digiMaxDistanceX")) { std::vector inCollections = iConfig.getParameter >("oldCollection"); for (const auto& inCollection : inCollections) { inputs_[inCollection.instance()] = consumes(inCollection); @@ -94,7 +101,7 @@ MuonDetCleaner::~MuonDetCleaner() { } template -void MuonDetCleaner::produce(edm::Event& iEvent, const edm::EventSetup& es) { +void MuonDetCleaner::produce(edm::Event& iEvent, edm::EventSetup const& iSetup) { std::map > recHits_output; // This data format is easyer to handle std::vector vetoHits; @@ -131,14 +138,14 @@ void MuonDetCleaner::produce(edm::Event& iEvent, const edm::EventSetup& vetoHits.erase(unique( vetoHits.begin(), vetoHits.end() ), vetoHits.end()); iEvent.getByToken(m_dtDigisToken, m_dtDigis); iEvent.getByToken(m_cscDigisToken, m_cscDigis); - iSetup.get().get(m_dtGeometry); - iSetup.get().get(m_cscGeometry); + auto const& m_dtGeometry = iSetup.getData(m_dtGeometryToken); + auto const& m_cscGeometry = iSetup.getData(m_cscGeometryToken); edm::ESHandle propagator; - iSetup.get().get("SteppingHelixPropagatorAny", propagator); - trackAssociator_.setPropagator(propagator.product()); + trackAssociator_.setPropagator(&iSetup.getData(propagatorToken_)); TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any); // inspired from Muon Identification algorithm: https://github.com/cms-sw/cmssw/blob/3b943c0dbbdf4494cd66064a5a147301f38af295/RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc#L911 + // and the MuonShowerDigiFiller: https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/interface/MuonShowerDigiFiller.h & https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/src/MuonShowerDigiFiller.cc for (const auto &chamber : info.chambers) { if (chamber.id.subdetId() == MuonSubdetId::RPC) //&& rpcHitHandle_.isValid()) @@ -182,7 +189,7 @@ void MuonDetCleaner::produce(edm::Event& iEvent, const edm::EventSetup& for (auto digiIt = range.first; digiIt != range.second; ++digiIt) { - const auto topo = m_dtGeometry->layer(layerId)->specificTopology(); + const auto topo = m_dtGeometry.layer(layerId)->specificTopology(); double xWire = topo.wirePosition((*digiIt).wire()); double dX = std::abs(xWire - xTrack); @@ -226,7 +233,7 @@ void MuonDetCleaner::produce(edm::Event& iEvent, const edm::EventSetup& if (!hasFired) continue; - const CSCLayerGeometry *layerGeom = m_cscGeometry->layer(layerId)->geometry(); + const CSCLayerGeometry *layerGeom = m_cscGeometry.layer(layerId)->geometry(); Float_t xStrip = layerGeom->xOfStrip(digiIt->getStrip(), yTrack); float dX = std::abs(xStrip - xTrack); @@ -243,7 +250,6 @@ void MuonDetCleaner::produce(edm::Event& iEvent, const edm::EventSetup& //----------------- } -} sort( vetoHits.begin(), vetoHits.end() ); vetoHits.erase( unique( vetoHits.begin(), vetoHits.end() ), vetoHits.end() ); From 01c93074b4be83cc3fb88af07924e653322ed0aa Mon Sep 17 00:00:00 2001 From: cwinter Date: Mon, 27 Nov 2023 18:55:03 +0100 Subject: [PATCH 50/58] format code with clang-format --- .../MCEmbeddingTools/plugins/CaloCleaner.cc | 2 +- .../MCEmbeddingTools/plugins/CaloCleaner.h | 60 ++-- .../plugins/CollectionMerger.cc | 226 +++++++------ .../plugins/CollectionMerger.h | 56 ++-- .../plugins/DYToElElGenFilter.cc | 113 +++---- .../plugins/DYToElTauGenFilter.cc | 228 ++++++------- .../plugins/DYToMuMuGenFilter.cc | 50 +-- .../plugins/DYToMuTauGenFilter.cc | 228 ++++++------- .../plugins/DYToTauTauGenFilter.cc | 204 +++++------- .../plugins/DoubleCollectionMerger.cc | 128 ++++---- .../plugins/DoubleCollectionMerger.h | 133 ++++---- .../EmbeddingBeamSpotOnlineProducer.cc | 17 +- .../plugins/EmbeddingBeamSpotOnlineProducer.h | 21 +- .../EmbeddingHltPixelVerticesProducer.cc | 134 ++++---- .../plugins/EmbeddingLHEProducer.cc | 133 ++++---- .../plugins/EmbeddingVertexCorrector.cc | 28 +- .../plugins/MuMuForEmbeddingSelector.cc | 75 ++--- .../plugins/MuonDetCleaner.cc | 75 ++--- .../MCEmbeddingTools/plugins/MuonDetCleaner.h | 302 +++++++++--------- .../plugins/TrackMergeremb.cc | 178 ++++++----- .../MCEmbeddingTools/plugins/TrackMergeremb.h | 45 ++- .../plugins/TrackerCleaner.cc | 6 +- .../MCEmbeddingTools/plugins/TrackerCleaner.h | 57 ++-- 23 files changed, 1201 insertions(+), 1298 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc index 4ba0752a1ae05..3aac2b04c54ef 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc @@ -1,11 +1,11 @@ #include "TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h" #include "DataFormats/EcalRecHit/interface/EcalRecHit.h" +#include "DataFormats/HcalRecHit/interface/CastorRecHit.h" #include "DataFormats/HcalRecHit/interface/HBHERecHit.h" #include "DataFormats/HcalRecHit/interface/HFRecHit.h" #include "DataFormats/HcalRecHit/interface/HORecHit.h" #include "DataFormats/HcalRecHit/interface/ZDCRecHit.h" -#include "DataFormats/HcalRecHit/interface/CastorRecHit.h" typedef CaloCleaner EcalRecHitColCleaner; typedef CaloCleaner HBHERecHitColCleaner; diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h index e9eec4a8f9fa8..9114af7d93ffd 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h @@ -2,65 +2,65 @@ * * Clean collections of calorimeter recHits * (detectors supported at the moment: EB/EE, HB/HE and HO) - * + * * \author Tomasz Maciej Frueboes; * Christian Veelken, LLR * - * + * * * Clean Up from STefan Wayand, KIT */ #ifndef TauAnalysis_MCEmbeddingTools_CaloCleaner_H #define TauAnalysis_MCEmbeddingTools_CaloCleaner_H -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "DataFormats/Common/interface/Handle.h" -#include "DataFormats/PatCandidates/interface/Muon.h" #include "DataFormats/MuonReco/interface/MuonEnergy.h" +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h" #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h" -#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" #include "DataFormats/Common/interface/SortedCollection.h" #include "DataFormats/EcalRecHit/interface/EcalRecHit.h" -#include #include #include +#include template class CaloCleaner : public edm::stream::EDProducer<> { public: - explicit CaloCleaner(const edm::ParameterSet&); + explicit CaloCleaner(const edm::ParameterSet &); ~CaloCleaner() override; private: - void produce(edm::Event&, const edm::EventSetup&) override; + void produce(edm::Event &, const edm::EventSetup &) override; typedef edm::SortedCollection RecHitCollection; - const edm::EDGetTokenT > mu_input_; + const edm::EDGetTokenT> mu_input_; - std::map > inputs_; + std::map> inputs_; edm::ESGetToken propagatorToken_; TrackDetectorAssociator trackAssociator_; TrackAssociatorParameters parameters_; bool is_preshower_; - void fill_correction_map(TrackDetMatchInfo*, std::map*); + void fill_correction_map(TrackDetMatchInfo *, std::map *); }; template -CaloCleaner::CaloCleaner(const edm::ParameterSet& iConfig) - : mu_input_(consumes >(iConfig.getParameter("MuonCollection"))), +CaloCleaner::CaloCleaner(const edm::ParameterSet &iConfig) + : mu_input_(consumes>(iConfig.getParameter("MuonCollection"))), propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))) { - std::vector inCollections = iConfig.getParameter >("oldCollection"); - for (const auto& inCollection : inCollections) { + std::vector inCollections = iConfig.getParameter>("oldCollection"); + for (const auto &inCollection : inCollections) { inputs_[inCollection.instance()] = consumes(inCollection); produces(inCollection.instance()); } @@ -69,7 +69,7 @@ CaloCleaner::CaloCleaner(const edm::ParameterSet& iConfig) edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); edm::ConsumesCollector iC = consumesCollector(); parameters_.loadParameters(parameters, iC); - //trackAssociator_.useDefaultPropagator(); + // trackAssociator_.useDefaultPropagator(); } template @@ -78,11 +78,11 @@ CaloCleaner::~CaloCleaner() { } template -void CaloCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - auto const& propagator = iSetup.getData(propagatorToken_); +void CaloCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + auto const &propagator = iSetup.getData(propagatorToken_); trackAssociator_.setPropagator(&propagator); - edm::Handle > muonHandle; + edm::Handle> muonHandle; iEvent.getByToken(mu_input_, muonHandle); edm::View muons = *muonHandle; @@ -92,7 +92,7 @@ void CaloCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { // get the basic informaiton like fill reco mouon does // RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc - const reco::Track* track = nullptr; + const reco::Track *track = nullptr; if (iMuon->track().isNonnull()) track = iMuon->track().get(); else if (iMuon->standAloneMuon().isNonnull()) @@ -124,14 +124,14 @@ void CaloCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) } else { recHitCollection_output->push_back(*recHit); } - /* For the inveted collection - if (correction_map[recHit->detid().rawId()] > 0){ - float new_energy = correction_map[recHit->detid().rawId()]; - if (new_energy < 0) new_energy =0; - T newRecHit(*recHit); - newRecHit.setEnergy(new_energy); - recHitCollection_output->push_back(newRecHit); - }*/ + /* For the inveted collection + if (correction_map[recHit->detid().rawId()] > 0){ + float new_energy = correction_map[recHit->detid().rawId()]; + if (new_energy < 0) new_energy =0; + T newRecHit(*recHit); + newRecHit.setEnergy(new_energy); + recHitCollection_output->push_back(newRecHit); + }*/ } // Save the new collection recHitCollection_output->sort(); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc index 37c74eee9a518..705f9222267f6 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc @@ -4,26 +4,26 @@ #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" #include "DataFormats/SiStripCluster/interface/SiStripCluster.h" -#include "DataFormats/EcalRecHit/interface/EcalRecHit.h" #include "DataFormats/Common/interface/SortedCollection.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHit.h" -#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" #include "DataFormats/EgammaReco/interface/SuperCluster.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" -#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" #include "DataFormats/ParticleFlowReco/interface/PFCluster.h" +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" #include "DataFormats/CaloRecHit/interface/CaloCluster.h" -#include "DataFormats/MuonDetId/interface/DTLayerId.h" -#include "DataFormats/DTRecHit/interface/DTSLRecCluster.h" #include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h" +#include "DataFormats/DTRecHit/interface/DTSLRecCluster.h" +#include "DataFormats/MuonDetId/interface/DTLayerId.h" -#include "DataFormats/MuonDetId/interface/CSCDetId.h" #include "DataFormats/CSCRecHit/interface/CSCRecHit2D.h" +#include "DataFormats/HcalRecHit/interface/ZDCRecHit.h" +#include "DataFormats/MuonDetId/interface/CSCDetId.h" #include "DataFormats/MuonDetId/interface/RPCDetId.h" #include "DataFormats/RPCRecHit/interface/RPCRecHit.h" -#include "DataFormats/HcalRecHit/interface/ZDCRecHit.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" @@ -36,11 +36,11 @@ #include "DataFormats/EgammaCandidates/interface/Conversion.h" -#include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h" +#include "DataFormats/VertexReco/interface/Vertex.h" -#include "DataFormats/Common/interface/RangeMap.h" #include "DataFormats/Common/interface/OwnVector.h" +#include "DataFormats/Common/interface/RangeMap.h" typedef CollectionMerger, SiPixelCluster> PixelColMerger; typedef CollectionMerger, SiStripCluster> StripColMerger; @@ -54,28 +54,24 @@ typedef CollectionMerger, HORecHit> HORecHitColM typedef CollectionMerger, CastorRecHit> CastorRecHitColMerger; typedef CollectionMerger, ZDCRecHit> ZDCRecHitColMerger; -typedef CollectionMerger >, DTRecHit1DPair> DTRecHitColMerger; -typedef CollectionMerger >, CSCRecHit2D> CSCRecHitColMerger; -typedef CollectionMerger >, RPCRecHit> RPCRecHitColMerger; +typedef CollectionMerger>, DTRecHit1DPair> DTRecHitColMerger; +typedef CollectionMerger>, CSCRecHit2D> CSCRecHitColMerger; +typedef CollectionMerger>, RPCRecHit> RPCRecHitColMerger; template -void CollectionMerger::willconsume(const edm::ParameterSet& iConfig) -{ - -} +void CollectionMerger::willconsume(const edm::ParameterSet &iConfig) {} template -void CollectionMerger::willproduce(std::string instance, std::string alias) -{ +void CollectionMerger::willproduce(std::string instance, std::string alias) { produces(instance); } // -------- Here Tracker Merger ----------- template void CollectionMerger::fill_output_obj_tracker(std::unique_ptr &output, - std::vector > &inputCollections, + std::vector> &inputCollections, bool print_pixel) { - std::map > output_map; + std::map> output_map; // First merge the collections with the help of the output map for (auto const &inputCollection : inputCollections) { for (typename MergeCollection::const_iterator clustSet = inputCollection->begin(); @@ -89,7 +85,7 @@ void CollectionMerger::fill_output_obj_tracker(std::unique_ptr >::const_iterator outHits = output_map.begin(); + for (typename std::map>::const_iterator outHits = output_map.begin(); outHits != output_map.end(); ++outHits) { DetId detIdObject(outHits->first); @@ -102,7 +98,7 @@ void CollectionMerger::fill_output_obj_tracker(std::unique_ptr void CollectionMerger::fill_output_obj_calo(std::unique_ptr &output, - std::vector > &inputCollections) { + std::vector> &inputCollections) { std::map output_map; // First merge the two collections again for (auto const &inputCollection : inputCollections) { @@ -121,14 +117,14 @@ void CollectionMerger::fill_output_obj_calo(std::unique_ptrpush_back(outHits->second); } - output->sort(); //Do a sort for this collection + output->sort(); // Do a sort for this collection } // -------- Here Muon Chamber Merger ----------- template void CollectionMerger::fill_output_obj_muonchamber( - std::unique_ptr &output, std::vector > &inputCollections) { - std::map > output_map; + std::unique_ptr &output, std::vector> &inputCollections) { + std::map> output_map; // First merge the collections with the help of the output map for (auto const &inputCollection : inputCollections) { for (typename MergeCollection::const_iterator recHit = inputCollection->begin(); recHit != inputCollection->end(); @@ -138,7 +134,7 @@ void CollectionMerger::fill_output_obj_muonchamber( } } // Now save it into the standard CMSSW format, with the standard Filler - for (typename std::map >::const_iterator outHits = output_map.begin(); + for (typename std::map>::const_iterator outHits = output_map.begin(); outHits != output_map.end(); ++outHits) { output->put((typename T1::id_iterator::value_type)outHits->first, @@ -147,99 +143,102 @@ void CollectionMerger::fill_output_obj_muonchamber( } } - // -------- Here Electron Seed Merger ----------- -//TODO: move seed merger to TrackMerger class +// TODO: move seed merger to TrackMerger class template <> -void CollectionMerger, reco::ElectronSeed>::willconsume(const edm::ParameterSet& iConfig) -{ - //track refs for trackerdriven seeds - inputs_fixtrackrefs_ = consumes( edm::InputTag("generalTracks") ); - inputs_fixtrackcol_ = consumes( edm::InputTag("generalTracks") ); - - //sc refs for ecaldriven seeds - inputs_scEB_ = consumes(edm::InputTag("particleFlowSuperClusterECAL:particleFlowSuperClusterECALBarrel") ); - inputs_scEE_ = consumes(edm::InputTag("particleFlowSuperClusterECAL:particleFlowSuperClusterECALEndcapWithPreshower") ); +void CollectionMerger, reco::ElectronSeed>::willconsume( + const edm::ParameterSet &iConfig) { + // track refs for trackerdriven seeds + inputs_fixtrackrefs_ = consumes(edm::InputTag("generalTracks")); + inputs_fixtrackcol_ = consumes(edm::InputTag("generalTracks")); + + // sc refs for ecaldriven seeds + inputs_scEB_ = consumes( + edm::InputTag("particleFlowSuperClusterECAL:particleFlowSuperClusterECALBarrel")); + inputs_scEE_ = consumes( + edm::InputTag("particleFlowSuperClusterECAL:particleFlowSuperClusterECALEndcapWithPreshower")); } template <> -void CollectionMerger, reco::ElectronSeed>::willproduce(std::string instance, std::string alias) -{ - produces(instance); +void CollectionMerger, reco::ElectronSeed>::willproduce(std::string instance, + std::string alias) { + produces(instance); } template -void CollectionMerger::fill_output_obj_seed(edm::Event& iEvent, std::unique_ptr & output, std::vector > &inputCollections) -{ - //track to track map for trackerdriven seed fix +void CollectionMerger::fill_output_obj_seed(edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { + // track to track map for trackerdriven seed fix edm::Handle track_ref_map; iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map); edm::Handle track_new_col; iEvent.getByToken(inputs_fixtrackcol_, track_new_col); - std::map simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map - for (unsigned abc =0; abc < track_new_col->size(); ++abc) { + std::map + simple_track_to_track_map; // I didn't find a more elegant way, so just build a good old fassion std::map + for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; } - //ECAL barrel supercluster collection + // ECAL barrel supercluster collection edm::Handle scEB; - iEvent.getByToken(inputs_scEB_,scEB); + iEvent.getByToken(inputs_scEB_, scEB); auto bScEB = scEB->cbegin(); auto eScEB = scEB->cend(); - //ECAL endcap supercluster collection + // ECAL endcap supercluster collection edm::Handle scEE; - iEvent.getByToken(inputs_scEE_,scEE); + iEvent.getByToken(inputs_scEE_, scEE); auto bScEE = scEE->cbegin(); auto eScEE = scEE->cend(); // First merge the two collections again - for (auto const & inputCollection : inputCollections){ - for ( typename MergeCollection::const_iterator seed = inputCollection->begin(); seed!= inputCollection->end(); ++seed ) { + for (auto const &inputCollection : inputCollections) { + for (typename MergeCollection::const_iterator seed = inputCollection->begin(); seed != inputCollection->end(); + ++seed) { T2 newSeed(*seed); - //fix reference to supercluster if seed is ecal driven + // fix reference to supercluster if seed is ecal driven if (seed->isEcalDriven()) { - const reco::ElectronSeed::CaloClusterRef & seedCcRef(seed->caloCluster()); - if( seedCcRef.isNonnull() ) { - - //find corresponding supercluster in ECAL barrel and endcap + const reco::ElectronSeed::CaloClusterRef &seedCcRef(seed->caloCluster()); + if (seedCcRef.isNonnull()) { + // find corresponding supercluster in ECAL barrel and endcap float dx, dy, dz, dr; float drMin = std::numeric_limits::infinity(); reco::ElectronSeed::CaloClusterRef ccRefMin; - for( auto sc = bScEB; sc != eScEB; ++sc ) { - const reco::SuperClusterRef & scRef(reco::SuperClusterRef(scEB,std::distance(bScEB,sc))); - dx = fabs(scRef->x()-seedCcRef->x()); - dy = fabs(scRef->y()-seedCcRef->y()); - dz = fabs(scRef->z()-seedCcRef->z()); - dr = sqrt(dx*dx+dy*dy+dz*dz); - if ( dr < drMin ) { + for (auto sc = bScEB; sc != eScEB; ++sc) { + const reco::SuperClusterRef &scRef(reco::SuperClusterRef(scEB, std::distance(bScEB, sc))); + dx = fabs(scRef->x() - seedCcRef->x()); + dy = fabs(scRef->y() - seedCcRef->y()); + dz = fabs(scRef->z() - seedCcRef->z()); + dr = sqrt(dx * dx + dy * dy + dz * dz); + if (dr < drMin) { drMin = dr; ccRefMin = reco::ElectronSeed::CaloClusterRef(scRef); } } - for( auto sc = bScEE; sc != eScEE; ++sc ) { - const reco::SuperClusterRef & scRef(reco::SuperClusterRef(scEE,std::distance(bScEE,sc))); - dx = fabs(scRef->x()-seedCcRef->x()); - dy = fabs(scRef->y()-seedCcRef->y()); - dz = fabs(scRef->z()-seedCcRef->z()); - dr = sqrt(dx*dx+dy*dy+dz*dz); - if ( dr < drMin ) { + for (auto sc = bScEE; sc != eScEE; ++sc) { + const reco::SuperClusterRef &scRef(reco::SuperClusterRef(scEE, std::distance(bScEE, sc))); + dx = fabs(scRef->x() - seedCcRef->x()); + dy = fabs(scRef->y() - seedCcRef->y()); + dz = fabs(scRef->z() - seedCcRef->z()); + dr = sqrt(dx * dx + dy * dy + dz * dz); + if (dr < drMin) { drMin = dr; ccRefMin = reco::ElectronSeed::CaloClusterRef(scRef); } } - //set new calocluster if new ref was found + // set new calocluster if new ref was found if (drMin < 10.0) { newSeed.setCaloCluster(ccRefMin); } } } if (seed->isTrackerDriven()) { - const reco::ElectronSeed::CtfTrackRef & ctfTrackRef(seed->ctfTrack()); - if ( ctfTrackRef.isNonnull() ){ + const reco::ElectronSeed::CtfTrackRef &ctfTrackRef(seed->ctfTrack()); + if (ctfTrackRef.isNonnull()) { newSeed.setCtfTrack(simple_track_to_track_map[ctfTrackRef]); } } @@ -250,90 +249,113 @@ void CollectionMerger::fill_output_obj_seed(edm::Event& iEvent, std::uni // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections template -void CollectionMerger::fill_output_obj(edm::Event& iEvent, std::unique_ptr &output, - std::vector > &inputCollections) { +void CollectionMerger::fill_output_obj(edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { assert(0); // CV: make sure general function never gets called; // always use template specializations } // Start with the Tracker collections template <> -void CollectionMerger, SiPixelCluster>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger, SiPixelCluster>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_tracker(output, inputCollections, true); } template <> -void CollectionMerger, SiStripCluster>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger, SiStripCluster>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_tracker(output, inputCollections); } // Next are the Calo entries template <> -void CollectionMerger, EcalRecHit>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger, EcalRecHit>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, HBHERecHit>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger, HBHERecHit>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, HFRecHit>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger, HFRecHit>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, HORecHit>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger, HORecHit>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, CastorRecHit>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger, CastorRecHit>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_calo(output, inputCollections); } template <> -void CollectionMerger, ZDCRecHit>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger, ZDCRecHit>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_calo(output, inputCollections); } // Here the Muon Chamber template <> -void CollectionMerger >, DTRecHit1DPair>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger>, DTRecHit1DPair>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_muonchamber(output, inputCollections); } template <> -void CollectionMerger >, CSCRecHit2D>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger>, CSCRecHit2D>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_muonchamber(output, inputCollections); } template <> -void CollectionMerger >, RPCRecHit>::fill_output_obj(edm::Event& iEvent, - std::unique_ptr &output, std::vector > &inputCollections) { +void CollectionMerger>, RPCRecHit>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { fill_output_obj_muonchamber(output, inputCollections); } // Here Electron Seeds template <> -void CollectionMerger, reco::ElectronSeed>::fill_output_obj(edm::Event& iEvent,std::unique_ptr & output, std::vector > &inputCollections) -{ - fill_output_obj_seed(iEvent, output,inputCollections); +void CollectionMerger, reco::ElectronSeed>::fill_output_obj( + edm::Event &iEvent, + std::unique_ptr &output, + std::vector> &inputCollections) { + fill_output_obj_seed(iEvent, output, inputCollections); } - - DEFINE_FWK_MODULE(PixelColMerger); DEFINE_FWK_MODULE(StripColMerger); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h index ba1b46c6e6dd3..ead32c8ccb58b 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h @@ -12,38 +12,38 @@ #ifndef TauAnalysis_MCEmbeddingTools_CollectionMerger_H #define TauAnalysis_MCEmbeddingTools_CollectionMerger_H -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "DataFormats/Common/interface/Handle.h" -#include "DataFormats/PatCandidates/interface/Muon.h" #include "DataFormats/MuonReco/interface/MuonEnergy.h" +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" #include "DataFormats/EgammaReco/interface/SuperCluster.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" -#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" #include "DataFormats/ParticleFlowReco/interface/PFCluster.h" +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" #include "DataFormats/TrackReco/interface/TrackToTrackMap.h" +#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h" #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h" -#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" +#include "DataFormats/Common/interface/DetSetVectorNew.h" #include "DataFormats/Common/interface/SortedCollection.h" #include "DataFormats/EcalRecHit/interface/EcalRecHit.h" -#include "DataFormats/Common/interface/DetSetVectorNew.h" #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h" #include "DataFormats/TrackerRecHit2D/interface/OmniClusterRef.h" -//#include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h" -#include +// #include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h" #include #include +#include template class CollectionMerger : public edm::stream::EDProducer<> { @@ -56,42 +56,44 @@ class CollectionMerger : public edm::stream::EDProducer<> { typedef T1 MergeCollection; typedef T2 BaseHit; - std::map > > inputs_; + std::map>> inputs_; - edm::EDGetTokenT inputs_scEB_,inputs_scEE_, inputs_SC_; + edm::EDGetTokenT inputs_scEB_, inputs_scEE_, inputs_SC_; typedef edm::ValueMap TrackToTrackMapnew; - edm::EDGetTokenT inputs_fixtrackrefs_; - edm::EDGetTokenT inputs_fixtrackcol_; + edm::EDGetTokenT inputs_fixtrackrefs_; + edm::EDGetTokenT inputs_fixtrackcol_; - void fill_output_obj(edm::Event&, std::unique_ptr &output, - std::vector > &inputCollections); + void fill_output_obj(edm::Event &, + std::unique_ptr &output, + std::vector> &inputCollections); void fill_output_obj_tracker(std::unique_ptr &output, - std::vector > &inputCollections, + std::vector> &inputCollections, bool print_pixel = false); void fill_output_obj_calo(std::unique_ptr &output, - std::vector > &inputCollections); + std::vector> &inputCollections); void fill_output_obj_muonchamber(std::unique_ptr &output, - std::vector > &inputCollections); - //seed merger - void fill_output_obj_seed(edm::Event&, std::unique_ptr & output, std::vector > &inputCollections); + std::vector> &inputCollections); + // seed merger + void fill_output_obj_seed(edm::Event &, + std::unique_ptr &output, + std::vector> &inputCollections); void willproduce(std::string instance, std::string alias); - void willconsume(const edm::ParameterSet& iConfig); - + void willconsume(const edm::ParameterSet &iConfig); }; template CollectionMerger::CollectionMerger(const edm::ParameterSet &iConfig) { - std::vector inCollections = iConfig.getParameter >("mergCollections"); + std::vector inCollections = iConfig.getParameter>("mergCollections"); for (auto const &inCollection : inCollections) { inputs_[inCollection.instance()].push_back(consumes(inCollection)); } willconsume(iConfig); for (const auto &toproduce : inputs_) { - std::string alias( iConfig.getParameter( "@module_label" ) ); + std::string alias(iConfig.getParameter("@module_label")); // std::cout< void CollectionMerger::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { for (auto input_ : inputs_) { std::unique_ptr output(new MergeCollection()); - std::vector > inputCollections; + std::vector> inputCollections; inputCollections.resize(input_.second.size()); for (unsigned id = 0; id < input_.second.size(); id++) { iEvent.getByToken(input_.second[id], inputCollections[id]); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc index 46b25d12d7928..453de52082d35 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc @@ -1,9 +1,9 @@ -#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" #include "DataFormats/HepMCCandidate/interface/GenParticle.h" #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/Candidate/interface/Candidate.h" #include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/Framework/interface/stream/EDFilter.h" #include "FWCore/Utilities/interface/StreamID.h" @@ -12,94 +12,71 @@ #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +class DYToElElGenFilter : public edm::stream::EDFilter<> { +public: + explicit DYToElElGenFilter(const edm::ParameterSet &); + ~DYToElElGenFilter() override; -class DYToElElGenFilter: public edm::stream::EDFilter<> { - public: - explicit DYToElElGenFilter(const edm::ParameterSet&); - ~DYToElElGenFilter() override; + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); +private: + void beginStream(edm::StreamID) override; + bool filter(edm::Event &, const edm::EventSetup &) override; + void endStream() override; - private: - void beginStream(edm::StreamID) override; - bool filter(edm::Event&, const edm::EventSetup&) override; - void endStream() override; - - edm::InputTag inputTag_; - edm::EDGetTokenT genParticleCollection_; + edm::InputTag inputTag_; + edm::EDGetTokenT genParticleCollection_; - edm::Handle gen_handle; - - //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; - //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; - //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + edm::Handle gen_handle; - // ----------member data --------------------------- -}; + // virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + // virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + // virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + // virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + // ----------member data --------------------------- +}; -DYToElElGenFilter::DYToElElGenFilter(const edm::ParameterSet& iConfig) -{ - inputTag_= iConfig.getParameter("inputTag"); +DYToElElGenFilter::DYToElElGenFilter(const edm::ParameterSet &iConfig) { + inputTag_ = iConfig.getParameter("inputTag"); genParticleCollection_ = consumes(inputTag_); } - -DYToElElGenFilter::~DYToElElGenFilter() { -} - -bool DYToElElGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { - - - iEvent.getByToken(genParticleCollection_, gen_handle); - - for(unsigned int i = 0; i < gen_handle->size(); i++) - { - const reco::GenParticle gen_particle = (*gen_handle)[i]; - // Check if Z Boson decayed into two leptons - if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) - { - // Check if daugther particles are Electrons - if (std::abs(gen_particle.daughter(0)->pdgId()) == 11 - && std::abs(gen_particle.daughter(1)->pdgId()) == 11 - && std::abs(gen_particle.daughter(0)->eta())<2.6 - && std::abs(gen_particle.daughter(1)->eta())<2.6 - && gen_particle.daughter(0)->pt()>7 - && gen_particle.daughter(1)->pt()>7) - { - edm::LogPrint("") << "Electron Event ! "; - return true; - } - else - { +DYToElElGenFilter::~DYToElElGenFilter() {} + +bool DYToElElGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { + iEvent.getByToken(genParticleCollection_, gen_handle); + + for (unsigned int i = 0; i < gen_handle->size(); i++) { + const reco::GenParticle gen_particle = (*gen_handle)[i]; + // Check if Z Boson decayed into two leptons + if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { + // Check if daugther particles are Electrons + if (std::abs(gen_particle.daughter(0)->pdgId()) == 11 && std::abs(gen_particle.daughter(1)->pdgId()) == 11 && + std::abs(gen_particle.daughter(0)->eta()) < 2.6 && std::abs(gen_particle.daughter(1)->eta()) < 2.6 && + gen_particle.daughter(0)->pt() > 7 && gen_particle.daughter(1)->pt() > 7) { + edm::LogPrint("") << "Electron Event ! "; + return true; + } else { return false; } - } + } } return false; } // ------------ method called once each stream before processing any runs, lumis or events ------------ -void -DYToElElGenFilter::beginStream(edm::StreamID) -{ -} +void DYToElElGenFilter::beginStream(edm::StreamID) {} // ------------ method called once each stream after processing all runs, lumis and events ------------ -void -DYToElElGenFilter::endStream() { -} +void DYToElElGenFilter::endStream() {} // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void -DYToElElGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters +void DYToElElGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); } - - DEFINE_FWK_MODULE(DYToElElGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc index 2bc0e845987ec..ddd9c79569f5b 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc @@ -1,9 +1,9 @@ -#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" #include "DataFormats/HepMCCandidate/interface/GenParticle.h" #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/Candidate/interface/Candidate.h" #include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/Framework/interface/stream/EDFilter.h" #include "FWCore/Utilities/interface/StreamID.h" @@ -12,154 +12,122 @@ #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +class DYToElTauGenFilter : public edm::stream::EDFilter<> { +public: + explicit DYToElTauGenFilter(const edm::ParameterSet &); + ~DYToElTauGenFilter() override; -class DYToElTauGenFilter: public edm::stream::EDFilter<> { - public: - explicit DYToElTauGenFilter(const edm::ParameterSet&); - ~DYToElTauGenFilter() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - - private: - void beginStream(edm::StreamID) override; - bool filter(edm::Event&, const edm::EventSetup&) override; - void endStream() override; - bool leptondecay(const reco::Candidate *d, int depth); - bool electrondecay(const reco::Candidate *d, int depth); + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - edm::InputTag inputTag_; - edm::EDGetTokenT genParticleCollection_; - edm::Handle gen_handle; +private: + void beginStream(edm::StreamID) override; + bool filter(edm::Event &, const edm::EventSetup &) override; + void endStream() override; + bool leptondecay(const reco::Candidate *d, int depth); + bool electrondecay(const reco::Candidate *d, int depth); + edm::InputTag inputTag_; + edm::EDGetTokenT genParticleCollection_; + edm::Handle gen_handle; }; -DYToElTauGenFilter::DYToElTauGenFilter(const edm::ParameterSet& iConfig) -{ - inputTag_= iConfig.getParameter("inputTag"); +DYToElTauGenFilter::DYToElTauGenFilter(const edm::ParameterSet &iConfig) { + inputTag_ = iConfig.getParameter("inputTag"); genParticleCollection_ = consumes(inputTag_); } - -DYToElTauGenFilter::~DYToElTauGenFilter() { -} - - -bool DYToElTauGenFilter::leptondecay(const reco::Candidate *d, int depth) -{ - //returns true if the event has an leptonic decay - // Debug Output - // std::cout << std::string(4*depth, '-') << "---Hadroncheck-" << std::endl; - // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; - // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; - // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; - // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; - bool check = false; - if (d->status()!= 1) - { - if(d->numberOfDaughters() == 3) - { - if(std::abs(d->daughter(0)->pdgId()) == 14 - || std::abs(d->daughter(1)->pdgId()) == 14 - || std::abs(d->daughter(2)->pdgId()) == 14 - || std::abs(d->daughter(0)->pdgId()) == 12 - || std::abs(d->daughter(1)->pdgId()) == 12 - || std::abs(d->daughter(2)->pdgId()) == 12) check = true; - } - else if (d->numberOfDaughters() > 3) return false; - if (d->numberOfDaughters() < 4) - { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) - { - // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; - int new_depth = depth + 1; - if(leptondecay(d->daughter(k), new_depth) == true) check = true; - } - } - } - return check; +DYToElTauGenFilter::~DYToElTauGenFilter() {} + +bool DYToElTauGenFilter::leptondecay(const reco::Candidate *d, int depth) { + // returns true if the event has an leptonic decay + // Debug Output + // std::cout << std::string(4*depth, '-') << "---Hadroncheck-" << std::endl; + // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; + // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; + // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; + // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; + bool check = false; + if (d->status() != 1) { + if (d->numberOfDaughters() == 3) { + if (std::abs(d->daughter(0)->pdgId()) == 14 || std::abs(d->daughter(1)->pdgId()) == 14 || + std::abs(d->daughter(2)->pdgId()) == 14 || std::abs(d->daughter(0)->pdgId()) == 12 || + std::abs(d->daughter(1)->pdgId()) == 12 || std::abs(d->daughter(2)->pdgId()) == 12) + check = true; + } else if (d->numberOfDaughters() > 3) + return false; + if (d->numberOfDaughters() < 4) { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { + // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; + int new_depth = depth + 1; + if (leptondecay(d->daughter(k), new_depth) == true) + check = true; + } + } + } + return check; } -bool DYToElTauGenFilter::electrondecay(const reco::Candidate *d, int depth) -{ - //returns true if the event has an electron decay - bool check = false; - if (d->status()!= 1) - { - if(d->numberOfDaughters() == 3) - { - if(std::abs(d->daughter(0)->pdgId()) == 12 - || std::abs(d->daughter(1)->pdgId()) == 12 - || std::abs(d->daughter(2)->pdgId()) == 12) check = true; - } - else if (d->numberOfDaughters() > 3) return false; - if (d->numberOfDaughters() < 4) - { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) - { - int new_depth = depth + 1; - if(electrondecay(d->daughter(k), new_depth) == true) check = true; - } - } - } - return check; +bool DYToElTauGenFilter::electrondecay(const reco::Candidate *d, int depth) { + // returns true if the event has an electron decay + bool check = false; + if (d->status() != 1) { + if (d->numberOfDaughters() == 3) { + if (std::abs(d->daughter(0)->pdgId()) == 12 || std::abs(d->daughter(1)->pdgId()) == 12 || + std::abs(d->daughter(2)->pdgId()) == 12) + check = true; + } else if (d->numberOfDaughters() > 3) + return false; + if (d->numberOfDaughters() < 4) { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { + int new_depth = depth + 1; + if (electrondecay(d->daughter(k), new_depth) == true) + check = true; + } + } + } + return check; } -bool DYToElTauGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { - - - iEvent.getByToken(genParticleCollection_, gen_handle); - - for(unsigned int i = 0; i < gen_handle->size(); i++) - { - const reco::GenParticle gen_particle = (*gen_handle)[i]; - // Check if Z Boson decayed into two leptons - if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) - { - // Check if daugther particles are taus - // From Generator: Mu.Pt > 18 && Had.Pt > 25 && Mu.Eta < 2.1 - if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 - && std::abs(gen_particle.daughter(0)->eta())<2.1 - && gen_particle.daughter(0)->pt()>25 - && gen_particle.daughter(1)->pt()>18) - { - bool had_1 = !DYToElTauGenFilter::leptondecay(gen_particle.daughter(0),1); - bool el_2 = DYToElTauGenFilter::electrondecay(gen_particle.daughter(1),1); - bool had_2 = !DYToElTauGenFilter::leptondecay(gen_particle.daughter(1),1); - bool el_1 = DYToElTauGenFilter::electrondecay(gen_particle.daughter(0),1); - - std::cout << had_1 << " & " << el_2 << " / " << had_2 << " & " << el_1 << " |" << std::endl; - if ((had_1 && el_2)||(had_2 && el_1)) - { - std::cout << "Hadronic Decay Check was positive" << std::endl; - return true; - } - std::cout << "Hadronic Decay Check was negative" << std::endl; - } - return false; - } +bool DYToElTauGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { + iEvent.getByToken(genParticleCollection_, gen_handle); + + for (unsigned int i = 0; i < gen_handle->size(); i++) { + const reco::GenParticle gen_particle = (*gen_handle)[i]; + // Check if Z Boson decayed into two leptons + if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { + // Check if daugther particles are taus + // From Generator: Mu.Pt > 18 && Had.Pt > 25 && Mu.Eta < 2.1 + if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 && std::abs(gen_particle.daughter(0)->eta()) < 2.1 && + gen_particle.daughter(0)->pt() > 25 && gen_particle.daughter(1)->pt() > 18) { + bool had_1 = !DYToElTauGenFilter::leptondecay(gen_particle.daughter(0), 1); + bool el_2 = DYToElTauGenFilter::electrondecay(gen_particle.daughter(1), 1); + bool had_2 = !DYToElTauGenFilter::leptondecay(gen_particle.daughter(1), 1); + bool el_1 = DYToElTauGenFilter::electrondecay(gen_particle.daughter(0), 1); + + std::cout << had_1 << " & " << el_2 << " / " << had_2 << " & " << el_1 << " |" << std::endl; + if ((had_1 && el_2) || (had_2 && el_1)) { + std::cout << "Hadronic Decay Check was positive" << std::endl; + return true; + } + std::cout << "Hadronic Decay Check was negative" << std::endl; + } + return false; } - return false; + } + return false; } // ------------ method called once each stream before processing any runs, lumis or events ------------ -void -DYToElTauGenFilter::beginStream(edm::StreamID) -{ -} +void DYToElTauGenFilter::beginStream(edm::StreamID) {} // ------------ method called once each stream after processing all runs, lumis and events ------------ -void -DYToElTauGenFilter::endStream() { -} +void DYToElTauGenFilter::endStream() {} // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void -DYToElTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters +void DYToElTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); } - - DEFINE_FWK_MODULE(DYToElTauGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc index a5206e56c9e6b..b7dde02fa79a3 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc @@ -1,9 +1,9 @@ -#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" #include "DataFormats/HepMCCandidate/interface/GenParticle.h" #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/Candidate/interface/Candidate.h" #include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/Framework/interface/stream/EDFilter.h" #include "FWCore/Utilities/interface/StreamID.h" @@ -16,7 +16,7 @@ class DYToMuMuGenFilter : public edm::stream::EDFilter<> { public: explicit DYToMuMuGenFilter(const edm::ParameterSet&); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); private: bool filter(edm::Event&, const edm::EventSetup&) override; @@ -29,7 +29,7 @@ class DYToMuMuGenFilter : public edm::stream::EDFilter<> { // ----------member data --------------------------- }; -DYToMuMuGenFilter::DYToMuMuGenFilter(const edm::ParameterSet& iConfig) { +DYToMuMuGenFilter::DYToMuMuGenFilter(const edm::ParameterSet &iConfig) { inputTag_ = iConfig.getParameter("inputTag"); genParticleCollection_ = consumes(inputTag_); } @@ -41,28 +41,28 @@ bool DYToMuMuGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup const reco::GenParticle gen_particle = (*gen_handle)[i]; // Check if Z Boson decayed into two leptons if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { - //Debug output - //std::cout << "pdgId" << gen_particle.pdgId() << std::endl; - //std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; - //std::cout << "Dau1" << gen_particle->daughters->at(0).pdgId() << std::endl; - //std::cout << "Dau2" << gen_particle.numberOfDaughters() << std::endl; - //std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; - //std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; - //std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; + // Debug output + // std::cout << "pdgId" << gen_particle.pdgId() << std::endl; + // std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; + // std::cout << "Dau1" << gen_particle->daughters->at(0).pdgId() << std::endl; + // std::cout << "Dau2" << gen_particle.numberOfDaughters() << std::endl; + // std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; + // std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; + // std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; // Check if daugther particles are muons if (std::abs(gen_particle.daughter(0)->pdgId()) == 13 && std::abs(gen_particle.daughter(0)->eta()) < 2.6 && std::abs(gen_particle.daughter(1)->eta()) < 2.6 && gen_particle.daughter(0)->pt() > 7 && gen_particle.daughter(1)->pt() > 7) { - //std::cout << "pdgId" << gen_particle.pdgId() << std::endl; - //std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; - //std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; - //std::cout << "Dau1 pt " << gen_particle.daughter(0)->pt() << std::endl; - //std::cout << "Dau1 pt " << gen_particle.daughter(0)->eta() << std::endl; - //std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; - //std::cout << "Dau2 pt " << gen_particle.daughter(1)->pt() << std::endl; - //std::cout << "Dau2 pt " << gen_particle.daughter(1)->eta() << std::endl; - //std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; + // std::cout << "pdgId" << gen_particle.pdgId() << std::endl; + // std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; + // std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; + // std::cout << "Dau1 pt " << gen_particle.daughter(0)->pt() << std::endl; + // std::cout << "Dau1 pt " << gen_particle.daughter(0)->eta() << std::endl; + // std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; + // std::cout << "Dau2 pt " << gen_particle.daughter(1)->pt() << std::endl; + // std::cout << "Dau2 pt " << gen_particle.daughter(1)->eta() << std::endl; + // std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; return true; } else { return false; @@ -73,9 +73,9 @@ bool DYToMuMuGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void DYToMuMuGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters +void DYToMuMuGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc index 2ee48ab74745a..545bb090d7d99 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc @@ -1,9 +1,9 @@ -#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" #include "DataFormats/HepMCCandidate/interface/GenParticle.h" #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/Candidate/interface/Candidate.h" #include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/Framework/interface/stream/EDFilter.h" #include "FWCore/Utilities/interface/StreamID.h" @@ -12,154 +12,122 @@ #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +class DYToMuTauGenFilter : public edm::stream::EDFilter<> { +public: + explicit DYToMuTauGenFilter(const edm::ParameterSet &); + ~DYToMuTauGenFilter() override; -class DYToMuTauGenFilter: public edm::stream::EDFilter<> { - public: - explicit DYToMuTauGenFilter(const edm::ParameterSet&); - ~DYToMuTauGenFilter() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - - private: - void beginStream(edm::StreamID) override; - bool filter(edm::Event&, const edm::EventSetup&) override; - void endStream() override; - bool leptondecay(const reco::Candidate *d, int depth); - bool muondecay(const reco::Candidate *d, int depth); + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - edm::InputTag inputTag_; - edm::EDGetTokenT genParticleCollection_; - edm::Handle gen_handle; +private: + void beginStream(edm::StreamID) override; + bool filter(edm::Event &, const edm::EventSetup &) override; + void endStream() override; + bool leptondecay(const reco::Candidate *d, int depth); + bool muondecay(const reco::Candidate *d, int depth); + edm::InputTag inputTag_; + edm::EDGetTokenT genParticleCollection_; + edm::Handle gen_handle; }; -DYToMuTauGenFilter::DYToMuTauGenFilter(const edm::ParameterSet& iConfig) -{ - inputTag_= iConfig.getParameter("inputTag"); +DYToMuTauGenFilter::DYToMuTauGenFilter(const edm::ParameterSet &iConfig) { + inputTag_ = iConfig.getParameter("inputTag"); genParticleCollection_ = consumes(inputTag_); } - -DYToMuTauGenFilter::~DYToMuTauGenFilter() { -} - - -bool DYToMuTauGenFilter::leptondecay(const reco::Candidate *d, int depth) -{ - //returns true if the event has an leptonic decay - // Debug Output - // std::cout << std::string(4*depth, '-') << "---Hadroncheck-" << std::endl; - // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; - // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; - // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; - // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; - bool check = false; - if (d->status()!= 1) - { - if(d->numberOfDaughters() == 3) - { - if(std::abs(d->daughter(0)->pdgId()) == 14 - || std::abs(d->daughter(1)->pdgId()) == 14 - || std::abs(d->daughter(2)->pdgId()) == 14 - || std::abs(d->daughter(0)->pdgId()) == 12 - || std::abs(d->daughter(1)->pdgId()) == 12 - || std::abs(d->daughter(2)->pdgId()) == 12) check = true; - } - else if (d->numberOfDaughters() > 3) return false; - if (d->numberOfDaughters() < 4) - { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) - { - // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; - int new_depth = depth + 1; - if(leptondecay(d->daughter(k), new_depth) == true) check = true; - } - } - } - return check; +DYToMuTauGenFilter::~DYToMuTauGenFilter() {} + +bool DYToMuTauGenFilter::leptondecay(const reco::Candidate *d, int depth) { + // returns true if the event has an leptonic decay + // Debug Output + // std::cout << std::string(4*depth, '-') << "---Hadroncheck-" << std::endl; + // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; + // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; + // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; + // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; + bool check = false; + if (d->status() != 1) { + if (d->numberOfDaughters() == 3) { + if (std::abs(d->daughter(0)->pdgId()) == 14 || std::abs(d->daughter(1)->pdgId()) == 14 || + std::abs(d->daughter(2)->pdgId()) == 14 || std::abs(d->daughter(0)->pdgId()) == 12 || + std::abs(d->daughter(1)->pdgId()) == 12 || std::abs(d->daughter(2)->pdgId()) == 12) + check = true; + } else if (d->numberOfDaughters() > 3) + return false; + if (d->numberOfDaughters() < 4) { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { + // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; + int new_depth = depth + 1; + if (leptondecay(d->daughter(k), new_depth) == true) + check = true; + } + } + } + return check; } -bool DYToMuTauGenFilter::muondecay(const reco::Candidate *d, int depth) -{ - //returns true if the event has an muon decay - bool check = false; - if (d->status()!= 1) - { - if(d->numberOfDaughters() == 3) - { - if(std::abs(d->daughter(0)->pdgId()) == 14 - || std::abs(d->daughter(1)->pdgId()) == 14 - || std::abs(d->daughter(2)->pdgId()) == 14) check = true; - } - else if (d->numberOfDaughters() > 3) return false; - if (d->numberOfDaughters() < 4) - { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) - { - int new_depth = depth + 1; - if(muondecay(d->daughter(k), new_depth) == true) check = true; - } - } - } - return check; +bool DYToMuTauGenFilter::muondecay(const reco::Candidate *d, int depth) { + // returns true if the event has an muon decay + bool check = false; + if (d->status() != 1) { + if (d->numberOfDaughters() == 3) { + if (std::abs(d->daughter(0)->pdgId()) == 14 || std::abs(d->daughter(1)->pdgId()) == 14 || + std::abs(d->daughter(2)->pdgId()) == 14) + check = true; + } else if (d->numberOfDaughters() > 3) + return false; + if (d->numberOfDaughters() < 4) { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { + int new_depth = depth + 1; + if (muondecay(d->daughter(k), new_depth) == true) + check = true; + } + } + } + return check; } -bool DYToMuTauGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { - - - iEvent.getByToken(genParticleCollection_, gen_handle); - - for(unsigned int i = 0; i < gen_handle->size(); i++) - { - const reco::GenParticle gen_particle = (*gen_handle)[i]; - // Check if Z Boson decayed into two leptons - if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) - { - // Check if daugther particles are taus - // From Generator: Mu.Pt > 18 && Had.Pt > 25 && Mu.Eta < 2.1 - if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 - && std::abs(gen_particle.daughter(0)->eta())<2.1 - && gen_particle.daughter(0)->pt()>25 - && gen_particle.daughter(1)->pt()>18) - { - bool had_1 = !DYToMuTauGenFilter::leptondecay(gen_particle.daughter(0),1); - bool mu_2 = DYToMuTauGenFilter::muondecay(gen_particle.daughter(1),1); - bool had_2 = !DYToMuTauGenFilter::leptondecay(gen_particle.daughter(1),1); - bool mu_1 = DYToMuTauGenFilter::muondecay(gen_particle.daughter(0),1); - - std::cout << had_1 << " & " << mu_2 << " / " << had_2 << " & " << mu_1 << " |" << std::endl; - if ((had_1 && mu_2)||(had_2 && mu_1)) - { - std::cout << "Hadronic Decay Check was positive" << std::endl; - return true; - } - std::cout << "Hadronic Decay Check was negative" << std::endl; - } - return false; - } +bool DYToMuTauGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { + iEvent.getByToken(genParticleCollection_, gen_handle); + + for (unsigned int i = 0; i < gen_handle->size(); i++) { + const reco::GenParticle gen_particle = (*gen_handle)[i]; + // Check if Z Boson decayed into two leptons + if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { + // Check if daugther particles are taus + // From Generator: Mu.Pt > 18 && Had.Pt > 25 && Mu.Eta < 2.1 + if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 && std::abs(gen_particle.daughter(0)->eta()) < 2.1 && + gen_particle.daughter(0)->pt() > 25 && gen_particle.daughter(1)->pt() > 18) { + bool had_1 = !DYToMuTauGenFilter::leptondecay(gen_particle.daughter(0), 1); + bool mu_2 = DYToMuTauGenFilter::muondecay(gen_particle.daughter(1), 1); + bool had_2 = !DYToMuTauGenFilter::leptondecay(gen_particle.daughter(1), 1); + bool mu_1 = DYToMuTauGenFilter::muondecay(gen_particle.daughter(0), 1); + + std::cout << had_1 << " & " << mu_2 << " / " << had_2 << " & " << mu_1 << " |" << std::endl; + if ((had_1 && mu_2) || (had_2 && mu_1)) { + std::cout << "Hadronic Decay Check was positive" << std::endl; + return true; + } + std::cout << "Hadronic Decay Check was negative" << std::endl; + } + return false; } - return false; + } + return false; } // ------------ method called once each stream before processing any runs, lumis or events ------------ -void -DYToMuTauGenFilter::beginStream(edm::StreamID) -{ -} +void DYToMuTauGenFilter::beginStream(edm::StreamID) {} // ------------ method called once each stream after processing all runs, lumis and events ------------ -void -DYToMuTauGenFilter::endStream() { -} +void DYToMuTauGenFilter::endStream() {} // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void -DYToMuTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters +void DYToMuTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); } - - DEFINE_FWK_MODULE(DYToMuTauGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc index 285fcb0ef3a9f..bece7750fc4bc 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc @@ -1,9 +1,9 @@ -#include "FWCore/Utilities/interface/InputTag.h" +#include "DataFormats/Candidate/interface/Candidate.h" +#include "DataFormats/Candidate/interface/LeafCandidate.h" #include "DataFormats/HepMCCandidate/interface/GenParticle.h" #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/Candidate/interface/Candidate.h" #include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/Framework/interface/stream/EDFilter.h" #include "FWCore/Utilities/interface/StreamID.h" @@ -12,144 +12,110 @@ #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +class DYToTauTauGenFilter : public edm::stream::EDFilter<> { +public: + explicit DYToTauTauGenFilter(const edm::ParameterSet &); + ~DYToTauTauGenFilter() override; -class DYToTauTauGenFilter: public edm::stream::EDFilter<> { - public: - explicit DYToTauTauGenFilter(const edm::ParameterSet&); - ~DYToTauTauGenFilter() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - private: - void beginStream(edm::StreamID) override; - bool filter(edm::Event&, const edm::EventSetup&) override; - void endStream() override; - - edm::InputTag inputTag_; - edm::EDGetTokenT genParticleCollection_; +private: + void beginStream(edm::StreamID) override; + bool filter(edm::Event &, const edm::EventSetup &) override; + void endStream() override; - edm::Handle gen_handle; - - //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; - //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; - //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - - // ----------member data --------------------------- -}; + edm::InputTag inputTag_; + edm::EDGetTokenT genParticleCollection_; + edm::Handle gen_handle; + // virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + // virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + // virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + // virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + // ----------member data --------------------------- +}; -DYToTauTauGenFilter::DYToTauTauGenFilter(const edm::ParameterSet& iConfig) -{ - inputTag_= iConfig.getParameter("inputTag"); +DYToTauTauGenFilter::DYToTauTauGenFilter(const edm::ParameterSet &iConfig) { + inputTag_ = iConfig.getParameter("inputTag"); genParticleCollection_ = consumes(inputTag_); } - -DYToTauTauGenFilter::~DYToTauTauGenFilter() { -} - -bool photoncheck(const reco::Candidate *d, int depth) -{ - // Debug Output - // std::cout << std::string(4*depth, '-') << "-----------------" << std::endl; - // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; - // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; - // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; - // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; - bool check = false; - if (d->status()!= 1) - { - if(d->numberOfDaughters() == 3) - { - if(std::abs(d->daughter(0)->pdgId()) == 14 - || std::abs(d->daughter(1)->pdgId()) == 14 - || std::abs(d->daughter(2)->pdgId()) == 14 - || std::abs(d->daughter(0)->pdgId()) == 12 - || std::abs(d->daughter(1)->pdgId()) == 12 - || std::abs(d->daughter(2)->pdgId()) == 12) - { - check = true; - } - } - else if (d->numberOfDaughters() > 3) return false; - if (d->numberOfDaughters() < 4) - { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) - { - // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; - int new_depth = depth + 1; - if(photoncheck(d->daughter(k), new_depth) == true) - check = true; - } - } - - } - return check; - +DYToTauTauGenFilter::~DYToTauTauGenFilter() {} + +bool photoncheck(const reco::Candidate *d, int depth) { + // Debug Output + // std::cout << std::string(4*depth, '-') << "-----------------" << std::endl; + // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; + // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; + // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; + // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; + bool check = false; + if (d->status() != 1) { + if (d->numberOfDaughters() == 3) { + if (std::abs(d->daughter(0)->pdgId()) == 14 || std::abs(d->daughter(1)->pdgId()) == 14 || + std::abs(d->daughter(2)->pdgId()) == 14 || std::abs(d->daughter(0)->pdgId()) == 12 || + std::abs(d->daughter(1)->pdgId()) == 12 || std::abs(d->daughter(2)->pdgId()) == 12) { + check = true; + } + } else if (d->numberOfDaughters() > 3) + return false; + if (d->numberOfDaughters() < 4) { + for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { + // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; + int new_depth = depth + 1; + if (photoncheck(d->daughter(k), new_depth) == true) + check = true; + } + } + } + return check; } -bool DYToTauTauGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { - - - iEvent.getByToken(genParticleCollection_, gen_handle); - - for(unsigned int i = 0; i < gen_handle->size(); i++) - { - const reco::GenParticle gen_particle = (*gen_handle)[i]; - // Check if Z Boson decayed into two leptons - if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) - { - //Debug output - // std::cout << "pdgId" << gen_particle.pdgId() << std::endl; - // std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; - // std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; - // std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; - // std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; - - // Check if daugther particles are taus - if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 - && std::abs(gen_particle.daughter(0)->eta())<2.3 - && std::abs(gen_particle.daughter(1)->eta())<2.3 - && ((gen_particle.daughter(0)->pt()>30 - && gen_particle.daughter(1)->pt()>35)||(gen_particle.daughter(0)->pt()>35 - && gen_particle.daughter(1)->pt()>30))) - { - if (!photoncheck(gen_particle.daughter(0),1) && !photoncheck(gen_particle.daughter(1),1)) - { - //std::cout << "Hadronic Decay Check was positive" << std::endl; - return true; - } - //std::cout << "Hadronic Decay Check was negative" << std::endl; - } - return false; - } +bool DYToTauTauGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { + iEvent.getByToken(genParticleCollection_, gen_handle); + + for (unsigned int i = 0; i < gen_handle->size(); i++) { + const reco::GenParticle gen_particle = (*gen_handle)[i]; + // Check if Z Boson decayed into two leptons + if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { + // Debug output + // std::cout << "pdgId" << gen_particle.pdgId() << std::endl; + // std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; + // std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; + // std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; + // std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; + + // Check if daugther particles are taus + if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 && std::abs(gen_particle.daughter(0)->eta()) < 2.3 && + std::abs(gen_particle.daughter(1)->eta()) < 2.3 && + ((gen_particle.daughter(0)->pt() > 30 && gen_particle.daughter(1)->pt() > 35) || + (gen_particle.daughter(0)->pt() > 35 && gen_particle.daughter(1)->pt() > 30))) { + if (!photoncheck(gen_particle.daughter(0), 1) && !photoncheck(gen_particle.daughter(1), 1)) { + // std::cout << "Hadronic Decay Check was positive" << std::endl; + return true; + } + // std::cout << "Hadronic Decay Check was negative" << std::endl; + } + return false; } - return false; + } + return false; } // ------------ method called once each stream before processing any runs, lumis or events ------------ -void -DYToTauTauGenFilter::beginStream(edm::StreamID) -{ -} +void DYToTauTauGenFilter::beginStream(edm::StreamID) {} // ------------ method called once each stream after processing all runs, lumis and events ------------ -void -DYToTauTauGenFilter::endStream() { -} +void DYToTauTauGenFilter::endStream() {} // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void -DYToTauTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters +void DYToTauTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); } - - DEFINE_FWK_MODULE(DYToTauTauGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc index 3d38f2aaf886e..16dbdfa5485a2 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc @@ -3,43 +3,45 @@ #include "DataFormats/Common/interface/SortedCollection.h" -#include "DataFormats/EcalDigi/interface/EcalSrFlag.h" -#include "DataFormats/EcalDigi/interface/EESrFlag.h" #include "DataFormats/EcalDigi/interface/EBSrFlag.h" +#include "DataFormats/EcalDigi/interface/EESrFlag.h" +#include "DataFormats/EcalDigi/interface/EcalSrFlag.h" #include "DataFormats/EcalDigi/src/EcalSrFlag.cc" #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h" -#include "DataFormats/Common/interface/RangeMap.h" #include "DataFormats/Common/interface/OwnVector.h" +#include "DataFormats/Common/interface/RangeMap.h" - -typedef DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag> EcalSrFlagColMerger; -typedef DoubleCollectionMerger HcalDigiColMerger; +typedef DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag> + EcalSrFlagColMerger; +typedef DoubleCollectionMerger + HcalDigiColMerger; // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections template -void DoubleCollectionMerger::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) -{ - assert(0); // CV: make sure general function never gets called; - // always use template specializations +void DoubleCollectionMerger::fill_output_obj( + std::unique_ptr &output, std::vector> &inputCollections) { + assert(0); // CV: make sure general function never gets called; + // always use template specializations } template -void DoubleCollectionMerger::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) -{ - assert(0); // CV: make sure general function never gets called; - // always use template specializations +void DoubleCollectionMerger::fill_output_obj( + std::unique_ptr &output, std::vector> &inputCollections) { + assert(0); // CV: make sure general function never gets called; + // always use template specializations } template -void DoubleCollectionMerger::fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections) -{ - std::map output_map; +void DoubleCollectionMerger::fill_output_obj_digiflag( + std::unique_ptr &output, std::vector> &inputCollections) { + std::map output_map; // First merge the two collections again - for (auto const & inputCollection : inputCollections){ - for ( typename MergeCollection1::const_iterator obj = inputCollection->begin(); obj!= inputCollection->end(); ++obj ) { - DetId detIdObject( obj->id().rawId() ); + for (auto const &inputCollection : inputCollections) { + for (typename MergeCollection1::const_iterator obj = inputCollection->begin(); obj != inputCollection->end(); + ++obj) { + DetId detIdObject(obj->id().rawId()); std::map::iterator it = output_map.find(detIdObject.rawId()); if (it == output_map.end()) { @@ -47,14 +49,16 @@ void DoubleCollectionMerger::fill_output_obj_digiflag(std::unique_ T2 newSrFlag(*obj); *akt_flag_obj = newSrFlag; } else { - //re-determine flag + // re-determine flag BaseHit1 preFlag = it->second; BaseHit1 *akt_flag_obj = &output_map[detIdObject.rawId()]; T2 newSrFlag(*obj); - newSrFlag.setValue(std::max(obj->value(),preFlag.value())); - if (preFlag.value() == 3 or obj->value() == 3) newSrFlag.setValue(3); - if (preFlag.value() == 7 or obj->value() == 7) newSrFlag.setValue(7); + newSrFlag.setValue(std::max(obj->value(), preFlag.value())); + if (preFlag.value() == 3 or obj->value() == 3) + newSrFlag.setValue(3); + if (preFlag.value() == 7 or obj->value() == 7) + newSrFlag.setValue(7); *akt_flag_obj = newSrFlag; } @@ -62,22 +66,25 @@ void DoubleCollectionMerger::fill_output_obj_digiflag(std::unique_ } // Now save it into the standard CMSSW format - for (typename std::map::const_iterator outFlags = output_map.begin(); outFlags != output_map.end(); ++outFlags ) { + for (typename std::map::const_iterator outFlags = output_map.begin(); + outFlags != output_map.end(); + ++outFlags) { BaseHit1 currFlag = outFlags->second; output->push_back(outFlags->second); } - output->sort(); //Do a sort for this collection + output->sort(); // Do a sort for this collection } template -void DoubleCollectionMerger::fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections) -{ - std::map output_map; +void DoubleCollectionMerger::fill_output_obj_digiflag( + std::unique_ptr &output, std::vector> &inputCollections) { + std::map output_map; // First merge the two collections again - for (auto const & inputCollection : inputCollections){ - for ( typename MergeCollection2::const_iterator obj = inputCollection->begin(); obj!= inputCollection->end(); ++obj ) { - DetId detIdObject( obj->id().rawId() ); + for (auto const &inputCollection : inputCollections) { + for (typename MergeCollection2::const_iterator obj = inputCollection->begin(); obj != inputCollection->end(); + ++obj) { + DetId detIdObject(obj->id().rawId()); std::map::iterator it = output_map.find(detIdObject.rawId()); if (it == output_map.end()) { @@ -85,14 +92,16 @@ void DoubleCollectionMerger::fill_output_obj_digiflag(std::unique_ T4 newSrFlag(*obj); *akt_flag_obj = newSrFlag; } else { - //re-determine flag + // re-determine flag BaseHit2 preFlag = it->second; BaseHit2 *akt_flag_obj = &output_map[detIdObject.rawId()]; T4 newSrFlag(*obj); - newSrFlag.setValue(std::max(obj->value(),preFlag.value())); - if (preFlag.value() == 3 or obj->value() == 3) newSrFlag.setValue(3); - if (preFlag.value() == 7 or obj->value() == 7) newSrFlag.setValue(7); + newSrFlag.setValue(std::max(obj->value(), preFlag.value())); + if (preFlag.value() == 3 or obj->value() == 3) + newSrFlag.setValue(3); + if (preFlag.value() == 7 or obj->value() == 7) + newSrFlag.setValue(7); *akt_flag_obj = newSrFlag; } @@ -100,51 +109,56 @@ void DoubleCollectionMerger::fill_output_obj_digiflag(std::unique_ } // Now save it into the standard CMSSW format - for (typename std::map::const_iterator outFlags = output_map.begin(); outFlags != output_map.end(); ++outFlags ) { + for (typename std::map::const_iterator outFlags = output_map.begin(); + outFlags != output_map.end(); + ++outFlags) { BaseHit2 currFlag = outFlags->second; output->push_back(outFlags->second); } - output->sort(); //Do a sort for this collection + output->sort(); // Do a sort for this collection } template -void DoubleCollectionMerger::fill_output_obj_hcaldigi(std::unique_ptr & output, std::vector > &inputCollections) -{ - //TODO: implement proper merging, only skeleton for the time-being +void DoubleCollectionMerger::fill_output_obj_hcaldigi( + std::unique_ptr &output, std::vector> &inputCollections) { + // TODO: implement proper merging, only skeleton for the time-being return; } template -void DoubleCollectionMerger::fill_output_obj_hcaldigi(std::unique_ptr & output, std::vector > &inputCollections) -{ - //TODO: implement proper merging, only skeleton for the time-being +void DoubleCollectionMerger::fill_output_obj_hcaldigi( + std::unique_ptr &output, std::vector> &inputCollections) { + // TODO: implement proper merging, only skeleton for the time-being return; } template <> -void DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag>::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) -{ - fill_output_obj_digiflag(output,inputCollections); +void DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag>:: + fill_output_obj(std::unique_ptr &output, + std::vector> &inputCollections) { + fill_output_obj_digiflag(output, inputCollections); } template <> -void DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag>::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) -{ - fill_output_obj_digiflag(output,inputCollections); +void DoubleCollectionMerger, EESrFlag, edm::SortedCollection, EBSrFlag>:: + fill_output_obj(std::unique_ptr &output, + std::vector> &inputCollections) { + fill_output_obj_digiflag(output, inputCollections); } template <> -void DoubleCollectionMerger::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) -{ - fill_output_obj_hcaldigi(output,inputCollections); +void DoubleCollectionMerger:: + fill_output_obj(std::unique_ptr &output, + std::vector> &inputCollections) { + fill_output_obj_hcaldigi(output, inputCollections); } template <> -void DoubleCollectionMerger::fill_output_obj(std::unique_ptr & output, std::vector > &inputCollections) -{ - fill_output_obj_hcaldigi(output,inputCollections); +void DoubleCollectionMerger:: + fill_output_obj(std::unique_ptr &output, + std::vector> &inputCollections) { + fill_output_obj_hcaldigi(output, inputCollections); } - DEFINE_FWK_MODULE(EcalSrFlagColMerger); DEFINE_FWK_MODULE(HcalDigiColMerger); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h index e3aa2a01939fb..e74d50fbe232f 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h @@ -1,118 +1,113 @@ /** \class DoubleCollectionMerger * - * + * * \author Per Ahrens * - * * - * + * + * * */ #ifndef TauAnalysis_MCEmbeddingTools_DoubleCollectionMerger_H #define TauAnalysis_MCEmbeddingTools_DoubleCollectionMerger_H -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "DataFormats/Common/interface/Handle.h" +#include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "DataFormats/Common/interface/SortedCollection.h" #include "DataFormats/Common/interface/DetSetVectorNew.h" +#include "DataFormats/Common/interface/SortedCollection.h" - -//#include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h" -#include +// #include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h" #include #include - - +#include template -class DoubleCollectionMerger : public edm::stream::EDProducer<> -{ - public: - explicit DoubleCollectionMerger(const edm::ParameterSet&); +class DoubleCollectionMerger : public edm::stream::EDProducer<> { +public: + explicit DoubleCollectionMerger(const edm::ParameterSet &); ~DoubleCollectionMerger(); - private: - void produce(edm::Event&, const edm::EventSetup&) override; +private: + void produce(edm::Event &, const edm::EventSetup &) override; typedef T1 MergeCollection1; typedef T2 BaseHit1; typedef T3 MergeCollection2; typedef T4 BaseHit2; - std::map > > inputs1_; - std::map > > inputs2_; - - void fill_output_obj(std::unique_ptr & output1, std::vector > &inputCollections1); - void fill_output_obj(std::unique_ptr & output2, std::vector > &inputCollections2); - void fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections); - void fill_output_obj_digiflag(std::unique_ptr & output, std::vector > &inputCollections); - void fill_output_obj_hcaldigi(std::unique_ptr & output, std::vector > &inputCollections); - void fill_output_obj_hcaldigi(std::unique_ptr & output, std::vector > &inputCollections); - + std::map>> inputs1_; + std::map>> inputs2_; + + void fill_output_obj(std::unique_ptr &output1, + std::vector> &inputCollections1); + void fill_output_obj(std::unique_ptr &output2, + std::vector> &inputCollections2); + void fill_output_obj_digiflag(std::unique_ptr &output, + std::vector> &inputCollections); + void fill_output_obj_digiflag(std::unique_ptr &output, + std::vector> &inputCollections); + void fill_output_obj_hcaldigi(std::unique_ptr &output, + std::vector> &inputCollections); + void fill_output_obj_hcaldigi(std::unique_ptr &output, + std::vector> &inputCollections); }; template -DoubleCollectionMerger::DoubleCollectionMerger(const edm::ParameterSet& iConfig) -{ - std::vector inCollections = iConfig.getParameter >("mergCollections"); - for (auto const & inCollection : inCollections){ - inputs1_[inCollection.instance()].push_back(consumes(inCollection)); - inputs2_[inCollection.instance()].push_back(consumes(inCollection)); +DoubleCollectionMerger::DoubleCollectionMerger(const edm::ParameterSet &iConfig) { + std::vector inCollections = iConfig.getParameter>("mergCollections"); + for (auto const &inCollection : inCollections) { + inputs1_[inCollection.instance()].push_back(consumes(inCollection)); + inputs2_[inCollection.instance()].push_back(consumes(inCollection)); } - for (auto toproduce : inputs1_){ - //std::cout<(toproduce.first); } - for (auto toproduce : inputs2_){ - //std::cout<(toproduce.first); } } - template -DoubleCollectionMerger::~DoubleCollectionMerger() -{ -// nothing to be done yet... +DoubleCollectionMerger::~DoubleCollectionMerger() { + // nothing to be done yet... } - template -void DoubleCollectionMerger::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) -{ - //std::cout << "DoubleCollectionMerger::produce" << std::endl; - for (auto input_ : inputs1_){ - //std::cout << "input_.first()=" << input_.first << std::endl; - //std::cout << "input_.second.size()=" << input_.second.size() << std::endl; - std::unique_ptr output(new MergeCollection1()); - std::vector > inputCollections; +void DoubleCollectionMerger::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + // std::cout << "DoubleCollectionMerger::produce" << std::endl; + for (auto input_ : inputs1_) { + // std::cout << "input_.first()=" << input_.first << std::endl; + // std::cout << "input_.second.size()=" << input_.second.size() << std::endl; + std::unique_ptr output(new MergeCollection1()); + std::vector> inputCollections; inputCollections.resize(input_.second.size()); - for (unsigned id = 0; id("src"); consumes(beamSpotInput_); produces(); - -} +} EmbeddingBeamSpotOnlineProducer::~EmbeddingBeamSpotOnlineProducer() {} -void -EmbeddingBeamSpotOnlineProducer::produce(Event& iEvent, const EventSetup& iSetup) -{ - //copy beam spot from input data into HLT simulation sequence +void EmbeddingBeamSpotOnlineProducer::produce(Event &iEvent, const EventSetup &iSetup) { + // copy beam spot from input data into HLT simulation sequence edm::Handle beamSpotH; - iEvent.getByLabel(beamSpotInput_,beamSpotH); + iEvent.getByLabel(beamSpotInput_, beamSpotH); auto result = std::make_unique(); *result = *beamSpotH; iEvent.put(std::move(result)); - } DEFINE_FWK_MODULE(EmbeddingBeamSpotOnlineProducer); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.h b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.h index f8a2b37937b64..13672b8b5a273 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingBeamSpotOnlineProducer.h @@ -8,19 +8,18 @@ ________________________________________________________________**/ #include "FWCore/Framework/interface/stream/EDProducer.h" -class EmbeddingBeamSpotOnlineProducer: public edm::stream::EDProducer<> { +class EmbeddingBeamSpotOnlineProducer : public edm::stream::EDProducer<> { +public: + /// constructor + explicit EmbeddingBeamSpotOnlineProducer(const edm::ParameterSet &iConf); + /// destructor + ~EmbeddingBeamSpotOnlineProducer() override; - public: - /// constructor - explicit EmbeddingBeamSpotOnlineProducer(const edm::ParameterSet& iConf); - /// destructor - ~EmbeddingBeamSpotOnlineProducer() override; - - /// produce a beam spot class - void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override; + /// produce a beam spot class + void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override; - private: - edm::InputTag beamSpotInput_; +private: + edm::InputTag beamSpotInput_; }; #endif diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc index 3e38131d40e3e..213610e150682 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc @@ -2,7 +2,7 @@ // // Package: tautrigger/EmbeddingHltPixelVerticesProducer // Class: EmbeddingHltPixelVerticesProducer -// +// /**\class EmbeddingHltPixelVerticesProducer EmbeddingHltPixelVerticesProducer.cc tautrigger/EmbeddingHltPixelVerticesProducer/plugins/EmbeddingHltPixelVerticesProducer.cc Description: [one line class summary] @@ -16,7 +16,6 @@ // // - // system include files #include @@ -30,38 +29,36 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Utilities/interface/StreamID.h" +#include "DataFormats/Math/interface/Error.h" +#include "DataFormats/Math/interface/Point3D.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" -#include "DataFormats/Math/interface/Point3D.h" -#include "DataFormats/Math/interface/Error.h" -#include "DataFormats/TrackReco/interface/TrackBase.h" #include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackBase.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" #include "DataFormats/Common/interface/RefToBase.h" class EmbeddingHltPixelVerticesProducer : public edm::stream::EDProducer<> { - public: - explicit EmbeddingHltPixelVerticesProducer(const edm::ParameterSet&); - ~EmbeddingHltPixelVerticesProducer(); +public: + explicit EmbeddingHltPixelVerticesProducer(const edm::ParameterSet &); + ~EmbeddingHltPixelVerticesProducer(); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - private: - virtual void beginStream(edm::StreamID) override; - virtual void produce(edm::Event&, const edm::EventSetup&) override; - virtual void endStream() override; - edm::InputTag vertexPositionLabel; - //edm::InputTag generalTracks; +private: + virtual void beginStream(edm::StreamID) override; + virtual void produce(edm::Event &, const edm::EventSetup &) override; + virtual void endStream() override; + edm::InputTag vertexPositionLabel; + // edm::InputTag generalTracks; - // ----------member data --------------------------- + // ----------member data --------------------------- }; -EmbeddingHltPixelVerticesProducer::EmbeddingHltPixelVerticesProducer(const edm::ParameterSet& iConfig) -{ - - vertexPositionLabel = edm::InputTag("externalLHEProducer","vertexPosition"); +EmbeddingHltPixelVerticesProducer::EmbeddingHltPixelVerticesProducer(const edm::ParameterSet &iConfig) { + vertexPositionLabel = edm::InputTag("externalLHEProducer", "vertexPosition"); consumes(vertexPositionLabel); produces(); @@ -70,71 +67,62 @@ EmbeddingHltPixelVerticesProducer::EmbeddingHltPixelVerticesProducer(const edm:: // consumes(generalTracks); } - -EmbeddingHltPixelVerticesProducer::~EmbeddingHltPixelVerticesProducer() -{} - +EmbeddingHltPixelVerticesProducer::~EmbeddingHltPixelVerticesProducer() {} // ------------ method called to produce the data ------------ -void -EmbeddingHltPixelVerticesProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) -{ - using namespace edm; - std::unique_ptr embeddingVertex(new reco::VertexCollection); - Handle vertex_position; - iEvent.getByLabel(vertexPositionLabel, vertex_position); +void EmbeddingHltPixelVerticesProducer::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + using namespace edm; + std::unique_ptr embeddingVertex(new reco::VertexCollection); + Handle vertex_position; + iEvent.getByLabel(vertexPositionLabel, vertex_position); // edm::LogPrint("") << "externalLHEProducer Vertex (" << vertex_position.product()->x() << "," << vertex_position.product()->y() << "," << vertex_position.product()->z() << ")"; - math::XYZPoint genVertex = math::XYZPoint(vertex_position.product()->x(),vertex_position.product()->y(),vertex_position.product()->z()); - math::Error<3>::type Error; - // additionally, get the general Tracks: - // edm::Handle tks; - // iEvent.getByLabel(generalTracks, tks); - // edm::LogPrint("") << "Loaded " << tks->size() << " tracks:"; - - // edm::Handle tks_ref; - // iEvent.getByLabel(generalTracks, tks_ref); - // std::vector > tks_base_; - // tks_base_.push_back(edm::RefToBase(tks_ref)); - //reco::Vertex saveVertex = reco::Vertex(genVertex, Error); - // Try to produce an nonfake Vertex - // constructor for a valid vertex, with all data - //Vertex( const Point &, const Error &, double chi2, double ndof, size_t size ); - // Need at least 5 ndof so the vertex Quality is considered good - reco::Vertex saveVertex = reco::Vertex(genVertex, Error,1.0,6.0,6); - - //for (auto track: *tks) - //{ - //edm::LogPrint("") << track.vertex(); - //saveVertex.add(track, 0.5); - //} - //if (saveVertex.isFake()) edm::LogPrint("") << " The produced Vertex is fake"; - //else edm::LogPrint("") << " The produced Vertex is not fake"; - //edm::LogPrint("") << "Vertex Properties: " << saveVertex.isFake() << " / " << saveVertex.ndof() << " / " << abs(saveVertex.z()) << " / " << abs(saveVertex.position().Rho()); - //if (!saveVertex.isFake() && saveVertex.ndof() >= 4.0 && abs(saveVertex.z()) <= 24.0 && abs(saveVertex.position().Rho()) <= 2.0) - // edm::LogPrint("") << "The Vertex is a goodOfflineVertex"; - embeddingVertex->push_back(saveVertex); - // iEvent.put(std::move(embeddingVertex), "embeddingVertex"); - iEvent.put(std::move(embeddingVertex)); - + math::XYZPoint genVertex = + math::XYZPoint(vertex_position.product()->x(), vertex_position.product()->y(), vertex_position.product()->z()); + math::Error<3>::type Error; + // additionally, get the general Tracks: + // edm::Handle tks; + // iEvent.getByLabel(generalTracks, tks); + // edm::LogPrint("") << "Loaded " << tks->size() << " tracks:"; + + // edm::Handle tks_ref; + // iEvent.getByLabel(generalTracks, tks_ref); + // std::vector > tks_base_; + // tks_base_.push_back(edm::RefToBase(tks_ref)); + // reco::Vertex saveVertex = reco::Vertex(genVertex, Error); + // Try to produce an nonfake Vertex + // constructor for a valid vertex, with all data + // Vertex( const Point &, const Error &, double chi2, double ndof, size_t size ); + // Need at least 5 ndof so the vertex Quality is considered good + reco::Vertex saveVertex = reco::Vertex(genVertex, Error, 1.0, 6.0, 6); + + // for (auto track: *tks) + //{ + // edm::LogPrint("") << track.vertex(); + // saveVertex.add(track, 0.5); + //} + // if (saveVertex.isFake()) edm::LogPrint("") << " The produced Vertex is fake"; + // else edm::LogPrint("") << " The produced Vertex is not fake"; + // edm::LogPrint("") << "Vertex Properties: " << saveVertex.isFake() << " / " << saveVertex.ndof() << " / " << abs(saveVertex.z()) << " / " << abs(saveVertex.position().Rho()); + // if (!saveVertex.isFake() && saveVertex.ndof() >= 4.0 && abs(saveVertex.z()) <= 24.0 && abs(saveVertex.position().Rho()) <= 2.0) + // edm::LogPrint("") << "The Vertex is a goodOfflineVertex"; + embeddingVertex->push_back(saveVertex); + // iEvent.put(std::move(embeddingVertex), "embeddingVertex"); + iEvent.put(std::move(embeddingVertex)); } // ------------ method called once each stream before processing any runs, lumis or events ------------ -void EmbeddingHltPixelVerticesProducer::beginStream(edm::StreamID) -{ -} +void EmbeddingHltPixelVerticesProducer::beginStream(edm::StreamID) {} // ------------ method called once each stream after processing all runs, lumis and events ------------ -void EmbeddingHltPixelVerticesProducer::endStream() { -} - +void EmbeddingHltPixelVerticesProducer::endStream() {} -void EmbeddingHltPixelVerticesProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters +void EmbeddingHltPixelVerticesProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); } -//define this as a plug-in +// define this as a plug-in DEFINE_FWK_MODULE(EmbeddingHltPixelVerticesProducer); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc index ec4a9a3229797..526aeee4bf22f 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc @@ -17,44 +17,44 @@ // // system include files +#include "TLorentzVector.h" #include +#include #include #include -#include -#include #include -#include "TLorentzVector.h" +#include // user include files #include "FWCore/Framework/interface/Frameworkfwd.h" #include "FWCore/Framework/interface/one/EDProducer.h" #include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/Run.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/Run.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "DataFormats/Math/interface/LorentzVector.h" +#include "DataFormats/PatCandidates/interface/Muon.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" -#include "DataFormats/PatCandidates/interface/Muon.h" -#include "DataFormats/Math/interface/LorentzVector.h" -#include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" #include "SimDataFormats/GeneratorProducts/interface/LHECommonBlocks.h" -#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h" #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h" +#include "SimDataFormats/GeneratorProducts/interface/LesHouches.h" -#include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" #include "GeneratorInterface/LHEInterface/interface/LHEReader.h" +#include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" +#include "CLHEP/Random/RandExponential.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Utilities/interface/RandomNumberGenerator.h" #include "FWCore/Utilities/interface/StreamID.h" -#include "CLHEP/Random/RandExponential.h" // // class declaration @@ -97,7 +97,7 @@ class EmbeddingLHEProducer : public edm::one::EDProducer> muonsCollection_; edm::EDGetTokenT vertexCollection_; int particleToEmbed_; - bool mirror_, rotate180_,InitialRecoCorrection_; + bool mirror_, rotate180_, InitialRecoCorrection_; const double tauMass_ = 1.77682; const double muonMass_ = 0.1057; const double elMass_ = 0.00051; @@ -116,7 +116,7 @@ class EmbeddingLHEProducer : public edm::one::EDProducer(); produces(); produces("vertexPosition"); @@ -136,7 +136,7 @@ EmbeddingLHEProducer::EmbeddingLHEProducer(const edm::ParameterSet &iConfig) { file.open(lhe_ouputfile, std::fstream::out | std::fstream::trunc); } - //check if particle can be embedded + // check if particle can be embedded if (std::find(std::begin(embeddingParticles), std::end(embeddingParticles), particleToEmbed_) == std::end(embeddingParticles)) { throw cms::Exception("Configuration") << "The given particle to embed is not in the list of allowed particles."; @@ -191,7 +191,9 @@ void EmbeddingLHEProducer::produce(edm::Event &iEvent, const edm::EventSetup &iS } else if (mu_minus_found && mu_plus_found) break; } - InitialRecoCorrection(positiveLepton,negativeLepton); //corrects Z mass peak to take into account smearing happening due to first muon reconstruction in the selection step + InitialRecoCorrection( + positiveLepton, + negativeLepton); // corrects Z mass peak to take into account smearing happening due to first muon reconstruction in the selection step mirror(positiveLepton, negativeLepton); // if no mirror, function does nothing. rotate180(positiveLepton, negativeLepton); // if no rotate180, function does nothing transform_mumu_to_tautau(positiveLepton, negativeLepton); // if MuonEmbedding, function does nothing. @@ -225,28 +227,28 @@ void EmbeddingLHEProducer::beginRunProduce(edm::Run &run, edm::EventSetup const // set number of processes: 1 for Z to tau tau heprup.resize(1); - //Process independent information + // Process independent information - //beam particles ID (two protons) - //heprup.IDBMUP.first = 2212; - //heprup.IDBMUP.second = 2212; + // beam particles ID (two protons) + // heprup.IDBMUP.first = 2212; + // heprup.IDBMUP.second = 2212; - //beam particles energies (both 6.5 GeV) - //heprup.EBMUP.first = 6500.; - //heprup.EBMUP.second = 6500.; + // beam particles energies (both 6.5 GeV) + // heprup.EBMUP.first = 6500.; + // heprup.EBMUP.second = 6500.; - //take default pdf group for both beamparticles - //heprup.PDFGUP.first = -1; - //heprup.PDFGUP.second = -1; + // take default pdf group for both beamparticles + // heprup.PDFGUP.first = -1; + // heprup.PDFGUP.second = -1; - //take certan pdf set ID (same as in officially produced DYJets LHE files) - //heprup.PDFSUP.first = -1; - //heprup.PDFSUP.second = -1; + // take certan pdf set ID (same as in officially produced DYJets LHE files) + // heprup.PDFSUP.first = -1; + // heprup.PDFSUP.second = -1; - //master switch for event weight iterpretation (same as in officially produced DYJets LHE files) + // master switch for event weight iterpretation (same as in officially produced DYJets LHE files) heprup.IDWTUP = 3; - //Information for first process (Z to tau tau), for now only placeholder: + // Information for first process (Z to tau tau), for now only placeholder: heprup.XSECUP[0] = 1.; heprup.XERRUP[0] = 0; heprup.XMAXUP[0] = 1; @@ -280,7 +282,7 @@ void EmbeddingLHEProducer::fill_lhe_from_mumu(TLorentzVector &positiveLepton, tau_ctau0 * CLHEP::RandExponential::shoot(engine); // return -std::log(HepRandom::getTheEngine()->flat()); // replaces tau = process[iNow].tau0() * rndmPtr->exp(); from pythia8212/src/ProcessContainer.cc which is not initialized for ProcessLevel:all = off mode (no beam particle mode) double tau_ctau_n = tau_ctau0 * CLHEP::RandExponential::shoot(engine); - //std::cout<<"tau_ctau P: "<60.&&diLeptonMass<122.) { - //std::cout << "DiLeptonMass " << diLeptonMass << std::endl; - float zmass=91.1876; - float correction_deviation=5.; // to ensure only a correction that drops corresponding to a Gaussian with mean zmass and std. dev. 5 GeV - double EmbeddingCorrection = 1.138; // value derived by function fitting to fold embedded mass spectrum back to original selection when using mu -> mu embedding - EmbeddingCorrection=EmbeddingCorrection/(EmbeddingCorrection-(EmbeddingCorrection-1.)*exp(-pow((diLeptonMass-zmass),2.)/(2.*pow(correction_deviation,2.)))); - EmbeddingCorrection=((diLeptonMass + (EmbeddingCorrection - 1.)*zmass)/(diLeptonMass*EmbeddingCorrection)); - double correctedpositiveLeptonEnergy=std::sqrt(muonMass_*muonMass_+EmbeddingCorrection*positiveLepton.Px()*EmbeddingCorrection*positiveLepton.Px()+EmbeddingCorrection*positiveLepton.Py()*EmbeddingCorrection*positiveLepton.Py()+EmbeddingCorrection*positiveLepton.Pz()*EmbeddingCorrection*positiveLepton.Pz()); - double correctednegativeLeptonEnergy=std::sqrt(muonMass_*muonMass_+EmbeddingCorrection*negativeLepton.Px()*EmbeddingCorrection*negativeLepton.Px()+EmbeddingCorrection*negativeLepton.Py()*EmbeddingCorrection*negativeLepton.Py()+EmbeddingCorrection*negativeLepton.Pz()*EmbeddingCorrection*negativeLepton.Pz()); - positiveLepton.SetPxPyPzE(EmbeddingCorrection*positiveLepton.Px(),EmbeddingCorrection*positiveLepton.Py(),EmbeddingCorrection*positiveLepton.Pz(),correctedpositiveLeptonEnergy); - negativeLepton.SetPxPyPzE(EmbeddingCorrection*negativeLepton.Px(),EmbeddingCorrection*negativeLepton.Py(),EmbeddingCorrection*negativeLepton.Pz(),correctednegativeLeptonEnergy); - - edm::LogInfo("TauEmbedding") << "MuMinus after. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M() ; - //std::cout << " MuMinus after. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M() << " Energy: " << negativeLepton.E() << std::endl; + edm::LogInfo("TauEmbedding") << "MuMinus before. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M(); + // std::cout << " MuMinus before. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M() << " Energy: " << negativeLepton.E() << std::endl; + float diLeptonMass = (positiveLepton + negativeLepton).M(); + if (diLeptonMass > 60. && diLeptonMass < 122.) { + // std::cout << "DiLeptonMass " << diLeptonMass << std::endl; + float zmass = 91.1876; + float correction_deviation = + 5.; // to ensure only a correction that drops corresponding to a Gaussian with mean zmass and std. dev. 5 GeV + double EmbeddingCorrection = + 1.138; // value derived by function fitting to fold embedded mass spectrum back to original selection when using mu -> mu embedding + EmbeddingCorrection = + EmbeddingCorrection / + (EmbeddingCorrection - + (EmbeddingCorrection - 1.) * exp(-pow((diLeptonMass - zmass), 2.) / (2. * pow(correction_deviation, 2.)))); + EmbeddingCorrection = ((diLeptonMass + (EmbeddingCorrection - 1.) * zmass) / (diLeptonMass * EmbeddingCorrection)); + double correctedpositiveLeptonEnergy = std::sqrt( + muonMass_ * muonMass_ + EmbeddingCorrection * positiveLepton.Px() * EmbeddingCorrection * positiveLepton.Px() + + EmbeddingCorrection * positiveLepton.Py() * EmbeddingCorrection * positiveLepton.Py() + + EmbeddingCorrection * positiveLepton.Pz() * EmbeddingCorrection * positiveLepton.Pz()); + double correctednegativeLeptonEnergy = std::sqrt( + muonMass_ * muonMass_ + EmbeddingCorrection * negativeLepton.Px() * EmbeddingCorrection * negativeLepton.Px() + + EmbeddingCorrection * negativeLepton.Py() * EmbeddingCorrection * negativeLepton.Py() + + EmbeddingCorrection * negativeLepton.Pz() * EmbeddingCorrection * negativeLepton.Pz()); + positiveLepton.SetPxPyPzE(EmbeddingCorrection * positiveLepton.Px(), + EmbeddingCorrection * positiveLepton.Py(), + EmbeddingCorrection * positiveLepton.Pz(), + correctedpositiveLeptonEnergy); + negativeLepton.SetPxPyPzE(EmbeddingCorrection * negativeLepton.Px(), + EmbeddingCorrection * negativeLepton.Py(), + EmbeddingCorrection * negativeLepton.Pz(), + correctednegativeLeptonEnergy); + + edm::LogInfo("TauEmbedding") << "MuMinus after. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M(); + // std::cout << " MuMinus after. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M() << " Energy: " << negativeLepton.E() << std::endl; } return; } @@ -580,12 +599,12 @@ LHERunInfoProduct::Header EmbeddingLHEProducer::give_slha() { // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ void EmbeddingLHEProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); } -//define this as a plug-in +// define this as a plug-in DEFINE_FWK_MODULE(EmbeddingLHEProducer); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingVertexCorrector.cc b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingVertexCorrector.cc index dae640883fe88..c70f5939a4d77 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingVertexCorrector.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingVertexCorrector.cc @@ -29,8 +29,8 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Utilities/interface/StreamID.h" -#include "CLHEP/Units/GlobalSystemOfUnits.h" #include "CLHEP/Units/GlobalPhysicalConstants.h" +#include "CLHEP/Units/GlobalSystemOfUnits.h" #include "DataFormats/Math/interface/LorentzVector.h" #include "DataFormats/Math/interface/LorentzVectorFwd.h" @@ -38,10 +38,10 @@ #include "DataFormats/VertexReco/interface/VertexFwd.h" #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" -#include "CondFormats/DataRecord/interface/SimBeamSpotObjectsRcd.h" +#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h" #include "CondFormats/BeamSpotObjects/interface/SimBeamSpotObjects.h" #include "CondFormats/DataRecord/interface/BeamSpotObjectsRcd.h" -#include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h" +#include "CondFormats/DataRecord/interface/SimBeamSpotObjectsRcd.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" @@ -56,13 +56,13 @@ namespace HepMC { class EmbeddingVertexCorrector : public edm::stream::EDProducer<> { public: - explicit EmbeddingVertexCorrector(const edm::ParameterSet&); + explicit EmbeddingVertexCorrector(const edm::ParameterSet &); ~EmbeddingVertexCorrector() override; - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); private: - void produce(edm::Event&, const edm::EventSetup&) override; + void produce(edm::Event &, const edm::EventSetup &) override; // ----------member data --------------------------- edm::InputTag sourceLabel; @@ -72,7 +72,7 @@ class EmbeddingVertexCorrector : public edm::stream::EDProducer<> { // // constructors and destructor // -EmbeddingVertexCorrector::EmbeddingVertexCorrector(const edm::ParameterSet& iConfig) { +EmbeddingVertexCorrector::EmbeddingVertexCorrector(const edm::ParameterSet &iConfig) { produces(); sourceLabel = iConfig.getParameter("src"); @@ -88,16 +88,16 @@ EmbeddingVertexCorrector::~EmbeddingVertexCorrector() {} // // ------------ method called to produce the data ------------ -void EmbeddingVertexCorrector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { +void EmbeddingVertexCorrector::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { using namespace edm; // Retrieving generated Z to TauTau Event Handle InputGenEvent; iEvent.getByLabel(sourceLabel, InputGenEvent); - HepMC::GenEvent* genevent = new HepMC::GenEvent(*InputGenEvent->GetEvent()); + HepMC::GenEvent *genevent = new HepMC::GenEvent(*InputGenEvent->GetEvent()); std::unique_ptr CorrectedGenEvent(new edm::HepMCProduct(genevent)); - //Retrieving vertex position from input and creating vertex shift + // Retrieving vertex position from input and creating vertex shift Handle vertex_position; iEvent.getByLabel(vertexPositionLabel, vertex_position); HepMC::FourVector vertex_shift( @@ -109,13 +109,13 @@ void EmbeddingVertexCorrector::produce(edm::Event& iEvent, const edm::EventSetup } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void EmbeddingVertexCorrector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters +void EmbeddingVertexCorrector::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); } -//define this as a plug-in +// define this as a plug-in DEFINE_FWK_MODULE(EmbeddingVertexCorrector); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc b/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc index d3e38c4d16f67..1d0f39215697a 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc @@ -32,12 +32,12 @@ #include "DataFormats/Candidate/interface/CompositeCandidate.h" #include "DataFormats/PatCandidates/interface/Muon.h" +#include "DataFormats/BeamSpot/interface/BeamSpot.h" #include "DataFormats/VertexReco/interface/Vertex.h" #include "DataFormats/VertexReco/interface/VertexFwd.h" -#include "DataFormats/BeamSpot/interface/BeamSpot.h" -#include "DataFormats/PatCandidates/interface/MET.h" #include "DataFormats/METReco/interface/MET.h" +#include "DataFormats/PatCandidates/interface/MET.h" // // class declaration @@ -47,7 +47,7 @@ class MuMuForEmbeddingSelector : public edm::stream::EDProducer<> { public: explicit MuMuForEmbeddingSelector(const edm::ParameterSet&); - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); private: void produce(edm::Event&, const edm::EventSetup&) override; @@ -73,7 +73,7 @@ class MuMuForEmbeddingSelector : public edm::stream::EDProducer<> { // // constructors and destructor // -MuMuForEmbeddingSelector::MuMuForEmbeddingSelector(const edm::ParameterSet& iConfig) +MuMuForEmbeddingSelector::MuMuForEmbeddingSelector(const edm::ParameterSet &iConfig) : ZmumuCandidates_(consumes>( iConfig.getParameter("ZmumuCandidatesCollection"))) { use_zmass = iConfig.getParameter("use_zmass"); @@ -91,9 +91,9 @@ MuMuForEmbeddingSelector::MuMuForEmbeddingSelector(const edm::ParameterSet& iCon produces("initialPuppiMETphi"); theVertexLabel_ = consumes(iConfig.getParameter("inputTagVertex")); theBeamSpotLabel_ = consumes(iConfig.getParameter("inputTagBeamSpot")); - theMETLabel_ = consumes< edm::View >(iConfig.getParameter("Met")); - thePuppiMETLabel_ = consumes< edm::View >(iConfig.getParameter("PuppiMet")); - //now do what ever other initialization is needed + theMETLabel_ = consumes>(iConfig.getParameter("Met")); + thePuppiMETLabel_ = consumes>(iConfig.getParameter("PuppiMet")); + // now do what ever other initialization is needed } // @@ -101,22 +101,22 @@ MuMuForEmbeddingSelector::MuMuForEmbeddingSelector(const edm::ParameterSet& iCon // // ------------ method called to produce the data ------------ -void MuMuForEmbeddingSelector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { +void MuMuForEmbeddingSelector::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { using namespace edm; edm::Handle> ZmumuCandidatesHandle; iEvent.getByToken(ZmumuCandidates_, ZmumuCandidatesHandle); edm::View ZmumuCandidates = *ZmumuCandidatesHandle; - const reco::CompositeCandidate* chosenZCand = nullptr; - const reco::CompositeCandidate* chosenZCand_zmass = nullptr; - const reco::CompositeCandidate* chosenZCand_largest = nullptr; + const reco::CompositeCandidate *chosenZCand = nullptr; + const reco::CompositeCandidate *chosenZCand_zmass = nullptr; + const reco::CompositeCandidate *chosenZCand_largest = nullptr; double massDifference = -1.0; edm::Handle beamSpot; iEvent.getByToken(theBeamSpotLabel_, beamSpot); edm::Handle vertex; iEvent.getByToken(theVertexLabel_, vertex); - edm::Handle > met; + edm::Handle> met; iEvent.getByToken(theMETLabel_, met); - edm::Handle > puppimet; + edm::Handle> puppimet; iEvent.getByToken(thePuppiMETLabel_, puppimet); // get primary vertex reco::Vertex::Point posVtx; @@ -125,14 +125,13 @@ void MuMuForEmbeddingSelector::produce(edm::Event& iEvent, const edm::EventSetup std::vector::const_iterator vertexEnd = vertex->end(); for (; vertexIt != vertexEnd; ++vertexIt) { if (vertexIt->isValid() && !vertexIt->isFake()) { - posVtx = vertexIt->position(); - errVtx = vertexIt->error(); - break; + posVtx = vertexIt->position(); + errVtx = vertexIt->error(); + break; } } reco::Vertex primaryVertex(posVtx, errVtx); - for (edm::View::const_iterator iZCand = ZmumuCandidates.begin(); iZCand != ZmumuCandidates.end(); ++iZCand) { @@ -141,25 +140,21 @@ void MuMuForEmbeddingSelector::produce(edm::Event& iEvent, const edm::EventSetup chosenZCand_zmass = &(*iZCand); } } - for (edm::View::const_iterator iZCand = ZmumuCandidates.begin(); iZCand != ZmumuCandidates.end(); ++iZCand) - { - if (chosenZCand_largest == nullptr) - { + for (edm::View::const_iterator iZCand = ZmumuCandidates.begin(); + iZCand != ZmumuCandidates.end(); + ++iZCand) { + if (chosenZCand_largest == nullptr) { chosenZCand_largest = &(*iZCand); - } - else - { - if (iZCand->mass() > chosenZCand_largest->mass()) - { + } else { + if (iZCand->mass() > chosenZCand_largest->mass()) { chosenZCand_largest = &(*iZCand); } } } - if(use_zmass){ + if (use_zmass) { // edm::LogDebug("MuMuForEmbeddingSelector") << "Using Z mass candidate" << chosenZCand_zmass->mass(); chosenZCand = chosenZCand_zmass; - } - else { + } else { // edm::LogDebug("MuMuForEmbeddingSelector") << "Using largest mass candidate" << chosenZCand_largest->mass(); chosenZCand = chosenZCand_largest; } @@ -172,10 +167,16 @@ void MuMuForEmbeddingSelector::produce(edm::Event& iEvent, const edm::EventSetup iEvent.put(std::make_unique(chosenZCand_zmass->mass()), "oldMass"); iEvent.put(std::make_unique(chosenZCand_largest->mass()), "newMass"); iEvent.put(std::make_unique(ZmumuCandidates.size()), "nPairCandidates"); - iEvent.put(std::make_unique(chosenZCand->daughter(0)->masterClone().castTo()->isMediumMuon()), "isMediumLeadingMuon"); - iEvent.put(std::make_unique(chosenZCand->daughter(0)->masterClone().castTo()->isTightMuon(primaryVertex)), "isTightLeadingMuon"); - iEvent.put(std::make_unique(chosenZCand->daughter(1)->masterClone().castTo()->isMediumMuon()), "isMediumTrailingMuon"); - iEvent.put(std::make_unique(chosenZCand->daughter(1)->masterClone().castTo()->isTightMuon(primaryVertex)), "isTightTrailingMuon"); + iEvent.put(std::make_unique(chosenZCand->daughter(0)->masterClone().castTo()->isMediumMuon()), + "isMediumLeadingMuon"); + iEvent.put(std::make_unique( + chosenZCand->daughter(0)->masterClone().castTo()->isTightMuon(primaryVertex)), + "isTightLeadingMuon"); + iEvent.put(std::make_unique(chosenZCand->daughter(1)->masterClone().castTo()->isMediumMuon()), + "isMediumTrailingMuon"); + iEvent.put(std::make_unique( + chosenZCand->daughter(1)->masterClone().castTo()->isTightMuon(primaryVertex)), + "isTightTrailingMuon"); iEvent.put(std::make_unique(met->at(0).et()), "initialMETEt"); iEvent.put(std::make_unique(met->at(0).phi()), "initialMETphi"); iEvent.put(std::make_unique(puppimet->at(0).et()), "initialPuppiMETEt"); @@ -185,13 +186,13 @@ void MuMuForEmbeddingSelector::produce(edm::Event& iEvent, const edm::EventSetup } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void MuMuForEmbeddingSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters +void MuMuForEmbeddingSelector::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { + // The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); } -//define this as a plug-in +// define this as a plug-in DEFINE_FWK_MODULE(MuMuForEmbeddingSelector); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc index 14166c081ae3d..641bec5d8676c 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc @@ -1,11 +1,11 @@ #include "TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h" -#include "DataFormats/MuonDetId/interface/DTLayerId.h" -#include "DataFormats/DTRecHit/interface/DTSLRecCluster.h" #include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h" +#include "DataFormats/DTRecHit/interface/DTSLRecCluster.h" +#include "DataFormats/MuonDetId/interface/DTLayerId.h" -#include "DataFormats/MuonDetId/interface/CSCDetId.h" #include "DataFormats/CSCRecHit/interface/CSCRecHit2D.h" +#include "DataFormats/MuonDetId/interface/CSCDetId.h" #include "DataFormats/MuonDetId/interface/RPCDetId.h" #include "DataFormats/RPCRecHit/interface/RPCRecHit.h" @@ -20,23 +20,23 @@ typedef MuonDetCleaner RPCRecHitColCleaner; //------------------------------------------------------------------------------- template -uint32_t MuonDetCleaner::getRawDetId(const T2& recHit) { +uint32_t MuonDetCleaner::getRawDetId(const T2 &recHit) { assert(0); // CV: make sure general function never gets called; // always use template specializations } template <> -uint32_t MuonDetCleaner::getRawDetId(const CSCRecHit2D& recHit) { +uint32_t MuonDetCleaner::getRawDetId(const CSCRecHit2D &recHit) { return recHit.cscDetId().rawId(); } template <> -uint32_t MuonDetCleaner::getRawDetId(const DTRecHit1DPair& recHit) { +uint32_t MuonDetCleaner::getRawDetId(const DTRecHit1DPair &recHit) { return recHit.geographicalId().rawId(); } template <> -uint32_t MuonDetCleaner::getRawDetId(const RPCRecHit& recHit) { +uint32_t MuonDetCleaner::getRawDetId(const RPCRecHit &recHit) { return recHit.rpcId().rawId(); } @@ -45,39 +45,36 @@ uint32_t MuonDetCleaner::getRawDetId(const RPCRecHit& recHi //------------------------------------------------------------------------------- template -bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recHit) { +bool MuonDetCleaner::checkrecHit(const TrackingRecHit &recHit) { edm::LogError("TauEmbedding") << "!!!! Please add the checkrecHit for the individual class templates " assert(0); } template <> -bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recHit) { - const std::type_info& hit_type = typeid(recHit); +bool MuonDetCleaner::checkrecHit(const TrackingRecHit &recHit) { + const std::type_info &hit_type = typeid(recHit); if (hit_type == typeid(CSCSegment)) { return true; } // This should be the default one (which are included in the global (outer) muon track) else if (hit_type == typeid(CSCRecHit2D)) { return true; } - //else {std::cout<<"else "< -uint32_t MuonDetCleaner::getRawDetId(const CSCSegment& recHit) -{ +uint32_t MuonDetCleaner::getRawDetId(const CSCSegment &recHit) { return recHit.cscDetId().rawId(); } template <> -uint32_t MuonDetCleaner::getRawDetId(const DTRecSegment4D& recHit) -{ +uint32_t MuonDetCleaner::getRawDetId(const DTRecSegment4D &recHit) { return recHit.geographicalId().rawId(); } - template <> -bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recHit) { - const std::type_info& hit_type = typeid(recHit); +bool MuonDetCleaner::checkrecHit(const TrackingRecHit &recHit) { + const std::type_info &hit_type = typeid(recHit); if (hit_type == typeid(DTRecSegment4D)) { return true; } // This should be the default one (which are included in the global (outer) muon track) @@ -93,34 +90,40 @@ bool MuonDetCleaner::checkrecHit(const TrackingRecHit } template <> -bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recHit) { - const std::type_info& hit_type = typeid(recHit); +bool MuonDetCleaner::checkrecHit(const TrackingRecHit &recHit) { + const std::type_info &hit_type = typeid(recHit); if (hit_type == typeid(RPCRecHit)) { return true; } // This should be the default one (which are included in the global (outer) muon track) - //else {std::cout<<"else "< -bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recHit) -{ - const std::type_info &hit_type = typeid(recHit); - if (hit_type == typeid(CSCSegment)) {return true;} // This should be the default one (which are included in the global (outer) muon track) - //else {std::cout<<"else "<::checkrecHit(const TrackingRecHit &recHit) { + const std::type_info &hit_type = typeid(recHit); + if (hit_type == typeid(CSCSegment)) { + return true; + } // This should be the default one (which are included in the global (outer) muon track) + // else {std::cout<<"else "< -bool MuonDetCleaner::checkrecHit(const TrackingRecHit& recHit) -{ - const std::type_info &hit_type = typeid(recHit); - if (hit_type == typeid(DTRecSegment4D)) {return true;} // This should be the default one (which are included in the global (outer) muon track) - else if (hit_type == typeid(DTRecHit1D)) {return true;} - else if (hit_type == typeid(DTSLRecCluster)) {return true; } - else if (hit_type == typeid(DTSLRecSegment2D)) {return true; } - // else {std::cout<<"else "<::checkrecHit(const TrackingRecHit &recHit) { + const std::type_info &hit_type = typeid(recHit); + if (hit_type == typeid(DTRecSegment4D)) { + return true; + } // This should be the default one (which are included in the global (outer) muon track) + else if (hit_type == typeid(DTRecHit1D)) { + return true; + } else if (hit_type == typeid(DTSLRecCluster)) { + return true; + } else if (hit_type == typeid(DTSLRecSegment2D)) { + return true; + } + // else {std::cout<<"else "< #include #include -#include template class MuonDetCleaner : public edm::stream::EDProducer<> { public: - explicit MuonDetCleaner(const edm::ParameterSet&); + explicit MuonDetCleaner(const edm::ParameterSet &); ~MuonDetCleaner() override; private: - void produce(edm::Event&, const edm::EventSetup&) override; + typedef edm::RangeMap> RecHitCollection; - typedef edm::RangeMap > RecHitCollection; - void fillVetoHits(const TrackingRecHit&, std::vector*); + void produce(edm::Event &, const edm::EventSetup &) override; + void fillVetoHits(const TrackingRecHit &, std::vector *); + uint32_t getRawDetId(const T2 &); + bool checkrecHit(const TrackingRecHit &); - uint32_t getRawDetId(const T2&); - bool checkrecHit(const TrackingRecHit&); + const edm::EDGetTokenT> mu_input_; - const edm::EDGetTokenT > mu_input_; - - std::map > inputs_; + std::map> inputs_; TrackAssociatorParameters parameters_; TrackDetectorAssociator trackAssociator_; @@ -66,7 +65,6 @@ class MuonDetCleaner : public edm::stream::EDProducer<> { edm::EDGetTokenT m_cscDigisToken; edm::Handle m_dtDigis; edm::Handle m_cscDigis; - edm::ESHandle m_dtGeometry; edm::ESHandle m_cscGeometry; edm::ESGetToken m_dtGeometryToken; @@ -76,20 +74,19 @@ class MuonDetCleaner : public edm::stream::EDProducer<> { }; template -MuonDetCleaner::MuonDetCleaner(const edm::ParameterSet& iConfig): - mu_input_(consumes >(iConfig.getParameter("MuonCollection"))), - m_dtDigisToken(consumes(iConfig.getParameter("dtDigiCollectionLabel"))), - m_cscDigisToken(consumes(iConfig.getParameter("cscDigiCollectionLabel"))), - m_dtGeometryToken(esConsumes()), - m_cscGeometryToken(esConsumes()), - propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), - m_digiMaxDistanceX(iConfig.getParameter("digiMaxDistanceX")) { - std::vector inCollections = iConfig.getParameter >("oldCollection"); - for (const auto& inCollection : inCollections) { +MuonDetCleaner::MuonDetCleaner(const edm::ParameterSet &iConfig) + : mu_input_(consumes>(iConfig.getParameter("MuonCollection"))), + m_dtDigisToken(consumes(iConfig.getParameter("dtDigiCollectionLabel"))), + m_cscDigisToken(consumes(iConfig.getParameter("cscDigiCollectionLabel"))), + m_dtGeometryToken(esConsumes()), + m_cscGeometryToken(esConsumes()), + propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), + m_digiMaxDistanceX(iConfig.getParameter("digiMaxDistanceX")) { + std::vector inCollections = iConfig.getParameter>("oldCollection"); + for (const auto &inCollection : inCollections) { inputs_[inCollection.instance()] = consumes(inCollection); produces(inCollection.instance()); } - edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); edm::ConsumesCollector iC = consumesCollector(); parameters_.loadParameters(parameters, iC); @@ -101,16 +98,16 @@ MuonDetCleaner::~MuonDetCleaner() { } template -void MuonDetCleaner::produce(edm::Event& iEvent, edm::EventSetup const& iSetup) { - std::map > recHits_output; // This data format is easyer to handle +void MuonDetCleaner::produce(edm::Event &iEvent, edm::EventSetup const &iSetup) { + std::map> recHits_output; // This data format is easyer to handle std::vector vetoHits; // First fill the veto RecHits colletion with the Hits from the input muons - edm::Handle > muonHandle; + edm::Handle> muonHandle; iEvent.getByToken(mu_input_, muonHandle); edm::View muons = *muonHandle; for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { - const reco::Track* track = nullptr; + const reco::Track *track = nullptr; if (iMuon->isGlobalMuon()) track = iMuon->outerTrack().get(); else if (iMuon->isStandAloneMuon()) @@ -126,7 +123,7 @@ void MuonDetCleaner::produce(edm::Event& iEvent, edm::EventSetup const& } for (trackingRecHit_iterator hitIt = track->recHitsBegin(); hitIt != track->recHitsEnd(); ++hitIt) { - const TrackingRecHit& murechit = **hitIt; // Base class for all rechits + const TrackingRecHit &murechit = **hitIt; // Base class for all rechits if (!(murechit).isValid()) continue; if (!checkrecHit(murechit)) @@ -134,125 +131,112 @@ void MuonDetCleaner::produce(edm::Event& iEvent, edm::EventSetup const& fillVetoHits(murechit, &vetoHits); // Go back to the very basic rechits } - sort(vetoHits.begin(), vetoHits.end()); - vetoHits.erase(unique( vetoHits.begin(), vetoHits.end() ), vetoHits.end()); - iEvent.getByToken(m_dtDigisToken, m_dtDigis); - iEvent.getByToken(m_cscDigisToken, m_cscDigis); - auto const& m_dtGeometry = iSetup.getData(m_dtGeometryToken); - auto const& m_cscGeometry = iSetup.getData(m_cscGeometryToken); - edm::ESHandle propagator; - trackAssociator_.setPropagator(&iSetup.getData(propagatorToken_)); - TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any); - - // inspired from Muon Identification algorithm: https://github.com/cms-sw/cmssw/blob/3b943c0dbbdf4494cd66064a5a147301f38af295/RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc#L911 - // and the MuonShowerDigiFiller: https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/interface/MuonShowerDigiFiller.h & https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/src/MuonShowerDigiFiller.cc - for (const auto &chamber : info.chambers) - { - if (chamber.id.subdetId() == MuonSubdetId::RPC) //&& rpcHitHandle_.isValid()) - continue; // Skip RPC chambers, they are taken care of below) - - reco::MuonChamberMatch matchedChamber; - - const auto &lErr = chamber.tState.localError(); - const auto &lPos = chamber.tState.localPosition(); - const auto &lDir = chamber.tState.localDirection(); - const auto &localError = lErr.positionError(); - - matchedChamber.x = lPos.x(); - matchedChamber.y = lPos.y(); - matchedChamber.xErr = sqrt(localError.xx()); - matchedChamber.yErr = sqrt(localError.yy()); - matchedChamber.dXdZ = lDir.z() != 0 ? lDir.x() / lDir.z() : 9999; - matchedChamber.dYdZ = lDir.z() != 0 ? lDir.y() / lDir.z() : 9999; - - // DANGEROUS - compiler cannot guaranty parameters ordering - AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix(); - matchedChamber.dXdZErr = trajectoryCovMatrix(1, 1) > 0 ? sqrt(trajectoryCovMatrix(1, 1)) : 0; - matchedChamber.dYdZErr = trajectoryCovMatrix(2, 2) > 0 ? sqrt(trajectoryCovMatrix(2, 2)) : 0; - - matchedChamber.edgeX = chamber.localDistanceX; - matchedChamber.edgeY = chamber.localDistanceY; - - matchedChamber.id = chamber.id; - - // DT chamber - if (matchedChamber.detector() == MuonSubdetId::DT) - { - double xTrack = matchedChamber.x; - - for (int sl = 1; sl <= DTChamberId::maxSuperLayerId; sl += 2) - { - for (int layer = 1; layer <= DTChamberId::maxLayerId; ++layer) - { - const DTLayerId layerId(DTChamberId(matchedChamber.id.rawId()), sl, layer); - auto range = m_dtDigis->get(layerId); - - for (auto digiIt = range.first; digiIt != range.second; ++digiIt) - { - const auto topo = m_dtGeometry.layer(layerId)->specificTopology(); - double xWire = topo.wirePosition((*digiIt).wire()); - double dX = std::abs(xWire - xTrack); - - if (dX < m_digiMaxDistanceX) - { - vetoHits.push_back(matchedChamber.id.rawId()); - } - } - } - } - } - - else if (matchedChamber.detector() == MuonSubdetId::CSC) - { - double xTrack = matchedChamber.x; - double yTrack = matchedChamber.y; - - for (int iLayer = 1; iLayer <= CSCDetId::maxLayerId(); ++iLayer) - { - const CSCDetId chId(matchedChamber.id.rawId()); - const CSCDetId layerId(chId.endcap(), chId.station(), chId.ring(), chId.chamber(), iLayer); - auto range = m_cscDigis->get(layerId); - - for (auto digiIt = range.first; digiIt != range.second; ++digiIt) - { - std::vector adcVals = digiIt->getADCCounts(); - bool hasFired = false; - float pedestal = 0.5 * (float)(adcVals[0] + adcVals[1]); - float threshold = 13.3; - float diff = 0.; - for (const auto &adcVal : adcVals) - { - diff = (float)adcVal - pedestal; - if (diff > threshold) - { - hasFired = true; - break; - } - } - - if (!hasFired) - continue; - - const CSCLayerGeometry *layerGeom = m_cscGeometry.layer(layerId)->geometry(); - Float_t xStrip = layerGeom->xOfStrip(digiIt->getStrip(), yTrack); - float dX = std::abs(xStrip - xTrack); - - if (dX < m_digiMaxDistanceX) - { - vetoHits.push_back(matchedChamber.id.rawId()); - } - } - } - } - } - - // std::cout << "END CUSTOM MUON CLEANING" << std::endl; - - //----------------- + sort(vetoHits.begin(), vetoHits.end()); + vetoHits.erase(unique(vetoHits.begin(), vetoHits.end()), vetoHits.end()); + iEvent.getByToken(m_dtDigisToken, m_dtDigis); + iEvent.getByToken(m_cscDigisToken, m_cscDigis); + auto const &m_dtGeometry = iSetup.getData(m_dtGeometryToken); + auto const &m_cscGeometry = iSetup.getData(m_cscGeometryToken); + edm::ESHandle propagator; + trackAssociator_.setPropagator(&iSetup.getData(propagatorToken_)); + TrackDetMatchInfo info = + trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any); + + // inspired from Muon Identification algorithm: https://github.com/cms-sw/cmssw/blob/3b943c0dbbdf4494cd66064a5a147301f38af295/RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc#L911 + // and the MuonShowerDigiFiller: https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/interface/MuonShowerDigiFiller.h & https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/src/MuonShowerDigiFiller.cc + for (const auto &chamber : info.chambers) { + if (chamber.id.subdetId() == MuonSubdetId::RPC) //&& rpcHitHandle_.isValid()) + continue; // Skip RPC chambers, they are taken care of below) + + reco::MuonChamberMatch matchedChamber; + + const auto &lErr = chamber.tState.localError(); + const auto &lPos = chamber.tState.localPosition(); + const auto &lDir = chamber.tState.localDirection(); + const auto &localError = lErr.positionError(); + + matchedChamber.x = lPos.x(); + matchedChamber.y = lPos.y(); + matchedChamber.xErr = sqrt(localError.xx()); + matchedChamber.yErr = sqrt(localError.yy()); + matchedChamber.dXdZ = lDir.z() != 0 ? lDir.x() / lDir.z() : 9999; + matchedChamber.dYdZ = lDir.z() != 0 ? lDir.y() / lDir.z() : 9999; + + // DANGEROUS - compiler cannot guaranty parameters ordering + AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix(); + matchedChamber.dXdZErr = trajectoryCovMatrix(1, 1) > 0 ? sqrt(trajectoryCovMatrix(1, 1)) : 0; + matchedChamber.dYdZErr = trajectoryCovMatrix(2, 2) > 0 ? sqrt(trajectoryCovMatrix(2, 2)) : 0; + + matchedChamber.edgeX = chamber.localDistanceX; + matchedChamber.edgeY = chamber.localDistanceY; + + matchedChamber.id = chamber.id; + + // DT chamber + if (matchedChamber.detector() == MuonSubdetId::DT) { + double xTrack = matchedChamber.x; + + for (int sl = 1; sl <= DTChamberId::maxSuperLayerId; sl += 2) { + for (int layer = 1; layer <= DTChamberId::maxLayerId; ++layer) { + const DTLayerId layerId(DTChamberId(matchedChamber.id.rawId()), sl, layer); + auto range = m_dtDigis->get(layerId); + + for (auto digiIt = range.first; digiIt != range.second; ++digiIt) { + const auto topo = m_dtGeometry.layer(layerId)->specificTopology(); + double xWire = topo.wirePosition((*digiIt).wire()); + double dX = std::abs(xWire - xTrack); + + if (dX < m_digiMaxDistanceX) { + vetoHits.push_back(matchedChamber.id.rawId()); + } + } + } + } + } + + else if (matchedChamber.detector() == MuonSubdetId::CSC) { + double xTrack = matchedChamber.x; + double yTrack = matchedChamber.y; + + for (int iLayer = 1; iLayer <= CSCDetId::maxLayerId(); ++iLayer) { + const CSCDetId chId(matchedChamber.id.rawId()); + const CSCDetId layerId(chId.endcap(), chId.station(), chId.ring(), chId.chamber(), iLayer); + auto range = m_cscDigis->get(layerId); + + for (auto digiIt = range.first; digiIt != range.second; ++digiIt) { + std::vector adcVals = digiIt->getADCCounts(); + bool hasFired = false; + float pedestal = 0.5 * (float)(adcVals[0] + adcVals[1]); + float threshold = 13.3; + float diff = 0.; + for (const auto &adcVal : adcVals) { + diff = (float)adcVal - pedestal; + if (diff > threshold) { + hasFired = true; + break; + } + } + + if (!hasFired) + continue; + + const CSCLayerGeometry *layerGeom = m_cscGeometry.layer(layerId)->geometry(); + Float_t xStrip = layerGeom->xOfStrip(digiIt->getStrip(), yTrack); + float dX = std::abs(xStrip - xTrack); + + if (dX < m_digiMaxDistanceX) { + vetoHits.push_back(matchedChamber.id.rawId()); + } + } + } + } + } + + // End improved cleaning in the muon chambers } - sort( vetoHits.begin(), vetoHits.end() ); - vetoHits.erase( unique( vetoHits.begin(), vetoHits.end() ), vetoHits.end() ); + sort(vetoHits.begin(), vetoHits.end()); + vetoHits.erase(unique(vetoHits.begin(), vetoHits.end()), vetoHits.end()); // Now this can also handle different instance for (auto input_ : inputs_) { @@ -262,7 +246,7 @@ void MuonDetCleaner::produce(edm::Event& iEvent, edm::EventSetup const& iEvent.getByToken(input_.second, RecHitinput); for (typename RecHitCollection::const_iterator recHit = RecHitinput->begin(); recHit != RecHitinput->end(); ++recHit) { // loop over the basic rec hit collection (DT CSC or RPC) - //if (find(vetoHits.begin(),vetoHits.end(),getRawDetId(*recHit)) == vetoHits.end()) continue; // For the invertec selcetion + // if (find(vetoHits.begin(),vetoHits.end(),getRawDetId(*recHit)) == vetoHits.end()) continue; // For the invertec selcetion if (find(vetoHits.begin(), vetoHits.end(), getRawDetId(*recHit)) != vetoHits.end()) continue; // If the hit is not in the T1 detId(getRawDetId(*recHit)); @@ -271,7 +255,7 @@ void MuonDetCleaner::produce(edm::Event& iEvent, edm::EventSetup const& // Last step savet the output in the CMSSW Data Format std::unique_ptr output(new RecHitCollection()); - for (typename std::map >::const_iterator recHit = recHits_output.begin(); + for (typename std::map>::const_iterator recHit = recHits_output.begin(); recHit != recHits_output.end(); ++recHit) { output->put(recHit->first, recHit->second.begin(), recHit->second.end()); @@ -282,12 +266,12 @@ void MuonDetCleaner::produce(edm::Event& iEvent, edm::EventSetup const& } template -void MuonDetCleaner::fillVetoHits(const TrackingRecHit& rh, std::vector* HitsList) { - std::vector rh_components = rh.recHits(); +void MuonDetCleaner::fillVetoHits(const TrackingRecHit &rh, std::vector *HitsList) { + std::vector rh_components = rh.recHits(); if (rh_components.empty()) { HitsList->push_back(rh.rawId()); } else { - for (std::vector::const_iterator rh_component = rh_components.begin(); + for (std::vector::const_iterator rh_component = rh_components.begin(); rh_component != rh_components.end(); ++rh_component) { fillVetoHits(**rh_component, HitsList); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc index 1c137436fbbbb..0a241745987a1 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc @@ -4,13 +4,13 @@ #include "DataFormats/TrackReco/interface/TrackExtra.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackExtra.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackExtraFwd.h" -#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" -#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" #include "DataFormats/EgammaReco/interface/SuperCluster.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" #include "DataFormats/EgammaTrackReco/interface/ConversionTrack.h" #include "DataFormats/EgammaTrackReco/interface/ConversionTrackFwd.h" @@ -18,29 +18,29 @@ #include "DataFormats/MuonReco/interface/MuonFwd.h" #include "DataFormats/MuonReco/interface/MuonTrackLinks.h" -#include "DataFormats/MuonReco/interface/MuonQuality.h" #include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/MuonReco/interface/MuonQuality.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h" #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h" +#include "DataFormats/MuonReco/interface/CaloMuon.h" #include "DataFormats/MuonReco/interface/Muon.h" -#include "DataFormats/MuonReco/interface/MuonTrackLinks.h" -#include "DataFormats/MuonReco/interface/MuonFwd.h" -#include "RecoMuon/MuonIdentification/interface/MuonTimingFiller.h" #include "DataFormats/MuonReco/interface/MuonCocktails.h" +#include "DataFormats/MuonReco/interface/MuonFwd.h" #include "DataFormats/MuonReco/interface/MuonTime.h" #include "DataFormats/MuonReco/interface/MuonTimeExtra.h" #include "DataFormats/MuonReco/interface/MuonTimeExtraMap.h" +#include "DataFormats/MuonReco/interface/MuonTrackLinks.h" #include "DataFormats/RecoCandidate/interface/IsoDeposit.h" #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h" -#include "DataFormats/MuonReco/interface/CaloMuon.h" +#include "RecoMuon/MuonIdentification/interface/MuonTimingFiller.h" #include "DataFormats/EgammaCandidates/interface/Photon.h" #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h" -#include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h" #include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h" typedef TrackMergeremb TrackColMerger; typedef TrackMergeremb GsfTrackColMerger; @@ -57,12 +57,12 @@ void TrackMergeremb::willproduce(std::string instance, std::string alias) { } template -void TrackMergeremb::willconsume(const edm::ParameterSet& iConfig) {} +void TrackMergeremb::willconsume(const edm::ParameterSet &iConfig) {} template -void TrackMergeremb::merg_and_put(edm::Event& iEvent, +void TrackMergeremb::merg_and_put(edm::Event &iEvent, std::string instance, - std::vector >& to_merge) { + std::vector> &to_merge) { std::unique_ptr outTracks = std::unique_ptr(new TrackCollectionemb); for (auto akt_collection : to_merge) { @@ -90,7 +90,7 @@ void TrackMergeremb::willproduce(std::string instance, st template <> void TrackMergeremb::merg_and_put( - edm::Event& iEvent, std::string instance, std::vector >& to_merge) { + edm::Event &iEvent, std::string instance, std::vector> &to_merge) { std::unique_ptr outTracks = std::make_unique(); std::unique_ptr outTracks_ex = std::make_unique(); std::unique_ptr outTracks_rh = std::make_unique(); @@ -100,7 +100,7 @@ void TrackMergeremb::merg_and_put( // auto rHits = iEvent.getRefBeforePut(); std::vector trackRefColl; - //std::vector trackRefColl; + // std::vector trackRefColl; for (auto akt_collection : to_merge) { edm::Handle track_col_in; @@ -112,7 +112,7 @@ void TrackMergeremb::merg_and_put( outTracks->push_back(reco::Track(*it)); auto rechits = it->recHits(); // Fixing geometry records of detector components for tracking rec. hits - for (auto ith = rechits.begin(); ith!= rechits.end(); ith++){ + for (auto ith = rechits.begin(); ith != rechits.end(); ith++) { auto hit = *(&(*ith)); hit->setDet(*geometry_->idToDet(hit->rawId())); } @@ -139,12 +139,12 @@ void TrackMergeremb::merg_and_put( } template <> -void TrackMergeremb::willconsume(const edm::ParameterSet& iConfig) { - //track refs for trackerdriven seeds - inputs_fixtrackrefs_ = consumes( edm::InputTag("generalTracks") ); - inputs_fixtrackcol_ = consumes( edm::InputTag("generalTracks") ); - inputs_rElectronMergedSeeds_ = consumes(edm::InputTag("electronMergedSeeds") ); - inputs_rElectronMergedSeedViews_ = consumes>(edm::InputTag("electronMergedSeeds") ); +void TrackMergeremb::willconsume(const edm::ParameterSet &iConfig) { + // track refs for trackerdriven seeds + inputs_fixtrackrefs_ = consumes(edm::InputTag("generalTracks")); + inputs_fixtrackcol_ = consumes(edm::InputTag("generalTracks")); + inputs_rElectronMergedSeeds_ = consumes(edm::InputTag("electronMergedSeeds")); + inputs_rElectronMergedSeedViews_ = consumes>(edm::InputTag("electronMergedSeeds")); } template <> @@ -158,12 +158,13 @@ void TrackMergeremb::willproduce(std::string instance, template <> void TrackMergeremb::merg_and_put( - edm::Event& iEvent, std::string instance, std::vector >& to_merge) { + edm::Event &iEvent, std::string instance, std::vector> &to_merge) { std::unique_ptr outTracks = std::make_unique(); std::unique_ptr outTracks_ex = std::make_unique(); std::unique_ptr outTracks_exgsf = std::make_unique(); std::unique_ptr outTracks_rh = std::make_unique(); - std::unique_ptr outTracks_refs = std::unique_ptr(new GsfTrackToTrackMapnew()); + std::unique_ptr outTracks_refs = + std::unique_ptr(new GsfTrackToTrackMapnew()); auto rTrackExtras = iEvent.getRefBeforePut(); auto rTrackExtras_gsf = iEvent.getRefBeforePut(); @@ -171,17 +172,19 @@ void TrackMergeremb::merg_and_put( auto rHits = iEvent.getRefBeforePut(); std::vector trackRefColl; - //track to track map for trackerdriven seed fix + // track to track map for trackerdriven seed fix edm::Handle track_ref_map; iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map); edm::Handle track_new_col; iEvent.getByToken(inputs_fixtrackcol_, track_new_col); - std::map simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map - for (unsigned abc =0; abc < track_new_col->size(); ++abc) { + std::map + simple_track_to_track_map; // I didn't find a more elegant way, so just build a good old fassion std::map + for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); - simple_track_to_track_map[trackRef] = trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again + simple_track_to_track_map[trackRef] = + trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; } @@ -194,11 +197,11 @@ void TrackMergeremb::merg_and_put( for (reco::GsfTrackCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it, ++sedref_it) { reco::ElectronSeedRef seed = it->seedRef().castTo(); - (const_cast(seed.get()))->setCtfTrack(simple_track_to_track_map[seed->ctfTrack()]); + (const_cast(seed.get()))->setCtfTrack(simple_track_to_track_map[seed->ctfTrack()]); outTracks->push_back(reco::GsfTrack(*it)); auto rechits = it->recHits(); // Fixing geometry records of detector components for tracking rec. hits - for (auto ith = rechits.begin(); ith!= rechits.end(); ith++){ + for (auto ith = rechits.begin(); ith != rechits.end(); ith++) { auto hit = *(&(*ith)); hit->setDet(*geometry_->idToDet(hit->rawId())); } @@ -216,45 +219,45 @@ void TrackMergeremb::merg_and_put( } // end merge - edm::OrphanHandle trackHandle = iEvent.put(std::move(outTracks),instance); + edm::OrphanHandle trackHandle = iEvent.put(std::move(outTracks), instance); GsfTrackToTrackMapnew::Filler filler(*outTracks_refs); - filler.insert(trackHandle, trackRefColl.begin(), trackRefColl.end() ); + filler.insert(trackHandle, trackRefColl.begin(), trackRefColl.end()); filler.fill(); - edm::Handle elSeeds; - iEvent.getByToken(inputs_rElectronMergedSeeds_,elSeeds); + iEvent.getByToken(inputs_rElectronMergedSeeds_, elSeeds); auto bElSeeds = elSeeds->cbegin(); auto eElSeeds = elSeeds->cend(); - edm::Handle > seedViewsHandle; - iEvent.getByToken(inputs_rElectronMergedSeedViews_,seedViewsHandle); + edm::Handle> seedViewsHandle; + iEvent.getByToken(inputs_rElectronMergedSeedViews_, seedViewsHandle); - std::unique_ptr outTracks_ex_new = std::unique_ptr(new reco::TrackExtraCollection()); + std::unique_ptr outTracks_ex_new = + std::unique_ptr(new reco::TrackExtraCollection()); - //fix track extras to new merged seeds - for ( typename reco::TrackExtraCollection::const_iterator tex = outTracks_ex->begin(); tex!= outTracks_ex->end(); ++tex ) { + // fix track extras to new merged seeds + for (typename reco::TrackExtraCollection::const_iterator tex = outTracks_ex->begin(); tex != outTracks_ex->end(); + ++tex) { reco::TrackExtra newTrackExtra(*tex); if (tex->seedRef().isAvailable()) { - const reco::ElectronSeedRef & trSeedRef (tex->seedRef().castTo()); - if( trSeedRef.isAvailable() ) { - - //find new seed with corresponding supercluster or ctfTrack - //note that seed can be both Ecal- and Tracker-driven + const reco::ElectronSeedRef &trSeedRef(tex->seedRef().castTo()); + if (trSeedRef.isAvailable()) { + // find new seed with corresponding supercluster or ctfTrack + // note that seed can be both Ecal- and Tracker-driven size_t sedref_it = 0; - for( auto tseed = bElSeeds; tseed != eElSeeds; ++tseed, ++sedref_it) { - const reco::ElectronSeedRef elSeedRef (elSeeds, sedref_it); + for (auto tseed = bElSeeds; tseed != eElSeeds; ++tseed, ++sedref_it) { + const reco::ElectronSeedRef elSeedRef(elSeeds, sedref_it); if (trSeedRef->isEcalDriven() && elSeedRef->isEcalDriven()) { - //match seeds by pair of detIds - if ( trSeedRef->detId(0) == elSeedRef->detId(0) && trSeedRef->detId(1) == elSeedRef->detId(1)) { + // match seeds by pair of detIds + if (trSeedRef->detId(0) == elSeedRef->detId(0) && trSeedRef->detId(1) == elSeedRef->detId(1)) { edm::RefToBase traSeedRef(seedViewsHandle, sedref_it); newTrackExtra.setSeedRef(traSeedRef); } } if (trSeedRef->isTrackerDriven() && elSeedRef->isTrackerDriven()) { - //if tracker driven, check for same ctf track + // if tracker driven, check for same ctf track if (simple_track_to_track_map[trSeedRef->ctfTrack()] == elSeedRef->ctfTrack()) { edm::RefToBase traSeedRef(seedViewsHandle, sedref_it); newTrackExtra.setSeedRef(traSeedRef); @@ -268,7 +271,7 @@ void TrackMergeremb::merg_and_put( } iEvent.put(std::move(outTracks_refs)); - iEvent.put(std::move(outTracks_ex_new),instance); + iEvent.put(std::move(outTracks_ex_new), instance); iEvent.put(std::move(outTracks_exgsf), instance); iEvent.put(std::move(outTracks_rh), instance); } @@ -292,23 +295,23 @@ void TrackMergeremb::willproduce(std::string instance, std } template <> -void TrackMergeremb::willconsume(const edm::ParameterSet& iConfig) { - if(alias == "displacedMuons1stStep"){ +void TrackMergeremb::willconsume(const edm::ParameterSet &iConfig) { + if (alias == "displacedMuons1stStep") { inputs_fixtrackrefs_ = consumes(edm::InputTag("displacedTracks")); inputs_fixtrackcol_ = consumes(edm::InputTag("displacedTracks")); - } - else{ + } else { inputs_fixtrackrefs_ = consumes(edm::InputTag("generalTracks")); inputs_fixtrackcol_ = consumes(edm::InputTag("generalTracks")); } } template <> -void TrackMergeremb::merg_and_put( - edm::Event& iEvent, std::string instance, std::vector >& to_merge) { +void TrackMergeremb::merg_and_put(edm::Event &iEvent, + std::string instance, + std::vector> &to_merge) { std::unique_ptr outTracks = std::make_unique(); std::unique_ptr calomu = - std::make_unique(); //not implemented so far + std::make_unique(); // not implemented so far edm::Handle track_ref_map; iEvent.getByToken(inputs_fixtrackrefs_, track_ref_map); @@ -316,10 +319,11 @@ void TrackMergeremb::merg_and_put( edm::Handle track_new_col; iEvent.getByToken(inputs_fixtrackcol_, track_new_col); std::map - simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map + simple_track_to_track_map; // I didn't find a more elegant way, so just build a good old fassion std::map for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); - simple_track_to_track_map[trackRef] = trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again + simple_track_to_track_map[trackRef] = + trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; } @@ -338,7 +342,7 @@ void TrackMergeremb::merg_and_put( reco::MuonRef muRefnew(outputMuonsRefProd, new_idx); if (it->track().isNonnull()) { - //std::cout<<"pfmerge tr: "<trackRef().id()<< " "<< it->trackRef().key()<< " " << simple_track_to_track_map[it->trackRef()].id() << " " << simple_track_to_track_map[it->trackRef()].key() <trackRef().id()<< " "<< it->trackRef().key()<< " " << simple_track_to_track_map[it->trackRef()].id() << " " << simple_track_to_track_map[it->trackRef()].key() <back().setTrack(simple_track_to_track_map[it->track()]); } } @@ -358,7 +362,7 @@ void TrackMergeremb::merg_and_put( edm::OrphanHandle muonHandle = iEvent.put(std::move(outTracks)); - auto fillMap = [](auto refH, auto& vec, edm::Event& ev, const std::string& cAl = "") { + auto fillMap = [](auto refH, auto &vec, edm::Event &ev, const std::string &cAl = "") { typedef edm::ValueMap::type::value_type> MapType; std::unique_ptr oMap(new MapType()); { @@ -389,19 +393,19 @@ void TrackMergeremb::willproduce(std::string instan } template <> -void TrackMergeremb::willconsume(const edm::ParameterSet& iConfig) { +void TrackMergeremb::willconsume(const edm::ParameterSet &iConfig) { inputs_fixtrackrefs_ = consumes(edm::InputTag("generalTracks")); inputs_fixtrackcol_ = consumes(edm::InputTag("generalTracks")); - inputs_fixgsftrackrefs_ = consumes( edm::InputTag("electronGsfTracks") ); - inputs_fixgsftrackcol_ = consumes( edm::InputTag("electronGsfTracks") ); + inputs_fixgsftrackrefs_ = consumes(edm::InputTag("electronGsfTracks")); + inputs_fixgsftrackcol_ = consumes(edm::InputTag("electronGsfTracks")); inputs_fixmurefs_ = consumes(edm::InputTag("muons1stStep")); inputs_fixmucol_ = consumes(edm::InputTag("muons1stStep")); - inputs_SC_ = consumes(edm::InputTag("particleFlowEGamma") ); + inputs_SC_ = consumes(edm::InputTag("particleFlowEGamma")); } template <> void TrackMergeremb::merg_and_put( - edm::Event& iEvent, std::string instance, std::vector >& to_merge) { + edm::Event &iEvent, std::string instance, std::vector> &to_merge) { std::unique_ptr outTracks = std::make_unique(); edm::Handle track_ref_map; @@ -410,10 +414,11 @@ void TrackMergeremb::merg_and_put( edm::Handle track_new_col; iEvent.getByToken(inputs_fixtrackcol_, track_new_col); std::map - simple_track_to_track_map; //I didn't find a more elegant way, so just build a good old fassion std::map + simple_track_to_track_map; // I didn't find a more elegant way, so just build a good old fassion std::map for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); - simple_track_to_track_map[trackRef] = trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again + simple_track_to_track_map[trackRef] = + trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; } @@ -422,8 +427,9 @@ void TrackMergeremb::merg_and_put( edm::Handle gsftrack_new_col; iEvent.getByToken(inputs_fixgsftrackcol_, gsftrack_new_col); - std::map simple_gsftrack_to_gsftrack_map; //I didn't find a more elegant way, so just build a good old fassion std::map - for (unsigned abc =0; abc < gsftrack_new_col->size(); ++abc) { + std::map + simple_gsftrack_to_gsftrack_map; // I didn't find a more elegant way, so just build a good old fassion std::map + for (unsigned abc = 0; abc < gsftrack_new_col->size(); ++abc) { reco::GsfTrackRef gsfTrackRef(gsftrack_new_col, abc); simple_gsftrack_to_gsftrack_map[((*gsftrack_ref_map)[gsfTrackRef])[0]] = gsfTrackRef; } @@ -434,15 +440,15 @@ void TrackMergeremb::merg_and_put( edm::Handle muon_new_col; iEvent.getByToken(inputs_fixmucol_, muon_new_col); std::map - simple_mu_to_mu_map; //I didn't find a more elegant way, so just build a good old fassion std::map + simple_mu_to_mu_map; // I didn't find a more elegant way, so just build a good old fassion std::map for (unsigned abc = 0; abc < muon_new_col->size(); ++abc) { reco::MuonRef muRef(muon_new_col, abc); simple_mu_to_mu_map[(*muon_ref_map)[muRef]] = muRef; } - //used for photon matching + // used for photon matching edm::Handle sCs; - iEvent.getByToken(inputs_SC_,sCs); + iEvent.getByToken(inputs_SC_, sCs); auto bSc = sCs->cbegin(); auto eSc = sCs->cend(); @@ -451,35 +457,35 @@ void TrackMergeremb::merg_and_put( iEvent.getByToken(akt_collection, track_col_in); for (reco::PFCandidateCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it) { outTracks->push_back(reco::PFCandidate(*it)); - //if (fabs(it->pdgId()) == 13){ + // if (fabs(it->pdgId()) == 13){ if (it->trackRef().isNonnull() && outTracks->back().charge()) { - //std::cout<<"pfmerge tr: "<trackRef().id()<< " "<< it->trackRef().key()<< " " << simple_track_to_track_map[it->trackRef()].id() << " " << simple_track_to_track_map[it->trackRef()].key() <trackRef().id()<< " "<< it->trackRef().key()<< " " << simple_track_to_track_map[it->trackRef()].id() << " " << simple_track_to_track_map[it->trackRef()].key() <back().setTrackRef(simple_track_to_track_map[it->trackRef()]); } - if(it->gsfTrackRef().isNonnull()) { - outTracks->back().setGsfTrackRef( simple_gsftrack_to_gsftrack_map[it->gsfTrackRef()] ); + if (it->gsfTrackRef().isNonnull()) { + outTracks->back().setGsfTrackRef(simple_gsftrack_to_gsftrack_map[it->gsfTrackRef()]); } if (it->superClusterRef().isNonnull()) { - const reco::SuperClusterRef & pfScRef(it->superClusterRef()); + const reco::SuperClusterRef &pfScRef(it->superClusterRef()); float dx, dy, dz, dr; - //float drMin = std::numeric_limits::infinity(); - float drMin = 10.0;//also used as treshold for matching + // float drMin = std::numeric_limits::infinity(); + float drMin = 10.0; // also used as treshold for matching reco::SuperClusterRef ccrefMin; - for( auto sc = bSc; sc != eSc; ++sc ) { - const reco::SuperClusterRef & scRef(reco::SuperClusterRef(sCs,std::distance(bSc,sc))); - dx = fabs(scRef->x()-pfScRef->x()); - dy = fabs(scRef->y()-pfScRef->y()); - dz = fabs(scRef->z()-pfScRef->z()); - dr = sqrt(dx*dx+dy*dy+dz*dz); - if ( dr < drMin ) { + for (auto sc = bSc; sc != eSc; ++sc) { + const reco::SuperClusterRef &scRef(reco::SuperClusterRef(sCs, std::distance(bSc, sc))); + dx = fabs(scRef->x() - pfScRef->x()); + dy = fabs(scRef->y() - pfScRef->y()); + dz = fabs(scRef->z() - pfScRef->z()); + dr = sqrt(dx * dx + dy * dy + dz * dz); + if (dr < drMin) { drMin = dr; outTracks->back().setSuperClusterRef(scRef); } } } if (it->muonRef().isNonnull()) { - //std::cout<<"pfmerge mu: "<muonRef().id()<< " "<< it->muonRef().key()<< " " << simple_mu_to_mu_map[it->muonRef()].id() << " " << simple_mu_to_mu_map[it->muonRef()].key() <muonRef().id()<< " "<< it->muonRef().key()<< " " << simple_mu_to_mu_map[it->muonRef()].id() << " " << simple_mu_to_mu_map[it->muonRef()].key() <back().setMuonRef(simple_mu_to_mu_map[it->muonRef()]); } } diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h index f7452ef025c3e..2de7f8e7c2be3 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h @@ -12,66 +12,65 @@ #ifndef TauAnalysis_MCEmbeddingTools_TrackMergeremb_H #define TauAnalysis_MCEmbeddingTools_TrackMergeremb_H -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "DataFormats/Common/interface/Handle.h" +#include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" #include "DataFormats/EgammaReco/interface/SuperCluster.h" +#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h" #include "DataFormats/EgammaReco/interface/ElectronSeed.h" #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h" -#include "TrackingTools/PatternTools/interface/Trajectory.h" -#include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h" -#include "DataFormats/EgammaReco/interface/ElectronSeed.h" #include "DataFormats/ParticleFlowReco/interface/PreId.h" +#include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h" +#include "TrackingTools/PatternTools/interface/Trajectory.h" -#include "DataFormats/MuonReco/interface/MuonQuality.h" #include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/MuonReco/interface/MuonQuality.h" #include "DataFormats/MuonReco/interface/MuonToMuonMap.h" #include "DataFormats/TrackReco/interface/Track.h" #include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackExtra.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackExtraFwd.h" -#include "DataFormats/GsfTrackReco/interface/GsfTrack.h" #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h" #include "DataFormats/TrackReco/interface/TrackToTrackMap.h" #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h" #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h" -#include #include #include +#include template class TrackMergeremb : public edm::stream::EDProducer<> { public: - explicit TrackMergeremb(const edm::ParameterSet&); + explicit TrackMergeremb(const edm::ParameterSet &); ~TrackMergeremb() override; private: - void produce(edm::Event&, const edm::EventSetup&) override; + void produce(edm::Event &, const edm::EventSetup &) override; typedef T1 TrackCollectionemb; void willproduce(std::string instance, std::string alias); - void willconsume(const edm::ParameterSet& iConfig); - void merg_and_put(edm::Event&, std::string, std::vector >&); + void willconsume(const edm::ParameterSet &iConfig); + void merg_and_put(edm::Event &, std::string, std::vector> &); - std::map > > inputs_; - std::map > > > inputs_qual_; + std::map>> inputs_; + std::map>>> inputs_qual_; - //typedef edm::ValueMap TrackToTrackMapnew; + // typedef edm::ValueMap TrackToTrackMapnew; typedef edm::ValueMap TrackToTrackMapnew; typedef edm::ValueMap GsfTrackToTrackMapnew; edm::ESGetToken globalGeomToken_; - const GlobalTrackingGeometry* geometry_ = nullptr; + const GlobalTrackingGeometry *geometry_ = nullptr; edm::EDGetTokenT inputs_fixtrackrefs_; edm::EDGetTokenT inputs_fixtrackcol_; @@ -90,15 +89,15 @@ class TrackMergeremb : public edm::stream::EDProducer<> { }; template -TrackMergeremb::TrackMergeremb(const edm::ParameterSet& iConfig) { +TrackMergeremb::TrackMergeremb(const edm::ParameterSet &iConfig) { alias = iConfig.getParameter("@module_label"); - std::vector inCollections = iConfig.getParameter >("mergCollections"); + std::vector inCollections = iConfig.getParameter>("mergCollections"); globalGeomToken_ = esConsumes(); - for (const auto& inCollection : inCollections) { + for (const auto &inCollection : inCollections) { inputs_[inCollection.instance()].push_back(consumes(inCollection)); } willconsume(iConfig); - for (const auto& toproduce : inputs_) { + for (const auto &toproduce : inputs_) { willproduce(toproduce.first, alias); } } @@ -109,7 +108,7 @@ TrackMergeremb::~TrackMergeremb() { } template -void TrackMergeremb::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { +void TrackMergeremb::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { geometry_ = &iSetup.getData(globalGeomToken_); for (auto input_ : inputs_) { merg_and_put(iEvent, input_.first, input_.second); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc index 0730953bd2ab7..7ba413e8bda7c 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc @@ -1,12 +1,12 @@ #include "TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h" +#include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h" +#include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h" #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h" #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h" -#include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h" -#include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h" -#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h" #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" +#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h" typedef TrackerCleaner PixelColCleaner; typedef TrackerCleaner StripColCleaner; diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h index cb52dfe60199e..c55dc50de74e3 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h @@ -1,64 +1,64 @@ /** \class TrackerCleaner * - * + * * \author Stefan Wayand; * Christian Veelken, LLR * - * * - * + * + * * */ #ifndef TauAnalysis_MCEmbeddingTools_TrackerCleaner_H #define TauAnalysis_MCEmbeddingTools_TrackerCleaner_H -#include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "DataFormats/Common/interface/Handle.h" -#include "DataFormats/PatCandidates/interface/Muon.h" #include "DataFormats/MuonReco/interface/MuonEnergy.h" +#include "DataFormats/PatCandidates/interface/Muon.h" +#include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h" #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h" -#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" -#include "DataFormats/Common/interface/SortedCollection.h" #include "DataFormats/Common/interface/DetSetVectorNew.h" +#include "DataFormats/Common/interface/SortedCollection.h" #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h" #include "DataFormats/TrackerRecHit2D/interface/OmniClusterRef.h" #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h" -#include #include #include +#include template class TrackerCleaner : public edm::stream::EDProducer<> { public: - explicit TrackerCleaner(const edm::ParameterSet&); + explicit TrackerCleaner(const edm::ParameterSet &); ~TrackerCleaner() override; private: - void produce(edm::Event&, const edm::EventSetup&) override; + void produce(edm::Event &, const edm::EventSetup &) override; - const edm::EDGetTokenT > mu_input_; + const edm::EDGetTokenT> mu_input_; typedef edmNew::DetSetVector TrackClusterCollection; - std::map > inputs_; + std::map> inputs_; - bool match_rechit_type(const TrackingRecHit& murechit); + bool match_rechit_type(const TrackingRecHit &murechit); }; template -TrackerCleaner::TrackerCleaner(const edm::ParameterSet& iConfig) - : mu_input_(consumes >(iConfig.getParameter("MuonCollection"))) +TrackerCleaner::TrackerCleaner(const edm::ParameterSet &iConfig) + : mu_input_(consumes>(iConfig.getParameter("MuonCollection"))) { - std::vector inCollections = iConfig.getParameter >("oldCollection"); - for (const auto& inCollection : inCollections) { + std::vector inCollections = iConfig.getParameter>("oldCollection"); + for (const auto &inCollection : inCollections) { inputs_[inCollection.instance()] = consumes(inCollection); produces(inCollection.instance()); } @@ -70,10 +70,10 @@ TrackerCleaner::~TrackerCleaner() { } template -void TrackerCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { +void TrackerCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { using namespace edm; - edm::Handle > muonHandle; + edm::Handle> muonHandle; iEvent.getByToken(mu_input_, muonHandle); edm::View muons = *muonHandle; @@ -88,22 +88,21 @@ void TrackerCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetu for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { if (!iMuon->isGlobalMuon()) continue; - const reco::Track* mutrack = iMuon->globalTrack().get(); + const reco::Track *mutrack = iMuon->globalTrack().get(); // reco::Track *mutrack = new reco::Track(*(iMuon->innerTrack() )); for (trackingRecHit_iterator hitIt = mutrack->recHitsBegin(); hitIt != mutrack->recHitsEnd(); ++hitIt) { - const TrackingRecHit& murechit = **hitIt; + const TrackingRecHit &murechit = **hitIt; if (!(murechit).isValid()) continue; if (match_rechit_type(murechit)) { - auto& thit = reinterpret_cast(murechit); - auto const& cluster = thit.firstClusterRef(); + auto &thit = reinterpret_cast(murechit); + auto const &cluster = thit.firstClusterRef(); vetodClusters[cluster.key()] = true; } auto &thit = reinterpret_cast(murechit); - if (trackerHitRTTI::isMatched(thit)) - { - vetodClusters[reinterpret_cast(murechit).stereoClusterRef().key()] = true; + if (trackerHitRTTI::isMatched(thit)) { + vetodClusters[reinterpret_cast(murechit).stereoClusterRef().key()] = true; } } } @@ -120,7 +119,7 @@ void TrackerCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetu idx++; if (vetodClusters[idx - 1]) continue; - //if (!vetodClusters[idx-1]) continue; for inverted selction + // if (!vetodClusters[idx-1]) continue; for inverted selction spc.push_back(*clustIt); } } From e9283b6a82a54b670068c6e1621b9428c1da8b66 Mon Sep 17 00:00:00 2001 From: cwinter Date: Tue, 28 Nov 2023 12:58:00 +0100 Subject: [PATCH 51/58] rewrite header files to only contain declaration --- .../MCEmbeddingTools/plugins/CaloCleaner.cc | 84 +++++++ .../MCEmbeddingTools/plugins/CaloCleaner.h | 86 +------- .../plugins/CollectionMerger.cc | 33 +++ .../plugins/CollectionMerger.h | 37 ---- .../plugins/DoubleCollectionMerger.cc | 56 +++++ .../plugins/DoubleCollectionMerger.h | 61 ------ .../plugins/MuonDetCleaner.cc | 206 ++++++++++++++++++ .../MCEmbeddingTools/plugins/MuonDetCleaner.h | 206 ------------------ .../plugins/TrackMergeremb.cc | 28 +++ .../MCEmbeddingTools/plugins/TrackMergeremb.h | 27 --- .../plugins/TrackerCleaner.cc | 75 +++++++ .../MCEmbeddingTools/plugins/TrackerCleaner.h | 74 ------- 12 files changed, 483 insertions(+), 490 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc index 3aac2b04c54ef..482ebd8632658 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc @@ -14,6 +14,90 @@ typedef CaloCleaner HORecHitColCleaner; typedef CaloCleaner CastorRecHitColCleaner; typedef CaloCleaner ZDCRecHitColCleaner; +template +CaloCleaner::CaloCleaner(const edm::ParameterSet &iConfig) + : mu_input_(consumes>(iConfig.getParameter("MuonCollection"))), + propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))) { + std::vector inCollections = iConfig.getParameter>("oldCollection"); + for (const auto &inCollection : inCollections) { + inputs_[inCollection.instance()] = consumes(inCollection); + produces(inCollection.instance()); + } + + is_preshower_ = iConfig.getUntrackedParameter("is_preshower", false); + edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); + edm::ConsumesCollector iC = consumesCollector(); + parameters_.loadParameters(parameters, iC); + // trackAssociator_.useDefaultPropagator(); +} + +template +CaloCleaner::~CaloCleaner() { + // nothing to be done yet... +} + +template +void CaloCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + auto const &propagator = iSetup.getData(propagatorToken_); + trackAssociator_.setPropagator(&propagator); + + edm::Handle> muonHandle; + iEvent.getByToken(mu_input_, muonHandle); + edm::View muons = *muonHandle; + + std::map correction_map; + + // Fill the correction map + for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { + // get the basic informaiton like fill reco mouon does + // RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc + const reco::Track *track = nullptr; + if (iMuon->track().isNonnull()) + track = iMuon->track().get(); + else if (iMuon->standAloneMuon().isNonnull()) + track = iMuon->standAloneMuon().get(); + else + throw cms::Exception("FatalError") + << "Failed to fill muon id information for a muon with undefined references to tracks"; + TrackDetMatchInfo info = + trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any); + fill_correction_map(&info, &correction_map); + } + + // Copy the old collection and correct if necessary + for (auto input_ : inputs_) { + std::unique_ptr recHitCollection_output(new RecHitCollection()); + edm::Handle recHitCollection; + // iEvent.getByToken(input_.second[0], recHitCollection); + iEvent.getByToken(input_.second, recHitCollection); + for (typename RecHitCollection::const_iterator recHit = recHitCollection->begin(); + recHit != recHitCollection->end(); + ++recHit) { + if (correction_map[recHit->detid().rawId()] > 0) { + float new_energy = recHit->energy() - correction_map[recHit->detid().rawId()]; + if (new_energy <= 0) + continue; // Do not save empty Hits + T newRecHit(*recHit); + newRecHit.setEnergy(new_energy); + recHitCollection_output->push_back(newRecHit); + } else { + recHitCollection_output->push_back(*recHit); + } + /* For the inveted collection + if (correction_map[recHit->detid().rawId()] > 0){ + float new_energy = correction_map[recHit->detid().rawId()]; + if (new_energy < 0) new_energy =0; + T newRecHit(*recHit); + newRecHit.setEnergy(new_energy); + recHitCollection_output->push_back(newRecHit); + }*/ + } + // Save the new collection + recHitCollection_output->sort(); + iEvent.put(std::move(recHitCollection_output), input_.first); + } +} + //------------------------------------------------------------------------------- // define 'buildRecHit' functions used for different types of recHits //------------------------------------------------------------------------------- diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h index 9114af7d93ffd..7438d09bda3de 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h @@ -54,88 +54,4 @@ class CaloCleaner : public edm::stream::EDProducer<> { bool is_preshower_; void fill_correction_map(TrackDetMatchInfo *, std::map *); }; - -template -CaloCleaner::CaloCleaner(const edm::ParameterSet &iConfig) - : mu_input_(consumes>(iConfig.getParameter("MuonCollection"))), - propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))) { - std::vector inCollections = iConfig.getParameter>("oldCollection"); - for (const auto &inCollection : inCollections) { - inputs_[inCollection.instance()] = consumes(inCollection); - produces(inCollection.instance()); - } - - is_preshower_ = iConfig.getUntrackedParameter("is_preshower", false); - edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); - edm::ConsumesCollector iC = consumesCollector(); - parameters_.loadParameters(parameters, iC); - // trackAssociator_.useDefaultPropagator(); -} - -template -CaloCleaner::~CaloCleaner() { - // nothing to be done yet... -} - -template -void CaloCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { - auto const &propagator = iSetup.getData(propagatorToken_); - trackAssociator_.setPropagator(&propagator); - - edm::Handle> muonHandle; - iEvent.getByToken(mu_input_, muonHandle); - edm::View muons = *muonHandle; - - std::map correction_map; - - // Fill the correction map - for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { - // get the basic informaiton like fill reco mouon does - // RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc - const reco::Track *track = nullptr; - if (iMuon->track().isNonnull()) - track = iMuon->track().get(); - else if (iMuon->standAloneMuon().isNonnull()) - track = iMuon->standAloneMuon().get(); - else - throw cms::Exception("FatalError") - << "Failed to fill muon id information for a muon with undefined references to tracks"; - TrackDetMatchInfo info = - trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any); - fill_correction_map(&info, &correction_map); - } - - // Copy the old collection and correct if necessary - for (auto input_ : inputs_) { - std::unique_ptr recHitCollection_output(new RecHitCollection()); - edm::Handle recHitCollection; - // iEvent.getByToken(input_.second[0], recHitCollection); - iEvent.getByToken(input_.second, recHitCollection); - for (typename RecHitCollection::const_iterator recHit = recHitCollection->begin(); - recHit != recHitCollection->end(); - ++recHit) { - if (correction_map[recHit->detid().rawId()] > 0) { - float new_energy = recHit->energy() - correction_map[recHit->detid().rawId()]; - if (new_energy <= 0) - continue; // Do not save empty Hits - T newRecHit(*recHit); - newRecHit.setEnergy(new_energy); - recHitCollection_output->push_back(newRecHit); - } else { - recHitCollection_output->push_back(*recHit); - } - /* For the inveted collection - if (correction_map[recHit->detid().rawId()] > 0){ - float new_energy = correction_map[recHit->detid().rawId()]; - if (new_energy < 0) new_energy =0; - T newRecHit(*recHit); - newRecHit.setEnergy(new_energy); - recHitCollection_output->push_back(newRecHit); - }*/ - } - // Save the new collection - recHitCollection_output->sort(); - iEvent.put(std::move(recHitCollection_output), input_.first); - } -} -#endif +#endif \ No newline at end of file diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc index 705f9222267f6..293e683c9a0fa 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc @@ -58,6 +58,39 @@ typedef CollectionMerger typedef CollectionMerger>, CSCRecHit2D> CSCRecHitColMerger; typedef CollectionMerger>, RPCRecHit> RPCRecHitColMerger; +template +CollectionMerger::CollectionMerger(const edm::ParameterSet &iConfig) { + std::vector inCollections = iConfig.getParameter>("mergCollections"); + for (auto const &inCollection : inCollections) { + inputs_[inCollection.instance()].push_back(consumes(inCollection)); + } + willconsume(iConfig); + for (const auto &toproduce : inputs_) { + std::string alias(iConfig.getParameter("@module_label")); + // std::cout< +CollectionMerger::~CollectionMerger() { + // nothing to be done yet... +} + +template +void CollectionMerger::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + for (auto input_ : inputs_) { + std::unique_ptr output(new MergeCollection()); + std::vector> inputCollections; + inputCollections.resize(input_.second.size()); + for (unsigned id = 0; id < input_.second.size(); id++) { + iEvent.getByToken(input_.second[id], inputCollections[id]); + } + fill_output_obj(iEvent, output, inputCollections); + iEvent.put(std::move(output), input_.first); + } +} + template void CollectionMerger::willconsume(const edm::ParameterSet &iConfig) {} diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h index ead32c8ccb58b..9835cd3349aa0 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h @@ -1,13 +1,8 @@ /** \class CollectionMerger - * * * \author Stefan Wayand; * Christian Veelken, LLR * - * - * - * - * */ #ifndef TauAnalysis_MCEmbeddingTools_CollectionMerger_H #define TauAnalysis_MCEmbeddingTools_CollectionMerger_H @@ -83,36 +78,4 @@ class CollectionMerger : public edm::stream::EDProducer<> { void willconsume(const edm::ParameterSet &iConfig); }; -template -CollectionMerger::CollectionMerger(const edm::ParameterSet &iConfig) { - std::vector inCollections = iConfig.getParameter>("mergCollections"); - for (auto const &inCollection : inCollections) { - inputs_[inCollection.instance()].push_back(consumes(inCollection)); - } - willconsume(iConfig); - for (const auto &toproduce : inputs_) { - std::string alias(iConfig.getParameter("@module_label")); - // std::cout< -CollectionMerger::~CollectionMerger() { - // nothing to be done yet... -} - -template -void CollectionMerger::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { - for (auto input_ : inputs_) { - std::unique_ptr output(new MergeCollection()); - std::vector> inputCollections; - inputCollections.resize(input_.second.size()); - for (unsigned id = 0; id < input_.second.size(); id++) { - iEvent.getByToken(input_.second[id], inputCollections[id]); - } - fill_output_obj(iEvent, output, inputCollections); - iEvent.put(std::move(output), input_.first); - } -} #endif diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc index 16dbdfa5485a2..c75b6f76d06f5 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc @@ -17,6 +17,62 @@ typedef DoubleCollectionMerger, EESrFlag, edm::S typedef DoubleCollectionMerger HcalDigiColMerger; +template +DoubleCollectionMerger::DoubleCollectionMerger(const edm::ParameterSet &iConfig) { + std::vector inCollections = iConfig.getParameter>("mergCollections"); + for (auto const &inCollection : inCollections) { + inputs1_[inCollection.instance()].push_back(consumes(inCollection)); + inputs2_[inCollection.instance()].push_back(consumes(inCollection)); + } + for (auto toproduce : inputs1_) { + // std::cout<(toproduce.first); + } + for (auto toproduce : inputs2_) { + // std::cout<(toproduce.first); + } +} + +template +DoubleCollectionMerger::~DoubleCollectionMerger() { + // nothing to be done yet... +} + +template +void DoubleCollectionMerger::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + // std::cout << "DoubleCollectionMerger::produce" << std::endl; + for (auto input_ : inputs1_) { + // std::cout << "input_.first()=" << input_.first << std::endl; + // std::cout << "input_.second.size()=" << input_.second.size() << std::endl; + std::unique_ptr output(new MergeCollection1()); + std::vector> inputCollections; + inputCollections.resize(input_.second.size()); + for (unsigned id = 0; id < input_.second.size(); id++) { + // std::cout << "input_.second[id]=" << input_.second[id] << std::endl; + // std::cout << "input_.second[id]=" << id << std::endl; + iEvent.getByToken(input_.second[id], inputCollections[id]); + } + fill_output_obj(output, inputCollections); + iEvent.put(std::move(output), input_.first); + } + + for (auto input_ : inputs2_) { + // std::cout << "input_.first()=" << input_.first << std::endl; + // std::cout << "input_.second.size()=" << input_.second.size() << std::endl; + std::unique_ptr output(new MergeCollection2()); + std::vector> inputCollections; + inputCollections.resize(input_.second.size()); + for (unsigned id = 0; id < input_.second.size(); id++) { + // std::cout << "input_.second[id]=" << input_.second[id] << std::endl; + // std::cout << "input_.second[id]=" << id << std::endl; + iEvent.getByToken(input_.second[id], inputCollections[id]); + } + fill_output_obj(output, inputCollections); + iEvent.put(std::move(output), input_.first); + } +} + // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections template void DoubleCollectionMerger::fill_output_obj( diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h index e74d50fbe232f..fc23b2d55315a 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h @@ -1,12 +1,7 @@ /** \class DoubleCollectionMerger - * * * \author Per Ahrens * - * - * - * - * */ #ifndef TauAnalysis_MCEmbeddingTools_DoubleCollectionMerger_H #define TauAnalysis_MCEmbeddingTools_DoubleCollectionMerger_H @@ -54,60 +49,4 @@ class DoubleCollectionMerger : public edm::stream::EDProducer<> { void fill_output_obj_hcaldigi(std::unique_ptr &output, std::vector> &inputCollections); }; - -template -DoubleCollectionMerger::DoubleCollectionMerger(const edm::ParameterSet &iConfig) { - std::vector inCollections = iConfig.getParameter>("mergCollections"); - for (auto const &inCollection : inCollections) { - inputs1_[inCollection.instance()].push_back(consumes(inCollection)); - inputs2_[inCollection.instance()].push_back(consumes(inCollection)); - } - for (auto toproduce : inputs1_) { - // std::cout<(toproduce.first); - } - for (auto toproduce : inputs2_) { - // std::cout<(toproduce.first); - } -} - -template -DoubleCollectionMerger::~DoubleCollectionMerger() { - // nothing to be done yet... -} - -template -void DoubleCollectionMerger::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { - // std::cout << "DoubleCollectionMerger::produce" << std::endl; - for (auto input_ : inputs1_) { - // std::cout << "input_.first()=" << input_.first << std::endl; - // std::cout << "input_.second.size()=" << input_.second.size() << std::endl; - std::unique_ptr output(new MergeCollection1()); - std::vector> inputCollections; - inputCollections.resize(input_.second.size()); - for (unsigned id = 0; id < input_.second.size(); id++) { - // std::cout << "input_.second[id]=" << input_.second[id] << std::endl; - // std::cout << "input_.second[id]=" << id << std::endl; - iEvent.getByToken(input_.second[id], inputCollections[id]); - } - fill_output_obj(output, inputCollections); - iEvent.put(std::move(output), input_.first); - } - - for (auto input_ : inputs2_) { - // std::cout << "input_.first()=" << input_.first << std::endl; - // std::cout << "input_.second.size()=" << input_.second.size() << std::endl; - std::unique_ptr output(new MergeCollection2()); - std::vector> inputCollections; - inputCollections.resize(input_.second.size()); - for (unsigned id = 0; id < input_.second.size(); id++) { - // std::cout << "input_.second[id]=" << input_.second[id] << std::endl; - // std::cout << "input_.second[id]=" << id << std::endl; - iEvent.getByToken(input_.second[id], inputCollections[id]); - } - fill_output_obj(output, inputCollections); - iEvent.put(std::move(output), input_.first); - } -} #endif diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc index 641bec5d8676c..112126b756f41 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc @@ -15,6 +15,212 @@ typedef MuonDetCleaner DTRecSegment4DColCleaner; typedef MuonDetCleaner DTRecHitColCleaner; typedef MuonDetCleaner RPCRecHitColCleaner; +template +MuonDetCleaner::MuonDetCleaner(const edm::ParameterSet &iConfig) + : mu_input_(consumes>(iConfig.getParameter("MuonCollection"))), + m_dtDigisToken(consumes(iConfig.getParameter("dtDigiCollectionLabel"))), + m_cscDigisToken(consumes(iConfig.getParameter("cscDigiCollectionLabel"))), + m_dtGeometryToken(esConsumes()), + m_cscGeometryToken(esConsumes()), + propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), + m_digiMaxDistanceX(iConfig.getParameter("digiMaxDistanceX")) { + std::vector inCollections = iConfig.getParameter>("oldCollection"); + for (const auto &inCollection : inCollections) { + inputs_[inCollection.instance()] = consumes(inCollection); + produces(inCollection.instance()); + } + edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); + edm::ConsumesCollector iC = consumesCollector(); + parameters_.loadParameters(parameters, iC); +} + +template +MuonDetCleaner::~MuonDetCleaner() { + // nothing to be done yet... +} + +template +void MuonDetCleaner::produce(edm::Event &iEvent, edm::EventSetup const &iSetup) { + std::map> recHits_output; // This data format is easyer to handle + std::vector vetoHits; + + // First fill the veto RecHits colletion with the Hits from the input muons + edm::Handle> muonHandle; + iEvent.getByToken(mu_input_, muonHandle); + edm::View muons = *muonHandle; + for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { + const reco::Track *track = nullptr; + if (iMuon->isGlobalMuon()) + track = iMuon->outerTrack().get(); + else if (iMuon->isStandAloneMuon()) + track = iMuon->outerTrack().get(); + else if (iMuon->isRPCMuon()) + track = iMuon->innerTrack().get(); // To add, try to access the rpc track + else if (iMuon->isTrackerMuon()) + track = iMuon->innerTrack().get(); + else { + edm::LogError("TauEmbedding") << "The imput muon: " << (*iMuon) + << " must be either global or does or be tracker muon"; + assert(0); + } + + for (trackingRecHit_iterator hitIt = track->recHitsBegin(); hitIt != track->recHitsEnd(); ++hitIt) { + const TrackingRecHit &murechit = **hitIt; // Base class for all rechits + if (!(murechit).isValid()) + continue; + if (!checkrecHit(murechit)) + continue; // Check if the hit belongs to a specifc detector section + fillVetoHits(murechit, &vetoHits); // Go back to the very basic rechits + } + + sort(vetoHits.begin(), vetoHits.end()); + vetoHits.erase(unique(vetoHits.begin(), vetoHits.end()), vetoHits.end()); + iEvent.getByToken(m_dtDigisToken, m_dtDigis); + iEvent.getByToken(m_cscDigisToken, m_cscDigis); + auto const &m_dtGeometry = iSetup.getData(m_dtGeometryToken); + auto const &m_cscGeometry = iSetup.getData(m_cscGeometryToken); + edm::ESHandle propagator; + trackAssociator_.setPropagator(&iSetup.getData(propagatorToken_)); + TrackDetMatchInfo info = + trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any); + + // inspired from Muon Identification algorithm: https://github.com/cms-sw/cmssw/blob/3b943c0dbbdf4494cd66064a5a147301f38af295/RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc#L911 + // and the MuonShowerDigiFiller: https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/interface/MuonShowerDigiFiller.h & https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/src/MuonShowerDigiFiller.cc + for (const auto &chamber : info.chambers) { + if (chamber.id.subdetId() == MuonSubdetId::RPC) //&& rpcHitHandle_.isValid()) + continue; // Skip RPC chambers, they are taken care of below) + + reco::MuonChamberMatch matchedChamber; + + const auto &lErr = chamber.tState.localError(); + const auto &lPos = chamber.tState.localPosition(); + const auto &lDir = chamber.tState.localDirection(); + const auto &localError = lErr.positionError(); + + matchedChamber.x = lPos.x(); + matchedChamber.y = lPos.y(); + matchedChamber.xErr = sqrt(localError.xx()); + matchedChamber.yErr = sqrt(localError.yy()); + matchedChamber.dXdZ = lDir.z() != 0 ? lDir.x() / lDir.z() : 9999; + matchedChamber.dYdZ = lDir.z() != 0 ? lDir.y() / lDir.z() : 9999; + + // DANGEROUS - compiler cannot guaranty parameters ordering + AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix(); + matchedChamber.dXdZErr = trajectoryCovMatrix(1, 1) > 0 ? sqrt(trajectoryCovMatrix(1, 1)) : 0; + matchedChamber.dYdZErr = trajectoryCovMatrix(2, 2) > 0 ? sqrt(trajectoryCovMatrix(2, 2)) : 0; + + matchedChamber.edgeX = chamber.localDistanceX; + matchedChamber.edgeY = chamber.localDistanceY; + + matchedChamber.id = chamber.id; + + // DT chamber + if (matchedChamber.detector() == MuonSubdetId::DT) { + double xTrack = matchedChamber.x; + + for (int sl = 1; sl <= DTChamberId::maxSuperLayerId; sl += 2) { + for (int layer = 1; layer <= DTChamberId::maxLayerId; ++layer) { + const DTLayerId layerId(DTChamberId(matchedChamber.id.rawId()), sl, layer); + auto range = m_dtDigis->get(layerId); + + for (auto digiIt = range.first; digiIt != range.second; ++digiIt) { + const auto topo = m_dtGeometry.layer(layerId)->specificTopology(); + double xWire = topo.wirePosition((*digiIt).wire()); + double dX = std::abs(xWire - xTrack); + + if (dX < m_digiMaxDistanceX) { + vetoHits.push_back(matchedChamber.id.rawId()); + } + } + } + } + } + + else if (matchedChamber.detector() == MuonSubdetId::CSC) { + double xTrack = matchedChamber.x; + double yTrack = matchedChamber.y; + + for (int iLayer = 1; iLayer <= CSCDetId::maxLayerId(); ++iLayer) { + const CSCDetId chId(matchedChamber.id.rawId()); + const CSCDetId layerId(chId.endcap(), chId.station(), chId.ring(), chId.chamber(), iLayer); + auto range = m_cscDigis->get(layerId); + + for (auto digiIt = range.first; digiIt != range.second; ++digiIt) { + std::vector adcVals = digiIt->getADCCounts(); + bool hasFired = false; + float pedestal = 0.5 * (float)(adcVals[0] + adcVals[1]); + float threshold = 13.3; + float diff = 0.; + for (const auto &adcVal : adcVals) { + diff = (float)adcVal - pedestal; + if (diff > threshold) { + hasFired = true; + break; + } + } + + if (!hasFired) + continue; + + const CSCLayerGeometry *layerGeom = m_cscGeometry.layer(layerId)->geometry(); + Float_t xStrip = layerGeom->xOfStrip(digiIt->getStrip(), yTrack); + float dX = std::abs(xStrip - xTrack); + + if (dX < m_digiMaxDistanceX) { + vetoHits.push_back(matchedChamber.id.rawId()); + } + } + } + } + } + + // End improved cleaning in the muon chambers + } + + sort(vetoHits.begin(), vetoHits.end()); + vetoHits.erase(unique(vetoHits.begin(), vetoHits.end()), vetoHits.end()); + + // Now this can also handle different instance + for (auto input_ : inputs_) { + // Second read in the RecHit Colltection which is to be replaced, without the vetoRecHits + typedef edm::Handle RecHitCollectionHandle; + RecHitCollectionHandle RecHitinput; + iEvent.getByToken(input_.second, RecHitinput); + for (typename RecHitCollection::const_iterator recHit = RecHitinput->begin(); recHit != RecHitinput->end(); + ++recHit) { // loop over the basic rec hit collection (DT CSC or RPC) + // if (find(vetoHits.begin(),vetoHits.end(),getRawDetId(*recHit)) == vetoHits.end()) continue; // For the invertec selcetion + if (find(vetoHits.begin(), vetoHits.end(), getRawDetId(*recHit)) != vetoHits.end()) + continue; // If the hit is not in the + T1 detId(getRawDetId(*recHit)); + recHits_output[detId].push_back(*recHit); + } + + // Last step savet the output in the CMSSW Data Format + std::unique_ptr output(new RecHitCollection()); + for (typename std::map>::const_iterator recHit = recHits_output.begin(); + recHit != recHits_output.end(); + ++recHit) { + output->put(recHit->first, recHit->second.begin(), recHit->second.end()); + } + output->post_insert(); + iEvent.put(std::move(output), input_.first); + } +} + +template +void MuonDetCleaner::fillVetoHits(const TrackingRecHit &rh, std::vector *HitsList) { + std::vector rh_components = rh.recHits(); + if (rh_components.empty()) { + HitsList->push_back(rh.rawId()); + } else { + for (std::vector::const_iterator rh_component = rh_components.begin(); + rh_component != rh_components.end(); + ++rh_component) { + fillVetoHits(**rh_component, HitsList); + } + } +} + //------------------------------------------------------------------------------- // define 'getRawDetId' functions used for different types of recHits //------------------------------------------------------------------------------- diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h index b14dab23bf857..0a5da76032901 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h @@ -73,210 +73,4 @@ class MuonDetCleaner : public edm::stream::EDProducer<> { double m_digiMaxDistanceX; }; -template -MuonDetCleaner::MuonDetCleaner(const edm::ParameterSet &iConfig) - : mu_input_(consumes>(iConfig.getParameter("MuonCollection"))), - m_dtDigisToken(consumes(iConfig.getParameter("dtDigiCollectionLabel"))), - m_cscDigisToken(consumes(iConfig.getParameter("cscDigiCollectionLabel"))), - m_dtGeometryToken(esConsumes()), - m_cscGeometryToken(esConsumes()), - propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), - m_digiMaxDistanceX(iConfig.getParameter("digiMaxDistanceX")) { - std::vector inCollections = iConfig.getParameter>("oldCollection"); - for (const auto &inCollection : inCollections) { - inputs_[inCollection.instance()] = consumes(inCollection); - produces(inCollection.instance()); - } - edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); - edm::ConsumesCollector iC = consumesCollector(); - parameters_.loadParameters(parameters, iC); -} - -template -MuonDetCleaner::~MuonDetCleaner() { - // nothing to be done yet... -} - -template -void MuonDetCleaner::produce(edm::Event &iEvent, edm::EventSetup const &iSetup) { - std::map> recHits_output; // This data format is easyer to handle - std::vector vetoHits; - - // First fill the veto RecHits colletion with the Hits from the input muons - edm::Handle> muonHandle; - iEvent.getByToken(mu_input_, muonHandle); - edm::View muons = *muonHandle; - for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { - const reco::Track *track = nullptr; - if (iMuon->isGlobalMuon()) - track = iMuon->outerTrack().get(); - else if (iMuon->isStandAloneMuon()) - track = iMuon->outerTrack().get(); - else if (iMuon->isRPCMuon()) - track = iMuon->innerTrack().get(); // To add, try to access the rpc track - else if (iMuon->isTrackerMuon()) - track = iMuon->innerTrack().get(); - else { - edm::LogError("TauEmbedding") << "The imput muon: " << (*iMuon) - << " must be either global or does or be tracker muon"; - assert(0); - } - - for (trackingRecHit_iterator hitIt = track->recHitsBegin(); hitIt != track->recHitsEnd(); ++hitIt) { - const TrackingRecHit &murechit = **hitIt; // Base class for all rechits - if (!(murechit).isValid()) - continue; - if (!checkrecHit(murechit)) - continue; // Check if the hit belongs to a specifc detector section - fillVetoHits(murechit, &vetoHits); // Go back to the very basic rechits - } - - sort(vetoHits.begin(), vetoHits.end()); - vetoHits.erase(unique(vetoHits.begin(), vetoHits.end()), vetoHits.end()); - iEvent.getByToken(m_dtDigisToken, m_dtDigis); - iEvent.getByToken(m_cscDigisToken, m_cscDigis); - auto const &m_dtGeometry = iSetup.getData(m_dtGeometryToken); - auto const &m_cscGeometry = iSetup.getData(m_cscGeometryToken); - edm::ESHandle propagator; - trackAssociator_.setPropagator(&iSetup.getData(propagatorToken_)); - TrackDetMatchInfo info = - trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any); - - // inspired from Muon Identification algorithm: https://github.com/cms-sw/cmssw/blob/3b943c0dbbdf4494cd66064a5a147301f38af295/RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc#L911 - // and the MuonShowerDigiFiller: https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/interface/MuonShowerDigiFiller.h & https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/src/MuonShowerDigiFiller.cc - for (const auto &chamber : info.chambers) { - if (chamber.id.subdetId() == MuonSubdetId::RPC) //&& rpcHitHandle_.isValid()) - continue; // Skip RPC chambers, they are taken care of below) - - reco::MuonChamberMatch matchedChamber; - - const auto &lErr = chamber.tState.localError(); - const auto &lPos = chamber.tState.localPosition(); - const auto &lDir = chamber.tState.localDirection(); - const auto &localError = lErr.positionError(); - - matchedChamber.x = lPos.x(); - matchedChamber.y = lPos.y(); - matchedChamber.xErr = sqrt(localError.xx()); - matchedChamber.yErr = sqrt(localError.yy()); - matchedChamber.dXdZ = lDir.z() != 0 ? lDir.x() / lDir.z() : 9999; - matchedChamber.dYdZ = lDir.z() != 0 ? lDir.y() / lDir.z() : 9999; - - // DANGEROUS - compiler cannot guaranty parameters ordering - AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix(); - matchedChamber.dXdZErr = trajectoryCovMatrix(1, 1) > 0 ? sqrt(trajectoryCovMatrix(1, 1)) : 0; - matchedChamber.dYdZErr = trajectoryCovMatrix(2, 2) > 0 ? sqrt(trajectoryCovMatrix(2, 2)) : 0; - - matchedChamber.edgeX = chamber.localDistanceX; - matchedChamber.edgeY = chamber.localDistanceY; - - matchedChamber.id = chamber.id; - - // DT chamber - if (matchedChamber.detector() == MuonSubdetId::DT) { - double xTrack = matchedChamber.x; - - for (int sl = 1; sl <= DTChamberId::maxSuperLayerId; sl += 2) { - for (int layer = 1; layer <= DTChamberId::maxLayerId; ++layer) { - const DTLayerId layerId(DTChamberId(matchedChamber.id.rawId()), sl, layer); - auto range = m_dtDigis->get(layerId); - - for (auto digiIt = range.first; digiIt != range.second; ++digiIt) { - const auto topo = m_dtGeometry.layer(layerId)->specificTopology(); - double xWire = topo.wirePosition((*digiIt).wire()); - double dX = std::abs(xWire - xTrack); - - if (dX < m_digiMaxDistanceX) { - vetoHits.push_back(matchedChamber.id.rawId()); - } - } - } - } - } - - else if (matchedChamber.detector() == MuonSubdetId::CSC) { - double xTrack = matchedChamber.x; - double yTrack = matchedChamber.y; - - for (int iLayer = 1; iLayer <= CSCDetId::maxLayerId(); ++iLayer) { - const CSCDetId chId(matchedChamber.id.rawId()); - const CSCDetId layerId(chId.endcap(), chId.station(), chId.ring(), chId.chamber(), iLayer); - auto range = m_cscDigis->get(layerId); - - for (auto digiIt = range.first; digiIt != range.second; ++digiIt) { - std::vector adcVals = digiIt->getADCCounts(); - bool hasFired = false; - float pedestal = 0.5 * (float)(adcVals[0] + adcVals[1]); - float threshold = 13.3; - float diff = 0.; - for (const auto &adcVal : adcVals) { - diff = (float)adcVal - pedestal; - if (diff > threshold) { - hasFired = true; - break; - } - } - - if (!hasFired) - continue; - - const CSCLayerGeometry *layerGeom = m_cscGeometry.layer(layerId)->geometry(); - Float_t xStrip = layerGeom->xOfStrip(digiIt->getStrip(), yTrack); - float dX = std::abs(xStrip - xTrack); - - if (dX < m_digiMaxDistanceX) { - vetoHits.push_back(matchedChamber.id.rawId()); - } - } - } - } - } - - // End improved cleaning in the muon chambers - } - - sort(vetoHits.begin(), vetoHits.end()); - vetoHits.erase(unique(vetoHits.begin(), vetoHits.end()), vetoHits.end()); - - // Now this can also handle different instance - for (auto input_ : inputs_) { - // Second read in the RecHit Colltection which is to be replaced, without the vetoRecHits - typedef edm::Handle RecHitCollectionHandle; - RecHitCollectionHandle RecHitinput; - iEvent.getByToken(input_.second, RecHitinput); - for (typename RecHitCollection::const_iterator recHit = RecHitinput->begin(); recHit != RecHitinput->end(); - ++recHit) { // loop over the basic rec hit collection (DT CSC or RPC) - // if (find(vetoHits.begin(),vetoHits.end(),getRawDetId(*recHit)) == vetoHits.end()) continue; // For the invertec selcetion - if (find(vetoHits.begin(), vetoHits.end(), getRawDetId(*recHit)) != vetoHits.end()) - continue; // If the hit is not in the - T1 detId(getRawDetId(*recHit)); - recHits_output[detId].push_back(*recHit); - } - - // Last step savet the output in the CMSSW Data Format - std::unique_ptr output(new RecHitCollection()); - for (typename std::map>::const_iterator recHit = recHits_output.begin(); - recHit != recHits_output.end(); - ++recHit) { - output->put(recHit->first, recHit->second.begin(), recHit->second.end()); - } - output->post_insert(); - iEvent.put(std::move(output), input_.first); - } -} - -template -void MuonDetCleaner::fillVetoHits(const TrackingRecHit &rh, std::vector *HitsList) { - std::vector rh_components = rh.recHits(); - if (rh_components.empty()) { - HitsList->push_back(rh.rawId()); - } else { - for (std::vector::const_iterator rh_component = rh_components.begin(); - rh_component != rh_components.end(); - ++rh_component) { - fillVetoHits(**rh_component, HitsList); - } - } -} - #endif diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc index 0a241745987a1..1c11f477bcd1f 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc @@ -50,6 +50,34 @@ typedef TrackMergeremb PhotonColMerger; typedef TrackMergeremb ConversionColMerger; typedef TrackMergeremb PFColMerger; +template +TrackMergeremb::TrackMergeremb(const edm::ParameterSet &iConfig) { + alias = iConfig.getParameter("@module_label"); + std::vector inCollections = iConfig.getParameter>("mergCollections"); + globalGeomToken_ = esConsumes(); + for (const auto &inCollection : inCollections) { + inputs_[inCollection.instance()].push_back(consumes(inCollection)); + } + willconsume(iConfig); + for (const auto &toproduce : inputs_) { + willproduce(toproduce.first, alias); + } +} + +template +TrackMergeremb::~TrackMergeremb() { + // nothing to be done yet... +} + +template +void TrackMergeremb::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + geometry_ = &iSetup.getData(globalGeomToken_); + for (auto input_ : inputs_) { + merg_and_put(iEvent, input_.first, input_.second); + + } // end instance +} + // Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections template void TrackMergeremb::willproduce(std::string instance, std::string alias) { diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h index 2de7f8e7c2be3..b3305102622a6 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h @@ -88,31 +88,4 @@ class TrackMergeremb : public edm::stream::EDProducer<> { std::string alias; }; -template -TrackMergeremb::TrackMergeremb(const edm::ParameterSet &iConfig) { - alias = iConfig.getParameter("@module_label"); - std::vector inCollections = iConfig.getParameter>("mergCollections"); - globalGeomToken_ = esConsumes(); - for (const auto &inCollection : inCollections) { - inputs_[inCollection.instance()].push_back(consumes(inCollection)); - } - willconsume(iConfig); - for (const auto &toproduce : inputs_) { - willproduce(toproduce.first, alias); - } -} - -template -TrackMergeremb::~TrackMergeremb() { - // nothing to be done yet... -} - -template -void TrackMergeremb::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { - geometry_ = &iSetup.getData(globalGeomToken_); - for (auto input_ : inputs_) { - merg_and_put(iEvent, input_.first, input_.second); - - } // end instance -} #endif diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc index 7ba413e8bda7c..261f0d89c64ca 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc @@ -11,6 +11,81 @@ typedef TrackerCleaner PixelColCleaner; typedef TrackerCleaner StripColCleaner; +template +TrackerCleaner::TrackerCleaner(const edm::ParameterSet &iConfig) + : mu_input_(consumes>(iConfig.getParameter("MuonCollection"))) + +{ + std::vector inCollections = iConfig.getParameter>("oldCollection"); + for (const auto &inCollection : inCollections) { + inputs_[inCollection.instance()] = consumes(inCollection); + produces(inCollection.instance()); + } +} + +template +TrackerCleaner::~TrackerCleaner() { + // nothing to be done yet... +} + +template +void TrackerCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { + using namespace edm; + + edm::Handle> muonHandle; + iEvent.getByToken(mu_input_, muonHandle); + edm::View muons = *muonHandle; + + for (auto input_ : inputs_) { + edm::Handle inputClusters; + iEvent.getByToken(input_.second, inputClusters); + + std::vector vetodClusters; + + vetodClusters.resize(inputClusters->dataSize(), false); + + for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { + if (!iMuon->isGlobalMuon()) + continue; + const reco::Track *mutrack = iMuon->globalTrack().get(); + // reco::Track *mutrack = new reco::Track(*(iMuon->innerTrack() )); + for (trackingRecHit_iterator hitIt = mutrack->recHitsBegin(); hitIt != mutrack->recHitsEnd(); ++hitIt) { + const TrackingRecHit &murechit = **hitIt; + if (!(murechit).isValid()) + continue; + + if (match_rechit_type(murechit)) { + auto &thit = reinterpret_cast(murechit); + auto const &cluster = thit.firstClusterRef(); + vetodClusters[cluster.key()] = true; + } + auto &thit = reinterpret_cast(murechit); + if (trackerHitRTTI::isMatched(thit)) { + vetodClusters[reinterpret_cast(murechit).stereoClusterRef().key()] = true; + } + } + } + std::unique_ptr output(new TrackClusterCollection()); + + int idx = 0; + for (typename TrackClusterCollection::const_iterator clustSet = inputClusters->begin(); + clustSet != inputClusters->end(); + ++clustSet) { + DetId detIdObject(clustSet->detId()); + typename TrackClusterCollection::FastFiller spc(*output, detIdObject); + for (typename edmNew::DetSet::const_iterator clustIt = clustSet->begin(); clustIt != clustSet->end(); + ++clustIt) { + idx++; + if (vetodClusters[idx - 1]) + continue; + // if (!vetodClusters[idx-1]) continue; for inverted selction + spc.push_back(*clustIt); + } + } + iEvent.put(std::move(output), input_.first); + } +} + //------------------------------------------------------------------------------- // define 'buildRecHit' functions used for different types of recHits //------------------------------------------------------------------------------- diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h index c55dc50de74e3..39a62e0c438f2 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.h @@ -52,78 +52,4 @@ class TrackerCleaner : public edm::stream::EDProducer<> { bool match_rechit_type(const TrackingRecHit &murechit); }; -template -TrackerCleaner::TrackerCleaner(const edm::ParameterSet &iConfig) - : mu_input_(consumes>(iConfig.getParameter("MuonCollection"))) - -{ - std::vector inCollections = iConfig.getParameter>("oldCollection"); - for (const auto &inCollection : inCollections) { - inputs_[inCollection.instance()] = consumes(inCollection); - produces(inCollection.instance()); - } -} - -template -TrackerCleaner::~TrackerCleaner() { - // nothing to be done yet... -} - -template -void TrackerCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { - using namespace edm; - - edm::Handle> muonHandle; - iEvent.getByToken(mu_input_, muonHandle); - edm::View muons = *muonHandle; - - for (auto input_ : inputs_) { - edm::Handle inputClusters; - iEvent.getByToken(input_.second, inputClusters); - - std::vector vetodClusters; - - vetodClusters.resize(inputClusters->dataSize(), false); - - for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { - if (!iMuon->isGlobalMuon()) - continue; - const reco::Track *mutrack = iMuon->globalTrack().get(); - // reco::Track *mutrack = new reco::Track(*(iMuon->innerTrack() )); - for (trackingRecHit_iterator hitIt = mutrack->recHitsBegin(); hitIt != mutrack->recHitsEnd(); ++hitIt) { - const TrackingRecHit &murechit = **hitIt; - if (!(murechit).isValid()) - continue; - - if (match_rechit_type(murechit)) { - auto &thit = reinterpret_cast(murechit); - auto const &cluster = thit.firstClusterRef(); - vetodClusters[cluster.key()] = true; - } - auto &thit = reinterpret_cast(murechit); - if (trackerHitRTTI::isMatched(thit)) { - vetodClusters[reinterpret_cast(murechit).stereoClusterRef().key()] = true; - } - } - } - std::unique_ptr output(new TrackClusterCollection()); - - int idx = 0; - for (typename TrackClusterCollection::const_iterator clustSet = inputClusters->begin(); - clustSet != inputClusters->end(); - ++clustSet) { - DetId detIdObject(clustSet->detId()); - typename TrackClusterCollection::FastFiller spc(*output, detIdObject); - for (typename edmNew::DetSet::const_iterator clustIt = clustSet->begin(); clustIt != clustSet->end(); - ++clustIt) { - idx++; - if (vetodClusters[idx - 1]) - continue; - // if (!vetodClusters[idx-1]) continue; for inverted selction - spc.push_back(*clustIt); - } - } - iEvent.put(std::move(output), input_.first); - } -} #endif From efe13d9bbe420e970509656dc54b0570dcb85279 Mon Sep 17 00:00:00 2001 From: cwinter Date: Wed, 6 Dec 2023 16:33:28 +0100 Subject: [PATCH 52/58] load EventSetup information for each run separatly --- .../MCEmbeddingTools/plugins/MuonDetCleaner.cc | 13 +++++++++---- .../MCEmbeddingTools/plugins/MuonDetCleaner.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc index 112126b756f41..f32b9aac2a1f9 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc @@ -39,6 +39,13 @@ MuonDetCleaner::~MuonDetCleaner() { // nothing to be done yet... } +template +void MuonDetCleaner::beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) { + // get the geometries from the event setup everytime the run (of the event which is processed right now to the previous event) changes + m_dtGeometry = iSetup.getHandle(m_dtGeometryToken); + m_cscGeometry = iSetup.getHandle(m_cscGeometryToken); +} + template void MuonDetCleaner::produce(edm::Event &iEvent, edm::EventSetup const &iSetup) { std::map> recHits_output; // This data format is easyer to handle @@ -77,8 +84,6 @@ void MuonDetCleaner::produce(edm::Event &iEvent, edm::EventSetup const & vetoHits.erase(unique(vetoHits.begin(), vetoHits.end()), vetoHits.end()); iEvent.getByToken(m_dtDigisToken, m_dtDigis); iEvent.getByToken(m_cscDigisToken, m_cscDigis); - auto const &m_dtGeometry = iSetup.getData(m_dtGeometryToken); - auto const &m_cscGeometry = iSetup.getData(m_cscGeometryToken); edm::ESHandle propagator; trackAssociator_.setPropagator(&iSetup.getData(propagatorToken_)); TrackDetMatchInfo info = @@ -124,7 +129,7 @@ void MuonDetCleaner::produce(edm::Event &iEvent, edm::EventSetup const & auto range = m_dtDigis->get(layerId); for (auto digiIt = range.first; digiIt != range.second; ++digiIt) { - const auto topo = m_dtGeometry.layer(layerId)->specificTopology(); + const auto topo = m_dtGeometry->layer(layerId)->specificTopology(); double xWire = topo.wirePosition((*digiIt).wire()); double dX = std::abs(xWire - xTrack); @@ -162,7 +167,7 @@ void MuonDetCleaner::produce(edm::Event &iEvent, edm::EventSetup const & if (!hasFired) continue; - const CSCLayerGeometry *layerGeom = m_cscGeometry.layer(layerId)->geometry(); + const CSCLayerGeometry *layerGeom = m_cscGeometry->layer(layerId)->geometry(); Float_t xStrip = layerGeom->xOfStrip(digiIt->getStrip(), yTrack); float dX = std::abs(xStrip - xTrack); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h index 0a5da76032901..36560987e4493 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.h @@ -50,6 +50,7 @@ class MuonDetCleaner : public edm::stream::EDProducer<> { private: typedef edm::RangeMap> RecHitCollection; + void beginRun(const edm::Run &, const edm::EventSetup &) override; void produce(edm::Event &, const edm::EventSetup &) override; void fillVetoHits(const TrackingRecHit &, std::vector *); uint32_t getRawDetId(const T2 &); From c79fde4a9395f3d2fc8ce88cea28fbcee4fabf35 Mon Sep 17 00:00:00 2001 From: cwinter Date: Wed, 6 Dec 2023 16:35:52 +0100 Subject: [PATCH 53/58] debug correct handling of input comming from RESELECT collection --- TauAnalysis/MCEmbeddingTools/python/customisers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index f1d52763da4db..ecde79c05c6f9 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -419,6 +419,15 @@ def customiseCleaning(process, changeProcessname=True, reselect=False): TrackAssociatorParameterBlock.TrackAssociatorParameters.HORecHitCollectionLabel = ( cms.InputTag("horeco", "", dataTier) ) + TrackAssociatorParameterBlock.TrackAssociatorParameters.ME0HitCollectionLabel = ( + cms.InputTag("me0RecHits", "", dataTier) + ) + TrackAssociatorParameterBlock.TrackAssociatorParameters.ME0SegmentCollectionLabel = ( + cms.InputTag("me0Segments", "", dataTier) + ) + TrackAssociatorParameterBlock.TrackAssociatorParameters.RPCHitCollectionLabel = ( + cms.InputTag("rpcRecHits", "", dataTier) + ) MuonImput = cms.InputTag("selectedMuonsForEmbedding", "", "") ## This are the muon for akt_manimod in to_bemanipulate: From 49d02ef149b3a61d5793befd02bf918b33312962 Mon Sep 17 00:00:00 2001 From: cwinter Date: Wed, 13 Dec 2023 18:40:29 +0100 Subject: [PATCH 54/58] add a running test for embedding. --- TauAnalysis/MCEmbeddingTools/test/runtests.sh | 136 +++++++++++++++--- 1 file changed, 118 insertions(+), 18 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/test/runtests.sh b/TauAnalysis/MCEmbeddingTools/test/runtests.sh index 2d543bcd432cd..c2c789b1ef228 100755 --- a/TauAnalysis/MCEmbeddingTools/test/runtests.sh +++ b/TauAnalysis/MCEmbeddingTools/test/runtests.sh @@ -1,30 +1,130 @@ -#!/bin/bash -ex +#!/bin/bash +# This script runs all the steps of the embedding workflow +# author: Christian Winter (christian.winter@cern.ch) +# TODO: move the dataset to a more persistent and for cmssw accessible place than a private EOS user folder -##____________________________________________________________________________|| +# print the exit status before exiting function die { echo $1: status $2 ; exit $2; } -# echo '{ -#"274199" : [[1, 180]] -#}' > step1_lumiRanges.log 2>&1 - -# (das_client --limit 0 --query 'file dataset=/DoubleMuon/Run2016B-v2/RAW run=274199') | sort -u > step1_dasquery.log 2>&1 -#due to frequent failures of das_client: use file directly -#echo "/store/data/Run2016B/DoubleMuon/RAW/v2/000/274/199/00000/02893BCB-6426-E611-B266-02163E012552.root" > step1_dasquery.log +## This is a PRE SKIMED dataset +dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/PreRAWskimmed.root" -#cmsDriver.py selecting -s RAW2DIGI,L1Reco,RECO,PAT --data --scenario pp --conditions auto:run2_data --era Run2_2016_HIPM --eventcontent RAWRECO --datatier RAWRECO --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2016,TauAnalysis/MCEmbeddingTools/customisers.customiseSelecting --filein filelist:step1_dasquery.log --lumiToProcess step1_lumiRanges.log --fileout step2.root -n 200 --nThreads 32 +echo "################ Selection ################" +cmsDriver.py RECO \ +--step RAW2DIGI,L1Reco,RECO,PAT \ +--data \ +--scenario pp \ +--conditions auto:run2_data \ +--era Run2_2018 \ +--eventcontent RAWRECO \ +--datatier RAWRECO \ +--customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2018,\ +TauAnalysis/MCEmbeddingTools/customisers.customiseSelecting_Reselect \ +--filein $dataset \ +--fileout file:selection.root \ +-n -1 \ +--python_filename selection.py || die 'Failure during selecting step' $? +echo "################ LHE production and cleaning ################" +cmsDriver.py LHEprodandCLEAN \ +--step RAW2DIGI,RECO,PAT \ +--data \ +--scenario pp \ +--conditions auto:run2_data \ +--era Run2_2018 \ +--eventcontent RAWRECO \ +--datatier RAWRECO \ +--customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2018,\ +TauAnalysis/MCEmbeddingTools/customisers.customiseLHEandCleaning_Reselect \ +--filein file:selection.root \ +--fileout file:lhe_and_cleaned.root \ +-n -1 \ +--python_filename lheprodandcleaning.py || die 'Failure during LHE and Cleaning step' $? -## This is a PRE SKIMED dataset, so -echo "/store/user/swayand/Emmbeddingfiles/Emmbedding_testInput3.root" > file_list.txt +# Simulation (MC & Detector) +echo "################ Simulation (MC & Detector) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ +--step GEN,SIM,DIGI,L1,DIGI2RAW \ +--mc \ +--beamspot Realistic25ns13TeVEarly2018Collision \ +--geometry DB:Extended \ +--era Run2_2018 \ +--conditions auto:phase1_2018_realistic \ +--eventcontent RAWSIM \ +--datatier RAWSIM \ +--customise \ +TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_preHLT_Reselect \ +--filein file:lhe_and_cleaned.root \ +--fileout file:simulated_and_cleaned_prehlt.root \ +-n -1 \ +--python_filename generator_preHLT.py || die 'Failure during MC & Detector simulation step' $? +# Simulation (Trigger) +echo "################ Simulation (Trigger) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ +--step HLT:Fake2 \ +--mc \ +--beamspot Realistic25ns13TeVEarly2018Collision \ +--geometry DB:Extended \ +--era Run2_2018 \ +--conditions auto:phase1_2018_realistic \ +--eventcontent RAWSIM \ +--datatier RAWSIM \ +--customise \ +TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_HLT_Reselect \ +--filein file:simulated_and_cleaned_prehlt.root \ +--fileout file:simulated_and_cleaned_hlt.root \ +-n -1 \ +--python_filename generator_HLT.py || die 'Failure during Fake Trigger simulation step' $? -cmsDriver.py selecting -s RAW2DIGI,L1Reco,RECO,PAT --data --scenario pp --conditions auto:run2_data --era Run2_2016_HIPM --eventcontent RAWRECO --datatier RAWRECO --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2016,TauAnalysis/MCEmbeddingTools/customisers.customiseSelecting --filein filelist:file_list.txt --fileout file:selected.root --python_filename selecting.py -n 5 || die 'Failure during selecting step' $? +# Simulation (Reconstruction) +echo "################ Simulation (Reconstruction) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ +--step RAW2DIGI,L1Reco,RECO,RECOSIM \ +--mc \ +--beamspot Realistic25ns13TeVEarly2018Collision \ +--geometry DB:Extended \ +--era Run2_2018 \ +--conditions auto:phase1_2018_realistic \ +--eventcontent RAWRECOSIMHLT \ +--datatier RAW-RECO-SIM \ +--customise \ +TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_postHLT_Reselect \ +--filein file:simulated_and_cleaned_hlt.root \ +--fileout file:simulated_and_cleaned_posthlt.root \ +-n -1 \ +--python_filename generator_postHLT.py || die 'Failure during reconstruction simulation step' $? -cmsDriver.py LHEembeddingCLEAN --filein file:selected.root --fileout file:lhe_and_cleaned.root --data --scenario pp --conditions auto:run2_data --era Run2_2016_HIPM --eventcontent RAWRECO --datatier RAWRECO --step RAW2DIGI,RECO --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2016,TauAnalysis/MCEmbeddingTools/customisers.customiseLHEandCleaning -n -1 --python_filename lheprodandcleaning.py || die 'Failure during LHE and Cleaning step' $? +# Merging +echo "################ Merging ################" +cmsDriver.py PAT \ +--step PAT \ +--data \ +--scenario pp \ +--conditions auto:run2_data \ +--era Run2_2018 \ +--eventcontent MINIAODSIM \ +--datatier USER \ +--customise \ +TauAnalysis/MCEmbeddingTools/customisers.customiseMerging_Reselect \ +--filein file:simulated_and_cleaned_posthlt.root \ +--fileout file:merged.root \ +-n -1 \ +--python_filename merging.py || die 'Failure during the merging step' $? -### Do not run HLT in CMSSW_9_0_X so far since the RecoPixelVertexingPixelTrackFittingPlugins. seems not to work -cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py --filein file:lhe_and_cleaned.root --fileout file:simulated_and_cleaned.root --conditions auto:run2_mc --era Run2_2016 --eventcontent RAWRECO --step GEN,SIM,DIGI,L1,DIGI2RAW,RAW2DIGI,RECO --datatier RAWRECO --customise TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator --beamspot Realistic25ns13TeV2016Collision -n -1 --customise_commands "process.generator.nAttempts = cms.uint32(1000)\n" --python_filename simulation.py || die 'Failure during Simulation step' $? - -cmsDriver.py MERGE -s PAT --filein file:simulated_and_cleaned.root --fileout file:merged.root --era Run2_2016_HIPM --data --scenario pp --conditions auto:run2_data --eventcontent MINIAODSIM --datatier USER --customise TauAnalysis/MCEmbeddingTools/customisers.customiseMerging --customise_commands "process.patTrigger.processName = cms.string('SIMembedding')" -n -1 || die 'Failure during merging step' $? +# NanoAOD Production +echo "################ NanoAOD Production ################" +cmsDriver.py \ +--step NANO \ +--data \ +--conditions auto:run2_data \ +--era Run2_2018,run2_nanoAOD_106Xv2 \ +--eventcontent NANOAODSIM \ +--datatier NANOAODSIM \ +--customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \ +--filein file:merged.root \ +--fileout file:merged_nano.root \ +-n -1 \ +--python_filename embedding_nanoAOD.py || die 'Failure during the nanoAOD step' $? From 41944c07afb163d7da9b3c64b1a77aca07e83187 Mon Sep 17 00:00:00 2001 From: cwinter Date: Wed, 24 Jan 2024 11:19:18 +0100 Subject: [PATCH 55/58] add workflow unittests for each UL year --- .../MCEmbeddingTools/test/BuildFile.xml | 6 +- .../test/run_2016postVFPUL_workflow_tests.sh | 129 +++++++++++++++++ .../test/run_2016preVFPUL_workflow_tests.sh | 129 +++++++++++++++++ .../test/run_2017UL_workflow_tests.sh | 129 +++++++++++++++++ .../test/run_2018UL_workflow_tests.sh | 129 +++++++++++++++++ TauAnalysis/MCEmbeddingTools/test/runtests.sh | 130 ------------------ 6 files changed, 521 insertions(+), 131 deletions(-) create mode 100755 TauAnalysis/MCEmbeddingTools/test/run_2016postVFPUL_workflow_tests.sh create mode 100755 TauAnalysis/MCEmbeddingTools/test/run_2016preVFPUL_workflow_tests.sh create mode 100755 TauAnalysis/MCEmbeddingTools/test/run_2017UL_workflow_tests.sh create mode 100755 TauAnalysis/MCEmbeddingTools/test/run_2018UL_workflow_tests.sh delete mode 100755 TauAnalysis/MCEmbeddingTools/test/runtests.sh diff --git a/TauAnalysis/MCEmbeddingTools/test/BuildFile.xml b/TauAnalysis/MCEmbeddingTools/test/BuildFile.xml index a9f16abe0d0fe..1fc12a955bbc7 100644 --- a/TauAnalysis/MCEmbeddingTools/test/BuildFile.xml +++ b/TauAnalysis/MCEmbeddingTools/test/BuildFile.xml @@ -1 +1,5 @@ - + + + + + diff --git a/TauAnalysis/MCEmbeddingTools/test/run_2016postVFPUL_workflow_tests.sh b/TauAnalysis/MCEmbeddingTools/test/run_2016postVFPUL_workflow_tests.sh new file mode 100755 index 0000000000000..b8d690336bbe4 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/test/run_2016postVFPUL_workflow_tests.sh @@ -0,0 +1,129 @@ +#!/bin/bash +# This script runs all the steps of the embedding workflow +# author: Christian Winter (christian.winter@cern.ch) +# TODO: move the dataset to a more persistent and for cmssw accessible place than a private EOS user folder + +# print the exit status before exiting +function die { + echo $1: status $2 + exit $2 +} + +## This is a PRE SKIMED dataset +dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/2016_G-v1_RAW_preselected.root" + +echo "################ Selection ################" +cmsDriver.py RECO \ + --step RAW2DIGI,L1Reco,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2016 \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2016,TauAnalysis/MCEmbeddingTools/customisers.customiseSelecting_Reselect \ + --filein $dataset \ + --fileout file:selection.root \ + -n -1 \ + --python_filename selection.py || die 'Failure during selecting step' $? + +echo "################ LHE production and cleaning ################" +cmsDriver.py LHEprodandCLEAN \ + --step RAW2DIGI,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2016 \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2016,TauAnalysis/MCEmbeddingTools/customisers.customiseLHEandCleaning_Reselect \ + --filein file:selection.root \ + --fileout file:lhe_and_cleaned.root \ + -n -1 \ + --python_filename lheprodandcleaning.py || die 'Failure during LHE and Cleaning step' $? + +# Simulation (MC & Detector) +echo "################ Simulation (MC & Detector) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step GEN,SIM,DIGI,L1,DIGI2RAW \ + --mc \ + --beamspot Realistic25ns13TeV2016Collision \ + --geometry DB:Extended \ + --era Run2_2016 \ + --conditions auto:run2_mc \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_preHLT_Reselect \ + --filein file:lhe_and_cleaned.root \ + --fileout file:simulated_and_cleaned_prehlt.root \ + -n -1 \ + --python_filename generator_preHLT.py || die 'Failure during MC & Detector simulation step' $? + +# Simulation (Trigger) +echo "################ Simulation (Trigger) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step HLT:Fake2 \ + --mc \ + --beamspot Realistic25ns13TeV2016Collision \ + --geometry DB:Extended \ + --era Run2_2016 \ + --conditions auto:run2_mc \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_HLT_Reselect \ + --filein file:simulated_and_cleaned_prehlt.root \ + --fileout file:simulated_and_cleaned_hlt.root \ + -n -1 \ + --python_filename generator_HLT.py || die 'Failure during Fake Trigger simulation step' $? + +# Simulation (Reconstruction) +echo "################ Simulation (Reconstruction) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step RAW2DIGI,L1Reco,RECO,RECOSIM \ + --mc \ + --beamspot Realistic25ns13TeV2016Collision \ + --geometry DB:Extended \ + --era Run2_2016 \ + --conditions auto:run2_mc \ + --eventcontent RAWRECOSIMHLT \ + --datatier RAW-RECO-SIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_postHLT_Reselect \ + --filein file:simulated_and_cleaned_hlt.root \ + --fileout file:simulated_and_cleaned_posthlt.root \ + -n -1 \ + --python_filename generator_postHLT.py || die 'Failure during reconstruction simulation step' $? + +# Merging +echo "################ Merging ################" +cmsDriver.py PAT \ + --step PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2016 \ + --eventcontent MINIAODSIM \ + --datatier USER \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseMerging_Reselect \ + --filein file:simulated_and_cleaned_posthlt.root \ + --fileout file:merged.root \ + -n -1 \ + --python_filename merging.py || die 'Failure during the merging step' $? + +# NanoAOD Production +echo "################ NanoAOD Production ################" +cmsDriver.py \ + --step NANO \ + --data \ + --conditions auto:run2_data \ + --era Run2_2016,run2_nanoAOD_106Xv2 \ + --eventcontent NANOAODSIM \ + --datatier NANOAODSIM \ + --customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \ + --filein file:merged.root \ + --fileout file:merged_nano.root \ + -n -1 \ + --python_filename embedding_nanoAOD.py || die 'Failure during the nanoAOD step' $? diff --git a/TauAnalysis/MCEmbeddingTools/test/run_2016preVFPUL_workflow_tests.sh b/TauAnalysis/MCEmbeddingTools/test/run_2016preVFPUL_workflow_tests.sh new file mode 100755 index 0000000000000..4e1cad8b1de88 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/test/run_2016preVFPUL_workflow_tests.sh @@ -0,0 +1,129 @@ +#!/bin/bash +# This script runs all the steps of the embedding workflow +# author: Christian Winter (christian.winter@cern.ch) +# TODO: move the dataset to a more persistent and for cmssw accessible place than a private EOS user folder + +# print the exit status before exiting +function die { + echo $1: status $2 + exit $2 +} + +## This is a PRE SKIMED dataset +dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/2016_C-v2_RAW_preselected.root" + +echo "################ Selection ################" +cmsDriver.py RECO \ + --step RAW2DIGI,L1Reco,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2016_HIPM \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2016,TauAnalysis/MCEmbeddingTools/customisers.customiseSelecting_Reselect \ + --filein $dataset \ + --fileout file:selection.root \ + -n -1 \ + --python_filename selection.py || die 'Failure during selecting step' $? + +echo "################ LHE production and cleaning ################" +cmsDriver.py LHEprodandCLEAN \ + --step RAW2DIGI,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2016_HIPM \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2016,TauAnalysis/MCEmbeddingTools/customisers.customiseLHEandCleaning_Reselect \ + --filein file:selection.root \ + --fileout file:lhe_and_cleaned.root \ + -n -1 \ + --python_filename lheprodandcleaning.py || die 'Failure during LHE and Cleaning step' $? + +# Simulation (MC & Detector) +echo "################ Simulation (MC & Detector) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step GEN,SIM,DIGI,L1,DIGI2RAW \ + --mc \ + --beamspot Realistic25ns13TeV2016Collision \ + --geometry DB:Extended \ + --era Run2_2016_HIPM \ + --conditions auto:run2_mc_pre_vfp \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_preHLT_Reselect \ + --filein file:lhe_and_cleaned.root \ + --fileout file:simulated_and_cleaned_prehlt.root \ + -n -1 \ + --python_filename generator_preHLT.py || die 'Failure during MC & Detector simulation step' $? + +# Simulation (Trigger) +echo "################ Simulation (Trigger) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step HLT:Fake2 \ + --mc \ + --beamspot Realistic25ns13TeV2016Collision \ + --geometry DB:Extended \ + --era Run2_2016_HIPM \ + --conditions auto:run2_mc_pre_vfp \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_HLT_Reselect \ + --filein file:simulated_and_cleaned_prehlt.root \ + --fileout file:simulated_and_cleaned_hlt.root \ + -n -1 \ + --python_filename generator_HLT.py || die 'Failure during Fake Trigger simulation step' $? + +# Simulation (Reconstruction) +echo "################ Simulation (Reconstruction) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step RAW2DIGI,L1Reco,RECO,RECOSIM \ + --mc \ + --beamspot Realistic25ns13TeV2016Collision \ + --geometry DB:Extended \ + --era Run2_2016_HIPM \ + --conditions auto:run2_mc_pre_vfp \ + --eventcontent RAWRECOSIMHLT \ + --datatier RAW-RECO-SIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_postHLT_Reselect \ + --filein file:simulated_and_cleaned_hlt.root \ + --fileout file:simulated_and_cleaned_posthlt.root \ + -n -1 \ + --python_filename generator_postHLT.py || die 'Failure during reconstruction simulation step' $? + +# Merging +echo "################ Merging ################" +cmsDriver.py PAT \ + --step PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2016_HIPM \ + --eventcontent MINIAODSIM \ + --datatier USER \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseMerging_Reselect \ + --filein file:simulated_and_cleaned_posthlt.root \ + --fileout file:merged.root \ + -n -1 \ + --python_filename merging.py || die 'Failure during the merging step' $? + +# NanoAOD Production +echo "################ NanoAOD Production ################" +cmsDriver.py \ + --step NANO \ + --data \ + --conditions auto:run2_data \ + --era Run2_2016_HIPM,run2_nanoAOD_106Xv2 \ + --eventcontent NANOAODSIM \ + --datatier NANOAODSIM \ + --customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \ + --filein file:merged.root \ + --fileout file:merged_nano.root \ + -n -1 \ + --python_filename embedding_nanoAOD.py || die 'Failure during the nanoAOD step' $? diff --git a/TauAnalysis/MCEmbeddingTools/test/run_2017UL_workflow_tests.sh b/TauAnalysis/MCEmbeddingTools/test/run_2017UL_workflow_tests.sh new file mode 100755 index 0000000000000..4f15da73c2b06 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/test/run_2017UL_workflow_tests.sh @@ -0,0 +1,129 @@ +#!/bin/bash +# This script runs all the steps of the embedding workflow +# author: Christian Winter (christian.winter@cern.ch) +# TODO: move the dataset to a more persistent and for cmssw accessible place than a private EOS user folder + +# print the exit status before exiting +function die { + echo $1: status $2 + exit $2 +} + +## This is a PRE SKIMED dataset +dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/2017_B-v1_RAW_preselected.root" + +echo "################ Selection ################" +cmsDriver.py RECO \ + --step RAW2DIGI,L1Reco,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2017 \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2017,TauAnalysis/MCEmbeddingTools/customisers.customiseSelecting_Reselect \ + --filein $dataset \ + --fileout file:selection.root \ + -n -1 \ + --python_filename selection.py || die 'Failure during selecting step' $? + +echo "################ LHE production and cleaning ################" +cmsDriver.py LHEprodandCLEAN \ + --step RAW2DIGI,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2017 \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2017,TauAnalysis/MCEmbeddingTools/customisers.customiseLHEandCleaning_Reselect \ + --filein file:selection.root \ + --fileout file:lhe_and_cleaned.root \ + -n -1 \ + --python_filename lheprodandcleaning.py || die 'Failure during LHE and Cleaning step' $? + +# Simulation (MC & Detector) +echo "################ Simulation (MC & Detector) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step GEN,SIM,DIGI,L1,DIGI2RAW \ + --mc \ + --beamspot Realistic25ns13TeVEarly2017Collision \ + --geometry DB:Extended \ + --era Run2_2017 \ + --conditions auto:phase1_2017_realistic \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_preHLT_Reselect \ + --filein file:lhe_and_cleaned.root \ + --fileout file:simulated_and_cleaned_prehlt.root \ + -n -1 \ + --python_filename generator_preHLT.py || die 'Failure during MC & Detector simulation step' $? + +# Simulation (Trigger) +echo "################ Simulation (Trigger) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step HLT:Fake2 \ + --mc \ + --beamspot Realistic25ns13TeVEarly2017Collision \ + --geometry DB:Extended \ + --era Run2_2017 \ + --conditions auto:phase1_2017_realistic \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_HLT_Reselect \ + --filein file:simulated_and_cleaned_prehlt.root \ + --fileout file:simulated_and_cleaned_hlt.root \ + -n -1 \ + --python_filename generator_HLT.py || die 'Failure during Fake Trigger simulation step' $? + +# Simulation (Reconstruction) +echo "################ Simulation (Reconstruction) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step RAW2DIGI,L1Reco,RECO,RECOSIM \ + --mc \ + --beamspot Realistic25ns13TeVEarly2017Collision \ + --geometry DB:Extended \ + --era Run2_2017 \ + --conditions auto:phase1_2017_realistic \ + --eventcontent RAWRECOSIMHLT \ + --datatier RAW-RECO-SIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_postHLT_Reselect \ + --filein file:simulated_and_cleaned_hlt.root \ + --fileout file:simulated_and_cleaned_posthlt.root \ + -n -1 \ + --python_filename generator_postHLT.py || die 'Failure during reconstruction simulation step' $? + +# Merging +echo "################ Merging ################" +cmsDriver.py PAT \ + --step PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2017 \ + --eventcontent MINIAODSIM \ + --datatier USER \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseMerging_Reselect \ + --filein file:simulated_and_cleaned_posthlt.root \ + --fileout file:merged.root \ + -n -1 \ + --python_filename merging.py || die 'Failure during the merging step' $? + +# NanoAOD Production +echo "################ NanoAOD Production ################" +cmsDriver.py \ + --step NANO \ + --data \ + --conditions auto:run2_data \ + --era Run2_2017,run2_nanoAOD_106Xv2 \ + --eventcontent NANOAODSIM \ + --datatier NANOAODSIM \ + --customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \ + --filein file:merged.root \ + --fileout file:merged_nano.root \ + -n -1 \ + --python_filename embedding_nanoAOD.py || die 'Failure during the nanoAOD step' $? diff --git a/TauAnalysis/MCEmbeddingTools/test/run_2018UL_workflow_tests.sh b/TauAnalysis/MCEmbeddingTools/test/run_2018UL_workflow_tests.sh new file mode 100755 index 0000000000000..4ed1b4f542e21 --- /dev/null +++ b/TauAnalysis/MCEmbeddingTools/test/run_2018UL_workflow_tests.sh @@ -0,0 +1,129 @@ +#!/bin/bash +# This script runs all the steps of the embedding workflow +# author: Christian Winter (christian.winter@cern.ch) +# TODO: move the dataset to a more persistent and for cmssw accessible place than a private EOS user folder + +# print the exit status before exiting +function die { + echo $1: status $2 + exit $2 +} + +## This is a PRE SKIMED dataset +dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/2018_C-v2_RAW_preselected.root" + +echo "################ Selection ################" +cmsDriver.py RECO \ + --step RAW2DIGI,L1Reco,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2018 \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2018,TauAnalysis/MCEmbeddingTools/customisers.customiseSelecting_Reselect \ + --filein $dataset \ + --fileout file:selection.root \ + -n -1 \ + --python_filename selection.py || die 'Failure during selecting step' $? + +echo "################ LHE production and cleaning ################" +cmsDriver.py LHEprodandCLEAN \ + --step RAW2DIGI,RECO,PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2018 \ + --eventcontent RAWRECO \ + --datatier RAWRECO \ + --customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2018,TauAnalysis/MCEmbeddingTools/customisers.customiseLHEandCleaning_Reselect \ + --filein file:selection.root \ + --fileout file:lhe_and_cleaned.root \ + -n -1 \ + --python_filename lheprodandcleaning.py || die 'Failure during LHE and Cleaning step' $? + +# Simulation (MC & Detector) +echo "################ Simulation (MC & Detector) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step GEN,SIM,DIGI,L1,DIGI2RAW \ + --mc \ + --beamspot Realistic25ns13TeVEarly2018Collision \ + --geometry DB:Extended \ + --era Run2_2018 \ + --conditions auto:phase1_2018_realistic \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_preHLT_Reselect \ + --filein file:lhe_and_cleaned.root \ + --fileout file:simulated_and_cleaned_prehlt.root \ + -n -1 \ + --python_filename generator_preHLT.py || die 'Failure during MC & Detector simulation step' $? + +# Simulation (Trigger) +echo "################ Simulation (Trigger) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step HLT:Fake2 \ + --mc \ + --beamspot Realistic25ns13TeVEarly2018Collision \ + --geometry DB:Extended \ + --era Run2_2018 \ + --conditions auto:phase1_2018_realistic \ + --eventcontent RAWSIM \ + --datatier RAWSIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_HLT_Reselect \ + --filein file:simulated_and_cleaned_prehlt.root \ + --fileout file:simulated_and_cleaned_hlt.root \ + -n -1 \ + --python_filename generator_HLT.py || die 'Failure during Fake Trigger simulation step' $? + +# Simulation (Reconstruction) +echo "################ Simulation (Reconstruction) ################" +cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ + --step RAW2DIGI,L1Reco,RECO,RECOSIM \ + --mc \ + --beamspot Realistic25ns13TeVEarly2018Collision \ + --geometry DB:Extended \ + --era Run2_2018 \ + --conditions auto:phase1_2018_realistic \ + --eventcontent RAWRECOSIMHLT \ + --datatier RAW-RECO-SIM \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_postHLT_Reselect \ + --filein file:simulated_and_cleaned_hlt.root \ + --fileout file:simulated_and_cleaned_posthlt.root \ + -n -1 \ + --python_filename generator_postHLT.py || die 'Failure during reconstruction simulation step' $? + +# Merging +echo "################ Merging ################" +cmsDriver.py PAT \ + --step PAT \ + --data \ + --scenario pp \ + --conditions auto:run2_data \ + --era Run2_2018 \ + --eventcontent MINIAODSIM \ + --datatier USER \ + --customise \ + TauAnalysis/MCEmbeddingTools/customisers.customiseMerging_Reselect \ + --filein file:simulated_and_cleaned_posthlt.root \ + --fileout file:merged.root \ + -n -1 \ + --python_filename merging.py || die 'Failure during the merging step' $? + +# NanoAOD Production +echo "################ NanoAOD Production ################" +cmsDriver.py \ + --step NANO \ + --data \ + --conditions auto:run2_data \ + --era Run2_2018,run2_nanoAOD_106Xv2 \ + --eventcontent NANOAODSIM \ + --datatier NANOAODSIM \ + --customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \ + --filein file:merged.root \ + --fileout file:merged_nano.root \ + -n -1 \ + --python_filename embedding_nanoAOD.py || die 'Failure during the nanoAOD step' $? diff --git a/TauAnalysis/MCEmbeddingTools/test/runtests.sh b/TauAnalysis/MCEmbeddingTools/test/runtests.sh deleted file mode 100755 index c2c789b1ef228..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/test/runtests.sh +++ /dev/null @@ -1,130 +0,0 @@ -#!/bin/bash -# This script runs all the steps of the embedding workflow -# author: Christian Winter (christian.winter@cern.ch) -# TODO: move the dataset to a more persistent and for cmssw accessible place than a private EOS user folder - -# print the exit status before exiting -function die { echo $1: status $2 ; exit $2; } - - -## This is a PRE SKIMED dataset -dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/PreRAWskimmed.root" - -echo "################ Selection ################" -cmsDriver.py RECO \ ---step RAW2DIGI,L1Reco,RECO,PAT \ ---data \ ---scenario pp \ ---conditions auto:run2_data \ ---era Run2_2018 \ ---eventcontent RAWRECO \ ---datatier RAWRECO \ ---customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2018,\ -TauAnalysis/MCEmbeddingTools/customisers.customiseSelecting_Reselect \ ---filein $dataset \ ---fileout file:selection.root \ --n -1 \ ---python_filename selection.py || die 'Failure during selecting step' $? - -echo "################ LHE production and cleaning ################" -cmsDriver.py LHEprodandCLEAN \ ---step RAW2DIGI,RECO,PAT \ ---data \ ---scenario pp \ ---conditions auto:run2_data \ ---era Run2_2018 \ ---eventcontent RAWRECO \ ---datatier RAWRECO \ ---customise Configuration/DataProcessing/RecoTLR.customisePostEra_Run2_2018,\ -TauAnalysis/MCEmbeddingTools/customisers.customiseLHEandCleaning_Reselect \ ---filein file:selection.root \ ---fileout file:lhe_and_cleaned.root \ --n -1 \ ---python_filename lheprodandcleaning.py || die 'Failure during LHE and Cleaning step' $? - -# Simulation (MC & Detector) -echo "################ Simulation (MC & Detector) ################" -cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ ---step GEN,SIM,DIGI,L1,DIGI2RAW \ ---mc \ ---beamspot Realistic25ns13TeVEarly2018Collision \ ---geometry DB:Extended \ ---era Run2_2018 \ ---conditions auto:phase1_2018_realistic \ ---eventcontent RAWSIM \ ---datatier RAWSIM \ ---customise \ -TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_preHLT_Reselect \ ---filein file:lhe_and_cleaned.root \ ---fileout file:simulated_and_cleaned_prehlt.root \ --n -1 \ ---python_filename generator_preHLT.py || die 'Failure during MC & Detector simulation step' $? - -# Simulation (Trigger) -echo "################ Simulation (Trigger) ################" -cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ ---step HLT:Fake2 \ ---mc \ ---beamspot Realistic25ns13TeVEarly2018Collision \ ---geometry DB:Extended \ ---era Run2_2018 \ ---conditions auto:phase1_2018_realistic \ ---eventcontent RAWSIM \ ---datatier RAWSIM \ ---customise \ -TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_HLT_Reselect \ ---filein file:simulated_and_cleaned_prehlt.root \ ---fileout file:simulated_and_cleaned_hlt.root \ --n -1 \ ---python_filename generator_HLT.py || die 'Failure during Fake Trigger simulation step' $? - - -# Simulation (Reconstruction) -echo "################ Simulation (Reconstruction) ################" -cmsDriver.py TauAnalysis/MCEmbeddingTools/python/EmbeddingPythia8Hadronizer_cfi.py \ ---step RAW2DIGI,L1Reco,RECO,RECOSIM \ ---mc \ ---beamspot Realistic25ns13TeVEarly2018Collision \ ---geometry DB:Extended \ ---era Run2_2018 \ ---conditions auto:phase1_2018_realistic \ ---eventcontent RAWRECOSIMHLT \ ---datatier RAW-RECO-SIM \ ---customise \ -TauAnalysis/MCEmbeddingTools/customisers.customiseGenerator_postHLT_Reselect \ ---filein file:simulated_and_cleaned_hlt.root \ ---fileout file:simulated_and_cleaned_posthlt.root \ --n -1 \ ---python_filename generator_postHLT.py || die 'Failure during reconstruction simulation step' $? - -# Merging -echo "################ Merging ################" -cmsDriver.py PAT \ ---step PAT \ ---data \ ---scenario pp \ ---conditions auto:run2_data \ ---era Run2_2018 \ ---eventcontent MINIAODSIM \ ---datatier USER \ ---customise \ -TauAnalysis/MCEmbeddingTools/customisers.customiseMerging_Reselect \ ---filein file:simulated_and_cleaned_posthlt.root \ ---fileout file:merged.root \ --n -1 \ ---python_filename merging.py || die 'Failure during the merging step' $? - -# NanoAOD Production -echo "################ NanoAOD Production ################" -cmsDriver.py \ ---step NANO \ ---data \ ---conditions auto:run2_data \ ---era Run2_2018,run2_nanoAOD_106Xv2 \ ---eventcontent NANOAODSIM \ ---datatier NANOAODSIM \ ---customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \ ---filein file:merged.root \ ---fileout file:merged_nano.root \ --n -1 \ ---python_filename embedding_nanoAOD.py || die 'Failure during the nanoAOD step' $? From 12e24e3b352169e7bc35d00b98126e78a01abb86 Mon Sep 17 00:00:00 2001 From: cwinter Date: Mon, 5 Feb 2024 19:20:46 +0100 Subject: [PATCH 56/58] apply patches for code-checks and code-format as CI suggests --- TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc | 6 +++--- .../MCEmbeddingTools/plugins/DoubleCollectionMerger.cc | 8 ++++---- .../MCEmbeddingTools/plugins/DoubleCollectionMerger.h | 2 +- .../plugins/EmbeddingHltPixelVerticesProducer.cc | 8 ++++---- .../MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc | 4 ++-- TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc | 6 ++---- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc index b7dde02fa79a3..40c04b2052774 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc @@ -14,12 +14,12 @@ class DYToMuMuGenFilter : public edm::stream::EDFilter<> { public: - explicit DYToMuMuGenFilter(const edm::ParameterSet&); + explicit DYToMuMuGenFilter(const edm::ParameterSet &); static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); private: - bool filter(edm::Event&, const edm::EventSetup&) override; + bool filter(edm::Event &, const edm::EventSetup &) override; edm::InputTag inputTag_; edm::EDGetTokenT genParticleCollection_; @@ -34,7 +34,7 @@ DYToMuMuGenFilter::DYToMuMuGenFilter(const edm::ParameterSet &iConfig) { genParticleCollection_ = consumes(inputTag_); } -bool DYToMuMuGenFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) { +bool DYToMuMuGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { iEvent.getByToken(genParticleCollection_, gen_handle); for (unsigned int i = 0; i < gen_handle->size(); i++) { diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc index c75b6f76d06f5..0781333476b91 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc @@ -24,11 +24,11 @@ DoubleCollectionMerger::DoubleCollectionMerger(const edm::Parame inputs1_[inCollection.instance()].push_back(consumes(inCollection)); inputs2_[inCollection.instance()].push_back(consumes(inCollection)); } - for (auto toproduce : inputs1_) { + for (const auto &toproduce : inputs1_) { // std::cout<(toproduce.first); } - for (auto toproduce : inputs2_) { + for (const auto &toproduce : inputs2_) { // std::cout<(toproduce.first); } @@ -102,7 +102,7 @@ void DoubleCollectionMerger::fill_output_obj_digiflag( std::map::iterator it = output_map.find(detIdObject.rawId()); if (it == output_map.end()) { BaseHit1 *akt_flag_obj = &output_map[detIdObject.rawId()]; - T2 newSrFlag(*obj); + const T2 &newSrFlag(*obj); *akt_flag_obj = newSrFlag; } else { // re-determine flag @@ -145,7 +145,7 @@ void DoubleCollectionMerger::fill_output_obj_digiflag( std::map::iterator it = output_map.find(detIdObject.rawId()); if (it == output_map.end()) { BaseHit2 *akt_flag_obj = &output_map[detIdObject.rawId()]; - T4 newSrFlag(*obj); + const T4 &newSrFlag(*obj); *akt_flag_obj = newSrFlag; } else { // re-determine flag diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h index fc23b2d55315a..9bfd81c5d2d03 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h @@ -24,7 +24,7 @@ template class DoubleCollectionMerger : public edm::stream::EDProducer<> { public: explicit DoubleCollectionMerger(const edm::ParameterSet &); - ~DoubleCollectionMerger(); + ~DoubleCollectionMerger() override; private: void produce(edm::Event &, const edm::EventSetup &) override; diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc index 213610e150682..5ebbfe2589b96 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc @@ -43,14 +43,14 @@ class EmbeddingHltPixelVerticesProducer : public edm::stream::EDProducer<> { public: explicit EmbeddingHltPixelVerticesProducer(const edm::ParameterSet &); - ~EmbeddingHltPixelVerticesProducer(); + ~EmbeddingHltPixelVerticesProducer() override; static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); private: - virtual void beginStream(edm::StreamID) override; - virtual void produce(edm::Event &, const edm::EventSetup &) override; - virtual void endStream() override; + void beginStream(edm::StreamID) override; + void produce(edm::Event &, const edm::EventSetup &) override; + void endStream() override; edm::InputTag vertexPositionLabel; // edm::InputTag generalTracks; diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc b/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc index 1d0f39215697a..dd110d25e22ef 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc @@ -45,12 +45,12 @@ class MuMuForEmbeddingSelector : public edm::stream::EDProducer<> { public: - explicit MuMuForEmbeddingSelector(const edm::ParameterSet&); + explicit MuMuForEmbeddingSelector(const edm::ParameterSet &); static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); private: - void produce(edm::Event&, const edm::EventSetup&) override; + void produce(edm::Event &, const edm::EventSetup &) override; // ----------member data --------------------------- edm::EDGetTokenT> ZmumuCandidates_; diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc index 1c11f477bcd1f..1e4e333a20c54 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.cc @@ -191,8 +191,7 @@ void TrackMergeremb::merg_and_put( std::unique_ptr outTracks_ex = std::make_unique(); std::unique_ptr outTracks_exgsf = std::make_unique(); std::unique_ptr outTracks_rh = std::make_unique(); - std::unique_ptr outTracks_refs = - std::unique_ptr(new GsfTrackToTrackMapnew()); + std::unique_ptr outTracks_refs = std::make_unique(); auto rTrackExtras = iEvent.getRefBeforePut(); auto rTrackExtras_gsf = iEvent.getRefBeforePut(); @@ -260,8 +259,7 @@ void TrackMergeremb::merg_and_put( edm::Handle> seedViewsHandle; iEvent.getByToken(inputs_rElectronMergedSeedViews_, seedViewsHandle); - std::unique_ptr outTracks_ex_new = - std::unique_ptr(new reco::TrackExtraCollection()); + std::unique_ptr outTracks_ex_new = std::make_unique(); // fix track extras to new merged seeds for (typename reco::TrackExtraCollection::const_iterator tex = outTracks_ex->begin(); tex != outTracks_ex->end(); From ffeab60bc60bb894cd35add9a5508b8ae6ef912b Mon Sep 17 00:00:00 2001 From: cwinter Date: Wed, 14 Feb 2024 19:46:22 +0100 Subject: [PATCH 57/58] change root file dir in embedding tests --- .../MCEmbeddingTools/test/run_2016postVFPUL_workflow_tests.sh | 2 +- .../MCEmbeddingTools/test/run_2016preVFPUL_workflow_tests.sh | 2 +- TauAnalysis/MCEmbeddingTools/test/run_2017UL_workflow_tests.sh | 2 +- TauAnalysis/MCEmbeddingTools/test/run_2018UL_workflow_tests.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TauAnalysis/MCEmbeddingTools/test/run_2016postVFPUL_workflow_tests.sh b/TauAnalysis/MCEmbeddingTools/test/run_2016postVFPUL_workflow_tests.sh index b8d690336bbe4..44460e267c9dc 100755 --- a/TauAnalysis/MCEmbeddingTools/test/run_2016postVFPUL_workflow_tests.sh +++ b/TauAnalysis/MCEmbeddingTools/test/run_2016postVFPUL_workflow_tests.sh @@ -10,7 +10,7 @@ function die { } ## This is a PRE SKIMED dataset -dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/2016_G-v1_RAW_preselected.root" +dataset="root://eoscms.cern.ch//store/group/phys_tau/embedding_test_files/2016_G-v1_RAW_preselected.root" echo "################ Selection ################" cmsDriver.py RECO \ diff --git a/TauAnalysis/MCEmbeddingTools/test/run_2016preVFPUL_workflow_tests.sh b/TauAnalysis/MCEmbeddingTools/test/run_2016preVFPUL_workflow_tests.sh index 4e1cad8b1de88..7d9ef57444afa 100755 --- a/TauAnalysis/MCEmbeddingTools/test/run_2016preVFPUL_workflow_tests.sh +++ b/TauAnalysis/MCEmbeddingTools/test/run_2016preVFPUL_workflow_tests.sh @@ -10,7 +10,7 @@ function die { } ## This is a PRE SKIMED dataset -dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/2016_C-v2_RAW_preselected.root" +dataset="root://eoscms.cern.ch//store/group/phys_tau/embedding_test_files/2016_C-v2_RAW_preselected.root" echo "################ Selection ################" cmsDriver.py RECO \ diff --git a/TauAnalysis/MCEmbeddingTools/test/run_2017UL_workflow_tests.sh b/TauAnalysis/MCEmbeddingTools/test/run_2017UL_workflow_tests.sh index 4f15da73c2b06..c3a33688e0135 100755 --- a/TauAnalysis/MCEmbeddingTools/test/run_2017UL_workflow_tests.sh +++ b/TauAnalysis/MCEmbeddingTools/test/run_2017UL_workflow_tests.sh @@ -10,7 +10,7 @@ function die { } ## This is a PRE SKIMED dataset -dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/2017_B-v1_RAW_preselected.root" +dataset="root://eoscms.cern.ch//store/group/phys_tau/embedding_test_files/2017_B-v1_RAW_preselected.root" echo "################ Selection ################" cmsDriver.py RECO \ diff --git a/TauAnalysis/MCEmbeddingTools/test/run_2018UL_workflow_tests.sh b/TauAnalysis/MCEmbeddingTools/test/run_2018UL_workflow_tests.sh index 4ed1b4f542e21..31551064a911a 100755 --- a/TauAnalysis/MCEmbeddingTools/test/run_2018UL_workflow_tests.sh +++ b/TauAnalysis/MCEmbeddingTools/test/run_2018UL_workflow_tests.sh @@ -10,7 +10,7 @@ function die { } ## This is a PRE SKIMED dataset -dataset="root://eosuser.cern.ch//eos/user/c/cwinter/embedding_test_root_files/2018_C-v2_RAW_preselected.root" +dataset="root://eoscms.cern.ch//store/group/phys_tau/embedding_test_files/2018_C-v2_RAW_preselected.root" echo "################ Selection ################" cmsDriver.py RECO \ From a8eae9f4a2d73c32837fd8d4610ce1da51de0e74 Mon Sep 17 00:00:00 2001 From: Sebastian Brommer Date: Tue, 16 Apr 2024 10:24:12 +0200 Subject: [PATCH 58/58] PR to adress review comments (#3) * remove comments, set constants constant * remove CASTOR cleaner and merger * Remove single generator customize function. It is not used anymore since the generator step is splitted in 3 steps. * remove unneeded filters * optimize embedding correction calculation * optimize selector loops * format cpp code with scram build code-format --------- Co-authored-by: cwinter --- .../MCEmbeddingTools/plugins/CaloCleaner.cc | 26 +--- .../MCEmbeddingTools/plugins/CaloCleaner.h | 6 +- .../plugins/CollectionMerger.cc | 20 +-- .../plugins/CollectionMerger.h | 2 +- .../plugins/DYToElElGenFilter.cc | 82 ----------- .../plugins/DYToElTauGenFilter.cc | 133 ------------------ .../plugins/DYToMuMuGenFilter.cc | 84 ----------- .../plugins/DYToMuTauGenFilter.cc | 133 ------------------ .../plugins/DYToTauTauGenFilter.cc | 121 ---------------- .../plugins/DoubleCollectionMerger.cc | 18 +-- .../plugins/DoubleCollectionMerger.h | 2 +- .../EmbeddingHltPixelVerticesProducer.cc | 30 ---- .../plugins/EmbeddingLHEProducer.cc | 73 +++------- .../plugins/MuMuForEmbeddingSelector.cc | 22 ++- .../plugins/MuonDetCleaner.cc | 10 +- .../MCEmbeddingTools/plugins/MuonDetCleaner.h | 5 +- .../plugins/TrackMergeremb.cc | 27 +--- .../MCEmbeddingTools/plugins/TrackMergeremb.h | 7 +- .../plugins/TrackerCleaner.cc | 2 - .../python/DYToElElGenFilter_cfi.py | 7 - .../python/DYToElTauGenFilter_cfi.py | 6 - .../python/DYToMuMuGenFilter_cfi.py | 5 - .../python/DYToMuTauGenFilter_cfi.py | 6 - .../python/DYToTauTauGenFilter_cfi.py | 6 - .../MCEmbeddingTools/python/customisers.py | 66 --------- 25 files changed, 45 insertions(+), 854 deletions(-) delete mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc delete mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc delete mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc delete mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc delete mode 100644 TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc delete mode 100644 TauAnalysis/MCEmbeddingTools/python/DYToElElGenFilter_cfi.py delete mode 100644 TauAnalysis/MCEmbeddingTools/python/DYToElTauGenFilter_cfi.py delete mode 100644 TauAnalysis/MCEmbeddingTools/python/DYToMuMuGenFilter_cfi.py delete mode 100644 TauAnalysis/MCEmbeddingTools/python/DYToMuTauGenFilter_cfi.py delete mode 100644 TauAnalysis/MCEmbeddingTools/python/DYToTauTauGenFilter_cfi.py diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc index 482ebd8632658..af279da3cc966 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.cc @@ -1,7 +1,6 @@ #include "TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h" #include "DataFormats/EcalRecHit/interface/EcalRecHit.h" -#include "DataFormats/HcalRecHit/interface/CastorRecHit.h" #include "DataFormats/HcalRecHit/interface/HBHERecHit.h" #include "DataFormats/HcalRecHit/interface/HFRecHit.h" #include "DataFormats/HcalRecHit/interface/HORecHit.h" @@ -11,7 +10,6 @@ typedef CaloCleaner EcalRecHitColCleaner; typedef CaloCleaner HBHERecHitColCleaner; typedef CaloCleaner HFRecHitColCleaner; typedef CaloCleaner HORecHitColCleaner; -typedef CaloCleaner CastorRecHitColCleaner; typedef CaloCleaner ZDCRecHitColCleaner; template @@ -28,7 +26,6 @@ CaloCleaner::CaloCleaner(const edm::ParameterSet &iConfig) edm::ParameterSet parameters = iConfig.getParameter("TrackAssociatorParameters"); edm::ConsumesCollector iC = consumesCollector(); parameters_.loadParameters(parameters, iC); - // trackAssociator_.useDefaultPropagator(); } template @@ -49,8 +46,6 @@ void CaloCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) // Fill the correction map for (edm::View::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) { - // get the basic informaiton like fill reco mouon does - // RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc const reco::Track *track = nullptr; if (iMuon->track().isNonnull()) track = iMuon->track().get(); @@ -68,7 +63,6 @@ void CaloCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) for (auto input_ : inputs_) { std::unique_ptr recHitCollection_output(new RecHitCollection()); edm::Handle recHitCollection; - // iEvent.getByToken(input_.second[0], recHitCollection); iEvent.getByToken(input_.second, recHitCollection); for (typename RecHitCollection::const_iterator recHit = recHitCollection->begin(); recHit != recHitCollection->end(); @@ -83,14 +77,6 @@ void CaloCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) } else { recHitCollection_output->push_back(*recHit); } - /* For the inveted collection - if (correction_map[recHit->detid().rawId()] > 0){ - float new_energy = correction_map[recHit->detid().rawId()]; - if (new_energy < 0) new_energy =0; - T newRecHit(*recHit); - newRecHit.setEnergy(new_energy); - recHitCollection_output->push_back(newRecHit); - }*/ } // Save the new collection recHitCollection_output->sort(); @@ -104,8 +90,7 @@ void CaloCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) template void CaloCleaner::fill_correction_map(TrackDetMatchInfo *, std::map *) { - assert(0); // CV: make sure general function never gets called; - // always use template specializations + assert(0); } template <> @@ -120,7 +105,6 @@ void CaloCleaner::fill_correction_map(TrackDetMatchInfo *info, std:: for (std::vector::const_iterator hit = info->crossedEcalRecHits.begin(); hit != info->crossedEcalRecHits.end(); hit++) { - // (*cor_map) [(*hit)->detid().rawId()] +=(*hit)->energy(); (*cor_map)[(*hit)->detid().rawId()] = (*hit)->energy(); } } @@ -149,14 +133,9 @@ void CaloCleaner::fill_correction_map(TrackDetMatchInfo *info, std::ma return; // No corrections for HF } -template <> -void CaloCleaner::fill_correction_map(TrackDetMatchInfo *info, std::map *cor_map) { - return; // No corrections for Castor -} - template <> void CaloCleaner::fill_correction_map(TrackDetMatchInfo *info, std::map *cor_map) { - return; // No corrections for Castor + return; // No corrections for ZDC } DEFINE_FWK_MODULE(EcalRecHitColCleaner); @@ -164,5 +143,4 @@ DEFINE_FWK_MODULE(HBHERecHitColCleaner); DEFINE_FWK_MODULE(HORecHitColCleaner); // no need for cleaning outside of tracker, so just a copy of the old collection DEFINE_FWK_MODULE(HFRecHitColCleaner); -DEFINE_FWK_MODULE(CastorRecHitColCleaner); DEFINE_FWK_MODULE(ZDCRecHitColCleaner); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h index 7438d09bda3de..7a57c8d67fc49 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/CaloCleaner.h @@ -1,14 +1,12 @@ /** \class CaloCleaner * * Clean collections of calorimeter recHits - * (detectors supported at the moment: EB/EE, HB/HE and HO) + * (detectors supported: EB/EE, HB/HE and HO) * * \author Tomasz Maciej Frueboes; * Christian Veelken, LLR - * - * - * * Clean Up from STefan Wayand, KIT + * Clean Up from Christian Winter & Sebastian Brommer, KIT */ #ifndef TauAnalysis_MCEmbeddingTools_CaloCleaner_H #define TauAnalysis_MCEmbeddingTools_CaloCleaner_H diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc index 293e683c9a0fa..5f1629f0eaa48 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.cc @@ -51,7 +51,6 @@ typedef CollectionMerger, EcalRecHit> EcalRecH typedef CollectionMerger, HBHERecHit> HBHERecHitColMerger; typedef CollectionMerger, HFRecHit> HFRecHitColMerger; typedef CollectionMerger, HORecHit> HORecHitColMerger; -typedef CollectionMerger, CastorRecHit> CastorRecHitColMerger; typedef CollectionMerger, ZDCRecHit> ZDCRecHitColMerger; typedef CollectionMerger>, DTRecHit1DPair> DTRecHitColMerger; @@ -67,7 +66,6 @@ CollectionMerger::CollectionMerger(const edm::ParameterSet &iConfig) { willconsume(iConfig); for (const auto &toproduce : inputs_) { std::string alias(iConfig.getParameter("@module_label")); - // std::cout<::fill_output_obj_seed(edm::Event &iEvent, edm::Handle track_new_col; iEvent.getByToken(inputs_fixtrackcol_, track_new_col); - std::map - simple_track_to_track_map; // I didn't find a more elegant way, so just build a good old fassion std::map + std::map simple_track_to_track_map; for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; @@ -285,8 +282,7 @@ template void CollectionMerger::fill_output_obj(edm::Event &iEvent, std::unique_ptr &output, std::vector> &inputCollections) { - assert(0); // CV: make sure general function never gets called; - // always use template specializations + assert(0); } // Start with the Tracker collections @@ -306,7 +302,6 @@ void CollectionMerger, SiStripCluster>::fil fill_output_obj_tracker(output, inputCollections); } -// Next are the Calo entries template <> void CollectionMerger, EcalRecHit>::fill_output_obj( edm::Event &iEvent, @@ -339,14 +334,6 @@ void CollectionMerger, HORecHit>::fill_output_ob fill_output_obj_calo(output, inputCollections); } -template <> -void CollectionMerger, CastorRecHit>::fill_output_obj( - edm::Event &iEvent, - std::unique_ptr &output, - std::vector> &inputCollections) { - fill_output_obj_calo(output, inputCollections); -} - template <> void CollectionMerger, ZDCRecHit>::fill_output_obj( edm::Event &iEvent, @@ -355,7 +342,6 @@ void CollectionMerger, ZDCRecHit>::fill_output_ fill_output_obj_calo(output, inputCollections); } -// Here the Muon Chamber template <> void CollectionMerger>, DTRecHit1DPair>::fill_output_obj( edm::Event &iEvent, @@ -380,7 +366,6 @@ void CollectionMerger>, RPCRec fill_output_obj_muonchamber(output, inputCollections); } -// Here Electron Seeds template <> void CollectionMerger, reco::ElectronSeed>::fill_output_obj( edm::Event &iEvent, @@ -399,7 +384,6 @@ DEFINE_FWK_MODULE(EcalRecHitColMerger); DEFINE_FWK_MODULE(HBHERecHitColMerger); DEFINE_FWK_MODULE(HFRecHitColMerger); DEFINE_FWK_MODULE(HORecHitColMerger); -DEFINE_FWK_MODULE(CastorRecHitColMerger); DEFINE_FWK_MODULE(ZDCRecHitColMerger); DEFINE_FWK_MODULE(DTRecHitColMerger); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h index 9835cd3349aa0..a6ce870072870 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/CollectionMerger.h @@ -3,6 +3,7 @@ * \author Stefan Wayand; * Christian Veelken, LLR * + * Clean Up from Christian Winter & Sebastian Brommer, KIT */ #ifndef TauAnalysis_MCEmbeddingTools_CollectionMerger_H #define TauAnalysis_MCEmbeddingTools_CollectionMerger_H @@ -35,7 +36,6 @@ #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h" #include "DataFormats/TrackerRecHit2D/interface/OmniClusterRef.h" -// #include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h" #include #include #include diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc deleted file mode 100644 index 453de52082d35..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToElElGenFilter.cc +++ /dev/null @@ -1,82 +0,0 @@ -#include "DataFormats/Candidate/interface/Candidate.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/HepMCCandidate/interface/GenParticle.h" -#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Utilities/interface/InputTag.h" - -#include "FWCore/Framework/interface/stream/EDFilter.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -class DYToElElGenFilter : public edm::stream::EDFilter<> { -public: - explicit DYToElElGenFilter(const edm::ParameterSet &); - ~DYToElElGenFilter() override; - - static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - -private: - void beginStream(edm::StreamID) override; - bool filter(edm::Event &, const edm::EventSetup &) override; - void endStream() override; - - edm::InputTag inputTag_; - edm::EDGetTokenT genParticleCollection_; - - edm::Handle gen_handle; - - // virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; - // virtual void endRun(edm::Run const&, edm::EventSetup const&) override; - // virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - // virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - - // ----------member data --------------------------- -}; - -DYToElElGenFilter::DYToElElGenFilter(const edm::ParameterSet &iConfig) { - inputTag_ = iConfig.getParameter("inputTag"); - genParticleCollection_ = consumes(inputTag_); -} - -DYToElElGenFilter::~DYToElElGenFilter() {} - -bool DYToElElGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { - iEvent.getByToken(genParticleCollection_, gen_handle); - - for (unsigned int i = 0; i < gen_handle->size(); i++) { - const reco::GenParticle gen_particle = (*gen_handle)[i]; - // Check if Z Boson decayed into two leptons - if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { - // Check if daugther particles are Electrons - if (std::abs(gen_particle.daughter(0)->pdgId()) == 11 && std::abs(gen_particle.daughter(1)->pdgId()) == 11 && - std::abs(gen_particle.daughter(0)->eta()) < 2.6 && std::abs(gen_particle.daughter(1)->eta()) < 2.6 && - gen_particle.daughter(0)->pt() > 7 && gen_particle.daughter(1)->pt() > 7) { - edm::LogPrint("") << "Electron Event ! "; - return true; - } else { - return false; - } - } - } - return false; -} -// ------------ method called once each stream before processing any runs, lumis or events ------------ -void DYToElElGenFilter::beginStream(edm::StreamID) {} - -// ------------ method called once each stream after processing all runs, lumis and events ------------ -void DYToElElGenFilter::endStream() {} - -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void DYToElElGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { - // The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); -} - -DEFINE_FWK_MODULE(DYToElElGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc deleted file mode 100644 index ddd9c79569f5b..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToElTauGenFilter.cc +++ /dev/null @@ -1,133 +0,0 @@ -#include "DataFormats/Candidate/interface/Candidate.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/HepMCCandidate/interface/GenParticle.h" -#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Utilities/interface/InputTag.h" - -#include "FWCore/Framework/interface/stream/EDFilter.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -class DYToElTauGenFilter : public edm::stream::EDFilter<> { -public: - explicit DYToElTauGenFilter(const edm::ParameterSet &); - ~DYToElTauGenFilter() override; - - static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - -private: - void beginStream(edm::StreamID) override; - bool filter(edm::Event &, const edm::EventSetup &) override; - void endStream() override; - bool leptondecay(const reco::Candidate *d, int depth); - bool electrondecay(const reco::Candidate *d, int depth); - - edm::InputTag inputTag_; - edm::EDGetTokenT genParticleCollection_; - edm::Handle gen_handle; -}; - -DYToElTauGenFilter::DYToElTauGenFilter(const edm::ParameterSet &iConfig) { - inputTag_ = iConfig.getParameter("inputTag"); - genParticleCollection_ = consumes(inputTag_); -} - -DYToElTauGenFilter::~DYToElTauGenFilter() {} - -bool DYToElTauGenFilter::leptondecay(const reco::Candidate *d, int depth) { - // returns true if the event has an leptonic decay - // Debug Output - // std::cout << std::string(4*depth, '-') << "---Hadroncheck-" << std::endl; - // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; - // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; - // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; - // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; - bool check = false; - if (d->status() != 1) { - if (d->numberOfDaughters() == 3) { - if (std::abs(d->daughter(0)->pdgId()) == 14 || std::abs(d->daughter(1)->pdgId()) == 14 || - std::abs(d->daughter(2)->pdgId()) == 14 || std::abs(d->daughter(0)->pdgId()) == 12 || - std::abs(d->daughter(1)->pdgId()) == 12 || std::abs(d->daughter(2)->pdgId()) == 12) - check = true; - } else if (d->numberOfDaughters() > 3) - return false; - if (d->numberOfDaughters() < 4) { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { - // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; - int new_depth = depth + 1; - if (leptondecay(d->daughter(k), new_depth) == true) - check = true; - } - } - } - return check; -} -bool DYToElTauGenFilter::electrondecay(const reco::Candidate *d, int depth) { - // returns true if the event has an electron decay - bool check = false; - if (d->status() != 1) { - if (d->numberOfDaughters() == 3) { - if (std::abs(d->daughter(0)->pdgId()) == 12 || std::abs(d->daughter(1)->pdgId()) == 12 || - std::abs(d->daughter(2)->pdgId()) == 12) - check = true; - } else if (d->numberOfDaughters() > 3) - return false; - if (d->numberOfDaughters() < 4) { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { - int new_depth = depth + 1; - if (electrondecay(d->daughter(k), new_depth) == true) - check = true; - } - } - } - return check; -} - -bool DYToElTauGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { - iEvent.getByToken(genParticleCollection_, gen_handle); - - for (unsigned int i = 0; i < gen_handle->size(); i++) { - const reco::GenParticle gen_particle = (*gen_handle)[i]; - // Check if Z Boson decayed into two leptons - if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { - // Check if daugther particles are taus - // From Generator: Mu.Pt > 18 && Had.Pt > 25 && Mu.Eta < 2.1 - if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 && std::abs(gen_particle.daughter(0)->eta()) < 2.1 && - gen_particle.daughter(0)->pt() > 25 && gen_particle.daughter(1)->pt() > 18) { - bool had_1 = !DYToElTauGenFilter::leptondecay(gen_particle.daughter(0), 1); - bool el_2 = DYToElTauGenFilter::electrondecay(gen_particle.daughter(1), 1); - bool had_2 = !DYToElTauGenFilter::leptondecay(gen_particle.daughter(1), 1); - bool el_1 = DYToElTauGenFilter::electrondecay(gen_particle.daughter(0), 1); - - std::cout << had_1 << " & " << el_2 << " / " << had_2 << " & " << el_1 << " |" << std::endl; - if ((had_1 && el_2) || (had_2 && el_1)) { - std::cout << "Hadronic Decay Check was positive" << std::endl; - return true; - } - std::cout << "Hadronic Decay Check was negative" << std::endl; - } - return false; - } - } - return false; -} -// ------------ method called once each stream before processing any runs, lumis or events ------------ -void DYToElTauGenFilter::beginStream(edm::StreamID) {} - -// ------------ method called once each stream after processing all runs, lumis and events ------------ -void DYToElTauGenFilter::endStream() {} - -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void DYToElTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { - // The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); -} - -DEFINE_FWK_MODULE(DYToElTauGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc deleted file mode 100644 index 40c04b2052774..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuMuGenFilter.cc +++ /dev/null @@ -1,84 +0,0 @@ -#include "DataFormats/Candidate/interface/Candidate.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/HepMCCandidate/interface/GenParticle.h" -#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Utilities/interface/InputTag.h" - -#include "FWCore/Framework/interface/stream/EDFilter.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -class DYToMuMuGenFilter : public edm::stream::EDFilter<> { -public: - explicit DYToMuMuGenFilter(const edm::ParameterSet &); - - static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - -private: - bool filter(edm::Event &, const edm::EventSetup &) override; - - edm::InputTag inputTag_; - edm::EDGetTokenT genParticleCollection_; - - edm::Handle gen_handle; - - // ----------member data --------------------------- -}; - -DYToMuMuGenFilter::DYToMuMuGenFilter(const edm::ParameterSet &iConfig) { - inputTag_ = iConfig.getParameter("inputTag"); - genParticleCollection_ = consumes(inputTag_); -} - -bool DYToMuMuGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { - iEvent.getByToken(genParticleCollection_, gen_handle); - - for (unsigned int i = 0; i < gen_handle->size(); i++) { - const reco::GenParticle gen_particle = (*gen_handle)[i]; - // Check if Z Boson decayed into two leptons - if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { - // Debug output - // std::cout << "pdgId" << gen_particle.pdgId() << std::endl; - // std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; - // std::cout << "Dau1" << gen_particle->daughters->at(0).pdgId() << std::endl; - // std::cout << "Dau2" << gen_particle.numberOfDaughters() << std::endl; - // std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; - // std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; - // std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; - - // Check if daugther particles are muons - if (std::abs(gen_particle.daughter(0)->pdgId()) == 13 && std::abs(gen_particle.daughter(0)->eta()) < 2.6 && - std::abs(gen_particle.daughter(1)->eta()) < 2.6 && gen_particle.daughter(0)->pt() > 7 && - gen_particle.daughter(1)->pt() > 7) { - // std::cout << "pdgId" << gen_particle.pdgId() << std::endl; - // std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; - // std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; - // std::cout << "Dau1 pt " << gen_particle.daughter(0)->pt() << std::endl; - // std::cout << "Dau1 pt " << gen_particle.daughter(0)->eta() << std::endl; - // std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; - // std::cout << "Dau2 pt " << gen_particle.daughter(1)->pt() << std::endl; - // std::cout << "Dau2 pt " << gen_particle.daughter(1)->eta() << std::endl; - // std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; - return true; - } else { - return false; - } - } - } - return false; -} - -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void DYToMuMuGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { - // The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); -} - -DEFINE_FWK_MODULE(DYToMuMuGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc deleted file mode 100644 index 545bb090d7d99..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToMuTauGenFilter.cc +++ /dev/null @@ -1,133 +0,0 @@ -#include "DataFormats/Candidate/interface/Candidate.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/HepMCCandidate/interface/GenParticle.h" -#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Utilities/interface/InputTag.h" - -#include "FWCore/Framework/interface/stream/EDFilter.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -class DYToMuTauGenFilter : public edm::stream::EDFilter<> { -public: - explicit DYToMuTauGenFilter(const edm::ParameterSet &); - ~DYToMuTauGenFilter() override; - - static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - -private: - void beginStream(edm::StreamID) override; - bool filter(edm::Event &, const edm::EventSetup &) override; - void endStream() override; - bool leptondecay(const reco::Candidate *d, int depth); - bool muondecay(const reco::Candidate *d, int depth); - - edm::InputTag inputTag_; - edm::EDGetTokenT genParticleCollection_; - edm::Handle gen_handle; -}; - -DYToMuTauGenFilter::DYToMuTauGenFilter(const edm::ParameterSet &iConfig) { - inputTag_ = iConfig.getParameter("inputTag"); - genParticleCollection_ = consumes(inputTag_); -} - -DYToMuTauGenFilter::~DYToMuTauGenFilter() {} - -bool DYToMuTauGenFilter::leptondecay(const reco::Candidate *d, int depth) { - // returns true if the event has an leptonic decay - // Debug Output - // std::cout << std::string(4*depth, '-') << "---Hadroncheck-" << std::endl; - // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; - // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; - // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; - // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; - bool check = false; - if (d->status() != 1) { - if (d->numberOfDaughters() == 3) { - if (std::abs(d->daughter(0)->pdgId()) == 14 || std::abs(d->daughter(1)->pdgId()) == 14 || - std::abs(d->daughter(2)->pdgId()) == 14 || std::abs(d->daughter(0)->pdgId()) == 12 || - std::abs(d->daughter(1)->pdgId()) == 12 || std::abs(d->daughter(2)->pdgId()) == 12) - check = true; - } else if (d->numberOfDaughters() > 3) - return false; - if (d->numberOfDaughters() < 4) { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { - // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; - int new_depth = depth + 1; - if (leptondecay(d->daughter(k), new_depth) == true) - check = true; - } - } - } - return check; -} -bool DYToMuTauGenFilter::muondecay(const reco::Candidate *d, int depth) { - // returns true if the event has an muon decay - bool check = false; - if (d->status() != 1) { - if (d->numberOfDaughters() == 3) { - if (std::abs(d->daughter(0)->pdgId()) == 14 || std::abs(d->daughter(1)->pdgId()) == 14 || - std::abs(d->daughter(2)->pdgId()) == 14) - check = true; - } else if (d->numberOfDaughters() > 3) - return false; - if (d->numberOfDaughters() < 4) { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { - int new_depth = depth + 1; - if (muondecay(d->daughter(k), new_depth) == true) - check = true; - } - } - } - return check; -} - -bool DYToMuTauGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { - iEvent.getByToken(genParticleCollection_, gen_handle); - - for (unsigned int i = 0; i < gen_handle->size(); i++) { - const reco::GenParticle gen_particle = (*gen_handle)[i]; - // Check if Z Boson decayed into two leptons - if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { - // Check if daugther particles are taus - // From Generator: Mu.Pt > 18 && Had.Pt > 25 && Mu.Eta < 2.1 - if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 && std::abs(gen_particle.daughter(0)->eta()) < 2.1 && - gen_particle.daughter(0)->pt() > 25 && gen_particle.daughter(1)->pt() > 18) { - bool had_1 = !DYToMuTauGenFilter::leptondecay(gen_particle.daughter(0), 1); - bool mu_2 = DYToMuTauGenFilter::muondecay(gen_particle.daughter(1), 1); - bool had_2 = !DYToMuTauGenFilter::leptondecay(gen_particle.daughter(1), 1); - bool mu_1 = DYToMuTauGenFilter::muondecay(gen_particle.daughter(0), 1); - - std::cout << had_1 << " & " << mu_2 << " / " << had_2 << " & " << mu_1 << " |" << std::endl; - if ((had_1 && mu_2) || (had_2 && mu_1)) { - std::cout << "Hadronic Decay Check was positive" << std::endl; - return true; - } - std::cout << "Hadronic Decay Check was negative" << std::endl; - } - return false; - } - } - return false; -} -// ------------ method called once each stream before processing any runs, lumis or events ------------ -void DYToMuTauGenFilter::beginStream(edm::StreamID) {} - -// ------------ method called once each stream after processing all runs, lumis and events ------------ -void DYToMuTauGenFilter::endStream() {} - -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void DYToMuTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { - // The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); -} - -DEFINE_FWK_MODULE(DYToMuTauGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc b/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc deleted file mode 100644 index bece7750fc4bc..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/plugins/DYToTauTauGenFilter.cc +++ /dev/null @@ -1,121 +0,0 @@ -#include "DataFormats/Candidate/interface/Candidate.h" -#include "DataFormats/Candidate/interface/LeafCandidate.h" -#include "DataFormats/HepMCCandidate/interface/GenParticle.h" -#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Utilities/interface/InputTag.h" - -#include "FWCore/Framework/interface/stream/EDFilter.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -class DYToTauTauGenFilter : public edm::stream::EDFilter<> { -public: - explicit DYToTauTauGenFilter(const edm::ParameterSet &); - ~DYToTauTauGenFilter() override; - - static void fillDescriptions(edm::ConfigurationDescriptions &descriptions); - -private: - void beginStream(edm::StreamID) override; - bool filter(edm::Event &, const edm::EventSetup &) override; - void endStream() override; - - edm::InputTag inputTag_; - edm::EDGetTokenT genParticleCollection_; - - edm::Handle gen_handle; - - // virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; - // virtual void endRun(edm::Run const&, edm::EventSetup const&) override; - // virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - // virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - - // ----------member data --------------------------- -}; - -DYToTauTauGenFilter::DYToTauTauGenFilter(const edm::ParameterSet &iConfig) { - inputTag_ = iConfig.getParameter("inputTag"); - genParticleCollection_ = consumes(inputTag_); -} - -DYToTauTauGenFilter::~DYToTauTauGenFilter() {} - -bool photoncheck(const reco::Candidate *d, int depth) { - // Debug Output - // std::cout << std::string(4*depth, '-') << "-----------------" << std::endl; - // std::cout << std::string(4*depth, '-') << "| Depth " << depth << std::endl; - // std::cout << std::string(4*depth, '-') << "| ID: " << d->pdgId() << std::endl; - // std::cout << std::string(4*depth, '-') << "| Status: " << d->status() << std::endl; - // std::cout << std::string(4*depth, '-') << "| NDaughters: " << d->numberOfDaughters()<< std::endl; - bool check = false; - if (d->status() != 1) { - if (d->numberOfDaughters() == 3) { - if (std::abs(d->daughter(0)->pdgId()) == 14 || std::abs(d->daughter(1)->pdgId()) == 14 || - std::abs(d->daughter(2)->pdgId()) == 14 || std::abs(d->daughter(0)->pdgId()) == 12 || - std::abs(d->daughter(1)->pdgId()) == 12 || std::abs(d->daughter(2)->pdgId()) == 12) { - check = true; - } - } else if (d->numberOfDaughters() > 3) - return false; - if (d->numberOfDaughters() < 4) { - for (unsigned int k = 0; k < d->numberOfDaughters(); k++) { - // std::cout << std::string(4*depth, '-') << "| Daughter Number " << k << std::endl; - int new_depth = depth + 1; - if (photoncheck(d->daughter(k), new_depth) == true) - check = true; - } - } - } - return check; -} - -bool DYToTauTauGenFilter::filter(edm::Event &iEvent, const edm::EventSetup &iSetup) { - iEvent.getByToken(genParticleCollection_, gen_handle); - - for (unsigned int i = 0; i < gen_handle->size(); i++) { - const reco::GenParticle gen_particle = (*gen_handle)[i]; - // Check if Z Boson decayed into two leptons - if (gen_particle.pdgId() == 23 && gen_particle.numberOfDaughters() == 2) { - // Debug output - // std::cout << "pdgId" << gen_particle.pdgId() << std::endl; - // std::cout << "nDau" << gen_particle.numberOfDaughters() << std::endl; - // std::cout << "Dau1 " << gen_particle.daughter(0)->pdgId() << std::endl; - // std::cout << "Dau2 " << gen_particle.daughter(1)->pdgId() << std::endl; - // std::cout << gen_particle.daughter(1)->pdgId()+gen_particle.daughter(0)->pdgId() << std::endl; - - // Check if daugther particles are taus - if (std::abs(gen_particle.daughter(0)->pdgId()) == 15 && std::abs(gen_particle.daughter(0)->eta()) < 2.3 && - std::abs(gen_particle.daughter(1)->eta()) < 2.3 && - ((gen_particle.daughter(0)->pt() > 30 && gen_particle.daughter(1)->pt() > 35) || - (gen_particle.daughter(0)->pt() > 35 && gen_particle.daughter(1)->pt() > 30))) { - if (!photoncheck(gen_particle.daughter(0), 1) && !photoncheck(gen_particle.daughter(1), 1)) { - // std::cout << "Hadronic Decay Check was positive" << std::endl; - return true; - } - // std::cout << "Hadronic Decay Check was negative" << std::endl; - } - return false; - } - } - return false; -} -// ------------ method called once each stream before processing any runs, lumis or events ------------ -void DYToTauTauGenFilter::beginStream(edm::StreamID) {} - -// ------------ method called once each stream after processing all runs, lumis and events ------------ -void DYToTauTauGenFilter::endStream() {} - -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void DYToTauTauGenFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) { - // The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); -} - -DEFINE_FWK_MODULE(DYToTauTauGenFilter); diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc index 0781333476b91..a2eb74544b976 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.cc @@ -25,11 +25,9 @@ DoubleCollectionMerger::DoubleCollectionMerger(const edm::Parame inputs2_[inCollection.instance()].push_back(consumes(inCollection)); } for (const auto &toproduce : inputs1_) { - // std::cout<(toproduce.first); } for (const auto &toproduce : inputs2_) { - // std::cout<(toproduce.first); } } @@ -41,16 +39,11 @@ DoubleCollectionMerger::~DoubleCollectionMerger() { template void DoubleCollectionMerger::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) { - // std::cout << "DoubleCollectionMerger::produce" << std::endl; for (auto input_ : inputs1_) { - // std::cout << "input_.first()=" << input_.first << std::endl; - // std::cout << "input_.second.size()=" << input_.second.size() << std::endl; std::unique_ptr output(new MergeCollection1()); std::vector> inputCollections; inputCollections.resize(input_.second.size()); for (unsigned id = 0; id < input_.second.size(); id++) { - // std::cout << "input_.second[id]=" << input_.second[id] << std::endl; - // std::cout << "input_.second[id]=" << id << std::endl; iEvent.getByToken(input_.second[id], inputCollections[id]); } fill_output_obj(output, inputCollections); @@ -58,14 +51,10 @@ void DoubleCollectionMerger::produce(edm::Event &iEvent, const e } for (auto input_ : inputs2_) { - // std::cout << "input_.first()=" << input_.first << std::endl; - // std::cout << "input_.second.size()=" << input_.second.size() << std::endl; std::unique_ptr output(new MergeCollection2()); std::vector> inputCollections; inputCollections.resize(input_.second.size()); for (unsigned id = 0; id < input_.second.size(); id++) { - // std::cout << "input_.second[id]=" << input_.second[id] << std::endl; - // std::cout << "input_.second[id]=" << id << std::endl; iEvent.getByToken(input_.second[id], inputCollections[id]); } fill_output_obj(output, inputCollections); @@ -73,19 +62,16 @@ void DoubleCollectionMerger::produce(edm::Event &iEvent, const e } } -// Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections template void DoubleCollectionMerger::fill_output_obj( std::unique_ptr &output, std::vector> &inputCollections) { - assert(0); // CV: make sure general function never gets called; - // always use template specializations + assert(0); } template void DoubleCollectionMerger::fill_output_obj( std::unique_ptr &output, std::vector> &inputCollections) { - assert(0); // CV: make sure general function never gets called; - // always use template specializations + assert(0); } template diff --git a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h index 9bfd81c5d2d03..89fbd4af7b9c6 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/DoubleCollectionMerger.h @@ -2,6 +2,7 @@ * * \author Per Ahrens * + * Clean Up from Christian Winter & Sebastian Brommer, KIT */ #ifndef TauAnalysis_MCEmbeddingTools_DoubleCollectionMerger_H #define TauAnalysis_MCEmbeddingTools_DoubleCollectionMerger_H @@ -15,7 +16,6 @@ #include "DataFormats/Common/interface/DetSetVectorNew.h" #include "DataFormats/Common/interface/SortedCollection.h" -// #include "TauAnalysis/MCEmbeddingTools/interface/embeddingAuxFunctions.h" #include #include #include diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc index 5ebbfe2589b96..0569afd397315 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingHltPixelVerticesProducer.cc @@ -52,7 +52,6 @@ class EmbeddingHltPixelVerticesProducer : public edm::stream::EDProducer<> { void produce(edm::Event &, const edm::EventSetup &) override; void endStream() override; edm::InputTag vertexPositionLabel; - // edm::InputTag generalTracks; // ----------member data --------------------------- }; @@ -61,10 +60,6 @@ EmbeddingHltPixelVerticesProducer::EmbeddingHltPixelVerticesProducer(const edm:: vertexPositionLabel = edm::InputTag("externalLHEProducer", "vertexPosition"); consumes(vertexPositionLabel); produces(); - - // generalTracks = iConfig.getParameter("TrackLabel"); - // consumes(generalTracks); - // consumes(generalTracks); } EmbeddingHltPixelVerticesProducer::~EmbeddingHltPixelVerticesProducer() {} @@ -75,38 +70,13 @@ void EmbeddingHltPixelVerticesProducer::produce(edm::Event &iEvent, const edm::E std::unique_ptr embeddingVertex(new reco::VertexCollection); Handle vertex_position; iEvent.getByLabel(vertexPositionLabel, vertex_position); - // edm::LogPrint("") << "externalLHEProducer Vertex (" << vertex_position.product()->x() << "," << vertex_position.product()->y() << "," << vertex_position.product()->z() << ")"; math::XYZPoint genVertex = math::XYZPoint(vertex_position.product()->x(), vertex_position.product()->y(), vertex_position.product()->z()); math::Error<3>::type Error; - // additionally, get the general Tracks: - // edm::Handle tks; - // iEvent.getByLabel(generalTracks, tks); - // edm::LogPrint("") << "Loaded " << tks->size() << " tracks:"; - - // edm::Handle tks_ref; - // iEvent.getByLabel(generalTracks, tks_ref); - // std::vector > tks_base_; - // tks_base_.push_back(edm::RefToBase(tks_ref)); - // reco::Vertex saveVertex = reco::Vertex(genVertex, Error); // Try to produce an nonfake Vertex - // constructor for a valid vertex, with all data - // Vertex( const Point &, const Error &, double chi2, double ndof, size_t size ); // Need at least 5 ndof so the vertex Quality is considered good reco::Vertex saveVertex = reco::Vertex(genVertex, Error, 1.0, 6.0, 6); - - // for (auto track: *tks) - //{ - // edm::LogPrint("") << track.vertex(); - // saveVertex.add(track, 0.5); - //} - // if (saveVertex.isFake()) edm::LogPrint("") << " The produced Vertex is fake"; - // else edm::LogPrint("") << " The produced Vertex is not fake"; - // edm::LogPrint("") << "Vertex Properties: " << saveVertex.isFake() << " / " << saveVertex.ndof() << " / " << abs(saveVertex.z()) << " / " << abs(saveVertex.position().Rho()); - // if (!saveVertex.isFake() && saveVertex.ndof() >= 4.0 && abs(saveVertex.z()) <= 24.0 && abs(saveVertex.position().Rho()) <= 2.0) - // edm::LogPrint("") << "The Vertex is a goodOfflineVertex"; embeddingVertex->push_back(saveVertex); - // iEvent.put(std::move(embeddingVertex), "embeddingVertex"); iEvent.put(std::move(embeddingVertex)); } diff --git a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc index 526aeee4bf22f..26935821447a7 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/EmbeddingLHEProducer.cc @@ -56,10 +56,6 @@ #include "FWCore/Utilities/interface/RandomNumberGenerator.h" #include "FWCore/Utilities/interface/StreamID.h" -// -// class declaration -// - namespace CLHEP { class HepRandomEngine; } @@ -98,9 +94,9 @@ class EmbeddingLHEProducer : public edm::one::EDProducer vertexCollection_; int particleToEmbed_; bool mirror_, rotate180_, InitialRecoCorrection_; - const double tauMass_ = 1.77682; - const double muonMass_ = 0.1057; - const double elMass_ = 0.00051; + static constexpr double tauMass_ = 1.77682; + static constexpr double muonMass_ = 0.1057; + static constexpr double elMass_ = 0.00051; const int embeddingParticles[3]{11, 13, 15}; std::ofstream file; @@ -227,24 +223,6 @@ void EmbeddingLHEProducer::beginRunProduce(edm::Run &run, edm::EventSetup const // set number of processes: 1 for Z to tau tau heprup.resize(1); - // Process independent information - - // beam particles ID (two protons) - // heprup.IDBMUP.first = 2212; - // heprup.IDBMUP.second = 2212; - - // beam particles energies (both 6.5 GeV) - // heprup.EBMUP.first = 6500.; - // heprup.EBMUP.second = 6500.; - - // take default pdf group for both beamparticles - // heprup.PDFGUP.first = -1; - // heprup.PDFGUP.second = -1; - - // take certan pdf set ID (same as in officially produced DYJets LHE files) - // heprup.PDFSUP.first = -1; - // heprup.PDFSUP.second = -1; - // master switch for event weight iterpretation (same as in officially produced DYJets LHE files) heprup.IDWTUP = 3; @@ -276,13 +254,9 @@ void EmbeddingLHEProducer::fill_lhe_from_mumu(TLorentzVector &positiveLepton, TLorentzVector Z = positiveLepton + negativeLepton; int leptonPDGID = particleToEmbed_; - // double tau_ctau = 0.00871100; //cm - double tau_ctau0 = 8.71100e-02; // mm (for Pythia) - double tau_ctau_p = - tau_ctau0 * CLHEP::RandExponential::shoot(engine); // return -std::log(HepRandom::getTheEngine()->flat()); - // replaces tau = process[iNow].tau0() * rndmPtr->exp(); from pythia8212/src/ProcessContainer.cc which is not initialized for ProcessLevel:all = off mode (no beam particle mode) + static constexpr double tau_ctau0 = 8.71100e-02; // mm (for Pythia) + double tau_ctau_p = tau_ctau0 * CLHEP::RandExponential::shoot(engine); double tau_ctau_n = tau_ctau0 * CLHEP::RandExponential::shoot(engine); - // std::cout<<"tau_ctau P: "< 60. && diLeptonMass < 122.) { - // std::cout << "DiLeptonMass " << diLeptonMass << std::endl; - float zmass = 91.1876; + static constexpr float zmass = 91.1876; float correction_deviation = 5.; // to ensure only a correction that drops corresponding to a Gaussian with mean zmass and std. dev. 5 GeV double EmbeddingCorrection = 1.138; // value derived by function fitting to fold embedded mass spectrum back to original selection when using mu -> mu embedding - EmbeddingCorrection = - EmbeddingCorrection / + EmbeddingCorrection /= (EmbeddingCorrection - (EmbeddingCorrection - 1.) * exp(-pow((diLeptonMass - zmass), 2.) / (2. * pow(correction_deviation, 2.)))); EmbeddingCorrection = ((diLeptonMass + (EmbeddingCorrection - 1.) * zmass) / (diLeptonMass * EmbeddingCorrection)); - double correctedpositiveLeptonEnergy = std::sqrt( - muonMass_ * muonMass_ + EmbeddingCorrection * positiveLepton.Px() * EmbeddingCorrection * positiveLepton.Px() + - EmbeddingCorrection * positiveLepton.Py() * EmbeddingCorrection * positiveLepton.Py() + - EmbeddingCorrection * positiveLepton.Pz() * EmbeddingCorrection * positiveLepton.Pz()); - double correctednegativeLeptonEnergy = std::sqrt( - muonMass_ * muonMass_ + EmbeddingCorrection * negativeLepton.Px() * EmbeddingCorrection * negativeLepton.Px() + - EmbeddingCorrection * negativeLepton.Py() * EmbeddingCorrection * negativeLepton.Py() + - EmbeddingCorrection * negativeLepton.Pz() * EmbeddingCorrection * negativeLepton.Pz()); - positiveLepton.SetPxPyPzE(EmbeddingCorrection * positiveLepton.Px(), - EmbeddingCorrection * positiveLepton.Py(), - EmbeddingCorrection * positiveLepton.Pz(), - correctedpositiveLeptonEnergy); - negativeLepton.SetPxPyPzE(EmbeddingCorrection * negativeLepton.Px(), - EmbeddingCorrection * negativeLepton.Py(), - EmbeddingCorrection * negativeLepton.Pz(), - correctednegativeLeptonEnergy); - + double correctedpositiveLeptonEnergy = + std::sqrt((pow(muonMass_, 2) / pow(EmbeddingCorrection, 2)) + pow(positiveLepton.Px(), 2) + + pow(positiveLepton.Py(), 2) + pow(positiveLepton.Pz(), 2)); + double correctednegativeLeptonEnergy = + std::sqrt((pow(muonMass_, 2) / pow(EmbeddingCorrection, 2)) + pow(negativeLepton.Px(), 2) + + pow(negativeLepton.Py(), 2) + pow(negativeLepton.Pz(), 2)); + positiveLepton.SetE(correctedpositiveLeptonEnergy); + negativeLepton.SetE(correctednegativeLeptonEnergy); + positiveLepton *= EmbeddingCorrection; + negativeLepton *= EmbeddingCorrection; edm::LogInfo("TauEmbedding") << "MuMinus after. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M(); - // std::cout << " MuMinus after. Pt: " << negativeLepton.Pt() << " Mass: " << negativeLepton.M() << " Energy: " << negativeLepton.E() << std::endl; } return; } diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc b/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc index dd110d25e22ef..2bceab1cf15ef 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuMuForEmbeddingSelector.cc @@ -59,7 +59,7 @@ class MuMuForEmbeddingSelector : public edm::stream::EDProducer<> { edm::EDGetTokenT> theMETLabel_; edm::EDGetTokenT> thePuppiMETLabel_; bool use_zmass = false; - double ZMass = 91.0; + static constexpr double zmass = 91.1876; }; // @@ -109,7 +109,7 @@ void MuMuForEmbeddingSelector::produce(edm::Event &iEvent, const edm::EventSetup const reco::CompositeCandidate *chosenZCand = nullptr; const reco::CompositeCandidate *chosenZCand_zmass = nullptr; const reco::CompositeCandidate *chosenZCand_largest = nullptr; - double massDifference = -1.0; + double massDifference = 9999; edm::Handle beamSpot; iEvent.getByToken(theBeamSpotLabel_, beamSpot); edm::Handle vertex; @@ -121,12 +121,10 @@ void MuMuForEmbeddingSelector::produce(edm::Event &iEvent, const edm::EventSetup // get primary vertex reco::Vertex::Point posVtx; reco::Vertex::Error errVtx; - std::vector::const_iterator vertexIt = vertex->begin(); - std::vector::const_iterator vertexEnd = vertex->end(); - for (; vertexIt != vertexEnd; ++vertexIt) { - if (vertexIt->isValid() && !vertexIt->isFake()) { - posVtx = vertexIt->position(); - errVtx = vertexIt->error(); + for (const auto &vtx : *vertex) { + if (vtx.isValid() && !vtx.isFake()) { + posVtx = vtx.position(); + errVtx = vtx.error(); break; } } @@ -135,8 +133,8 @@ void MuMuForEmbeddingSelector::produce(edm::Event &iEvent, const edm::EventSetup for (edm::View::const_iterator iZCand = ZmumuCandidates.begin(); iZCand != ZmumuCandidates.end(); ++iZCand) { - if (std::abs(ZMass - iZCand->mass()) < massDifference || massDifference < 0) { - massDifference = std::abs(ZMass - iZCand->mass()); + if (std::abs(zmass - iZCand->mass()) < massDifference) { + massDifference = std::abs(zmass - iZCand->mass()); chosenZCand_zmass = &(*iZCand); } } @@ -152,10 +150,8 @@ void MuMuForEmbeddingSelector::produce(edm::Event &iEvent, const edm::EventSetup } } if (use_zmass) { - // edm::LogDebug("MuMuForEmbeddingSelector") << "Using Z mass candidate" << chosenZCand_zmass->mass(); chosenZCand = chosenZCand_zmass; } else { - // edm::LogDebug("MuMuForEmbeddingSelector") << "Using largest mass candidate" << chosenZCand_largest->mass(); chosenZCand = chosenZCand_largest; } @@ -181,8 +177,6 @@ void MuMuForEmbeddingSelector::produce(edm::Event &iEvent, const edm::EventSetup iEvent.put(std::make_unique(met->at(0).phi()), "initialMETphi"); iEvent.put(std::make_unique(puppimet->at(0).et()), "initialPuppiMETEt"); iEvent.put(std::make_unique(puppimet->at(0).phi()), "initialPuppiMETphi"); - // edm::LogDebug("MuMuForEmbeddingSelector") << "PuppiMet: " << puppimet->at(0).et() << " phi: " << puppimet->at(0).phi(); - // edm::LogDebug("MuMuForEmbeddingSelector") << "MET: " << met->at(0).et() << " phi: " << met->at(0).phi(); } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ diff --git a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc index f32b9aac2a1f9..c315286497d1b 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/MuonDetCleaner.cc @@ -92,8 +92,8 @@ void MuonDetCleaner::produce(edm::Event &iEvent, edm::EventSetup const & // inspired from Muon Identification algorithm: https://github.com/cms-sw/cmssw/blob/3b943c0dbbdf4494cd66064a5a147301f38af295/RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc#L911 // and the MuonShowerDigiFiller: https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/interface/MuonShowerDigiFiller.h & https://github.com/cms-sw/cmssw/blob/29909891e150c9781f4ade2a6f7b5beb0bd67a6e/RecoMuon/MuonIdentification/src/MuonShowerDigiFiller.cc for (const auto &chamber : info.chambers) { - if (chamber.id.subdetId() == MuonSubdetId::RPC) //&& rpcHitHandle_.isValid()) - continue; // Skip RPC chambers, they are taken care of below) + if (chamber.id.subdetId() == MuonSubdetId::RPC) + continue; reco::MuonChamberMatch matchedChamber; @@ -193,7 +193,6 @@ void MuonDetCleaner::produce(edm::Event &iEvent, edm::EventSetup const & iEvent.getByToken(input_.second, RecHitinput); for (typename RecHitCollection::const_iterator recHit = RecHitinput->begin(); recHit != RecHitinput->end(); ++recHit) { // loop over the basic rec hit collection (DT CSC or RPC) - // if (find(vetoHits.begin(),vetoHits.end(),getRawDetId(*recHit)) == vetoHits.end()) continue; // For the invertec selcetion if (find(vetoHits.begin(), vetoHits.end(), getRawDetId(*recHit)) != vetoHits.end()) continue; // If the hit is not in the T1 detId(getRawDetId(*recHit)); @@ -269,7 +268,6 @@ bool MuonDetCleaner::checkrecHit(const TrackingRecHit &re else if (hit_type == typeid(CSCRecHit2D)) { return true; } - // else {std::cout<<"else "<::checkrecHit(const TrackingRecHit } else if (hit_type == typeid(DTSLRecSegment2D)) { return true; } - // else {std::cout<<"else "<::checkrecHit(const TrackingRecHit &recH if (hit_type == typeid(RPCRecHit)) { return true; } // This should be the default one (which are included in the global (outer) muon track) - // else {std::cout<<"else "<::checkrecHit(const TrackingRecHit &rec if (hit_type == typeid(CSCSegment)) { return true; } // This should be the default one (which are included in the global (outer) muon track) - // else {std::cout<<"else "<::checkrecHit(const TrackingRecH } else if (hit_type == typeid(DTSLRecSegment2D)) { return true; } - // else {std::cout<<"else "<::produce(edm::Event &iEvent, const edm::EventSetup &iSet } // end instance } -// Here some overloaded functions, which are needed such that the right merger function is called for the indivudal Collections template void TrackMergeremb::willproduce(std::string instance, std::string alias) { produces(instance); @@ -125,10 +124,8 @@ void TrackMergeremb::merg_and_put( std::unique_ptr outTracks_refs = std::make_unique(); auto rTrackExtras = iEvent.getRefBeforePut(); - // auto rHits = iEvent.getRefBeforePut(); std::vector trackRefColl; - // std::vector trackRefColl; for (auto akt_collection : to_merge) { edm::Handle track_col_in; @@ -206,12 +203,10 @@ void TrackMergeremb::merg_and_put( edm::Handle track_new_col; iEvent.getByToken(inputs_fixtrackcol_, track_new_col); - std::map - simple_track_to_track_map; // I didn't find a more elegant way, so just build a good old fassion std::map + std::map simple_track_to_track_map; for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); - simple_track_to_track_map[trackRef] = - trackRef; // catch the case, where a seed ctf track could already be updated, such that the update doesn't happen again + simple_track_to_track_map[trackRef] = trackRef; simple_track_to_track_map[((*track_ref_map)[trackRef])[0]] = trackRef; } @@ -344,8 +339,7 @@ void TrackMergeremb::merg_and_put(edm::Event &iEvent, edm::Handle track_new_col; iEvent.getByToken(inputs_fixtrackcol_, track_new_col); - std::map - simple_track_to_track_map; // I didn't find a more elegant way, so just build a good old fassion std::map + std::map simple_track_to_track_map; for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); simple_track_to_track_map[trackRef] = @@ -368,7 +362,6 @@ void TrackMergeremb::merg_and_put(edm::Event &iEvent, reco::MuonRef muRefnew(outputMuonsRefProd, new_idx); if (it->track().isNonnull()) { - // std::cout<<"pfmerge tr: "<trackRef().id()<< " "<< it->trackRef().key()<< " " << simple_track_to_track_map[it->trackRef()].id() << " " << simple_track_to_track_map[it->trackRef()].key() <back().setTrack(simple_track_to_track_map[it->track()]); } } @@ -415,7 +408,6 @@ void TrackMergeremb::merg_and_put(edm::Event &iEvent, template <> void TrackMergeremb::willproduce(std::string instance, std::string alias) { produces(instance); - // std::cout<<"Produce PF Collection: "< @@ -439,8 +431,7 @@ void TrackMergeremb::merg_and_put( edm::Handle track_new_col; iEvent.getByToken(inputs_fixtrackcol_, track_new_col); - std::map - simple_track_to_track_map; // I didn't find a more elegant way, so just build a good old fassion std::map + std::map simple_track_to_track_map; for (unsigned abc = 0; abc < track_new_col->size(); ++abc) { reco::TrackRef trackRef(track_new_col, abc); simple_track_to_track_map[trackRef] = @@ -453,8 +444,7 @@ void TrackMergeremb::merg_and_put( edm::Handle gsftrack_new_col; iEvent.getByToken(inputs_fixgsftrackcol_, gsftrack_new_col); - std::map - simple_gsftrack_to_gsftrack_map; // I didn't find a more elegant way, so just build a good old fassion std::map + std::map simple_gsftrack_to_gsftrack_map; for (unsigned abc = 0; abc < gsftrack_new_col->size(); ++abc) { reco::GsfTrackRef gsfTrackRef(gsftrack_new_col, abc); simple_gsftrack_to_gsftrack_map[((*gsftrack_ref_map)[gsfTrackRef])[0]] = gsfTrackRef; @@ -465,8 +455,7 @@ void TrackMergeremb::merg_and_put( edm::Handle muon_new_col; iEvent.getByToken(inputs_fixmucol_, muon_new_col); - std::map - simple_mu_to_mu_map; // I didn't find a more elegant way, so just build a good old fassion std::map + std::map simple_mu_to_mu_map; for (unsigned abc = 0; abc < muon_new_col->size(); ++abc) { reco::MuonRef muRef(muon_new_col, abc); simple_mu_to_mu_map[(*muon_ref_map)[muRef]] = muRef; @@ -483,9 +472,7 @@ void TrackMergeremb::merg_and_put( iEvent.getByToken(akt_collection, track_col_in); for (reco::PFCandidateCollection::const_iterator it = track_col_in->begin(); it != track_col_in->end(); ++it) { outTracks->push_back(reco::PFCandidate(*it)); - // if (fabs(it->pdgId()) == 13){ if (it->trackRef().isNonnull() && outTracks->back().charge()) { - // std::cout<<"pfmerge tr: "<trackRef().id()<< " "<< it->trackRef().key()<< " " << simple_track_to_track_map[it->trackRef()].id() << " " << simple_track_to_track_map[it->trackRef()].key() <back().setTrackRef(simple_track_to_track_map[it->trackRef()]); } if (it->gsfTrackRef().isNonnull()) { @@ -495,7 +482,6 @@ void TrackMergeremb::merg_and_put( const reco::SuperClusterRef &pfScRef(it->superClusterRef()); float dx, dy, dz, dr; - // float drMin = std::numeric_limits::infinity(); float drMin = 10.0; // also used as treshold for matching reco::SuperClusterRef ccrefMin; for (auto sc = bSc; sc != eSc; ++sc) { @@ -511,7 +497,6 @@ void TrackMergeremb::merg_and_put( } } if (it->muonRef().isNonnull()) { - // std::cout<<"pfmerge mu: "<muonRef().id()<< " "<< it->muonRef().key()<< " " << simple_mu_to_mu_map[it->muonRef()].id() << " " << simple_mu_to_mu_map[it->muonRef()].key() <back().setMuonRef(simple_mu_to_mu_map[it->muonRef()]); } } diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h index b3305102622a6..051e84bd9a904 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackMergeremb.h @@ -3,11 +3,7 @@ * * \author Stefan Wayand; * Christian Veelken, LLR - * - * - * - * - * + * Clean Up from Christian Winter & Sebastian Brommer, KIT */ #ifndef TauAnalysis_MCEmbeddingTools_TrackMergeremb_H #define TauAnalysis_MCEmbeddingTools_TrackMergeremb_H @@ -65,7 +61,6 @@ class TrackMergeremb : public edm::stream::EDProducer<> { std::map>> inputs_; std::map>>> inputs_qual_; - // typedef edm::ValueMap TrackToTrackMapnew; typedef edm::ValueMap TrackToTrackMapnew; typedef edm::ValueMap GsfTrackToTrackMapnew; diff --git a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc index 261f0d89c64ca..d9a219a560fdf 100644 --- a/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc +++ b/TauAnalysis/MCEmbeddingTools/plugins/TrackerCleaner.cc @@ -48,7 +48,6 @@ void TrackerCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetu if (!iMuon->isGlobalMuon()) continue; const reco::Track *mutrack = iMuon->globalTrack().get(); - // reco::Track *mutrack = new reco::Track(*(iMuon->innerTrack() )); for (trackingRecHit_iterator hitIt = mutrack->recHitsBegin(); hitIt != mutrack->recHitsEnd(); ++hitIt) { const TrackingRecHit &murechit = **hitIt; if (!(murechit).isValid()) @@ -78,7 +77,6 @@ void TrackerCleaner::produce(edm::Event &iEvent, const edm::EventSetup &iSetu idx++; if (vetodClusters[idx - 1]) continue; - // if (!vetodClusters[idx-1]) continue; for inverted selction spc.push_back(*clustIt); } } diff --git a/TauAnalysis/MCEmbeddingTools/python/DYToElElGenFilter_cfi.py b/TauAnalysis/MCEmbeddingTools/python/DYToElElGenFilter_cfi.py deleted file mode 100644 index ca816bf1eaf72..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/python/DYToElElGenFilter_cfi.py +++ /dev/null @@ -1,7 +0,0 @@ -import FWCore.ParameterSet.Config as cms - - -dyToElElGenFilter = cms.EDFilter("DYToElElGenFilter", - inputTag = cms.InputTag("genParticles"), - #filter = cms.bool(True) - ) diff --git a/TauAnalysis/MCEmbeddingTools/python/DYToElTauGenFilter_cfi.py b/TauAnalysis/MCEmbeddingTools/python/DYToElTauGenFilter_cfi.py deleted file mode 100644 index a48d967386197..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/python/DYToElTauGenFilter_cfi.py +++ /dev/null @@ -1,6 +0,0 @@ -import FWCore.ParameterSet.Config as cms - - -dyToElTauGenFilter = cms.EDFilter("DYToElTauGenFilter", - inputTag = cms.InputTag("genParticles"), - filter = cms.bool(True)) diff --git a/TauAnalysis/MCEmbeddingTools/python/DYToMuMuGenFilter_cfi.py b/TauAnalysis/MCEmbeddingTools/python/DYToMuMuGenFilter_cfi.py deleted file mode 100644 index 7e4bc2d936324..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/python/DYToMuMuGenFilter_cfi.py +++ /dev/null @@ -1,5 +0,0 @@ -import FWCore.ParameterSet.Config as cms - - -dYToMuMuGenFilter = cms.EDFilter("DYToMuMuGenFilter", - inputTag = cms.InputTag("prunedGenParticles")) diff --git a/TauAnalysis/MCEmbeddingTools/python/DYToMuTauGenFilter_cfi.py b/TauAnalysis/MCEmbeddingTools/python/DYToMuTauGenFilter_cfi.py deleted file mode 100644 index 39aa66546d2ed..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/python/DYToMuTauGenFilter_cfi.py +++ /dev/null @@ -1,6 +0,0 @@ -import FWCore.ParameterSet.Config as cms - - -dyToMuTauGenFilter = cms.EDFilter("DYToMuTauGenFilter", - inputTag = cms.InputTag("genParticles"), - filter = cms.bool(True)) diff --git a/TauAnalysis/MCEmbeddingTools/python/DYToTauTauGenFilter_cfi.py b/TauAnalysis/MCEmbeddingTools/python/DYToTauTauGenFilter_cfi.py deleted file mode 100644 index c3e547327f8e0..0000000000000 --- a/TauAnalysis/MCEmbeddingTools/python/DYToTauTauGenFilter_cfi.py +++ /dev/null @@ -1,6 +0,0 @@ -import FWCore.ParameterSet.Config as cms - - -dyToTauTauGenFilter = cms.EDFilter("DYToTauTauGenFilter", - inputTag = cms.InputTag("genParticles"), - filter = cms.bool(True)) diff --git a/TauAnalysis/MCEmbeddingTools/python/customisers.py b/TauAnalysis/MCEmbeddingTools/python/customisers.py index ecde79c05c6f9..3cce2db3c0f5e 100644 --- a/TauAnalysis/MCEmbeddingTools/python/customisers.py +++ b/TauAnalysis/MCEmbeddingTools/python/customisers.py @@ -206,9 +206,6 @@ def __init__( to_bemanipulate.append( module_manipulate(module_name="hfreco", manipulator_name="HFRecHit") ) -to_bemanipulate.append( - module_manipulate(module_name="castorreco", manipulator_name="CastorRecHit") -) to_bemanipulate.append( @@ -569,69 +566,6 @@ def keepSimulated(process, processname="SIMembedding"): ret_vstring.append(entry) return ret_vstring - -def customiseGenerator(process, changeProcessname=True, reselect=False): - if reselect: - dataTier = "RESELECT" - else: - dataTier = "SELECT" - if changeProcessname: - process._Process__name = "SIMembedding" - - ## here correct the vertex collection - - process.load("TauAnalysis.MCEmbeddingTools.EmbeddingVertexCorrector_cfi") - process.VtxSmeared = process.VtxCorrectedToInput.clone() - print( - "Correcting Vertex in genEvent to one from input. Replaced 'VtxSmeared' with the Corrector." - ) - process.load("TauAnalysis.MCEmbeddingTools.EmbeddingBeamSpotOnline_cfi") - process.hltOnlineBeamSpot = process.onlineEmbeddingBeamSpotProducer.clone() - print( - "Setting online beam spot in HLTSchedule to the one from input data. Replaced 'hltOnlineBeamSpot' with the offline beam spot." - ) - - # Remove BeamSpot Production, use the one from selected data instead. - process.reconstruction.remove(process.offlineBeamSpot) - - # Disable noise simulation - process.mix.digitizers.castor.doNoise = cms.bool(False) - - process.mix.digitizers.ecal.doESNoise = cms.bool(False) - process.mix.digitizers.ecal.doENoise = cms.bool(False) - - process.mix.digitizers.hcal.doNoise = cms.bool(False) - process.mix.digitizers.hcal.doThermalNoise = cms.bool(False) - process.mix.digitizers.hcal.doHPDNoise = cms.bool(False) - - process.mix.digitizers.pixel.AddNoisyPixels = cms.bool(False) - process.mix.digitizers.pixel.AddNoise = cms.bool(False) - - process.mix.digitizers.strip.Noise = cms.bool(False) - - # Replace HLT vertexing with vertex taken from LHE step - process.load("TauAnalysis.MCEmbeddingTools.EmbeddingHltPixelVerticesProducer_cfi") - process.hltPixelVertices = process.embeddingHltPixelVertices.clone() - process.offlinePrimaryVertices = process.embeddingHltPixelVertices.clone() - process.firstStepPrimaryVerticesUnsorted = process.embeddingHltPixelVertices.clone() - process.firstStepPrimaryVerticesPreSplitting = ( - process.embeddingHltPixelVertices.clone() - ) - - process = customisoptions(process) - ##process = fix_input_tags(process) - - return modify_outputModules( - process, - [keepSelected(dataTier), keepCleaned(dataTier), keepSimulated(process)], - ["AODSIMoutput"], - ) - - -def customiseGenerator_Reselect(process): - return customiseGenerator(process, reselect=True) - - def customiseGenerator_preHLT(process, changeProcessname=True, reselect=False): if reselect: dataTier = "RESELECT"