StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fgtOfflineEventDisplay.C
1 /*
2  * \class fgtEvDisFrame
3  * \author S. Gliske, Jan 2012 (sgliske@anl.gov)
4  *
5  * Provides a GUI interface to step through event display histograms,
6  * as generated by the macro fgtSingleEvents.C
7  *
8  */
9 
10 
11 #include <TGClient.h>
12 #include <TCanvas.h>
13 #include <TF1.h>
14 #include <TRandom.h>
15 #include <TGButton.h>
16 #include <TGFrame.h>
17 #include <TRootEmbeddedCanvas.h>
18 #include <RQ_OBJECT.h>
19 
21  RQ_OBJECT("fgtEvDisFrame")
22 private:
23  enum { kEvent, kTimeBin, kDisc, kQuad, kNum = 4 };
24 
25  TGMainFrame *mMain;
26  TRootEmbeddedCanvas *mEcanvas;
27 
28  TGLayoutHints *mLayHintMain, *mLayHintPlot, *mLayHintOptions, *mLayHintNum;
29  TGLayoutHints *mLayHintButton, *mLayHintRad;
30 
31  // frames
32  TGHorizontalFrame *mMainHortzFrame;
33  TGVerticalFrame *mOptFrame;
34  TGVerticalFrame *mNumFrame;
35  TGHorizontalFrame *mNumFrameInner[kNum];
36  TGHorizontalFrame *mButtonFrame;
37 
38  // numbers
39  TGNumberEntry *mNumEntry[kNum];
40  TGLabel *mNumLabel[kNum];
41  TGGroupFrame *mRadioFrame;
42  TGRadioButton *mRad1, *mRad2;
43 
44  // buttons
45  TGTextButton *mDrawButton;
46  TGTextButton *mExitButton;
47 
48  // message bar
49  TGCompositeFrame *mMessFrame;
50  TGLabel *mMessLabel;
51 
52  // for interfacing plots
53  std::string mLastName;
54  std::stringstream mSS;
55 
56  // for opening the histograms
57  TFile *mTFile;
58  TH2F *hPlast, *hRlast;
59 
60 
61 public:
62  // constructor & deconstructor
63  fgtEvDisFrame( const TGWindow *p,UInt_t w,UInt_t h, const Char_t *filename );
64  virtual ~fgtEvDisFrame();
65 
66  // the real "action" functions
67  void DoDraw();
68  void HandleButtons();
69  void GetHists( const std::string& name, TH2F* &hP, TH2F* &hR );
70 };
71 
72 // initialize numbers
73 Int_t numinit[] = { 0, 2, 0, 0, 0 };
74 const Char_t *numlabel[50] = { "Event", "Time Bin", "Disc", "Quad", "Side" };
75 
76 fgtEvDisFrame::fgtEvDisFrame(const TGWindow *p,UInt_t w,UInt_t h, const Char_t *filename )
77  : hPlast(0), hRlast(0) {
78 
79  mTFile = new TFile( filename, "READ" );
80  if( !mTFile || !mTFile->IsOpen() ){
81  cerr << "ERROR opening file '" << filename << "'" << endl;
82  return;
83  };
84 
85  // style
86  gROOT->SetStyle("Plain");
87 
88  // Create a main frame
89  mMain = new TGMainFrame(p,w,h);
90 
91  // Make a hortz frame to divide in half
92  mMainHortzFrame = new TGHorizontalFrame(mMain, 1000, 2000);
93  mLayHintMain = new TGLayoutHints(kLHintsCenterY|kLHintsCenterX|kLHintsTop|kLHintsLeft|kLHintsExpandX|kLHintsExpandY,10,10,10,1);
94  mMain->AddFrame( mMainHortzFrame, mLayHintMain );
95 
96  // Create canvas widget
97  mEcanvas = new TRootEmbeddedCanvas("Ecanvas",mMainHortzFrame,700,600);
98 
99  // divide the canvas
100  gStyle->SetOptStat(0);
101  TCanvas *canPtr = mEcanvas->GetCanvas();
102  canPtr->SetBorderSize(0);
103  canPtr->Divide(2,1);
104  canPtr->cd(1);
105  gPad->SetBorderMode(0);
106  gPad->SetTopMargin(0.01);
107  gPad->SetRightMargin(0.16);
108  gPad->SetLeftMargin(0.1);
109  canPtr->cd(2);
110  gPad->SetBorderMode(0);
111  gPad->SetTopMargin(0.01);
112  gPad->SetRightMargin(0.16);
113  gPad->SetLeftMargin(0.15);
114 
115  // add the canvas with layout hints
116  mLayHintPlot = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX|kLHintsExpandY,10,10,10,10);
117  mMainHortzFrame->AddFrame(mEcanvas, mLayHintPlot);
118 
119 
120  // now a frame for all the options
121  mOptFrame = new TGVerticalFrame( mMainHortzFrame, 50, 50 );
122  mLayHintOptions = new TGLayoutHints(kLHintsTop|kLHintsRight|kLHintsExpandY,10,10,10,10);
123  mMainHortzFrame->AddFrame(mOptFrame, mLayHintOptions );
124 
125  // number entries
126  mNumFrame = new TGVerticalFrame(mOptFrame, 200, 300);
127  mLayHintNums = new TGLayoutHints(kLHintsCenterY|kLHintsExpandX, 2, 2, 2, 2);
128  mOptFrame->AddFrame(mNumFrame, mLayHintNums );
129 
130  for( Int_t i = 0; i < kNum; ++i ){
131  // frame
132  mNumFrameInner[i] = new TGHorizontalFrame(mNumFrame, 200, 30);
133  mNumFrame->AddFrame(mNumFrameInner[i], mLayHintNums);
134 
135  // label
136  mNumLabel[i] = new TGLabel(mNumFrameInner[i], numlabel[i] );
137  mNumFrameInner[i]->AddFrame(mNumLabel[i], mLayHintNums);
138 
139  // number entry
140  mNumEntry[i] = new TGNumberEntry(mNumFrameInner[i], numinit[i], 12, i + 20,(TGNumberFormat::EStyle) 0);
141  mNumFrameInner[i]->AddFrame(mNumEntry[i], mLayHintNums);
142 
143  // set to signal draw
144  mNumEntry[i]->Connect("ValueSet(Long_t)","fgtEvDisFrame",this,"DoDraw()");
145  };
146 
147  mNumEntry[kEvent] ->SetLimits(TGNumberFormat::kNELLimitMin, 0, 100 );
148  mNumEntry[kTimeBin]->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, 4 );
149  mNumEntry[kDisc] ->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, 5 );
150  mNumEntry[kQuad] ->SetLimits(TGNumberFormat::kNELLimitMinMax, 0, 3 );
151 
152  // Create a horizontal frame widget with buttons
153  mButtonFrame = new TGHorizontalFrame(mOptFrame,200,40);
154  mDrawButton = new TGTextButton(mButtonFrame,"&Draw");
155  mDrawButton->Connect("Clicked()","fgtEvDisFrame",this,"DoDraw()");
156  mButtonFrame->AddFrame(mDrawButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
157 
158  mExitButton = new TGTextButton(mButtonFrame,"&Exit","gApplication->Terminate(0)");
159  mButtonFrame->AddFrame(mExitButton, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
160  mOptFrame->AddFrame( mButtonFrame, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
161 
162  // message
163  mMessFrame = new TGCompositeFrame( mOptFrame, 100, 100, kSunkenFrame);
164  mOptFrame->AddFrame( mMessFrame, new TGLayoutHints(kLHintsLeft|kLHintsLeft|kLHintsExpandX,3,3,3,3) );
165  mMessLabel = new TGLabel( mMessFrame, "initializing the class" );
166  mMessLabel->SetTextJustify( kTextCenterY|kTextLeft );
167  mMessFrame->AddFrame( mMessLabel, new TGLayoutHints( kLHintsTop|kLHintsExpandX, 2,2,2,2 ));
168 
169  mRadioFrame = new TGGroupFrame( mNumFrame, "Octant" );
170  mNumFrame->AddFrame( mRadioFrame, mLayHintNums );
171 
172  mRad1 = new TGRadioButton(mRadioFrame, "&Long Side", 81);
173  mRad2 = new TGRadioButton(mRadioFrame, "&Short Side", 82);
174  mRad1->SetState(kButtonDown);
175  mRad2->SetState(kButtonUp);
176 
177  mLayHintRad = new TGLayoutHints( kLHintsCenterX, 2,2,2,2 );
178  mRadioFrame->AddFrame( mRad1, mLayHintRad );
179  mRadioFrame->AddFrame( mRad2, mLayHintRad );
180  mRad1->Connect("Clicked()", "fgtEvDisFrame", this, "HandleButtons()");
181  mRad2->Connect("Clicked()", "fgtEvDisFrame", this, "HandleButtons()");
182 
183 
184  // Set a name to the main frame
185  mMain->SetWindowName("Offline FGT Event Display");
186  // Map all subwindows of main frame
187 // mButtonFrame->MapWindow();
188 // mNumFrame->MapSubwindows();
189 // mOptFrame->MapSubwindows();
190 // mMainHortzFrame->MapSubwindows();
191  mMain->MapSubwindows();
192 
193  // Initialize the layout algorithm
194  mMain->Resize(mMain->GetDefaultSize());
195 
196  cout << "Mapping main window" << endl;
197  // Map main frame
198  mMain->MapWindow();
199 
200  // Draw the first
201  DoDraw();
202 }
203 
204 void fgtEvDisFrame::DoDraw() {
205  TCanvas *canPtr = mEcanvas->GetCanvas();
206 
207  mSS.str("");
208  mSS.clear();
209  mSS << "h"
210  << "_e" << mNumEntry[kEvent]->GetIntNumber()
211  << "_t" << mNumEntry[kTimeBin]->GetIntNumber()
212  << "_d" << mNumEntry[kDisc]->GetIntNumber()
213  << "_q" << mNumEntry[kQuad]->GetIntNumber()
214  << ( mRad1->GetState() ? 'L' : 'S' );
215  std::string name = mSS.str();
216 
217  if( name != mLastName ){
218  mMessLabel->SetText( "drawing" );
219 
220  TH2F *hP = 0, *hR = 0;
221  GetHists( name, hP, hR );
222 
223  if( hP && hR ){
224  gStyle->SetPalette(1);
225  hP->GetYaxis()->SetBinLabel( 1, "inner" );
226  hP->GetYaxis()->SetBinLabel( 2, "outer" );
227 
228  canPtr->cd(1);
229  hP->GetYaxis()->SetLabelSize(0.06);
230  hP->GetXaxis()->SetTitle("strip number");
231  hP->SetTitle("#phi Strips");
232  hP->SetMinimum( -500 );
233  hP->SetMaximum( 1500 );
234  hP->Draw("COLZ");
235  FixTitle();
236 
237  canPtr->cd(2);
238  hR->SetTitle("Radial Strips");
239  hR->GetXaxis()->SetBinLabel( 1, "#phi in [0,#pi/4]" );
240  hR->GetYaxis()->CenterTitle();
241  hR->GetYaxis()->SetTitleOffset(1.5);
242  hR->GetYaxis()->SetTitle("strip number");
243  hR->GetXaxis()->SetLabelSize(0.06);
244  hR->SetMinimum( -500 );
245  hR->SetMaximum( 1500 );
246  hR->Draw("COLZ");
247  FixTitle();
248  canPtr->Update();
249 
250  mSS.str("");
251  mSS.clear();
252  mSS << "Drew "
253  << "e" << mNumEntry[kEvent]->GetIntNumber()
254  << " t" << mNumEntry[kTimeBin]->GetIntNumber()
255  << " d" << mNumEntry[kDisc]->GetIntNumber()
256  << " q" << mNumEntry[kQuad]->GetIntNumber()
257  << ' ' << ( mRad1->GetState() ? 'L' : 'S' );
258 
259  mMessLabel->SetText( mSS.str().data() );
260  hPlast = hP;
261  hRlast = hR;
262  } else {
263 // canPtr->cd(1);
264 // gPad->GetListOfPrimitives()->RemoveAll();
265 // canPtr->cd(2);
266 // gPad->GetListOfPrimitives()->RemoveAll();
267  canPtr->Clear();
268  canPtr->Divide(2,1);
269  canPtr->Update();
270 
271  mSS.str("");
272  mSS.clear();
273  mSS << "Error with "
274  << "e" << mNumEntry[kEvent]->GetIntNumber()
275  << " t" << mNumEntry[kTimeBin]->GetIntNumber()
276  << " d" << mNumEntry[kDisc]->GetIntNumber()
277  << " q" << mNumEntry[kQuad]->GetIntNumber()
278  << ' ' << ( mRad1->GetState() ? 'L' : 'S' );
279 
280  mMessLabel->SetText( mSS.str().data() );
281  };
282  };
283  mLastName = name;
284 };
285 
286 fgtEvDisFrame::~fgtEvDisFrame() {
287  // Clean up used widgets: frames, buttons, layouthints
288  mMain->Cleanup();
289  delete mMain;
290 }
291 
292 void fgtEvDisFrame::HandleButtons(){
293  // Handle different buttons.
294 
295  Int_t id = -1;
296  if (id == -1) {
297  TGButton *btn = (TGButton *) gTQSender;
298  id = btn->WidgetId();
299  }
300 
301  switch (id) {
302  case 81:
303  mRad2->SetState(kButtonUp);
304  DoDraw();
305  break;
306  case 82:
307  mRad1->SetState(kButtonUp);
308  DoDraw();
309  break;
310  };
311 };
312 
313 
314 void fgtEvDisFrame::FixTitle(){
315  gPad->Update();
316  gPad->Modified();
317 
318  TPaveText *title = (TPaveText*)(gPad->GetPrimitive("title"));
319  if( title ){
320  title->SetX1NDC( 0.045 );
321  title->SetX2NDC( 0.55 );
322  title->SetY1NDC( 0.91 ) ;
323  title->SetY2NDC( 0.999 );
324  title->SetBorderSize(0);
325  title->SetTextAlign( 12 );
326  title->SetTextColor(kBlue);
327  title->Draw();
328  };
329 };
330 
331 void fgtEvDisFrame::GetHists( const std::string& name, TH2F* &hP, TH2F* &hR ){
332 // TH2F *hP = new TH2F( "hP", "", 360, 0, 360, 2, 0, 2 );
333 // TH2F *hR = new TH2F( "hR", "", 1, 0, 0.7854, 280, 0, 280 ); // phi range diff
334 // hP->Fill( 180, 0.1, 100 );
335 // hP->Fill( 181, 0.1, 500 );
336 // hP->Fill( 181, 1.1, 500 );
337 // hP->Fill( 182, 0.1, 100 );
338 // hR->Fill( 0.1, 180, 100 );
339 // hR->Fill( 0.1, 181, 500 );
340 // hR->Fill( 0.1, 182, 100 );
341 
342  hP = (TH2F*)mTFile->Get( (name + "_P").data() );
343  hR = (TH2F*)mTFile->Get( (name + "_R").data() );
344 };
345 
346 void fgtOfflineEventDisplay( const Char_t *filename ) {
347  // Popup the GUI...
348  new fgtEvDisFrame(gClient->GetRoot(),2000,2000, filename );
349 };
350 
351 /*
352  * $Id: fgtOfflineEventDisplay.C,v 1.1 2012/01/31 09:26:18 sgliske Exp $
353  * $Log: fgtOfflineEventDisplay.C,v $
354  * Revision 1.1 2012/01/31 09:26:18 sgliske
355  * StFgtQaMakers moved to StFgtPool
356  *
357  * Revision 1.1 2012/01/24 06:30:46 sgliske
358  * creation
359  *
360  */
361