Skip to content

Commit

Permalink
Merge pull request #22129 from jpriscia/apvGainToTree
Browse files Browse the repository at this point in the history
Strip APV gains dumped in TTree
  • Loading branch information
cmsbuild committed Feb 20, 2018
2 parents 32425bf + 48d2b6d commit 8ac6801
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CondTools/SiStrip/README.md
@@ -0,0 +1,7 @@
## CondTools/SiStrip

- _SiStripApvGainReader_: reads APV gains from input sqlite. Dumps TTree with following infos: detectorID, APV number, gain
Infos are also dumped in txt file, in format : DetId APV1 APV2 APV3 APV4 (APV5) (APV6)
- To run:
- `cmsRun test/SiStripApvGainReader_cfg.py inputFiles=sqlite_input tag=my_tag runN=run_in_IOV`
- `readSiStripApvGain.py inputFiles=sqlite_input tag=my_tag runN=run_in_IOV`
1 change: 1 addition & 0 deletions CondTools/SiStrip/plugins/BuildFile.xml
Expand Up @@ -6,6 +6,7 @@
<use name="Geometry/Records"/>
<use name="Geometry/TrackerGeometryBuilder"/>
<use name="CommonTools/TrackerMap"/>
<use name="CommonTools/UtilAlgos"/>
<use name="CalibTracker/Records"/>
<use name="CondCore/DBOutputService"/>
<use name="CondFormats/SiStripObjects"/>
Expand Down
23 changes: 19 additions & 4 deletions CondTools/SiStrip/plugins/SiStripApvGainReader.cc
Expand Up @@ -15,8 +15,17 @@ using namespace cms;
SiStripApvGainReader::SiStripApvGainReader( const edm::ParameterSet& iConfig ):
printdebug_(iConfig.getUntrackedParameter<bool>("printDebug",true)),
formatedOutput_(iConfig.getUntrackedParameter<std::string>("outputFile","")),
gainType_ (iConfig.getUntrackedParameter<uint32_t>("gainType",1))
{}
gainType_ (iConfig.getUntrackedParameter<uint32_t>("gainType",1)),
tree_(0){
if (fs_.isAvailable()){
tree_=fs_->make<TTree>("Gains","Gains");

tree_->Branch("Index",&id_,"Index/I");
tree_->Branch("DetId",&detId_,"DetId/I");
tree_->Branch("APVId",&apvId_,"APVId/I");
tree_->Branch("Gain",&gain_,"Gain/D");
}
}

SiStripApvGainReader::~SiStripApvGainReader(){}

Expand All @@ -25,20 +34,26 @@ void SiStripApvGainReader::analyze( const edm::Event& e, const edm::EventSetup&
edm::ESHandle<SiStripGain> SiStripApvGain_;
iSetup.get<SiStripGainRcd>().get(SiStripApvGain_);
edm::LogInfo("SiStripApvGainReader") << "[SiStripApvGainReader::analyze] End Reading SiStripApvGain" << std::endl;

std::vector<uint32_t> detid;
SiStripApvGain_->getDetIds(detid);
edm::LogInfo("Number of detids ") << detid.size() << std::endl;

FILE* pFile=nullptr;
if(formatedOutput_!="")pFile=fopen(formatedOutput_.c_str(), "w");

for (size_t id=0;id<detid.size();id++){
SiStripApvGain::Range range=SiStripApvGain_->getRange(detid[id], gainType_);
if(printdebug_){
int apv=0;
for(int it=0;it<range.second-range.first;it++){
edm::LogInfo("SiStripApvGainReader") << "detid " << detid[id] << " \t " << apv++ << " \t " << SiStripApvGain_->getApvGain(it,range) << std::endl;
id_++;

if (tree_){
detId_ = detid[id];
apvId_ = apv ;
gain_ = SiStripApvGain_->getApvGain(it,range);
tree_->Fill();
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion CondTools/SiStrip/plugins/SiStripApvGainReader.h
Expand Up @@ -13,8 +13,14 @@
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"


// root objects
#include "TROOT.h"
#include "TSystem.h"
#include "TFile.h"
#include "TDirectory.h"
#include "TTree.h"

class SiStripApvGainReader : public edm::EDAnalyzer {

Expand All @@ -28,6 +34,10 @@ class SiStripApvGainReader : public edm::EDAnalyzer {
bool printdebug_;
std::string formatedOutput_;
uint32_t gainType_;
edm::Service<TFileService> fs_;
TTree *tree_;
int id_=0, detId_=0, apvId_=0;
double gain_=0;

};
#endif
80 changes: 80 additions & 0 deletions CondTools/SiStrip/scripts/readSiStripApvGain.py
@@ -0,0 +1,80 @@
#! /bin/env cmsRun
import FWCore.ParameterSet.Config as cms
from FWCore.ParameterSet.VarParsing import VarParsing


options = VarParsing('python')
options.register('runN', 1,
VarParsing.multiplicity.singleton,
VarParsing.varType.int,
"runN in the IOV"
)

options.parseArguments()

if (not options.tag or not options.inputFiles):
raise ValueError('usage: cmsRun SiStripApvGainReader_cfg.py inputFiles=my_input_file tag=my_tag')
process = cms.Process("SiStripApvGainReader")

process.MessageLogger = cms.Service(
"MessageLogger",
debugModules = cms.untracked.vstring(''),
threshold = cms.untracked.string('INFO'),
destinations = cms.untracked.vstring('SiStripApvGainReader.log')
)

##
## Empty events source
## (specify the run number to pick correct IOV)
##
process.source = cms.Source("EmptySource",
numberEventsInRun = cms.untracked.uint32(1),
firstRun = cms.untracked.uint32(options.runN)
)

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(1)
)

##
## To Correctly build the SiStripGainRcd in the ES
## we need all the dependent records => specify a Global Tag
##
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
from Configuration.AlCa.GlobalTag import GlobalTag

process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '')


##
## Prefer the SiStripApvGainRcd or SiStripApvGain2Rcd
## under test
##
process.poolDBESSource = cms.ESSource("PoolDBESSource",
#connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
connect = cms.string(options.inputFiles[0]),
toGet = cms.VPSet(cms.PSet(record = cms.string('SiStripApvGainRcd'),
tag = cms.string(options.tag)
)
)
)
process.prefer_poolDBESSource = cms.ESPrefer("PoolDBESSource","poolDBESSource")

##
## Dump the Gain payload. It will be in the format
## DetId APV1 APV2 APV3 APV4 (APV5) (APV6)
##
process.gainreader = cms.EDAnalyzer("SiStripApvGainReader",
printDebug = cms.untracked.bool(True),
outputFile = cms.untracked.string("SiStripApvGains_dump.txt"),
gainType = cms.untracked.uint32(0) #0 for G1, 1 for G2
)

process.TFileService = cms.Service("TFileService",
fileName = cms.string("gain.root"),
closeFileFast = cms.untracked.bool(True)
)

process.p1 = cms.Path(process.gainreader)


27 changes: 24 additions & 3 deletions CondTools/SiStrip/test/SiStripApvGainReader_cfg.py
@@ -1,5 +1,18 @@
import FWCore.ParameterSet.Config as cms
from FWCore.ParameterSet.VarParsing import VarParsing


options = VarParsing('python')
options.register('runN', 1,
VarParsing.multiplicity.singleton,
VarParsing.varType.int,
"runN in the IOV"
)

options.parseArguments()

if (not options.tag or not options.inputFiles):
raise ValueError('usage: cmsRun SiStripApvGainReader_cfg.py inputFiles=my_input_file tag=my_tag')
process = cms.Process("SiStripApvGainReader")

process.MessageLogger = cms.Service(
Expand All @@ -15,7 +28,7 @@
##
process.source = cms.Source("EmptySource",
numberEventsInRun = cms.untracked.uint32(1),
firstRun = cms.untracked.uint32(1)
firstRun = cms.untracked.uint32(options.runN)
)

process.maxEvents = cms.untracked.PSet(
Expand All @@ -28,16 +41,19 @@
##
process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
from Configuration.AlCa.GlobalTag import GlobalTag

process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_data', '')


##
## Prefer the SiStripApvGainRcd or SiStripApvGain2Rcd
## under test
##
process.poolDBESSource = cms.ESSource("PoolDBESSource",
connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
#connect = cms.string('frontier://FrontierProd/CMS_CONDITIONS'),
connect = cms.string(options.inputFiles[0]),
toGet = cms.VPSet(cms.PSet(record = cms.string('SiStripApvGainRcd'),
tag = cms.string('SiStripApvGain_GR10_v1_hlt')
tag = cms.string(options.tag)
)
)
)
Expand All @@ -53,6 +69,11 @@
gainType = cms.untracked.uint32(0) #0 for G1, 1 for G2
)

process.TFileService = cms.Service("TFileService",
fileName = cms.string("gain.root"),
closeFileFast = cms.untracked.bool(True)
)

process.p1 = cms.Path(process.gainreader)


0 comments on commit 8ac6801

Please sign in to comment.