-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34754 from fabiocos/fc-fixAnalyzers
Modernization of several simulation standalone test EDAnalyzers
- Loading branch information
Showing
16 changed files
with
631 additions
and
663 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,99 @@ | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/one/EDAnalyzer.h" | ||
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" | ||
#include "FWCore/Utilities/interface/EDGetToken.h" | ||
#include "DataFormats/Common/interface/ValidHandle.h" | ||
|
||
#include <iostream> | ||
|
||
#include "IOMC/EventVertexGenerators/test/VtxTester.h" | ||
|
||
#include "FWCore/Framework/interface/Event.h" | ||
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/Utilities/interface/InputTag.h" | ||
|
||
// essentials !!! | ||
#include "FWCore/Framework/interface/Event.h" | ||
//#include "DataFormats/Common/interface/Handle.h" | ||
#include "DataFormats/Common/interface/Handle.h" | ||
#include "FWCore/ServiceRegistry/interface/Service.h" | ||
#include "CommonTools/UtilAlgos/interface/TFileService.h" | ||
|
||
#include "TFile.h" | ||
#include "TH1.h" | ||
#include "TH2.h" | ||
|
||
#include "CLHEP/Units/PhysicalConstants.h" | ||
#include "CLHEP/Units/SystemOfUnits.h" | ||
|
||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
|
||
using namespace edm; | ||
using namespace std; | ||
|
||
VtxTester::VtxTester(const ParameterSet&) { | ||
fOutputFile = 0; | ||
fVtxHistz = 0; | ||
fVtxHistx = 0; | ||
fVtxHisty = 0; | ||
fVtxHistxy = 0; | ||
fPhiHistOrg = 0; | ||
fPhiHistSmr = 0; | ||
fEtaHistOrg = 0; | ||
fEtaHistSmr = 0; | ||
class VtxTester : public edm::one::EDAnalyzer<> { | ||
public: | ||
// | ||
explicit VtxTester(const edm::ParameterSet&); | ||
virtual ~VtxTester() {} | ||
|
||
void beginJob() override {} | ||
void analyze(const edm::Event&, const edm::EventSetup&) override; | ||
void endJob() override {} | ||
|
||
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); | ||
|
||
private: | ||
edm::EDGetTokenT<edm::HepMCProduct> srcHepMCToken_; | ||
|
||
TH1D* fVtxHistTime_; | ||
TH1D* fVtxHistz_; | ||
TH2D* fVtxHistzTime_; | ||
TH1D* fVtxHistx_; | ||
TH1D* fVtxHisty_; | ||
TH2D* fVtxHistxy_; | ||
TH1D* fPhiHist_; | ||
TH1D* fEtaHist_; | ||
}; | ||
|
||
VtxTester::VtxTester(const edm::ParameterSet& cfg) | ||
: srcHepMCToken_(consumes<edm::HepMCProduct>(cfg.getParameter<edm::InputTag>("src"))) { | ||
edm::Service<TFileService> fs; | ||
|
||
fVtxHistTime_ = fs->make<TH1D>("VtxHistTime", "#vtx, t [ns]", 60, -0.9, 0.9); | ||
fVtxHistz_ = fs->make<TH1D>("VtxHistz", "#vtx, z [mm]", 400, -200., 200.); | ||
fVtxHistzTime_ = fs->make<TH2D>("VtxHistzTime", "#vtx time [ns] vs z [mm]", 400, -200., 200., 60, -0.9, 0.9); | ||
fVtxHistx_ = fs->make<TH1D>("VtxHistx", "#vtx, x [mm]", 200, -1., 1.); | ||
fVtxHisty_ = fs->make<TH1D>("VtxHisty", "#vtx, y [mm]", 200, -1., 1.); | ||
fVtxHistxy_ = fs->make<TH2D>("VtxHistxy", "#vtx y vs x [mm]", 200, -1., 1., 200, -1., 1.); | ||
|
||
fPhiHist_ = fs->make<TH1D>("PhiHist", "#vtx phi", 70, -3.5, 3.5); | ||
fEtaHist_ = fs->make<TH1D>("EtaHist", "#vtx eta", 120, -6., 6.); | ||
} | ||
|
||
void VtxTester::beginJob() { | ||
fOutputFile = new TFile("VtxTest.root", "RECREATE"); | ||
fVtxHistz = new TH1D("VtxHistz", "Test Z-spread", 100, -250., 250.); | ||
fVtxHistx = new TH1D("VtxHistx", "Test X-spread", 500, -1., 1.); | ||
fVtxHisty = new TH1D("VtxHisty", "Test Y-spread", 500, -1., 1.); | ||
fVtxHistxy = new TH2D("VtxHistxy", "Test X-Y spread", 700, -1., 1., 700, -1., 1.); | ||
void VtxTester::analyze(const edm::Event& e, const edm::EventSetup&) { | ||
auto theGenEvent = makeValid(e.getHandle(srcHepMCToken_)); | ||
|
||
fPhiHistOrg = new TH1D("PhiHistOrg", "Test Phi, org.", 80, -4., 4.); | ||
fPhiHistSmr = new TH1D("PhiHistSmr", "Test Phi, smr.", 80, -4., 4.); | ||
fEtaHistOrg = new TH1D("EtaHistOrg", "Test Eta, org.", 80, -4., 4.); | ||
fEtaHistSmr = new TH1D("EtaHistSmr", "Test Eta, smr.", 80, -4., 4.); | ||
const HepMC::GenEvent* Evt = theGenEvent->GetEvent(); | ||
|
||
return; | ||
} | ||
// take only 1st vertex for now - it's been tested only of PGuns... | ||
|
||
HepMC::GenEvent::vertex_const_iterator Vtx = Evt->vertices_begin(); | ||
|
||
fVtxHistTime_->Fill((*Vtx)->position().t() * CLHEP::mm / CLHEP::c_light); | ||
fVtxHistz_->Fill((*Vtx)->position().z() * CLHEP::mm); | ||
fVtxHistzTime_->Fill((*Vtx)->position().z() * CLHEP::mm, (*Vtx)->position().t() * CLHEP::mm / CLHEP::c_light); | ||
fVtxHistx_->Fill((*Vtx)->position().x() * CLHEP::mm); | ||
fVtxHisty_->Fill((*Vtx)->position().y() * CLHEP::mm); | ||
fVtxHistxy_->Fill((*Vtx)->position().x() * CLHEP::mm, (*Vtx)->position().y() * CLHEP::mm); | ||
|
||
void VtxTester::analyze(const Event& e, const EventSetup&) { | ||
vector<Handle<HepMCProduct> > EvtHandles; | ||
e.getManyByType(EvtHandles); | ||
|
||
for (unsigned int i = 0; i < EvtHandles.size(); i++) { | ||
if (EvtHandles[i].isValid()) { | ||
const HepMC::GenEvent* Evt = EvtHandles[i]->GetEvent(); | ||
|
||
// take only 1st vertex for now - it's been tested only of PGuns... | ||
// | ||
HepMC::GenEvent::vertex_const_iterator Vtx = Evt->vertices_begin(); | ||
|
||
for (HepMC::GenEvent::particle_const_iterator Part = Evt->particles_begin(); Part != Evt->particles_end(); | ||
Part++) { | ||
//HepLorentzVector Mom = (*Part)->momentum() ; | ||
HepMC::FourVector Mom = (*Part)->momentum(); | ||
double Phi = Mom.phi(); | ||
double Eta = -log(tan(Mom.theta() / 2.)); | ||
|
||
//if ( EvtHandles[i].provenance()->moduleLabel() == "VtxSmeared" ) | ||
//{ | ||
fVtxHistz->Fill((*Vtx)->position().z()); | ||
fVtxHistx->Fill((*Vtx)->position().x()); | ||
fVtxHisty->Fill((*Vtx)->position().y()); | ||
fVtxHistxy->Fill((*Vtx)->position().x(), (*Vtx)->position().y()); | ||
fPhiHistSmr->Fill(Phi); | ||
fEtaHistSmr->Fill(Eta); | ||
//} | ||
//else | ||
//{ | ||
//fPhiHistOrg->Fill( Phi ) ; | ||
//fEtaHistOrg->Fill( Eta ) ; | ||
//} | ||
} | ||
} | ||
for (HepMC::GenEvent::particle_const_iterator Part = Evt->particles_begin(); Part != Evt->particles_end(); Part++) { | ||
HepMC::FourVector Mom = (*Part)->momentum(); | ||
double Phi = Mom.phi(); | ||
double Eta = -log(tan(Mom.theta() / 2.)); | ||
|
||
fPhiHist_->Fill(Phi); | ||
fEtaHist_->Fill(Eta); | ||
} | ||
|
||
return; | ||
} | ||
|
||
void VtxTester::endJob() { | ||
fOutputFile->Write(); | ||
fOutputFile->Close(); | ||
|
||
return; | ||
void VtxTester::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { | ||
edm::ParameterSetDescription desc; | ||
desc.add<edm::InputTag>("src", edm::InputTag("generatorSmeared")) | ||
->setComment("Input generated HepMC event after vtx smearing"); | ||
descriptions.add("vtxTester", desc); | ||
} | ||
|
||
DEFINE_FWK_MODULE(VtxTester); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
process = cms.Process('TestVertex') | ||
|
||
# import of standard configurations | ||
process.load('Configuration.StandardSequences.Services_cff') | ||
process.load('SimGeneral.HepPDTESSource.pythiapdt_cfi') | ||
process.load('FWCore.MessageService.MessageLogger_cfi') | ||
process.load('Configuration.EventContent.EventContent_cff') | ||
process.load('Configuration.StandardSequences.Generator_cff') | ||
process.load('IOMC.EventVertexGenerators.VtxSmearedHLLHC14TeV_cfi') | ||
process.load('GeneratorInterface.Core.genFilterSummary_cff') | ||
process.load('Configuration.StandardSequences.EndOfProcess_cff') | ||
|
||
process.maxEvents = cms.untracked.PSet( | ||
input = cms.untracked.int32(200000), | ||
# input = cms.untracked.int32(100), | ||
output = cms.optional.untracked.allowed(cms.int32,cms.PSet) | ||
) | ||
|
||
# Input source | ||
process.source = cms.Source("EmptySource") | ||
|
||
# Output definition | ||
|
||
process.RAWSIMoutput = cms.OutputModule("PoolOutputModule", | ||
fileName = cms.untracked.string('file:step1.root'), | ||
outputCommands = process.RAWSIMEventContent.outputCommands, | ||
) | ||
|
||
# Additional output definition | ||
|
||
# Other statements | ||
process.genstepfilter.triggerConditions=cms.vstring("generation_step") | ||
|
||
process.generator = cms.EDFilter("Pythia8PtGun", | ||
PGunParameters = cms.PSet( | ||
AddAntiParticle = cms.bool(True), | ||
MaxEta = cms.double(2.85), | ||
MaxPhi = cms.double(3.14159265359), | ||
MaxPt = cms.double(100.0), | ||
MinEta = cms.double(-2.85), | ||
MinPhi = cms.double(-3.14159265359), | ||
MinPt = cms.double(2.0), | ||
ParticleID = cms.vint32(-13) | ||
), | ||
PythiaParameters = cms.PSet( | ||
parameterSets = cms.vstring() | ||
), | ||
Verbosity = cms.untracked.int32(0), | ||
firstRun = cms.untracked.uint32(1), | ||
psethack = cms.string('single mu pt 2 to 100') | ||
) | ||
|
||
process.vtxtester = cms.EDAnalyzer("VtxTester") | ||
|
||
process.TFileService = cms.Service("TFileService", | ||
fileName = cms.string('vtxTester.root') | ||
) | ||
|
||
# Path and EndPath definitions | ||
process.generation_step = cms.Path(process.pgen+process.vtxtester) | ||
process.genfiltersummary_step = cms.EndPath(process.genFilterSummary) | ||
process.RAWSIMoutput_step = cms.EndPath(process.RAWSIMoutput) | ||
|
||
# Schedule definition | ||
process.schedule = cms.Schedule(process.generation_step,process.genfiltersummary_step,process.RAWSIMoutput_step) | ||
# filter all path with the production filter sequence | ||
for path in process.paths: | ||
getattr(process,path).insert(0, process.generator) | ||
|
||
process.MessageLogger.cerr.FwkReport.reportEvery = 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.