OnMonAnaHistos.C
Go to the documentation of this file.
1 #include <TFile.h>
2 #include <TTree.h>
3 #include <TChain.h>
4 #include <TMarker.h>
5 #include <TCanvas.h>
6 #include <TNtuple.h>
7 #include <TLegend.h>
8 #include <TH1.h>
9 #include <TH2.h>
10 #include <TH1F.h>
11 #include <TH2F.h>
12 #include <TGraph.h>
13 #include <TH1D.h>
14 #include <TProfile.h>
15 #include <TColor.h>
16 #include <TMultiGraph.h>
17 #include "TStyle.h"
18 
19 #include <algorithm>
20 #include <iostream>
21 #include <iomanip>
22 #include <vector>
23 #include <fstream>
24 #include <sstream>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <time.h>
28 #include <string>
29 
30 #include "RateSummaryNt.h"
31 
32 // before running on root do gSystem->Load("libOnlineMonitoringAna.so");
33 
34 //void rates_by_run()
35 void OnMonAnaHistos(int idet, const std::string& infile)
36 {
37 
38  // int runlo=10230;
39  // int runhi=10579;
40 
41  int runlo, runhi;
42 
43  int colors[33];
44  colors[0]=632;//red
45  colors[1]=920+2;//gray
46  colors[2]=632-7;//red
47  colors[3]=900+5;//pink
48  colors[4]=400-6;//yellow
49  colors[5]=616;//mgnt
50  colors[6]=616+2;//mgnt
51  colors[7]=616-6;//mgnt
52  colors[8]=800+10;//orange
53  colors[9]=880-7;//violet
54  colors[10]=600;//blue
55  colors[11]=600+2;//blue
56  colors[12]=600-3;//blue
57  colors[13]=600+3;//blue
58  colors[14]=600-6;//blue
59  colors[15]=860+7;//azure
60  colors[16]=432+1;//cyan
61  colors[17]=880-5;//violet
62  colors[18]=432-6;//cyan
63  colors[19]=416;//green
64  colors[20]=416+3;//green
65  colors[21]=416-6;//green
66  colors[22]=416+2;//green
67  colors[23]=820-5;//spring
68  colors[24]=820-7;//spring
69  colors[25]=820+4;//spring
70  colors[26]=400+2;//yellow
71  colors[27]=400+3;//yellow
72  colors[28]=800+7;//orange
73  colors[29]=632+2;//red
74  colors[30]=860+7;//azure
75  colors[31]=900+6;//pink
76  colors[32]=800+4;//orange
77 
78  const Int_t NRGBs = 3;
79  const Int_t NCont = 255;
80  Double_t stops[NRGBs] = { 0.00, 0.34, 1.00};
81  Double_t red[NRGBs] = { 1.00, 1.00, 0.60};
82  Double_t green[NRGBs] = { 0.97, 0.40, 0.00};
83  Double_t blue[NRGBs] = { 0.99, 0.70, 0.00};
84 
85  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
86  gStyle->SetNumberContours(NCont);
87 
88  //...............
89  // TChain ch("OnMonSummary");
90  // for(int i=runlo; i<runhi+1; i++ ){
91  // char anafilename[200];
92  // sprintf(anafilename, "/nova/ana/users/psihas/OnMonSummary/Summary-onmon_ana-subrun-%.5u-*.root", i);
93  // ch.Add(anafilename);
94  // std::cout<<" Chained ana file: "<<anafilename<<std::endl;
95  // }
96 
97 
98  // std::cout<<" Reading file: "<<infile<<std::endl;
99 
100  int DB_size1;
101  int DCM_size1;
102  int MapXbin;
103  int MapXmin;
104  int MapXmax;
105  int MapXsize;
106  int MapYbin;
107  int MapYmin;
108  int MapYmax;
109  int MapYdiv;
110  double MapLblS;
111  double MapYoff;
112  string detname;
113 
114  if(idet==1){
115  cout << " far det " << endl;
116  detname="FarDet";
117  DB_size1 = 16;
118  DCM_size1 = 13;
119  MapXbin = 224;
120  MapXmin = 0;
121  MapXmax = 896;
122  MapXsize = 500;
123  MapYbin = 48;
124  MapYmin = 0;
125  MapYmax = 384;
126  MapYdiv = 20;
127  MapYoff = 1;
128  MapLblS = 0.035;
129  }
130  else if(idet==2){
131  cout << " near det " << endl;
132  detname="NearDet";
133  DB_size1 = 5;
134  DCM_size1 = 5;
135  MapXbin = 64;
136  MapXmin = 0;
137  MapXmax = 256;
138  MapXsize = 300;
139  MapYbin = 16;
140  MapYmin = 0;
141  MapYmax = 128;
142  MapYdiv = 4;
143  MapYoff = 0.5;
144  MapLblS = 0.055;
145  }
146  else if(idet==5){
147  cout << " test beam " << endl;
148  detname="TestBeam";
149  DB_size1 = 2;
150  DCM_size1 = 4;
151  MapXbin = 16;
152  MapXmin = 0;
153  MapXmax = 46;
154  MapXsize = 300;
155  MapYbin = 12;
156  MapYmin = 0;
157  MapYmax = 96;
158  MapYdiv = 4;
159  MapYoff = 0.5;
160  MapLblS = 0.055;
161  }
162 
163  // std::ifstream in;
164  // in.open(infile);
165  //in.open("NearDetAnaFilesForNoiseHist.txt");
166 
167 
168  std::ifstream in;
169  in.open(infile.c_str());
170 
171  std::cout<<" Reading file: "<<infile<<std::endl;
172 
173  std::vector<std::string> newfiles;
174  string line;
175  while(in.good()) {
176  in >> line;
177  newfiles.push_back(line);
178  }
179 
180  TChain ch("OnMonSummary");
181  for(unsigned int i=0; i<newfiles.size()-1; i++){ //MakeHWwatchlist.sh leaves an extra space in file
182  ch.Add(&newfiles[i][0]);
183  std::cout<<"Chaining file: "<<&newfiles[i][0]<<std::endl;
184  }
185 
186  std::cout<<" Done Chaining "<<std::endl;
187  //...............
189  ch.SetBranchAddress("fRateSummaryNt", &Nt);
190 
191  static const unsigned int DB_size = 16;
192  static const unsigned int DCM_size = 13;
193  static const unsigned int FEB_size = 64;
194  static const unsigned int PIX_size = 33;
195  TH2D* HighRatesDCMs[DB_size];
196  TH2D* AllTheDCMs[DB_size];
197  TH2D* HighRatesFEBs[DB_size][DCM_size];
198  TH2D* AllTheFEBs[DB_size][DCM_size];
199 
200  std::cout << "Initializing histos... " << std::endl;
201  for(unsigned int i = 0; i < DB_size; ++i) {
202  HighRatesDCMs[i] = 0;
203  AllTheDCMs[i] = 0;
204  for(unsigned int j = 0; j < DCM_size; ++j) {
205  HighRatesFEBs[i][j] = 0;
206  AllTheFEBs[i][j] = 0;
207  }
208  }
209 
210  int n_entries = ch.GetEntries();
211  std::cout << "Got " << n_entries << std::endl;
212 
213  // Get run range if none is given
214  if(runlo==0 && runhi==0){
215  ch.GetEntry(0);
216  runlo=Nt->run;
217  ch.GetEntry(n_entries-1);
218  runhi=Nt->run;
219  }
220  runhi++;
221  std::cout << "RUNS " << runlo <<" - "<< runhi << std::endl;
222 
223 
224  int runsperbin = 10;
225  int runbins = (runhi-runlo)/runsperbin;
226  int runhitbins = (runhi-runlo)*64;
227 
228  TH1D* AllRates = new TH1D("AllPixelHitRates",
229  "Rate in all Pixels;log10(rate (Hz));pixels*subrun", 70, -1, 6);
230  TH1D* AllRatesHi = new TH1D("AllPixelHitRatesHi",
231  "High ADC Rate in all Pixels;log10(rate (Hz));pixels*subrun", 70, -1, 6);
232  TH1D* AllRatesLo = new TH1D("AllPixelHitRatesLo",
233  "Low ADC Rate in all Pixels;log10(rate (Hz));pixels*subrun", 70, -1, 6);
234  TH1D* AllDropouts = new TH1D("AllDropouts",
235  "Dropout Count per FEB;Count;FEBs*subrun", 500, 0, 500);
236  TH1D* AllDropouts13 = new TH1D("AllDropouts13",
237  "Dropout Count per FEB in DB01-03;Count;FEBs*subrun", 500, 0, 500);
238  TH2D* RatesPerRun = new TH2D("RatesPerRun",
239  "Rate in all Pixels per run;run;log10(rate (Hz))",runbins, runlo, runhi, 70,-1,7);
240 
241  int pastrun=0;
242  // Fill Pixel and FEB level graphs with rates
243  for (unsigned int i = 0; i < n_entries; ++i)
244  {
245  ch.GetEntry(i);
246  if(Nt->run!= pastrun && Nt->run % 5 == 0){
247  std::cout << "RUN: " << Nt->run << std::endl;
248  pastrun=Nt->run;
249  }
250  double RUN = (double)(Nt->run)+((double)(Nt->subrun)/64.0);
251  if(Nt->rate > 0){
252  double lograte = log10(Nt->rate);
253  AllRates->Fill(lograte);
254  RatesPerRun->Fill(RUN,lograte);
255  }
256  if(Nt->rateLow > 0){
257  double logratelo = log10(Nt->rateLow);
258  AllRatesLo->Fill(logratelo);
259  }
260  if(Nt->rateHigh > 0){
261  double logratehi = log10(Nt->rateHigh);
262  AllRatesHi->Fill(logratehi);
263  }
264  if(Nt->dropoutCount > 0){
265  double dropoutFEB = Nt->dropoutCount;
266  AllDropouts->Fill(dropoutFEB);
267  if (Nt->db < 4) AllDropouts13->Fill(dropoutFEB);
268  }
269  if(AllTheDCMs[Nt->db] == 0){
270  char ratehistoname[50];
271  sprintf(ratehistoname, "AllTheDCMs_%.2u", Nt->db);
272  char ratehistotitle[100];
273  sprintf(ratehistotitle, "All rates on DCMs for DB%.2u;run;DCM", Nt->db);
274  // AllTheDCMs[Nt->db] = new TH2D(ratehistoname, ratehistotitle, runbins, runlo, runhi, 12, 1, 13);
275  AllTheDCMs[Nt->db] = new TH2D(ratehistoname, ratehistotitle, runbins, runlo, runhi, 4, 1, 5);
276  }
277  if(AllTheFEBs[Nt->db][Nt->dcm] == 0){
278  char ratehistoname[50];
279  sprintf(ratehistoname, "AllTheFEBs_%.2u_%.2u", Nt->db, Nt->dcm);
280  char ratehistotitle[100];
281  sprintf(ratehistotitle, "All rates on FEBs for DB%.2u DCM%.2u;run;FEB", Nt->db, Nt->dcm);
282  AllTheFEBs[Nt->db][Nt->dcm] = new TH2D(ratehistoname, ratehistotitle, runbins, runlo, runhi, 64, 0, 64);
283  }
284  AllTheDCMs[Nt->db]->Fill(RUN,Nt->dcm);
285  AllTheFEBs[Nt->db][Nt->dcm]->Fill(RUN,Nt->feb);
286  if(Nt->rate > 500){
287  if(HighRatesFEBs[Nt->db][Nt->dcm] == 0){
288  char hratehistoname[50];
289  sprintf(hratehistoname, "HighRateFEB_%.2u_%.2u", Nt->db, Nt->dcm);
290  char ratehistotitle[100];
291  sprintf(ratehistotitle, "Fraction of noise incidents (DB%.2u DCM%.2u);run;FEB", Nt->db, Nt->dcm);
292  HighRatesFEBs[Nt->db][Nt->dcm] = new TH2D(hratehistoname, ratehistotitle, runbins, runlo, runhi, 64, 0, 64);
293  }
294  if(HighRatesDCMs[Nt->db] == 0){
295  char hratehistoname[50];
296  sprintf(hratehistoname, "HighRateDCM_%.2u", Nt->db);
297  char ratehistotitle[100];
298  sprintf(ratehistotitle, "Fraction of noise incidents (DB%.2u);run;DCM", Nt->db);
299  // HighRatesDCMs[Nt->db] = new TH2D(hratehistoname, ratehistotitle, runbins, runlo, runhi, 12, 1, 13);
300  HighRatesDCMs[Nt->db] = new TH2D(hratehistoname, ratehistotitle, runbins, runlo, runhi, 4, 1, 5);
301  }
302  HighRatesDCMs[Nt->db]->Fill(RUN,Nt->dcm);
303  HighRatesFEBs[Nt->db][Nt->dcm]->Fill(RUN,Nt->feb);
304  }
305  }
306 
307  // Open output file for this subrun
308  char outfilename[100];
309  sprintf(outfilename, "Onmon_ana-Histos-run%.2u-%.2u.root", runlo, runhi-1);
310  TFile* out_file = new TFile(outfilename, "RECREATE");
311  out_file->mkdir("DCMPlots");
312  std::cout << "Writting " << outfilename << std::endl;
313 
314  AllRates->Write();
315  AllRatesLo->Write();
316  AllRatesHi->Write();
317  AllDropouts->Write();
318  AllDropouts13->Write();
319 
320  RatesPerRun->Write();
321 
322  for(unsigned int i = 1; i < DB_size; ++i) {
323  if( AllTheDCMs[i] !=0 && HighRatesDCMs[i] !=0) {
324  HighRatesDCMs[i]->Divide(AllTheDCMs[i]);
325  AllTheDCMs[i]->GetYaxis()->SetNdivisions(MapYdiv);
326  HighRatesDCMs[i]->GetYaxis()->SetNdivisions(MapYdiv);
327  HighRatesDCMs[i]->GetYaxis()->SetLabelSize(MapLblS);
328  HighRatesDCMs[i]->GetXaxis()->SetLabelSize(MapLblS);
329  HighRatesDCMs[i]->GetXaxis()->SetTitleSize(MapLblS);
330  HighRatesDCMs[i]->GetYaxis()->SetTitleSize(MapLblS);
331  HighRatesDCMs[i]->GetYaxis()->SetTitleOffset(MapYoff);
332  HighRatesDCMs[i]->Write();
333  }
334  }
335 
336  out_file->cd("DCMPlots");
337  for(unsigned int i = 1; i < DB_size; ++i) {
338  for(unsigned int j = 1; j < DCM_size; ++j) {
339  if( AllTheFEBs[i][j] !=0 && HighRatesFEBs[i][j]) {
340  HighRatesFEBs[i][j]->Divide(AllTheFEBs[i][j]);
341  AllTheFEBs[i][j]->GetYaxis()->SetNdivisions(64);
342  AllTheFEBs[i][j]->GetYaxis()->SetLabelSize(0.015);
343  HighRatesFEBs[i][j]->GetYaxis()->SetNdivisions(64);
344  HighRatesFEBs[i][j]->GetYaxis()->SetLabelSize(0.015);
345  HighRatesFEBs[i][j]->GetXaxis()->SetLabelSize(0.025);
346  HighRatesFEBs[i][j]->Write();
347  }
348  }
349  }
350 
351  out_file->Close();
352 
353 
354  for(unsigned int i = 1; i < DB_size; ++i) {
355  TCanvas* cPerDB = new TCanvas("perDB","perDB",800,310);
356  if( AllTheDCMs[i] !=0 && HighRatesDCMs[i] !=0) {
357  //HighRatesDCMs[i]->Divide(AllTheDCMs[i]);
358  AllTheDCMs[i]->GetYaxis()->SetNdivisions(MapYdiv);
359  HighRatesDCMs[i]->GetYaxis()->SetNdivisions(MapYdiv);
360  HighRatesDCMs[i]->Draw("colz");
361  HighRatesDCMs[i]->SetStats(0);
362  cPerDB->SetGridy();
363  char plottitle[50];
364  sprintf(plottitle, "PinkPlots/DCMsNoiseHistoryDB%.2u_%.2u-%.2u.png",i,runlo,runhi);
365  // sprintf(plottitle, "%sHWstatusDB%.2u.png",detname.c_str(), i);
366  cPerDB->Print(plottitle, "png");
367  }
368  }
369 
370  for(unsigned int i = 1; i < DB_size; ++i) {
371  for(unsigned int j = 1; j < DCM_size; ++j) {
372  TCanvas* cPerDCM = new TCanvas("perDCM","perDCM",800,600);
373  if( AllTheFEBs[i][j] !=0 && HighRatesFEBs[i][j]) {
374  // HighRatesFEBs[i][j]->Divide(AllTheFEBs[i][j]);
375  AllTheFEBs[i][j]->GetYaxis()->SetNdivisions(64);
376  AllTheFEBs[i][j]->GetYaxis()->SetLabelSize(0.015);
377  HighRatesFEBs[i][j]->GetYaxis()->SetNdivisions(64);
378  HighRatesFEBs[i][j]->GetYaxis()->SetLabelSize(0.015);
379  HighRatesFEBs[i][j]->GetXaxis()->SetLabelSize(0.025);
380  HighRatesFEBs[i][j]->Draw("colz");
381  HighRatesFEBs[i][j]->SetStats(0);
382  cPerDCM->SetGridy();
383  char plottitle[50];
384  sprintf(plottitle, "PinkPlots/APDsNoiseHistoryDB%.2uDCM%.2u_%.2u-%.2u.png",i,j,runlo,runhi);
385  // sprintf(plottitle, "%sHWstatusDB%.2u.png",detname.c_str(), i);
386  cPerDCM->Print(plottitle, "png");
387  }
388  }
389  }
390 
391 
392  //Show some examples of the 2D histos
393  TCanvas* cAllRates = new TCanvas("AllRates","AllRates",800,500);
394  AllRates->Draw();
395 
396  TCanvas* cAllDrops = new TCanvas("AllDrops","AllDrops",800,500);
397  AllDropouts->SetLineColor(kPink+6);
398  AllDropouts->SetFillColor(kPink+6);
399  AllDropouts->Draw();
400  AllDropouts13->SetLineColor(kBlue+1);
401  AllDropouts13->SetFillColor(kBlue);
402  AllDropouts13->Draw("same");
403  TLegend *legend = new TLegend(0.6,0.6,0.85,0.85);
404  legend->AddEntry(AllDropouts,"All DB","l");
405  legend->AddEntry(AllDropouts13,"DB 01-03","l");
406  legend->SetFillStyle(4000);
407  legend->SetLineColor(0);
408  legend->SetFillColor(0);
409  legend->Draw();
410  cAllDrops->SetLogy();
411  cAllDrops->SetLogx();
412  AllDropouts->SetStats(0);
413  AllDropouts13->SetStats(0);
414 
415 
416  TCanvas* cRatePerRun = new TCanvas("RatePerRun","RatePerRun",800,500);
417  RatesPerRun->Draw("colz");
418 
419  TCanvas* cAllDCMsDB1 = new TCanvas("AllDCMsDB1","AllDCMsDB1",1000,500);
420  cAllDCMsDB1->Divide(2);
421  cAllDCMsDB1->cd(1);
422  AllTheFEBs[1][2]->Draw("colz");
423  AllTheFEBs[1][2]->SetStats(0);
424  cAllDCMsDB1->cd(2);
425  HighRatesFEBs[1][2]->Draw("colz");
426  HighRatesFEBs[1][2]->SetStats(0);
427 
428  TCanvas* cHighRatesDCMsDB1Ratio = new TCanvas("HighRatesDCMsDB1Ratio","HighRatesDCMsDB1Ratio",800,330);
429  HighRatesDCMs[1]->Draw("colz");
430  HighRatesDCMs[1]->SetStats(0);
431  cHighRatesDCMsDB1Ratio->SetGridy();
432 
433  TCanvas* cHighRatesFEBDCM1DB1Ratio = new TCanvas("HighRatesFEBDCM1DB1Ratio","HighRatesFEBDCM1DB1Ratio",800,600);
434  HighRatesFEBs[1][2]->Draw("colz");
435  HighRatesFEBs[1][2]->SetStats(0);
436  cHighRatesFEBDCM1DB1Ratio->SetGridy();
437 
438 
439 }
440 
void OnMonAnaHistos(int idet, const std::string &infile)
string outfilename
knobs that need extra care
out_file
Append EOF lines.
Definition: modifyFHiCL.py:113
int colors[6]
Definition: tools.h:1
string infile
tuple blue
Definition: rootlogon.py:65
int NRGBs
Definition: rootlogon.py:77
int NCont
Definition: rootlogon.py:78
const double j
Definition: BetheBloch.cxx:29
OStream cout
Definition: OStream.cxx:6
ifstream in
Definition: comparison.C:7
T log10(T number)
Definition: d0nt_math.hpp:120
enum BeamMode kBlue
enum BeamMode string