Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:14:58

0001 #include "TF1.h"
0002 #include "TH1F.h"
0003 #include "TCanvas.h"
0004 #include "TFile.h"
0005 #include "TTree.h"
0006 #include "TGraphErrors.h"
0007 #include "TGraph.h"
0008 #include "TROOT.h"
0009 #include "Riostream.h"
0010 #include "TBox.h"
0011 #include "TLine.h"
0012 #include "TLatex.h"
0013 #include "TText.h"
0014 #include "TStyle.h"
0015 
0016 
0017 void LAFits(double RANGE,int PHICUT, int SHOW, int SAVE)
0018 {
0019 gROOT->Reset();
0020 gStyle->SetHistLineWidth(2.5);
0021 gStyle->SetLineWidth(2.5);
0022 gStyle->SetLineStyleString(2,"[12 12]"); 
0023 gROOT->SetStyle("Plain");
0024 
0025 TFile* f = new TFile("LA_TEST.root");
0026 
0027 TTree* tree = (TTree*)f->Get("LorentzAngle_Plots/Rootple/ModuleTree");
0028 
0029 TCanvas *tib_graph = new TCanvas("tib_graph","TIB Graph",1);
0030 TCanvas *tob_graph = new TCanvas("tob_graph","TOB Graph",1);
0031 TCanvas *tib_graph_rms = new TCanvas("tib_graph_rms","TIB Graph (RMS)",1);
0032 TCanvas *tob_graph_rms = new TCanvas("tob_graph_rms","TOB Graph (RMS)",1);
0033 TCanvas *Ratios = new TCanvas("Ratios","Ratios",1);
0034 
0035 int showplots = SHOW;
0036 
0037 int save_plots=SAVE;
0038 int phicut = PHICUT;
0039 double range = RANGE;
0040 
0041 double histo_range = 0.2;
0042 
0043 float TIB_expected = 0.024;
0044 float TOB_expected = 0.027;
0045 
0046 TH1F *plot_TIB1= new TH1F("plot_TIB1","TIB1",600,-histo_range,histo_range);
0047 TH1F *plot_TIB2= new TH1F("plot_TIB2","TIB2",600,-histo_range,histo_range);
0048 TH1F *plot_TIB3= new TH1F("plot_TIB3","TIB3",600,-histo_range,histo_range);
0049 TH1F *plot_TIB4= new TH1F("plot_TIB4","TIB4",600,-histo_range,histo_range);
0050 
0051 TH1F *plot_TOB1= new TH1F("plot_TOB1","TOB1",600,-histo_range,histo_range);
0052 TH1F *plot_TOB2= new TH1F("plot_TOB2","TOB2",600,-histo_range,histo_range);
0053 TH1F *plot_TOB3= new TH1F("plot_TOB3","TOB3",600,-histo_range,histo_range);
0054 TH1F *plot_TOB4= new TH1F("plot_TOB4","TOB4",600,-histo_range,histo_range);
0055 TH1F *plot_TOB5= new TH1F("plot_TOB5","TOB5",600,-histo_range,histo_range);
0056 TH1F *plot_TOB6= new TH1F("plot_TOB6","TOB6",600,-histo_range,histo_range);
0057 
0058 if(phicut==0){
0059 tree->Draw("muH >> plot_TIB1","TIB==1 && Layer==1 && goodFit==1");
0060 tree->Draw("muH >> plot_TIB2","TIB==1 && Layer==2 && goodFit==1");
0061 tree->Draw("muH >> plot_TIB3","TIB==1 && Layer==3 && goodFit==1");
0062 tree->Draw("muH >> plot_TIB4","TIB==1 && Layer==4 && goodFit==1");
0063 
0064 tree->Draw("muH >> plot_TOB1","TOB==1 && Layer==1 && goodFit==1");
0065 tree->Draw("muH >> plot_TOB2","TOB==1 && Layer==2 && goodFit==1");
0066 tree->Draw("muH >> plot_TOB3","TOB==1 && Layer==3 && goodFit==1");
0067 tree->Draw("muH >> plot_TOB4","TOB==1 && Layer==4 && goodFit==1");
0068 tree->Draw("muH >> plot_TOB5","TOB==1 && Layer==5 && goodFit==1");
0069 tree->Draw("muH >> plot_TOB6","TOB==1 && Layer==6 && goodFit==1");
0070 }
0071 
0072 if(phicut==1){
0073 tree->Draw("muH >> plot_TIB1","TIB==1 && Layer==1 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0074 tree->Draw("muH >> plot_TIB2","TIB==1 && Layer==2 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0075 tree->Draw("muH >> plot_TIB3","TIB==1 && Layer==3 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0076 tree->Draw("muH >> plot_TIB4","TIB==1 && Layer==4 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0077 
0078 tree->Draw("muH >> plot_TOB1","TOB==1 && Layer==1 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0079 tree->Draw("muH >> plot_TOB2","TOB==1 && Layer==2 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0080 tree->Draw("muH >> plot_TOB3","TOB==1 && Layer==3 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0081 tree->Draw("muH >> plot_TOB4","TOB==1 && Layer==4 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0082 tree->Draw("muH >> plot_TOB5","TOB==1 && Layer==5 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0083 tree->Draw("muH >> plot_TOB6","TOB==1 && Layer==6 && goodFit==1 && ((-2.2<gphi && gphi<-1) || (1<gphi && gphi<2.2))");
0084 } 
0085 
0086 ofstream out;
0087 out.open("Layer_MuH.txt");
0088 out<<endl;
0089   
0090 plot_TIB1->Fit("gaus","","",-range,range);
0091 TF1 *FitFunc1 = plot_TIB1->GetFunction("gaus");
0092 double TIB1_muh = (FitFunc1->GetParameter(1));
0093 double TIB1_muh_err = (FitFunc1->GetParError(1));
0094 double TIB1_muh_rms = (FitFunc1->GetParameter(2));
0095 out<<"TIB1 = "<<TIB1_muh<<" +- "<<TIB1_muh_err<<" Sigma = "<<TIB1_muh_rms<<endl;
0096 if(showplots==1){
0097 TCanvas *a1=new TCanvas;
0098 a1->cd();
0099 gStyle->SetOptStat(11);
0100 gStyle->SetOptFit(111);
0101 plot_TIB1->Draw();
0102 }
0103 
0104 plot_TIB2->Fit("gaus","","",-range,range);
0105 TF1 *FitFunc2 = plot_TIB2->GetFunction("gaus");
0106 double TIB2_muh = (FitFunc2->GetParameter(1));
0107 double TIB2_muh_err = (FitFunc2->GetParError(1));
0108 double TIB2_muh_rms = (FitFunc2->GetParameter(2));
0109 out<<"TIB2 = "<<TIB2_muh<<" +- "<<TIB2_muh_err<<" Sigma = "<<TIB2_muh_rms<<endl;
0110 if(showplots==1){
0111 TCanvas *a2 = new TCanvas;
0112 a2->cd();
0113 gStyle->SetOptStat(11);
0114 gStyle->SetOptFit(111);
0115 plot_TIB2->Draw();
0116 if(save_plots==1)a2->SaveAs("TIB2.eps");
0117 }
0118 
0119 plot_TIB3->Fit("gaus","","",-range,range);
0120 TF1 *FitFunc3 = plot_TIB3->GetFunction("gaus");
0121 double TIB3_muh = (FitFunc3->GetParameter(1));
0122 double TIB3_muh_err = (FitFunc3->GetParError(1));
0123 double TIB3_muh_rms = (FitFunc3->GetParameter(2));
0124 out<<"TIB3 = "<<TIB3_muh<<" +- "<<TIB3_muh_err<<" Sigma = "<<TIB3_muh_rms<<endl;
0125 if(showplots==1){
0126 TCanvas *a3 = new TCanvas;
0127 a3->cd();
0128 gStyle->SetOptStat(11);
0129 gStyle->SetOptFit(111);
0130 plot_TIB3->Draw();
0131 if(save_plots==1)a3->SaveAs("TIB3.eps");
0132 }
0133 
0134 plot_TIB4->Fit("gaus","","",-range,range);
0135 TF1 *FitFunc4 = plot_TIB4->GetFunction("gaus");
0136 double TIB4_muh = (FitFunc4->GetParameter(1));
0137 double TIB4_muh_err = (FitFunc4->GetParError(1));
0138 double TIB4_muh_rms = (FitFunc4->GetParameter(2));
0139 out<<"TIB4 = "<<TIB4_muh<<" +- "<<TIB4_muh_err<<" Sigma = "<<TIB4_muh_rms<<endl;
0140 if(showplots==1){
0141 TCanvas *a4 = new TCanvas;
0142 a4->cd();
0143 gStyle->SetOptStat(11);
0144 gStyle->SetOptFit(111);
0145 plot_TIB4->Draw();
0146 if(save_plots==1)a4->SaveAs("TIB4.eps");
0147 }
0148 
0149 plot_TOB1->Fit("gaus","","",-range,range);
0150 TF1 *FitFunc5 = plot_TOB1->GetFunction("gaus");
0151 double TOB1_muh = (FitFunc5->GetParameter(1));
0152 double TOB1_muh_err = (FitFunc5->GetParError(1));
0153 double TOB1_muh_rms = (FitFunc5->GetParameter(2));
0154 out<<"TOB1 = "<<TOB1_muh<<" +- "<<TOB1_muh_err<<" Sigma = "<<TOB1_muh_rms<<endl;
0155 if(showplots==1){
0156 TCanvas *c1=new TCanvas;
0157 c1->cd();
0158 gStyle->SetOptStat(11);
0159 gStyle->SetOptFit(111);
0160 plot_TOB1->Draw();
0161 if(save_plots==1)c1->SaveAs("TOB1.eps");
0162 }
0163 
0164 plot_TOB2->Fit("gaus","","",-range,range);
0165 TF1 *FitFunc6 = plot_TOB2->GetFunction("gaus");
0166 double TOB2_muh = (FitFunc6->GetParameter(1));
0167 double TOB2_muh_err = (FitFunc6->GetParError(1));
0168 double TOB2_muh_rms = (FitFunc6->GetParameter(2));
0169 out<<"TOB2 = "<<TOB2_muh<<" +- "<<TOB2_muh_err<<" Sigma = "<<TOB2_muh_rms<<endl;
0170 if(showplots==1){
0171 TCanvas *c2=new TCanvas;
0172 c2->cd();
0173 gStyle->SetOptStat(11);
0174 gStyle->SetOptFit(111);
0175 plot_TOB2->Draw();
0176 if(save_plots==1)c2->SaveAs("TOB2.eps");
0177 }
0178 
0179 plot_TOB3->Fit("gaus","","",-range,range);
0180 TF1 *FitFunc7 = plot_TOB3->GetFunction("gaus");
0181 double TOB3_muh = (FitFunc7->GetParameter(1));
0182 double TOB3_muh_err = (FitFunc7->GetParError(1));
0183 double TOB3_muh_rms = (FitFunc7->GetParameter(2));
0184 out<<"TOB3 = "<<TOB3_muh<<" +- "<<TOB3_muh_err<<" Sigma = "<<TOB3_muh_rms<<endl;
0185 if(showplots==1){
0186 TCanvas *c3=new TCanvas;
0187 c3->cd();
0188 gStyle->SetOptStat(11);
0189 gStyle->SetOptFit(111);
0190 plot_TOB3->Draw();
0191 if(save_plots==1)c3->SaveAs("TOB3.eps");
0192 }
0193 
0194 plot_TOB4->Fit("gaus","","",-range,range);
0195 TF1 *FitFunc8 = plot_TOB4->GetFunction("gaus");
0196 double TOB4_muh = (FitFunc8->GetParameter(1));
0197 double TOB4_muh_err = (FitFunc8->GetParError(1));
0198 double TOB4_muh_rms = (FitFunc8->GetParameter(2));
0199 out<<"TOB4 = "<<TOB4_muh<<" +- "<<TOB4_muh_err<<" Sigma = "<<TOB4_muh_rms<<endl;
0200 if(showplots==1){
0201 TCanvas *c4=new TCanvas;
0202 c4->cd();
0203 gStyle->SetOptStat(11);
0204 gStyle->SetOptFit(111);
0205 plot_TOB4->Draw();
0206 if(save_plots==1)c4->SaveAs("TOB4.eps");
0207 }
0208 
0209 plot_TOB5->Fit("gaus","","",-range,range);
0210 TF1 *FitFunc9 = plot_TOB5->GetFunction("gaus");
0211 double TOB5_muh = (FitFunc9->GetParameter(1));
0212 double TOB5_muh_err = (FitFunc9->GetParError(1));
0213 double TOB5_muh_rms = (FitFunc9->GetParameter(2));
0214 out<<"TOB5 = "<<TOB5_muh<<" +- "<<TOB5_muh_err<<" Sigma = "<<TOB5_muh_rms<<endl;
0215 if(showplots==1){
0216 TCanvas *c5=new TCanvas;
0217 c5->cd();
0218 gStyle->SetOptStat(11);
0219 gStyle->SetOptFit(111);
0220 plot_TOB5->Draw();
0221 if(save_plots==1)c5->SaveAs("TOB5.eps");
0222 }
0223 
0224 plot_TOB6->Fit("gaus","","",-range,range);
0225 TF1 *FitFunc10 = plot_TOB6->GetFunction("gaus");
0226 double TOB6_muh = (FitFunc10->GetParameter(1));
0227 double TOB6_muh_err = (FitFunc10->GetParError(1));
0228 double TOB6_muh_rms = (FitFunc10->GetParameter(2));
0229 out<<"TOB6 = "<<TOB6_muh<<" +- "<<TOB6_muh_err<<" Sigma = "<<TOB6_muh_rms<<endl;
0230 if(showplots==1){
0231 TCanvas *c6=new TCanvas;
0232 c6->cd();
0233 gStyle->SetOptStat(11);
0234 gStyle->SetOptFit(111);
0235 plot_TOB6->Draw();
0236 if(save_plots==1)c6->SaveAs("TOB6.eps");
0237 }
0238 
0239 if(showplots==1){
0240 TCanvas *a5=new TCanvas;
0241 a5->cd();
0242 gStyle->SetOptStat(11);
0243 gStyle->SetOptFit(111);
0244 plot_TIB1->Draw();
0245 if(save_plots==1)a5->SaveAs("TIB1.eps");
0246 }
0247 
0248 int n_tib = 4;
0249 int n_tob = 6;
0250 
0251 //TIB graph
0252 
0253 float TIBx[4]={1,2,3,4};
0254 float TIBex[4]={0,0,0,0};
0255 float TIBy[4]={TIB1_muh, TIB2_muh, TIB3_muh, TIB4_muh};
0256 float TIBey[4]={TIB1_muh_err, TIB2_muh_err, TIB3_muh_err, TIB4_muh_err};
0257 TGraphErrors *TIB_graph = new TGraphErrors(n_tib,TIBx,TIBy,TIBex,TIBey);
0258 TIB_graph->SetTitle("TIB MuH Values per Layer");
0259 TIB_graph->SetMarkerStyle(20);
0260 TIB_graph->GetXaxis()->SetTitle("Layer number");
0261 TIB_graph->GetXaxis()->SetNdivisions(4);
0262 TIB_graph->GetYaxis()->SetTitle("#mu_{H} (m^{2}/Vs)");
0263 TIB_graph->GetYaxis()->CenterTitle();
0264 TIB_graph->GetYaxis()->SetTitleOffset(1.25);
0265 TIB_graph->GetYaxis()->SetRangeUser(0.015,0.021);
0266 TF1 *TIBFit = new TF1("TIBFit","[0]",0,5);
0267 TIB_graph->Fit("TIBFit","E","", 1, 4);
0268 tib_graph->cd();
0269 gStyle->SetOptStat(11);
0270 gStyle->SetOptFit(111);
0271 TIB_graph->Draw("AP");
0272 
0273 if(save_plots==1)tib_graph->SaveAs("TIB_Graph.eps");
0274 
0275 //TOB graph
0276 
0277 float TOBx[6]={1,2,3,4,5,6};
0278 float TOBex[6]={0,0,0,0,0,0};
0279 float TOBy[6]={TOB1_muh, TOB2_muh, TOB3_muh, TOB4_muh, TOB5_muh, TOB6_muh};
0280 float TOBey[6]={TOB1_muh_err, TOB2_muh_err, TOB3_muh_err, TOB4_muh_err, TOB5_muh_err,TOB6_muh_err};
0281 TGraphErrors *TOB_graph = new TGraphErrors(n_tob,TOBx,TOBy,TOBex,TOBey);
0282 TOB_graph->SetTitle("TOB MuH Values per Layer");
0283 TOB_graph->SetMarkerStyle(20);
0284 TOB_graph->GetXaxis()->SetTitle("Layer number");
0285 TOB_graph->GetXaxis()->SetNdivisions(6);
0286 TOB_graph->GetYaxis()->SetTitle("#mu_{H} (m^{2}/Vs)");
0287 TOB_graph->GetYaxis()->CenterTitle();
0288 TOB_graph->GetYaxis()->SetTitleOffset(1.25);
0289 TOB_graph->GetYaxis()->SetRangeUser(0.02,0.025);
0290 TF1 *TOBFit = new TF1("TOBFit","[0]",0,7);
0291 TOB_graph->Fit("TOBFit","E","", 1, 6);
0292 tob_graph->cd();
0293 gStyle->SetOptStat(11);
0294 gStyle->SetOptFit(111);
0295 TOB_graph->Draw("AP");
0296 if(save_plots==1)tob_graph->SaveAs("TOB_Graph.eps");
0297 
0298 //TIB graph
0299 
0300 float rmsTIBey[4]={TIB1_muh_rms, TIB2_muh_rms, TIB3_muh_rms, TIB4_muh_rms};
0301 TGraphErrors *TIB_graph_rms = new TGraphErrors(n_tib,TIBx,TIBy,TIBex,rmsTIBey);
0302 TIB_graph_rms->SetMarkerStyle(20);
0303 TIB_graph_rms->SetTitle("TIB MuH Values per Layer (RMS)");
0304 TIB_graph_rms->GetXaxis()->SetTitle("Layer number");
0305 TIB_graph_rms->GetXaxis()->SetNdivisions(4);
0306 TIB_graph_rms->GetYaxis()->SetTitle("#mu_{H} (m^{2}/Vs)");
0307 TIB_graph_rms->GetYaxis()->CenterTitle();
0308 TIB_graph_rms->GetYaxis()->SetTitleOffset(1.25);
0309 TIB_graph_rms->GetYaxis()->SetRangeUser(0.01,0.03);
0310 tib_graph_rms->cd();
0311 TIB_graph_rms->Draw("AP");
0312 
0313 if(save_plots==1)tib_graph_rms->SaveAs("TIB_Graph_rms.eps");
0314 
0315 //TOB graph
0316 
0317 float rmsTOBey[6]={TOB1_muh_rms, TOB2_muh_rms, TOB3_muh_rms, TOB4_muh_rms, TOB5_muh_rms,TOB6_muh_rms};
0318 TGraphErrors *TOB_graph_rms = new TGraphErrors(n_tob,TOBx,TOBy,TOBex,rmsTOBey);
0319 TOB_graph_rms->SetMarkerStyle(20);
0320 TOB_graph_rms->SetTitle("TOB MuH Values per Layer (RMS)");
0321 TOB_graph_rms->GetXaxis()->SetTitle("Layer number");
0322 TOB_graph_rms->GetXaxis()->SetNdivisions(6);
0323 TOB_graph_rms->GetYaxis()->SetTitle("#mu_{H} (m^{2}/Vs)");
0324 TOB_graph_rms->GetYaxis()->CenterTitle();
0325 TOB_graph_rms->GetYaxis()->SetTitleOffset(1.25);
0326 TOB_graph_rms->GetYaxis()->SetRangeUser(0.01,0.03);
0327 tob_graph_rms->cd();
0328 TOB_graph_rms->Draw("AP");
0329 
0330 if(save_plots==1)tob_graph_rms->SaveAs("TOB_Graph_rms.eps");
0331 
0332 float rTIB1 = TIB1_muh/TIB_expected;
0333 float rTIB2 = TIB2_muh/TIB_expected; 
0334 float rTIB3 = TIB3_muh/TIB_expected; 
0335 float rTIB4 = TIB4_muh/TIB_expected; 
0336 float rTOB1 = TOB1_muh/TOB_expected; 
0337 float rTOB2 = TOB2_muh/TOB_expected; 
0338 float rTOB3 = TOB3_muh/TOB_expected; 
0339 float rTOB4 = TOB4_muh/TOB_expected; 
0340 float rTOB5 = TOB5_muh/TOB_expected; 
0341 float rTOB6 = TOB6_muh/TOB_expected;
0342 
0343 out<<endl<<endl<<"------ Ratios ------"<<endl<<endl;
0344 out<<"TIB1 (meas/exp) = "<<rTIB1<<endl;
0345 out<<"TIB2 (meas/exp) = "<<rTIB2<<endl;
0346 out<<"TIB3 (meas/exp) = "<<rTIB3<<endl;
0347 out<<"TIB4 (meas/exp) = "<<rTIB4<<endl;
0348 out<<"TOB1 (meas/exp) = "<<rTOB1<<endl;
0349 out<<"TOB2 (meas/exp) = "<<rTOB2<<endl;
0350 out<<"TOB3 (meas/exp) = "<<rTOB3<<endl;
0351 out<<"TOB4 (meas/exp) = "<<rTOB4<<endl;
0352 out<<"TOB5 (meas/exp) = "<<rTOB5<<endl;
0353 out<<"TOB6 (meas/exp) = "<<rTOB6<<endl;
0354 out<<endl;
0355 
0356 int r = 10;
0357 float RatiosX[10]={1,2,3,4,5,6,7,8,9,10};
0358 float RatiosEX[10]={0,0,0,0,0,0,0,0,0,0};
0359 float RatiosY[10]={rTIB1,rTIB2,rTIB3,rTIB4,rTOB1,rTOB2,rTOB3,rTOB4,rTOB5,rTOB6};
0360 float RatiosEY[10]={TIB1_muh_err/TIB_expected, TIB2_muh_err/TIB_expected, TIB3_muh_err/TIB_expected, TIB4_muh_err/TIB_expected, TOB1_muh_err/TOB_expected,TOB2_muh_err/TOB_expected, TOB3_muh_err/TOB_expected, TOB4_muh_err/TOB_expected, TOB5_muh_err/TOB_expected,TOB6_muh_err/TOB_expected};
0361 TGraphErrors *Ratios_graph = new TGraphErrors(r,RatiosX,RatiosY,RatiosEX,RatiosEY);
0362 Ratios_graph->SetMarkerStyle(20);
0363 Ratios_graph->SetTitle("MuH Ratios (meas/exp)");
0364 Ratios_graph->GetXaxis()->SetNdivisions(10);
0365 Ratios_graph->GetXaxis()->SetTitle("Layers");
0366 Ratios_graph->GetYaxis()->SetTitle("muH");
0367 Ratios_graph->GetYaxis()->CenterTitle();
0368 Ratios_graph->GetYaxis()->SetTitleOffset(1.1);
0369 Ratios->cd();
0370 Ratios_graph ->Draw("AP");
0371 
0372 out.close();
0373 
0374 }
0375