Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:16

0001 
0002 #include "TFile.h"
0003 #include "TH1F.h"
0004 #include "TCanvas.h"
0005 #include "TLegend.h"
0006 #include "TText.h"
0007 #include "TStyle.h"
0008 #include "TROOT.h"
0009 
0010 
0011 void setStyle();
0012 
0013 
0014 void rechitresiduals() {
0015 
0016   setStyle();
0017 
0018   TFile * f = TFile::Open("rechits_validation.root");
0019 
0020   TH1F * h1p = (TH1F *) f->FindObjectAny("Cluster_Size_Pixel_layer_1");
0021   TH1F * h2p = (TH1F *) f->FindObjectAny("Cluster_Size_Pixel_layer_2");
0022   TH1F * h3p = (TH1F *) f->FindObjectAny("Cluster_Size_Pixel_layer_3");
0023   h1p->Add(h2p);
0024   h1p->Add(h3p);
0025   TH1F * h1s = (TH1F *) f->FindObjectAny("Cluster_Size_Strip_layer_1");
0026   TH1F * h2s = (TH1F *) f->FindObjectAny("Cluster_Size_Strip_layer_2");
0027   TH1F * h3s = (TH1F *) f->FindObjectAny("Cluster_Size_Strip_layer_3");
0028   h1s->Add(h2s);
0029   h1s->Add(h3s);
0030   TH1F * h4s = (TH1F *) f->FindObjectAny("Cluster_Size_Strip_layer_4");
0031   TH1F * h5s = (TH1F *) f->FindObjectAny("Cluster_Size_Strip_layer_5");
0032   TH1F * h6s = (TH1F *) f->FindObjectAny("Cluster_Size_Strip_layer_6");
0033   h4s->Add(h5s);
0034   h4s->Add(h6s);
0035 
0036   h1p->GetXaxis()->SetRange(1,11);
0037   h1s->GetXaxis()->SetRange(1,11);
0038   h4s->GetXaxis()->SetRange(1,11);
0039 
0040   TCanvas * c0 = new TCanvas();
0041   TH1 * hn1 = h1p->DrawNormalized();
0042   hn1->SetNdivisions(11);
0043   hn1->SetMaximum(2.0);
0044   hn1->SetXTitle("Cluster size");
0045   hn1->SetYTitle("Arbitrary units");
0046   h1p->SetLineColor(kRed+1);
0047   h1s->SetLineColor(kOrange-3);
0048   h4s->SetLineColor(kBlack);
0049   h1p->SetLineWidth(2);
0050   h1s->SetLineWidth(2);
0051   h4s->SetLineWidth(3);
0052   h1p->SetLineStyle(1);
0053   h1s->SetLineStyle(2);
0054   h4s->SetLineStyle(3);
0055 
0056   h1p->DrawNormalized("same");
0057   h1s->DrawNormalized("same");
0058   h4s->DrawNormalized("same");
0059 
0060   TLegend * l0 = new TLegend(0.63,0.72,0.91,0.91);
0061   l0->SetBorderSize(0);
0062   l0->SetFillStyle(0);
0063   l0->AddEntry(h1p,"Macro-pixels","L");
0064   l0->AddEntry(h1s,"PS strips","L");
0065   l0->AddEntry(h4s,"2S strips","L");
0066   l0->Draw();
0067 
0068   TText * t1 = new TText(.18,.96,"CMS");
0069   TText * t2 = new TText(.26,.96,"Phase2 Simulation");
0070   t1->SetNDC();
0071   t2->SetNDC();
0072   t1->SetTextFont(62);
0073   t2->SetTextFont(52);
0074   t1->SetTextSize(0.035);
0075   t2->SetTextSize(0.033);
0076   t1->Draw();
0077   t2->Draw();
0078 
0079   c0->SetLogy();
0080   c0->SaveAs("clustersize_p_vs_s_vs_2s.png");
0081   c0->SaveAs("clustersize_p_vs_s_vs_2s.pdf");
0082 
0083   h1p = (TH1F *) f->FindObjectAny("Delta_X_Pixel_layer_1");
0084   h2p = (TH1F *) f->FindObjectAny("Delta_X_Pixel_layer_2");
0085   h3p = (TH1F *) f->FindObjectAny("Delta_X_Pixel_layer_3");
0086   h1p->Add(h2p);
0087   h1p->Add(h3p);
0088   h1s = (TH1F *) f->FindObjectAny("Delta_X_Strip_layer_1");
0089   h2s = (TH1F *) f->FindObjectAny("Delta_X_Strip_layer_2");
0090   h3s = (TH1F *) f->FindObjectAny("Delta_X_Strip_layer_3");
0091   h1s->Add(h2s);
0092   h1s->Add(h3s);
0093   h4s = (TH1F *) f->FindObjectAny("Delta_X_Strip_layer_4");
0094   h5s = (TH1F *) f->FindObjectAny("Delta_X_Strip_layer_5");
0095   h6s = (TH1F *) f->FindObjectAny("Delta_X_Strip_layer_6");
0096   h4s->Add(h5s);
0097   h4s->Add(h6s);
0098 
0099   TCanvas * c1 = new TCanvas();
0100   hn1 = h1p->DrawNormalized();
0101   hn1->SetMaximum(0.11);
0102   hn1->SetXTitle("#Deltax(cluster,simhit) [cm]");
0103   hn1->SetYTitle("Arbitrary units");
0104   h1p->SetLineColor(kRed+1);
0105   h1s->SetLineColor(kOrange-3);
0106   h4s->SetLineColor(kBlack);
0107   h1p->SetLineWidth(2);
0108   h1s->SetLineWidth(2);
0109   h4s->SetLineWidth(3);
0110   h1p->SetLineStyle(1);
0111   h1s->SetLineStyle(2);
0112   h4s->SetLineStyle(3);
0113 
0114   h1p->DrawNormalized("same");
0115   h1p->Fit("gaus","N","",-0.006,0.006);
0116   h1s->DrawNormalized("same");
0117   h1s->Fit("gaus","N","",-0.006,0.006);
0118   h4s->DrawNormalized("same");
0119   h4s->Fit("gaus","N","",-0.006,0.006);
0120 
0121   TLegend * l1 = new TLegend(0.63,0.72,0.91,0.91);
0122   l1->SetBorderSize(0);
0123   l1->SetFillStyle(0);
0124   l1->AddEntry(h1p,"Macro-pixels","L");
0125   l1->AddEntry(h1s,"PS strips","L");
0126   l1->AddEntry(h4s,"2S strips","L");
0127   l1->Draw();
0128 
0129   t1->Draw();
0130   t2->Draw();
0131 
0132   c1->SaveAs("rechitresiduals_p_vs_s_vs_2s.png");
0133   c1->SaveAs("rechitresiduals_p_vs_s_vs_2s.pdf");
0134 
0135   TH1F * h1p1 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_1_ClS_1"); h1p1->Rebin();
0136   TH1F * h2p1 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_2_ClS_1"); h2p1->Rebin();
0137   TH1F * h3p1 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_3_ClS_1"); h3p1->Rebin();
0138   h1p1->Add(h2p1);
0139   h1p1->Add(h3p1);
0140   TH1F * h1s1 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_1_ClS_1"); h1s1->Rebin();
0141   TH1F * h2s1 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_2_ClS_1"); h2s1->Rebin();
0142   TH1F * h3s1 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_3_ClS_1"); h3s1->Rebin();
0143   h1p1->Add(h1s1);
0144   h1p1->Add(h2s1);
0145   h1p1->Add(h3s1);
0146   TH1F * h4s1 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_4_ClS_1"); h4s1->Rebin();
0147   TH1F * h5s1 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_5_ClS_1"); h5s1->Rebin();
0148   TH1F * h6s1 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_6_ClS_1"); h6s1->Rebin();
0149   h1p1->Add(h4s1);
0150   h1p1->Add(h5s1);
0151   h1p1->Add(h6s1);
0152 
0153   TH1F * h1p2 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_1_ClS_2"); h1p2->Rebin();
0154   TH1F * h2p2 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_2_ClS_2"); h2p2->Rebin();
0155   TH1F * h3p2 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_3_ClS_2"); h3p2->Rebin();
0156   h1p2->Add(h2p2);
0157   h1p2->Add(h3p2);
0158   TH1F * h1s2 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_1_ClS_2"); h1s2->Rebin();
0159   TH1F * h2s2 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_2_ClS_2"); h2s2->Rebin();
0160   TH1F * h3s2 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_3_ClS_2"); h3s2->Rebin();
0161   h1p2->Add(h1s2);
0162   h1p2->Add(h2s2);
0163   h1p2->Add(h3s2);
0164   TH1F * h4s2 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_4_ClS_2"); h4s2->Rebin();
0165   TH1F * h5s2 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_5_ClS_2"); h5s2->Rebin();
0166   TH1F * h6s2 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_6_ClS_2"); h6s2->Rebin();
0167   h1p2->Add(h4s2);
0168   h1p2->Add(h5s2);
0169   h1p2->Add(h6s2);
0170 
0171   TH1F * h1p3 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_1_ClS_3"); h1p3->Rebin();
0172   TH1F * h2p3 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_2_ClS_3"); h2p3->Rebin();
0173   TH1F * h3p3 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_3_ClS_3"); h3p3->Rebin();
0174   h1p3->Add(h2p3);
0175   h1p3->Add(h3p3);
0176   TH1F * h1s3 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_1_ClS_3"); h1s3->Rebin();
0177   TH1F * h2s3 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_2_ClS_3"); h2s3->Rebin();
0178   TH1F * h3s3 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_3_ClS_3"); h3s3->Rebin();
0179   h1p3->Add(h1s3);
0180   h1p3->Add(h2s3);
0181   h1p3->Add(h3s3);
0182   TH1F * h4s3 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_4_ClS_3"); h4s3->Rebin();
0183   TH1F * h5s3 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_5_ClS_3"); h5s3->Rebin();
0184   TH1F * h6s3 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_6_ClS_3"); h6s3->Rebin();
0185   h1p3->Add(h4s3);
0186   h1p3->Add(h5s3);
0187   h1p3->Add(h6s3);
0188 
0189   TH1F * h1p4 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_1_ClS_4"); h1p4->Rebin();
0190   TH1F * h2p4 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_2_ClS_4"); h2p4->Rebin();
0191   TH1F * h3p4 = (TH1F *) f->FindObjectAny("Pull_X_Pixel_layer_3_ClS_4"); h3p4->Rebin();
0192   h1p4->Add(h2p4);
0193   h1p4->Add(h3p4);
0194   TH1F * h1s4 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_1_ClS_4"); h1s4->Rebin();
0195   TH1F * h2s4 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_2_ClS_4"); h2s4->Rebin();
0196   TH1F * h3s4 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_3_ClS_4"); h3s4->Rebin();
0197   h1p4->Add(h1s4);
0198   h1p4->Add(h2s4);
0199   h1p4->Add(h3s4);
0200   TH1F * h4s4 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_4_ClS_4"); h4s4->Rebin();
0201   TH1F * h5s4 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_5_ClS_4"); h5s4->Rebin();
0202   TH1F * h6s4 = (TH1F *) f->FindObjectAny("Pull_X_Strip_layer_6_ClS_4"); h6s4->Rebin();
0203   h1p4->Add(h4s4);
0204   h1p4->Add(h5s4);
0205   h1p4->Add(h6s4);
0206 
0207   TCanvas * c2 = new TCanvas();
0208   TH1 * hn2 = h1p1->DrawNormalized();
0209   hn2->SetMaximum(0.2);
0210   hn2->SetXTitle("Residual pull");
0211   hn2->SetYTitle("Arbitrary units");
0212   h1p1->SetLineColor(kRed+1);
0213   h1p2->SetLineColor(kOrange-3);
0214   h1p3->SetLineColor(kBlack);
0215   h1p4->SetLineColor(kViolet-1);
0216   h1p1->SetLineWidth(2);
0217   h1p2->SetLineWidth(2);
0218   h1p3->SetLineWidth(3);
0219   h1p4->SetLineWidth(2);
0220   h1p1->SetLineStyle(1);
0221   h1p2->SetLineStyle(2);
0222   h1p3->SetLineStyle(3);
0223   h1p4->SetLineStyle(4);
0224 
0225   h1p1->DrawNormalized("same");
0226   h1p1->Fit("gaus","N","",-2,2);
0227   h1p2->DrawNormalized("same");
0228   h1p2->Fit("gaus","N","",-2,2);
0229   h1p3->DrawNormalized("same");
0230   h1p3->Fit("gaus","N","",-2,2);
0231   h1p4->DrawNormalized("same");
0232   h1p4->Fit("gaus","N","",-2,2);
0233 
0234   TLegend * l2 = new TLegend(0.6,0.67,0.98,0.91);
0235   l2->SetBorderSize(0);
0236   l2->SetFillStyle(0);
0237   l2->AddEntry(h1p1,"Cluster size 1","L");
0238   l2->AddEntry(h1p2,"Cluster size 2","L");
0239   l2->AddEntry(h1p3,"Cluster size 3","L");
0240   l2->AddEntry(h1p4,"Cluster size 4","L");
0241   l2->Draw();
0242 
0243   t1->Draw();
0244   t2->Draw();
0245 
0246   c2->SaveAs("rechitpull_clustersize.png");
0247   c2->SaveAs("rechitpull_clustersize.pdf");
0248 
0249 }
0250 
0251 
0252 void setStyle() {
0253   TStyle * tdrStyle = new TStyle("tdrStyle","Style for P-TDR");
0254 
0255   // For the canvas:
0256   tdrStyle->SetCanvasBorderMode(0);
0257   tdrStyle->SetCanvasColor(kWhite);
0258   tdrStyle->SetCanvasDefH(600); //Height of canvas
0259   tdrStyle->SetCanvasDefW(600); //Width of canvas
0260   tdrStyle->SetCanvasDefX(0);   //POsition on screen
0261   tdrStyle->SetCanvasDefY(0);
0262 
0263   // For the Pad:
0264   tdrStyle->SetPadBorderMode(0);
0265   // tdrStyle->SetPadBorderSize(Width_t size = 1);
0266   tdrStyle->SetPadColor(kWhite);
0267   tdrStyle->SetPadGridX(false);
0268   tdrStyle->SetPadGridY(false);
0269   tdrStyle->SetGridColor(0);
0270   tdrStyle->SetGridStyle(3);
0271   tdrStyle->SetGridWidth(1);
0272 
0273   // For the frame:
0274   tdrStyle->SetFrameBorderMode(0);
0275   tdrStyle->SetFrameBorderSize(1);
0276   tdrStyle->SetFrameFillColor(0);
0277   tdrStyle->SetFrameFillStyle(0);
0278   tdrStyle->SetFrameLineColor(1);
0279   tdrStyle->SetFrameLineStyle(1);
0280   tdrStyle->SetFrameLineWidth(1);
0281 
0282   // For the histo:
0283   // tdrStyle->SetHistFillColor(1);
0284   // tdrStyle->SetHistFillStyle(0);
0285   tdrStyle->SetHistLineColor(1);
0286   tdrStyle->SetHistLineStyle(0);
0287   tdrStyle->SetHistLineWidth(1);
0288   // tdrStyle->SetLegoInnerR(Float_t rad = 0.5);
0289   // tdrStyle->SetNumberContours(Int_t number = 20);
0290 
0291   tdrStyle->SetEndErrorSize(2);
0292   //tdrStyle->SetErrorMarker(20);
0293   tdrStyle->SetErrorX(0.5);
0294   
0295   tdrStyle->SetMarkerStyle(20);
0296 
0297   //For the fit/function:
0298   tdrStyle->SetOptFit(1);
0299   tdrStyle->SetFitFormat("5.4g");
0300   tdrStyle->SetFuncColor(2);
0301   tdrStyle->SetFuncStyle(1);
0302   tdrStyle->SetFuncWidth(1);
0303 
0304   //For the date:
0305   tdrStyle->SetOptDate(0);
0306   // tdrStyle->SetDateX(Float_t x = 0.01);
0307   // tdrStyle->SetDateY(Float_t y = 0.01);
0308 
0309   // For the statistics box:
0310   tdrStyle->SetOptFile(0);
0311   tdrStyle->SetOptStat(0); // To display the mean and RMS:   SetOptStat("mr");
0312   tdrStyle->SetStatColor(kWhite);
0313   tdrStyle->SetStatFont(42);
0314   tdrStyle->SetStatFontSize(0.025);
0315   tdrStyle->SetStatTextColor(1);
0316   tdrStyle->SetStatFormat("6.4g");
0317   tdrStyle->SetStatBorderSize(1);
0318   tdrStyle->SetStatH(0.1);
0319   tdrStyle->SetStatW(0.15);
0320 
0321   // Margins:
0322   tdrStyle->SetPadTopMargin(0.05);
0323   tdrStyle->SetPadBottomMargin(0.14);
0324   tdrStyle->SetPadLeftMargin(0.18);
0325   tdrStyle->SetPadRightMargin(0.05);
0326 
0327   // For the Global title:
0328   tdrStyle->SetOptTitle(0);
0329 
0330   // For the axis titles:
0331   tdrStyle->SetTitleColor(1, "XYZ");
0332   tdrStyle->SetTitleFont(42, "XYZ");
0333   tdrStyle->SetTitleSize(0.06, "XYZ");
0334   tdrStyle->SetTitleXOffset(1.0);
0335   tdrStyle->SetTitleYOffset(1.4);
0336 
0337   // For the axis labels:
0338   tdrStyle->SetLabelColor(1, "XYZ");
0339   tdrStyle->SetLabelFont(42, "XYZ");
0340   tdrStyle->SetLabelOffset(0.007, "XYZ");
0341   tdrStyle->SetLabelSize(0.05, "XYZ");
0342 
0343   // For the axis:
0344   tdrStyle->SetAxisColor(1, "XYZ");
0345   tdrStyle->SetStripDecimals(kTRUE);
0346   tdrStyle->SetTickLength(0.03, "XYZ");
0347   tdrStyle->SetNdivisions(510, "XYZ");
0348   tdrStyle->SetPadTickX(1);  // To get tick marks on the opposite side of the frame
0349   tdrStyle->SetPadTickY(1);
0350 
0351   // Change for log plots:
0352   tdrStyle->SetOptLogx(0);
0353   tdrStyle->SetOptLogy(0);
0354   tdrStyle->SetOptLogz(0);
0355 
0356   // some more stuff
0357   tdrStyle->SetNdivisions(505, "X");
0358   tdrStyle->SetPalette(1,0);
0359 
0360   tdrStyle->cd();
0361   gROOT->ForceStyle();
0362 }