HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoAnalyseMonitorNew.cxx
Go to the documentation of this file.
1 //
2 // File HarpoAnalyseMonitorNew.cxx
3 //
12 #include "HarpoAnalyseMonitorNew.h"
13 #include "HarpoConfig.h"
14 #include "HarpoDetSet.h"
15 //#include "HarpoDetSet.h"
16 #include "HarpoDccEvent.h"
17 #include "Pmm2Event.h"
18 #include "Pmm2Header.h"
19 #include "Pmm2Status.h"
20 #include "HarpoEvent.h"
21 
22 #include "TROOT.h"
23 #include "TStyle.h"
24 #include "TApplication.h"
25 #include "TFile.h"
26 #include "TCanvas.h"
27 #include "TLatex.h"
28 #include "TGraph.h"
29 #include "TMath.h"
30 #include "TBox.h"
31 #include "TMapFile.h"
32 #include "TLinearFitter.h"
33 #include "TRandom.h"
34 #include "TSystem.h"
35 
36 #include <cstdlib>
37 #include <cstring>
38 #include <cassert>
39 #include <iostream>
40 
41 ClassImp(HarpoAnalyseMonitorNew)
42 
43 
44 
45 enum HarpoMonitorEventType {
46  E_CREATED,
47  E_TRAVERSING,
48  E_EMPTY,
49  E_SATURATED,
50  E_OTHER
51 };
52 
53 
55 {
56  UInt_t nd; // number of detectors
58 
59  assert(hdr != NULL);
60  hdr->print();
61 
62  for (nd = 0; nd < gkNDetectors; nd++) {
63  // if (fEvt->isdataExist(nd)) {
64  HarpoDccMap *plane = fEvt->GetDccMap(nd);
65  if (plane != NULL )plane->print();
66  }
67 }
68 
70 {
71  nEvents++;
72  if(nEvents%100 == 0)
73  // std::cout << " Processing Event " << nEvents<< std::endl;
74  Info("process","Event %ld",nEvents);
75  if(nEvents%100 == 0)
76  Save();
77  hTev[0]->Reset();
78  hTev[1]->Reset();
79  hTevZs[0]->Reset();
80  hTevZs[1]->Reset();
81  hQev[0]->Reset();
82  hQev[1]->Reset();
83  hQevZs[0]->Reset();
84  hQevZs[1]->Reset();
85  //hInfo->Reset();
86  hPmm2->Reset();
87 
88  Double_t qtot[2] = {-1,-1};
89  // Double_t qtb[NADC][2];
90  // Int_t npix = 0, nch = 0, ntb = 0;
91  // for(Int_t ndet=0;ndet<gkNDetectors;ndet++) {
92  // Int_t qmin = 10000, qmax = 300000;
93  // Double_t tmin = 150, lTpc = 200;
94  Double_t timestamp = -1;
95  //const Int_t TRIG_TT = 0;
96 
97  Bool_t isTT = false;
98 
99  hInfo->SetBinContent(1,gHConfig->GetRunNo());
100  hInfo->SetBinContent(2,fEvt->GetHeader()->GetEvtNo());
101  hInfo->SetBinContent(6,gHConfig->GetSkipEvents()+1);
102  hInfo->SetBinContent(7,gHConfig->GetFromEvent());
103  Int_t triggerType = -1;
104  if(gHDetSet->isExist(PMM2)) {
105  hInfo->SetBinContent(5,fEvt->GetTimeStamp(PMM2));
106  timestamp = fEvt->GetTimeStamp(PMM2)*10;
107 
108 
109 
110  if(nEvents==1){
111 
113  fTriggerTimeTot = 0;
114  for(Int_t i = 0; i<kNtriggerTypes; i++){
115  fTriggerTime[i] = 0;
116  fTriggerDownscaling[i] = 1;
117  if(pmm2Hdr == NULL) continue;
118  Pmm2Status* pmm2Stat = pmm2Hdr->getStatus();
119  if(pmm2Stat == NULL) continue;
120  unsigned int triggerinfo = pmm2Stat->getTrigger(i); // 32bits:
121  // time (16bits * XXXms),
122  // downscaling (16bits)
123  fTriggerTime[i] = triggerinfo/65536;
124  fTriggerDownscaling[i] = triggerinfo%65536;
125  }
126  for(Int_t i = 0; i<kNtriggerTypes; i++)
128  for(Int_t i = 0; i<kNtriggerTypes; i++){
129  Double_t trigCorr = 1.;
130  if(fTriggerTime[i])
131  trigCorr /= fTriggerTime[i]/fTriggerTimeTot;
132  if(fTriggerDownscaling[i])
133  trigCorr *= fTriggerDownscaling[i];
134  hTriggerCorrection->SetBinContent(i+2,trigCorr);
135  Info("Init","Trigger param %d %d => %g",fTriggerTime[i],fTriggerDownscaling[i],trigCorr);
136  }
137  hTriggerCorrection->SetBinContent(1,1);
138  }
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149  Pmm2Event *anaEvt = static_cast<Pmm2Event *>(fEvt->GetDetEvent(PMM2));
150  if(gHarpoDebug>0)
151  std::cout << "pmm2Event: " << anaEvt << std::endl;
152 
153  triggerType = anaEvt->GetTriggerType();
154  //Info("process","** trigger type: %d",triggerType);
155 
156  int imes;
157  int esize = anaEvt->GetHeader()->eventSize;
158  //int ievnum = anaEvt->GetHeader()->eventNumb;
159  //Info("process","ievnum = %d, esize = %d",ievnum,esize);
160  //Info("process","esize = %d",esize);
161  hPmm2Size->Fill(esize);
162  Pmm2MesVect * pm = anaEvt->GetMesurements();
163  int hit[16];
164  for(int ch = 0; ch<16; ch++) hit[ch] = 0;
165  for(imes=0;imes<esize;imes++) {
166  int ch = pm->at(imes).getChNum(); // channel
167  int q = pm->at(imes).getCharge(); // charge
168  //Info("process","ch = %d, q = %d",ch,q);
169  hPmm2->SetBinContent(ch+1,q);
170  hPmm2Spectrum2D->Fill(ch,q);
171  hit[ch] = 1;
172  if(gHarpoDebug>1)
173  std::cout << ch << " ";
174  }
175  if(gHarpoDebug>1)
176  std::cout << std::endl;
177 
178 // #if 0
179 // // FIXME: fake trigger types
180 // triggerType = 7+gRandom->Rndm()*6;
181 
182 // int nScint = (hit[1] && hit[2])
183 // + (hit[3] && hit[4])
184 // + (hit[5] && hit[6])
185 // + (hit[7] && hit[8])
186 // + (hit[9] && hit[10])
187 // + (hit[11] && hit[12]);
188 // if(nScint>1) triggerType = 14;
189 
190  if(hit[3] && hit[4] && hit[5] && hit[6]){
191  if(gHarpoDebug>1)
192  Info("process","TT");
193  isTT = true;
194  hInfo->SetBinContent(9,hInfo->GetBinContent(9)+1);
195  }
196 // if(((hit[1] && hit[2]) ||
197 // (hit[3] && hit[4]) ||
198 // (hit[7] && hit[8]) ||
199 // (hit[9] && hit[10]) ||
200 // (hit[11] && hit[12])) &&
201 // !(hit[5] && hit[6]))
202 // triggerType = 5;
203 
204 // #endif
205 
206 
207  for(int ch = 0; ch<16; ch++){
208  int ch2 = ch%2 ? ch+1 : ch-1;
209  if(hit[ch2]){
210  if(!hit[ch])
211  hPmm2Missed->Fill(ch);
212  hPmm2Triggered->Fill(ch);
213  }
214  }
215 
216  for(int ch1 = 0; ch1<16; ch1++){
217  for(int ch2 = 0; ch2<16; ch2++){
218  // if(hit[ch1] && hit[ch2] && ch1 != ch2){
219  if(hit[ch1] && hit[ch2]){
220  hPmm2Coincidence->Fill(ch1,ch2);
221  }
222  }
223  }
224  }else{
225  for(Int_t ch = 0; ch<16; ch++) hPmm2->SetBinContent(ch+1,-1);
226  }
227 
228 
229 
230  if(gHarpoDebug>0)
231  Info("process","isTT = %d",isTT);
232 
233 
234  HarpoMonitorEventType eventType = E_OTHER;
235  for(Int_t ndet=0;ndet<2;ndet++) {
236  if (gHDetSet->isExist(ndet)) {
237  hInfo->SetBinContent(3+ndet,fEvt->GetTimeStamp(ndet));
238  timestamp = fEvt->GetTimeStamp(ndet);
239  HarpoDccMap * m = fEvt->GetDccMap(ndet);
240  // std::cout << "Event " << nEvents << ", detector " << ndet << " " << m << std::endl;
241  if ( m != NULL ) {
242 
243  hZs[ndet]->Reset();
244  h[ndet]->Reset();
245 
246  if(nEvents<10){
247 
248  Int_t Qnoise = 0;
249  for(Int_t i=0;i<NADC;i++){ //Time bins
250  for(Int_t j=NCHAN;j<NALL;j++){ // Noise Channels
251  Double_t q = m->GetData(j,i);
252  Qnoise += q;
253  }
254  }
255  fIsZs = Qnoise<100*NADC;
256  }
257  h[ndet]->SetTitle(Form("X direction, evt: %li",nEvents));
258 
259  Double_t qTot = 0, qTotZs = 0, Tmin = -10, Xmin = -500, Tmax = -10;
260  for(Int_t i=0;i<NADC;i++){ //Time bins
261  // qtb[i][ndet] = 0;
262  Double_t qTotT = 0, qTotTZs = 0, meanCh = 0;
263  Int_t nCh = 0;
264  for(Int_t j=0;j<NALL;j++){ // Channels
265  Double_t q = m->GetData(j,i);
266  if(q<0) continue;
267  h[ndet]->SetBinContent(i+1,j+1,q);
268  qTotT += q;
269  nCh++;
270  meanCh += q*j;
271  qTot += q;
272  hCh[ndet]->Fill(j+0.5,q);
273  hT[ndet]->Fill(i+0.5,q);
274  hTev[ndet]->Fill(i+0.5,q);
275  hQ[ndet]->Fill(q);
276  hQev[ndet]->Fill(q);
277  //}
278  }
279  if(gHarpoDebug>0)
280  Info("process","TT %d %f",i,qTotT);
281  if(qTotT>0){
282  hQtotT[ndet]->Fill(qTotT);
283  hQtotTev[ndet]->Fill(qTotT);
284  // if(triggerType == TRIG_TT){
285  if(isTT){
286  if(gHarpoDebug>1){
287  Info("process","TT %d %f",i,qTotT);
288  std::cout << i << " " << qTotT << std::endl;
289  }
290  hQvsT_TT[ndet]->Fill(i,qTotT);
291  hQvsT_TT2D[ndet]->Fill(i,qTotT);
292  }
293  meanCh /= qTotT;
294  }
295 
296  // if(!fIsZs){
297 
298  // Int_t Qnoise = 0;
299  // for(Int_t ii=0;i<NADC;i++){ //Time bins
300  // for(Int_t j=NCHAN;j<NALL;j++){ // Noise Channels
301  // Double_t q = m->GetData(j,ii);
302  // if(q<0) continue;
303  // Qnoise += q;
304  // }
305  // }
306  // // Bool_t isZs = Qnoise<100*NADC;
307 
308  // TLinearFitter* fFitCh = new TLinearFitter(1,"pol2","D");
309  // // Double_t qTotT = 0;
310  // TArrayD* valuesTB = new TArrayD(NALL);
311  // for(Int_t j=0;j<NCHAN;j++){ // Channels
312  // Double_t q = m->GetData(j,i);
313  // if(q<0) continue;
314  // valuesTB->AddAt(q,j);
315  // }
316  // Double_t noiseTB = TruncMean(valuesTB,0.16,0.84);
317  // //if(i>490) Info("process","t = %d, noiseTB = %g",i,noiseTB);
318  // TGraph* gMinusCh = new TGraph();
319  // for(Int_t j=0;j<NCHAN;j++){ // Channels
320  // Double_t q = m->GetData(j,i);
321  // q -= noiseTB;
322  // m->SetData(j,i,q);
323  // gMinusCh->SetPoint(gMinusCh->GetN(),j,q);
324  // }
325  // fFitCh->AssignData(gMinusCh->GetN(), 1, gMinusCh->GetX(), gMinusCh->GetY());
326  // fFitCh->Eval();
327  // delete gMinusCh;
328  // Double_t mean = 0, rms = 0;
329  // Int_t nnoise = 0;
330  // for(Int_t j=0;j<NCHAN;j++){ // Channels
331  // Double_t q = m->GetData(j,i);
332  // if(q<0) continue;
333  // q -= fFitCh->GetParameter(0) + j*fFitCh->GetParameter(1) + j*j*fFitCh->GetParameter(2);
334  // m->SetData(j,i,q);
335  // if(q<100){
336  // mean += q;
337  // rms += q*q;
338  // nnoise++;
339  // }
340  // }
341  // rms = TMath::Sqrt(rms/nnoise - mean*mean/nnoise/nnoise);
342  // for(Int_t j=0;j<NALL;j++){ // Channels
343  // Double_t q = m->GetData(j,i);
344  // if(q<0) continue;
345  // if(q>2*rms){
346  // m->SetData(j,i,q);
347  // }else{
348  // m->SetData(j,i,0);
349  // }
350  // }
351  // fFitCh->Delete();
352  // }
353 
354 
355 
356  Double_t Qcl = 0, Xcl = 0;
357  for(Int_t j=0;j<NCHAN;j++){ // Channels
358  Double_t q = m->GetData(j,i);
359  if(q<0) continue;
360  if(q>40){
361  Qcl += q;
362  Xcl += q*j;
363  }
364  //if(i>250 && j==200) Info("process","t = %d, ch = %d, Q = %g",i,j,q);
365  hCumul[ndet]->Fill(i+0.5,j+0.5,q);
366  hZs[ndet]->SetBinContent(i+1,j+1,q);
367  qTotTZs += q;
368  qTotZs += q;
369  hChZs[ndet]->Fill(j+0.5,q);
370  hTZs[ndet]->Fill(i+0.5,q);
371  hTevZs[ndet]->Fill(i+0.5,q);
372  hQZs[ndet]->Fill(q);
373  hQevZs[ndet]->Fill(q);
374  }
375  if(Qcl>250 && Tmin == -10 && i>5){
376  Tmin = i;
377  Xmin = Xcl/Qcl;
378  }
379  if(Qcl>250 && Tmin > 0) Tmax = i;
380  hQtotTZs[ndet]->Fill(qTotTZs);
381  //hQtotTZs[ndet]->Fill(Qcl);
382  hQtotTevZs[ndet]->Fill(qTotTZs);
383  }
384  hTmin[ndet]->Fill(Tmin);
385  hTmax[ndet]->Fill(Tmax);
386  gXTmin[ndet]->SetPoint(gXTmin[ndet]->GetN(),Tmin,Xmin);
387 
388  hQtot[ndet]->Fill(qTot);
389  hQtotZs[ndet]->Fill(qTotZs);
390  qtot[ndet] = qTot;
391  if(Tmin>fTmin) eventType = E_CREATED;
392  if(Tmax-Tmin>fLTpc) eventType = E_TRAVERSING;
393  // if(triggerType == TRIG_TT)
394  if(isTT)
395  hTdrift_TT[ndet]->Fill(Tmax-Tmin);
396  } else {
397  std::cout << "No Data Map for plane "<< ndet << std::endl;
398  }
399  }
400  }
401 
402  if(qtot[0]>fQmax || qtot[1]>fQmax) eventType = E_SATURATED;
403  if(qtot[0]<fQmin && qtot[1]<fQmin) eventType = E_EMPTY;
404 
405  hInfo->SetBinContent(8,triggerType);
406  //Info("process","trigger type: %d",triggerType);
407  switch(eventType){
408  case E_CREATED:
409  hTriggerCreated->Fill(triggerType);
410  fNcreated[triggerType+1]++;
411  break;
412  case E_TRAVERSING:
413  hTriggerTraversing->Fill(triggerType);
414  fNtraversing[triggerType+1]++;
415  break;
416  case E_EMPTY:
417  hTriggerEmpty->Fill(triggerType);
418  fNempty[triggerType+1]++;
419  break;
420  case E_SATURATED:
421  hTriggerSaturated->Fill(triggerType);
422  fNsaturated[triggerType+1]++;
423  break;
424  case E_OTHER:
425  hTriggerOther->Fill(triggerType);
426  fNother[triggerType+1]++;
427  break;
428  }
429 
430 
431  hDeadTime[triggerType+1]->Fill((timestamp-timestampprev)*1e-5);
432  timestampprev = timestamp;
433 
434  nSamples++;
435  qtotX += qtot[0];
436  qtotY += qtot[1];
437  qtot2X += qtot[0]*qtot[0];
438  qtot2Y += qtot[1]*qtot[1];
439  if(timestamp>timestampold+fRateSample*1e8){ // every second
440  Double_t freq = 1e8/(timestamp-timestampold); // Hz
441  freq *= gHConfig->GetSkipEvents()+1;
442  timestampold = timestamp;
443  Double_t time = (timestamp+timestampold)/2e8; // seconds
444  // Info("process","freq = 1e7/(%g - %g) = %g",timestamp,timestampold,freq);
445  for(Int_t i = 0; i<kNtriggerTypes; i++){
446  Double_t trigCorr = hTriggerCorrection->GetBinContent(i+1);
447  // Double_t trigCorr = 1.;
448  // if(fTriggerTime[i])
449  // trigCorr = fTriggerTimeTot/fTriggerTime[i];
450  // if(fTriggerDownscaling[i])
451  // trigCorr *= fTriggerDownscaling[i];
452  if(gHarpoDebug>1)
453  Info("process","trigCorr = %g",trigCorr);
454  gRateCreated[i]->SetPoint(gRateCreated[i]->GetN(),time,fNcreated[i]*freq*trigCorr);
455  //gRateCreated[i]->SetPointError(gRateCreated[i]->GetN()-1,fRateSample/2,TMath::Sqrt(fNcreated[i])*freq*trigCorr);
456 
457  gRateTraversing[i]->SetPoint(gRateTraversing[i]->GetN(),time,fNtraversing[i]*freq*trigCorr);
458  //gRateTraversing[i]->SetPointError(gRateTraversing[i]->GetN()-1,fRateSample/2,TMath::Sqrt(fNtraversing[i])*freq*trigCorr);
459 
460  gRateEmpty[i]->SetPoint(gRateEmpty[i]->GetN(),time,fNempty[i]*freq*trigCorr);
461  //gRateEmpty[i]->SetPointError(gRateEmpty[i]->GetN()-1,fRateSample/2,TMath::Sqrt(fNempty[i])*freq*trigCorr);
462 
463  gRateSaturated[i]->SetPoint(gRateSaturated[i]->GetN(),time,fNsaturated[i]*freq*trigCorr);
464  //gRateSaturated[i]->SetPointError(gRateSaturated[i]->GetN()-1,fRateSample/2,TMath::Sqrt(fNsaturated[i])*freq*trigCorr);
465 
466  gRateOther[i]->SetPoint(gRateOther[i]->GetN(),time,fNother[i]*freq*trigCorr);
467  // gRateOther[i]->SetPointError(gRateOther[i]->GetN()-1,fRateSample/2,TMath::Sqrt(fNother[i])*freq*trigCorr);
468 
469  Int_t nTot = fNother[i]+fNtraversing[i]+fNempty[i]+fNcreated[i]+fNsaturated[i];
470  if(nTot){
471  gRateTotal[i]->SetPoint(gRateTotal[i]->GetN(),time,nTot*freq*trigCorr);
472  // gRateTotal[i]->SetPointError(gRateTotal[i]->GetN()-1,fRateSample/2,TMath::Sqrt(nTot)*freq*trigCorr);
473  gRateTotal[i]->SetPointError(gRateTotal[i]->GetN()-1,0,0);
474  }
475  fNcreated[i] = 0;
476  fNtraversing[i] = 0;
477  fNempty[i] = 0;
478  fNsaturated[i] = 0;
479  fNother[i] = 0;
480  }
481 
482  if(nSamples){
483  qtotX /= nSamples;
484  qtot2X /= nSamples;
485  qtotY /= nSamples;
486  qtot2Y /= nSamples;
487 
488  gQtotTT_X->SetPoint(gQtotTT_X->GetN(),time,qtotX);
489  gQtotTT_X->SetPointError(gQtotTT_X->GetN()-1,fRateSample/2,TMath::Sqrt(qtot2X-qtotX*qtotX)/2);
490  gQtotTT_Y->SetPoint(gQtotTT_Y->GetN(),time,qtotY);
491  gQtotTT_Y->SetPointError(gQtotTT_Y->GetN()-1,fRateSample/2,TMath::Sqrt(qtot2Y-qtotY*qtotY)/2);
492  }
493  nSamples = 0;
494  qtotX = 0;
495  qtotY = 0;
496  qtot2X = 0;
497  qtot2Y = 0;
498  }
499 
500  // for(Int_t i = 0; i<gkHarpoMonNhist; i++){
501  // HarpoHistoIdentifier id = HarpoHistoIdentifier(i);
502  // GetHist(id,0)->Write(Form("h%d_0",i));
503  // GetHist(id,1)->Write(Form("h%d_1",i));
504  // }
505  if((nEvents-1)%fSaveRate == 0)
506  mfile->Update();
507 }
508 
510 {
511  // m_hmap[0] = new HarpoMap(0);
512  // m_hmap[1] = new HarpoMap(1);
513 
514 
515 
516 
517 
518  Long64_t fAddress = 0x7fef1fc55000;
519  Long64_t address = 0;
520  if ( ! gHConfig->Lookup("monitor.address",address) )
521  Info("Init","Use default address %lld",fAddress);
522  else{
523  fAddress = address;
524  TMapFile::SetMapAddress(fAddress);
525  }
526 
527  // TMapFile::SetMapAddress(0xb46a5000);
528  // TMapFile::SetMapAddress(0x7fef1fc55000);
529  mfile = TMapFile::Create("/tmp/harpo.map","RECREATE", 50000000,
530  "Memory mapped file with monitoring histograms");
531 
532  // for(Int_t ndet = 0; ndet<1; ndet++){
533  // if(ndet == 0) color = kBlue;
534  // else color = kRed;
535  // MakeHist(H_,ndet,";",
536  fIsZs = 1;
537  Long64_t isZs = 1;
538  if ( ! gHConfig->Lookup("monitor.IsZs",isZs) )
539  Info("Init","Use default fIsZs %d",fIsZs);
540  else
541  fIsZs = isZs;
542 
543  fQmin = 10000;
544  Long64_t qmin = 0;
545  if ( ! gHConfig->Lookup("monitor.Qmin",qmin) )
546  Info("Init","Use default fQmin %d",fQmin);
547  else
548  fQmin = qmin;
549 
550  fQmax = 300000;
551  Long64_t qmax = 0;
552  if ( ! gHConfig->Lookup("monitor.Qmax",qmax) )
553  Info("Init","Use default fQmax %d",fQmax);
554  else
555  fQmax = qmax;
556 
557  fTmin = 150;
558  Double_t tmin = 0;
559  if ( ! gHConfig->Lookup("monitor.Tmin",tmin) )
560  Info("InitCfg","Use default fTmin %g",fTmin);
561  else
562  fTmin = tmin;
563 
564  fLTpc = 200;
565  Double_t lTpc = 0;
566  if ( ! gHConfig->Lookup("monitor.LTpc",lTpc) )
567  Info("InitCfg","Use default fLTpc %g",fLTpc);
568  else
569  fLTpc = lTpc;
570 
571  fRateSample = 200;
572  Double_t rateSample = 0;
573  if ( ! gHConfig->Lookup("monitor.RateSample",rateSample) )
574  Info("InitCfg","Use default fRateSample %g",fRateSample);
575  else
576  fRateSample = rateSample;
577 
578  fSaveRate = 1;
579  Long64_t saveRate = 0;
580  if ( ! gHConfig->Lookup("monitor.SaveRate",saveRate) )
581  Info("InitCfg","Use default fSaveRate %d",fSaveRate);
582  else
583  fSaveRate = saveRate;
584  if(fSaveRate<1) fSaveRate = 1;
585 
586 
587 
588  hQvsT_TT[0] = new TH1F("hQvsT_TT_X","Q vs T (traversing tracks);T [tb]; Q [ADC]",511,0,511);
589  hQvsT_TT[1] = new TH1F("hQvsT_TT_Y","Q vs T (traversing tracks);T [tb]; Q [ADC]",511,0,511);
590  hQvsT_TT2D[0] = new TH2F("hQvsT_TT2D_X","Q vs T (traversing tracks);T [tb]; Q [ADC]",511,0,511,500,0,50000);
591  hQvsT_TT2D[1] = new TH2F("hQvsT_TT2D_Y","Q vs T (traversing tracks);T [tb]; Q [ADC]",511,0,511,500,0,50000);
592  hTdrift_TT[0] = new TH1F("hTdrift_TT_X",";T_{max}-T_{min} [tb]",511,0,511);
593  hTdrift_TT[1] = new TH1F("hTdrift_TT_Y",";T_{max}-T_{min} [tb]",511,0,511);
594 
595 
596  hTmin[0] = new TH1F("hTmin_X","Tmin;T_{min} [tb]",511,0,511);
597  hTmin[1] = new TH1F("hTmin_Y","Tmin;T_{min} [tb]",511,0,511);
598 
599  hTmax[0] = new TH1F("hTmax_X",";T_{max} [tb]",511,0,511);
600  hTmax[1] = new TH1F("hTmax_Y",";T_{max} [tb]",511,0,511);
601 
602  hT[0] = new TH1F("hT_X",";time [tb]",511,0,511);
603  hT[1] = new TH1F("hT_Y",";time [tb]",511,0,511);
604 
605  hCh[0] = new TH1F("hCh_X","Channels (cumulated);channel",304,0,304);
606  hCh[1] = new TH1F("hCh_Y","Channels (cumulated);channel",304,0,304);
607 
608  hQ[0] = new TH1F("hQ_X","Pixel Charge;Q_{pixel} [ADC]",4096,0,4096);
609  hQ[1] = new TH1F("hQ_Y","Pixel Charge;Q_{pixel} [ADC]",4096,0,4096);
610 
611  hQev[0] = new TH1F("hQev_X",";Q_{pixel} [ADC]",4096,0,4096);
612  hQev[1] = new TH1F("hQev_Y",";Q_{pixel} [ADC]",4096,0,4096);
613 
614 
615  hTZs[0] = new TH1F("hTZs_X",";time [tb]",511,0,511);
616  hTZs[1] = new TH1F("hTZs_Y",";time [tb]",511,0,511);
617 
618  hChZs[0] = new TH1F("hChZs_X","Channels (cumulated);channel",304,0,304);
619  hChZs[1] = new TH1F("hChZs_Y","Channels (cumulated);channel",304,0,304);
620 
621  hQZs[0] = new TH1F("hQZs_X",";Q_{pixel} [ADC]",4096,0,4096);
622  hQZs[1] = new TH1F("hQZs_Y",";Q_{pixel} [ADC]",4096,0,4096);
623 
624  hQevZs[0] = new TH1F("hQevZs_X",";Q_{pixel} [ADC]",4096,0,4096);
625  hQevZs[1] = new TH1F("hQevZs_Y",";Q_{pixel} [ADC]",4096,0,4096);
626 
627 
628  const Int_t nbins1 = 500;
629  const Int_t nbins2 = 500;
630  Double_t xmin = 10;
631  Double_t xmin2 = 10;
632  Double_t xmax = 2e5;
633  Double_t xmax2 = 1e8;
634  Double_t logxmin = TMath::Log(xmin);
635  Double_t logxmin2 = TMath::Log(xmin2);
636  Double_t logxmax = TMath::Log(xmax);
637  Double_t logxmax2 = TMath::Log(xmax2);
638  Double_t binwidth = (logxmax-logxmin)/nbins1;
639  Double_t binwidth2 = (logxmax2-logxmin2)/nbins2;
640  Double_t xbins1[nbins1+1];
641  Double_t xbins2[nbins2+1];
642  xbins1[0] = xmin;
643  xbins2[0] = xmin2;
644  for (Int_t i=1;i<=nbins1;i++)
645  xbins1[i] = TMath::Exp(logxmin+i*binwidth);
646  for (Int_t i=1;i<=nbins2;i++)
647  xbins2[i] = TMath::Exp(logxmin2+i*binwidth2);
648 
649  hQtotT[0] = new TH1F("hQtotT_X","Cluster Charge;Q_{cluster} [ADC]",nbins1,xbins1);
650  hQtotT[1] = new TH1F("hQtotT_Y","Cluster Charge;Q_{cluster} [ADC]",nbins1,xbins1);
651 
652  hQtot[0] = new TH1F("hQtot_X","Event Charge;Q_{event} [ADC]",nbins2,xbins2);
653  hQtot[1] = new TH1F("hQtot_Y","Event Charge;Q_{event} [ADC]",nbins2,xbins2);
654 
655  hQtotTZs[0] = new TH1F("hQtotTZs_X",";Q_{cluster} [ADC]",nbins1,xbins1);
656  hQtotTZs[1] = new TH1F("hQtotTZs_Y",";Q_{cluster} [ADC]",nbins1,xbins1);
657 
658  hQtotZs[0] = new TH1F("hQtotZs_X","Event Charge;Q_{event} [ADC]",nbins2,xbins2);
659  hQtotZs[1] = new TH1F("hQtotZs_Y","Event Charge;Q_{event} [ADC]",nbins2,xbins2);
660 
661  // hQtotT[0] = new TH1F("hQtotT_X",";Q_{cluster} [ADC]",1000,0,10000);
662  // hQtotT[1] = new TH1F("hQtotT_Y",";Q_{cluster} [ADC]",1000,0,10000);
663 
664  // hQtot[0] = new TH1F("hQtot_X","Q_{event} [ADC]",1000,0,1e7);
665  // hQtot[1] = new TH1F("hQtot_Y","Q_{event} [ADC]",1000,0,1e7);
666 
667  // hQtotTZs[0] = new TH1F("hQtotTZs_X",";Q_{cluster} [ADC]",1000,0,10000);
668  // hQtotTZs[1] = new TH1F("hQtotTZs_Y",";Q_{cluster} [ADC]",1000,0,10000);
669 
670  // hQtotZs[0] = new TH1F("hQtotZs_X","Q_{event} [ADC]",1000,0,1e7);
671  // hQtotZs[1] = new TH1F("hQtotZs_Y","Q_{event} [ADC]",1000,0,1e7);
672 
673  hInfo = new TH1F("hInfo","",15,0.5,15.5);
674  hPmm2 = new TH1F("hPmm2","",16,0,16);
675 
676  hTmin[0]->SetLineColor(kBlue);
677  hTmax[0]->SetLineColor(kBlue+3);
678  hTmin[1]->SetLineColor(kRed);
679  hTmax[1]->SetLineColor(kRed+3);
680 
681 
682  hCh[0]->SetLineColor(kBlue);
683  hT[0]->SetLineColor(kBlue);
684  hQtotT[0]->SetLineColor(kBlue);
685  hQtot[0]->SetLineColor(kBlue);
686  hQ[0]->SetLineColor(kBlue);
687  hQev[0]->SetLineColor(kBlue);
688  hCh[1]->SetLineColor(kRed);
689  hT[1]->SetLineColor(kRed);
690  hQtotT[1]->SetLineColor(kRed);
691  hQtot[1]->SetLineColor(kRed);
692  hQ[1]->SetLineColor(kRed);
693  hQev[1]->SetLineColor(kRed);
694 
695  hQvsT_TT[0]->SetLineColor(kBlue);
696  hQvsT_TT[1]->SetLineColor(kRed);
697  hTdrift_TT[0]->SetLineColor(kBlue);
698  hTdrift_TT[1]->SetLineColor(kRed);
699 
700  hChZs[0]->SetLineColor(kBlue);
701  hTZs[0]->SetLineColor(kBlue);
702  hQtotTZs[0]->SetLineColor(kBlue);
703  hQtotZs[0]->SetLineColor(kBlue);
704  hQevZs[0]->SetLineColor(kBlue);
705  hQZs[0]->SetLineColor(kBlue);
706  hChZs[1]->SetLineColor(kRed);
707  hTZs[1]->SetLineColor(kRed);
708  hQtotTZs[1]->SetLineColor(kRed);
709  hQtotZs[1]->SetLineColor(kRed);
710  hQevZs[1]->SetLineColor(kRed);
711  hQZs[1]->SetLineColor(kRed);
712 
713  hChZs[0]->SetLineStyle(2);
714  hTZs[0]->SetLineStyle(2);
715  hQtotTZs[0]->SetLineStyle(2);
716  hQtotZs[0]->SetLineStyle(2);
717  hQevZs[0]->SetLineStyle(2);
718  hQZs[0]->SetLineStyle(2);
719  hChZs[1]->SetLineStyle(2);
720  hTZs[1]->SetLineStyle(2);
721  hQtotTZs[1]->SetLineStyle(2);
722  hQtotZs[1]->SetLineStyle(2);
723  hQevZs[1]->SetLineStyle(2);
724  hQZs[1]->SetLineStyle(2);
725 
726 
727  hTev[0] = new TH1F("hTev_X","",511,0,511);
728  hTev[1] = new TH1F("hTev_Y","",511,0,511);
729  hTevZs[0] = new TH1F("hTevZs_X","",511,0,511);
730  hTevZs[1] = new TH1F("hTevZs_Y","",511,0,511);
731 
732  Int_t nbins = 1000;
733  Int_t Qmax = 10000;
734  hQtotTev[0] = new TH1F("hQtotTev_X","",nbins,0,Qmax);
735  hQtotTev[1] = new TH1F("hQtotTev_Y","",nbins,0,Qmax);
736  hQtotTevZs[0] = new TH1F("hQtotTevZs_X","",nbins,0,Qmax);
737  hQtotTevZs[1] = new TH1F("hQtotTevZs_Y","",nbins,0,Qmax);
738 
739  hTev[0]->SetLineColor(kBlue);
740  hTev[1]->SetLineColor(kRed);
741  hQtotTev[0]->SetLineColor(kBlue);
742  hQtotTev[1]->SetLineColor(kRed);
743  hTevZs[0]->SetLineColor(kBlue);
744  hTevZs[1]->SetLineColor(kRed);
745  hQtotTevZs[0]->SetLineColor(kBlue);
746  hQtotTevZs[1]->SetLineColor(kRed);
747  hTevZs[0]->SetLineStyle(2);
748  hTevZs[1]->SetLineStyle(2);
749  hQtotTevZs[0]->SetLineStyle(2);
750  hQtotTevZs[1]->SetLineStyle(2);
751 
752 
753  h[0] = new TH2F("hX","X direction;time [t.b.];channel [1mm]",511,0,511,304,0,304);
754  hZs[0] = new TH2F("hXZs","X direction;time [t.b.];channel [1mm]",511,0,511,304,0,304);
755  h[1] = new TH2F("hY","Y direction;time [t.b.];channel [1mm]",511,0,511,304,0,304);
756  hZs[1] = new TH2F("hYZs","Y direction;time [t.b.];channel [1mm]",511,0,511,304,0,304);
757  hCumul[0] = new TH2F("hCumul_X","X direction;time [t.b.];channel [1mm]",511,0,511,304,0,304);
758  hCumul[1] = new TH2F("hCumul_Y","Y direction;time [t.b.];channel [1mm]",511,0,511,304,0,304);
759 
760  hTriggerCorrection = new TH1F("hTriggerCorrection",";Trigger Type",kNtriggerTypes+1,-1,kNtriggerTypes);
761  hTriggerCreated = new TH1F("hTriggerCreated",";Trigger Type",kNtriggerTypes+1,-1,kNtriggerTypes);
762  hTriggerTraversing = new TH1F("hTriggerTraversing",";Trigger Type",kNtriggerTypes+1,-1,kNtriggerTypes);
763  hTriggerEmpty = new TH1F("hTriggerEmpty",";Trigger Type",kNtriggerTypes+1,-1,kNtriggerTypes);
764  hTriggerSaturated = new TH1F("hTriggerSaturated",";Trigger Type",kNtriggerTypes+1,-1,kNtriggerTypes);
765  hTriggerOther = new TH1F("hTriggerOther",";Trigger Type",kNtriggerTypes+1,-1,kNtriggerTypes);
766 
767 
768  hPmm2Size = new TH1F("hPmm2Size",";#PM",12,1,13);
769  hPmm2Triggered = new TH1F("hPmm2Triggered",";#PM",12,1,13);
770  hPmm2Missed = new TH1F("hPmm2Missed",";#PM",12,1,13);
771  hPmm2Spectrum2D = new TH2F("hPmm2Spectrum2D",";Channel;Charge [ADC]",12,1,13,1024,0,1024);
772  hPmm2Coincidence = new TH2F("hPmm2Coincidence",";Channel;Channel",12,1,13,12,1,13);
773 
774  gXTmin[0] = new TGraph();
775  mfile->Add(gXTmin[0],"gXTmin");
776  gXTmin[1] = new TGraph();
777  mfile->Add(gXTmin[1],"gYTmin");
778  for(Int_t i = 0; i<kNtriggerTypes+1; i++){
779  gRateCreated[i] = new TGraphErrors();
780  mfile->Add(gRateCreated[i],Form("gRateCreated_%d",i));
781  gRateTraversing[i] = new TGraphErrors();
782  mfile->Add(gRateTraversing[i],Form("gRateTraversing_%d",i));
783  gRateEmpty[i] = new TGraphErrors();
784  mfile->Add(gRateEmpty[i],Form("gRateEmpty_%d",i));
785  gRateSaturated[i] = new TGraphErrors();
786  mfile->Add(gRateSaturated[i],Form("gRateSaturated_%d",i));
787  gRateOther[i] = new TGraphErrors();
788  mfile->Add(gRateOther[i],Form("gRateOther_%d",i));
789  gRateTotal[i] = new TGraphErrors();
790  mfile->Add(gRateTotal[i],Form("gRateTotal_%d",i));
791  fNcreated[i] = 0;
792  fNtraversing[i] = 0;
793  fNempty[i] = 0;
794  fNsaturated[i] = 0;
795  fNother[i] = 0;
796  hDeadTime[i] = new TH1F(Form("hDeadTime_%d",i),"; #deltaT [ms]; counts",500,0,500);
797  }
798 
799  gQtotTT_X = new TGraphErrors();
800  mfile->Add(gQtotTT_X,"gQtotTT_X");
801  gQtotTT_Y = new TGraphErrors();
802  mfile->Add(gQtotTT_Y,"gQtotTT_Y");
803  qtotX = 0;
804  qtotY = 0;
805  qtot2X = 0;
806  qtot2Y = 0;
807  nSamples = 0;
808 
809  mfile->Print();
810 
811 
812  timestampold = 0;
813 }
814 
815 
817 {
818 
819  // Int_t ndet = i%2;
820  // Int_t ihist = i/2;
821 
822  switch(ihist){
823  case H_MAP: return h[ndet];
824  case H_MAP_ZS: return hZs[ndet];
825  case H_Q: return hQ[ndet];
826  case H_Q_EV: return hQev[ndet];
827  case H_T: return hT[ndet];
828  case H_CH: return hCh[ndet];
829  case H_QTOT_T: return hQtotT[ndet];
830  case H_QTOT: return hQtot[ndet];
831  case H_Q_ZS: return hQZs[ndet];
832  case H_Q_EV_ZS: return hQevZs[ndet];
833  case H_T_ZS: return hTZs[ndet];
834  case H_CH_ZS: return hChZs[ndet];
835  case H_QTOTT_ZS: return hQtotTZs[ndet];
836  case H_QTOT_ZS: return hQtotZs[ndet];
837  case H_T_EV: return hTev[ndet];
838  case H_T_EV_ZS: return hTevZs[ndet];
839  case H_QTOTT_EV: return hQtotTev[ndet];
840  case H_QTOTT_EV_ZS: return hQtotTevZs[ndet];
841  default: return 0;
842  }
843 
844  return 0;
845 }
846 
847 
848 
849 void HarpoAnalyseMonitorNew::Save(char * /* mode */)
850 {
851  TString * hstFile = gHConfig->GetHistFile();
852  // if ( hstFile == NULL ) {
853  // std::cout << gHConfig->GetProgramName() << " " <<
854  // "No Hist File name gived, use default" << std::endl;
855  // hstFile = new TString("onlinemonitor.root");
856  // }
857  if ( hstFile == NULL ) {
858  const char* dir = gSystem->ExpandPathName("$HARPO_ANA_DIR/monitor");
859  //const char* dir = "$HARPO_ANA_DIR/monitor";
860  if(gSystem->AccessPathName(dir))
861  hstFile = new TString(Form("onlinemonitor%lli.root",gHConfig->GetRunNo()));
862  else
863  hstFile = new TString(Form("%s/onlinemonitor%lli.root",dir,gHConfig->GetRunNo()));
864  Info("Save","No Hist File name given, use default %s",hstFile->Data());
865  }
866 
867  TFile *hf = new TFile(hstFile->Data(),"RECREATE");
868  hQvsT_TT[0]->Write();
869  hQvsT_TT[1]->Write();
870  hQvsT_TT2D[0]->Write();
871  hQvsT_TT2D[1]->Write();
872  hTdrift_TT[0]->Write();
873  hTdrift_TT[1]->Write();
874  hTmin[0]->Write();
875  hTmin[1]->Write();
876  hTmax[0]->Write();
877  hTmax[1]->Write();
878  hT[0]->Write();
879  hT[1]->Write();
880  hCh[0]->Write();
881  hCh[1]->Write();
882  hQ[0]->Write();
883  hQ[1]->Write();
884  hQev[0]->Write();
885  hQev[1]->Write();
886  hTZs[0]->Write();
887  hTZs[1]->Write();
888  hChZs[0]->Write();
889  hChZs[1]->Write();
890  hQZs[0]->Write();
891  hQZs[1]->Write();
892  hQevZs[0]->Write();
893  hQevZs[1]->Write();
894  hQtotT[0]->Write();
895  hQtotT[1]->Write();
896  hQtot[0]->Write();
897  hQtot[1]->Write();
898  hQtotTZs[0]->Write();
899  hQtotTZs[1]->Write();
900  hQtotZs[0]->Write();
901  hQtotZs[1]->Write();
902  hInfo->Write();
903  hPmm2->Write();
904  hTev[0]->Write();
905  hTev[1]->Write();
906  hTevZs[0]->Write();
907  hTevZs[1]->Write();
908  hQtotTev[0]->Write();
909  hQtotTev[1]->Write();
910  hQtotTevZs[0]->Write();
911  hQtotTevZs[1]->Write();
912  h[0]->Write();
913  hZs[0]->Write();
914  h[1]->Write();
915  hZs[1]->Write();
916  hCumul[0]->Write();
917  hCumul[1]->Write();
918  hTriggerCorrection->Write();
919  hTriggerCreated->Write();
920  hTriggerTraversing->Write();
921  hTriggerEmpty->Write();
922  hTriggerSaturated->Write();
923  hTriggerOther->Write();
924  hPmm2Size->Write();
925  hPmm2Triggered->Write();
926  hPmm2Missed->Write();
927  hPmm2Spectrum2D->Write();
928  hPmm2Coincidence->Write();
929 
930 
931 
932 
933  hf->Close();
934 }
935 
936 
937 
938 
939 Double_t HarpoAnalyseMonitorNew::TruncMean(TArrayD* vect, Double_t tl, Double_t th)
940 {
941  //
942  // Calculates the truncated mean mean of the non zero value in vect
943  // The truncation is done on the 100*tl% lowest and 100*(1-th) highest value
944  //
945  // debug(2,"truncated mean");
946 
947 
948  Int_t size = vect->GetSize();
949  Double_t truncMean = 0;
950  Int_t* index = new Int_t[size];
951  TMath::Sort(size,vect->GetArray(),index,kFALSE);
952  Int_t t = 0, tLow, tHigh;
953 
954 
955  while(vect->At(index[t])<10&&t<size-1) t++;
956  tLow = TMath::FloorNint(t + (size - t)*tl);
957  tHigh = TMath::FloorNint(t + (size - t)*th);
958 
959  for(Int_t tind = tLow; tind<tHigh; tind++) truncMean += vect->At(index[tind]);
960  if(tHigh-tLow) {
961  return truncMean/(tHigh-tLow);
962  }
963  else return 0;
964 }
#define NALL
Definition: HarpoDccMap.h:15
Int_t fNsaturated[kNtriggerTypes+1]
Double_t TruncMean(TArrayD *vect, Double_t tl, Double_t th)
Dcc Plane Y.
Definition: HarpoDet.h:20
TH1 * GetHist(HarpoHistoIdentifiers i, Int_t ndet)
Redefine empty default.
Long64_t GetRunNo()
Set Run Number.
Definition: HarpoConfig.h:127
A class Pmm2Status is bits representation of pmm2 status register (0x400).
Definition: Pmm2Status.h:12
Int_t fTriggerDownscaling[kNtriggerTypes]
#define NCHAN
Definition: HarpoDccMap.h:16
HarpoDetHeader * GetHeader(UInt_t ndet=XDCC)
Int_t fNcreated[kNtriggerTypes+1]
Double_t GetData(Int_t i, Int_t j)
Set/Get Data Cell.
Definition: HarpoDccMap.cxx:84
Bool_t isExist(ULong_t det)
Detecror date exist //! Number of Real Detectors.
Definition: HarpoDetSet.h:33
TGraphErrors * gRateSaturated[kNtriggerTypes+1]
UInt_t eventSize
Raw Event size.
Definition: HarpoDetEvent.h:28
A class hold HARPO run information.
Definition: Pmm2Header.h:17
Long_t GetEvtNo()
Get Event Number.
unsigned int getTrigger(int trig) const
Definition: Pmm2Status.cxx:168
Int_t fTriggerTime[kNtriggerTypes]
virtual void print()
TGraphErrors * gRateTraversing[kNtriggerTypes+1]
Long64_t GetSkipEvents()
Definition: HarpoConfig.h:90
FullEvent Header not scecific to the detectors The class is ....
Int_t GetTriggerType()
Definition: Pmm2Event.h:29
Int_t fNempty[kNtriggerTypes+1]
virtual void print()
Int_t getCharge() const
Definition: Pmm2Mes.h:52
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
Monitoring RAW data for online GUI.
HarpoDetEvent * GetDetEvent(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:93
Pmm2MesVect * GetMesurements()
Return pointer to decoded data.
Definition: Pmm2Event.cxx:78
Pmm2Status * getStatus()
Definition: Pmm2Header.h:36
TGraphErrors * gRateOther[kNtriggerTypes+1]
#define NADC
Definition: HarpoDccMap.h:18
Long64_t gHarpoDebug
Definition: HarpoDebug.cxx:9
HarpoHistoIdentifiers
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
Long64_t GetFromEvent()
Get First Event to process.
Definition: HarpoConfig.h:120
TGraphErrors * gRateEmpty[kNtriggerTypes+1]
Int_t getChNum() const
Definition: Pmm2Mes.h:28
HarpoRunHeader * fRunHeader
Definition: HarpoAnalyse.h:76
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
HarpoDccMap * GetDccMap(Long_t plane=XDCC)
Definition: HarpoEvent.cxx:108
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
void print()
Ovreloaded medod whic do all job.
Pmm2Mes at(ULong_t idx)
Definition: Pmm2MesList.h:37
TGraphErrors * gRateTotal[kNtriggerTypes+1]
static const Int_t kNtriggerTypes
TH1F * hDeadTime[kNtriggerTypes+1]
R__EXTERN HarpoDetSet * gHDetSet
Definition: HarpoDetSet.h:71
Int_t fNother[kNtriggerTypes+1]
TGraphErrors * gRateCreated[kNtriggerTypes+1]
Int_t fNtraversing[kNtriggerTypes+1]