]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/OnlineDisplay/AliHLTPHOSOnlineDisplayFourierTab.cxx
Changes for #64259 Request for including the new class AliTRDresponse in STEER and...
[u/mrichter/AliRoot.git] / HLT / PHOS / OnlineDisplay / AliHLTPHOSOnlineDisplayFourierTab.cxx
1 // $Id$
2
3 /**************************************************************************
4  * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved.      *
5  *                                                                        *
6  * Authors: Per Thomas Hille for the ALICE                                *
7  * offline/HLT Project. Contributors are mentioned in the code where      *
8  * appropriate.                                                           *
9  *                                                                        *
10  * Permission to use, copy, modify and distribute this software and its   *
11  * documentation strictly for non-commercial purposes is hereby granted   *
12  * without fee, provided that the above copyright notice appears in all   *
13  * copies and that both the copyright notice and this permission notice   *
14  * appear in the supporting documentation. The authors make no claims     *
15  * about the suitability of this software for any purpose. It is          *
16  * provided "as is" without express or implied warranty.                  *
17  **************************************************************************/
18
19 #include "AliHLTPHOSOnlineDisplayFourierTab.h"
20 #include <iostream>
21 #include "TGFrame.h"
22 #include "AliHLTPHOSGetEventButton.h"
23 #include "AliHLTPHOSCommonDefs.h"
24 #include "AliHLTDataTypes.h"
25 #include "AliHLTHOMERData.h"
26 #include "AliHLTHOMERReader.h"
27 #include "AliHLTHOMERWriter.h"
28 //#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
29 //#include "AliHLTPHOSRcuCellEnergyDataStruct.h"
30 //#include "AliHLTPHOSRcuCellEnergyDataStruct.h" 
31 #include "AliHLTPHOSOnlineDisplay.h"
32 #include "AliHLTPHOSSharedMemoryInterfacev2.h"
33 #include "AliHLTPHOSFourier.h"
34 #include "AliHLTPHOSOnlineDisplayTH2D.h"
35
36
37 #include "AliHLTPHOSRcuFFTDataStruct.h"
38 #include "TStyle.h"
39
40 #define SAMPLINGFREQUENCY 10
41
42 using namespace std;
43
44 // MT Crap
45 #include <TMath.h>
46 //#include <TEveManager.h>
47 //#include <TEveBoxSet.h>
48
49 //TEveBoxSet* gAliEveBoxSet = 0;
50
51 AliHLTPHOSOnlineDisplayFourierTab::AliHLTPHOSOnlineDisplayFourierTab()
52 {
53   // See header file for documentation
54   cout << "ERROR: You cannot create a onlinedisplay Tab without arguments" << endl;
55 }
56
57
58 AliHLTPHOSOnlineDisplayFourierTab::AliHLTPHOSOnlineDisplayFourierTab(AliHLTPHOSOnlineDisplay * const onlineDisplayPtr, TGTab  *tabPtr, 
59                                                                      const AliHLTHOMERReader * homerSyncPtr, const AliHLTHOMERReader * const homerPtrs[MAXHOSTS], int nHosts) :  AliHLTPHOSOnlineDisplayTab(), fEvtCnt(0)
60 {     
61   // See header file for documentation
62   // gStyle->SetOptLogy();
63   // gStyle->SetOptStat(false);
64   
65
66   fShmPtr = new AliHLTPHOSSharedMemoryInterfacev2();
67   fOnlineDisplayPtr =  onlineDisplayPtr;
68   fFourierPtr = new AliHLTPHOSFourier();
69
70   for(int gain = 0; gain < NGAINS; gain ++ )
71     {
72       fFourierHistoNew[gain] = 0;
73       fFourierHistoOld[gain] = 0;
74       fFourierHistoAccumulated[gain] = 0;
75     }
76
77   for(int i=0; i<MAXHOSTS; i++)
78     {
79        fgHomerReadersPtr[i] = 0;
80     }
81
82   fgHomerReaderPtr = const_cast<AliHLTHOMERReader*>(homerSyncPtr);
83   
84   for(int i=0; i<nHosts; i++)
85     {
86       fgHomerReadersPtr[i] = const_cast<AliHLTHOMERReader*>(homerPtrs[i]);
87
88     }
89
90   fgNHosts = nHosts;
91   InitDisplay(tabPtr);
92 }
93
94
95 AliHLTPHOSOnlineDisplayFourierTab::~AliHLTPHOSOnlineDisplayFourierTab()
96
97 {
98   // See header file for documentation
99 }
100
101
102
103 int
104 AliHLTPHOSOnlineDisplayFourierTab::GetNextEvent()
105 {
106   // See header file for documentation
107   //  ResetDisplay();
108   DoGetNextEvent();
109   //  FillHistograms();
110   UpdateDisplay();
111   fEvtCnt ++;
112   // fgEvntCnt ++;
113
114  
115 }
116
117
118
119 void 
120 AliHLTPHOSOnlineDisplayFourierTab::ReadBlockData(AliHLTHOMERReader * const homeReaderPtr)
121
122   // See header file for documentation
123   //  AliHLTPHOSValidCellDataStruct *currentChannel =0;
124   cout << "AliHLTPHOSOnlineDisplayFourierTab::ReadBlockDat, Reading block data, therere are " <<  homeReaderPtr->GetBlockCnt() << " blocks " <<endl;
125   //  unsigned long blk = homeReaderPtr->FindBlockNdx("RENELLEC","SOHP", 0xFFFFFFFF );
126
127 //   while ( blk != ~(unsigned long)0 ) 
128 //     {
129 //       Int_t moduleID;
130 //       Int_t rcuX = 0;
131 //       Int_t rcuZ = 0;
132 //       AliHLTPHOSRcuCellEnergyDataStruct* cellEnergiesPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)homeReaderPtr->GetBlockData( blk ); 
133       
134 //       unsigned int *t = (unsigned int*)cellEnergiesPtr;
135       
136 //       moduleID = cellEnergiesPtr->fModuleID ;
137 //       rcuX = cellEnergiesPtr->fRcuX;
138 //       rcuZ = cellEnergiesPtr->fRcuZ;
139
140 //       cout << "AliHLTPHOSOnlineDisplayFourierTab::ReadBlockData,  fModuleID =" <<moduleID << endl; 
141
142 //       Int_t tmpZ;
143 //       Int_t tmpX;
144 //       Int_t tmpGain;
145 //       int cnt = 0;
146 //       Int_t* tmpPtr = 0;
147
148 //       fShmPtr->SetMemory(cellEnergiesPtr);
149 //       currentChannel = fShmPtr->NextChannel();
150
151 //       while(currentChannel != 0)
152 //      {
153 //        cnt ++;
154 //        tmpZ = currentChannel->fZ;
155 //        tmpX = currentChannel->fX;
156 //        tmpGain =  currentChannel->fGain;
157
158 //        if(cellEnergiesPtr->fHasRawData == true)
159 //          {
160 //            Int_t nSamples = 0;
161 //            Int_t* rawPtr = 0;
162 //            rawPtr = fShmPtr->GetRawData(nSamples);
163 //            fFourierPtr->ProcessFourier(rawPtr, nSamples, tmpZ, tmpX, tmpGain, fEvtCnt);
164 //          }
165           
166 //        currentChannel = fShmPtr->NextChannel();
167 //      }
168 //       blk = homeReaderPtr->FindBlockNdx("RENELLEC","SOHP", 0xFFFFFFFF, blk+1);
169 //     }
170
171 //  FillHistograms(fFourierPtr->GetPSD(), fFourierPtr->GetDataSize());
172
173   unsigned long blk = homeReaderPtr->FindBlockNdx("TREIRUOF","SOHP", 0x0);
174   while ( blk != ~(unsigned long)0 ) 
175     {  
176       AliHLTPHOSRcuFFTDataStruct* fftDataPtr = (AliHLTPHOSRcuFFTDataStruct*)homeReaderPtr->GetBlockData( blk );
177       FillHistograms(*fftDataPtr, fftDataPtr->fDataLength);
178
179       blk = homeReaderPtr->FindBlockNdx("TREIRUOF","SOHP", blk+1);
180     }
181 }
182
183
184
185 void 
186 AliHLTPHOSOnlineDisplayFourierTab::FillHistograms(const AliHLTPHOSRcuFFTDataStruct psd, const int size)
187 {
188   // See header file for documentation
189   //  gStyle->SetOptLogy();
190   //  gStyle->SetOptStat(false);
191
192   char tmpname[256];
193   char tmptitle[256];
194
195   int linewidth = 0;
196   // double  linewidth = 1.2;
197
198   for(int gain = 0; gain < NGAINS; gain ++ )
199     {
200       if( fFourierHistoNew[gain] == 0)
201         {
202           sprintf(tmptitle, "PSD averaged over all %s channels: Most recent event", Gain2Text(gain, ' ')); 
203           sprintf(tmpname,  "PSD_averaged_over_all_%s_channels__most_recent_event", Gain2Text(gain, '_'));  
204           fFourierHistoNew[gain] = new TH1D(tmpname, tmptitle,  (size/2) +1, 0, SAMPLINGFREQUENCY/2);
205           fFourierHistoNew[gain]->GetXaxis()->SetTitle("f/MHz");
206           fFourierHistoNew[gain]->GetYaxis()->SetTitle("Power (arbitrary units)"); 
207           fFourierHistoNew[gain]->SetLineWidth(linewidth);
208
209         }
210       if (fFourierHistoOld[gain] == 0)
211         {
212           sprintf(tmptitle, "PSD averaged over all %s channels: Previous event", Gain2Text(gain, ' ')); 
213           sprintf(tmpname,  "PSD_averaged_over_all_%s_channels__previous_event", Gain2Text(gain, '_')); 
214           fFourierHistoOld[gain] = new TH1D(tmpname, tmptitle,  (size/2) +1, 0, SAMPLINGFREQUENCY/2);
215           fFourierHistoOld[gain]->GetXaxis()->SetTitle("f/MHz");
216           fFourierHistoOld[gain]->GetYaxis()->SetTitle("Power (arbitrary units)"); 
217           fFourierHistoOld[gain]->SetLineWidth(linewidth);
218
219         }
220       if( fFourierHistoAccumulated[gain] == 0 )
221         {
222           sprintf(tmptitle, "PSD averaged over all %s channels: All events", Gain2Text(gain, ' ')); 
223           sprintf(tmpname,  "PSD_averaged_over_all_%s_channels__All_events", Gain2Text(gain, '_')); 
224           fFourierHistoAccumulated[gain] = new TH1D(tmpname, tmptitle,  (size/2) +1, 0, SAMPLINGFREQUENCY/2);
225           fFourierHistoAccumulated[gain]->GetXaxis()->SetTitle("f/MHz");
226           fFourierHistoAccumulated[gain]->GetYaxis()->SetTitle("Power (arbitrary units)"); 
227           fFourierHistoAccumulated[gain]->SetLineWidth(linewidth);
228
229         }
230
231 //       fFourierHistoNew[gain]->Reset();
232 //       fFourierHistoOld[gain]->Reset();
233 //       fFourierHistoAccumulated[gain]->Reset();
234       
235       for(int i = 0; i <size/2; i++)
236         {
237           fFourierHistoOld[gain]->SetBinContent(i+1,  fFourierHistoNew[gain]->GetBinContent(i+1));
238           fFourierHistoNew[gain]->SetBinContent(i+1,  psd.fGlobalLastPSD[gain][i] );
239           fFourierHistoAccumulated[gain]->SetBinContent(i+1,  psd.fGlobalAccumulatedPSD[gain][i] );
240         }
241
242     }
243 }
244
245
246
247
248 void
249 AliHLTPHOSOnlineDisplayFourierTab::InitDisplay(TGTab  *tabPtr)
250 {
251   // See header file for documentatino
252   for(int gain=0; gain < NGAINS; gain++)
253     {
254       char gainLabel[100];
255       char label[256];
256  
257       //     Gain2Text
258       fOnlineDisplayPtr->Gain2Text(gain,gainLabel);
259       sprintf(label, "PHOS Fourier transform %s", gainLabel);
260       fgLegoPlotPtr[gain] = new AliHLTPHOSOnlineDisplayTH2D(fOnlineDisplayPtr, label, label, 
261                                                             NXCOLUMNSMOD*NMODULES , 0, NXCOLUMNSMOD*NMODULES,  
262                                                             NZROWSMOD,   0, NZROWSMOD);   
263            //    fgLegoPlotPtr[gain]->SetGain(HIGHGAIN);
264       fgLegoPlotPtr[gain]->SetMaximum(1023);
265       fgLegoPlotPtr[gain]->Reset();
266       fgLegoPlotPtr[gain]->GetXaxis()->SetRange(XRANGESTART, XRANGEEND);
267  
268    }
269   
270
271
272   TGLayoutHints *fL1 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
273                                          kLHintsExpandY, 2, 2, 15, 1);
274
275   TGCompositeFrame *tf = tabPtr->AddTab("Power spectrum");
276   fSubTab1 = new TGTab(tf, 100, 100);
277   TGCompositeFrame *tf2 = fSubTab1->AddTab("Most recent event");  
278   fSubF1 = new TGCompositeFrame(tf2, 60, 20, kVerticalFrame);
279   fEc1 = new TRootEmbeddedCanvas("ecf1", fSubF1, 100, 100);
280   fSubF1->AddFrame(fEc1, fL1);
281   fEc2 = new TRootEmbeddedCanvas("ecf2", fSubF1, 100, 100);
282   fSubF1->AddFrame(fEc2, fL1);
283   tf2->AddFrame(fSubF1, fL1);
284   
285   tf2 = fSubTab1->AddTab("Previous event"); 
286   fSubF2 = new TGCompositeFrame(tf2, 60, 20, kVerticalFrame);
287   tf2->AddFrame(fSubF2, fL1);
288   fEc3 = new TRootEmbeddedCanvas("ecf3", fSubF2, 100, 100);
289   fSubF2->AddFrame(fEc3, fL1);
290   fEc4 = new TRootEmbeddedCanvas("ecf4", fSubF2, 100, 100);
291   fSubF2->AddFrame(fEc4, fL1);
292  
293   
294   tf2 = fSubTab1->AddTab("Accumulated"); 
295   fSubF3 = new TGCompositeFrame(tf2, 60, 20, kVerticalFrame);
296   tf2->AddFrame(fSubF3, fL1);
297   fEc5 = new TRootEmbeddedCanvas("ecf5", fSubF3, 100, 100);
298   fSubF3->AddFrame(fEc5, fL1);
299   fEc6 = new TRootEmbeddedCanvas("ecf6", fSubF3, 100, 100);
300   fSubF3->AddFrame(fEc6, fL1);
301   fSubTab1->Resize();
302   tf->AddFrame(fSubTab1, fL1);
303   
304
305   fgEventButtPtr = new  AliHLTPHOSGetEventButton(fSubF1, "get fourier", 'e');
306 }
307
308
309
310 void
311 AliHLTPHOSOnlineDisplayFourierTab::UpdateDisplay()
312 {
313   // See header file for documentation
314   if( fFourierHistoNew[HIGHGAIN])
315     {
316       fgCanvasPtr[HIGHGAIN] =  fEc1->GetCanvas();
317       fgCanvasPtr[HIGHGAIN]->cd();
318       gPad->SetLogy();
319       //  fgLegoPlotPtr[HIGHGAIN]->Draw("LGZ");
320       fFourierHistoNew[HIGHGAIN]->Draw();
321       fgCanvasPtr[HIGHGAIN]->Update();
322     }
323
324   if( fFourierHistoNew[LOWGAIN])
325     {
326       fgCanvasPtr[LOWGAIN] = fEc2->GetCanvas();
327       fgCanvasPtr[LOWGAIN]->cd();
328       gPad->SetLogy();
329       //  fgLegoPlotPtr[LOWGAIN]->Draw("HGZ");
330       fFourierHistoNew[LOWGAIN]->Draw();
331       fgCanvasPtr[LOWGAIN]->Update();
332     }
333   if( fFourierHistoOld[HIGHGAIN])
334     {
335       fgCanvasPtr[HIGHGAIN] =  fEc3->GetCanvas();
336       fgCanvasPtr[HIGHGAIN]->cd();
337       gPad->SetLogy();
338       // fgLegoPlotPtr[HIGHGAIN]->Draw("Low gain");
339       fFourierHistoOld[HIGHGAIN]->Draw();
340       fgCanvasPtr[HIGHGAIN]->Update();
341     }
342
343   if( fFourierHistoOld[LOWGAIN])
344     {
345       fgCanvasPtr[LOWGAIN] = fEc4->GetCanvas();
346       fgCanvasPtr[LOWGAIN]->cd();
347       //fgLegoPlotPtr[LOWGAIN]->Draw("High gain");
348       gPad->SetLogy();
349       fFourierHistoOld[LOWGAIN]->Draw();
350       fgCanvasPtr[LOWGAIN]->Update();
351     }
352
353   if( fFourierHistoAccumulated[HIGHGAIN])
354     {
355       fgCanvasPtr[HIGHGAIN] =  fEc5->GetCanvas();
356       fgCanvasPtr[HIGHGAIN]->cd();
357       gPad->SetLogy();
358       fFourierHistoAccumulated[HIGHGAIN]->Draw();
359       //  fgLegoPlotPtr[HIGHGAIN]->Draw("CONTZ");
360       fgCanvasPtr[HIGHGAIN]->Update();
361     }
362
363   if( fFourierHistoAccumulated[LOWGAIN])
364     {
365       fgCanvasPtr[LOWGAIN] = fEc6->GetCanvas();
366       fgCanvasPtr[LOWGAIN]->cd();
367       gPad->SetLogy();
368       //  fgLegoPlotPtr[LOWGAIN]->Draw("CONTZ");
369       fFourierHistoAccumulated[LOWGAIN]->Draw();
370       fgCanvasPtr[LOWGAIN]->Update();
371     }
372   
373 }
374
375
376 const  char* 
377 AliHLTPHOSOnlineDisplayFourierTab::Gain2Text(const int gain, const char delimeter)
378 {
379   // See header file for documentation
380   if(gain ==  LOWGAIN)
381     {
382       sprintf(fGainText, "low%cgain", delimeter);
383
384     }
385   else if(gain ==  HIGHGAIN)
386     {
387       sprintf(fGainText, "high%cgain", delimeter);
388     }
389   else
390     {
391       sprintf(fGainText, "Error, invalid gain");
392     }
393   return fGainText;
394 }