Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 TH1D ratioEff(TH1D* hn, TH1D* hd);
0002 
0003 // ch is Chamber name
0004 void PlotEff(const char* ch = "") {
0005   gROOT->LoadMacro("macros.C");     // Load service macros
0006   TStyle * style = getStyle("tdr");
0007 //  style->SetTitleYOffset(1.6);
0008   style->cd();                      // Apply style 
0009 
0010   if (ch == "" ) {
0011     cout << "Usage: PlotEff(\"ChamberName\") " << endl;
0012     cout << "Ex: PlotEff(\"Wh1_Sec10_St1\") " << endl;
0013     return;
0014   }
0015   TCanvas *c1 = new TCanvas("c1", "c1",10,25,900,400);
0016 
0017   c1->Update();
0018   c1->Divide(3);
0019   gStyle->SetOptFit(0);
0020   gStyle->SetOptStat(0);
0021   gStyle->SetPalette(1);
0022   TFile* file = TFile::Open("DTEffAnalyzer.root");
0023   //TFile* file = TFile::Open("DTEffAnalyzer_4398_118kev.root");
0024   //TFile* file = TFile::Open("DTEffAnalyzer_4398_100kev.root");
0025 
0026   TString nameDen("hEffGoodSegVsPosDen_");
0027   nameDen+=ch;
0028   TH2F* h2d = (TH2F*)(file->Get(nameDen));
0029 
0030   TString nameNum("hEffGoodCloseSegVsPosNum_");
0031   nameNum+=ch;
0032   TH2F* h2n = (TH2F*)(file->Get(nameNum));
0033   TH2F h2=(*h2n)/(*h2d);
0034   //h2.DrawCopy("zcol");
0035   TH1D* proxN=h2n->ProjectionX();
0036   TH1D* proxD=h2d->ProjectionX();
0037   TH1D* proyN=h2n->ProjectionY();
0038   TH1D* proyD=h2d->ProjectionY();
0039   int firstBinY=1;
0040   int lastBinY=h2.GetNbinsY();
0041   int midbinX=h2.GetNbinsX()/2;
0042   // cout << "midbinX " << midbinX << endl;
0043   for (int i=2; i<h2.GetNbinsY()-1; ++i) {
0044     //cout << "GetBinContent " << i << "=" << h2.GetBinContent(midbinX,i) << endl;
0045     if (firstBinY==1 && h2.GetBinContent(midbinX,i)>0) {
0046       // cout << "firstBinY " << i << endl;
0047       firstBinY=i+1;
0048       continue;
0049     }
0050     if (firstBinY!=1 && h2.GetBinContent(midbinX,i)==0) {
0051       // cout << "lastBinY " << i << endl;
0052       lastBinY=i-1;
0053       break;
0054     }
0055   }
0056   // cout << "firstBinY " << firstBinY << endl;
0057   // cout << "lastBinY " << lastBinY << endl;
0058 
0059   int firstBinX=1;
0060   int lastBinX=h2.GetNbinsX();
0061   int midbinY=h2.GetNbinsY()/2;
0062   // cout << "midbinY " << midbinY << endl;
0063   for (int i=2; i<h2.GetNbinsX()-1; ++i) {
0064     //cout << "GetBinContent " << i << "=" << h2.GetBinContent(midbinY,i) << endl;
0065     if (firstBinX==1 && h2.GetBinContent(i,midbinY)>0) {
0066       // cout << "firstBinX " << i << endl;
0067       firstBinX=i+1;
0068       continue;
0069     }
0070     if (firstBinX!=1 && h2.GetBinContent(i,midbinY)==0) {
0071       // cout << "lastBinX " << i << endl;
0072       lastBinX=i-1;
0073       break;
0074     }
0075   }
0076   // cout << "firstBinX " << firstBinX << endl;
0077   // cout << "lastBinX " << lastBinX << endl;
0078   TH1D* proxNc=h2n->ProjectionX("_pxnc",firstBinY,lastBinY);
0079   TH1D* proxDc=h2d->ProjectionX("_pxdc",firstBinY,lastBinY);
0080   TH1D* proyNc=h2n->ProjectionY("_pync",firstBinX,lastBinX);
0081   TH1D* proyDc=h2d->ProjectionY("_pydc",firstBinX,lastBinX);
0082 
0083   TLegend* leg= new TLegend(0.28,0.15,0.72,0.3,"Eff");
0084     leg->SetFillColor(0);
0085   c1->cd(1);
0086   TGraphAsymmErrors* hx = new TGraphAsymmErrors();
0087   hx->BayesDivide(proxN,proxD);
0088   hx->SetTitle("Efficiency along X:x (cm):#epsilon");
0089   (hx->GetXaxis())->SetTitle("x (cm)");
0090   (hx->GetYaxis())->SetTitle("#epsilon");
0091   hx->SetMarkerColor(4);
0092   hx->SetMarkerStyle(22);
0093   hx->SetMarkerSize(.8);
0094   hx->SetMinimum(0.8);
0095   hx->SetMaximum(1.05);
0096   hx->Draw("ALP");
0097   leg->AddEntry(hx,"Full chamber","P");
0098 
0099   TGraphAsymmErrors* hxc = new TGraphAsymmErrors();
0100   hxc->BayesDivide(proxNc,proxDc);
0101   hxc->SetTitle("Efficiency along X (no Y border)");
0102   hxc->SetMarkerColor(2);
0103   hxc->SetMarkerStyle(20);
0104   hxc->SetMarkerSize(.8);
0105   hxc->Draw("LP");
0106   leg->AddEntry(hxc,"Excluding chamber edge","P");
0107   leg->Draw();
0108 
0109   c1->cd(2);
0110   TGraphAsymmErrors* hy = new TGraphAsymmErrors();
0111   hy->BayesDivide(proyN,proyD);
0112   hy->SetTitle("Efficiency along y");
0113   (hy->GetXaxis())->SetTitle("y (cm)");
0114   (hy->GetYaxis())->SetTitle("#epsilon");
0115   hy->SetMarkerColor(4);
0116   hy->SetMarkerStyle(22);
0117   hy->SetMinimum(0.80);
0118   hy->SetMaximum(1.05);
0119   hy->Draw("ALP");
0120   TGraphAsymmErrors* hyc = new TGraphAsymmErrors();
0121   hyc->BayesDivide(proyNc,proyDc);
0122   hyc->SetTitle("Efficiency along Y (no X border)");
0123   hyc->SetMarkerColor(2);
0124   hyc->SetMarkerStyle(20);
0125   hyc->SetMarkerSize(.8);
0126   hyc->Draw("LP");
0127   leg->Draw();
0128 
0129   c1->cd(3);
0130   // TH2F* h2n = (TH2F*)(file->Get(nameNum));
0131   // TH2F h2=(*h2n)/(*h2d);
0132   // h2.SetMinimum(0.5);
0133   h2.SetTitle("Efficiency vs (x,y)");
0134   (h2.GetXaxis())->SetTitle("x (cm)");
0135   (h2.GetXaxis())->SetRange(firstBinX-2,lastBinX+2);
0136   (h2.GetYaxis())->SetTitle("y (cm)");
0137   (h2.GetYaxis())->SetRange(firstBinY-2,lastBinY+2);
0138   h2.DrawCopy("zcol");
0139   TString f("hSegEff");
0140   c1->Print(f+ch+".eps");
0141   c1->Print(f+ch+".root");
0142 }