Rev 47 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 47 | Rev 91 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | #include "TFile.h" | 
            2 | #include "TFile.h" | 
          
| 3 | #include "TBenchmark.h" | 
            3 | #include "TBenchmark.h" | 
          
| - | 4 | #include "TH1.h" | 
          |
| 4 | #include "TH1F.h" | 
            5 | #include "TH1F.h" | 
          
| 5 | #include "TH2F.h" | 
            6 | #include "TH2F.h" | 
          
| 6 | #include "TH3F.h" | 
            7 | #include "TH3F.h" | 
          
| 7 | #include "TCanvas.h" | 
            8 | #include "TCanvas.h" | 
          
| 8 | #include "TStyle.h" | 
            9 | #include "TStyle.h" | 
          
| 9 | #include "TPad.h" | 
            10 | #include "TPad.h" | 
          
| 10 | #include "TF1.h" | 
            11 | #include "TF1.h" | 
          
| 11 | #include "TGraph.h" | 
            12 | #include "TGraph.h" | 
          
| 12 | #include "TSpectrum.h" | 
            13 | #include "TSpectrum.h" | 
          
| - | 14 | #include "TAttFill.h" | 
          |
| 13 | #include "stdio.h" | 
            15 | #include "stdio.h" | 
          
| - | 16 | ||
| - | 17 | #include "include/RTUtil.h" | 
          |
| 14 | 18 | ||
| 15 | //#include "include/RTUtil.h" | 
            19 | //#include "include/RTUtil.h" | 
          
| 16 | 20 | ||
| 17 | int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=  | 
            21 | int tdc(char filename[256] = "test", int chX=0, int chY=0, double rangeLeft=87, double rangeRight=107, bool debug = false)  | 
          
| 18 | { | 
            22 | { | 
          
| 19 |   //const int c_nChannels = 64; | 
            - | |
| 20 |   //const double c_xOffset = 2.2; // mm | 
            - | |
| 21 |   //const double c_yOffset = 2.3; | 
            - | |
| 22 | 23 | ||
| 23 | int map[8][8]={{32,34,53,55,40,42,61,63},  | 
            24 | int map[8][8]={{32,34,53,55,40,42,61,63},  | 
          
| 24 | {48,50,37,39,56,58,45,47},  | 
            25 | {48,50,37,39,56,58,45,47},  | 
          
| 25 | {33,35,52,54,41,43,60,62},  | 
            26 | {33,35,52,54,41,43,60,62},  | 
          
| 26 | {49,51,36,38,57,59,44,46},  | 
            27 | {49,51,36,38,57,59,44,46},  | 
          
| Line 39... | Line 40... | ||
| 39 | printf("Cannot open root file %s!!!\n",fnameroot);  | 
            40 | printf("Cannot open root file %s!!!\n",fnameroot);  | 
          
| 40 | return(0);  | 
            41 | return(0);  | 
          
| 41 |         } | 
            42 |         } | 
          
| 42 | 43 | ||
| 43 |         // set draw style | 
            44 |         // set draw style | 
          
| - | 45 |         /* | 
          |
| 44 | gStyle->SetPalette(1, 0);  | 
            46 |         gStyle->SetPalette(1, 0); | 
          
| 45 | 47 |         | 
          |
| 46 | gStyle->SetPaperSize(TStyle::kA4);  | 
            48 |         gStyle->SetPaperSize(TStyle::kA4); | 
          
| 47 | gStyle->SetStatBorderSize(1);  | 
            49 |         gStyle->SetStatBorderSize(1); | 
          
| 48 | gStyle->SetFrameBorderMode(0);  | 
            50 |         gStyle->SetFrameBorderMode(0); | 
          
| Line 50... | Line 52... | ||
| 50 | gStyle->SetCanvasBorderMode(0);  | 
            52 |         gStyle->SetCanvasBorderMode(0); | 
          
| 51 | gStyle->SetPadBorderMode(0);  | 
            53 |         gStyle->SetPadBorderMode(0); | 
          
| 52 | gStyle->SetPadColor(0);  | 
            54 |         gStyle->SetPadColor(0); | 
          
| 53 | gStyle->SetCanvasColor(0);  | 
            55 |         gStyle->SetCanvasColor(0); | 
          
| 54 | gStyle->SetStatColor(0);  | 
            56 |         gStyle->SetStatColor(0); | 
          
| 55 | gStyle  | 
            57 | gStyle->SetOptFit(1111);  | 
          
| 56 | gStyle->SetOptStat("ne");  | 
            58 |         gStyle->SetOptStat("ne"); | 
          
| 57 | gStyle->SetPadTopMargin(0.15);  | 
            59 |         gStyle->SetPadTopMargin(0.15); | 
          
| 58 | gStyle->SetPadBottomMargin(0.15);  | 
            60 |         gStyle->SetPadBottomMargin(0.15); | 
          
| 59 | gStyle->SetPadRightMargin(0.15);  | 
            61 |         gStyle->SetPadRightMargin(0.15); | 
          
| 60 | gStyle->SetPadLeftMargin(0.15);  | 
            62 |         gStyle->SetPadLeftMargin(0.15); | 
          
| 61 | 
  | 
            63 | //gStyle->SetTitleYOffset(1.4);*/  | 
          
| - | 64 | RTSetStyle(gStyle);  | 
          |
| 62 | 65 | ||
| 63 | TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000);  | 
            66 | TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000);  | 
          
| 64 | TH2F*  | 
            67 | TH2F* h_tdc = (TH2F*) rootfile->Get("htdc");  | 
          
| 65 | canvas1->cd();  | 
            68 | canvas1->cd();  | 
          
| 66 | 
  | 
            69 | h_tdc->Draw("colz");  | 
          
| 67 | 70 | ||
| 68 |     //TH3F* h_3D = (TH3F*) rootfile->Get("h_correctedTDC"); | 
            71 |     //TH3F* h_3D = (TH3F*) rootfile->Get("h_correctedTDC"); | 
          
| 69 | TH2F* h_correctedTDC = (TH2F*) rootfile->Get("h_correctedTDC");  | 
            72 | TH2F* h_correctedTDC = (TH2F*) rootfile->Get("h_correctedTDC");  | 
          
| 70 | TCanvas* canvas2 = new TCanvas("canvas2","canvas2",  | 
            73 | TCanvas* canvas2 = new TCanvas("canvas2","canvas2",1000,1000);  | 
          
| 71 | canvas2->cd();  | 
            74 | canvas2->cd();  | 
          
| 72 | h_correctedTDC->Draw("colz");  | 
            75 | h_correctedTDC->Draw("colz");  | 
          
| 73 | 76 | ||
| 74 | 
  | 
            77 | |
| 75 | 
  | 
            78 |     //TH2D* h_correctedTDC = (TH2D*) h_3D->Project3D("xz"); | 
          
| 76 | 
  | 
            79 |     //h_correctedTDC->SetTitle("; t [ns]; Channel"); | 
          
| 77 | 
  | 
            80 |     //h_correctedTDC->Draw("colz"); | 
          
| 78 | 
  | 
            81 | TCanvas* canvas3 = new TCanvas("canvas3","canvas3",1600,1600);  | 
          
| 79 | 
  | 
            82 | canvas3->cd();  | 
          
| 80 | 
  | 
            83 |     //TH1D* h_allTDCbins = h_correctedTDC->ProjectionX("", 1, 64); | 
          
| 81 | 
  | 
            84 |     //h_allTDCbins->Draw(); | 
          
| 82 | 
  | 
            85 | |
| 83 | 
  | 
            86 | |
| 84 |     int binY = map[chX][chY]; | 
            87 | int binY = map[chX][chY];  | 
          
| - | 88 | if (debug) printf("%d\n", binY);  | 
          |
| 85 | 
  | 
            89 |     //TH1D* channelY = h_correctedTDC->ProjectionX("",binY+1,binY+1); | 
          
| - | 90 | TH1D* channelY = h_tdc->ProjectionX("",binY+1,binY+1);  | 
          |
| 86 | 
  | 
            91 | channelY->SetStats(1);  | 
          
| 87 |     | 
            92 | |
| 88 |     char title[256]; | 
            93 | char title[256];  | 
          
| 89 | 
  | 
            94 | sprintf(title,";Time [ns];Events");  | 
          
| 90 |     channelY->SetTitle(title); | 
            95 | channelY->SetTitle(title);  | 
          
| 91 | 
  | 
            96 |     //channelY->GetYaxis()->SetTitleOffset(1.7); | 
          
| 92 | 
  | 
            97 |     //TAxis* xAxis = h_correctedTDC->GetXaxis(); | 
          
| 93 | 
  | 
            98 |     //int range = xAxis->GetBinUpEdge(xAxis->GetLast()+1); | 
          
| 94 | 
  | 
            99 |     //channelY->GetXaxis()->SetRangeUser(-range, range); | 
          
| - | 100 |     //gStyle->SetOptStat("nemr"); | 
          |
| - | 101 |     //gStyle->SetOptFit(111); | 
          |
| - | 102 | channelY->GetXaxis()->SetRangeUser(rangeLeft,rangeRight);  | 
          |
| 95 |     channelY->Draw(); | 
            103 | channelY->Draw();  | 
          
| 96 | - | ||
| 97 |     TF1* f_gaus1 = new TF1("f_gaus1","[0] + gaus(1)", rangeLeft,rangeRight); | 
            - | |
| 98 |     TF1* f_gaus2 = new TF1("f_gaus2","[0] + gaus(1) + gaus(4)",-8,8); | 
            - | |
| 99 |     f_gaus1->SetParNames("Linear","Norm","#mu","#sigma"); | 
            - | |
| 100 |     f_gaus2->SetParNames("Linear","Norm1","Mean1","Sigma1","Norm2","Mean2","Sigma2"); | 
            - | |
| 101 |     Int_t n = channelY->GetMaximum(); | 
            - | |
| 102 |     Float_t mean = channelY->GetBinCenter(channelY->GetMaximumBin()); | 
            - | |
| 103 |     | 
            - | |
| 104 |     f_gaus1->SetParameters(channelY->GetMinimum(), n, mean, 2.0); | 
            - | |
| 105 |     channelY->Fit(f_gaus1,"0"); | 
            - | |
| 106 |     channelY->Fit(f_gaus1,"r"); | 
            - | |
| 107 |     */ | 
            - | |
| 108 |     //Fit in range +- 3 sigma | 
            - | |
| 109 |     //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(2)-3*f_gaus1->GetParameter(3), | 
            - | |
| 110 |       //                            f_gaus1->GetParameter(2)+3*f_gaus1->GetParameter(3)); | 
            - | |
| 111 | 104 | ||
| - | 105 |     // Fit function: linear for background c + k*x | 
          |
| - | 106 |     // Signal: norm*gaussian(mu,sigma) | 
          |
| - | 107 | TF1* f_gaus1 = new TF1("f_gaus1","[0] +[1]*x + gaus(2)", rangeLeft, rangeRight);  | 
          |
| - | 108 |     //TF1* f_gaus1 = new TF1("f_gaus1","[0] +[1]*x + gaus(2)"); | 
          |
| - | 109 | f_gaus1->SetParNames("Const","Linear","Norm","#mu","#sigma");  | 
          |
| - | 110 |     //f_gaus1->SetLineColor(kAzure+1); | 
          |
| - | 111 | f_gaus1->SetLineColor(kBlack);  | 
          |
| - | 112 | f_gaus1->SetLineWidth(4);  | 
          |
| - | 113 | ||
| - | 114 | f_gaus1->SetParameter(0, channelY->GetMinimum());  | 
          |
| - | 115 | f_gaus1->SetParameter(1, 0.0);  | 
          |
| - | 116 | f_gaus1->SetParameter(2, channelY->GetMaximum() - channelY->GetMinimum());  | 
          |
| - | 117 | f_gaus1->SetParameter(3, channelY->GetBinCenter(channelY->GetMaximumBin()));  | 
          |
| - | 118 | f_gaus1->SetParameter(4, 1.0);  | 
          |
| - | 119 |     //channelY->Fit(f_gaus1,"qr"); | 
          |
| - | 120 |     //channelY->Fit(f_gaus1,"r"); | 
          |
| - | 121 | ||
| - | 122 |     //Fit in range +- 3 sigma | 
          |
| - | 123 |     //channelY->Fit(f_gaus1,"r","", f_gaus1->GetParameter(3)-3*f_gaus1->GetParameter(4), | 
          |
| - | 124 | channelY->Fit(f_gaus1,"","");  | 
          |
| - | 125 |                                   //f_gaus1->GetParameter(3)+3*f_gaus1->GetParameter(4)); | 
          |
| - | 126 | ||
| - | 127 | double N = channelY->GetEntries();  | 
          |
| - | 128 | double Nbkg = (rangeRight - rangeLeft)*f_gaus1->GetParameter(0);  | 
          |
| - | 129 | double Nsig = N - Nbkg;  | 
          |
| - | 130 | printf("\nN = %f, Nsig = %f, Nbkg = %f, SN = %f***\n\n", N, Nsig, Nbkg, Nsig/Nbkg);  | 
          |
| - | 131 |    /* | 
          |
| - | 132 |     //to draw a shaded area above and below an histogram range, we create | 
          |
| - | 133 |    //a TGraph object (here we shade bins 60 to 80). | 
          |
| - | 134 |    Int_t i; | 
          |
| - | 135 |    Int_t n = 2*(80-60); | 
          |
| - | 136 |    TGraph *gr = new TGraph(2*n); | 
          |
| - | 137 |    for (i=0;i<20;i++) { | 
          |
| - | 138 |       Float_t xlow = h1->GetBinLowEdge(60+i); | 
          |
| - | 139 |       Float_t xup  = h1->GetBinLowEdge(60+i+1); | 
          |
| - | 140 |       Float_t y    = h1->GetBinContent(60+i); | 
          |
| - | 141 |       Float_t yup  = 1.1*y; | 
          |
| - | 142 |       Float_t ydown= 0.9*y; | 
          |
| - | 143 |       gr->SetPoint(2*i,  xlow,yup); | 
          |
| - | 144 |       gr->SetPoint(2*i+1,xup, yup); | 
          |
| - | 145 |       gr->SetPoint(2*n-2*i-1,xlow, ydown); | 
          |
| - | 146 |       gr->SetPoint(2*n-2*i-2,xup, ydown); | 
          |
| - | 147 |    } | 
          |
| - | 148 |    gr->SetFillColor(2); | 
          |
| - | 149 |    gr->Draw("lf");*/ | 
          |
| 112 | 150 | ||
| - | 151 | TH1D* timeWindow = (TH1D*) channelY->Clone();  | 
          |
| 113 | 
  | 
            152 | timeWindow->GetXaxis()->SetRangeUser(92,102);  | 
          
| 114 | 
  | 
            153 |     //timeWindow->SetFillColor(kAzure-1); | 
          
| 115 | 
  | 
            154 | timeWindow->SetFillColor(kBlack);  | 
          
| 116 | 
  | 
            155 | timeWindow->SetFillStyle(3004);  | 
          
| 117 | 
  | 
            156 | timeWindow->Draw("same");  | 
          
| - | 157 | ||
| - | 158 | ||
| - | 159 | char drawing[128];  | 
          |
| 118 | 
  | 
            160 | sprintf(drawing, "ps/%sTDC.pdf", filename);  | 
          
| 119 | 
  | 
            161 | canvas3->SaveAs(drawing);  | 
          
| - | 162 | ||
| 120 | 163 | gPad->Update();  | 
          |
| 121 | return (0);  | 
            164 | return (0);  | 
          
| 122 |   } | 
            165 |   } |