Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "TROOT.h"
  2. #include "TFile.h"
  3. #include "TBenchmark.h"
  4. #include "TH1F.h"
  5. #include "TH2F.h"
  6. #include "TCanvas.h"
  7. #include "TStyle.h"
  8. #include "TPad.h"
  9. #include "TF1.h"
  10. #include "TGraph.h"
  11. #include "TSpectrum.h"
  12. #include "stdio.h"
  13.  
  14. //#include "../RTUtil.h"
  15.  
  16. int plot_tdc(char* filename = "test", char *plopt="t", int chXstart=0, int chXend=7, int chYstart=0, int chYend=7)
  17. {
  18.   const int c_nChannels = 64;
  19.   char fullname[256];
  20.  
  21.   int map[8][8]={{32,34,53,55,40,42,61,63},
  22.                  {48,50,37,39,56,58,45,47},
  23.                  {33,35,52,54,41,43,60,62},
  24.                  {49,51,36,38,57,59,44,46},
  25.                  {17,19,4,6,25,27,12,14},
  26.                  {1,3,20,22,9,11,28,30},
  27.                  {16,18,5,7,24,26,13,15},
  28.                  {0,2,21,23,8,10,29,31}
  29.                 };
  30.  
  31.   char fnameroot[256];
  32.   TFile* rootfile;
  33.         sprintf(fnameroot, "root/%s.root", filename);
  34.         rootfile = (TFile *) gROOT->FindObject(filename);
  35.         if(rootfile==NULL) rootfile = new TFile(fnameroot);
  36.         if(rootfile==NULL) {
  37.           printf("Cannot open root file %s!!!\n",fnameroot);
  38.           return(0);
  39.         }
  40.  
  41.         // set draw style
  42.         gStyle->SetOptStat("ne");
  43.         gStyle->SetPalette(1, 0);
  44.        
  45.         gStyle->SetPaperSize(TStyle::kA4);
  46.         gStyle->SetStatBorderSize(1);
  47.         gStyle->SetFrameBorderMode(0);
  48.         gStyle->SetFrameFillColor(0);
  49.         gStyle->SetCanvasBorderMode(0);
  50.         gStyle->SetPadBorderMode(0);
  51.         gStyle->SetPadColor(0);
  52.         gStyle->SetCanvasColor(0);
  53.         gStyle->SetStatColor(0);
  54.         gStyle->SetOptFit(11);
  55.         gStyle->SetOptStat();
  56.         gStyle->SetPadRightMargin(0.15);
  57.         gStyle->SetPadLeftMargin(0.12);
  58.         //gStyle->SetTitleYOffset(1.4);
  59.        
  60.         if( strchr(plopt, 't') != NULL ) {  
  61.     TCanvas* canvas1 = new TCanvas("canvas1","canvas1",1000,1000);
  62.     TH2F* htdc = (TH2F*) rootfile->Get("htdc");
  63.     canvas1->cd();
  64.     htdc->Draw("colz");
  65.    
  66.     TH2F* h_correctedTDC = (TH2F*) rootfile->Get("h_correctedTDC");
  67.     TCanvas* canvas6 = new TCanvas("canvas6","canvas6",500,500);
  68.     canvas6->cd();
  69.     h_correctedTDC->Draw("colz");
  70.    
  71.     TH1D* channelY = htdc->ProjectionX("",54,54);
  72.     channelY->SetStats(0);
  73.     channelY->SetTitle(";TDC [ns];Events");
  74.     channelY->GetYaxis()->SetTitleOffset(1.7);
  75.     //channelY->GetXaxis()->SetRangeUser(-40,40);
  76.     //channelY->Draw();
  77.  
  78.     TF1* f_gaus = new TF1("f_gaus","gaus(0)+gaus(3)",-10,20);
  79.     f_gaus->SetParNames("Constant1","Mean1","Sigma1","Constant2","Mean2","Sigma2");
  80.     f_gaus->SetParameters(channelY->GetMaximum(), channelY->GetBinCenter(channelY->GetMaximumBin()), 0.5,
  81.                           channelY->GetMaximum(), channelY->GetBinCenter(channelY->GetMaximumBin())/10.0, 0.05);
  82.     /*channelY->Fit(f_gaus,"0ql","",f_gaus->GetParameter(1)-0.1,f_gaus->GetParameter(1)+0.05);
  83.     channelY->Fit(f_gaus,"ql","",f_gaus->GetParameter(1)-0.1,f_gaus->GetParameter(1)+0.05);
  84.     channelY->Fit(f_gaus,"0qlr","",-20,20);
  85.     channelY->Fit(f_gaus,"qlr","",f_gaus->GetParameter(1)-2*f_gaus->GetParameter(2),
  86.                                  f_gaus->GetParameter(1)+2*f_gaus->GetParameter(2));*/
  87.   }
  88.  
  89.   if( strchr(plopt, 'all') != NULL ) {
  90.     TCanvas *canvas2 = new TCanvas("canvas2","Hits x;;",2000,2000);
  91.     TCanvas *canvas3 = new TCanvas("canvas3","Hits y;;",2000,2000);
  92.     canvas2->Divide(8,8);
  93.     canvas3->Divide(8,8);
  94.     TH1F* h_hitsx;
  95.     TH1F* h_hitsy;
  96.     for(int i=0; i<64; i++) {
  97.       canvas2->cd(i+1);
  98.       char hname[128];
  99.       sprintf(hname, "hnhitsx%d", i);
  100.       h_hitsx = (TH1F*)rootfile->Get(hname);
  101.       h_hitsx->Draw();
  102.       canvas3->cd(i+1);
  103.       sprintf(hname, "hnhitsy%d", i);
  104.       h_hitsy = (TH1F*)rootfile->Get(hname);
  105.       h_hitsy->Draw();  
  106.     }
  107.   }
  108.  
  109.   if( strchr(plopt, 'x') != NULL ) {
  110.     TCanvas *canvas10 = new TCanvas("canvas10","Ch x;;",500,500);
  111.     TH1F* h_hitsx;
  112.     canvas10->cd();
  113.     char hname[128];
  114.     sprintf(hname, "hnhitsx%d", chXstart);
  115.     h_hitsx = (TH1F*)rootfile->Get(hname);
  116.     h_hitsx->Draw();
  117.   }
  118.  
  119.   if( strchr(plopt, 'y') != NULL ) {
  120.     TCanvas *canvas11 = new TCanvas("canvas11","Ch x;;",500,500);
  121.     TH1F* h_hitsy;
  122.     canvas11->cd();
  123.     char hname[128];
  124.     sprintf(hname, "hnhitsy%d", chXstart);
  125.     h_hitsy = (TH1F*)rootfile->Get(hname);
  126.     h_hitsy->Draw();
  127.   }
  128.  
  129.   if( strstr(plopt, "share") != NULL ) {
  130.    /*TCanvas *canvas4 = new TCanvas("canvas1","canvas1",1000,1000);
  131.    int nChannels = chYend-chYstart+1;
  132.    int ncols = nChannels/2;
  133.    printf("nch %d nch\\2 %d\n", nChannels, ncols);
  134.    canvas4->Divide(2,ncols);
  135.    TH1F* h_hitsy;
  136.    for(int i=chYstart; i<=chYend; i++){
  137.      canvas4->cd(i-chYstart+1);
  138.      char hname[128];
  139.      int chPosition = map[0][i];
  140.      sprintf(hname, "hnhitsy%d", chPosition);
  141.      h_hitsy = (TH1F*)rootfile->Get(hname);
  142.      h_hitsy->Draw();
  143.    }*/
  144.    
  145.    TCanvas *canvas5 = new TCanvas("canvas5","canvas5",500,500);
  146.    canvas5->cd();
  147.    for(int i=chYstart; i<=chYend; i++) {
  148.      TH1F* h_hitsy;
  149.      char hname[128];
  150.      int chPosition = map[chXstart][i];
  151.      sprintf(hname, "hnhitsy%d", chPosition);
  152.      h_hitsy = (TH1F*)rootfile->Get(hname);
  153.      h_hitsy->SetTitle("Scan Y;y [mm]; Entries");
  154.      h_hitsy->GetYaxis()->SetTitleOffset(1.3);
  155.      h_hitsy->SetStats(0);
  156.      if (i == chYstart)
  157.       h_hitsy->Draw();
  158.      else {
  159.       h_hitsy->SetLineColor(i+1);
  160.       h_hitsy->Draw("same");
  161.      }
  162.    }
  163.    sprintf(fullname, "ps/%s_Yshare.eps", filename);
  164.          canvas5->SaveAs(fullname);
  165.   }
  166.  
  167.   if (strstr(plopt, "2d") != NULL) {
  168.    
  169.     int nX = chXend - chXstart + 1;
  170.     int nY = chYend - chYstart + 1;
  171.     TCanvas* canvas7 = new TCanvas("canvas7","canvas7", nX*250,nY*250);
  172.     printf("nx %d ny %d\n",nX,nY);
  173.     canvas7->Divide(nX,nY);
  174.     for(int i=chYstart; i<=chYend; i++) {
  175.       for(int j=chXstart; j<=chXend; j++) {
  176.       int canvasPosition = nX*(i-chYstart)+(j-chXstart)+1;
  177.       printf("canvas %d\n",canvasPosition);
  178.         canvas7->cd(canvasPosition);
  179.         char hname[128];
  180.         int chPosition = map[j][i];
  181.         sprintf(hname, "h2d%d", chPosition);
  182.         TH2F* h_2d = (TH2F*)rootfile->Get(hname);
  183.         h_2d->Draw("colz");
  184.       } //x
  185.     }
  186.   /*  
  187.     TCanvas* canvas8 = new TCanvas("canvas8","canvas8", 1000,1000);
  188.       char hname[128];
  189.       int chPosition = map[0][7];
  190.       sprintf(hname, "h2d%d", chPosition);
  191.       TH2F* h_2d1 = (TH2F*)rootfile->Get(hname);
  192.       chPosition = map[0][8];
  193.       sprintf(hname, "h2d%d", chPosition);
  194.       TH2F* h_2d2 = (TH2F*)rootfile->Get(hname);
  195.       h_2d1->SetOption("colz");
  196.       h_2d1->Draw();
  197.       h_2d2->SetOption("colz");
  198.       h_2d2->Draw("same");*/
  199.   }
  200.  
  201.   if( strstr(plopt, "sum") != NULL ) {
  202.     int nX = chXend - chXstart + 1;
  203.     int nY = chYend - chYstart + 1;
  204.           TCanvas* canvas12 = new TCanvas("canvas12","c2",1000,1000);
  205.           gStyle->SetOptStat(11);
  206.           //c2->Divide(1,4);
  207.           //TVirtualPad *pad=c2->cd();
  208.           //pad->SetLogz();
  209.           TH2F* h[64];
  210.           for(int i=chYstart; i<=chYend; i++) {
  211.       for(int j=chXstart; j<=chXend; j++) {
  212.       int chPosition = map[j][i];
  213.       char hname[128];
  214.             sprintf(hname, "h2d%d", chPosition);  
  215.             int histogram = nX*(i-chYstart)+(j-chXstart);
  216.             h[histogram] = (TH2F *) rootfile->Get(hname);
  217.             if (histogram) h[0]->Add(h[histogram]);
  218.     }
  219.     }
  220.     h[0]->Draw("COLZ");
  221.   }
  222.  
  223.   if (strstr(plopt, "beam") != NULL) {
  224.  
  225.   TCanvas* canvas9 = new TCanvas("canvas9","canvas9", 500,500);
  226.   char hname[128];
  227.   sprintf(hname, "hnhitsx%d", 36);
  228.   TH1F* h_laser = (TH1F*)rootfile->Get(hname);
  229.   h_laser->Draw();
  230.   h_laser->SetStats(1);
  231.  
  232.   TF1* err = new TF1("err","[0]+[1]*TMath::Erf((x-[2])/[3])");
  233.   err->SetParameters(0,h_laser->GetMaximum(),17.04,0.0001);
  234.   h_laser->Fit(err,"l");
  235.   }
  236.    
  237.   return(0);
  238. }
  239.