Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of new data vs emulator analyzer
- Loading branch information
Sven Dildick
committed
Apr 29, 2021
1 parent
f2a33b5
commit 033a209
Showing
4 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
167 changes: 167 additions & 0 deletions
167
L1Trigger/CSCTriggerPrimitives/plugins/CSCTriggerPrimitivesAnalyzer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
#include "L1Trigger/CSCTriggerPrimitives/plugins/CSCTriggerPrimitivesAnalyzer.h" | ||
#include "FWCore/Framework/interface/MakerMacros.h" | ||
#include "FWCore/MessageLogger/interface/MessageLogger.h" | ||
#include "FWCore/ServiceRegistry/interface/Service.h" | ||
#include "CommonTools/UtilAlgos/interface/TFileService.h" | ||
|
||
|
||
#include "TCanvas.h" | ||
#include "TFile.h" | ||
#include "TH1.h" | ||
#include "TText.h" | ||
#include "TPaveLabel.h" | ||
#include "TLegend.h" | ||
#include "TPostScript.h" | ||
#include "TStyle.h" | ||
#include "TROOT.h" | ||
#include "TFile.h" | ||
|
||
#include <iostream> | ||
CSCTriggerPrimitivesAnalyzer::CSCTriggerPrimitivesAnalyzer(const edm::ParameterSet& conf) : | ||
rootFileName_(conf.getParameter<std::string>("rootFileName")), | ||
runNumber_(conf.getParameter<unsigned>("runNumber")), | ||
monitorDir_(conf.getParameter<std::string>("monitorDir")), | ||
chambers_(conf.getParameter<std::vector<std::string>>("chambers")), | ||
// variables | ||
alctVars_(conf.getParameter<std::vector<std::string>>("alctVars")), | ||
clctVars_(conf.getParameter<std::vector<std::string>>("clctVars")), | ||
lctVars_(conf.getParameter<std::vector<std::string>>("lctVars")), | ||
dataVsEmulatorPlots_(conf.getParameter<bool>("dataVsEmulatorPlots")), | ||
mcEfficiencyPlots_(conf.getParameter<bool>("mcEfficiencyPlots")), | ||
mcResolutionPlots_(conf.getParameter<bool>("mcResolutionPlots")) | ||
{ | ||
} | ||
|
||
//---------------- | ||
// Destructor -- | ||
//---------------- | ||
CSCTriggerPrimitivesAnalyzer::~CSCTriggerPrimitivesAnalyzer() { | ||
} | ||
|
||
void CSCTriggerPrimitivesAnalyzer::analyze(const edm::Event& ev, const edm::EventSetup& setup) { | ||
// efficiency and resolution analysis is done here | ||
} | ||
|
||
void CSCTriggerPrimitivesAnalyzer::endJob() { | ||
|
||
if (dataVsEmulatorPlots_) | ||
makeDataVsEmulatorPlots(); | ||
} | ||
|
||
void CSCTriggerPrimitivesAnalyzer::makeDataVsEmulatorPlots() { | ||
// data vs emulator plots are created here | ||
edm::Service<TFileService> fs; | ||
|
||
// split monitorDir_ into two substrings | ||
std::string delimiter = "/"; | ||
int pos = monitorDir_.find(delimiter); | ||
std::string superDir = monitorDir_.substr(0, pos); | ||
monitorDir_.erase(0, pos + delimiter.length()); | ||
std::string subDir = monitorDir_; | ||
std::string path = "DQMData/Run " + std::to_string(runNumber_) + "/" + superDir + "/Run summary/" + subDir + "/"; | ||
|
||
std::cout << superDir << " " << subDir << std::endl; | ||
|
||
TFile* theFile = new TFile(rootFileName_.c_str()); | ||
if (theFile) { | ||
std::cout << "Loading DQM ROOT file: " << rootFileName_ << std::endl; | ||
} | ||
else { | ||
std::cout << "Unable to load DQM ROOT file: " << rootFileName_ << std::endl; | ||
return; | ||
} | ||
|
||
TDirectory* directory = theFile->GetDirectory(path.c_str()); | ||
if (directory) { | ||
std::cout << "Navigating to directory: " << path << std::endl; | ||
} | ||
else { | ||
std::cout << "Unable to navigate to directory: " << path << std::endl; | ||
return; | ||
} | ||
|
||
TPostScript* ps = new TPostScript("CSC_data_vs_emulation.ps", 111); | ||
|
||
// unsigned page = 1; | ||
|
||
// chamber type | ||
for (unsigned iType = 0; iType < chambers_.size(); iType++) { | ||
// alct variable | ||
for (unsigned iVar = 0; iVar < alctVars_.size(); iVar++) { | ||
const std::string key("alct_" + alctVars_[iVar]); | ||
const std::string histData(key + "_data_" + chambers_[iType]); | ||
const std::string histEmul(key + "_emul_" + chambers_[iType]); | ||
const std::string histDiff(key + "_diff_" + chambers_[iType]); | ||
|
||
TH1F * dataMon = (TH1F *) directory->Get(histData.c_str()); | ||
TH1F * emulMon = (TH1F *) directory->Get(histEmul.c_str()); | ||
TH1F * diffMon = (TH1F *) directory->Get(histDiff.c_str()); | ||
|
||
// when all histograms are found, make a new canvas and add it to | ||
// the collection | ||
if (dataMon && emulMon && diffMon) { | ||
makePlot(dataMon, emulMon, diffMon, "alct_", TString(alctVars_[iVar]), TString(chambers_[iType]), ps); | ||
// page++; | ||
} | ||
} | ||
} | ||
ps->Close(); | ||
// close the DQM file | ||
theFile->Close(); | ||
} | ||
|
||
void CSCTriggerPrimitivesAnalyzer::makePlot(TH1F * dataMon, TH1F * emulMon, TH1F * diffMon, TString lct, TString var, TString chamber, TPostScript* ps) const { | ||
ps->NewPage(); | ||
|
||
TCanvas* c1 = new TCanvas("c1", "", 800, 800); | ||
c1->Clear(); | ||
c1->Divide(2,1); | ||
c1->cd(1); | ||
|
||
TPad* pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0); | ||
pad1->SetBottomMargin(0.1); | ||
pad1->SetGridx(); | ||
pad1->SetGridy(); | ||
pad1->Draw(); | ||
pad1->cd(); | ||
gStyle->SetOptStat(1111); | ||
dataMon->SetTitle("ALCT " + var + " " + chamber); | ||
dataMon->GetXaxis()->SetTitle(var); | ||
dataMon->GetYaxis()->SetTitle("Entries"); | ||
dataMon->SetMarkerColor(kBlack); | ||
dataMon->SetMarkerStyle(kPlus); | ||
dataMon->SetMarkerSize(3); | ||
dataMon->Draw("histp"); | ||
emulMon->SetLineColor(kRed); | ||
emulMon->Draw("histsame"); | ||
auto legend = new TLegend(0.7,0.7,0.9,0.9); | ||
legend->AddEntry(dataMon,"Data","l"); | ||
legend->AddEntry(emulMon,"Emulator","l"); | ||
legend->Draw(); | ||
c1->cd(2); | ||
|
||
TPad *pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.3); | ||
pad2->SetTopMargin(0.1); | ||
pad2->SetBottomMargin(0.2); | ||
pad2->SetGridx(); | ||
pad2->SetGridy(); | ||
pad2->Draw(); | ||
pad2->cd(); | ||
gStyle->SetOptStat(0); | ||
diffMon->SetLineColor(kBlack); | ||
diffMon->SetTitle(""); | ||
diffMon->GetXaxis()->SetTitle(var); | ||
diffMon->GetYaxis()->SetTitle("Emul - Data"); | ||
diffMon->GetYaxis()->SetTitleOffset(0.4); | ||
diffMon->GetXaxis()->SetLabelSize(0.1); | ||
diffMon->GetYaxis()->SetLabelSize(0.1); | ||
diffMon->GetXaxis()->SetTitleSize(0.1); | ||
diffMon->GetYaxis()->SetTitleSize(0.1); | ||
diffMon->Draw("ep"); | ||
|
||
delete pad1; | ||
delete pad2; | ||
delete c1; | ||
} | ||
|
||
DEFINE_FWK_MODULE(CSCTriggerPrimitivesAnalyzer); |
63 changes: 63 additions & 0 deletions
63
L1Trigger/CSCTriggerPrimitives/plugins/CSCTriggerPrimitivesAnalyzer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef L1Trigger_CSCTriggerPrimitives_CSCTriggerPrimitivesAnalyzer_h | ||
#define L1Trigger_CSCTriggerPrimitives_CSCTriggerPrimitivesAnalyzer_h | ||
|
||
/** \class CSCTriggerPrimitivesAnalyzer | ||
* | ||
* Basic analyzer class which accesses ALCTs, CLCTs, and correlated LCTs | ||
* and plot various quantities. | ||
* | ||
* \author Sven Dildick, UCLA. | ||
* | ||
*/ | ||
|
||
#include "FWCore/Utilities/interface/EDGetToken.h" | ||
#include "FWCore/Framework/interface/Frameworkfwd.h" | ||
#include "FWCore/Framework/interface/EDAnalyzer.h" | ||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/EventSetup.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "FWCore/Utilities/interface/InputTag.h" | ||
#include "FWCore/Utilities/interface/ESGetToken.h" | ||
|
||
#include "TH1F.h" | ||
#include "TPostScript.h" | ||
|
||
#include <string> | ||
|
||
class CSCTriggerPrimitivesAnalyzer : public edm::EDAnalyzer { | ||
public: | ||
/// Constructor | ||
explicit CSCTriggerPrimitivesAnalyzer(const edm::ParameterSet &conf); | ||
|
||
/// Destructor | ||
~CSCTriggerPrimitivesAnalyzer() override; | ||
|
||
/// Does the job | ||
void analyze(const edm::Event &event, const edm::EventSetup &setup) override; | ||
|
||
/// Write to ROOT file, make plots, etc. | ||
void endJob() override; | ||
|
||
private: | ||
|
||
void makePlot(TH1F* dataMon, TH1F* emulMon, TH1F* diffMon, TString lct, TString var, TString chamber, TPostScript* ps) const; | ||
|
||
// plots of data vs emulator | ||
std::string rootFileName_; | ||
unsigned runNumber_; | ||
std::string monitorDir_; | ||
std::vector<std::string> chambers_; | ||
std::vector<std::string> alctVars_; | ||
std::vector<std::string> clctVars_; | ||
std::vector<std::string> lctVars_; | ||
bool dataVsEmulatorPlots_; | ||
void makeDataVsEmulatorPlots(); | ||
|
||
// plots of efficiencies in MC | ||
bool mcEfficiencyPlots_; | ||
|
||
// plots of resolution in MC | ||
bool mcResolutionPlots_; | ||
}; | ||
|
||
#endif |
12 changes: 12 additions & 0 deletions
12
L1Trigger/CSCTriggerPrimitives/python/cscTriggerPrimitivesAnalyzer_cfi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
from DQM.L1TMonitor.L1TdeCSCTPG_cfi import l1tdeCSCTPGCommon | ||
|
||
cscTriggerPrimitivesAnalyzer = cms.EDAnalyzer( | ||
"CSCTriggerPrimitivesAnalyzer", | ||
l1tdeCSCTPGCommon, | ||
rootFileName = cms.string("/uscms_data/d3/dildick/work/CSCValDQMReport/CMSSW_12_0_X_2021-04-19-2300/src/upload/DQM_V0001_L1TEMU_R000334393.root"), | ||
runNumber = cms.uint32(334393), | ||
dataVsEmulatorPlots = cms.bool(True), | ||
mcEfficiencyPlots = cms.bool(False), | ||
mcResolutionPlots = cms.bool(False), | ||
) |
10 changes: 10 additions & 0 deletions
10
L1Trigger/CSCTriggerPrimitives/test/CSCTriggerPrimitiveAnalyzer_cfg.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import FWCore.ParameterSet.Config as cms | ||
|
||
from Configuration.Eras.Era_Run2_2018_cff import Run2_2018 | ||
process = cms.Process("L1CSCTriggerPrimitivesReader", Run2_2018) | ||
process.load("L1Trigger.CSCTriggerPrimitives.cscTriggerPrimitivesAnalyzer_cfi") | ||
|
||
process.source = cms.Source("EmptySource") | ||
process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(1)) | ||
|
||
process.p = cms.Path(process.cscTriggerPrimitivesAnalyzer) |