HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoNoiseMonitorGui.cxx
Go to the documentation of this file.
1 #include "HarpoNoiseMonitorGui.h"
2 
3 #include <TPad.h>
4 #include <TH1.h>
5 #include <TH2.h>
6 #include <THStack.h>
7 #include <TLine.h>
8 #include <TCanvas.h>
9 #include <TRootEmbeddedCanvas.h>
10 #include <TGFrame.h>
11 #include <TGComboBox.h>
12 #include <TGButton.h>
13 #include <TGLabel.h>
14 #include <TGText.h>
15 #include <TGButtonGroup.h>
16 #include <TGNumberEntry.h>
17 #include <TGListBox.h>
18 #include <TObjArray.h>
19 #include <TLegend.h>
20 #include <TClonesArray.h>
21 #include <TSystemDirectory.h>
22 #include <TSystem.h>
23 #include <TStyle.h>
24 #include <TSpectrum.h>
25 #include <TChain.h>
26 #include <TProfile.h>
27 #include <TGraph.h>
28 #include <TLatex.h>
29 #include <TMath.h>
30 
31 #include <TGTab.h>
32 #include <TApplication.h>
33 
34 #include "TThread.h"
35 #include "TMethodCall.h"
36 #include "TMapFile.h"
37 
38 #include <math.h>
39 #include "HarpoAnalyseMonitorNew.h"
40 
41 #include "RVersion.h"
42 
43 #include <iostream>
44 using namespace std;
45 #include <fstream>
46 
47 
55 };
56 
57 HarpoNoiseMonitorGui::HarpoNoiseMonitorGui(const TGWindow *p, UInt_t w, UInt_t h, UInt_t opt, int argc, char **argv)
58  : TGMainFrame(p, w, h, opt)
59 {
60 
61  ecTabEvent = 0;
62  ecTabCumul = 0;
63  ecSideSummary = 0;
64  cTabEvent = 0;
65  cTabCumul = 0;
66  cSideSummary = 0;
67 
68  fFrameMain = 0;
69  fChooseRun = 0;
70  fChooseEvent = 0;
71  fChooseNEvents = 0;
72  fDisplayEvent = 0;
73  fNextEvent = 0;
74  fDisplay = 0;
75  fDisplayBox = 0;
76  fSave = 0;
77 
78  fRunNumber = 0;
79 
80  fAutoRefresh = kTRUE;
82 
83  UInt_t xsize1 = 200;
84  UInt_t xsize2 = 800;
85  UInt_t mainx = xsize1 + xsize2;
86  UInt_t mainy = 700;
87 
88  gStyle->SetFrameBorderMode(1);
89  gStyle->SetFrameBorderSize(1);
90  gStyle->SetOptStat(0);
91 
92  TGVerticalFrame* f1 = new TGVerticalFrame(this,xsize1,mainy,kVerticalFrame);
93  TGVerticalFrame* f2 = new TGVerticalFrame(this,xsize2,mainy,kVerticalFrame);
94  this->AddFrame(f1,new TGLayoutHints(kLHintsLeft | kLHintsExpandY,5,5,5,5));
95  this->AddFrame(f2,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5));
96  TGVerticalFrame* f20 = new TGVerticalFrame(f2,xsize2,mainy,kVerticalFrame);
97  f2->AddFrame(f20,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5));
98  TGHorizontalFrame* f21 = new TGHorizontalFrame(f2,xsize2,80,kHorizontalFrame);
99  f2->AddFrame(f21,new TGLayoutHints(kLHintsBottom ,5,5,5,5));
100 
101  BuildButtonsFrame(f1);
102  BuildDisplayFrame(f20);
103  BuildInfoFrame(f21);
104 
105  MapSubwindows();
106  MapWindow();
107  SetWindowName("HARPO Noise Monitor");
108  MoveResize(0,0,mainx,mainy);
109 
110  Layout();
111 
112  fAutoScale = kFALSE;
113 
114  SetStyle();
115 
116 
117 
118 
119 
120 
121  // HarpoRunHeader *hdr;
122 
123  HarpoConfig *cfg = new HarpoConfig(argc,argv,0x03);
124  cfg->Init();
125  cfg->print();
126 
127  fReader = new HarpoReader( cfg );
128 
129  if ( fReader->Init(hSyncTime) ) {
130  //hdr = fReader->GetRunHeader();
131  }else{
132  printf ("Int ERROR exiting ...\n");
133  return;
134  }
135 
136  printf ("Initialized\n");
137 
138 
139 
140  // h1Ch[0] = new TH1F("h1ChX",";time [tb]",508,0,508);
141  hAllCh[0] = new TH1F("hAllChX",";time [tb]",508,0,508);
142  h2D[0] = new TH2F("h2DX",";time [tb]; channel",508,0,508,304,0,304);
143 
144  // hFFT1Ch[0] = new TH1F("hFFT1ChX",";freq []",508,0,508);
145  hFFTAllCh[0] = new TH1F("hFFTAllChX",";freq []",508,0,508);
146  hFFT2D[0] = new TH2F("hFFT2DX",";freq []; channel",508,0,508,304,0,304);
147 
148  // hPed1Ch[0] = new TH1F("hPed1ChX",";pedesteal [ADC]",500,0,500);
149  hPedAllCh[0] = new TH1F("hPedAllChX",";pedesteal [ADC]",100,-50,50);
150  hPed2D[0] = new TH2F("hPed2DX",";pedesteal [ADC]; channel",500,-250,250,304,0,304);
151 
152 
153 
154 
155  // h1Ch[1] = new TH1F("h1ChY",";time [tb]",508,0,508);
156  hAllCh[1] = new TH1F("hAllChY",";time [tb]",508,0,508);
157  h2D[1] = new TH2F("h2DY",";time [tb]; channel",508,0,508,304,0,304);
158 
159  // hFFT1Ch[1] = new TH1F("hFFT1ChY",";freq []",508,0,508);
160  hFFTAllCh[1] = new TH1F("hFFTAllChY",";freq []",508,0,508);
161  hFFT2D[1] = new TH2F("hFFT2DY",";freq []; channel",508,0,508,304,0,304);
162 
163  // hPed1Ch[1] = new TH1F("hPed1ChY",";pedesteal [ADC]",500,0,500);
164  hPedAllCh[1] = new TH1F("hPedAllChY",";pedestal - 250 [ADC]",100,-50,50);
165  hPed2D[1] = new TH2F("hPed2DY",";pedestal - 250 [ADC]; channel",500,-250,250,304,0,304);
166 
167  hNoise[0] = new TH1F("h1EvNoiseX",";noise [ADC]",500,-50,50);
168  hNoise2D[0] = new TH2F("h1EvNoise2DX",";noise [ADC]; channel",500,-50,50,304,0,304);
169  hNoise[1] = new TH1F("h1EvNoiseY",";noise [ADC]",500,-50,50);
170  hNoise2D[1] = new TH2F("h1EvNoise2DY",";noise [ADC]; channel",500,-50,50,304,0,304);
171 
172 
173  fNevt = 0;
174 
175 
177  fAna-> Init(); // if errors ???
179 
180  fEvent = 0;
181  // fChooseEvent->SetNumber(1);
182  fReader->NextEvent();
183  fEvent = fReader->GetEvent();
184 
185  DisplayEvent();
186 
187 }
188 
189 
190 
192 {
193  // Got close message for this MainFrame. Terminate the application
194  // or returns from the TApplication event loop (depending on the
195  // argument specified in TApplication::Run()).
196 
197  gApplication->Terminate(0);
198 
199 
200 }
201 
202 
203 
204 void HarpoNoiseMonitorGui::BuildDisplayFrame(TGVerticalFrame* f20)
205 {
206 
207  UInt_t xsize2 = f20->GetWidth();
208  UInt_t mainy = f20->GetHeight();
209 
210  fEventLabel = new TGLabel(f20,"NO DATA");
211  fEventLabel->SetHeight(40);
212  f20->AddFrame(fEventLabel,new TGLayoutHints(kLHintsExpandX,5,5,5,5));
213 
214  TGTab* fTab = new TGTab(f20, xsize2, mainy);
215 
216  TGCompositeFrame *tf = fTab->AddTab("Current Event");
217  ecTabEvent = new TRootEmbeddedCanvas("ecTabEvent",tf,xsize2,mainy);
218  tf->AddFrame(ecTabEvent,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5));
219 
220  tf = fTab->AddTab("Cumulated data");
221  ecTabCumul = new TRootEmbeddedCanvas("ecTabCumul",tf,xsize2,mainy);
222  tf->AddFrame(ecTabCumul,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5));
223 
224  // tf = fTab->AddTab("Current Event Y");
225  // ecTabEventY = new TRootEmbeddedCanvas("ecTabEventY",tf,xsize2,mainy);
226  // tf->AddFrame(ecTabEventY,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5));
227 
228  // tf = fTab->AddTab("Cumulated data Y");
229  // ecTabCumulY = new TRootEmbeddedCanvas("ecTabCumulY",tf,xsize2,mainy);
230  // tf->AddFrame(ecTabCumulY,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5));
231 
232  f20->AddFrame(fTab,new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5));
233 
234 }
235 
236 void HarpoNoiseMonitorGui::BuildInfoFrame(TGHorizontalFrame* f21)
237 {
238 
239  UInt_t xsize2 = f21->GetWidth();
240  UInt_t ysize = f21->GetHeight();
241  TGVerticalFrame* f211 = new TGVerticalFrame(f21,xsize2/4,ysize,kVerticalFrame);
242  TGVerticalFrame* f212 = new TGVerticalFrame(f21,xsize2/4,ysize,kVerticalFrame);
243  TGVerticalFrame* f213 = new TGVerticalFrame(f21,xsize2/4,ysize,kVerticalFrame);
244  TGVerticalFrame* f214 = new TGVerticalFrame(f21,xsize2/4,ysize,kVerticalFrame);
245  TGLayoutHints* fLayout3 = new TGLayoutHints(kLHintsBottom ,5,5,5,5);
246  f21->AddFrame(f211,fLayout3);
247  f21->AddFrame(f212,fLayout3);
248  f21->AddFrame(f213,new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,5,5,5,5));
249  f21->AddFrame(f214,fLayout3);
250 
251 }
252 
254 {
255 
256  UInt_t xsize1 = f1->GetWidth();
257  UInt_t ysize = 20;
258  TGLayoutHints* fLayout1 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5,5,5);
259  // TGLayoutHints* fLayout12 = new TGLayoutHints(kLHintsLeft,5,5,5,5);
260  TGLayoutHints* fLayout2 = new TGLayoutHints(kLHintsExpandX | kLHintsTop,5,5,5,5);
261  // TGLayoutHints* fLayout3 = new TGLayoutHints(kLHintsBottom | kLHintsCenterX,5,5,5,5);
262  //TGLayoutHints* fLayout3 = new TGLayoutHints(kLHintsBottom ,5,5,5,5);
263 
264  TGHorizontalFrame* autorefreshFrame = new TGHorizontalFrame(f1,xsize1,ysize,kHorizontalFrame);
265  TGLabel* fDelayLabel = new TGLabel(f1, "Delay [s]");
266  fChooseDelay = new TGNumberEntry(autorefreshFrame);
267  fChooseDelay->Resize(xsize1 -20 ,ysize);
268  fAutoRefreshButton = new TGTextButton(autorefreshFrame, "Process Events", M_AUTOREFRESH);
269  fAutoRefreshButton->Resize(20, ysize);
270  fAutoRefreshButton->Associate(this);
271  // fChooseDir->Select(1);
272  autorefreshFrame->AddFrame(fAutoRefreshButton,fLayout2);
273  autorefreshFrame->AddFrame(fDelayLabel,fLayout2);//new TGLayoutHints(kLHintsExpandX | kLHintsCenterY,5,5,5,5));
274  autorefreshFrame->AddFrame(fChooseDelay,fLayout2);
275  fChooseDelay->SetNumber(1);
276 
277 
278  fDisplayEvent = new TGTextButton(f1,"Display Current Event",M_DISPLAY_EVENT);
279  fDisplayEvent->Associate(this);
280 
281  fNextEvent = new TGTextButton(f1,"Next Event",M_NEXT_EVENT);
282  fNextEvent->Associate(this);
283  fNextEvent->SetState(kButtonDisabled,kFALSE);
284 
285  fPrevEvent = new TGTextButton(f1,"Previous Event",M_PREV_EVENT);
286  fPrevEvent->Associate(this);
287  fPrevEvent->SetState(kButtonDisabled,kFALSE);
288 
289 
290  ecSideSummary = new TRootEmbeddedCanvas("ecSideSummary",f1,xsize1,300);
291 
292 
293  // fLog = new TGListBox(f1);
294  // fLog->Resize(xsize1,300);
295 
296  f1->AddFrame(autorefreshFrame,fLayout2);
297  f1->AddFrame(fDisplayEvent,fLayout2);
298  f1->AddFrame(fNextEvent,fLayout2);
299  f1->AddFrame(fPrevEvent,fLayout2);
300  f1->AddFrame(ecSideSummary,fLayout1);
301  // f1->AddFrame(fLog,fLayout1);
302 }
303 
304 
305 
306 
307 
308 
309 
310 void HarpoNoiseMonitorGui::SetListOfRuns(TGComboBox* /* box */ , const char* /*dirname */)
311 {
312  // cout << "Get List of files in " << dirname << endl;
313 
314  // const char* pwd = gSystem->ExpandPathName("$PWD");
315  // TSystemDirectory* sysdir = new TSystemDirectory("data_dir",dirname);
316  // TList* listoffiles = sysdir->GetListOfFiles();
317  // listoffiles->Sort();
318 
319  // box->RemoveAll();
320 
321  // cout << "Nfiles = " << listoffiles->GetEntries() << endl;
322  // for(Int_t Nfile = 0; Nfile<listoffiles->GetEntries(); Nfile++){
323 
324  // Int_t runnumber;
325  // Char_t buffer[126];
326  // const char* filename = listoffiles->At(Nfile)->GetName();
327  // if(sscanf(filename,"reduced-%d",&runnumber)){
328  // box->AddEntry(filename, Nfile);
329  // }
330  // }
331 
332  // sysdir->Delete();
333  // TSystemDirectory* startdir = new TSystemDirectory("startdir",pwd);
334  // startdir->GetListOfFiles();
335  // return;
336 
337 }
338 
339 
340 
341 
342 // void HarpoNoiseMonitorGui::StartThread()
343 // {
344 
345 // printf("Starting Thread 0\n");
346 // fThread1 = new TThread("t0", handle1, (void*) 0);
347 // fThread1->Run();
348 
349 // }
350 
351 
352 
354 {
355 
356  return kTRUE;
357 
358 }
359 
361 {
362 
363  Info("DisplayEvent","%p",event);
364 
365  if(event == 0) return;
366 
367  fNevt++;
368 
369  if(!cTabEvent){
370  cTabEvent = ecTabEvent->GetCanvas();
371  cTabEvent->SetName("cTabEvent");
372  cTabEvent->Divide(3,3);
373  }
374 
375  if(!cTabCumul){
376  cTabCumul = ecTabCumul->GetCanvas();
377  cTabCumul->SetName("cTabCumul");
378  cTabCumul->Divide(3,3);
379  }
380 
381  // if(!cTabEvent[1]){
382  // cTabEvent[1] = ecTabEventY->GetCanvas();
383  // cTabEvent[1]->SetName("cTabEventY");
384  // cTabEvent[1]->Divide(2,3);
385  // }
386 
387  // if(!cTabCumul[1]){
388  // cTabCumul[1] = ecTabCumulY->GetCanvas();
389  // cTabCumul[1]->SetName("cTabCumulY");
390  // cTabCumul[1]->Divide(2,3);
391  // }
392  // MakeNice2dHisto(hXZs,cTabEvent->GetPad(1),1);
393  // MakeNice2dHisto(hYZs,cTabEvent->GetPad(2),1);
394 
395  TLatex* latex = new TLatex();
396  latex->SetTextFont(132);
397  latex->SetTextAlign(12);
398  latex->SetTextSize(0.08);
399 
400 
401  // Int_t npix = 0, nch = 0, ntb = 0;
402 
403  for(Int_t ndet=0;ndet<2;ndet++) {
404  if (gHDetSet->isExist(ndet)) {
405  HarpoDccMap * m = event->GetDccMap(ndet);
406  // std::cout << "Event " << nEvents << " " << m << std::endl;
407  if ( m != NULL ) {
408 
409  Int_t color = ndet? kRed : kBlue;
410  latex->SetTextColor(color);
411 
412  // TH1F* h1Ev1Ch = new TH1F("h1Ev1Ch",";time [tb]",508,0,508);
413  TH1F* h1EvAllCh = new TH1F("h1EvAllCh",";time [tb]",508,0,508);
414  TH2F* h1Ev2D = new TH2F("h1Ev2D",";time [tb]; channel",508,0,508,304,0,304);
415 
416  // TH1F* h1EvFFT1Ch = new TH1F("h1EvFFT1Ch",";freq []",508,0,508);
417  TH1F* h1EvFFTAllCh = new TH1F("h1EvFFTAllCh",";freq []",508,0,508);
418  TH2F* h1EvFFT2D = new TH2F("h1EvFFT2D",";freq []; channel",508,0,508,304,0,304);
419 
420  // TH1F* h1EvPed1Ch = new TH1F("h1EvPed1Ch",";pedesteal [ADC]",500,0,500);
421  TH1F* h1EvPedAllCh = new TH1F("h1EvPedAllCh",";pedesteal [ADC]",100,-50,50);
422  TH2F* h1EvPed2D = new TH2F("h1EvPed2D",";pedesteal [ADC]; channel",500,-250,250,304,0,304);
423 
424 
425  TH1F* h1EvNoise = new TH1F("h1EvNoise",";noise [ADC]",500,-50,50);
426  TH2F* h1EvNoise2D = new TH2F("h1EvNoise2D",";noise [ADC]; channel",500,-250,250,304,0,304);
427 
428  // for(j=0;j<NCHAN;j++) // Channels
429  // Double_t qTot = 0;
430  TH1F* hTmp = new TH1F("hTmp","",508,0,508);
431  for(Int_t i=1;i<NADC;i++){ //Time bins
432  Double_t qTotT = 0;
433  Int_t nChan = 0;
434  for(Int_t j=0;j<NCHAN;j++){ // Channels
435  Double_t q = m->GetData(j,i);
436  if(q == 0) continue;
437  h2D[ndet]->SetBinContent(i+1,j+1,h2D[ndet]->GetBinContent(i+1,j+1)+q);
438  h1Ev2D->SetBinContent(i+1,j+1,q);
439  // if(j == 100){
440  // h1Ch[ndet]->SetBinContent(i+1,h1Ch[ndet]->GetBinContent(i+1)+q);
441  // h1Ev1Ch->SetBinContent(i+1,q);
442  // hPed1Ch[ndet]->Fill(q);
443  // h1EvPed1Ch->Fill(q);
444  // }
445  hPed2D[ndet]->Fill(q-250,j);
446  h1EvPed2D->Fill(q-250,j);
447  qTotT += q;
448  nChan++;
449  }
450  hAllCh[ndet]->SetBinContent(i+1,hAllCh[ndet]->GetBinContent(i+1)+qTotT/nChan);
451  h1EvAllCh->SetBinContent(i+1,qTotT/nChan);
452  hPedAllCh[ndet]->Fill(qTotT/nChan - 250);
453  h1EvPedAllCh->Fill(qTotT/nChan - 250);
454  hTmp->SetBinContent(i+1,qTotT/nChan);
455  for(Int_t j=0;j<nChan;j++){ // Channels
456  Double_t q = m->GetData(j,i);
457  hNoise[ndet]->Fill(q - qTotT/nChan);
458  hNoise2D[ndet]->Fill(j,q - qTotT/nChan);
459  h1EvNoise->Fill(q - qTotT/nChan);
460  h1EvNoise2D->Fill(j,q - qTotT/nChan);
461  }
462  }
463  TH1* hm1 = 0;
464  hm1 = hTmp->FFT(hm1, "MAG");
465  for(Int_t i=2;i<512;i++){ //Time bins
466  hFFTAllCh[ndet]->SetBinContent(i+1,hFFTAllCh[ndet]->GetBinContent(i+1)+hm1->GetBinContent(i+1));
467  h1EvFFTAllCh->SetBinContent(i+1,hm1->GetBinContent(i+1));
468  }
469  hTmp->Delete();
470  hm1->Delete();
471 
472  for(Int_t j=0;j<NCHAN;j++){ // Channels
473  TH1F* hTmp = new TH1F("hTmp","",508,0,508);
474  for(Int_t i=0;i<NADC;i++){ //Time bins
475  Double_t q = m->GetData(j,i);
476  hTmp->SetBinContent(i+1,q);
477  }
478 
479  TH1* hm = 0;
480  hm = hTmp->FFT(hm, "MAG");
481  for(Int_t i=2;i<512;i++){ //Time bins
482  hFFT2D[ndet]->SetBinContent(i+1,j+1,hFFT2D[ndet]->GetBinContent(i+1,j+1)+hm->GetBinContent(i+1));
483  h1EvFFT2D->SetBinContent(i+1,j+1,hm->GetBinContent(i+1));
484  // if(j==100){
485  // hFFT1Ch[ndet]->SetBinContent(i+1,hFFT1Ch[ndet]->GetBinContent(i+1,j+1)+hm->GetBinContent(i+1));
486  // h1EvFFT1Ch->SetBinContent(i+1,hm->GetBinContent(i+1));
487  // }
488  }
489  hTmp->Delete();
490  hm->Delete();
491 
492  }
493 
494  // hFFT1Ch[ndet]->GetXaxis()->SetRangeUser(-1,255);
495  hFFTAllCh[ndet]->GetXaxis()->SetRangeUser(-1,255);
496  hFFT2D[ndet]->GetXaxis()->SetRangeUser(-1,255);
497  // h1EvFFT1Ch->GetXaxis()->SetRangeUser(-1,255);
498  h1EvFFTAllCh->GetXaxis()->SetRangeUser(-1,255);
499  h1EvFFT2D->GetXaxis()->SetRangeUser(-1,255);
500 
501 
502  // // cTabCumul[ndet]->cd(1);
503  // // h1Ch[ndet]->DrawCopy();
504  // cTabCumul[ndet]->cd(1);
505  // hAllCh[ndet]->DrawNormalized("", hAllCh[ndet]->Integral()/fNevt);
506  // cTabCumul[ndet]->cd(2);
507  // h2D[ndet]->DrawNormalized("colz", h2D[ndet]->Integral()/fNevt);
508 
509  // // cTabCumul[ndet]->cd(4);
510  // // hFFT1Ch[ndet]->DrawNormalized("", hFFT1Ch[ndet]->Integral()/fNevt);
511  // cTabCumul[ndet]->cd(3);
512  // hFFTAllCh[ndet]->DrawNormalized("", hFFTAllCh[ndet]->Integral()/fNevt);
513  // cTabCumul[ndet]->cd(4);
514  // hFFT2D[ndet]->DrawNormalized("colz", hFFT2D[ndet]->Integral()/fNevt);
515 
516  // // cTabCumul[ndet]->cd(7);
517  // // hPed1Ch[ndet]->DrawNormalized("", hPed1Ch[ndet]->Integral()/fNevt);
518  // cTabCumul[ndet]->cd(5);
519  // // hPedAllCh[ndet]->DrawNormalized("", hPedAllCh[ndet]->Integral()/fNevt);
520  // hPedAllCh[ndet]->DrawNormalized("", 1);
521  // latex->DrawLatex(280,0.05,Form("FWHM = %g",FindFWHM(hPedAllCh[ndet])));
522  // cTabCumul[ndet]->cd(6);
523  // hPed2D[ndet]->DrawNormalized("colz", hPed2D[ndet]->Integral()/fNevt);
524 
525  // // cTabEvent[ndet]->cd(1);
526  // // h1Ev1Ch->DrawNormalized(, // h1Ev1Ch->Integral()/fNevt);
527  // cTabEvent[ndet]->cd(1);
528  // h1EvAllCh->DrawCopy();
529  // cTabEvent[ndet]->cd(2);
530  // h1Ev2D->DrawCopy("colz");
531 
532  // // cTabEvent[ndet]->cd(4);
533  // // h1EvFFT1Ch->DrawCopy();
534  // cTabEvent[ndet]->cd(3);
535  // h1EvFFTAllCh->DrawCopy();
536  // cTabEvent[ndet]->cd(4);
537  // h1EvFFT2D->DrawCopy("colz");
538 
539  // // cTabEvent[ndet]->cd(7);
540  // // h1EvPed1Ch->DrawCopy();
541  // cTabEvent[ndet]->cd(5);
542  // // h1EvPedAllCh->DrawCopy();
543  // h1EvPedAllCh->DrawNormalized();
544  // latex->DrawLatex(280,0.05,Form("FWHM = %g",FindFWHM(h1EvPedAllCh)));
545  // cTabEvent[ndet]->cd(6);
546  // h1EvPed2D->DrawCopy("colz");
547 
548 
549 
550 
551 
552 
553 
554 
555  h1EvAllCh->SetLineColor(color);
556  hAllCh[ndet]->SetLineColor(color);
557  h1EvFFTAllCh->SetLineColor(color);
558  hFFTAllCh[ndet]->SetLineColor(color);
559  h1EvPedAllCh->SetLineColor(color);
560  hPedAllCh[ndet]->SetLineColor(color);
561  h1EvNoise->SetLineColor(color+2);
562  hNoise[ndet]->SetLineColor(color+2);
563 
564 
565  Double_t ymax;
566 
567  // cTabCumul[ndet]->cd(1);
568  // h1Ch[ndet]->DrawCopy();
569  cTabCumul->cd(1);
570  if(ndet)
571  hAllCh[ndet]->DrawNormalized("same", hAllCh[ndet]->Integral()/fNevt);
572  else
573  hAllCh[ndet]->DrawNormalized("", hAllCh[ndet]->Integral()/fNevt);
574  cTabCumul->cd(2+ndet);
575  h2D[ndet]->DrawNormalized("colz", h2D[ndet]->Integral()/fNevt);
576 
577  // cTabCumul[ndet]->cd(4);
578  // hFFT1Ch[ndet]->DrawNormalized("", hFFT1Ch[ndet]->Integral()/fNevt);
579  cTabCumul->cd(4);
580  TH1* hDummy = 0;
581  if(ndet)
582  hDummy = hFFTAllCh[ndet]->DrawNormalized("same", hFFTAllCh[ndet]->Integral()/fNevt);
583  else
584  hDummy = hFFTAllCh[ndet]->DrawNormalized("", hFFTAllCh[ndet]->Integral()/fNevt);
585  ymax = hDummy->GetMaximum();//hFFTAllCh[ndet]->GetYaxis()->GetXmax();
586 
587  TSpectrum* spectrum = new TSpectrum(10,0.5);
588  spectrum->Search(hDummy,3,"goff",0.3);
589  Int_t npeaks = spectrum->GetNPeaks();
590 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
591  Double_t *Xpeak = spectrum->GetPositionX();
592  Double_t *Ypeak = spectrum->GetPositionY();
593 #else
594  Float_t *Xpeak = spectrum->GetPositionX();
595  Float_t *Ypeak = spectrum->GetPositionY();
596 #endif
597  for(Int_t i = 0; i<npeaks; i++)
598  cout << "*** " << Xpeak[i] << ", " << Ypeak[i] << endl;
599  latex->DrawLatex(80,(0.8 - 0.2*ndet)*ymax,Form("%g %g",Ypeak[0], Ypeak[1]));
600  spectrum->Delete();
601 
602  cTabCumul->cd(5+ndet);
603  hFFT2D[ndet]->DrawNormalized("colz", hFFT2D[ndet]->Integral()/fNevt);
604 
605  // cTabCumul[ndet]->cd(7);
606  // hPed1Ch[ndet]->DrawNormalized("", hPed1Ch[ndet]->Integral()/fNevt);
607  cTabCumul->cd(7);
608  // hPedAllCh[ndet]->DrawNormalized("", hPedAllCh[ndet]->Integral()/fNevt);
609  if(ndet)
610  hDummy = hPedAllCh[ndet]->DrawNormalized("same", 1);
611  else
612  hDummy = hPedAllCh[ndet]->DrawNormalized("", 1);
613  hDummy = hNoise[ndet]->DrawNormalized("same", 1);
614  ymax = hDummy->GetMaximum();
615  //ymax = hPedAllCh[ndet]->GetYaxis()->GetXmax();
616  // latex->DrawLatex(280,0.05 - 0.01*ndet,Form("FWHM = %g",FindFWHM(hPedAllCh[ndet])));
617  latex->DrawLatex(20,(0.8 - 0.2*ndet)*ymax,Form("FWHM = %g",FindFWHM(hPedAllCh[ndet])));
618  cTabCumul->cd(8+ndet);
619  hPed2D[ndet]->DrawNormalized("colz", hPed2D[ndet]->Integral()/fNevt);
620 
621  // cTabEvent[ndet]->cd(1);
622  // h1Ev1Ch->DrawNormalized(, // h1Ev1Ch->Integral()/fNevt);
623  cTabEvent->cd(1);
624  if(ndet)
625  h1EvAllCh->DrawCopy("same");
626  else
627  h1EvAllCh->DrawCopy();
628  cTabEvent->cd(2+ndet);
629  h1Ev2D->DrawCopy("colz");
630 
631  // cTabEvent[ndet]->cd(4);
632  // h1EvFFT1Ch->DrawCopy();
633  cTabEvent->cd(4);
634  if(ndet)
635  hDummy = h1EvFFTAllCh->DrawCopy("same");
636  else
637  hDummy = h1EvFFTAllCh->DrawCopy();
638  ymax = hDummy->GetMaximum();
639  spectrum = new TSpectrum(10,0.5);
640  spectrum->Search(hDummy,3,"goff",0.3);
641  npeaks = spectrum->GetNPeaks();
642  Xpeak = spectrum->GetPositionX();
643  Ypeak = spectrum->GetPositionY();
644  for(Int_t i = 0; i<npeaks; i++)
645  cout << "*** " << Xpeak[i] << ", " << Ypeak[i] << endl;
646  latex->DrawLatex(80,(0.8 - 0.2*ndet)*ymax,Form("%g %g",Ypeak[0], Ypeak[1]));
647  spectrum->Delete();
648 
649 
650  cTabEvent->cd(5+ndet);
651  h1EvFFT2D->DrawCopy("colz");
652 
653  // cTabEvent[ndet]->cd(7);
654  // h1EvPed1Ch->DrawCopy();
655  cTabEvent->cd(7);
656  // h1EvPedAllCh->DrawCopy();
657  if(ndet)
658  hDummy = h1EvPedAllCh->DrawNormalized("same");
659  else
660  hDummy = h1EvPedAllCh->DrawNormalized();
661  hDummy = h1EvNoise->DrawNormalized("same", 1);
662  // ymax = h1EvPedAllCh->GetYaxis()->GetXmax();
663  ymax = hDummy->GetMaximum();
664  latex->DrawLatex(20,(0.8 - 0.2*ndet)*ymax,Form("FWHM = %g",FindFWHM(h1EvPedAllCh)));
665  cTabEvent->cd(8+ndet);
666  h1EvPed2D->DrawCopy("colz");
667 
668 
669 
670 
671 
672 
673 
674 
675 
676 
677 
678 
679 
680  // h1Ev1Ch->Delete();
681  h1EvAllCh->Delete();
682  h1Ev2D->Delete();
683  // h1EvFFT1Ch->Delete();
684  h1EvFFTAllCh->Delete();
685  h1EvFFT2D->Delete();
686  // h1EvPed1Ch->Delete();
687  h1EvPedAllCh->Delete();
688  h1EvPed2D->Delete();
689 
690  h1EvNoise->Delete();
691  h1EvNoise2D->Delete();
692 
693  // cTabEvent[ndet]->Update();
694  // cTabCumul[ndet]->Update();
695  }
696  } else {
697  std::cout << "No Data Map for plane " << std::endl;
698  }
699  }
700  cTabEvent->Update();
701  cTabCumul->Update();
702 
703  return;
704 }
705 
706 
708 {
709 
711 
712  Int_t Event = Int_t(fChooseEvent->GetNumber()) + 1;
713  fChooseEvent->SetNumber(Event);
714  Bool_t test = fReader->NextEvent();
715  if(test)
716  fEvent = fReader->GetEvent();
717  else
718  fEvent = 0;
719  // fAna->ProcessEvent(evt);
720  // evt->Delete();
721 
722  return;
723 }
724 
725 
727 {
728 
730 
731  Int_t Event = Int_t(fChooseEvent->GetNumber()) - 1;
732  fChooseEvent->SetNumber(Event);
733  Bool_t test = fReader->Find(Event);
734  if(test)
735  fEvent = fReader->GetEvent();
736  else
737  fEvent = 0;
738 
739  return;
740 
741 }
742 
743 
745 {
746 
748  return;
749 }
750 
751 
753 {
754 
755  for(Int_t i = 0; i<nEvents; i++){
756  // Int_t Event = Int_t(fChooseEvent->GetNumber()) + 1;
757  // fChooseEvent->SetNumber(Event);
758  Bool_t test = fReader->NextEvent();
759  if(test){
760  fEvent = fReader->GetEvent();
762  }else{
763  fEvent = 0;
764  break;
765  }
766  }
767  return;
768 }
769 
770 
772 
773 }
774 
775 
776 // //__________________________________________________________________
777 // void HarpoNoiseMonitorGui::Hist2dClicked(TVirtualPad* pad, TObject* select, Int_t event)
778 // {
779 // //this action function is called whenever you click the mouse
780 // //it just prints the pad coordinates and channel number, and
781 // //displays the pulse in time in another window
782 
783 // if (event != kButton1Down) return; //has to click to see pad signal in time
784 // if (!select) return;
785 // if (!select->InheritsFrom("TH2F")) return;
786 // TH2F *hist = (TH2F*)select;
787 // }
788 
789 
790 //---------------------------------
791 
792 
793 
794 
795 
796 
797 Bool_t HarpoNoiseMonitorGui::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
798 {
799 
800  switch(GET_MSG(msg)){
801  case kC_COMMAND:
802  switch(GET_SUBMSG(msg)){
803  case kCM_BUTTON:
804  switch(parm1){
805  case M_DISPLAY_EVENT: DisplayEvent(); break;
806  case M_NEXT_EVENT: NextEvent(); break;
807  // case M_DISPLAY: Display(); break;
808  case M_SAVE: Save(); break;
809  case M_PREV_EVENT: PrevEvent(); break;
810  case M_AUTOREFRESH:
811  // fAutoRefresh = !fAutoRefresh;
812  // fChooseDelay->SetState(fAutoRefresh);
813  // if(fAutoRefresh) fAutoRefreshButton->SetText("Freeze");
814  // else fAutoRefreshButton->SetText("AutoRefresh");
815  LoopEvents(fChooseDelay->GetNumber());
816  break;
817  default: cout << "Unknown button" << endl; break;
818  }
819  default:
820  break;
821  }
822  default:
823  break;
824  }
825 
826  return kTRUE;
827 }
828 
829 
830 
832 {
833  // TStyle *myStyle= new TStyle("myStyle","Plot style");
834 
835  // // use plain black on white colors
836  // myStyle->SetFrameBorderMode(0);
837  // myStyle->SetCanvasBorderMode(0);
838  // myStyle->SetPadBorderMode(0);
839  // myStyle->SetPadColor(kWhite);
840  // myStyle->SetCanvasColor(kWhite);
841  // //myStyle->SetTitleColor(0);
842  // myStyle->SetStatColor(kWhite);
843  // myStyle->SetTitleFillColor(kWhite);
844  // //myStyle->SetFillColor(kWhite);
845 
846  // // set the paper & margin sizes
847  // myStyle->SetPaperSize(20,26);
848  // myStyle->SetPadTopMargin(0.05);
849  // myStyle->SetPadRightMargin(0.05);
850  // myStyle->SetPadBottomMargin(0.16);
851  // myStyle->SetPadLeftMargin(0.12);
852 
853  // // use large Times-Roman fonts
854  // myStyle->SetTitleFont(132,"xyz"); // set the all 3 axes title font
855  // // myStyle->SetTitleFont(132," "); // set the pad title font
856  // myStyle->SetTitleSize(0.07,"xyz"); // set the 3 axes title size
857  // // myStyle->SetTitleSize(0.06," "); // set the pad title size
858  // myStyle->SetTitleOffset(0.8,"y");
859  // myStyle->SetLabelFont(132,"xyz");
860  // myStyle->SetLabelSize(0.06,"xyz");
861  // myStyle->SetTextFont(132);
862  // myStyle->SetTextSize(0.08);
863  // // myStyle->SetStatFont(132);
864 
865  // // use bold lines and markers
866  // // myStyle->SetMarkerStyle(8);
867  // // myStyle->SetHistLineWidth(1.85);
868  // // myStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes
869 
870  // //..Get rid of X error bars
871  // myStyle->SetErrorX(0.001);
872 
873  // // do not display any of the standard histogram decorations
874  // myStyle->SetOptTitle(1);
875  // myStyle->SetOptStat(0);
876  // myStyle->SetOptFit(0);
877 
878  // // put tick marks on top and RHS of plots
879  // // myStyle->SetPadTickX(1);
880  // // myStyle->SetPadTickY(1);
881 
882 
883  // myStyle->SetPalette(1);
884 
885  // cout << "Using style 'myStyle'...\n";
886  // gROOT->SetStyle("myStyle");
887  // gROOT->ForceStyle();
888 }
889 
890 
891 
892 
893 
894 //_______________________________________________________________________
895 void HarpoNoiseMonitorGui::MakeNice1dHisto(TH1* hist, TVirtualPad* c1, const char* opt)
896 {
897  gStyle->SetTitleH(0.08);
898  gStyle->SetTitleW(0.78);
899  gStyle->SetTitleX(0.16);
900  gStyle->SetTitleY(0.99);
901  gStyle->SetTitleFont(132," ");
902  gStyle->SetTitleSize(0.09," ");
903  hist->SetTitleFont(132);
904  hist->SetTitleSize(0.09);
905  hist->GetXaxis()->SetTitleSize(0.07);
906  hist->GetYaxis()->SetTitleSize(0.07);
907  hist->GetXaxis()->SetTitleOffset(0.7);
908  hist->GetYaxis()->SetTitleOffset(0.7);
909  hist->GetXaxis()->SetTitleFont(132);
910  hist->GetYaxis()->SetTitleFont(132);
911  hist->GetXaxis()->SetLabelFont(132);
912  hist->GetYaxis()->SetLabelFont(132);
913  hist->GetXaxis()->SetLabelSize(0.06);
914  hist->GetYaxis()->SetLabelSize(0.06);
915  if(c1) {
916 
917  c1->SetLeftMargin(0.12);
918  c1->SetRightMargin(0.02);
919  c1->SetBottomMargin(0.12);
920  c1->SetTopMargin(0.09);
921  c1->cd();
922  hist->DrawCopy(opt);
923  }
924 }
925 
926 //_______________________________________________________________________
927 void HarpoNoiseMonitorGui::MakeNice2dHisto(TH2* hist, TVirtualPad* c1, Bool_t colz)
928 {
929  gStyle->SetTitleH(0.08);
930  gStyle->SetTitleW(0.78);
931  gStyle->SetTitleX(0.16);
932  gStyle->SetTitleY(0.99);
933  if(colz)
934  gStyle->SetTitleW(0.68);
935  gStyle->SetTitleFont(132," ");
936  gStyle->SetTitleSize(0.09," ");
937 
938  hist->GetXaxis()->SetTitleSize(0.07);
939  hist->GetYaxis()->SetTitleSize(0.07);
940  hist->GetZaxis()->SetTitleSize(0.07);
941  hist->GetXaxis()->SetTitleOffset(0.7);
942  hist->GetYaxis()->SetTitleOffset(0.8);
943  hist->GetZaxis()->SetTitleOffset(0.8);
944  hist->GetXaxis()->SetTitleFont(132);
945  hist->GetYaxis()->SetTitleFont(132);
946  hist->GetZaxis()->SetTitleFont(132);
947  hist->GetXaxis()->SetLabelFont(132);
948  hist->GetYaxis()->SetLabelFont(132);
949  hist->GetZaxis()->SetLabelFont(132);
950  hist->GetXaxis()->SetLabelSize(0.06);
951  hist->GetYaxis()->SetLabelSize(0.06);
952  hist->GetZaxis()->SetLabelSize(0.06);
953  if(c1) {
954 
955  c1->SetLeftMargin(0.12);
956  if(!colz)
957  c1->SetRightMargin(0.02);
958  else
959  c1->SetRightMargin(0.12);
960  c1->SetBottomMargin(0.12);
961  c1->SetTopMargin(0.09);
962  c1->cd();
963  if(colz)
964  hist->DrawCopy("colz");
965  else
966  hist->DrawCopy();
967  }
968 }
969 
970 
971 
972 Double_t HarpoNoiseMonitorGui::FindFWHM(TH1F* h, Double_t fact)
973 {
974 
975  Int_t maxbin = h->GetMaximumBin();
976  Double_t max = h->GetBinContent(maxbin);
977 
978  Int_t nbins = h->GetXaxis()->GetNbins();
979  Double_t x1 = 0, x2 = 0;
980  for(Int_t bin = 1; bin<=nbins; bin++){
981  if(h->GetBinContent(bin)<max*fact){
982  if(x2 == 0)
983  x1 = h->GetXaxis()->GetBinCenter(bin);
984  }
985  if(h->GetBinContent(bin)>=max*fact)
986  x2 = h->GetXaxis()->GetBinCenter(bin);
987  }
988  return x2 - x1;
989 }
void BuildInfoFrame(TGHorizontalFrame *f)
Monitor noise in non-zerosuppressed data.
TRootEmbeddedCanvas * ecSideSummary
Long_t Find(Long_t eventNo)
Find raw event by event number.
Definition: HarpoReader.h:82
Double_t FindFWHM(TH1F *h, Double_t fact=0.2)
#define NCHAN
Definition: HarpoDccMap.h:16
void AddAnalyseFunction(HarpoAnalyse *func)
Definition: HarpoReader.h:56
HarpoAnalyseNoiseMonitor * fAna
TRootEmbeddedCanvas * ecTabEvent
Double_t GetData(Int_t i, Int_t j)
Set/Get Data Cell.
Definition: HarpoDccMap.cxx:84
Bool_t Init(hReadMode mode=hSyncTime)
Definition: HarpoReader.h:73
TRootEmbeddedCanvas * ecTabCumul
void BuildDisplayFrame(TGVerticalFrame *f)
Bool_t isExist(ULong_t det)
Detecror date exist //! Number of Real Detectors.
Definition: HarpoDetSet.h:33
A class which instantiate the real top level reader.
Definition: HarpoReader.h:33
Bool_t NextEvent()
Definition: HarpoReader.h:62
TGTextButton * fDisplayEvent
ETestCommandIdentifiers
void MakeNice2dHisto(TH2 *hist, TVirtualPad *c1, Bool_t colz=kTRUE)
TGNumberEntry * fChooseDelay
TGTextButton * fAutoRefreshButton
void Init()
Definition: HarpoConfig.h:63
void LoopEvents(Int_t nEvents=1)
unpacked dcc data The class contains the data map for DCC or Feminos The data is stored as a 2D TMatr...
Definition: HarpoDccMap.h:29
void MakeNice1dHisto(TH1 *hist, TVirtualPad *c1, const char *opt="")
#define NADC
Definition: HarpoDccMap.h:18
void SetListOfRuns(TGComboBox *box, const char *dirname)
HarpoEvent * GetEvent()
Definition: HarpoReader.h:68
Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
TGNumberEntry * fChooseEvent
TGNumberEntry * fChooseNEvents
Harpo Event Simulation.
Definition: HarpoConfig.h:32
HarpoNoiseMonitorGui(const TGWindow *p, UInt_t w, UInt_t h, UInt_t opt, int argc, char **argv)
void print() const
Read config file in libconfig format.
A class store HARPO row event data and header. Provide access metods to the row event data...
Definition: HarpoEvent.h:29
void BuildButtonsFrame(TGVerticalFrame *f)
static hReaderType gHReaderType
Reader Type.
Definition: HarpoConfig.h:179
A class which keeps track of the entire configuration of the analysis.
Definition: HarpoConfig.h:50
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71