Skip to content

Commit

Permalink
Merge pull request cms-sw#11 from jozzez1/Run2HSCP_Jozze
Browse files Browse the repository at this point in the history
fixed the EDM creation
  • Loading branch information
quertenmont committed Jul 30, 2015
2 parents 830a98e + 8081e0f commit ed91d63
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 49 deletions.
171 changes: 171 additions & 0 deletions SUSYBSMAnalysis/HSCP/test/AnalysisCode/Analysis_Step3_MakePlots.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using namespace std;
void MassPrediction(string InputPattern, unsigned int CutIndex, string HistoSuffix="Mass", bool showMC=true, string Data="Data13TeV");
void PredictionAndControlPlot(string InputPattern, string Data, unsigned int CutIndex, unsigned int CutIndex_Flip);
void CutFlow(string InputPattern, unsigned int CutIndex=0);
void CutFlowPlot(string InputPattern, unsigned int CutIndex=4, double ylow=8e-6, double yhigh=8e+5, bool setLog=true);
void SelectionPlot (string InputPattern, unsigned int CutIndex, unsigned int CutIndexTight);

void Make2DPlot_Core(string ResultPattern, unsigned int CutIndex);
Expand Down Expand Up @@ -67,6 +68,8 @@ void Analysis_Step3_MakePlots()
MassPrediction(InputPattern, CutIndexTight, "Mass", true, "13TeV_Tight");
CutFlow(InputPattern, CutIndex);
CutFlow(InputPattern, CutIndexTight);
CutFlowPlot(InputPattern, CutIndex);
CutFlowPlot(InputPattern, CutIndexTight);
SelectionPlot(InputPattern, CutIndex, CutIndexTight);
PredictionAndControlPlot(InputPattern, "Data13TeV", CutIndex, CutIndex_Flip);

Expand All @@ -76,6 +79,8 @@ void Analysis_Step3_MakePlots()
MassPrediction(InputPattern, CutIndexTight, "Mass", true, "13TeV_Tight");
CutFlow(InputPattern, CutIndex);
CutFlow(InputPattern, CutIndexTight);
CutFlowPlot(InputPattern, CutIndex);
CutFlowPlot(InputPattern, CutIndexTight);
SelectionPlot(InputPattern, CutIndex, CutIndexTight);
PredictionAndControlPlot(InputPattern, "Data13TeV", CutIndex, CutIndex_Flip);

Expand Down Expand Up @@ -1366,6 +1371,172 @@ void CutFlow(string InputPattern, unsigned int CutIndex){
InputFile->Close();
}

void CutFlowPlot(string InputPattern, unsigned int CutIndex, double ylow, double yhigh, bool setLog){

TFile* InputFile = new TFile((InputPattern + "Histos.root").c_str());
if (!InputFile) std::cerr << "File could not be opened!" << std::endl;

typedef struct sampleDetails_t {
string SampleName;
string HistoName;
string LegEntry;
Color_t Color;

sampleDetails_t (string SampleName_, string HistoName_, string LegEntry_, Color_t Color_){
SampleName = SampleName_;
HistoName = HistoName_;
LegEntry = LegEntry_;
Color = Color_;
}
} sampleDetails_t;

vector < sampleDetails_t > SampleDetails;
SampleDetails.push_back(sampleDetails_t("Data13TeV", "Data13TeV", "13 TeV data", kBlack ));
SampleDetails.push_back(sampleDetails_t("MCTr_13TeV", "MCTr_13TeV", "MC (SM)", kBlue-3 ));
SampleDetails.push_back(sampleDetails_t("Gluino_13TeV_M1400_f10", "Gluino", "Gluino (M = 1000 GeV/#font[12]{c}^{2})", kRed+1 ));
SampleDetails.push_back(sampleDetails_t("Stop_13TeV_M1000", "Stop", "Stop (M = 1000 GeV/#font[12]{c}^{2})", kSpring-9 ));
SampleDetails.push_back(sampleDetails_t("GMStau_13TeV_M494", "Stau", "Stau (M = 494 GeV/#font[12]{c}^{2})", kOrange+7 ));
pair < TH1F*, TH1F* > * histos = new pair < TH1F*, TH1F* >[SampleDetails.size()];

const char * AxisLabels [19] = {"Total", "TNOH", "TNOM", "nDof", "Qual", "Chi2",
"Min Pt", "Min Ias", "Min TOF", "Dxy", "TIsol", "EIsol", "Pterr", "Dz", "PreSel",
"Pt", "Ias", "TOF", "Selection"};

// initialize histograms and fill them
for (unsigned int sample_i = 0; sample_i < SampleDetails.size(); sample_i++){
stPlots st;
stPlots_InitFromFile (InputFile, st, SampleDetails[sample_i].SampleName.c_str());

histos[sample_i].first = new TH1F ((SampleDetails[sample_i].HistoName+"_Abs").c_str(),
(SampleDetails[sample_i].HistoName+"_Abs").c_str(), 19, 0, 19);
histos[sample_i].second = new TH1F ((SampleDetails[sample_i].HistoName+"_Eff").c_str(),
(SampleDetails[sample_i].HistoName+"_Eff").c_str(), 19, 0, 19);

vector <double> Num, Eff;
Num.push_back (st.Total->GetBinContent (1)); Eff.push_back (1.0);
Num.push_back (st.TNOH ->GetBinContent (1)); Eff.push_back (1.0*Num[ 1]/ Num[ 0]);
Num.push_back (st.TNOM ->GetBinContent (1)); Eff.push_back (1.0*Num[ 2]/ Num[ 1]);
Num.push_back (st.nDof ->GetBinContent (1)); Eff.push_back (1.0*Num[ 3]/ Num[ 2]);
Num.push_back (st.Qual ->GetBinContent (1)); Eff.push_back (1.0*Num[ 4]/ Num[ 3]);
Num.push_back (st.Chi2 ->GetBinContent (1)); Eff.push_back (1.0*Num[ 5]/ Num[ 4]);
Num.push_back (st.MPt ->GetBinContent (1)); Eff.push_back (1.0*Num[ 6]/ Num[ 5]);
Num.push_back (st.MI ->GetBinContent (1)); Eff.push_back (1.0*Num[ 7]/ Num[ 6]);
Num.push_back (st.MTOF ->GetBinContent (1)); Eff.push_back (1.0*Num[ 8]/ Num[ 7]);
Num.push_back (st.Dxy ->GetBinContent (1)); Eff.push_back (1.0*Num[ 9]/ Num[ 8]);
Num.push_back (st.TIsol->GetBinContent (1)); Eff.push_back (1.0*Num[10]/ Num[ 9]);
Num.push_back (st.EIsol->GetBinContent (1)); Eff.push_back (1.0*Num[11]/ Num[10]);
Num.push_back (st.Pterr->GetBinContent (1)); Eff.push_back (1.0*Num[12]/ Num[11]);
Num.push_back (st.Dz ->GetBinContent (1)); Eff.push_back (1.0*Num[13]/ Num[12]);
Num.push_back (st.Basic->GetBinContent (1)); Eff.push_back (1.0*Num[14]/ Num[ 0]);
Num.push_back (st.Pt ->GetBinContent (CutIndex+1)); Eff.push_back (1.0*Num[15]/ Num[14]);
Num.push_back (st.I ->GetBinContent (CutIndex+1)); Eff.push_back (1.0*Num[16]/ Num[15]);
Num.push_back (st.TOF ->GetBinContent (CutIndex+1)); Eff.push_back (1.0*Num[17]/ Num[16]);
Num.push_back (st.TOF ->GetBinContent (CutIndex+1)); Eff.push_back (1.0*Num[17]/ Num[14]);

for (int cut_i = 1; cut_i <= 19; cut_i++){
if (std::isnan(Eff[cut_i-1])) Eff[cut_i-1] = 0.0;
histos[sample_i].first ->SetBinContent (cut_i, Num[cut_i-1]);
histos[sample_i].second->SetBinContent (cut_i, Eff[cut_i-1]);
}
histos[sample_i].first ->SetLineColor (SampleDetails[sample_i].Color);
histos[sample_i].first ->SetLineWidth (2.0);
histos[sample_i].first ->SetFillStyle (0); // <--makes the fill transparent

histos[sample_i].second->SetLineColor (SampleDetails[sample_i].Color);
histos[sample_i].second->SetLineWidth (2.0);
histos[sample_i].second->SetMarkerColor (SampleDetails[sample_i].Color);
histos[sample_i].second->SetMarkerStyle (20+sample_i);
}

// ----------------------------------
// Draw the Absolute Value histograms
// ----------------------------------
TCanvas* c1 = new TCanvas ("c1", "c1", 600, 600);
c1->SetLogy(setLog);
c1->SetGridx();
double Dx = 0.4, Dy = 6*0.03, x = 0.15, y = 0.15;
TLegend* leg = new TLegend(x+Dx, y+Dy, x, y);
leg->SetFillColor(0);
leg->SetFillStyle(0);
leg->SetBorderSize(0);

TH1F h ("Name", "Title", 19, 0, 19);
h.SetStats(0);
h.GetYaxis()->SetTitle ("number of tracks");
h.GetYaxis()->SetRangeUser(ylow,yhigh);
h.GetXaxis()->SetNdivisions(19);
h.GetXaxis()->SetLabelOffset (99); // disable label
h.Draw("hist");
for (unsigned int sample_i=0; sample_i < SampleDetails.size(); sample_i++){
leg->AddEntry (histos[sample_i].first, SampleDetails[sample_i].LegEntry.c_str(), "L");
histos[sample_i].first->Draw("same");
}

// now put the axis labels -- each cut at each place
TText T;
T.SetTextAngle(45);
T.SetTextAlign(33);
T.SetTextSize (0.03);
double Y = histos[0].first->GetYaxis()->GetBinLowEdge(1);
for (int cut_i = 0; cut_i < 19; cut_i++)
T.DrawText (histos[0].first->GetXaxis()->GetBinCenter(cut_i+1), Y, AxisLabels[cut_i]);

leg->Draw();
SQRTS=13; string LegendTitle = LegendFromType(InputPattern);
DrawPreliminary(LegendTitle, SQRTS, IntegratedLuminosityFromE(SQRTS));
char SaveName [128]; sprintf (SaveName, "CutFlowPlot_Abs_%u", CutIndex);
SaveCanvas(c1, InputPattern, SaveName);
delete c1;
delete leg;

// ----------------------------------
// Draw the Cut Efficiency histograms
// ----------------------------------
c1 = new TCanvas ("c1", "c1", 600, 600);
c1->SetLogy(false); // Efficiency should
c1->SetGridx();
c1->SetGridy();
leg = new TLegend(x+Dx, y+Dy, x, y);
leg->SetFillColor(0);
leg->SetFillStyle(0);
leg->SetBorderSize(0);

h.Reset();
h.SetStats(0);
h.GetYaxis()->SetTitle ("cut efficiency (%)");
h.GetYaxis()->SetRangeUser(0.0,1.0);
h.GetXaxis()->SetNdivisions(19);
h.GetYaxis()->SetNdivisions(5);
h.GetXaxis()->SetLabelOffset (99); // disable label
h.Draw("");
for (unsigned int sample_i=0; sample_i < SampleDetails.size(); sample_i++){
leg->AddEntry (histos[sample_i].second, SampleDetails[sample_i].LegEntry.c_str(), "LP");
histos[sample_i].second->Draw("same LP");
}

// now put the axis labels -- each cut at each place
T.SetTextAngle(45);
T.SetTextAlign(33);
T.SetTextSize (0.03);
Y = histos[0].second->GetYaxis()->GetBinLowEdge(1);
for (int cut_i = 0; cut_i < 19; cut_i++)
T.DrawText (histos[0].second->GetXaxis()->GetBinCenter(cut_i+1), Y, AxisLabels[cut_i]);

leg->Draw();
SQRTS=13; LegendTitle = LegendFromType(InputPattern);
DrawPreliminary(LegendTitle, SQRTS, IntegratedLuminosityFromE(SQRTS));
sprintf (SaveName, "CutFlowPlot_Eff_%u", CutIndex);
SaveCanvas(c1, InputPattern, SaveName);
delete c1;
delete leg;

for (unsigned int sample_i = 0; sample_i < SampleDetails.size(); sample_i++){
histos[sample_i].first ->~TH1F();
histos[sample_i].second->~TH1F();
}
delete [] histos;
}

// make all plots of the preselection and selection variables as well as some plots showing 2D planes
void SelectionPlot(string InputPattern, unsigned int CutIndex, unsigned int CutIndexTight){
string LegendTitle = LegendFromType(InputPattern);;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void DeDxStudy(string DIRNAME="COMPILE", string INPUT="dEdx.root", string OUTPUT
TH1::AddDirectory(kTRUE);

std::vector<string> FileName;
bool isData = true;
bool isData = INPUT.find("MC")!=string::npos ? false : true;
if(INPUT.find(".root")<std::string::npos){
char* pch=strtok(&INPUT[0],",");
while (pch!=NULL){
Expand Down
104 changes: 62 additions & 42 deletions SUSYBSMAnalysis/HSCP/test/UsefulScripts/DeDxStudy/MakePlot.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "TGraphAsymmErrors.h"
#include "TPaveText.h"
#include "TProfile.h"
#include "TProfile2D.h"
#include "TCutG.h"
#include "../../AnalysisCode/tdrstyle.C"
#include "../../AnalysisCode/Analysis_PlotFunction.h"
Expand All @@ -28,6 +29,7 @@ using namespace std;

void getScaleFactor(TFile* InputFile, string OutName, string ObjName1, string ObjName2);
void ExtractConstants(TH2D* input);
void DrawComparisons (TFile* InputFile1, TFile* InputFile2=NULL, string ObjName1="_Ias", string ObjName2="_IasInc");

//const double K = 2.4496; //Truncated40
//const double C = 2.2364; //Truncated40
Expand Down Expand Up @@ -77,7 +79,7 @@ TF1* GetMassLine(double M, bool left=false)
return MassLine;
}

void MakePlot()
void MakePlot(string INPUT, string INPUT2="EMPTY")
{
system("mkdir -p pictures");
system("mkdir -p fit");
Expand Down Expand Up @@ -135,24 +137,29 @@ void MakePlot()
TritonLineLeft->SetLineColor(1);
TritonLineLeft->SetLineWidth(2);

TFile* InputFile = new TFile("dEdxHistosNew.root");
TFile* InputFile = new TFile(INPUT.c_str());
std::vector<string> ObjName;
// ObjName.push_back("harm2");
ObjName.push_back("harm2_raw");
ObjName.push_back("harm2_PO");
ObjName.push_back("harm2_SO");
ObjName.push_back("harm2_SP");
ObjName.push_back("harm2_PO_raw");
ObjName.push_back("harm2_SO_raw");
ObjName.push_back("harm2_SP_raw");
ObjName.push_back("Ias_SO_inc");
ObjName.push_back("Ias_SO");
// ObjName.push_back("trunc40");
// ObjName.push_back("trunc40_raw");
// ObjName.push_back("Ias");

for(unsigned int i=0;i<ObjName.size();i++){
TH1D* HdedxMIP = (TH1D*) GetObjectFromPath(InputFile, (ObjName[i] + "_MIP" ).c_str() );
TH1D* HMass = (TH1D*) GetObjectFromPath(InputFile, (ObjName[i] + "_Mass" ).c_str() );
TH2D* HdedxVsP = (TH2D*) GetObjectFromPath(InputFile, (ObjName[i] + "_dedxVsP" ).c_str() );
TH2D* HdedxVsQP = (TH2D*) GetObjectFromPath(InputFile, (ObjName[i] + "_dedxVsQP" ).c_str() );
TProfile* HdedxVsPProfile = (TProfile*)GetObjectFromPath(InputFile, (ObjName[i] + "_Profile" ).c_str() );
TProfile* IasVsEta_ProfileS = (TProfile*)GetObjectFromPath(InputFile, (ObjName[i] + "_IasVsEta_ProfileS" ).c_str() );
TProfile* IasVsEta_ProfileU = (TProfile*)GetObjectFromPath(InputFile, (ObjName[i] + "_IasVsEta_ProfileU" ).c_str() );
TH2D* IasVsEta_Split = (TH2D*) GetObjectFromPath(InputFile, (ObjName[i] + "_IasVsEta_Split" ).c_str() );
TH2D* IasVsEta_Unsplit = (TH2D*) GetObjectFromPath(InputFile, (ObjName[i] + "_IasVsEta_Unsplit" ).c_str() );
TH1D* HdedxMIP = (TH1D*) GetObjectFromPath(InputFile, (ObjName[i] + "_MIP" ).c_str() );
TH1D* HMass = (TH1D*) GetObjectFromPath(InputFile, (ObjName[i] + "_Mass" ).c_str() );
TH2D* HdedxVsP = (TH2D*) GetObjectFromPath(InputFile, (ObjName[i] + "_dedxVsP" ).c_str() );
TH2D* HdedxVsQP = (TH2D*) GetObjectFromPath(InputFile, (ObjName[i] + "_dedxVsQP" ).c_str() );
TProfile* HdedxVsPProfile = (TProfile*) GetObjectFromPath(InputFile, (ObjName[i] + "_Profile" ).c_str() );
TH2D* HdedxVsEta = (TH2D*) GetObjectFromPath(InputFile, (ObjName[i] + "_Eta2D" ).c_str() );
TProfile* HdedxVsEtaProfile = (TProfile*) GetObjectFromPath(InputFile, (ObjName[i] + "_Eta" ).c_str() );
TProfile2D* HdedxVsP_NS = (TProfile2D*)GetObjectFromPath(InputFile, (ObjName[i] + "_dedxVsP_NS" ).c_str() );

ExtractConstants(HdedxVsP);

Expand Down Expand Up @@ -231,41 +238,30 @@ void MakePlot()

c1 = new TCanvas("c1", "c1", 600,600);
c1->SetLogz(true);
IasVsEta_Split->SetStats(kFALSE);
IasVsEta_Split->GetXaxis()->SetTitle("Eta");
IasVsEta_Split->GetYaxis()->SetTitle("I_{as}");
IasVsEta_Split->SetAxisRange(-2.1,2.1,"X");
IasVsEta_Split->Draw("COLZ");
SaveCanvas(c1, "pictures/", ObjName[i] + "_IasVsEta_Split");
HdedxVsEta->SetStats(kFALSE);
HdedxVsEta->GetXaxis()->SetTitle("Eta");
HdedxVsEta->GetYaxis()->SetTitle("I_{as}");
HdedxVsEta->SetAxisRange(-2.1,2.1,"X");
HdedxVsEta->Draw("COLZ");
SaveCanvas(c1, "pictures/", ObjName[i] + "_Eta2D");
delete c1;

c1 = new TCanvas("c1", "c1", 600,600);
c1->SetLogz(true);
IasVsEta_Unsplit->SetStats(kFALSE);
IasVsEta_Unsplit->GetXaxis()->SetTitle("Eta");
IasVsEta_Unsplit->GetYaxis()->SetTitle("I_{as}");
IasVsEta_Unsplit->SetAxisRange(-2.1,2.1,"X");
IasVsEta_Unsplit->Draw("COLZ");
SaveCanvas(c1, "pictures/", ObjName[i] + "_IasVsEta_Unsplit");
HdedxVsEtaProfile->SetStats(kFALSE);
HdedxVsEtaProfile->GetXaxis()->SetTitle("#eta");
HdedxVsEtaProfile->GetYaxis()->SetTitle("I_{as}");
HdedxVsEtaProfile->SetAxisRange(-2.1,2.1,"X");
HdedxVsEtaProfile->Draw("");
SaveCanvas(c1, "pictures/", ObjName[i] + "_HdedxVsEtaProfile");
delete c1;

c1 = new TCanvas("c1", "c1", 600,600);
TLegend* leg = new TLegend(0.50, 0.80, 0.80, 0.90);
leg->SetFillColor(0);
leg->SetFillStyle(0);
leg->SetBorderSize(0);
leg->AddEntry (IasVsEta_ProfileU, "Unsplit", "P");
leg->AddEntry (IasVsEta_ProfileS, "Split per module", "P");
IasVsEta_ProfileU->SetStats(kFALSE);
IasVsEta_ProfileS->SetMarkerStyle(23);
IasVsEta_ProfileS->SetMarkerColor(kBlue);
IasVsEta_ProfileU->GetXaxis()->SetTitle("pseudo-rapidity, #eta");
IasVsEta_ProfileU->GetYaxis()->SetTitle("I_{as}");
IasVsEta_ProfileU->Draw("");
IasVsEta_ProfileS->Draw("same");
leg->Draw();
SaveCanvas(c1, "pictures/", ObjName[i] + "_IasVsEta_Profile");
delete leg;
HdedxVsP_NS->SetStats(kFALSE);
HdedxVsP_NS->GetXaxis()->SetTitle("track momentum (GeV/c)");
HdedxVsP_NS->GetYaxis()->SetTitle(ObjName[i].find("Ias")!=std::string::npos?"I_{as}":"dE/dx (MeV/cm)");
HdedxVsP_NS->GetZaxis()->SetTitle("Number of saturated strips");
HdedxVsP_NS->Draw("COLZ");
SaveCanvas(c1, "pictures/", ObjName[i] + "_dedxVsP_NS");
delete c1;

c1 = new TCanvas("c1", "c1", 600,600);
Expand Down Expand Up @@ -580,3 +576,27 @@ void ExtractConstants(TH2D* input){
delete inputnew;
}
}

void DrawComparisons (TFile* InputFile1, TFile* InputFile2, string ObjName1, string ObjName2){
TProfile* HdedxVsEtaProfile1 = (TProfile*) GetObjectFromPath(InputFile1, (ObjName1 + "_Eta" ).c_str() );
TProfile* HdedxVsEtaProfile2 = (TProfile*) GetObjectFromPath(InputFile2?InputFile2:InputFile1, (ObjName2 + "_Eta" ).c_str() );

TCanvas* c1 = new TCanvas("c1", "c1", 600,600);
TLegend* leg = new TLegend(0.50, 0.80, 0.80, 0.90);
leg->SetFillColor(0);
leg->SetFillStyle(0);
leg->SetBorderSize(0);
leg->AddEntry (HdedxVsEtaProfile1, ObjName1.c_str(), "P");
leg->AddEntry (HdedxVsEtaProfile2, ObjName2.c_str(), "P");
HdedxVsEtaProfile1->SetStats(kFALSE);
HdedxVsEtaProfile2->SetMarkerStyle(23);
HdedxVsEtaProfile2->SetMarkerColor(kBlue);
HdedxVsEtaProfile1->GetXaxis()->SetTitle("#eta");
HdedxVsEtaProfile1->GetYaxis()->SetTitle(ObjName1.find("Ias")!=std::string::npos?"I_{as}":"dE/dx (MeV/cm)");
HdedxVsEtaProfile1->Draw("");
HdedxVsEtaProfile2->Draw("same");
leg->Draw();
SaveCanvas(c1, "pictures/", "Comparison_"+ObjName1+"_"+ObjName2+"_HdedxVsEtaProfile");
delete leg;
delete c1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ root -l -b << EOF
gSystem->Load("libDataFormatsCommon.so");
gSystem->Load("libDataFormatsTrackerRecHit2D.so");
gSystem->Load("libAnalysisDataFormatsSUSYBSMObjects.so");
.x MakePlot.C+
.x MakePlot.C+("$1");
EOF
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def getChunksFromList(MyList, n):
for DATASET in datasetList :
indir = os.getcwd() + "/Histos/"+DATASET[0]+'/'
os.system('hadd -f Histos_'+DATASET[0]+'.root ' + indir + '*.root')
os.system('./MakePlot.sh Histos_'+DATASET[0]+'.root > MakePlot_'+DATASET[0]+'.log 2>&1')
os.system('mv pictures pictures_'+DATASET[0]+' && MakePlot_'+DATASET[0]+'.log pictures_'+DATASET[0])

else:
print "Invalid argument"
Expand Down
Loading

0 comments on commit ed91d63

Please sign in to comment.