HARPO  5.1.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HarpoDccAnalyseNoiseMonitor.cxx
Go to the documentation of this file.
1 //
2 // File HarpoDccAnalyseNoiseMonitor.cxx
3 //
13 #include "HarpoConfig.h"
14 //#include "HarpoDetSet.h"
15 #include "HarpoDccEvent.h"
16 
17 #include "TROOT.h"
18 #include "TStyle.h"
19 #include "TApplication.h"
20 #include "TFile.h"
21 #include "TCanvas.h"
22 #include "TLatex.h"
23 #include "TGraph.h"
24 #include "TF1.h"
25 #include "TH1F.h"
26 #include "TH2F.h"
27 #include "TLinearFitter.h"
28 #include "TMath.h"
29 
30 #include <cstdlib>
31 #include <cstring>
32 #include <cassert>
33 #include <iostream>
34 
36 
37 void HarpoDccAnalyseNoiseMonitor::print()
38 {
39  // int nd; // number of detectors
40  //HarpoEventHeader *hdr = anaEvt->GetHeader();
41 
42  // assert(hdr != NULL);
43  // hdr->print();
44 
45  // for (nd = 0; nd < gkNDetectors; nd++) {
46  // // if (anaEvt->isdataExist(nd)) {
47  // HarpoDccMap *plane = anaEvt->GetDccMap(nd);
48  // if (plane != NULL )plane->print();
49  // }
50 }
51 
53 {
54  nEvents++;
55  std::cout << " Processing Event " << nEvents<< std::endl;
56 
57 
58 
59 
60 
61  TCanvas *c = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("cHarpo");
62  if(!c){
63  c = new TCanvas("cHarpo","DCC: All Events cumulated",0,0,1000,800);
64  c->Clear();
65  c->Divide(3,3);//,0.001,0.001);
66  }
67 
68  TCanvas *c2 = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("cHarpo2");
69  if(!c2){
70  c2 = new TCanvas("cHarpo2","DCC: Current Event",0,0,1000,800);
71  c2->Clear();
72  c2->Divide(3,3);//,0.001,0.001);
73  }
74 
75  gStyle->SetOptStat(0);
76 
77  TH1F* h1Ev1Ch = new TH1F("h1Ev1Ch",";time [tb]",511,0,511);
78  TH1F* h1EvAllCh = new TH1F("h1EvAllCh",";time [tb]",511,0,511);
79  TH2F* h1Ev2D = new TH2F("h1Ev2D",";time [tb]; channel",511,0,511,304,0,304);
80 
81  TH1F* h1EvFFT1Ch = new TH1F("h1EvFFT1Ch",";freq []",511,0,511);
82  TH1F* h1EvFFTAllCh = new TH1F("h1EvFFTAllCh",";freq []",511,0,511);
83  TH2F* h1EvFFT2D = new TH2F("h1EvFFT2D",";freq []; channel",511,0,511,304,0,304);
84 
85  TH1F* h1EvPed1Ch = new TH1F("h1EvPed1Ch",";pedesteal [ADC]",500,0,500);
86  TH1F* h1EvPedAllCh = new TH1F("h1EvPedAllCh",";pedesteal [ADC]",500,0,500);
87  TH2F* h1EvPed2D = new TH2F("h1EvPed2D",";pedesteal [ADC]; channel",500,0,500,304,0,304);
88 
89  // Int_t npix = 0, nch = 0, ntb = 0;
90 
91  HarpoDccMap * m = anaEvt->GetMap();
92  std::cout << "Event " << nEvents << " " << m << std::endl;
93  if ( m != NULL ) {
94  // for(j=0;j<NCHAN;j++) // Channels
95  // Double_t qTot = 0;
96  //TH2F* hFull = new TH2F("hFull",";time [25ns];channel [1mm]",511,0,511,304,0,304);
97 
98  TH1F* hTmp = new TH1F("hTmp","",511,0,511);
99  for(Int_t i=0;i<NADC;i++){ //Time bins
100  Double_t qTotT = 0;
101  for(Int_t j=0;j<NALL;j++){ // Channels
102  // Double_t q = m->map(j,i);
103  Double_t q = m->GetData(j,i);
104  h2D->SetBinContent(i+1,j+1,h2D->GetBinContent(i+1,j+1)+q);
105  h1Ev2D->SetBinContent(i+1,j+1,q);
106  if(j == 100){
107  h1Ch->SetBinContent(i+1,h1Ch->GetBinContent(i+1)+q);
108  h1Ev1Ch->SetBinContent(i+1,q);
109  hPed1Ch->Fill(q);
110  h1EvPed1Ch->Fill(q);
111  }
112  hPed2D->Fill(q,j);
113  h1EvPed2D->Fill(q,j);
114  qTotT += q;
115  }
116  hAllCh->SetBinContent(i+1,hAllCh->GetBinContent(i+1)+qTotT);
117  h1EvAllCh->SetBinContent(i+1,qTotT);
118  hPedAllCh->Fill(qTotT/288);
119  h1EvPedAllCh->Fill(qTotT/288);
120  hTmp->SetBinContent(i+1,qTotT);
121  }
122  TH1* hm1 = 0;
123  hm1 = hTmp->FFT(hm1, "MAG");
124  for(Int_t i=2;i<512;i++){ //Time bins
125  hFFTAllCh->SetBinContent(i+1,hFFTAllCh->GetBinContent(i+1)+hm1->GetBinContent(i+1));
126  h1EvFFTAllCh->SetBinContent(i+1,hm1->GetBinContent(i+1));
127  }
128  hTmp->Delete();
129  hm1->Delete();
130 
131  for(Int_t j=0;j<NALL;j++){ // Channels
132  TH1F* hTmp = new TH1F("hTmp","",511,0,511);
133  for(Int_t i=0;i<NADC;i++){ //Time bins
134  // Double_t q = m->map(j,i);
135  Double_t q = m->GetData(j,i);
136  hTmp->SetBinContent(i+1,q);
137  }
138 
139  TH1* hm = 0;
140  hm = hTmp->FFT(hm, "MAG");
141  for(Int_t i=2;i<512;i++){ //Time bins
142  hFFT2D->SetBinContent(i+1,j+1,hFFT2D->GetBinContent(i+1,j+1)+hm->GetBinContent(i+1));
143  h1EvFFT2D->SetBinContent(i+1,j+1,hm->GetBinContent(i+1));
144  if(j==100){
145  hFFT1Ch->SetBinContent(i+1,hFFT1Ch->GetBinContent(i+1,j+1)+hm->GetBinContent(i+1));
146  h1EvFFT1Ch->SetBinContent(i+1,hm->GetBinContent(i+1));
147  }
148  }
149  hTmp->Delete();
150  hm->Delete();
151 
152  }
153 
154  hFFT1Ch->GetXaxis()->SetRangeUser(-1,255);
155  hFFTAllCh->GetXaxis()->SetRangeUser(-1,255);
156  hFFT2D->GetXaxis()->SetRangeUser(-1,255);
157  h1EvFFT1Ch->GetXaxis()->SetRangeUser(-1,255);
158  h1EvFFTAllCh->GetXaxis()->SetRangeUser(-1,255);
159  h1EvFFT2D->GetXaxis()->SetRangeUser(-1,255);
160 
161 
162  c->cd(1);
163  h1Ch->DrawCopy();
164  c->cd(2);
165  hAllCh->DrawCopy();
166  c->cd(3);
167  h2D->DrawCopy("colz");
168 
169  c->cd(4);
170  hFFT1Ch->DrawCopy();
171  c->cd(5);
172  hFFTAllCh->DrawCopy();
173  c->cd(6);
174  hFFT2D->DrawCopy("colz");
175 
176  c->cd(7);
177  hPed1Ch->DrawCopy();
178  c->cd(8);
179  hPedAllCh->DrawCopy();
180  c->cd(9);
181  hPed2D->DrawCopy("colz");
182 
183  c2->cd(1);
184  h1Ev1Ch->DrawCopy();
185  c2->cd(2);
186  h1EvAllCh->DrawCopy();
187  c2->cd(3);
188  h1Ev2D->DrawCopy("colz");
189 
190  c2->cd(4);
191  h1EvFFT1Ch->DrawCopy();
192  c2->cd(5);
193  h1EvFFTAllCh->DrawCopy();
194  c2->cd(6);
195  h1EvFFT2D->DrawCopy("colz");
196 
197  c2->cd(7);
198  h1EvPed1Ch->DrawCopy();
199  c2->cd(8);
200  h1EvPedAllCh->DrawCopy();
201  c2->cd(9);
202  h1EvPed2D->DrawCopy("colz");
203 
204  TFile* file = new TFile("noise1Ev.root","recreate");
205 
206  h1Ev1Ch->Write();
207  h1EvAllCh->Write();
208  h1Ev2D->Write();
209 
210  h1EvFFT1Ch->Write();
211  h1EvFFTAllCh->Write();
212  h1EvFFT2D->Write();
213 
214  h1EvPed1Ch->Write();
215  h1EvPedAllCh->Write();
216  h1EvPed2D->Write();
217 
218  file->Close();
219 
220  h1Ev1Ch->Delete();
221  h1EvAllCh->Delete();
222  h1Ev2D->Delete();
223  h1EvFFT1Ch->Delete();
224  h1EvFFTAllCh->Delete();
225  h1EvFFT2D->Delete();
226  h1EvPed1Ch->Delete();
227  h1EvPedAllCh->Delete();
228  h1EvPed2D->Delete();
229 
230 
231 
232  } else {
233  std::cout << "No Data Map for plane " << std::endl;
234  }
235 
236  c->Update();
237  c2->Update();
238 
239 
240  int iscan;
241  printf("Event %d done. Waiting for input to continue: ",nEvents);
242  if(scanf("%d",&iscan) == 1)
243  std::cout << "Advance to next event" << std::endl;
244  else
245  std::cout << "Scan all events" << std::endl;
246 
247 }
248 
250 {
251  // m_hmap[0] = new HarpoMap(0);
252  // m_hmap[1] = new HarpoMap(1);
253 
254  h1Ch = new TH1F("h1Ch",";time [tb]",511,0,511);
255  hAllCh = new TH1F("hAllCh",";time [tb]",511,0,511);
256  h2D = new TH2F("h2D",";time [tb]; channel",511,0,511,304,0,304);
257 
258  hFFT1Ch = new TH1F("hFFT1Ch",";freq []",511,0,511);
259  hFFTAllCh = new TH1F("hFFTAllCh",";freq []",511,0,511);
260  hFFT2D = new TH2F("hFFT2D",";freq []; channel",511,0,511,304,0,304);
261 
262  hPed1Ch = new TH1F("hPed1Ch",";pedesteal [ADC]",500,0,500);
263  hPedAllCh = new TH1F("hPedAllCh",";pedesteal [ADC]",500,0,500);
264  hPed2D = new TH2F("hPed2D",";pedesteal [ADC]; channel",500,0,500,304,0,304);
265 
266 }
267 
268 void HarpoDccAnalyseNoiseMonitor::Save(char * /* mode */)
269 {
270  TCanvas *c = (TCanvas *)gROOT->GetListOfCanvases()->FindObject("cHarpo");
271  if(c){
272  c->SaveAs("noise.png");
273  c->SaveAs("noise.C");
274  }
275  // TString * hstFile = gHConfig->GetHistFile();
276  // if ( hstFile == NULL ) {
277  // std::cout << gHConfig->GetProgramName() << " " <<
278  // "No Hist File name gived, use default" << std::endl;
279  // hstFile = new TString("harpohst.root");
280  // }
281 
282  TFile* file = new TFile("noise.root","recreate");
283 
284  h1Ch->Write();
285  hAllCh->Write();
286  h2D->Write();
287 
288  hFFT1Ch->Write();
289  hFFTAllCh->Write();
290  hFFT2D->Write();
291 
292  hPed1Ch->Write();
293  hPedAllCh->Write();
294  hPed2D->Write();
295 
296  file->Close();
297  // TFile *hf = new TFile(hstFile->Data(),"RECREATE");
298  // hf->Close();
299 }
300 
301 
302 
303 
304 
305 
306 
307 // Double_t HarpoDccAnalyseNoiseMonitor::TruncMean(TArrayD* vect, Double_t tl, Double_t th)
308 // {
309 // //
310 // // Calculates the truncated mean mean of the non zero value in vect
311 // // The truncation is done on the 100*tl% lowest and 100*(1-th) highest value
312 // //
313 // // debug(2,"truncated mean");
314 
315 
316 // Int_t size = vect->GetSize();
317 // Double_t truncMean = 0;
318 // Int_t* index = new Int_t[size];
319 // TMath::Sort(size,vect->GetArray(),index,kFALSE);
320 // Int_t t = 0, tLow, tHigh;
321 
322 
323 // while(vect->At(index[t])<10&&t<size-1) t++;
324 // tLow = TMath::FloorNint(t + (size - t)*tl);
325 // tHigh = TMath::FloorNint(t + (size - t)*th);
326 
327 // for(Int_t tind = tLow; tind<tHigh; tind++) truncMean += vect->At(index[tind]);
328 // if(tHigh-tLow) {
329 // return truncMean/(tHigh-tLow);
330 // }
331 // else return 0;
332 // }
333 
334 
335 
#define NALL
Definition: HarpoDccMap.h:15
Double_t GetData(Int_t i, Int_t j)
Set/Get Data Cell.
Definition: HarpoDccMap.cxx:84
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
TH1F * h1Ch
Redefine empty default.
HarpoDccEvent * anaEvt
#define NADC
Definition: HarpoDccMap.h:18
HarpoDccMap * GetMap()
A virtual class which define intrafece between HARPO Reader and Event Analysis code.