-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.cc
More file actions
145 lines (110 loc) · 4.47 KB
/
utility.cc
File metadata and controls
145 lines (110 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//Questo programma contiene funzioni utili all'esecuzione di analisi
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include "TH1D.h"
#include "TH1F.h"
#include "TH2D.h"
#include "TH2F.h"
#include "TCanvas.h"
//Questa funzione serve per creare spazio tra una stampa ed un'altra
void breakLine(){
std::cout<<""<<std::endl;
std::cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"<<std::endl;
std::cout<<""<<std::endl;
}
//Questa funzione stampa una stringa all'interno di un riquadro
void frame(std::string stringa){
std::cout<<""<<std::endl;
for (int i=0; i<(stringa.size()+6); ++i){
std::cout<<"+";
}
std::cout<<""<<std::endl;
std::cout<<"+ "<<stringa.c_str()<<" +"<<std::endl;
for(int i=0; i<(stringa.size()+6); ++i){
std::cout<<"+";
}
std::cout<<"\n"<<std::endl;
}
//Questa funzione implementa le caratteristiche di un istogramma TH1D
void TH1D_config(TH1D *histo, const char* title, const char* title_x, const char* title_y, int color){
std::string x="";
x+=title_x;
if(strcmp(x.c_str(),"Eta")==0)x="#eta";
if(strcmp(x.c_str(),"Phi")==0)x="#Phi";
if(strcmp(x.c_str(),"Pt")==0)x="Pt [GeV]";
histo->SetTitle(title);
histo->GetXaxis()->SetTitle(x.c_str());
histo->GetYaxis()->SetTitle(title_y);
histo->SetLineColor(color);
histo->SetMarkerColor(color);
}
//Questa funzione implementa le caratteristiche di un istogramma TH1F
void TH1F_config(TH1F *histo, const char* title, const char* title_x, const char* title_y, int color){
std::string x="";
if(strcmp(x.c_str(),"Eta")==0)x="#eta";
if(strcmp(x.c_str(),"Phi")==0)x="#Phi";
if(strcmp(x.c_str(),"Pt")==0)x="Pt [GeV]";
histo->SetTitle(title);
histo->GetXaxis()->SetTitle(x.c_str());
histo->GetYaxis()->SetTitle(title_y);
histo->SetLineColor(color);
histo->SetMarkerColor(color);
}
//Questa funzione implementa le caratteristiche di un istogramma TH2D
void TH2D_config(TH2D *histo, const char* title, const char* title_x, const char* title_y, int color){
histo->SetTitle(title);
histo->GetXaxis()->SetTitle(title_x);
histo->GetYaxis()->SetTitle(title_y);
histo->SetLineColor(color);
histo->SetMarkerColor(color);
}
//Questa funzione implementa le caratteristiche di un istogramma TH2F
void TH2F_config(TH2F *histo, const char* title, const char* title_x, const char* title_y, int color){
histo->SetTitle(title);
histo->GetXaxis()->SetTitle(title_x);
histo->GetYaxis()->SetTitle(title_y);
histo->SetLineColor(color);
histo->SetMarkerColor(color);
}
//Questa funzione analizza gli istogrammi all'interno di un file.root e li scrive su un file di output
void LS_config(std::string rootFile, std::string outfile){
std::cout<<"Removing old config file: "<<outfile.c_str()<<std::endl;
system(Form("rm -rf %s",outfile.c_str()));
std::cout<<"Root File analyzed: "<<rootFile.c_str()<<std::endl;
system(Form("./ls_script.sh %s | tee %s",rootFile.c_str(),outfile.c_str()));
}
//Questa funzione calcola il numero di eventi presenti in un istogramma - ATTENZIONE alla variabile che si usa per l'hist!!!
double yield(const char* path, const char* cut, double rescale = 1.0, const char* treename){
TFile* file = new TFile(path);
TTree* tree = (TTree*)file->Get(treename);
if (!tree) tree = (TTree*)file->Get("tree");
TH1D *hist= new TH1D ("hist","hist",1,0,2000);
tree->Project("hist","njets", cut);
//tree->Draw("njets>>hist(1, 0, 2000)", cut); //da non includere
//tree->Draw("signaljetpt>>hist(1, 0, 2000)", cut);
//TH1* hist = (TH1F*)gDirectory->Get("hist"); //da non includere
hist->Scale(rescale);
//double yld = hist->GetBinContent(1);
double yld = hist->Integral();
file->Close();
return yld;
}
//Questa funzione calcola il numero di eventi presenti in un istogramma - ATTENZIONE alla variabile che si usa per l'hist!!!
std::pair<double, double> yieldwitherror(const char* path, const char* cut, double rescale = 1.0, const char* treename = "tree/tree", const char* histname = "hist") {
TFile* file = new TFile(path);
TTree* tree = (TTree*)file->Get(treename);
if (!tree) tree = (TTree*)file->Get("tree");
TH1F* hist = new TH1F("hist", "hist", 1, 0, 2000);
tree->Project("hist","njets", cut);
hist->Scale(rescale);
double yld = hist->GetBinContent(1);
double ylderr = hist->GetBinError(1);
file->Close();
return std::pair<double, double>(yld, ylderr);
}
//Questa funzione fa il rapporto tra due numeri
double Ratio(double a, double b){
//std::cout<<" "<<a/b<<std::endl;
return a/b;
}