PlotOnMon.C
Go to the documentation of this file.
1 
2 #include "/nova/app/users/jcoelho/SetupHistos.C"
3 
5 
6 #include "TSystem.h"
7 #include "TFile.h"
8 #include "TH2F.h"
9 #include "TString.h"
10 #include "TCanvas.h"
11 #include "TColor.h"
12 #include "TMath.h"
13 
14 double GetX(int ndb=14, int db=1, int feb=0, int pix=0);
15 double GetY(int dcm=1, int feb=0, int pix=0);
16 
17 TH2F* GetHist(TString omFileName, int htype = 0);
18 
19 float GetMedian(vector<float> scores);
20 
21 void PlotOnMon(int run = 13260, int subrun = 0, int ptype = 1){
22 
23  TString omDir = "/nova/data/nearline-OnMon/FarDet/";
24  TString omRel[5] = {"S15-02-05","FA14-09-23","S14-08-01","S14-02-05","S13-09-17"};
25  TString omForm[5] = {TString::Format("/%06d/%08d/t02-t00/fardet_nearline_r%08d_s%03d.onmon.root",int(run)/100,run,run,subrun),
26  TString::Format("/%06d/%08d/t02-t00/fardet_nearline_r%08d_s%03d.onmon.root",int(run)/100,run,run,subrun),
27  TString::Format("/%06d/%08d/fardet_nearline_r%08d_s%03d.onmon.root",int(run)/100,run,run,subrun),
28  TString::Format("/%06d/%08d/fardet_nearline_r%08d_s%03d.onmon.root",int(run)/100,run,run,subrun),
29  TString::Format("/%06d/%08d/FDNL-onmon-endsubrun-%08d-%03d.root",int(run)/100,run,run,subrun)};
30 
31  bool gotfile = false;
32  int ntries = 0;
33 
34  TString omFileName;
35 
36  while(!gotfile && ntries < 5){
37 
38  omFileName = omDir + omRel[ntries] + omForm[ntries];
39 
40  if(!gSystem->AccessPathName(omFileName)){
41  gotfile = true;
42  }
43 
44  ntries++;
45 
46  }
47 
48  if(!gotfile){
49  cout << "No file " + omFileName << endl;
50  return;
51  }
52 
53  cout << "Found file " + omFileName << endl;
54 
55  TCanvas *c1 = MakeLongCanvas();
56 
57  c1->SetRightMargin(0.17);
58 
59  TH2F *hDraw = GetHist(omFileName, ptype);
60 
61  if(!hDraw){
62  cout << "Failed to get histogram" << endl;
63  return;
64  }
65 
66  om::HwDetLabel *hwdetlbl = new om::HwDetLabel();
67 
68  SetHist(hDraw);
69  hDraw->SetTitle(";;;");
70 
71  hDraw->GetZaxis()->SetRangeUser(1,3);
72  hDraw->GetZaxis()->SetNdivisions(3);
73 
74  hDraw->GetXaxis()->SetTickLength(0);
75  hDraw->GetXaxis()->SetLabelColor(0);
76  hDraw->GetYaxis()->SetTickLength(0);
77  hDraw->GetYaxis()->SetLabelColor(0);
78  hDraw->GetZaxis()->SetTickLength(0);
79  hDraw->GetZaxis()->SetLabelColor(0);
80 
81 
82  // Get moodier colours for colz
83  const Int_t NRGBs = 6;
84  const Int_t NCont = 255;
85  Double_t stops[NRGBs] = { 0.00, 0.33, 0.34, 0.66, 0.67, 1.00 };
86  Double_t red[NRGBs] = { 0.00, 0.00, 0.00, 0.00, 1.00, 1.00 };
87  Double_t green[NRGBs] = { 0.00, 0.00, 1.00, 1.00, 0.00, 0.00 };
88  Double_t blue[NRGBs] = { 1.00, 1.00, 0.00, 0.00, 0.00, 0.00 };
89  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
90  gStyle->SetNumberContours(NCont);
91 
92  hwdetlbl->Config(hDraw);
93  hDraw->Draw("colz");
94  hwdetlbl->Draw();
95 
96  TLatex *ltx;
97  ltx = MiscText(0.9,0.90,0.05,"Hot / Bad");
98  ltx->SetTextAngle(-90);
99  ltx = MiscText(0.9,0.58,0.05,"Good");
100  ltx->SetTextAngle(-90);
101  ltx = MiscText(0.9,0.30,0.05,"Cold");
102  ltx->SetTextAngle(-90);
103 
104  MiscText(0.12,0.08,0.025,omFileName.Data());
105 
106 }
107 
108 
109 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
110 
111 double GetX(int ndb, int db, int feb, int pix){
112 
113  double x = (ndb-db)*16*4 + (feb%16)*4 + pix%4 + 1;
114 
115  return x;
116 
117 }
118 
119 double GetY(int dcm, int feb, int pix){
120 
121  double y = (12-dcm)*4*8 + int(feb/16)*8 + int(pix/4) + 1;
122 
123  return y;
124 
125 }
126 
127 ///////////////////////////////////////////////////////////////////////////////////////////////////////////
128 
129 TH2F* GetHist(TString omFileName, int htype){
130 
131  if(gSystem->AccessPathName(omFileName)){
132  cout << "No file " + omFileName << endl;
133  return 0;
134  }
135 
136  //Cut Parameter Values
137  Double_t PixelsPerFEB = 26; //Minimum # of good pixels per FEB
138  Double_t FEBsPerDCM = 56; //Minimum # of good FEBs per DCM
139  Double_t DCMsPerDB = 12; //Minimum # of good DCMs per DiBlock
140  Double_t MaxTopSideAsym = 0.5; //Maximum Top/Side MIP hit rate Asymmetry
141  Double_t MinTopSideAsym = 0.1; //Minimum Top/Side MIP hit rate Asymmetry
142 
143  float lowpixmip[7] = {13, 5, 4, 4, 2, 2, 1.5};
144  float highpixmip[7] = {31, 45, 36, 30, 26, 23, 20.};
145 
146  float lowfebmip[7] = {400, 300, 200, 200, 100, 100, 100};
147  float highfebmip[7] = {1000, 1200, 1000, 850, 700, 600, 550};
148 
149  TFile omFile(omFileName,"read");
150 
151  double setlivetime;
152 
153  // Get live time
154  TH1F *RecordedTime = (TH1F*)omFile.Get("RecordedTime");
155 
156  if(RecordedTime) setlivetime = RecordedTime->Integral()*500e-9;
157  else{
158 
159  cout << omFileName + " has no valid RecordedTime histogram." << endl;
160 
161  delete RecordedTime;
162 
163  return 0;
164 
165  }
166 
167  delete RecordedTime;
168 
169  TH2F* hDraw = 0;
170 
171  if(htype==0) hDraw = (TH2F*)omFile.Get("PixelHitRateMap")->Clone("");
172  if(htype==1) hDraw = (TH2F*)omFile.Get("FEBHitRateMap")->Clone("");
173  if(htype==2) hDraw = (TH2F*)omFile.Get("DCMHitRateMap")->Clone("");
174 
175  hDraw->Reset();
176 
177  int ndb = hDraw->GetXaxis()->GetXmax() / 16 / 4;
178 
179  // Nested loops to determine good diblock cut
180  for(int db=1;db<=14;db++){
181 
182  int nGoodDCMMipInDB = 0;
183 
184  vector<float> pixMipHitsTop;
185  vector<float> pixMipHitsSide;
186 
187  for(int dcm=1;dcm<=12;dcm++){
188 
189  TH2F *PixelHitMapMip = (TH2F*)omFile.Get(TString::Format("MipADCPixelsDCM_%02d_%02d",db,dcm));
190  if(!PixelHitMapMip) continue;
191 
192  TH2F *PixelRate = (TH2F*)omFile.Get(TString::Format("PixelsRateDCM_%02d_%02d",db,dcm));
193  if(!PixelRate) continue;
194 
195  int nGoodFEBMipInDCM = 0;
196 
197  for(int feb=0;feb<64;feb++){
198 
199  int nGoodPixMipInFEB = 0;
200 
201  double febmiphits = 0;
202 
203  for(int pix=0;pix<32;pix++){
204 
205  int ix = (feb%16)*4 + pix%4 + 1;
206  int iy = int(feb/16)*8 + int(pix/4) + 1;
207 
208  if( PixelHitMapMip->GetBinContent(ix,iy)==0 ) continue;
209  // cout << ix << "," << iy << " - " << PixelHitMapMip->GetBinContent(ix,iy) << endl;
210 
211  double pixhitrate = PixelRate->GetBinContent(ix,iy);
212  double pixmiphits = PixelHitMapMip->GetBinContent(ix,iy);
213 
214  febmiphits += TMath::Min(pixmiphits, highpixmip[TMath::Max(dcm-6,0)] * setlivetime * 4);
215 
216  if(dcm<7) pixMipHitsTop.push_back(pixmiphits);
217  else pixMipHitsSide.push_back(pixmiphits);
218 
219  if(pixhitrate<pow(10,3.5) && pixhitrate>pow(10,0.5) &&
220  TMath::Gamma(lowpixmip[TMath::Max(dcm-6,0)] * setlivetime , pixmiphits) > 0.1 &&
221  TMath::Gamma(highpixmip[TMath::Max(dcm-6,0)] * setlivetime , pixmiphits) < 0.9 ){
222 
223  nGoodPixMipInFEB++;
224  if(htype==0) hDraw->Fill(GetX(ndb,db,feb,pix), GetY(dcm,feb,pix), 2);
225 
226  }
227  else if(pixhitrate<=pow(10,0.5) || TMath::Gamma(lowpixmip[TMath::Max(dcm-6,0)] * setlivetime , pixmiphits) <= 0.1){
228 
229  if(htype==0) hDraw->Fill(GetX(ndb,db,feb,pix), GetY(dcm,feb,pix), 1);
230 
231  }
232  else{
233 
234  if(htype==0) hDraw->Fill(GetX(ndb,db,feb,pix), GetY(dcm,feb,pix), 3);
235 
236  }
237 
238  }// Pixel loop
239 
240  if(nGoodPixMipInFEB >= PixelsPerFEB &&
241  TMath::Gamma(lowfebmip[TMath::Max(dcm-6,0)] * setlivetime , febmiphits) > 0.1 &&
242  TMath::Gamma(highfebmip[TMath::Max(dcm-6,0)] * setlivetime , febmiphits) < 0.9 ){
243 
244  nGoodFEBMipInDCM++;
245  if(htype==1) hDraw->Fill(GetX(ndb,db,feb), GetY(dcm,feb), 2);
246 
247  }
248  else if(TMath::Gamma(lowfebmip[TMath::Max(dcm-6,0)] * setlivetime , febmiphits) <= 0.1 &&
249  febmiphits > 0){
250 
251  if(htype==1) hDraw->Fill(GetX(ndb,db,feb), GetY(dcm,feb), 1);
252 
253  }
254  else if(febmiphits > 0){
255 
256  if(htype==1) hDraw->Fill(GetX(ndb,db,feb), GetY(dcm,feb), 3);
257 
258  }
259 // else cout << TString::Format("dcm-2-%02d-%02d FEB %02d: %d/32 good Pixels; %2.1f",db,dcm,feb,nGoodPixMipInFEB,febmiphits / setlivetime) << endl;
260 
261  }// FEB loop
262 
263  if(nGoodFEBMipInDCM >= FEBsPerDCM){
264 
265  nGoodDCMMipInDB++;
266  if(htype==2) hDraw->Fill(GetX(ndb,db), GetY(dcm), 2);
267 
268  }
269  else{
270 
271  cout << TString::Format("Bad DCM-2-%02d-%02d : %d bad FEBs", db, dcm, 64-nGoodFEBMipInDCM) << endl;
272 
273  if(htype==2) hDraw->Fill(GetX(ndb,db), GetY(dcm), 3);
274 
275  }
276  // else cout << TString::Format("dcm-2-%02d-%02d: %d/64 good FEBs",db,dcm,nGoodFEBInDCM) << endl;
277 
278  delete PixelRate;
279  delete PixelHitMapMip;
280 
281  }// DCM loop
282 
283  double medianTop = GetMedian(pixMipHitsTop);
284  double medianSide = GetMedian(pixMipHitsSide);
285 
286  if(medianTop + medianSide != 0) medianTop = (medianTop - medianSide) / (medianTop + medianSide);
287  else{
288  medianTop = -999;
289  }
290 
291 
292  if(medianTop >= MaxTopSideAsym ||
293  medianTop <= MinTopSideAsym ){
294 
295  //dbasym[db-1] = false;
296  if(medianTop > -999) cout << "DB " << db << " has bad Top/Side asymmetry: " << medianTop << endl;
297 
298  }
299 
300  }// DB loop
301 
302  omFile.Clear();
303  omFile.Close();
304 
305  return hDraw;
306 
307 }
308 
309 float GetMedian(vector<float> scores)
310 {
311  float median;
312  size_t size = scores.size();
313 
314  if(size==0) return 0;
315 
316  sort(scores.begin(), scores.end());
317 
318  if (size % 2 == 0)
319  {
320  median = (scores[size / 2 - 1] + scores[size / 2]) / 2;
321  }
322  else
323  {
324  median = scores[size / 2];
325  }
326 
327  return median;
328 }
329 
void SetHist(TH1 *hist, int col=1, bool fill=false)
Definition: SetupHistos.C:60
constexpr T pow(T x)
Definition: pow.h:75
TLatex * MiscText(float x, float y, float size, TString text)
float Gamma() const
TH2F * GetHist(TString omFileName, int htype=0)
Definition: PlotOnMon.C:129
TCanvas * MakeLongCanvas()
Definition: SetupHistos.C:23
void PlotOnMon(int run=13260, int subrun=0, int ptype=1)
Definition: PlotOnMon.C:21
tuple blue
Definition: rootlogon.py:65
float GetMedian(vector< float > scores)
Definition: PlotOnMon.C:309
int NRGBs
Definition: rootlogon.py:77
int NCont
Definition: rootlogon.py:78
double GetY(int dcm=1, int feb=0, int pix=0)
Definition: PlotOnMon.C:119
double median(TH1D *h)
Definition: absCal.cxx:524
Definition: run.py:1
OStream cout
Definition: OStream.cxx:6
c1
Definition: demo5.py:24
Double_t setlivetime
Definition: SimpleIterate.C:45
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
void Config(const TH1 *h)
Definition: HwDetLabel.cxx:21
Float_t e
Definition: plot.C:35
double GetX(int ndb=14, int db=1, int feb=0, int pix=0)
Definition: PlotOnMon.C:111