stats.C
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <sstream>
4 #include <string>
5 
6 #include "TH1F.h"
7 #include "TH2F.h"
8 #include "TCanvas.h"
9 #include "TPad.h"
10 #include "TStyle.h"
11 
12 //int stats(std::string inputFilePath, int firstRun, int lastRun, Float_t thresh){
13 int stats(TString inputFilePath, Int_t firstRun, Int_t lastRun, Float_t thresh, TString myDet){
14 
15  //std::string myfile = inputFilePath+"/bad_chan_stats.txt";
16  //TString myfile = inputFilePath+"/bad_chan_stats.txt";
17  //std::cout<<"my file: "<< myfile <<std::endl;
18  //std::cout<<std::endl;
19 
20  // Open and load file
21  std::ifstream openfile;
22  // NOTE: PATH TO TXT FILE WOULD BE A PARAMETER!!
23  //openfile.open("bad_chan_stats.txt"); // original
24  //openfile.open(myfile.c_str()); //It works with string
25  openfile.open(inputFilePath+"/bad_chan_stats.txt");
26 
27  if ( !(openfile.is_open()) ){
29  std::cout << " === Unable to open bad_chan_stats.txt file ===" << std::endl;
31  }
32  //else{
33  // std::cout<<"SUCCESS!! "<<std::endl;
34  //}
35 
36  TH1F *hmismatch_distro = new TH1F("mismatch_distro",
37  myDet+" Distribution of Mismatches;Mismatch(%);frequency",
38  101,-0.2,100.8);
39  //28,-0.2,1.2);
40 
41  TH1F *hfracdb_distro = new TH1F("fracdb_distro",
42  myDet+" Fraction channels DB sees good, OnMon sees bad;FracDB(%);frequency",
43  101,-0.2,100.8);
44  //28,-0.2,1.2);
45 
46  TH1F *hfracom_distro = new TH1F("fracom_distro",
47  myDet+" Fraction of Channels OnMon sees good, DB sees bad;FracOM(%);frequency",
48  101,-0.2,100.8);
49  //28,-0.2,1.8);
50 
51  // For binning purposes
52  int nBins = (lastRun-firstRun)+3;
53  int lowR = firstRun-1;
54  int highR = lastRun+2;
55 
56  TH2F *hmismatchVsRun = new TH2F("mismatchVsRun",
57  myDet+" Mismatch vs Run number; Run; Mismatch (%)",
58  //70,10930,11000,100,0.0,100.0);
59  //275,22901,23176,100,0.0,100.0); // NOTE: NUMBER OF BINS AND START/END RUN WOULD BE A PARAMETER!!
60  //3,23977,23979,100,0.0,100.0);
61  nBins,lowR,highR,100,0.0,100.0);
62 
63  std::string Line;
64  int counter = 0;
65  int counterTotal = 0;
66 
68  while (getline(openfile,Line)){
69 
70  std::istringstream is(Line);
71  float run;
72  //float srun;
73  string srun;
74  float mismatch;
75  float fracdb;
76  float fracom;
77 
78  // Reads each column separately from the file
79  is >> run >> srun >> mismatch >> fracdb >> fracom;
80  counterTotal += 1;
81 
82  hmismatch_distro->Fill(mismatch);
83  hfracdb_distro->Fill(fracdb);
84  hfracom_distro->Fill(fracom);
85  hmismatchVsRun->Fill(run,mismatch);
86 
87  //if( (mismatch == 0.0) ){
88  //if( (mismatch > 0.000) && (mismatch <= 0.2)){
89  //if( (mismatch > 0.4) && (mismatch <= 1.0)){
90  //if( (mismatch > 1.0) && (mismatch <= 20.0)){
91  //if( (mismatch > 20.0) && (mismatch <= 30.0)){
92 
93  // NOTE: WARKING MESSAGE WOULD BE A PARAMETER!! (?)
94  if( (mismatch > thresh) ){
95  std::cout<< run <<", "<< srun <<", "<< mismatch
96  <<", "<< fracdb <<", "<< fracom <<std::endl;
97  counter += 1;
98  }
99  } // end while
101 
102  // TO DO: IMPLEMENT THIS
103  // ls -l badchan/*.root | wc -l output
104  //const int Nproc = 2795; // No. files processed
105  /*
106  // The number of files processed comes from % ls -l badchan_temp/*root | wc -l
107  std::cout<<"Counter for current condition: "<< counter
108  <<" (out of "<<counterTotal<<" in txt file, "<<Nproc <<" processed) as percentage: "
109  <<(float)counter*100/Nproc<<" % from proceesed ("<< Nproc <<")"<<std::endl;
110  */
111 
112  TCanvas *c1 = new TCanvas("c1","c1",880,590);
113  hmismatch_distro->SetLineColor(kBlue);
114  hmismatch_distro->SetLineWidth(2);
115  hmismatch_distro->SetStats(kTRUE);
116  gPad->SetLogy();
117  hmismatch_distro->Draw();
118  c1->SaveAs("mismatch_distro_"+myDet+".C");
119  //c1->SaveAs("mismatch_distro.png");
120  c1->SaveAs("/nusoft/app/web/htdoc/nova/users/novadq/BadChanValidationPlots/mismatch_distro_"+myDet+".png");
121 
122  //---
123  /*
124  // Draw an arrow on the canvas
125  TArrow arrow2(0.16,90.0,0.35,90.0,0.02,"----|>");
126  arrow2.SetLineWidth(3);
127  arrow2.SetLineColor(kRed);
128  arrow2.SetFillColor(kRed);
129  arrow2.DrawClone();
130 
131  // Draw a line on the canvas
132  //TLine line(0.16,0.0,0.16,350.0);
133  TLine line(0.16,0.0,0.16,1450.0);
134  line.SetLineWidth(3);
135  line.SetLineColor(kRed);
136  line.DrawClone();
137 
138  // Add some text to the plot
139  TLatex text(0.2,120.0,"Cut: 0.16");
140  text.SetTextColor(kRed);
141  text.DrawClone();
142  */
143  //--
144 
145 
146  TCanvas *c2 = new TCanvas("c2","c2",880,590);
147  hfracdb_distro->SetLineColor(kBlue);
148  hfracdb_distro->SetLineWidth(2);
149  hfracdb_distro->SetStats(kTRUE);
150  gPad->SetLogy();
151  hfracdb_distro->Draw();
152  c2->SaveAs("fracdb_distro_"+myDet+".C");
153  //c2->SaveAs("fracdb_distro.png");
154  c2->SaveAs("/nusoft/app/web/htdoc/nova/users/novadq/BadChanValidationPlots/fracdb_distro_"+myDet+".png");
155 
156  TCanvas *c3 = new TCanvas("c3","c3",880,590);
157  hfracom_distro->SetLineColor(kBlue);
158  hfracom_distro->SetLineWidth(2);
159  hfracom_distro->SetStats(kTRUE);
160  gPad->SetLogy();
161  hfracom_distro->Draw();
162  c3->SaveAs("fracom_distro_"+myDet+".C");
163  //c3->SaveAs("fracom_distro.png");
164  c3->SaveAs("/nusoft/app/web/htdoc/nova/users/novadq/BadChanValidationPlots/fracom_distro_"+myDet+".png");
165 
166  // Set colors
167  const Int_t NRGBs2 = 3;
168  const Int_t NCont2 = 255;
169  Double_t stops2[NRGBs2] = { 0.00, 0.3, 1.00};
170  Double_t red2[NRGBs2] = { 0.85, 0.25, 0.00};
171  Double_t green2[NRGBs2] = { 0.96, 0.61, 0.00};
172  Double_t blue2[NRGBs2] = { 1.00, 0.98, 0.59};
173  TColor::CreateGradientColorTable(NRGBs2, stops2, red2, green2, blue2, NCont2);
174  gStyle->SetNumberContours(NCont2);
175 
176  TCanvas *c4 = new TCanvas("c4","c4",880,590);
177  hmismatchVsRun->SetStats(kTRUE);
178  hmismatchVsRun->Draw("colz");
179  c4->SaveAs("mismatchVsRun_"+myDet+".C");
180  //c4->SaveAs("mismatchVsRun.png");
181  c4->SaveAs("/nusoft/app/web/htdoc/nova/users/novadq/BadChanValidationPlots/mismatchVsRun_"+myDet+".png");
182 
183  return 0;
184 }
int nBins
Definition: plotROC.py:16
int stats(TString inputFilePath, Int_t firstRun, Int_t lastRun, Float_t thresh, TString myDet)
Definition: stats.C:13
c2
Definition: demo5.py:33
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
c1
Definition: demo5.py:24