File indexing completed on 2024-04-06 11:59:44
0001
0002 int Color [] = {4,2,1,3,9,6,7,8,5};
0003 int Marker[] = {20,22,21,23,29,3,2};
0004 int Style [] = {1,2,5,7,9,10};
0005
0006
0007 TObject* GetObjectFromPath(TDirectory* File, string Path)
0008 {
0009 size_t pos = Path.find("/");
0010 if(pos < 256){
0011 string firstPart = Path.substr(0,pos);
0012 string endPart = Path.substr(pos+1,Path.length());
0013 TDirectory* TMP = (TDirectory*)File->Get(firstPart.c_str());
0014 if(TMP!=NULL)return GetObjectFromPath(TMP,endPart);
0015
0016 printf("BUG: %s\n",Path.c_str());
0017 return NULL;
0018 }else{
0019 return File->Get(Path.c_str());
0020 }
0021
0022 }
0023
0024 void SaveCanvas(TCanvas* c, string path, string name, bool OnlyPPNG=false){
0025 string filepath;
0026 filepath = path + "_" + name + ".png"; c->SaveAs(filepath.c_str()); if(OnlyPPNG)return;
0027 filepath = path + "_" + name + ".eps"; c->SaveAs(filepath.c_str());
0028 filepath = path + "_" + name + ".C" ; c->SaveAs(filepath.c_str());
0029 }
0030
0031 void DrawPreliminary(int Type, double X=0.28, double Y=0.98, double W=0.85, double H=0.95){
0032 TPaveText* T = new TPaveText(X,Y,W,H, "NDC");
0033 T->SetFillColor(0);
0034 T->SetTextAlign(11);
0035 if(Type==0)T->AddText("CMS Preliminary 2010 : #sqrt{s} = 7 TeV");
0036 if(Type==1)T->AddText("CMS Preliminary 2010 : MC with #sqrt{s} = 7 TeV");
0037 if(Type==2)T->AddText("CMS Preliminary 2010 : Data with #sqrt{s} = 7 TeV");
0038 T->Draw("same");
0039 }
0040
0041 void DrawLegend (TObject** Histos, std::vector<string> legend, string Title, string Style, double X=0.79, double Y=0.93, double W=0.20, double H=0.05)
0042 {
0043 int N = legend.size();
0044
0045 if(legend[0]!=""){
0046 TLegend* leg;
0047 leg = new TLegend(X,Y,X-W,Y - N*H);
0048 leg->SetFillColor(0);
0049 leg->SetBorderSize(0);
0050
0051 if(Title!="")leg->SetHeader(Title.c_str());
0052
0053 if(Style=="DataMC"){
0054 for(int i=0;i<N;i++){
0055 TH2D* temp = (TH2D*)Histos[i]->Clone();
0056 temp->SetMarkerSize(1.3);
0057 if(i==0){
0058 leg->AddEntry(temp, legend[i].c_str() ,"P");
0059 }else{
0060 leg->AddEntry(temp, legend[i].c_str() ,"L");
0061 }
0062 }
0063 }else{
0064 for(int i=0;i<N;i++){
0065 TH2D* temp = (TH2D*)Histos[i]->Clone();
0066 temp->SetMarkerSize(1.3);
0067 leg->AddEntry(temp, legend[i].c_str() ,Style.c_str());
0068 }
0069 }
0070 leg->Draw();
0071 }
0072 }
0073
0074
0075 void DrawStatBox(TObject** Histos, std::vector<string> legend, bool Mean, double X=0.15, double Y=0.93, double W=0.15, double H=0.03)
0076 {
0077 int N = legend.size();
0078 char buffer[255];
0079
0080 if(Mean)H*=3;
0081 for(int i=0;i<N;i++){
0082 TPaveText* stat = new TPaveText(X,Y-(i*H), X+W, Y-(i+1)*H, "NDC");
0083 TH1* Histo = (TH1*)Histos[i];
0084 sprintf(buffer,"Entries : %i\n",(int)Histo->GetEntries());
0085 stat->AddText(buffer);
0086
0087 if(Mean){
0088 sprintf(buffer,"Mean : %6.2f\n",Histo->GetMean());
0089 stat->AddText(buffer);
0090
0091 sprintf(buffer,"RMS : %6.2f\n",Histo->GetRMS());
0092 stat->AddText(buffer);
0093 }
0094
0095 stat->SetFillColor(0);
0096 stat->SetLineColor(Color[i]);
0097 stat->SetTextColor(Color[i]);
0098 stat->SetBorderSize(0);
0099 stat->SetMargin(0.05);
0100 stat->SetTextAlign(12);
0101 stat->Draw();
0102 }
0103 }
0104
0105
0106
0107 void DrawTH2D(TH2D** Histos, std::vector<string> legend, string Style, string Xlegend, string Ylegend, double xmin, double xmax, double ymin, double ymax)
0108 {
0109 int N = legend.size();
0110
0111 for(int i=0;i<N;i++){
0112 if(!Histos[i])continue;
0113 Histos[i]->SetTitle("");
0114 Histos[i]->SetStats(kFALSE);
0115 Histos[i]->GetXaxis()->SetTitle(Xlegend.c_str());
0116 Histos[i]->GetYaxis()->SetTitle(Ylegend.c_str());
0117 Histos[i]->GetYaxis()->SetTitleOffset(1.60);
0118 if(xmin!=xmax)Histos[i]->SetAxisRange(xmin,xmax,"X");
0119 if(ymin!=ymax)Histos[i]->SetAxisRange(ymin,ymax,"Y");
0120 Histos[i]->SetMarkerStyle(Marker[i]);
0121 Histos[i]->SetMarkerColor(Color[i]);
0122 Histos[i]->SetMarkerSize(0.3);
0123 }
0124
0125 char Buffer[256];
0126 Histos[0]->Draw(Style.c_str());
0127 for(int i=1;i<N;i++){
0128 sprintf(Buffer,"%s same",Style.c_str());
0129 Histos[i]->Draw(Buffer);
0130 }
0131 }
0132
0133
0134 void DrawSuperposedHistos(TH1** Histos, std::vector<string> legend, string Style, string Xlegend, string Ylegend, double xmin, double xmax, double ymin, double ymax, bool Normalize=false)
0135 {
0136 int N = legend.size();
0137
0138 double HistoMax = -1;
0139 int HistoHeighest = -1;
0140
0141 for(int i=0;i<N;i++){
0142 if(!Histos[i])continue;
0143 if(Normalize && Histos[i]->Integral()!=0)Histos[i]->Scale(1.0/Histos[i]->Integral());
0144 Histos[i]->SetTitle("");
0145 Histos[i]->SetStats(kFALSE);
0146 Histos[i]->GetXaxis()->SetTitle(Xlegend.c_str());
0147 Histos[i]->GetYaxis()->SetTitle(Ylegend.c_str());
0148 Histos[i]->GetYaxis()->SetTitleOffset(1.70);
0149 if(xmin!=xmax)Histos[i]->SetAxisRange(xmin,xmax,"X");
0150 if(ymin!=ymax)Histos[i]->SetAxisRange(ymin,ymax,"Y");
0151 Histos[i]->SetFillColor(0);
0152 Histos[i]->SetMarkerStyle(Marker[i]);
0153 Histos[i]->SetMarkerColor(Color[i]);
0154 Histos[i]->SetMarkerSize(1.0);
0155 Histos[i]->SetLineColor(Color[i]);
0156 Histos[i]->SetLineWidth(2);
0157 if(Style=="DataMC" && i==0){
0158 Histos[i]->SetFillColor(0);
0159 Histos[i]->SetMarkerStyle(20);
0160 Histos[i]->SetMarkerColor(1);
0161 Histos[i]->SetMarkerSize(1);
0162 Histos[i]->SetLineColor(1);
0163 Histos[i]->SetLineWidth(2);
0164 }
0165
0166 if(Histos[i]->GetMaximum() >= HistoMax){
0167 HistoMax = Histos[i]->GetMaximum();
0168 HistoHeighest = i;
0169 }
0170
0171 }
0172
0173 char Buffer[256];
0174 if(Style=="DataMC"){
0175 if(HistoHeighest==0){
0176 Histos[HistoHeighest]->Draw("E1");
0177 }else{
0178 Histos[HistoHeighest]->Draw("HIST");
0179 }
0180 for(int i=0;i<N;i++){
0181 if(i==0){
0182 Histos[i]->Draw("same E1");
0183 }else{
0184 Histos[i]->Draw("same");
0185 }
0186 }
0187 }else{
0188 Histos[HistoHeighest]->Draw(Style.c_str());
0189 for(int i=0;i<N;i++){
0190 if(Style!=""){
0191 sprintf(Buffer,"same %s",Style.c_str());
0192 }else{
0193 sprintf(Buffer,"same");
0194 }
0195 Histos[i]->Draw(Buffer);
0196 }
0197 }
0198 }
0199
0200
0201
0202