HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalysePmm2Monitor.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalysePmm2Monitor.cxx
3 //
13 #include "HarpoConfig.h"
14 #include "HarpoDetSet.h"
15 #include "HarpoDebug.h"
16 #include "HarpoDccEvent.h"
17 #include "HarpoEvent.h"
18 #include "Pmm2Event.h"
19 #include "HarpoRecoEvent.h"
20 
21 #include "MakeNiceHisto.h"
22 
23 #include "TFile.h"
24 #include "TStyle.h"
25 #include "TCanvas.h"
26 #include "TLegend.h"
27 #include "TLatex.h"
28 #include "TGraph.h"
29 #include "TH1F.h"
30 #include "TH2F.h"
31 #include "TArrayD.h"
32 #include "TMath.h"
33 #include "TLine.h"
34 #include "TGaxis.h"
35 #include "TROOT.h"
36 
37 #include <cstdlib>
38 #include <cstring>
39 #include <cassert>
40 #include <fstream>
41 #include <iostream>
42 
44 
45 void HarpoAnalysePmm2Monitor::print()
46  {
47  unsigned int nd; // number of detectors
48  HarpoEventHeader *hdr = fEvt->GetHeader();
49 
50  assert(hdr != NULL);
51  hdr->print();
52 
53  for (nd = 0; nd < gkNDetectors; nd++) {
54  // if (fEvt->isdataExist(nd)) {
55  HarpoDccMap *plane = fEvt->GetDccMap(nd);
56  if (plane != NULL )plane->print();
57  }
58  }
59 
61 {
62  // Bool_t drawEvent = kFALSE;
63  nEvents++;
64  // std::cout << " Processing Event " << nEvents<< std::endl;
65  if(nEvents%10000==0)
66  Info("process"," Processing Event %ld",nEvents);
67 
68  // TCanvas *ct = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("cPmm2");
69  // if(!ct){
70  // ct = new TCanvas("cPmm2","Monitor PMm2",0,0,1200,800);
71  // ct->Clear();
72  // ct->Divide(2);//,0.001,0.001);
73  // }
74 
75  if (!gHDetSet->isExist(PMM2)) return;
76  Pmm2Event *anaEvt = static_cast<Pmm2Event *>(fEvt->GetDetEvent(PMM2));
77 
78  fHistInfo->Reset();
79  fHistInfo->SetBinContent(1,gHConfig->GetRunNo());
80  fHistInfo->SetBinContent(2,fEvt->GetHeader()->GetEvtNo());
81  Double_t timestamp = fEvt->GetTimeStamp(PMM2)*10;
82  if(gHarpoDebug>1) Info("process","%g",timestamp);
83  if(timestamp==0) return;
84  // fHistInfo->SetBinContent(3,fEvt->GetTimeStamp(PMM2)*10);
85  fHistInfo->SetBinContent(3,timestamp);
86  int imes;
87  int esize = anaEvt->GetHeader()->eventSize;
88  // int ievnum = anaEvt->GetHeader()->eventNumb;
89  // Info("process","ievnum = %d, esize = %d",ievnum,esize);
90  Pmm2MesVect * pm = anaEvt->GetMesurements();
91 
92 
93  fHistSize->Fill(esize);
94  //int itsold = 0;
95  int hit[16];
96  for(int ch = 0; ch<16; ch++) hit[ch] = 0;
97  for(imes=0;imes<esize;imes++) {
98  // Pmm2MesVect &m = *pm;
99 
100  int ch = pm->at(imes).getChNum(); // channel
101  hit[ch] = 1;
102  rate[ch] += 1;
103  //fHistRatePmm2->Fill(ch);
104  fHistRatePmm2Tot->Fill(ch);
105  }
106  int nScint = (hit[1] || hit[2])
107  + (hit[3] || hit[4])
108  + (hit[5] || hit[6])
109  + (hit[7] || hit[8])
110  + (hit[9] || hit[10])
111  + (hit[11] || hit[12]);
112 
113  fHistNscint->Fill(nScint);
114 
115  bool trigger = nScint > 1;
116  if(trigger){
117  fHistSizeTrig->Fill(esize);
118  }
119 
120  for(int ch = 0; ch<16; ch++){
121  int ch2 = ch%2 ? ch+1 : ch-1;
122  if(trigger){
123  if(hit[ch2]){
124  if(!hit[ch])
125  fHistMissed->Fill(ch);
126  fHistTriggered->Fill(ch);
127  }
128  }
129  }
130 
131  TString str("");
132  str += nEvents;
133  str += " : ";
134  for(imes=0;imes<esize;imes++) {
135  // i cann't use operator[] on pointer
136  Pmm2MesVect &m = *pm;
137 
138  int ch = pm->at(imes).getChNum(); // channel
139  int iadc = m[imes].getCharge(); // Charge in adc counts
140  int trigtype= m[imes].GetNU0(); // Fine Time
141 
142  str += ch;
143  str += " ";
144  str += iadc;
145  str += " ";
146  str += trigtype;
147  str += " | ";
148 
149  if(ch<0 || ch>15){
150  Info("process","Unknown PMM2 channel %d",ch);
151  continue;
152  }
153  fHistSpectrum[ch]->Fill(iadc);
154  fHistSpectrum2D->Fill(ch,iadc);
155  if(trigger){
156  fHistSpectrumTrig[ch]->Fill(iadc);
157  fHistSpectrumTrig2D->Fill(ch,iadc);
158  }
159  } // Digi Loop
160  if(gHarpoDebug>1)
161  Info("process"," %s",str.Data());
162 
163  // if(timestamp<itsold-1){
164  // Info("process","%d - %d = %d",timestamp, itsold, timestamp - itsold);
165  // Info("","************************************************");
166  // startRun = kTRUE;
167  // }
168 
169  for(int ch1 = 0; ch1<16; ch1++){
170  for(int ch2 = 0; ch2<16; ch2++){
171  if(hit[ch1] && hit[ch2]){
172  fHistCoincidence->Fill(ch1,ch2);
173  }
174  if(hit[ch1])
175  fHistCoincidenceNorm->Fill(ch1,ch2);
176  }
177  }
178 
179 
180  if(timestamp>timestampold+fRateSample*1e8){ // every fRateSample seconds
181  Double_t freq = 1e8/(timestamp-timestampold); // Hz
182  timestampold = timestamp;
183  Double_t time = timestamp/1e8; // seconds
184  // fTimeTot += time;
185  Double_t ratetot = 0;
186  for(Int_t i = 0; i<16; i++){
187  // if(fHistRatePmm2->GetBinContent(i+1) == 0) continue;
188  // gRatePmm2[i]->SetPoint(gRatePmm2[i]->GetN(),time,fHistRatePmm2->GetBinContent(i+1)*freq);
189  // gRatePmm2[i]->SetPointError(gRatePmm2[i]->GetN()-1,fRateSample/2,TMath::Sqrt(fHistRatePmm2->GetBinContent(i+1))*freq);
190  // ratetot += fHistRatePmm2->GetBinContent(i+1);
191  // if(rate[i] <= 0) continue;
192  if(rate[i]){
193  gRatePmm2[i]->SetPoint(gRatePmm2[i]->GetN(),time,rate[i]*freq);
194  gRatePmm2[i]->SetPointError(gRatePmm2[i]->GetN()-1,fRateSample/2,TMath::Sqrt(rate[i])*freq);
195  ratetot += rate[i];
196  }
197  fHistRatePmm2->SetBinContent(i+1,rate[i]*freq);
198  // fHistRatePmm2->SetBinContent(i+1,rate[i]+ fHistRatePmm2->GetBinContent(i+1));
199  fHistRatePmm2->SetBinError(i+1,TMath::Sqrt(rate[i])*freq);
200  rate[i] = 0;
201  }
202  //Info("process","Ratetot %g",ratetot);
203  // fHistRatePmm2->Scale(freq);
204  // fHistRatePmm2->Reset();
205  gRatePmm2Tot->SetPoint(gRatePmm2Tot->GetN(),time,ratetot*freq);
206  gRatePmm2Tot->SetPointError(gRatePmm2Tot->GetN()-1,fRateSample/2,TMath::Sqrt(ratetot)*freq);
207  }
208 
209  fTimeTot = timestamp;
210  gTimeVsEvent->SetPoint(gTimeVsEvent->GetN(),nEvents,timestamp/1e8);
211 
212  if(fDisplay%2 == 0 && (nEvents-1)%10 == 0)
213  mfile->Update();
214 
215 
216 }
217 
219 {
220 
221  // Initialise histograms here
222 
223  fTimeTot = 0;
224 
225  fSaveRate = 1;
226  Long64_t saveRate = 0;
227  if ( ! gHConfig->Lookup("monitor.SaveRatePmm2",saveRate) )
228  Info("InitCfg","Use default fSaveRate %d",fSaveRate);
229  else
230  fSaveRate = saveRate;
231  if(fSaveRate<1) fSaveRate = 1;
232 
233 
234  fDisplay = 0;
235  Long64_t display = 0;
236  if ( ! gHConfig->Lookup("monitor.displayPmm2",display) )
237  Info("Init","Use default address %d",fDisplay);
238  else
239  fDisplay = display;
240 
241  if(fDisplay%2 == 0){
242  Long64_t fAddress = 0x7ff3ab9f9000;
243  Long64_t address = 0;
244  if ( ! gHConfig->Lookup("monitor.addressPmm2",address) )
245  Info("Init","Use default address 0x%llx",fAddress);
246  else{
247  fAddress = address;
248  TMapFile::SetMapAddress(fAddress);
249  }
250  // TMapFile::SetMapAddress(0x7ff3ab9f9000);
251  mfile = TMapFile::Create("/tmp/harpoPmm2.map","RECREATE", 10000000,
252  "Memory mapped file with monitoring histograms");
253  }
254 
255  for(Int_t ch = 0; ch<16; ch++){
256  fHistSpectrum[ch] = new TH1F(Form("fHistSpectrum%d",ch),"; signal [ADC]",1024,0,1024);
257  fHistSpectrum[ch]->SetLineColor(51 + ch*49./15);
258 
259  fHistSpectrumTrig[ch] = new TH1F(Form("fHistSpectrumTrig%d",ch),"",1024,0,1024);
260  fHistSpectrumTrig[ch]->SetLineColor(51 + ch*49./15);
261  }
262  fHistSpectrum2D = new TH2F("fHistSpectrum2D","; channel; signal [ADC]",16,0,16,1024,0,1024);
263  fHistSize = new TH1F("fHistSize","; Number of PM hit",16,0,16);
264 
265  fHistSpectrumTrig2D = new TH2F("fHistSpectrumTrig2D","",16,0,16,1024,0,1024);
266  fHistSizeTrig = new TH1F("fHistSizeTrig","",16,0,16);
267 
268 
269  fHistInfo = new TH1F("fHistInfo","",10,0,10);
270  fHistNscint = new TH1F("fHistNscint","",6,0,6);
271  fHistMissed = new TH1F("fHistMissed","; channel; efficiency",16,0,16);
272  fHistTriggered = new TH1F("fHistTriggered","; channel; efficiency",16,0,16);
273  fHistCoincidence = new TH2F("fHistCoincidence","",16,0,16,16,0,16);
274  fHistCoincidenceNorm = new TH2F("fHistCoincidenceNorm","",16,0,16,16,0,16);
275  fHistRatePmm2 = new TH1F("fHistRatePmm2","; channel; rate",16,0,16);
276  fHistRatePmm2Tot = new TH1F("fHistRatePmm2Tot","; channel; rate",16,0,16);
277 
278 
279  for(Int_t i = 0; i<16; i++){
280  gRatePmm2[i] = new TGraphErrors();
281  if(fDisplay%2 == 0)
282  mfile->Add(gRatePmm2[i],Form("gRatePmm2_%d",i));
283  rate[i] = 0;
284  }
285  timestampold = 0;
286  gRatePmm2Tot = new TGraphErrors();
287  if(fDisplay%2 == 0)
288  mfile->Add(gRatePmm2Tot,"gRatePmm2Tot");
289 
290  fRateSample = 200;
291  Double_t rateSample = 0;
292  if ( ! gHConfig->Lookup("monitor.RateSample",rateSample) )
293  Info("InitCfg","Use default fRateSample %g",fRateSample);
294  else
295  fRateSample = rateSample;
296 
297  gTimeVsEvent = new TGraphErrors();
298 
299  itscorr = 0;
300  itsold = 0;
301  itsold2 = 0;
302  nEventsTrig = 0;
303  startRun = kFALSE;
304 
305  if(fDisplay%2==0)
306  mfile->Print();
307 
308 
309 
310 }
311 
312 
313 
314 void HarpoAnalysePmm2Monitor::Save(char * /* mode */)
315  {
316 
317 
318  if(fDisplay==0) return;
319 
320 
321  if(gHarpoDebug>0) Info("Save","Displaying histograms");
322 
323  gStyle->SetOptStat(0);
324 
325  TLegend* lCh = new TLegend(0.75,0.4,0.9,0.9);
326  Int_t nSignal = 0;
327  for(Int_t ch = 0; ch<16; ch++){
328  fHistSpectrum[ch]->Rebin(8);
329  fHistSpectrumTrig[ch]->Rebin(8);
330  lCh->AddEntry(fHistSpectrum[ch],Form("Ch %d",ch));
331  nSignal += fHistSize->GetBinContent(ch+1)*ch;
332  }
333 
334  TLegend* l = new TLegend(0.6,0.6,0.9,0.9);
335 
336 
337  // TCanvas* ct0 = new TCanvas("cPmm2","Monitor PMm2",0,0,1200,800);
338  // ct0->Clear();
339  // ct0->Divide(2,2);//,0.001,0.001);
340 
341  // TH1F* hDummyEvt = new TH1F("hDummyEvt",";event number; time stamp",nEvents/10,0,nEvents);
342  // hDummyEvt->SetMaximum(16777216);
343  // ct0->cd(1);
344  // hDummyEvt->DrawCopy();
345  // fGraphTimeVsEvent->Draw("Psame");
346 
347  // ct0->cd(2);
348  // fHistTime2D->Draw("colz");
349  // ct0->GetPad(4)->SetLogz();
350 
351  // ct0->cd(3);
352  // hDummyEvt->DrawCopy();
353  // fGraphTimeVsEventTrig->Draw("Psame");
354 
355  // ct0->cd(4);
356  // fHistTimeTrig2D->Draw("colz");
357  // ct0->GetPad(4)->SetLogz();
358 
359  // ct0->Update();
360  TCanvas* ct1 = new TCanvas("cPmm2_1","Monitor PMm2",0,0,1200,800);
361  ct1->Clear();
362  ct1->Divide(2,2);//,0.001,0.001);
363 
364  TH1F* hThr = new TH1F("hThr","",16,0,16);
365  TH1F* hMean = new TH1F("hMean","",16,0,16);
366  TH1F* hTruncMax = new TH1F("hTruncMax","",16,0,16);
367  TH1F* hTruncMin = new TH1F("hTruncMin","",16,0,16);
368  TH1F* hSat = new TH1F("hSat","",16,0,16);
369 
370  ct1->cd(1);
371  Double_t max = 1;
372  Double_t meanThr = 0, normThr = 0;
373  for(Int_t ch = 0; ch<16; ch++){
374  if(fHistSpectrum[ch]->GetMaximum()>max)
375  max = fHistSpectrum[ch]->GetMaximum();
376  if(ch)
377  fHistSpectrum[ch]->Draw("same");
378  else
379  fHistSpectrum[ch]->Draw();
380 
381  Double_t thr = GetThr(fHistSpectrum[ch]);
382  if(!thr) continue;
383  meanThr += thr;
384  normThr++;
385  // TLine* line = new TLine(thr,0.5,thr,1.1*max);
386  // line->SetLineStyle(2);
387  // line->SetLineColor(fHistSpectrum[ch]->GetLineColor());
388  // line->Draw();
389  hThr->SetBinContent(ch+1,thr);
390  }
391  // fHistSpectrum[0]->GetYaxis()->SetRangeUser(0,1.1*max);
392  fHistSpectrum[0]->SetMaximum(1.1*max);
393  fHistSpectrum[0]->SetMinimum(0.5);
394  ct1->GetPad(1)->SetLogy();
395  lCh->Draw();
396 
397  ct1->cd(2);
398  fHistSpectrum2D->Draw("colz");
399  ct1->GetPad(2)->SetLogz();
400  hThr->SetLineWidth(3);
401  hThr->SetLineStyle(2);
402  hThr->Draw("same");
403  TLatex* latex = new TLatex();
404  latex->SetTextFont(132);
405  latex->SetTextAlign(12);
406  latex->SetTextSize(0.07);
407  latex->DrawLatex(1,900,Form("mean Thr %g",meanThr/normThr));
408 
409  ct1->cd(3);
410  max = 1;
411  Double_t meanMean = 0, normMean = 0;
412  for(Int_t ch = 0; ch<16; ch++){
413  if(fHistSpectrumTrig[ch]->GetMaximum()>max)
414  max = fHistSpectrumTrig[ch]->GetMaximum();
415  if(ch)
416  fHistSpectrumTrig[ch]->Draw("same");
417  else
418  fHistSpectrumTrig[ch]->Draw();
419 
420 
421  Double_t thr = GetThr(fHistSpectrum[ch]);
422  if(!thr) continue;
423  // TLine* line = new TLine(thr,0.5,thr,1.1*max);
424  // line->SetLineWidth(2);
425  // line->SetLineStyle(2);
426  // line->SetLineColor(fHistSpectrum[ch]->GetLineColor());
427  // line->Draw();
428 
429  Double_t truncMax = 0, truncMin = 0;
430  Double_t mean = GetTruncMean(fHistSpectrumTrig[ch],truncMin,truncMax,0.1,0.6);
431  Info("Save","mean ch %d: %g",ch,mean);
432  meanMean += mean;
433  normMean++;
434  hMean->SetBinContent(ch+1,mean);
435  hTruncMin->SetBinContent(ch+1,truncMin);
436  hTruncMax->SetBinContent(ch+1,truncMax);
437  // TLine* lineM = new TLine(truncMax,0.5,truncMax,1.1*max);
438  // lineM->SetLineWidth(2);
439  // lineM->SetLineColor(fHistSpectrum[ch]->GetLineColor());
440  // lineM->Draw();
441 
442 
443  fHistSpectrumTrig[ch]->GetXaxis()->SetRangeUser(150,1024);
444  Double_t nEvTrig = fHistSpectrumTrig[ch]->Integral();
445  fHistSpectrumTrig[ch]->GetXaxis()->SetRangeUser(600,1024);
446  Double_t nEvSat = fHistSpectrumTrig[ch]->Integral();
447  fHistSpectrumTrig[ch]->GetXaxis()->SetRangeUser(0,1024);
448 
449  if(nEvTrig)
450  hSat->SetBinContent(ch+1,nEvSat/nEvTrig);
451 
452 
453  // if(nEvTrig)
454  // Info("Save","Taux saturation ch %d: %g", ch, nEvSat/nEvTrig);
455 
456  }
457 
458  // fHistSpectrum[0]->GetYaxis()->SetRangeUser(0,1.1*max);
459  fHistSpectrumTrig[0]->SetMaximum(1.1*max);
460  fHistSpectrumTrig[0]->SetMinimum(0.5);
461  ct1->GetPad(3)->SetLogy();
462  lCh->Draw();
463 
464  ct1->cd(4);
465  fHistSpectrumTrig2D->Draw("colz");
466  ct1->GetPad(4)->SetLogz();
467  hMean->SetLineWidth(3);
468  hMean->Draw("same");
469  hTruncMin->SetLineStyle(2);
470  hTruncMin->SetLineWidth(3);
471  hTruncMin->Draw("same");
472  hTruncMax->SetLineStyle(2);
473  hTruncMax->SetLineWidth(3);
474  hTruncMax->Draw("same");
475  latex->DrawLatex(1,900,Form("mean Mean %g",meanMean/normMean));
476 
477  TCanvas* ct2 = new TCanvas("cPmm2_2","Monitor time PMm2",0,0,1200,800);
478  ct2->Divide(2,2);
479  ct2->cd(1);
480  Info("Save","fTimeTot %g, timestampold %g",fTimeTot,timestampold);
481  Double_t freq = 1e8/(fTimeTot-timestampold); // Hz
482  fTimeTot /= 1e8;
483  Double_t ratetot = 0;
484  for(Int_t i = 0; i<16; i++){
485  gRatePmm2[i]->SetPoint(gRatePmm2[i]->GetN(),fTimeTot,rate[i]*freq);
486  gRatePmm2[i]->SetPointError(gRatePmm2[i]->GetN()-1,fRateSample/2,TMath::Sqrt(rate[i])*freq);
487  ratetot += rate[i];
488  fHistRatePmm2->SetBinContent(i+1,rate[i]*freq);
489  fHistRatePmm2->SetBinError(i+1,TMath::Sqrt(rate[i])*freq);
490  rate[i] = 0;
491  }
492  gRatePmm2Tot->SetPoint(gRatePmm2Tot->GetN(),fTimeTot,ratetot*freq);
493  gRatePmm2Tot->SetPointError(gRatePmm2Tot->GetN()-1,fRateSample/2,TMath::Sqrt(ratetot)*freq);
494  TH1F* hDummyTime = new TH1F("hDummyTime",";time [s]; rate [Hz]",1000,0,fTimeTot);
495  hDummyTime->SetMaximum(gRatePmm2Tot->GetYaxis()->GetXmax());
496  // fGraphTimeVsEventCorr->GetHistogram()->SetTitle(";timestamp;event");
497  hDummyTime->DrawCopy();
498  gRatePmm2Tot->Draw("Psame");
499  for(Int_t i = 0; i<16; i++){
500  if(!gRatePmm2[i]->GetN()) continue;
501  Int_t color = 51 + i*49./17;
502  gRatePmm2[i]->SetLineColor(color);
503  gRatePmm2[i]->Draw("PSAME");
504  }
505 
506  ct2->cd(3);
507  fHistSize->Draw();
508  fHistSizeTrig->SetLineColor(kRed);
509  fHistSizeTrig->Draw("same");
510  l->AddEntry(fHistSize,"All events","L");
511  l->AddEntry(fHistSizeTrig,"Triggered events","L");
512  l->Draw();
513 
514 
515  Double_t N3 = fHistSizeTrig->GetBinContent(4);
516  Double_t N4 = fHistSizeTrig->GetBinContent(5);
517  Double_t N5 = fHistSizeTrig->GetBinContent(6);
518 
519  Double_t y = 0.5*fHistSize->GetMaximum(), x = 8;
520  Double_t dy = 0.1*fHistSize->GetMaximum();
521  latex->DrawLatex(x,y,Form("N_{4}/(N_{3}+N_{4}) = %.2g",N4/(N3+N4)));
522  y -= dy;
523  latex->DrawLatex(x,y,Form("N_{3}/(N_{3}+N_{4}) = %.2g",N3/(N3+N4)));
524  y -= dy;
525  latex->DrawLatex(x,y,Form("N_{5}/(N_{5}+N_{4}) = %.2g",N5/(N5+N4)));
526  y -= dy;
527  latex->DrawLatex(x,y,Form("N_{trig}/N_{tot} = %.2g",fHistSizeTrig->GetEntries()/fHistSize->GetEntries()));
528  y -= dy;
529 
530  ct2->cd(4);
531  fHistCoincidenceNorm->Scale(1./fHistCoincidenceNorm->GetMaximum());
532  for(int ch1 = 0; ch1<16; ch1++){
533  for(int ch2 = 0; ch2<16; ch2++){
534  if(fHistCoincidenceNorm->GetBinContent(ch1+1,ch2+1) == 0)
535  fHistCoincidenceNorm->SetBinContent(ch1+1,ch2+1,1);
536  }
537  }
539  fHistCoincidence->Draw("colz");
540  ct2->GetPad(4)->SetLogz();
541  ct2->cd(2);
542  // fHistCoincidenceNorm->Draw("colz");
543  // fHistNscint->Draw();
544  // hSat->SetLineColor(kRed);
545  // hSat->Draw("same");
546  // fHistRatePmm2Tot->DrawCopy();
547  // fHistRatePmm2->DrawCopy("same");
548 
549  TH1F* fHistEfficiency = (TH1F*)fHistTriggered->Clone();
550  fHistEfficiency->SetTitle("PM efficiency;Channel;Efficiency [%]");
551  fHistEfficiency->Add(fHistMissed,-1);
552  fHistEfficiency->Divide(fHistTriggered);
553  fHistEfficiency->Scale(100);
554  fHistEfficiency->SetMinimum(0);
555  fHistEfficiency->SetMaximum(100);
556  MakeNice1dHisto(fHistEfficiency,ct2->GetPad(2));
557 
558 
559 
560  Double_t scaletmp = 80./fHistRatePmm2Tot->GetMaximum();
561  fHistRatePmm2Tot->Scale(scaletmp); // Nevents -> arbitrary
562  fHistRatePmm2Tot->SetLineColor(kRed);
563  fHistRatePmm2->SetLineColor(kRed+2);
564  fHistRatePmm2->SetLineStyle(2);
565  fHistRatePmm2->Scale(fTimeTot); // Hz -> Nevents
566  fHistRatePmm2->Scale(scaletmp); // Nevents -> arbitrary
567  // draw an axis on the right side
568  TGaxis *axis = new TGaxis(16,0,
569  16,100,
570  0,100./scaletmp/fTimeTot,510,"+L");
571  axis->SetLineColor(kRed);
572  axis->SetTextColor(kRed);
573  axis->SetLabelColor(kRed);
574  axis->SetTitle("Rate [Hz]");
575  axis->SetTitleSize(0.07);
576  axis->SetTitleOffset(0.7);
577  axis->SetTitleFont(132);
578  axis->SetLabelFont(132);
579  axis->SetLabelSize(0.06);
580  axis->Draw();
581  MakeNiceHisto(fHistRatePmm2Tot,ct2->GetPad(2),"same");
582  MakeNiceHisto(fHistRatePmm2,ct2->GetPad(2),"same");
583  ct2->GetPad(2)->SetRightMargin(0.12);
584 
585 
586  ct2->cd(3);
587  gTimeVsEvent->Draw("A*");
588 
589  TString * hstFile = gHConfig->GetHistFile();
590  if ( hstFile == NULL ) {
591  std::cout << gHConfig->GetProgramName() << " " <<
592  "No Hist File name given, use default" << std::endl;
593  hstFile = new TString(Form("outputs/pmm2%lli.root",gHConfig->GetRunNo()));
594  }
595 
596 
597  TFile *hf = new TFile(hstFile->Data(),"RECREATE");
598  // Save histograms here
599 
600  for(Int_t ch = 0; ch<16; ch++){
601  fHistSpectrum[ch]->Write();
602  fHistSpectrumTrig[ch]->Write();
603  }
604  fHistSpectrum2D->Write();
605  // fHistTime2D->Write();
606  fHistSize->Write();
607 
608  fHistSpectrumTrig2D->Write();
609  // fHistTimeTrig2D->Write();
610  fHistSizeTrig->Write();
611 
612 
613  fHistNscint->Write();
614  fHistCoincidence->Write();
615  fHistCoincidenceNorm->Write();
616 
617 
618 
619  hf->Close();
620  printf("fNewFile %s closed\n", hstFile->Data() );
621 
622  }
623 
624 
626 {
627  if(h->GetEntries()<10) return 0;
628 
629  h->GetXaxis()->SetRangeUser(150,1000);
630  Int_t maxbin = h->GetMaximumBin();
631  Double_t max = h->GetBinContent(maxbin);
632  h->GetXaxis()->SetRangeUser(0,1024);
633 
634  Int_t nbins = h->GetXaxis()->GetNbins();
635 
636  Int_t i = 0;
637  while(i<nbins){
638  i++;
639  if(h->GetXaxis()->GetBinCenter(i)<150) continue;
640  Double_t val = h->GetBinContent(i);
641  if(val>max/2) break;
642  }
643 
644  Double_t thr = 0, W = 0;
645  for(Int_t k = -1; k<2; k++){
646  Double_t w = h->GetBinContent(i+k) - h->GetBinContent(i+k-1);
647  thr += w*h->GetXaxis()->GetBinCenter(i+k);
648  W += w;
649  }
650  thr = h->GetXaxis()->GetBinCenter(i);
651  W = 1;
652 
653  // if(W)
654  // Info("GetThr","%g / %g = %g",thr, W, thr/W);
655 
656  if(W)
657  return thr/W;
658  else
659  return -1;
660 
661 }
662 
663 Double_t HarpoAnalysePmm2Monitor::GetTruncMean(TH1F* h, Double_t &min, Double_t &max, Double_t tl, Double_t th)
664 {
665 
666  Int_t nbins = h->GetXaxis()->GetNbins();
667  Int_t ntot = h->GetEntries();
668  Int_t nt = 0, norm =0;
669  Double_t truncmean = 0;
670 
671  // TArrayD* arr = new TArrayD(ntot);
672  // Int_t l = 0;
673  min = 150;
674  for(Int_t i = 1; i<=nbins; i++){
675  Double_t q = h->GetXaxis()->GetBinCenter(i);
676  Int_t n = h->GetBinContent(i);
677  nt += n;
678  if(nt>th*ntot) break;
679  if(nt<tl*ntot){
680  min = q;
681  continue;
682  }
683  if(h->GetXaxis()->GetBinCenter(i)<150) {}; // ??? empty if ?????
684  truncmean += q*n;
685  norm += n;
686  max = q;
687  // for(Int_t k = 0; k<n; k++)
688  // arr->AddAt(q,l++);
689  }
690 
691  return truncmean/norm;
692  // return TruncMean(arr,tl,th);
693 }
694 
695 
696 Double_t HarpoAnalysePmm2Monitor::TruncMean(TArrayD* vect, Double_t tl, Double_t th)
697 {
698  //
699  // Calculates the truncated mean mean of the non zero value in vect
700  // The truncation is done on the 100*tl% lowest and 100*(1-th) highest value
701  //
702  // debug(2,"truncated mean");
703 
704 
705  Int_t size = vect->GetSize();
706  Double_t truncMean = 0;
707  Int_t* index = new Int_t[size];
708  TMath::Sort(size,vect->GetArray(),index,kFALSE);
709  Int_t t = 0, tLow, tHigh;
710 
711 
712  while(vect->At(index[t])<10&&t<size-1) t++;
713  tLow = TMath::FloorNint(t + (size - t)*tl);
714  tHigh = TMath::FloorNint(t + (size - t)*th);
715 
716  for(Int_t tind = tLow; tind<tHigh; tind++) truncMean += vect->At(index[tind]);
717  delete[] index;
718  if(tHigh-tLow) {
719  return truncMean/(tHigh-tLow);
720  }
721  else return 0;
722 }
Dcc Plane Y.
Definition: HarpoDet.h:20
TString * GetProgramName()
Get Program Name.
Definition: HarpoConfig.h:105
Long64_t GetRunNo()
Set Run Number.
Definition: HarpoConfig.h:127
Monitor Pmm2 data for online GUI.
Bool_t isExist(ULong_t det)
Detecror date exist //! Number of Real Detectors.
Definition: HarpoDetSet.h:33
UInt_t eventSize
Raw Event size.
Definition: HarpoDetEvent.h:28
Long_t GetEvtNo()
Get Event Number.
virtual void print()
FullEvent Header not scecific to the detectors The class is ....
void MakeNice1dHisto(TH1 *hist, TVirtualPad *c1, const char *opt, Bool_t copy)
Double_t GetTruncMean(TH1F *h, Double_t &min, Double_t &max, Double_t tl=0., Double_t th=0.6)
virtual void print()
Double_t TruncMean(TArrayD *vect, Double_t tl=0., Double_t th=0.6)
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
HarpoDetEvent * GetDetEvent(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:93
Pmm2MesVect * GetMesurements()
Return pointer to decoded data.
Definition: Pmm2Event.cxx:78
TVirtualPad * MakeNiceHisto(TH1 *hist, TVirtualPad *c1, const char *opt, Bool_t copy)
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
Bool_t Lookup(const char *path, Bool_t &val)
Lookup function for scalar values.
A class store HARPO raw PMM2 event buffer and header. End provide access metods to the row data...
Definition: Pmm2Event.h:19
virtual const EventHeader_t * GetHeader() const
Definition: HarpoDetEvent.h:38
HarpoEventHeader * GetHeader()
Definition: HarpoEvent.cxx:80
HarpoEvent * fEvt
Definition: HarpoAnalyse.h:70
ULong_t nEvents
Definition: HarpoAnalyse.h:75
Int_t getChNum() const
Definition: Pmm2Mes.h:28
TString * GetHistFile()
Get Name of Histogram output file.
Definition: HarpoConfig.h:100
const ULong_t gkNDetectors
Definition: HarpoDet.h:14
ULong_t GetTimeStamp(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:149
HarpoConfig * gHConfig
A list of all mesurements in one Event for Pmm2 v2 card The class is place holder for all unpacked me...
Definition: Pmm2MesList.h:19
Pmm2Mes at(ULong_t idx)
Definition: Pmm2MesList.h:37
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71
Double_t GetThr(TH1F *h)
Redefine empty default.