Skip to content

Commit

Permalink
reactivate export of source distributions from profiles - needs some …
Browse files Browse the repository at this point in the history
…improved cosmetics..., activate distribution export in JER-script
  • Loading branch information
kirschen committed May 24, 2012
1 parent 8d892f6 commit 0a80c13
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 39 deletions.
14 changes: 11 additions & 3 deletions ControlPlotsConfig.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// $Id: ControlPlotsConfig.cc,v 1.26 2012/04/27 12:34:27 kirschen Exp $
// $Id: ControlPlotsConfig.cc,v 1.27 2012/05/18 17:56:25 kirschen Exp $

#include "ControlPlotsConfig.h"

Expand Down Expand Up @@ -551,10 +551,15 @@ void ControlPlotsConfig::init() {

// Store which input tags are to be drawn
// in the distributions
std::vector<std::string> corrTypesStr2 = bag_of_string(config_->read<std::string>(name_+" distributions",";"));
std::vector<std::string> corrTypesStr2[3];
std::string corstrs2 = config_->read<std::string>(name_+" distributions",";");
corrTypesStr2[0] = bag_of_string(corstrs2);
corrTypesStr2[1] = bag_of_string(config_->read<std::string>(name_+" 1 distributions",corstrs2));
corrTypesStr2[2] = bag_of_string(config_->read<std::string>(name_+" 2 distributions",corstrs2));
// std::vector<std::string> corrTypesStr2 = bag_of_string(config_->read<std::string>(name_+" distributions",";"));
for(std::vector<int>::const_iterator samplesIt = sampleIds.begin() ;
samplesIt != sampleIds.end() ; samplesIt++) {
for(std::vector<std::string>::const_iterator corrTypesIt = corrTypesStr2.begin(); corrTypesIt != corrTypesStr2.end(); corrTypesIt++) {
for(std::vector<std::string>::const_iterator corrTypesIt = corrTypesStr2[*samplesIt].begin(); corrTypesIt != corrTypesStr2[*samplesIt].end(); corrTypesIt++) {
inputTagsDistributions_.push_back(std::make_pair(*samplesIt,correctionType(*corrTypesIt)));
}
}
Expand All @@ -572,6 +577,9 @@ void ControlPlotsConfig::init() {
// Store whether XY projections of all 2D histos are exported as .eps (or other plots format)
outXYProjections_= config_->read<bool>("export all XY projections",0);

// Store whether all Y projections of all 2D-histos are created, plotted with the Gauss Fits and written out.
outAllGaussFitsforProfiles_= config_->read<bool>("export all fitProfileHistos",0);

outFileType_ = config_->read<std::string>("plots format","eps");
// Define style for different correction types
// This should become configurable via config file
Expand Down
7 changes: 5 additions & 2 deletions ControlPlotsConfig.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// $Id: ControlPlotsConfig.h,v 1.12 2012/02/09 16:41:51 kirschen Exp $
// $Id: ControlPlotsConfig.h,v 1.13 2012/03/29 11:50:34 kirschen Exp $

#ifndef CONTROLPLOTS_CONFIG_H
#define CONTROLPLOTS_CONFIG_H
Expand Down Expand Up @@ -56,7 +56,7 @@ class ConfigFile;
//!
//! \author Matthias Schroeder
//! \date 2009/12/18
//! $Id: ControlPlotsConfig.h,v 1.12 2012/02/09 16:41:51 kirschen Exp $
//! $Id: ControlPlotsConfig.h,v 1.13 2012/03/29 11:50:34 kirschen Exp $
// ----------------------------------------------------------------
class ControlPlotsConfig {
public:
Expand Down Expand Up @@ -211,6 +211,8 @@ class ControlPlotsConfig {
bool outOnlyRoot() const { return outOnlyRoot_; }
//! Specifies whether X and Y projections of all 2D-histos are created and written out.
bool outXYProjections() const { return outXYProjections_; }
//! Specifies whether all Y projections of all 2D-histos are created, plotted with the Gauss Fits and written out.
bool outAllGaussFitsforProfiles() const { return outAllGaussFitsforProfiles_; }
//! Writes a \p obj to ROOT file
void toRootFile(TObject *obj) const;

Expand Down Expand Up @@ -249,6 +251,7 @@ class ControlPlotsConfig {
std::string outFileType_;
bool outOnlyRoot_;
bool outXYProjections_;
bool outAllGaussFitsforProfiles_;

std::map<InputTag,int> colors_;
std::map<InputTag,int> markerStyles_;
Expand Down
84 changes: 66 additions & 18 deletions ControlPlotsProfile.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// $Id: ControlPlotsProfile.cc,v 1.23 2012/01/24 16:26:37 kirschen Exp $
// $Id: ControlPlotsProfile.cc,v 1.24 2012/02/09 16:41:51 kirschen Exp $

#include "ControlPlotsProfile.h"

Expand Down Expand Up @@ -97,6 +97,7 @@ void ControlPlotsProfile::draw() {

Bool_t only_to_root = config_->outOnlyRoot();
Bool_t export_XY_projections = config_->outXYProjections();
Bool_t outAllGaussFitsforProfiles = config_->outAllGaussFitsforProfiles();
// std::cout << "only to root: " << only_to_root << std::endl;

TLegend *leg = bins_.front()->createLegend();
Expand Down Expand Up @@ -387,20 +388,65 @@ void ControlPlotsProfile::draw() {
delete leg;
}










leg = bins_.front()->createLegend();

std::cout << "outAllGaussFitsforProfiles: " << outAllGaussFitsforProfiles << std::endl;
// Draw distributions
for(std::vector<Bin*>::iterator binIt = bins_.begin();
binIt != bins_.end(); binIt++) {
for( ControlPlotsConfig::InputTagsIterator tagsIt = config_->distributionInputTagsBegin() ; tagsIt != config_->distributionInputTagsEnd(); ++tagsIt) {
if(outAllGaussFitsforProfiles){
for(std::vector<Bin*>::iterator binIt = bins_.begin();
binIt != bins_.end(); binIt++) {
for(int n = 0; n < (*binIt)->nDistributions(); n++) {
c1->Clear();
TH1D *h = (*binIt)->hYDistribution(n,*tagsIt);
h->Draw("HIST");
c1->SetLogx(0);
c1->cd();
bool firstHist = true;

for( ControlPlotsConfig::InputTagsIterator tagsIt = config_->distributionInputTagsBegin() ; tagsIt != config_->distributionInputTagsEnd(); ++tagsIt) {
TH1D *h = (*binIt)->hYDistribution(n,*tagsIt);
h->SetMarkerStyle(config_->markerStyle(*tagsIt));
h->SetMarkerColor(config_->color(*tagsIt));
h->SetLineColor(config_->color(*tagsIt));

h->GetXaxis()->SetRange(0,-1);
h->GetYaxis()->SetRangeUser(0,h->GetMaximum()*2);

// h->Dump();
if( firstHist ) {
// if(X_i==0){
if(h->GetMarkerStyle() < 0) {
h->SetLineStyle(std::abs(h->GetMarkerStyle()));
h->Draw("HIST");
std::cout << "should draw something" << std::endl;
} else {
h->Draw("PE1X0");
// if(TGraph* g = makeGraph(h)) g->Draw("LSAME");
}
firstHist = false;
} else {
if(h->GetMarkerStyle() < 0) {
h->SetLineStyle(std::abs(h->GetMarkerStyle()));
h->Draw("HISTSAME");
} else {
h->Draw("PE1X0same");
// if(TGraph* g = makeGraph(h)) g->Draw("LSAME");
}
}
config_->toRootFile(h);
fileName = config_->outDirName() + "/" + config_->outPlotSuffix() + "_";
fileName += (*binIt)->distributionFileName(n,*tagsIt) + "_Distribution." + config_->outFileType();
}
c1->SetLogx(0);
c1->RedrawAxis();
leg->Draw();
p2->DrawClone();
config_->toRootFile(h);
fileName = config_->outDirName() + "/" + config_->outPlotSuffix() + "_";
fileName += (*binIt)->distributionFileName(n,*tagsIt) + "_TEST_DISTRIBUTION_DELETE." + config_->outFileType();
if(!only_to_root)c1->SaveAs(fileName.c_str(),(config_->outFileType()).c_str());
}
}
Expand Down Expand Up @@ -713,12 +759,12 @@ int ControlPlotsProfile::Bin::fitProfiles() {
// Store distribution
char name[100];
sprintf(name,"%s_Distribution_%i",corrIt->second->GetName(),xBin);
TH1D *h = static_cast<TH1D*>(htemp->Clone(name));
h->SetTitle((config_->xBinTitle(xBin-1,min(),max())).c_str());
h->SetXTitle((config_->yTitle()).c_str());
h->SetYTitle("Number of jets");
h->SetLineColor(config_->color(corrIt->first));
hYDistributions_[corrIt->first].at(xBin-1) = h;
// std::cout<< name << std::endl;
htemp->SetName(name);
htemp->SetTitle((config_->xBinTitle(xBin-1,min(),max())).c_str());
htemp->SetXTitle((config_->yTitle()).c_str());
htemp->SetYTitle("Number of jets");
htemp->SetLineColor(config_->color(corrIt->first));
if(htemp->GetEntries()>100){
double mean = htemp->GetMean();
double meanerror = htemp->GetMeanError();
Expand All @@ -727,7 +773,7 @@ int ControlPlotsProfile::Bin::fitProfiles() {
if(htemp->GetSumOfWeights() <= 0) {
continue;
} else {
htemp->Fit("gaus","QNI","", mean - 3 * width,mean + 3 * width);
htemp->Fit("gaus","QI","", mean - 3 * width,mean + 3 * width); //removed N option to store GaussFit with histogram
TF1 *f = (TF1*)gROOT->GetFunction("gaus")->Clone();
mean = f->GetParameter(1);
meanerror = f->GetParError(1);
Expand All @@ -749,6 +795,7 @@ int ControlPlotsProfile::Bin::fitProfiles() {
}
hXProfile_[corrIt->first][ControlPlotsConfig::RatioOfGaussFitMeans]->SetBinContent(xBin,(1+mean)/(1-mean));
hXProfile_[corrIt->first][ControlPlotsConfig::RatioOfGaussFitMeans]->SetBinError(xBin,2 /((1-mean)*(1-mean))*meanerror);

}
hXProfile_[corrIt->first][ControlPlotsConfig::Chi2]->SetBinContent(xBin, f->GetChisquare() / f->GetNumberFreeParameters());
hXProfile_[corrIt->first][ControlPlotsConfig::Chi2]->SetBinError(xBin, 0.01);
Expand Down Expand Up @@ -797,6 +844,8 @@ int ControlPlotsProfile::Bin::fitProfiles() {
delete f;
}
} // do fits only if more than 100 entries
TH1D *h = static_cast<TH1D*>(htemp->Clone(name));
hYDistributions_[corrIt->first].at(xBin-1) = h;
} // End of loop over x bins
delete htemp;
hXProfile_[corrIt->first][ControlPlotsConfig::GaussFitMean]->SetEntries(hXProfile_[corrIt->first][ControlPlotsConfig::GaussFitMean]->GetEffectiveEntries());
Expand All @@ -818,7 +867,6 @@ int ControlPlotsProfile::Bin::fitProfiles() {
}



// ----------------------------------------------------------------
std::string ControlPlotsProfile::Bin::hist2DFileName(const ControlPlotsConfig::InputTag& tag) const {
std::string name = config_->name();
Expand Down
37 changes: 21 additions & 16 deletions scripts/runDiJets_JER.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def writeCfg(filename):
#plots format = pdf
plots only to root-file = false
export all XY projections = true
export all fitProfileHistos = true
#plots only to root-file = true
#export all XY projections = false
Expand All @@ -215,7 +216,7 @@ def writeCfg(filename):
abs_binning_values=BinningValues(BINNING,True)


plot_list=['AbsAsymmetryVsPt','NPVVsPt']
plot_list=['AbsAsymmetryVsPt']#,'NPVVsPt']
cut_list=['40','30','20','10']
cut_no_list=['.40','.30','.20','.10']
# cut_list=['40','35','30','25','20','15','10','05']
Expand Down Expand Up @@ -262,23 +263,25 @@ def writeCfg(filename):
fcfg.write(plot_list[0] + cut + " bin edges = " + abs_binning_values + "\n")
fcfg.write(plot_list[0] + cut + " cut variable = ThirdJetFractionPlain\n")
fcfg.write(plot_list[0] + cut + " cut edges = 0.0 " + cut_no_list[index_cut]+ "\n")
fcfg.write(plot_list[0] + cut + " distributions = L2L3; L2L3Res\n")
fcfg.write(plot_list[0] + cut + " 1 distributions = L2L3\n")
fcfg.write(plot_list[0] + cut + " correction types = L2L3; L2L3Res\n")
fcfg.write(plot_list[0] + cut + " 1 correction types = L2L3\n")
fcfg.write(plot_list[0] + cut + " profile types = Mean; GaussFitMean; RatioOfMeans; RatioOfGaussFitMeans; StandardDeviation; GaussFitWidth\n")
fcfg.write(plot_list[0] + cut + " input samples = 0:data;1:MC\n\n")

fcfg.write(plot_list[1] + cut + " x variable = MeanPt; log\n")
fcfg.write(plot_list[1] + cut + " x edges = 100 20 2000\n")
fcfg.write(plot_list[1] + cut + " y variable = VtxN\n")
fcfg.write(plot_list[1] + cut + " y edges = 44 0.0 44.0 0.0 44.0 \n")
fcfg.write(plot_list[1] + cut + " bin variable = AbsEta\n")
fcfg.write(plot_list[1] + cut + " bin edges = " + abs_binning_values + "\n")
fcfg.write(plot_list[1] + cut + " cut variable = ThirdJetFractionPlain\n")
fcfg.write(plot_list[1] + cut + " cut edges = 0.0 " + cut_no_list[index_cut]+ "\n")
fcfg.write(plot_list[1] + cut + " correction types = L2L3; L2L3Res\n")
fcfg.write(plot_list[1] + cut + " 1 correction types = L2L3\n")
fcfg.write(plot_list[1] + cut + " profile types = Mean\n")
fcfg.write(plot_list[1] + cut + " input samples = 0:data;1:MC\n\n")
# fcfg.write(plot_list[1] + cut + " x variable = MeanPt; log\n")
# fcfg.write(plot_list[1] + cut + " x edges = 100 20 2000\n")
# fcfg.write(plot_list[1] + cut + " y variable = VtxN\n")
# fcfg.write(plot_list[1] + cut + " y edges = 44 0.0 44.0 0.0 44.0 \n")
# fcfg.write(plot_list[1] + cut + " bin variable = AbsEta\n")
# fcfg.write(plot_list[1] + cut + " bin edges = " + abs_binning_values + "\n")
# fcfg.write(plot_list[1] + cut + " cut variable = ThirdJetFractionPlain\n")
# fcfg.write(plot_list[1] + cut + " cut edges = 0.0 " + cut_no_list[index_cut]+ "\n")
# fcfg.write(plot_list[1] + cut + " correction types = L2L3; L2L3Res\n")
# fcfg.write(plot_list[1] + cut + " 1 correction types = L2L3\n")
# fcfg.write(plot_list[1] + cut + " profile types = Mean\n")
# fcfg.write(plot_list[1] + cut + " input samples = 0:data;1:MC\n\n")

fcfg.write("\n\n")

Expand Down Expand Up @@ -306,6 +309,8 @@ def writeCfg(filename):
fcfg.write("JetEta1VsJetEta2 bin edges = 20 30 50 80 120 200 360 500 900 7000 \n")
fcfg.write("JetEta1VsJetEta2 cut variable = ThirdJetFractionPlain\n")
fcfg.write("JetEta1VsJetEta2 cut edges = 0.0 0.20\n")
# fcfg.write("JetEta1VsJetEta2 distributions = L2L3; L2L3Res\n")
# fcfg.write("JetEta1VsJetEta2 1 distributions = L2L3\n")
fcfg.write("JetEta1VsJetEta2 correction types = L2L3; L2L3Res\n")
fcfg.write("JetEta1VsJetEta2 1 correction types = L2L3\n")
fcfg.write("JetEta1VsJetEta2 profile types = Mean\n")
Expand All @@ -319,7 +324,7 @@ def writeCfg(filename):
fcfg.write("AsymmetryVsNPV20_pt_bin_all_eta y edges = 31 -0.70 0.70 -0.5 0.5 -0.5 0.5 0.7 1.3 0.7 1.3 -0.70 0.70 0.7 1.3\n")
fcfg.write("AsymmetryVsNPV20_pt_bin_all_eta bin variable = MeanPt\n")
fcfg.write("#AsymmetryVsNPV20_pt_bin_all_eta bin edges = 20 30 50 80 120 200 360 500 900 7000\n")
fcfg.write("AsymmetryVsNPV20_pt_bin_all_eta bin edges = 45 90 150 210 270 340 420 900 7000\n")
fcfg.write("AsymmetryVsNPV20_pt_bin_all_eta bin edges = 72 112 186 255 318 388 472 900 7000\n") #slightly adapted to new trigger thresholds by Denis, should be automated in the future
fcfg.write("AsymmetryVsNPV20_pt_bin_all_eta cut variable = ThirdJetFractionPlain\n")
fcfg.write("AsymmetryVsNPV20_pt_bin_all_eta cut edges = 0.0 0.2\n")
fcfg.write("AsymmetryVsNPV20_pt_bin_all_eta correction types = L2L3; L2L3Res\n")
Expand Down Expand Up @@ -446,7 +451,7 @@ def writeCfg(filename):
##################################
## is a suffix to the output folder name (can be used for extra information)
##################################
DIR_JETALGO="DefaultTestTEst"
DIR_JETALGO="DefaultTestTEstTest"
##################################
## chooses the jet type (for PF, akFastPF-files are read in, see below - does not make a difference when JEC is overridden)
##################################
Expand Down Expand Up @@ -603,7 +608,7 @@ def writeCfg(filename):
#nevents = -1
#nthreads = 1
#niothreads = 1
nevents = 1000
nevents = 1000000
MAIN_dirname = "/afs/naf.desy.de/user/k/kirschen/scratch/Kalibri/"+DATAYEAR+DATATYPE+"_CORR" + CORRECTION +"_MC_"+MC+MC_type+"_kostas_"+ DIR_JETALGO
dirname = MAIN_dirname + "/dijetsFall10_TuneZ2_AK5"+PF_CALO_JPT+"_weighted_residuals_"+BINNING
useconstraint = False
Expand Down

0 comments on commit 0a80c13

Please sign in to comment.