Cosmetics
[u/mrichter/AliRoot.git] / HLT / EMCAL / OnlineDisplay / AliHLTEMCALOnlineDisplayEventTab.cxx
1 // $Id: AliHLTEMCALOnlineDisplayEventTab.cxx 35108 2009-09-30 01:58:37Z phille $
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 "AliHLTEMCALOnlineDisplayEventTab.h"
20 #include <iostream>
21 #include "TGFrame.h"
22 #include "AliHLTEMCALGetEventButton.h"
23 #include "AliHLTDataTypes.h"
24 #include "AliHLTHOMERData.h"
25 #include "AliHLTHOMERReader.h"
26 #include "AliHLTHOMERWriter.h"
27 #include "TRootEmbeddedCanvas.h"
28 #include "AliHLTEMCALOnlineDisplay.h"
29 #include "AliHLTCaloChannelDataStruct.h"
30 #include "AliHLTCaloChannelDataHeaderStruct.h"
31 //#include "AliHLTCaloSharedMemoryInterfacev2.h"
32 #include "AliHLTEMCALSharedMemoryInterface.h"
33 #include "AliHLTCaloCoordinate.h"
34 //#include "AliHLTCaloChannelRawDataStruct.h"
35
36
37 using namespace std;
38
39 // MT Crap
40 #include <TMath.h>
41 #include "AliHLTEMCALOnlineDisplayTH2D.h"
42
43 #include <TEveManager.h>
44 #include <TEveBoxSet.h>
45
46 TEveBoxSet* gAliEveBoxSet = 0;
47
48 //gEve = new TEveManager(300, 300);
49
50 AliHLTEMCALOnlineDisplayEventTab::AliHLTEMCALOnlineDisplayEventTab()
51 {
52   cout << "ERROR: You cannot create a onlinedisplay Tab without arguments" << endl;
53 }
54
55
56 AliHLTEMCALOnlineDisplayEventTab::AliHLTEMCALOnlineDisplayEventTab(AliHLTEMCALOnlineDisplay * onlineDisplayPtr, TGTab  *tabPtr, 
57                                                                  AliHLTHOMERReader * homerSyncPtr, AliHLTHOMERReader * homerPtrs[MAXHOSTS], 
58                                                                  int nHosts,  int runnumber) :  AliHLTEMCALOnlineDisplayTab()
59 {
60   
61   //  gEve = new TEveManager(300, 300, kFALSE);
62   
63
64   //comment
65   /*
66   if(fIsSetRunNumber == true)
67     {
68       for(int i=0; i < NGAINS; i++)
69         {
70           fgLegoPlotPtr[gain]
71         }
72    }
73   */
74
75
76   // fShmPtr = new AliHLTEMCALSharedMemoryInterface();
77
78   // fShmPtr = new AliHLTEMCALSharedMemoryInterfacev2();
79  
80   fShmPtr = new AliHLTEMCALSharedMemoryInterface();
81
82   
83
84   fOnlineDisplayPtr =  onlineDisplayPtr;
85
86
87   for(int gain = 0; gain < NGAINS; gain ++ )
88     {
89       fgCanvasPtr[gain] = 0;
90       fgLegoPlotPtr[gain] = 0;
91  
92       
93       for(int mod =0; mod <NMODULES; mod ++)
94         {
95           for(int z = 0; z < NZROWSMOD ; z ++)
96               {
97                 for(int x = 0; x < NXCOLUMNSMOD; x ++)
98                   {
99                     fChannelData[mod][z][x][gain] = new int[ALTROMAXSAMPLES];
100                     fNChannelSamples[mod][z][x][gain] = 0;
101                     fChannelEnergy[mod][z][x][gain] = 0;
102                   }
103               }
104         }
105     }
106
107   for(int i=0; i<MAXHOSTS; i++)
108     {
109        fgHomerReadersPtr[i] = 0;
110     }
111
112   fgHomerReaderPtr = const_cast<AliHLTHOMERReader*>(homerSyncPtr);
113   
114   for(int i=0; i<nHosts; i++)
115     {
116       fgHomerReadersPtr[i] = homerPtrs[i] ;
117
118     }
119
120   fgNHosts = nHosts;
121   InitDisplay(tabPtr, runnumber);
122 }
123
124
125 AliHLTEMCALOnlineDisplayEventTab::~AliHLTEMCALOnlineDisplayEventTab()
126 {
127   //comment
128 }
129
130
131
132 Int_t
133 AliHLTEMCALOnlineDisplayEventTab::GetRawData(TH1D *histPtr, int x, int z, int gain)
134 {
135   
136   //  int tmpModID = x/64;
137   
138   int tmpModID = (x*z)/(NZROWSMOD*NXCOLUMNSMOD);
139
140   // const int NZROWSMOD      =  48;            /**<Number of rows per module*/       
141   //  const int NXCOLUMNSMOD   =  24;     
142   //int tmpModID = x/64;
143
144   /* 
145      int tmpRcuZ = z/32;
146      int tmpRcuX = (x%64)/32;
147      int tmpZ = z%28;
148      int tmpX = x%32;
149   */
150
151   cout << __FILE__ << __LINE__ <<": Getting raw data for mod =" << tmpModID << ", z="<< z << ",x=" << x << endl;
152
153   for(  int i=0;  i <  fNChannelSamples[tmpModID][z][x][gain] ; i++)
154     {
155       histPtr->SetBinContent(i, fChannelData[tmpModID][z][x][gain][i]);  
156     }
157   return fNChannelSamples [tmpModID][z][x][gain];
158 }
159
160
161
162 int
163 AliHLTEMCALOnlineDisplayEventTab::GetNextEvent()
164 {
165   ResetDisplay();
166   DoGetNextEvent();
167   UpdateDisplay();
168   fgEvntCnt ++;
169 }
170
171
172 void
173 AliHLTEMCALOnlineDisplayEventTab::FindFourierBlocks(AliHLTHOMERReader * const homerReaderPtr) const
174 {
175   //comment
176  cout << "AliHLTEMCALOnlineDisplayEventTab::FindFourierBlocks" << endl; 
177   // unsigned long blk = homeReaderPtr->FindBlockNdx("RENELLEC","SOHP", 0xFFFFFFFF );
178   unsigned long blk = homerReaderPtr->FindBlockNdx(" TREIRUOF","SOHP", 0xFFFFFFFF );
179
180   while ( blk != ~(unsigned long)0 )
181     {
182       cout << "AliHLTEMCALOnlineDisplayEventTab::FindFourierBlocks(homerReaderPtr) FOUND FOURIER DATA !!!!!!!!!!!!!!" << endl;
183       blk = homerReaderPtr->FindBlockNdx("TREIRUOF","SOHP", 0xFFFFFFFF );
184     }
185 }
186
187
188 void 
189 AliHLTEMCALOnlineDisplayEventTab::ReadBlockData(AliHLTHOMERReader *homeReaderPtr)
190 {  
191   //  AliHLTEMCALChannelDataStruct *currentChannel =0;
192   AliHLTCaloChannelDataStruct *currentChannel =0; 
193
194  cout << "AliHLTEMCALOnlineDisplayEventTab::ReadBlockDat, Reading block data, therere are " <<  homeReaderPtr->GetBlockCnt() << " blocks " <<endl;
195   FindFourierBlocks(homeReaderPtr);
196   // unsigned long blk = homeReaderPtr->FindBlockNdx("RENELLEC","SOHP", 0xFFFFFFFF );
197   unsigned long blk = homeReaderPtr->FindBlockNdx("TLENNAHC","SOHP", 0xFFFFFFFF );
198   cout << __FILE__ << ":" << __LINE__ << "blk"  << blk  << endl ;
199   int cnt = 0;
200   //
201   //  AliHLTEMCALCoordinate tmpCoord;
202   AliHLTCaloCoordinate tmpCoord;
203   
204
205   while ( blk != ~(unsigned long)0 ) 
206     {
207       
208       //   AliHLTEMCALChannelDataHeaderStruct* cellEnergiesPtr = (AliHLTEMCALChannelDataHeaderStruct*)homeReaderPtr->GetBlockData( blk ); 
209       AliHLTCaloChannelDataHeaderStruct* cellEnergiesPtr = (AliHLTCaloChannelDataHeaderStruct*)homeReaderPtr->GetBlockData( blk );    
210
211       Int_t* tmpPtr = 0;
212       fShmPtr->SetMemory(cellEnergiesPtr);
213       currentChannel = fShmPtr->NextChannel();
214
215       while(currentChannel != 0)
216         {
217           cnt ++;
218           AliHLTEMCALMapper::ChannelId2Coordinate( currentChannel->fChannelID, tmpCoord );
219           fgLegoPlotPtr[ tmpCoord.fGain ]->Fill(  tmpCoord.fModuleId*NXCOLUMNSMOD +   tmpCoord.fX,   tmpCoord.fZ, currentChannel->fEnergy );
220           fChannelEnergy[tmpCoord.fModuleId][tmpCoord.fZ][ tmpCoord.fX][tmpCoord.fGain] =  currentChannel->fEnergy;
221           
222           if(cellEnergiesPtr->fHasRawData == true)
223             {
224               FillRawData(fShmPtr->GetRawData());
225             }
226           currentChannel = fShmPtr->NextChannel();
227         }
228       //      blk = homeReaderPtr->FindBlockNdx("RENELLEC","SOHP", 0xFFFFFFFF, blk+1);
229       blk = homeReaderPtr->FindBlockNdx("TLENNAHC","SOHP", 0xFFFFFFFF, blk+1 );
230     }
231 }
232
233
234 void 
235 ///AliHLTEMCALOnlineDisplayEventTab::FillRawData(const AliHLTEMCALChannelRawDataStruct &rawStr)
236 AliHLTEMCALOnlineDisplayEventTab::FillRawData(const AliHLTCaloChannelRawDataStruct &rawStr)  
237
238 {
239   fNChannelSamples[ rawStr.fCoordinate.fModuleId ][ rawStr.fCoordinate.fZ ]  [ rawStr.fCoordinate.fX ][ rawStr.fCoordinate.fGain ] = rawStr.nSamplesUsed;
240   fChannelEnergy[ rawStr.fCoordinate.fModuleId ][ rawStr.fCoordinate.fZ ]  [ rawStr.fCoordinate.fX ][ rawStr.fCoordinate.fGain ] = rawStr.fEnergy;
241
242
243   /*
244   cout << __FILE__ << __LINE__<< "module ID = " << rawStr.fCoordinate.fModuleId  << endl;
245   cout << __FILE__ << __LINE__<< "fZ = " << rawStr.fCoordinate.fZ   << endl;
246   cout << __FILE__ << __LINE__<< "fX = " << rawStr.fCoordinate.fX   << endl;
247   cout << __FILE__ << __LINE__<< "fGain = " << rawStr.fCoordinate.fGain   << endl; 
248   cout << __FILE__ << __LINE__<< "nSamples = " <<    rawStr.nSamplesUsed   << endl; 
249   */
250
251   for(int i=0; i <  rawStr.nSamplesUsed; i++ )
252     {
253       //   cout <<  "i = "  << i << endl;
254       fChannelData[ rawStr.fCoordinate.fModuleId ][ rawStr.fCoordinate.fZ ]  [ rawStr.fCoordinate.fX ][ rawStr.fCoordinate.fGain ][i] =  rawStr.fDataPtr[i];  
255       //      fChannelData[ rawStr.fCoordinate.fModuleId ][   rawStr.fCoordinate.fX ]  [ rawStr.fCoordinate.fZ ][ rawStr.fCoordinate.fGain ][i] =  rawStr.fDataPtr[i];  
256     }
257
258
259 }
260
261
262
263 void
264 AliHLTEMCALOnlineDisplayEventTab::ResetDisplay()
265 {
266   //comment
267   if(fgAccumulate == kFALSE)
268     {
269       for(int gain=0; gain < NGAINS; gain++)
270         {
271           if(fgLegoPlotPtr[gain] !=0)
272             {
273               fgLegoPlotPtr[gain]->Reset(); 
274             }
275         }
276     } 
277 }
278
279
280 void
281 AliHLTEMCALOnlineDisplayEventTab::InitDisplay(TGTab  * tabPtr, int runnumber)
282 {
283   //  gStyle->SetOptLogy();
284   ///  gStyle->SetOptStat(true);
285
286   for(int gain=0; gain < NGAINS; gain++)
287     {
288       char gainLabel[100];
289       char label[256];
290  
291       //     Gain2Text
292       fOnlineDisplayPtr->Gain2Text(gain,gainLabel);
293       sprintf(label, "EMCAL HLT Online Display %s", gainLabel);
294       fgLegoPlotPtr[gain] = new AliHLTEMCALOnlineDisplayTH2D(fOnlineDisplayPtr, label, label, 
295                                                             NXCOLUMNSMOD*NMODULES , 0, NXCOLUMNSMOD*NMODULES,  
296                                                             NZROWSMOD,   0, NZROWSMOD);   
297       
298       //      cout << __FILE__ << ":" << __LINE__ << " Runnumber = "  << runnumber <<endl;
299    
300       fgLegoPlotPtr[gain]->SetRunNumber(runnumber);
301       fgLegoPlotPtr[gain]->SetMaximum(1023);
302       fgLegoPlotPtr[gain]->Reset();
303       //     fgLegoPlotPtr[gain]->GetXaxis()->SetRange(XRANGESTART, XRANGEEND);
304     }
305   
306
307   TGLayoutHints *fL1 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
308                                          kLHintsExpandY, 2, 2, 15, 1);
309
310   TGCompositeFrame * tf = tabPtr->AddTab("Event display");
311   fSubTab1 = new TGTab(tf, 100, 100);
312   TGCompositeFrame *tf2 = fSubTab1->AddTab("LEGO");  
313   fSubF1 = new TGCompositeFrame(tf2, 60, 20, kVerticalFrame);
314   fEc1 = new TRootEmbeddedCanvas("ec1", fSubF1, 100, 100);
315   fSubF1->AddFrame(fEc1, fL1);
316   fEc2 = new TRootEmbeddedCanvas("ec2", fSubF1, 100, 100);
317   fSubF1->AddFrame(fEc2, fL1);
318   tf2->AddFrame(fSubF1, fL1);
319   
320   tf2 = fSubTab1->AddTab("SCAT"); 
321   fSubF2 = new TGCompositeFrame(tf2, 60, 20, kVerticalFrame);
322   tf2->AddFrame(fSubF2, fL1);
323   fEc3 = new TRootEmbeddedCanvas("ec3", fSubF2, 100, 100);
324   fSubF2->AddFrame(fEc3, fL1);
325   fEc4 = new TRootEmbeddedCanvas("ec4", fSubF2, 100, 100);
326   fSubF2->AddFrame(fEc4, fL1);
327   
328   tf2 = fSubTab1->AddTab("SURF"); 
329   fSubF3 = new TGCompositeFrame(tf2, 60, 20, kVerticalFrame);
330   tf2->AddFrame(fSubF3, fL1);
331   fEc5 = new TRootEmbeddedCanvas("ec5", fSubF3, 100, 100);
332   fSubF3->AddFrame(fEc5, fL1);
333   fEc6 = new TRootEmbeddedCanvas("ec6", fSubF3, 100, 100);
334   fSubF3->AddFrame(fEc6, fL1);
335   fSubTab1->Resize();
336   tf->AddFrame(fSubTab1, fL1);
337
338   fgEventButtPtr = new  AliHLTEMCALGetEventButton(fSubF1, "get event", 'e');
339 }
340
341
342
343 void
344 AliHLTEMCALOnlineDisplayEventTab::UpdateDisplay()
345 {
346   // gStyle->SetOptLogy();
347   //  gStyle->SetOptStat(true);
348
349   fgCanvasPtr[HIGHGAIN] =  fEc1->GetCanvas();
350   fgCanvasPtr[HIGHGAIN]->cd();
351   fgLegoPlotPtr[HIGHGAIN]->Draw("LEGO2Z");
352   fgCanvasPtr[HIGHGAIN]->Update();
353   fgCanvasPtr[LOWGAIN] = fEc2->GetCanvas();
354   fgCanvasPtr[LOWGAIN]->cd();
355   fgLegoPlotPtr[LOWGAIN]->Draw("LEGO2Z");
356   fgCanvasPtr[LOWGAIN]->Update();
357
358   fgCanvasPtr[HIGHGAIN] =  fEc3->GetCanvas();
359   fgCanvasPtr[HIGHGAIN]->cd();
360   fgLegoPlotPtr[HIGHGAIN]->Draw("SCAT");
361   fgCanvasPtr[HIGHGAIN]->Update();
362   fgCanvasPtr[LOWGAIN] = fEc4->GetCanvas();
363   fgCanvasPtr[LOWGAIN]->cd();
364   fgLegoPlotPtr[LOWGAIN]->Draw("SCAT");
365   fgCanvasPtr[LOWGAIN]->Update();
366
367   /* 
368  fgCanvasPtr[HIGHGAIN] =  fEc5->GetCanvas();
369   fgCanvasPtr[HIGHGAIN]->cd();
370   fgLegoPlotPtr[HIGHGAIN]->Draw("CONTZ");
371   fgCanvasPtr[HIGHGAIN]->Update();
372   fgCanvasPtr[LOWGAIN] = fEc6->GetCanvas();
373   fgCanvasPtr[LOWGAIN]->cd();
374   fgLegoPlotPtr[LOWGAIN]->Draw("CONTZ");
375   fgCanvasPtr[LOWGAIN]->Update();
376   */
377
378   fgCanvasPtr[HIGHGAIN] =  fEc5->GetCanvas();
379   fgCanvasPtr[HIGHGAIN]->cd();
380   fgLegoPlotPtr[HIGHGAIN]->Draw("COLZ");
381   fgCanvasPtr[HIGHGAIN]->Update();
382   fgCanvasPtr[LOWGAIN] = fEc6->GetCanvas();
383   fgCanvasPtr[LOWGAIN]->cd();
384   fgLegoPlotPtr[LOWGAIN]->Draw("COLZ");
385   fgCanvasPtr[LOWGAIN]->Update();
386
387
388 }