Skip to content

Commit

Permalink
Merge pull request #40182 from mmusich/fixEoPPlottingMacro
Browse files Browse the repository at this point in the history
[TkAl] Fix EoP Validation plotting macros
  • Loading branch information
cmsbuild authored Dec 15, 2022
2 parents a82f3ca + 7e15bdf commit c0d007c
Show file tree
Hide file tree
Showing 10 changed files with 696 additions and 586 deletions.
1,145 changes: 621 additions & 524 deletions Alignment/OfflineValidation/macros/momentumBiasValidation.C

Large diffs are not rendered by default.

74 changes: 35 additions & 39 deletions Alignment/OfflineValidation/macros/momentumElectronBiasValidation.C
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ std::vector<Double_t> extractgausparams(TH1F* histo, TString option1, TString op

// -----------------------------------------------------------------------------
//
// Main function : momentumBiasValidation
// Main function : momentumElectronBiasValidation
//
// -----------------------------------------------------------------------------
void momentumBiasValidation(TString variable,
TString path,
TString alignmentWithLabel,
TString outputType,
Double_t radius = 1.,
Bool_t verbose = false,
Double_t givenMin = 0.,
Double_t givenMax = 0.) {
void momentumElectronBiasValidation(TString variable,
TString path,
TString alignmentWithLabel,
TString outputType,
Double_t radius = 1.,
Bool_t verbose = false,
Double_t givenMin = 0.,
Double_t givenMax = 0.) {
// Displaying first message
std::cout << "!!! Welcome to momentumBiasValidation !!!" << std::endl;
std::cout << "!!! Welcome to momentumElectronBiasValidation !!!" << std::endl;
std::cout << std::endl;
time_t start = time(0);

Expand All @@ -140,24 +140,25 @@ void momentumBiasValidation(TString variable,
std::cout << "Initializing the TTree ..." << std::endl;
std::vector<TTree*> trees(files.size(), 0);
EopElecVariables* track = new EopElecVariables();
if (!initializeTree(files, trees, track))
if (!initializeTree(files, trees, track)) {
delete track;
return;
return;
}

// Configuring ROOT style
std::cout << "Configuring the ROOT style ..." << std::endl;
configureROOTstyle(verbose);

TCanvas* c = new TCanvas("c", "Canvas", 0, 0, 1150, 800);
TCanvas* ccontrol = new TCanvas("ccontrol", "controlCanvas", 0, 0, 600, 300);
TCanvas* c = new TCanvas("cElectron", "Canvas", 0, 0, 1150, 800);
TCanvas* ccontrol = new TCanvas("ccontrolElectron", "controlCanvas", 0, 0, 600, 300);

// Creating histos
std::vector<HistoType> histos(files.size());

// Loop over files

// To save the table cut
TFile* histo1;
TFile* histo1 = nullptr;
std::string fileName;

for (unsigned int ifile = 0; ifile < histos.size(); ifile++) {
Expand Down Expand Up @@ -416,6 +417,11 @@ void fillFinalHisto(ModeType mode, Bool_t verbose, HistoType& histo) {
// calculate mean of different energy bins
TF1* fit = new TF1("fit", "pol0", 0, histo.eRange.size() - 1);
TF1* fit2 = new TF1("fit2", "pol0", 0, histo.eRange.size() - 1);

if (histo.fit[i]->GetEntries() < 10) {
return;
}

histo.fit[i]->Fit("fit", fitOption + "0");
histo.combinedxAxisBin[i]->Fit("fit2", "Q0");
overallmisalignment = fit->GetParameter(0);
Expand Down Expand Up @@ -542,9 +548,11 @@ void layoutFinalPlot(ModeType mode,
}

// Fit function
histos[i].f2->SetLineColor(i + 1);
histos[i].f2->SetLineStyle(i + 1);
histos[i].f2->SetLineWidth(2);
if (histos[i].f2) {
histos[i].f2->SetLineColor(i + 1);
histos[i].f2->SetLineStyle(i + 1);
histos[i].f2->SetLineWidth(2);
}

// Other settings
histos[i].overallhisto->GetYaxis()->SetTitleOffset(1.05);
Expand Down Expand Up @@ -609,7 +617,9 @@ void layoutFinalPlot(ModeType mode,

// draw final histogram
histos[i].overallhisto->DrawClone("pe1 same");
histos[i].f2->DrawClone("same");
if (histos[i].f2) {
histos[i].f2->DrawClone("same");
}
histos[i].overallGraph->DrawClone("|| same");
histos[i].overallGraph->DrawClone("pz same");
histos[i].overallGraph->SetLineStyle(i + 1);
Expand Down Expand Up @@ -663,7 +673,7 @@ void initializeHistograms(ModeType mode, HistoType& histo) {
unsigned int index = 0;
for (unsigned int i = 0; i < (histo.eRange.size() - 1); i++) {
// Labels for histo title
Char_t tmpstep[5];
Char_t tmpstep[10];
sprintf(tmpstep, "%1.1fGeV", histo.eRange[i]);
TString lowEnergyBorder = tmpstep;
sprintf(tmpstep, "%1.1fGeV", histo.eRange[i + 1]);
Expand All @@ -677,7 +687,7 @@ void initializeHistograms(ModeType mode, HistoType& histo) {

for (unsigned int j = 0; j < (histo.etaRange.size() - 1); j++) {
// Labels for histo name
Char_t tmpstep[5];
Char_t tmpstep[10];
sprintf(tmpstep, "%1.1fGeV", histo.eRange[i]);
TString lowEnergyBorder = tmpstep;
sprintf(tmpstep, "%1.1fGeV", histo.eRange[i + 1]);
Expand Down Expand Up @@ -1222,6 +1232,10 @@ void readTree(ModeType mode, TString variable, HistoType& histo, EopElecVariable
//
// -----------------------------------------------------------------------------
std::vector<Double_t> extractgausparams(TH1F* histo, TString option1, TString option2) {
if (histo->GetEntries() < 10) {
return {0., 0., 0., 0.};
}

// Fitting the histogram with a gaussian function
TF1* f1 = new TF1("f1", "gaus");
f1->SetRange(0., 2.);
Expand Down Expand Up @@ -1502,21 +1516,3 @@ Bool_t initializeTree(std::vector<TFile*>& files, std::vector<TTree*>& trees, Eo
}
return true;
}

// -----------------------------------------------------------------------------
//
// Main (only for stand alone compiled program)
//
// -----------------------------------------------------------------------------
int main() {
//momentumBiasValidation("eta","./","EopTree.root=Fit : ","root",1.,true);
momentumBiasValidation("eta",
"/opt/sbg/data/data1/cms/cgoetzma/Thesis/Eop_withElectrons/Outputs/GsfTracks/",
"QCD120to170.root=Chris1\\QCD15to30.root=Chris2\\QCD170to300.root=Chris3\\QCD300to470.root="
"Chris4\\QCD30to50.root=Chris5\\QCD470to600.root=Chris6\\QCD50to80.root=Chris7\\QCD600to800."
"root=Chris8\\QCD800to1000.root=Chris9\\QCD80to120.root=Chris10\\DyToEE.root=Chris11",
"root",
1.,
true);
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
'/store/data/Run2022A/JetHT/ALCARECO/TkAlMinBias-PromptReco-v1/000/352/900/00000/96120499-f83f-4b90-a828-58d4c2d26350.root'
)

filesDefaultData_JetHTRun2018DHcalIsoTrk = cms.untracked.vstring(
'/store/data/Run2018D/JetHT/ALCARECO/HcalCalIsoTrkFilter-12Nov2019_UL2018-v3/100000/075A1F1E-20B4-134D-9794-AD764DA6730D.root')

filesDefaultMC_NoPU = cms.untracked.vstring(
'/store/mc/RunIIWinter19PFCalibDR/Single_Pion_gun_E_2to200_13TeV_pythia8/GEN-SIM-RECO/2018ConditionsNoPU_105X_upgrade2018_realistic_v4-v1/270000/2BCBEBAB-BA94-B74F-9BFA-04F849A32558.root'
)
Expand Down
13 changes: 8 additions & 5 deletions Alignment/OfflineValidation/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@
<flags TEST_RUNNER_ARGS=" /bin/bash Alignment/OfflineValidation/test test_unitSubmitPVsplit.sh"/>
<use name="FWCore/Utilities"/>
</bin>
<bin file="testAlignmentOfflineValidation.cpp" name="EoPPion">
<flags TEST_RUNNER_ARGS=" /bin/bash Alignment/OfflineValidation/test test_unitEoPPion.sh"/>
<bin file="testAlignmentOfflineValidation.cpp" name="EoP">
<flags TEST_RUNNER_ARGS=" /bin/bash Alignment/OfflineValidation/test test_unitEoP.sh"/>
<use name="FWCore/Utilities"/>
</bin>
<bin file="testAlignmentOfflineValidation.cpp" name="EoPElectron">
<flags TEST_RUNNER_ARGS=" /bin/bash Alignment/OfflineValidation/test test_unitEoPElectron.sh"/>
<use name="FWCore/Utilities"/>
<bin file="testEoPPlotting.cpp" name="testEoPPlotting">
<flags PRE_TEST="EoP"/>
<use name="rootmath"/>
<use name="roothistmatrix"/>
<use name="rootgraphics"/>
<use name="Alignment/OfflineValidation"/>
</bin>
<bin file="testAlignmentOfflineValidation.cpp" name="Miscellanea">
<flags TEST_RUNNER_ARGS=" /bin/bash Alignment/OfflineValidation/test test_unitMiscellanea.sh"/>
Expand Down
2 changes: 1 addition & 1 deletion Alignment/OfflineValidation/test/eopElecTreeWriter_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

# initialize MessageLogger and output report
process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.cerr.FwkReport.reportEvery = 1000
process.MessageLogger.cerr.FwkReport.reportEvery = 100
process.MessageLogger.TrackRefitter=dict()
process.MessageLogger.EopElecTreeWriter=dict()

Expand Down
14 changes: 7 additions & 7 deletions Alignment/OfflineValidation/test/eopTreeWriter_cfg.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import FWCore.ParameterSet.Config as cms
import FWCore.ParameterSet.VarParsing as VarParsing
from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultData_JetHTRun2022A
from Alignment.OfflineValidation.TkAlAllInOneTool.defaultInputFiles_cff import filesDefaultData_JetHTRun2018DHcalIsoTrk

options = VarParsing.VarParsing("analysis")

options.register ('GlobalTag',
'auto:run3_data',
'auto:run2_data',
VarParsing.VarParsing.multiplicity.singleton, # singleton or list
VarParsing.VarParsing.varType.string, # string, int, or float
"Global Tag to be used")
Expand All @@ -24,13 +24,13 @@
####################################################################
process.load("FWCore.MessageService.MessageLogger_cfi")
#process.MessageLogger.cerr.threshold = 'ERROR'
process.MessageLogger.cerr.FwkReport.reportEvery = 10
process.MessageLogger.cerr.FwkReport.reportEvery = 100
process.MessageLogger.TrackRefitter=dict()

process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(False) )

# define input files
process.source = cms.Source("PoolSource", fileNames = filesDefaultData_JetHTRun2022A)
process.source = cms.Source("PoolSource", fileNames = filesDefaultData_JetHTRun2018DHcalIsoTrk)

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(options.maxEvents)
Expand Down Expand Up @@ -97,7 +97,7 @@
# configure alignment track selector
####################################################################
process.load("Alignment.CommonAlignmentProducer.AlignmentTrackSelector_cfi")
process.AlignmentTrackSelector.src = cms.InputTag('ALCARECOTkAlMinBias') # 'TkAlIsoProd' # trackCollection' # 'ALCARECOTkAlZMuMu' # 'ALCARECOTkAlMinBias' # adjust to input file
process.AlignmentTrackSelector.src = cms.InputTag('TkAlIsoProdFilter') # 'TkAlIsoProd' # trackCollection' # 'ALCARECOTkAlZMuMu' # 'ALCARECOTkAlMinBias' # adjust to input file
process.AlignmentTrackSelector.ptMin = 1.
process.AlignmentTrackSelector.etaMin = -5.
process.AlignmentTrackSelector.etaMax = 5.
Expand All @@ -110,8 +110,8 @@
# configure track refitter
####################################################################
process.load("RecoTracker.MeasurementDet.MeasurementTrackerEventProducer_cfi")
process.MeasurementTrackerEvent.pixelClusterProducer = "ALCARECOTkAlMinBias"
process.MeasurementTrackerEvent.stripClusterProducer = "ALCARECOTkAlMinBias"
process.MeasurementTrackerEvent.pixelClusterProducer = "TkAlIsoProdFilter"
process.MeasurementTrackerEvent.stripClusterProducer = "TkAlIsoProdFilter"
#process.MeasurementTrackerEvent.inactivePixelDetectorLabels = cms.VInputTag([''])
#process.MeasurementTrackerEvent.inactiveStripDetectorLabels = cms.VInputTag([''])

Expand Down
13 changes: 13 additions & 0 deletions Alignment/OfflineValidation/test/testEoPPlotting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <sstream>
#include <TSystem.h>
#include "Alignment/OfflineValidation/macros/momentumBiasValidation.C"
#include "Alignment/OfflineValidation/macros/momentumElectronBiasValidation.C"

int main(int argc, char** argv) {
//std::cout << "\n==== Executing pion analysis plotting \n" << std::endl;
//eop::momentumBiasValidation("eta", "./", "test_EopTree.root=TestPion");

std::cout << "\n==== Executing electron analysis plotting \n" << std::endl;
momentumElectronBiasValidation("eta", "./", "test_EopTreeElectron.root=TestEle", "png", true);
}
8 changes: 8 additions & 0 deletions Alignment/OfflineValidation/test/test_unitEoP.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash
function die { echo $1: status $2 ; exit $2; }

echo -e "\n\nTESTING eopTreeWriter (Pion Analysis) ..."
cmsRun ${LOCAL_TEST_DIR}/eopTreeWriter_cfg.py unitTest=True maxEvents=100 || die "Failure running eopTreeWriter" $?

echo -e "\n\nTESTING eopElecTreeWriter (Electron Analysis) ..."
cmsRun ${LOCAL_TEST_DIR}/eopElecTreeWriter_cfg.py maxEvents=100 || die "Failure running eopElecTreeWriter" $?
5 changes: 0 additions & 5 deletions Alignment/OfflineValidation/test/test_unitEoPElectron.sh

This file was deleted.

5 changes: 0 additions & 5 deletions Alignment/OfflineValidation/test/test_unitEoPPion.sh

This file was deleted.

0 comments on commit c0d007c

Please sign in to comment.