StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bsQaShowAdc.C
1 #include "TCanvas.h"
2 #include "TF1.h"
3 #include "TFile.h"
4 #include "TGaxis.h"
5 #include "TGraph.h"
6 #include "TGraphErrors.h"
7 #include "TH1.h"
8 #include "TH2.h"
9 #include "TMath.h"
10 #include "TLegend.h"
11 #include "TLine.h"
12 #include "TPaveText.h"
13 #include "TROOT.h"
14 #include "TString.h"
15 #include "TSystem.h"
16 #include "TStyle.h"
17 
18 #include <cmath>
19 #include <fstream>
20 #include <iostream>
21 #include <map>
22 using namespace std;
23 
24 //Shows ADC distribution of a channel
25 //===================================================================
26 void bsQaShowAdc(string inFile, int detId, int ch, bool PRINT = true)
27 {
28  gROOT->Reset();
29 
30  TFile *F = TFile::Open(inFile.c_str());
31  if (!F || F->IsZombie()) { cout <<"Cannot open the file: " <<inFile <<endl; return; }
32 
33  //Get run number
34  std::size_t strPos = inFile.find(".root");
35  string runNoStr = inFile.substr(strPos-8, 8);
36  const int runNo = std::atoi(runNoStr.c_str());
37 
38  TH2F* H2 = (TH2F*)F->Get(Form("Adc_d%i", detId));
39  if (!H2) { cout <<"Cannot open the histogram!" <<endl; return; }
40 
41  TH1F* H1 = (TH1F*)H2->ProjectionY("", ch, ch);
42  H1->SetTitle(Form("d%i_ch%i_run%i", detId, ch, runNo));
43 
44  int xMax = 1;
45  for (int x=0; x<H1->GetNbinsX(); x++) { if (H1->GetBinContent(x+1) != 0) xMax = x+1; }
46  H1->GetXaxis()->SetRangeUser(0, xMax + 10);
47  H1->GetXaxis()->SetLabelSize(0.05);
48  H1->GetXaxis()->SetTitleOffset(1.25);
49  H1->GetYaxis()->SetLabelSize(0.05);
50 
51  gStyle->SetOptDate(0);
52  gStyle->SetOptStat("emr");
53  TCanvas *c1 = new TCanvas("c1", H1->GetTitle(), 800*1.5, 600*1.5);
54  c1->Divide(1, 2);
55  c1->cd(1)->SetLogy();
56  H1->DrawCopy("hist e");
57  c1->cd(2);
58  H1->GetXaxis()->SetRangeUser(0, 32);
59  H1->DrawCopy("hist e");
60 
61  if (PRINT) c1->Print(Form("%s.png", c1->GetTitle()));
62  return;
63 }//Main