#include #include "framework/Registry.hpp" #include "edm/Event.hpp" #include "analysis_tutorial/AccessChunks.hpp" #include "em_evt/EMparticle.hpp" #include "em_evt/EMparticleChunk.hpp" #include "em_evt/EMparticleChunkSelector.hpp" #include "jet_evt/Jet.hpp" #include "jet_evt/JetChunk.hpp" #include "jet_evt/JetChunkSelector.hpp" #include "muonid/MuonParticle.hpp" #include "muonid/MuonParticleChunk.hpp" #include "chpart_evt/ChargedParticle.hpp" #include "chpart_evt/ChargedParticleChunk.hpp" #include "missingET/MissingET.hpp" #include "missingET/MissingETChunk.hpp" #include "HepTuple/HepRootFileManager.h" #include "TH1.h" // #include "TH2.h" namespace d0tutorial { FWK_REGISTRY_IMPL(AccessChunks,"$Name: $"); AccessChunks::AccessChunks(fwk::Context *ctx) : fwk::Package(ctx), fwk::Analyze(ctx), fwk::JobSummary(ctx), _debug(packageRCP().getBool("Debug")), _histofile_name("AccessChunk.root"), _events_processed(0) { using namespace edm; using namespace std; using namespace emid; using namespace jetid; log()(ELinfo, "AccessChunks") << "Instance = " << instanceName() << " created" << endmsg; RCP rcp = packageRCP(); // Now try to read an optional parameter. // _histofile_name has been initialized above to // a default value. try { _histofile_name = rcp.getString("HistogramFile"); } catch(XRCPNotFound& ex) { // Ignore the not found exception. // Other exceptions propagate out of the constructor. } // Initialize key for selecting the correct EM chunk RCP emidAlgoRCP = rcp.getRCP("EMid_Algo"); vector emidNestedRCP = rcp.getVString("EMid_SearchRCPs"); EMparticleChunkSelector emAlgoSel(emidAlgoRCP,emidNestedRCP); _emKey = edm::TKey(emAlgoSel); // Initialize key for selecting the correct Jet chunk string jetType = rcp.getString("JetAlgo_type"); vector jetValues = rcp.getVFloat("JetAlgo_values"); vector jetNames = rcp.getVString("JetAlgo_names"); if ( jetValues.size() != jetNames.size() ) { log()(ELerror, "JetAlgoSelection") << "Inconsistent RCP values for the jet selection, disable it" << endmsg; jetNames.clear(); jetValues.clear(); } jetid::JetAlgoInfo jetAlgoInfo(jetType,jetValues,jetNames); _jetKey = TKey(JetChunkSelector(jetAlgoInfo)); _mgr = new HepRootFileManager(_histofile_name.c_str(), ""); _em_pT = new TH1F("emPt", "EM particle pT", 100, 0.0, .0); _mu_pT = new TH1F("muPt", "Muon pT", 100, 0.0, 100.0); _jet_pT = new TH1F("jetPt", "Jet pT", 100, 0.0, 100.0); _met = new TH1F("met", "Missing Et", 100, 0.0, 100.0); } AccessChunks::~AccessChunks() { } fwk::Result AccessChunks::analyzeEvent(const edm::Event& event) { access_muon(event); access_em(event); access_jet(event); access_tracks(event); access_met(event); ++_events_processed; return fwk::Result::success; } template void fill_pT(ITERATOR first, ITERATOR second, TH1F *histogram) { while(first != second) { histogram->Fill((*first).pT()); ++first; } } void AccessChunks::access_em(const edm::Event& event) { using namespace edm; using namespace emid; typedef std::vector::const_iterator const_iterator; THandle handle = _emKey.find(event); if(handle.isValid()) { const std::vector *particles = handle->getParticles(); for(const_iterator it = particles->begin(); it != particles->end(); ++it) { const EMparticle& obj = *it; int id = abs(obj.typeID()); if(id == 10 || id == 11) { float pT = obj.pT(); float eta = obj.eta(); const EMQualityInfo *quality = obj.qualInfo(); float isolation = quality->isolation(); float em_fraction = quality->emclusptr()->emfrac(); } } fill_pT(particles->begin(), particles->end(), _em_pT); } } void AccessChunks::access_jet(const edm::Event& event) { using namespace edm; using namespace jetid; typedef std::vector::const_iterator const_iterator; THandle handle = _jetKey.find(event); if(handle.isValid()) { const std::vector *particles = handle->getParticles(); for(const_iterator it = particles->begin(); it != particles->end(); ++it) { const Jet& obj = *it; float pT = obj.pT(); float emfraction = obj.emETfraction(); float hotcellration = obj.hotcellratio(); int n90 = obj.n90(); } fill_pT(particles->begin(), particles->end(), _jet_pT); } } void AccessChunks::access_muon(const edm::Event& event) { using namespace edm; using namespace muonid; typedef std::vector::const_iterator const_iterator; TKey key; THandle handle = key.find(event); if(handle.isValid()) { const std::vector *particles = handle->getParticles(); for(const_iterator it = particles->begin(); it != particles->end(); ++it) { const MuonParticle& obj = *it; float pT = obj.pT(); const MuonQualityInfo *quality = obj.qualInfo(); int nhit = quality->nhit(); int nseg = quality->nseg(); } fill_pT(particles->begin(), particles->end(), _mu_pT); } } void AccessChunks::access_met(const edm::Event& event) { using namespace edm; // there is no namespace missingET... TKey key; THandle handle = key.find(event); if(handle.isValid()) { // Note: no 'const' qualifier here... MissingET *met = handle->getMissingET(); float MET = met->getMET(); float scalarET = met->getScalarET(); _met->Fill(MET); } } void AccessChunks::access_tracks(const edm::Event& event) { using namespace edm; using namespace vertex; // this is the namespace where ChargedParticle lives... typedef std::vector::const_iterator const_iterator; TKey key; THandle handle = key.find(event); if(handle.isValid()) { const std::vector *particles = handle->getParticles(); for(const_iterator it = particles->begin(); it != particles->end(); ++it) { const ChargedParticle& obj = *it; float pT = obj.pT(); } // book_pT(particles->begin(), particles->end(), _muon_pT) } } fwk::Result AccessChunks::jobSummary() { // Save histograms _mgr->write(); out() << packageName() << '/' << instanceName() << " : JobSummary called" << std::endl << packageName() << '/' << instanceName() << " : processed " << _events_processed << " events" << std::endl; return fwk::Result::success; } }