Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New script and macro to extract occupancy plots from DQM files #8298

Merged
merged 3 commits into from Mar 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions DQM/SiStripMonitorClient/README.md
@@ -0,0 +1,10 @@
###Macros and Scripts
####moduleOccupancyPlots
`moduleOccupancyPlots.sh <Datataking_period> <Dataset_type> <runnumber> <modulelistfile> <user certificate file> <user key file>`

This script produces a root file and png files of the occupancy plots of the modules selected with the file
`<modulelistfile>` which contains a list of detid from run `<runnumber>` as found in the official DQM file. The
`<Datataking_period>` and the `<Dataset_type>` have to match the names used in this site:
https://cmsweb.cern.ch/dqm/offline/data/browse/ROOT/OfflineData/

To access the DQM file a valid certificate and key has to be provided to the script
1 change: 1 addition & 0 deletions DQM/SiStripMonitorClient/bin/BuildFile.xml
Expand Up @@ -5,3 +5,4 @@
<bin name="modulediff" file="modulediff.cc"></bin>
<bin name="ls_cert" file="ls_cert.cc"></bin>
<bin name="lsbs_cert" file="lsbs_cert.cc"></bin>
<bin name="moduleOccupancyPlots" file="moduleOccupancyPlots.cc"></bin>
111 changes: 111 additions & 0 deletions DQM/SiStripMonitorClient/bin/moduleOccupancyPlots.cc
@@ -0,0 +1,111 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

#include "TFile.h"
#include "TH1D.h"
#include "TCanvas.h"

#define NOISEPREFIX "Profile_NoiseFromCondDB__det__"
#define PEDESTALPREFIX "Profile_PedestalFromCondDB__det__"
#define OCCUPANCYPREFIX "ClusterDigiPosition__det__"

void printPlot(TH1D* hist, char* prefix, char* postfix);

int main(int argc, char *argv[]) {

char* rootfilename;
char* modulelistname;
int pnbits;
char* prefix;
char* postfix;

if(argc==6) {
rootfilename = argv[1];
modulelistname = argv[2];
pnbits = atoi(argv[3]);
prefix = argv[4];
postfix = argv[5];
}
else {
std::cout << "Wrong number of parameters " << argc << std::endl;
return 1;
}

std::cout << "ready to go " << rootfilename << ' ' << modulelistname << std::endl;

TFile* rootfile = new TFile(rootfilename,"READ");
if(!rootfile) {
std::cout << "Problems with input root file" << std::endl;
return 2;
}
int detid;
std::ifstream modulelist(modulelistname);

std::stringstream outrootfilename;
outrootfilename << prefix << "SummaryFile" << postfix << ".root";
TFile* outrootfile = new TFile(outrootfilename.str().c_str(),"CREATE");

while (modulelist >> detid) {
std::cout << " ready to go with detid " << detid << " " << pnbits << std::endl;
// bit 0: noise
if(pnbits & 1) {
std::stringstream histoname;
histoname << NOISEPREFIX << detid;
std::cout << " ready to go with histogram " << histoname.str() << std::endl;
TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
if(hist) {
std:: cout << histoname.str() << " found!" << std::endl;
printPlot(hist,prefix,postfix);
hist->Write();
} else {
std:: cout << histoname.str() << " NOT found..." << std::endl;
}
}
// bit 1: pedestal
if(pnbits & 2) {
std::stringstream histoname;
histoname << PEDESTALPREFIX << detid;
std::cout << " ready to go with histogram " << histoname.str() << std::endl;
TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
if(hist) {
std:: cout << histoname.str() << " found!" << std::endl;
printPlot(hist,prefix,postfix);
hist->Write();
} else {
std:: cout << histoname.str() << " NOT found..." << std::endl;
}
}
// bit 2: pedestal
if(pnbits & 4) {
std::stringstream histoname;
histoname << OCCUPANCYPREFIX << detid;
std::cout << " ready to go with histogram " << histoname.str() << std::endl;
TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
if(hist) {
std:: cout << histoname.str() << " found!" << std::endl;
printPlot(hist,prefix,postfix);
hist->Write();
} else {
std:: cout << histoname.str() << " NOT found..." << std::endl;
}
}
}

outrootfile->Close();

return 0;

}

void printPlot(TH1D* hist, char* prefix, char* postfix) {

TCanvas* cc= new TCanvas;
hist->Draw();
std::stringstream filename;
filename << prefix << hist->GetName() << postfix << ".png";
cc->Print(filename.str().c_str());
delete cc;

}
17 changes: 17 additions & 0 deletions DQM/SiStripMonitorClient/scripts/moduleOccupancyPlots.sh
@@ -0,0 +1,17 @@
#!/bin/bash

#export PATH=/afs/cern.ch/cms/common:${PATH}
if [[ "$#" == "0" ]]; then
echo "usage: 'moduleOccupancyPlots.sh RootFileDirectory Dataset RunNumber ModuleListFile UserCertFile UserKeyFile'";
exit 1;
fi

nnn=`echo $3 | awk '{print substr($0,0,4)}'`
curl -k --cert $5 --key $6 -X GET 'https://cmsweb.cern.ch/dqm/offline/data/browse/ROOT/OfflineData/'$1'/'$2'/000'${nnn}'xx/' > index.html
dqmFileNames=`cat index.html | grep $3 | grep "_DQM.root" | egrep "Prompt|Express" | sed 's/.*>\(.*\)<\/a.*/\1/' `
dqmFileName=`expr "$dqmFileNames" : '\(DQM[A-Za-z0-9_/.\-]*root\)'`
echo ' dqmFileNames = '$dqmFileNames
echo ' dqmFileName = ['$dqmFileName']'
curl -k --cert $5 --key $6 -X GET https://cmsweb.cern.ch/dqm/offline/data/browse/ROOT/OfflineData/$1/$2/000${nnn}xx/${dqmFileName} > /tmp/${dqmFileName}

moduleOccupancyPlots /tmp/${dqmFileName} $4 4 "$2_" "_run_$3"