From 266e217fd78ee17a259dbfe0a0f6dbbddf62a6de Mon Sep 17 00:00:00 2001 From: capalmer85 Date: Sun, 12 Apr 2015 05:58:05 +0200 Subject: [PATCH 1/5] pcc-ntupler-74X-v1 --- .../LumiProducer/test/BuildFile.xml | 19 ++ .../test/analysis/plugins/PCCNTupler.cc | 287 ++++++++++++++++++ .../test/analysis/plugins/PCCNTupler.h | 140 +++++++++ .../test/analysis/test/Run_template.py | 79 +++++ .../test/analysis/test/crab2_template.cfg | 54 ++++ 5 files changed, 579 insertions(+) create mode 100644 RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc create mode 100644 RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h create mode 100644 RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py create mode 100644 RecoLuminosity/LumiProducer/test/analysis/test/crab2_template.cfg diff --git a/RecoLuminosity/LumiProducer/test/BuildFile.xml b/RecoLuminosity/LumiProducer/test/BuildFile.xml index a855523b7a4f5..57b1d2d8f5cb8 100755 --- a/RecoLuminosity/LumiProducer/test/BuildFile.xml +++ b/RecoLuminosity/LumiProducer/test/BuildFile.xml @@ -1,6 +1,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc new file mode 100644 index 0000000000000..959e73acfd63f --- /dev/null +++ b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc @@ -0,0 +1,287 @@ +// ---------------------------------------------------------------------- +// PCCNTupler +// --------- + +#include +#include +#include +#include +#include +#include + +#include "PCCNTupler.h" + +#include "CondFormats/Alignment/interface/Definitions.h" +#include "CondFormats/RunInfo/interface/RunInfo.h" + +#include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h" +#include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h" +#include "DataFormats/VertexReco/interface/Vertex.h" + +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/ServiceRegistry/interface/Service.h" + +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include + +#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" + + +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace edm; +using namespace reco; + +// ---------------------------------------------------------------------- +PCCNTupler::PCCNTupler(edm::ParameterSet const& iConfig): + fVerbose(iConfig.getUntrackedParameter("verbose", 0)), + fPixelClusterLabel(iConfig.getUntrackedParameter("pixelClusterLabel", edm::InputTag("siPixelClusters"))), + fHLTProcessName(iConfig.getUntrackedParameter("HLTProcessName")), + saveType(iConfig.getUntrackedParameter("saveType")), + sampleType(iConfig.getUntrackedParameter("sampleType")) +{ + cout << "----------------------------------------------------------------------" << endl; + cout << "--- PCCNTupler constructor" << endl; + + nPrint = 0; + edm::Service fs; + + includeVertexInformation = true; + includePixels = true; + + tree = fs->make("tree","Pixel Cluster Counters"); + tree->Branch("runNo",&runNo,"runNo/I"); + tree->Branch("LSNo",&LSNo,"LSNo/I"); + tree->Branch("LNNo",&LNNo,"LNNo/I"); + + pileup = fs->make("pileup","pileup",100,0,100); + if(includeVertexInformation){ + tree->Branch("nGoodVtx","map",&nGoodVtx); + tree->Branch("num_Trks",&nTrk,"nTrk/I"); + } + + if(includePixels){ + tree->Branch("BXNo","map",&BXNo); + tree->Branch("nPixelClusters","map",&nPixelClusters); + tree->Branch("nClusters","map",&nClusters); + tree->Branch("layers","map",&layers); + // dead modules + nDeadModules = 6; + nDeadPrint = 0; + deadModules[0] = 302125076; + deadModules[1] = 302125060; + deadModules[2] = 302197516; + deadModules[3] = 344019460; + deadModules[4] = 344019464; + deadModules[5] = 344019468; + } + +} + +// ---------------------------------------------------------------------- +PCCNTupler::~PCCNTupler() { } + +// ---------------------------------------------------------------------- +void PCCNTupler::endJob() { + tree->Fill(); + cout << "==>PCCNTupler> Succesfully gracefully ended job" << endl; +} + +// ---------------------------------------------------------------------- +void PCCNTupler::beginJob() { + +} + + +// ---------------------------------------------------------------------- +void PCCNTupler::beginRun(const Run &run, const EventSetup &iSetup) { + bool hasChanged; + fValidHLTConfig = fHltConfig.init(run,iSetup,fHLTProcessName,hasChanged); +} + +// ---------------------------------------------------------------------- +void PCCNTupler::endRun(Run const&run, EventSetup const&iSetup) { + fValidHLTConfig = false; +} + + + +// ---------------------------------------------------------------------- +void PCCNTupler::analyze(const edm::Event& iEvent, + const edm::EventSetup& iSetup) { + + using namespace edm; + using reco::VertexCollection; + + saveAndReset=false; + sameEvent = (eventNo==(int)iEvent.id().event()); + sameLumiNib = true; // FIXME where is this info? + sameLumiSect = (LSNo==(int)iEvent.getLuminosityBlock().luminosityBlock()); + firstEvent = (LSNo==-99); + + // When arriving at the new LS, LN or event the tree + // must be filled and branches must be reset. + // The final entry is saved in the deconstructor. + saveAndReset = (saveType=="LumiSect" && !sameLumiSect) + || (saveType=="LumiNib" && !sameLumiNib) + || (saveType=="Event" && !sameEvent); + + if( !saveAndReset && !sameLumiSect + && !sameLumiNib && !sameEvent) { + std::cout<<"Diff LS, LN and Event, but not saving/resetting..."<Fill(); + nVtx = 0; + nTrk = 0; + nPixelClusters.clear(); + nClusters.clear(); + layers.clear(); + BXNo.clear(); + nGoodVtx.clear(); + } + + if(sampleType=="MC"){ + edm::Handle > PupInfo; + iEvent.getByLabel("addPileupInfo", PupInfo); + std::vector::const_iterator PVI; + for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) { + int pu_bunchcrossing = PVI->getBunchCrossing(); + //std::cout<<"pu_bunchcrossing getPU_NumInteractions getTrueNumInteractions "<getPU_NumInteractions()<<" "<getTrueNumInteractions()<Fill(PVI->getPU_NumInteractions()); + } + } + } + + // Get the Run, Lumi Section, and Event numbers, etc. + runNo = iEvent.id().run(); + LSNo = iEvent.getLuminosityBlock().luminosityBlock(); + LNNo = -99; // FIXME need the luminibble + eventNo = iEvent.id().event(); + timeStamp = iEvent.time().unixTime(); + + if((BXNo.count(iEvent.bunchCrossing())==0||nGoodVtx.count(iEvent.bunchCrossing())==0) && !(BXNo.count(iEvent.bunchCrossing())==0&&nGoodVtx.count(iEvent.bunchCrossing())==0)){ + std::cout<<"BXNo and nGoodVtx should have the same keys but DO NOT!!!"< recVtxs; + iEvent.getByLabel("offlinePrimaryVertices",recVtxs); + + if(recVtxs.isValid()){ + for(reco::VertexCollection::const_iterator v=recVtxs->begin(); v!=recVtxs->end(); ++v){ + int nnTrk = v->tracksSize(); + int nd = (int)v->ndof(); + if(nd > 4 && v->isValid() && (v->isFake() == 0)){ + nVtx++; + if(nnTrk > 0){ + nGoodVtx[iEvent.bunchCrossing()]=nGoodVtx[iEvent.bunchCrossing()]+1; + if(nnTrk > nTrk){ + nTrk = nnTrk; + //FIXME why are we multiplying by 10000 or 10? + xV = 10000.*v->x(); + yV = 10000.*v->y(); + zV = 10.*v->z(); + chi2 = v->chi2(); + ndof = (int)v->ndof(); + } + } + } + } + } + } + + + // -- Does this belong into beginJob()? + ESHandle TG; + iSetup.get().get(TG); + + // -- FED + edm::eventsetup::EventSetupRecordKey recordKey(edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd")); + if (recordKey.type() == edm::eventsetup::EventSetupRecordKey::TypeTag()) { + //record not found + cout << "Record \"RunInfoRcd" << "\" does not exist " << endl; + fFED1 = 0; + fFED2 = (0x1 << 12) ; + } else { + edm::ESHandle runInfoHandle; + iSetup.get().get(runInfoHandle); + } + // -- Pixel cluster + edm::Handle< edmNew::DetSetVector > hClusterColl; + iEvent.getByLabel(fPixelClusterLabel, hClusterColl); + const edmNew::DetSetVector clustColl = *(hClusterColl.product()); + + + // ---------------------------------------------------------------------- + // -- Clusters without tracks + + for (TrackerGeometry::DetContainer::const_iterator it = TG->dets().begin(); it != TG->dets().end(); it++){ + //if (dynamic_cast((*it)) != 0){ + DetId detId = (*it)->geographicalId(); + + + // -- clusters on this det + edmNew::DetSetVector::const_iterator isearch = clustColl.find(detId); + if (isearch != clustColl.end()) { // Not an empty iterator + edmNew::DetSet::const_iterator di; + for (di = isearch->begin(); di != isearch->end(); ++di) { + if(nPixelClusters.count(detId())==0){ + nPixelClusters[detId()]=0; + } + nPixelClusters[detId()] = nPixelClusters[detId()]+1; + } + + int nCluster = isearch->size(); + if(nClusters.count(detId())==0){ + nClusters[detId()]=0; + } + nClusters[detId()] += nCluster; + + if (detId.subdetId() == PixelSubdetector::PixelBarrel) { + PixelBarrelName detName = PixelBarrelName(detId); + int layer = detName.layerName(); + if(layers.count(detId())==0){ + layers[detId()]=layer; + } + } else { + assert(detId.subdetId() == PixelSubdetector::PixelEndcap); + PixelEndcapName detName = PixelEndcapName(detId); + int disk = detName.diskName(); + if(layers.count(detId())==0){ + layers[detId()]=disk+3; + } + } + } + //} + } +} + +// define this as a plug-in +DEFINE_FWK_MODULE(PCCNTupler); + + diff --git a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h new file mode 100644 index 0000000000000..8761e51d69cf1 --- /dev/null +++ b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h @@ -0,0 +1,140 @@ +#ifndef PCCNTupler_h +#define PCCNTupler_h + +/** \class PCCNTupler + * ---------------------------------------------------------------------- + * PCCNTupler + * --------- + * Summary: The pixel clusters are summed per pixel module per lumi + * lumi section. + * + * ---------------------------------------------------------------------- + * Author: Chris Palmer + * ---------------------------------------------------------------------- + * + * + ************************************************************/ + +#include + +#include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/Framework/interface/EDAnalyzer.h" +#include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" +#include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h" +#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" +#include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h" + +#include "TObject.h" +#include "TH1F.h" + +using namespace reco; + +class TObject; +class TTree; +class TH1D; +class TFile; +class RectangularPixelTopology; +class DetId; + +class PCCNTupler : public edm::EDAnalyzer { + public: + explicit PCCNTupler(const edm::ParameterSet& ps); + virtual ~PCCNTupler(); + virtual void beginJob(); + virtual void beginRun(const edm::Run &, const edm::EventSetup &); + virtual void endRun(edm::Run const&, edm::EventSetup const&); + virtual void endJob(); + virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup); + + protected: + void init(); + void fillEvent(); + void fillTracks(); + void fillRecHits(); + void fillVertex(); + void fillDigis(); + + void bpixNames(const DetId &pID, int &DBlayer, int &DBladder, int &DBmodule); + void fpixNames(const DetId &pID, int &DBdisk, int &DBblade, int &DBpanel, int &DBplaquette); + + void onlineRocColRow(const DetId &pID, int offlineRow, int offlineCol, int &roc, int &col, int &row); + void isPixelTrack(const edm::Ref > &refTraj, bool &isBpixtrack, bool &isFpixtrack); + + + private: + int fVerbose; + std::string fRootFileName; + std::string fGlobalTag, fType; + int fDumpAllEvents; + edm::InputTag fPrimaryVertexCollectionLabel; + edm::InputTag fPixelClusterLabel; + std::string fHLTProcessName; + + bool fAccessSimHitInfo; + + TFile *fFile; + TTree *fTree; + + std::map fFEDID; + + // -- general stuff + unsigned int fRun, fEvent, fLumiBlock; + int fBX, fOrbit; + unsigned int fTimeLo, fTimeHi; + + float fBz; + int fFED1, fFED2; + + // -- clusters + static const int CLUSTERMAX = 100000; + static const int DGPERCLMAX = 100; + static const int TKPERCLMAX = 100; + + // module information + int nDeadModules; + uint32_t deadModules[6]; + int nDeadPrint; + + HLTConfigProvider fHltConfig; + bool fValidHLTConfig; + + // saving events per LS, LN or event + std::string saveType = "LumiSect"; // LumiSect or LumiNib or Event + bool saveAndReset; + bool sameEvent; + bool sameLumiNib; + bool sameLumiSect; + bool firstEvent; + std::string sampleType="MC"; // MC or DATA + + // Lumi stuff + TTree * tree; + int runNo; + int LSNo=-99; // set to indicate first pass of analyze method + int LNNo=-99; // set to indicate first pass of analyze method + int eventNo=-99; // set to indicate first pass of analyze method + + int eventCounter=0; + int totalEvents; + + bool includeVertexInformation, includePixels; + int nVtx, nTrk, ndof; + std::map nGoodVtx; + std::map nPixelClusters; + std::map nClusters; + std::map layers; + + TH1F* pileup; + + float xV, yV, zV, chi2; + UInt_t timeStamp; + int nPrint; + std::map BXNo; + edm::InputTag vertexTags_; //used to select what vertices to read from configuration file + edm::InputTag vertexBSTags_; //used to select what vertices with BS correction + +}; + +#endif diff --git a/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py b/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py new file mode 100644 index 0000000000000..63304540e5736 --- /dev/null +++ b/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py @@ -0,0 +1,79 @@ +# ###################################################################### +# +# pixelLumi.py +# +# ---------------------------------------------------------------------- +import os +import FWCore.ParameterSet.Config as cms +process = cms.Process("Lumi") + +# ---------------------------------------------------------------------- +process.load("FWCore.MessageLogger.MessageLogger_cfi") +process.MessageLogger.cerr.threshold = 'INFO' +process.MessageLogger.cerr.FwkReport.reportEvery = 1000 +process.MessageLogger.categories.append('HLTrigReport') +process.MessageLogger.categories.append('L1GtTrigReport') +process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(True) ) + +# -- Database configuration +process.load("CondCore.DBCommon.CondDBCommon_cfi") +process.load("CondCore.DBCommon.CondDBSetup_cfi") + +# -- Conditions +process.load("Configuration.StandardSequences.MagneticField_38T_cff") +process.load("Configuration.StandardSequences.GeometryRecoDB_cff") # works for MC & data +process.load("RecoVertex.BeamSpotProducer.BeamSpot_cfi") + +process.load('Configuration.StandardSequences.FrontierConditions_GlobalTag_condDBv2_cff') +from Configuration.AlCa.GlobalTag_condDBv2 import GlobalTag +process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '') + +process.load("Configuration.StandardSequences.Reconstruction_cff") + +# -- number of events +process.maxEvents = cms.untracked.PSet( + input = cms.untracked.int32(-1) + ) + +# -- skimming +process.zerobiasfilter = cms.EDFilter("HLTHighLevel", + TriggerResultsTag = cms.InputTag("TriggerResults","","HLT"), + HLTPaths = cms.vstring("HLT_ZeroBias_v*"), + eventSetupPathsKey = cms.string(""), + andOr = cms.bool(True), + throw = cms.bool(False) + ) + +# the main Analyzer +process.lumi = cms.EDAnalyzer( + "PCCNTupler", + verbose = cms.untracked.int32(0), + #rootFileName = cms.untracked.string(rootFileName), + #type = cms.untracked.string(getDataset(process.source.fileNames[0])), + globalTag = process.GlobalTag.globaltag, + dumpAllEvents = cms.untracked.int32(0), + PrimaryVertexCollectionLabel = cms.untracked.InputTag('offlinePrimaryVertices'), + pixelClusterLabel = cms.untracked.InputTag('siPixelClusters'), + HLTProcessName = cms.untracked.string('HLT'), + saveType = cms.untracked.string('LumiSect'), # LumiSect, LumiNib, Event + sampleType = cms.untracked.string('DATA'), # MC, DATA + L1GTReadoutRecordLabel = cms.untracked.InputTag('gtDigis'), + hltL1GtObjectMap = cms.untracked.InputTag('hltL1GtObjectMap'), + HLTResultsLabel = cms.untracked.InputTag('TriggerResults::HLT') + ) + +# -- Path +process.p = cms.Path( + process.zerobiasfilter* + process.lumi + ) + + +outFile = 'pcc.root' +process.TFileService = cms.Service("TFileService",fileName = cms.string(outFile)) +readFiles = cms.untracked.vstring() +secFiles = cms.untracked.vstring() +process.source = cms.Source ("PoolSource",fileNames = readFiles, secondaryFileNames = secFiles) +readFiles.extend([ +'/store/relval/CMSSW_7_4_0_pre8/RelValMinBias_13/GEN-SIM-RECO/MCRUN2_74_V7-v1/00000/08A7F47B-B9BD-E411-97B0-0025905B85D6.root' +]) diff --git a/RecoLuminosity/LumiProducer/test/analysis/test/crab2_template.cfg b/RecoLuminosity/LumiProducer/test/analysis/test/crab2_template.cfg new file mode 100644 index 0000000000000..00f1be97dcbf4 --- /dev/null +++ b/RecoLuminosity/LumiProducer/test/analysis/test/crab2_template.cfg @@ -0,0 +1,54 @@ +# original version produced by job_maker on Tue Aug 12 20:29:37 2014 +# command: + +[CRAB] +jobtype = cmssw +scheduler = remoteGlidein +#use_server = 1 + +[CMSSW] + +datasetpath=/MinimumBias/Run2012B-22Jan2013-v1/RECO +#runselection=124009 +#show_prod=1 +use_parent = 0 +pset = Run_195396.py + +#total_number_of_events = -1 +#events_per_job = 10000 +output_file = Histo_195396MZ.root + +lumi_mask = maskForRun195396.json +total_number_of_lumis = -1 +lumis_per_job = 20 + +[USER] +ui_working_dir = 195396 +return_data = 0 +copy_data = 1 + +srm_version=srmv2 +storage_element = srm-eoscms.cern.ch +storage_path=/srm/v2/server?SFN=/eos/cms/store/user +user_remote_dir=/capalmer/lumitest/195396 + +publish_data=0 + +[GRID] + +maxtarballsize = 50 +proxy_server = myproxy.cern.ch +#role=t1access +#remove_default_blacklist=1 +se_black_list = T0 +#se_white_list = + +#ce_black_list = in2p3 +#ce_white_list = + +virtual_organization = cms +retry_count = 10 + +[LSF] +queue = 1nh + From 41551037e7d6eb166b06fd29ba1991738cc1a2c2 Mon Sep 17 00:00:00 2001 From: capalmer85 Date: Tue, 21 Apr 2015 01:18:35 +0200 Subject: [PATCH 2/5] technical updates: getByToken, edm::one::EDAnalyzer<> (multi-thread aware) --- .../test/analysis/plugins/PCCNTupler.cc | 15 ++++++----- .../test/analysis/plugins/PCCNTupler.h | 25 +++++++++++++------ .../test/analysis/test/Run_template.py | 2 +- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc index 959e73acfd63f..562f569f046fc 100644 --- a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc +++ b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc @@ -16,7 +16,6 @@ #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h" #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h" -#include "DataFormats/VertexReco/interface/Vertex.h" #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/MakerMacros.h" @@ -24,10 +23,10 @@ #include "FWCore/ServiceRegistry/interface/Service.h" #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" -#include #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" #include "CommonTools/UtilAlgos/interface/TFileService.h" +DEFINE_FWK_MODULE(PCCNTupler); #include @@ -44,6 +43,7 @@ using namespace reco; // ---------------------------------------------------------------------- PCCNTupler::PCCNTupler(edm::ParameterSet const& iConfig): fVerbose(iConfig.getUntrackedParameter("verbose", 0)), + fPrimaryVertexCollectionLabel(iConfig.getUntrackedParameter("vertexCollLabel", edm::InputTag("offlinePrimaryVertices"))), fPixelClusterLabel(iConfig.getUntrackedParameter("pixelClusterLabel", edm::InputTag("siPixelClusters"))), fHLTProcessName(iConfig.getUntrackedParameter("HLTProcessName")), saveType(iConfig.getUntrackedParameter("saveType")), @@ -67,6 +67,7 @@ PCCNTupler::PCCNTupler(edm::ParameterSet const& iConfig): if(includeVertexInformation){ tree->Branch("nGoodVtx","map",&nGoodVtx); tree->Branch("num_Trks",&nTrk,"nTrk/I"); + recoVtxToken=consumes(fPrimaryVertexCollectionLabel); } if(includePixels){ @@ -83,6 +84,7 @@ PCCNTupler::PCCNTupler(edm::ParameterSet const& iConfig): deadModules[3] = 344019460; deadModules[4] = 344019464; deadModules[5] = 344019468; + pixelToken=consumes >(fPixelClusterLabel); } } @@ -98,7 +100,7 @@ void PCCNTupler::endJob() { // ---------------------------------------------------------------------- void PCCNTupler::beginJob() { - + } @@ -190,7 +192,8 @@ void PCCNTupler::analyze(const edm::Event& iEvent, if(includeVertexInformation){ edm::Handle recVtxs; - iEvent.getByLabel("offlinePrimaryVertices",recVtxs); + iEvent.getByToken(recoVtxToken,recVtxs); + if(recVtxs.isValid()){ for(reco::VertexCollection::const_iterator v=recVtxs->begin(); v!=recVtxs->end(); ++v){ @@ -233,7 +236,8 @@ void PCCNTupler::analyze(const edm::Event& iEvent, } // -- Pixel cluster edm::Handle< edmNew::DetSetVector > hClusterColl; - iEvent.getByLabel(fPixelClusterLabel, hClusterColl); + iEvent.getByToken(pixelToken,hClusterColl); + const edmNew::DetSetVector clustColl = *(hClusterColl.product()); @@ -282,6 +286,5 @@ void PCCNTupler::analyze(const edm::Event& iEvent, } // define this as a plug-in -DEFINE_FWK_MODULE(PCCNTupler); diff --git a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h index 8761e51d69cf1..c6abf96797ab4 100644 --- a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h +++ b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h @@ -20,11 +20,15 @@ #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/ServiceRegistry/interface/Service.h" -#include "FWCore/Framework/interface/EDAnalyzer.h" #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h" #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h" #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h" #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h" +#include "DataFormats/VertexReco/interface/VertexFwd.h" +#include "DataFormats/VertexReco/interface/Vertex.h" + +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Utilities/interface/EDGetToken.h" #include "TObject.h" #include "TH1F.h" @@ -38,16 +42,19 @@ class TFile; class RectangularPixelTopology; class DetId; -class PCCNTupler : public edm::EDAnalyzer { + +class PCCNTupler : public edm::one::EDAnalyzer { public: - explicit PCCNTupler(const edm::ParameterSet& ps); + //explicit PCCNTupler(const edm::ParameterSet& ps); + PCCNTupler(const edm::ParameterSet&); virtual ~PCCNTupler(); - virtual void beginJob(); + virtual void beginJob() override; + virtual void endJob() override; + virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override; virtual void beginRun(const edm::Run &, const edm::EventSetup &); virtual void endRun(edm::Run const&, edm::EventSetup const&); - virtual void endJob(); - virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup); - + + protected: void init(); void fillEvent(); @@ -64,6 +71,9 @@ class PCCNTupler : public edm::EDAnalyzer { private: + edm::EDGetTokenT > pixelToken; + edm::EDGetTokenT recoVtxToken; + int fVerbose; std::string fRootFileName; std::string fGlobalTag, fType; @@ -137,4 +147,5 @@ class PCCNTupler : public edm::EDAnalyzer { }; + #endif diff --git a/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py b/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py index 63304540e5736..2cbf9a1201e84 100644 --- a/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py +++ b/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py @@ -52,7 +52,7 @@ #type = cms.untracked.string(getDataset(process.source.fileNames[0])), globalTag = process.GlobalTag.globaltag, dumpAllEvents = cms.untracked.int32(0), - PrimaryVertexCollectionLabel = cms.untracked.InputTag('offlinePrimaryVertices'), + vertexCollLabel = cms.untracked.InputTag('offlinePrimaryVertices'), pixelClusterLabel = cms.untracked.InputTag('siPixelClusters'), HLTProcessName = cms.untracked.string('HLT'), saveType = cms.untracked.string('LumiSect'), # LumiSect, LumiNib, Event From 979025b119b671349cf71cb0a0bc474ad527d6c4 Mon Sep 17 00:00:00 2001 From: capalmer85 Date: Tue, 21 Apr 2015 16:51:54 +0200 Subject: [PATCH 3/5] add lumi section awareness --- .../test/analysis/plugins/PCCNTupler.cc | 17 +++++------------ .../test/analysis/plugins/PCCNTupler.h | 11 +++-------- .../test/analysis/test/Run_template.py | 1 - 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc index 562f569f046fc..04489d34f5023 100644 --- a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc +++ b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc @@ -45,7 +45,6 @@ PCCNTupler::PCCNTupler(edm::ParameterSet const& iConfig): fVerbose(iConfig.getUntrackedParameter("verbose", 0)), fPrimaryVertexCollectionLabel(iConfig.getUntrackedParameter("vertexCollLabel", edm::InputTag("offlinePrimaryVertices"))), fPixelClusterLabel(iConfig.getUntrackedParameter("pixelClusterLabel", edm::InputTag("siPixelClusters"))), - fHLTProcessName(iConfig.getUntrackedParameter("HLTProcessName")), saveType(iConfig.getUntrackedParameter("saveType")), sampleType(iConfig.getUntrackedParameter("sampleType")) { @@ -94,7 +93,6 @@ PCCNTupler::~PCCNTupler() { } // ---------------------------------------------------------------------- void PCCNTupler::endJob() { - tree->Fill(); cout << "==>PCCNTupler> Succesfully gracefully ended job" << endl; } @@ -104,17 +102,13 @@ void PCCNTupler::beginJob() { } -// ---------------------------------------------------------------------- -void PCCNTupler::beginRun(const Run &run, const EventSetup &iSetup) { - bool hasChanged; - fValidHLTConfig = fHltConfig.init(run,iSetup,fHLTProcessName,hasChanged); +void PCCNTupler::beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& isetup){ + firstEvent = true; } -// ---------------------------------------------------------------------- -void PCCNTupler::endRun(Run const&run, EventSetup const&iSetup) { - fValidHLTConfig = false; -} - +void PCCNTupler::endLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& isetup){ + tree->Fill(); +} // ---------------------------------------------------------------------- @@ -128,7 +122,6 @@ void PCCNTupler::analyze(const edm::Event& iEvent, sameEvent = (eventNo==(int)iEvent.id().event()); sameLumiNib = true; // FIXME where is this info? sameLumiSect = (LSNo==(int)iEvent.getLuminosityBlock().luminosityBlock()); - firstEvent = (LSNo==-99); // When arriving at the new LS, LN or event the tree // must be filled and branches must be reset. diff --git a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h index c6abf96797ab4..0d31fdac6974a 100644 --- a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h +++ b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h @@ -43,16 +43,15 @@ class RectangularPixelTopology; class DetId; -class PCCNTupler : public edm::one::EDAnalyzer { +class PCCNTupler : public edm::one::EDAnalyzer { public: - //explicit PCCNTupler(const edm::ParameterSet& ps); PCCNTupler(const edm::ParameterSet&); virtual ~PCCNTupler(); virtual void beginJob() override; virtual void endJob() override; virtual void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override; - virtual void beginRun(const edm::Run &, const edm::EventSetup &); - virtual void endRun(edm::Run const&, edm::EventSetup const&); + void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&); + void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&); protected: @@ -80,7 +79,6 @@ class PCCNTupler : public edm::one::EDAnalyzer { int fDumpAllEvents; edm::InputTag fPrimaryVertexCollectionLabel; edm::InputTag fPixelClusterLabel; - std::string fHLTProcessName; bool fAccessSimHitInfo; @@ -107,9 +105,6 @@ class PCCNTupler : public edm::one::EDAnalyzer { uint32_t deadModules[6]; int nDeadPrint; - HLTConfigProvider fHltConfig; - bool fValidHLTConfig; - // saving events per LS, LN or event std::string saveType = "LumiSect"; // LumiSect or LumiNib or Event bool saveAndReset; diff --git a/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py b/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py index 2cbf9a1201e84..80d9091c05807 100644 --- a/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py +++ b/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py @@ -54,7 +54,6 @@ dumpAllEvents = cms.untracked.int32(0), vertexCollLabel = cms.untracked.InputTag('offlinePrimaryVertices'), pixelClusterLabel = cms.untracked.InputTag('siPixelClusters'), - HLTProcessName = cms.untracked.string('HLT'), saveType = cms.untracked.string('LumiSect'), # LumiSect, LumiNib, Event sampleType = cms.untracked.string('DATA'), # MC, DATA L1GTReadoutRecordLabel = cms.untracked.InputTag('gtDigis'), From 0d2644f7b0b47546b25a11716de8f6fe8df1dd2d Mon Sep 17 00:00:00 2001 From: capalmer85 Date: Tue, 21 Apr 2015 17:11:01 +0200 Subject: [PATCH 4/5] add override --- .../LumiProducer/test/analysis/plugins/PCCNTupler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h index 0d31fdac6974a..4f1f06d394c76 100644 --- a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h +++ b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h @@ -50,8 +50,8 @@ class PCCNTupler : public edm::one::EDAnalyzer Date: Thu, 23 Apr 2015 16:39:09 +0200 Subject: [PATCH 5/5] add consumes for pileup info --- .../LumiProducer/test/analysis/plugins/PCCNTupler.cc | 10 +++++++--- .../LumiProducer/test/analysis/plugins/PCCNTupler.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc index 04489d34f5023..b4c80ebfbb083 100644 --- a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc +++ b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.cc @@ -45,6 +45,7 @@ PCCNTupler::PCCNTupler(edm::ParameterSet const& iConfig): fVerbose(iConfig.getUntrackedParameter("verbose", 0)), fPrimaryVertexCollectionLabel(iConfig.getUntrackedParameter("vertexCollLabel", edm::InputTag("offlinePrimaryVertices"))), fPixelClusterLabel(iConfig.getUntrackedParameter("pixelClusterLabel", edm::InputTag("siPixelClusters"))), + fPileUpInfoLabel(edm::InputTag("addPileupInfo")), saveType(iConfig.getUntrackedParameter("saveType")), sampleType(iConfig.getUntrackedParameter("sampleType")) { @@ -86,6 +87,9 @@ PCCNTupler::PCCNTupler(edm::ParameterSet const& iConfig): pixelToken=consumes >(fPixelClusterLabel); } + if(sampleType=="MC"){ + pileUpToken=consumes >(fPileUpInfoLabel); + } } // ---------------------------------------------------------------------- @@ -147,10 +151,10 @@ void PCCNTupler::analyze(const edm::Event& iEvent, } if(sampleType=="MC"){ - edm::Handle > PupInfo; - iEvent.getByLabel("addPileupInfo", PupInfo); + edm::Handle > pileUpInfo; + iEvent.getByToken(pileUpToken, pileUpInfo); std::vector::const_iterator PVI; - for(PVI = PupInfo->begin(); PVI != PupInfo->end(); ++PVI) { + for(PVI = pileUpInfo->begin(); PVI != pileUpInfo->end(); ++PVI) { int pu_bunchcrossing = PVI->getBunchCrossing(); //std::cout<<"pu_bunchcrossing getPU_NumInteractions getTrueNumInteractions "<getPU_NumInteractions()<<" "<getTrueNumInteractions()< > pixelToken; edm::EDGetTokenT recoVtxToken; + edm::EDGetTokenT > pileUpToken; int fVerbose; std::string fRootFileName; @@ -79,6 +80,7 @@ class PCCNTupler : public edm::one::EDAnalyzer