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..b4c80ebfbb083 --- /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 "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 "DataFormats/SiPixelCluster/interface/SiPixelCluster.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" +DEFINE_FWK_MODULE(PCCNTupler); + + +#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)), + 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")) +{ + 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"); + recoVtxToken=consumes(fPrimaryVertexCollectionLabel); + } + + 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; + pixelToken=consumes >(fPixelClusterLabel); + } + + if(sampleType=="MC"){ + pileUpToken=consumes >(fPileUpInfoLabel); + } +} + +// ---------------------------------------------------------------------- +PCCNTupler::~PCCNTupler() { } + +// ---------------------------------------------------------------------- +void PCCNTupler::endJob() { + cout << "==>PCCNTupler> Succesfully gracefully ended job" << endl; +} + +// ---------------------------------------------------------------------- +void PCCNTupler::beginJob() { + +} + + +void PCCNTupler::beginLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& isetup){ + firstEvent = true; +} + +void PCCNTupler::endLuminosityBlock(edm::LuminosityBlock const& lumi, edm::EventSetup const& isetup){ + tree->Fill(); +} + + +// ---------------------------------------------------------------------- +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()); + + // 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 > pileUpInfo; + iEvent.getByToken(pileUpToken, pileUpInfo); + std::vector::const_iterator PVI; + for(PVI = pileUpInfo->begin(); PVI != pileUpInfo->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.getByToken(recoVtxToken,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.getByToken(pixelToken,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 + + diff --git a/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h new file mode 100644 index 0000000000000..400f239932d42 --- /dev/null +++ b/RecoLuminosity/LumiProducer/test/analysis/plugins/PCCNTupler.h @@ -0,0 +1,148 @@ +#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 "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" + +using namespace reco; + +class TObject; +class TTree; +class TH1D; +class TFile; +class RectangularPixelTopology; +class DetId; + + +class PCCNTupler : public edm::one::EDAnalyzer { + public: + 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; + void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + + 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: + edm::EDGetTokenT > pixelToken; + edm::EDGetTokenT recoVtxToken; + edm::EDGetTokenT > pileUpToken; + + int fVerbose; + std::string fRootFileName; + std::string fGlobalTag, fType; + int fDumpAllEvents; + edm::InputTag fPrimaryVertexCollectionLabel; + edm::InputTag fPixelClusterLabel; + edm::InputTag fPileUpInfoLabel; + + 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; + + // 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..80d9091c05807 --- /dev/null +++ b/RecoLuminosity/LumiProducer/test/analysis/test/Run_template.py @@ -0,0 +1,78 @@ +# ###################################################################### +# +# 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), + vertexCollLabel = cms.untracked.InputTag('offlinePrimaryVertices'), + pixelClusterLabel = cms.untracked.InputTag('siPixelClusters'), + 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 +