Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

DisplayCanvas.cxx

Go to the documentation of this file.
00001 
00002 #include "bfemDisplay/DisplayCanvas.h"
00003 
00004 // Options for AnnotatePad() method.
00005 
00006 #define kDrawTitle 1
00007 #define kSetRange 2
00008 #define kShowAxes 4
00009 
00010 
00011 // 
00012 
00014 
00015 
00016 DisplayCanvas::DisplayCanvas( EDControl *evtCtrl ) {
00017 
00018 
00020 
00024 
00025    m_TowerHeight     = 38.81;
00026    m_TowerWidth      = 16.5; 
00027 
00028    frame_x           = m_TowerWidth;
00029    frame_y           = m_TowerWidth;
00030    frame_z           = m_TowerHeight;
00031 
00032    // Event control.
00033    m_evtCtrl = evtCtrl;
00034 
00035    Bool_t isRealData = m_evtCtrl->getRawDataType();  // Real or MC data?
00036 
00037    m_eventTextList = 0;   // List of TPaveTexts for one event.
00038 
00039 
00040    // Data trees.
00041 
00042    fTree = 0;
00043    rTree = 0;
00044 
00045    m_event = 0;
00046    m_recon = 0;
00047 
00048    // CAL, ACD, XGT pedestals.
00049 
00050    m_ped = m_evtCtrl->getCALPeds();
00051 
00052    m_acdped = m_evtCtrl->getACDPeds();
00053 
00054    // m_xgtped = m_evtCtrl->getXGTPeds();
00055     
00056 
00057    // Get pointer to display canvas.
00058    m_canvas = m_evtCtrl->getCanvas();
00059 
00060 
00061    // Make a top-level reference node ( old "ttt" node; seems necessary in order to properly set color
00062    // of  subsequent TBRIKs ).
00063    TBRIK* top = new TBRIK( "top", "top", "void", 0.001, 0.001, 0.001 );
00064 
00065    TNode* m_topNode = new TNode( "topNode", "topNode", "top" );
00066 
00067    // Set up pads
00068    //   setDrawingPads();
00069 
00070    // Create the reference frame.
00071    TBRIK *frame = new TBRIK( "frame", "frame", "void", frame_x, frame_y, frame_z );
00072    frame->SetLineColor( 10 );    // Do not draw - color is white.
00073 
00074    m_frameNode = new TNode( "frameNode", "frameNode", "frame" );
00075   
00076    // Create frame representing the tower.
00077    TBRIK *tower = new TBRIK( "tower", "tower", "void", m_TowerWidth, m_TowerWidth, m_TowerHeight );
00078    tower->SetLineColor( 10 );  // Do not draw - color is white.
00079 
00080    m_towerNode = new TNode( "towerNode", "towerNode", "tower" );
00081    m_towerNode->cd();
00082 
00083    // Create node and shape structure for the tracker.
00084    m_Tkr = new TkrDisplay( m_towerNode );
00085 
00086    // Create node and shape structure for the CAL.
00087    m_CAL = new CalDisplay( m_towerNode, m_ped );
00088 
00089    // Create node and shape structure for the CAL.
00090    m_Acd = new AcdDisplay( m_towerNode, m_acdped );
00091 
00092 
00093 
00094 
00095    m_currentevent = 0;
00096 
00097    m_scanForward = kTRUE;
00098 
00099    Draw( isRealData );
00100 
00101 
00102 }
00103 
00104 
00105 
00106 
00108 
00119 void DisplayCanvas::Draw( Bool_t dataType ) {
00120 
00121 
00122   // Refresh data tree pointers.
00123 
00124   fTree = m_evtCtrl->getRawTree();
00125   rTree = m_evtCtrl->getReconTree();
00126 
00127   m_event = m_evtCtrl->getEvent();
00128   m_recon = m_evtCtrl->getRecon();
00129 
00130   if ( m_event ) m_event->Clean();
00131 
00132 
00133   if ( fTree ) {
00134     
00135     if ( ( m_currentevent < 0 ) || ( m_currentevent > m_evtCtrl->getEntries() ) ) return;
00136 
00137     fTree->SetBranchStatus("*",0);  // disable all branches
00138     fTree->SetBranchStatus("m_Acd*",1);  // activate branchname
00139     fTree->SetBranchStatus("m_Xgt*",1);  // activate branchname
00140     fTree->SetBranchStatus("m_Tkr*",1);  // activate branchname
00141     fTree->SetBranchStatus("m_Cal*",1);  // activate branchname
00142     fTree->SetBranchStatus("m_eventId", 1); // activate branchname
00143     fTree->SetBranchStatus("m_run", 1); // activate branchname
00144     fTree->GetEvent(m_currentevent);
00145 
00146   }
00147 
00148   if ( rTree ) {
00149     TBranch* TKR = rTree->GetBranch("m_tkr");
00150     TKR->GetEvent( m_currentevent );
00151     TBranch* CALrec = rTree->GetBranch("m_cal");
00152     CALrec->GetEvent( m_currentevent );
00153   }
00154 
00155   m_canvas->Clear();
00156   setDrawingPads();
00157 
00158 
00159   if ( fTree ) {
00160     m_Tkr->DrawEvents( m_event, m_recon );
00161     m_CAL->DrawEvents( m_event, m_recon, dataType );
00162     m_Acd->DrawEvents( m_event );
00163   }
00164 
00165 
00166   // Add some info at top of canvas.
00167 
00168   addEnergyScale();
00169 
00170 
00172   //
00173   // Draw each of the various views in different pads on the canvas.
00174   //
00176 
00177 
00178   // Delete old paves for previous event.
00179   if ( m_eventTextList ) m_eventTextList->Delete();
00180   m_eventTextList = new TObjArray();
00181 
00182 
00183    // ------------------------------------- 3D display
00184 
00185    m_3DPad->cd();
00186 
00187    m_Tkr->setVisibility( kHideNone );  // All hits visible.
00188    m_CAL->setVisibility( kHideNone );
00189 
00190    m_towerNode->DrawClone();
00191 
00192    // N.B. Need DrawClone, otherwise visibility pointers for this pad are changed when re-drawing tower
00193    // on next pad.
00194 
00195    AnnotatePad( m_3DPad, "3D", kSetRange );
00196 
00197 
00198    DrawEventInfo( m_3DPad );   // Show some info about this event.
00199 
00200 
00201    // ------------------------------------- Front - ZX projection.
00202 
00203    m_zxpad->cd();
00204 
00205    m_Tkr->setVisibility( kHideY );  // Hide hits on strips parallel to X-axis ( Y measured coord. )
00206    m_CAL->setVisibility( kHideY );
00207 
00208    m_towerNode->DrawClone();
00209 
00210    AnnotatePad( m_zxpad, "Z-X", kDrawTitle | kSetRange );    // Add title and axes.
00211 
00212   // ------------------------------------- Side - ZY projection.
00213 
00214    m_zypad->cd();
00215 
00216    m_Tkr->setVisibility( kHideX );  // Hide hits on strips parallel to Y-axis ( X measured coord. )
00217    m_CAL->setVisibility( kHideX );
00218 
00219    m_towerNode->DrawClone();
00220 
00221    AnnotatePad( m_zypad, "Z-Y", kDrawTitle | kSetRange );
00222 
00223   // ------------------------------------- Top - XY projection.
00224 
00225    m_xyTopPad->cd();
00226 
00227    m_Tkr->setVisibility( kHideAll );
00228    m_CAL->setVisibility( kHideAll );
00229 
00230    m_towerNode->DrawClone();
00231 
00232    AnnotatePad( m_xyTopPad, "X-Y",  kDrawTitle | kSetRange );    // Add title and axes.
00233 
00234   // ------------------------------------- Top - YX projection.
00235 
00236    m_yxTopPad->cd();
00237 
00238    m_Tkr->setVisibility( kHideAll );
00239    m_CAL->setVisibility( kHideAll );
00240 
00241    m_towerNode->Draw();  // Last can and MUST be normal draw ( otherwise seg. violation! )
00242 
00243    AnnotatePad( m_yxTopPad, "Y-X",  kDrawTitle | kSetRange );    // Add title and axes.
00244 
00245 
00246   
00247 
00248    printf("\nFinished displaying event %i\n",m_currentevent);
00249   
00250 
00251    if ( m_scanForward ) m_currentevent++;
00252 
00253    else m_currentevent--;
00254 
00255   
00256    //   gObjectTable->Print();
00257 
00258    m_3DPad->cd();
00259 
00260    //   m_canvas->SetCanvasSize( 800, 840 );
00261 
00262    m_canvas->Update();
00263 
00264 
00265 }
00266 
00267 
00268 
00269 
00270 void DisplayCanvas::setDrawingPads() {
00271 
00272 
00274 
00275    m_infoPad = new TPad("mainpad","GLAST Display",0.0,0.95,1.0,1.0);
00276    m_infoPad->Draw();
00277 
00278 
00280 
00281    m_3DPad = new TPad("3DPad","GLAST Display",0.0,0.0,0.33,0.95);
00282    m_3DPad->Draw();
00283    m_3DPad->SetTheta(10.0); 
00284    m_3DPad->SetPhi(30.0);
00285 
00286 
00288 
00289    m_zxpad = new TPad("zxpad","GLAST Display",0.33,0.0,0.66,0.64);
00290    m_zxpad->Draw();
00291    m_zxpad->SetTheta(0.); 
00292    m_zxpad->SetPhi(0.);
00293 
00294    
00296 
00297    m_zypad = new TPad("zypad","GLAST Display",0.66,0.0,1.0,0.64);
00298    m_zypad->Draw();
00299    m_zypad->SetPhi(-90.); 
00300    m_zypad->SetTheta(0.);
00301 
00302 
00304 
00305    m_xyTopPad = new TPad("xyTopPad","GLAST Display",0.33,0.64,0.66,0.95);
00306    m_xyTopPad->Draw();
00307    m_xyTopPad->SetTheta(90.); 
00308    m_xyTopPad->SetPhi(0.);
00309 
00310 
00312 
00313    m_yxTopPad = new TPad("yxTopPad","GLAST Display",0.66,0.64,1.0,0.95);
00314    m_yxTopPad->Draw();
00315    m_yxTopPad->SetTheta(90.); 
00316    m_yxTopPad->SetPhi(-90.);
00317 
00318 }
00319 
00320 
00321 void DisplayCanvas::AnnotatePad( TPad *pad, Char_t *title, UShort_t opt ) {
00322 
00323   // Add a title and possibly axes to a pad.
00324 
00325   pad->cd();
00326 
00327   TView *view;
00328   TPaveText *text;
00329 
00330 
00331   if ( opt & kDrawTitle ) {
00332 
00333     Bool_t isTopView = !strcmp( title, "X-Y" ) || !strcmp( title, "Y-X" );
00334 
00335     if ( isTopView ) text = new TPaveText( 0.80, 0.90, 0.95, 0.98, "NDC" );
00336     else text = new TPaveText( 0.80, 0.95, 0.95, 0.99, "NDC" );
00337 
00338     text->SetFillColor( 42 );
00339 
00340     text->AddText( title );
00341     text->SetAllWith( title, "Size", 0.07 );
00342 
00343     text->Draw();
00344 
00345     m_eventTextList->Add( text );
00346 
00347   }
00348 
00349   view = pad->GetView();
00350 
00351   if ( opt & kSetRange ) {
00352 
00353     if ( !strcmp( title, "3D" ) ) view->SetRange( -23.0, -23.0, -35.0, 23.0, 23.0, 55.0 ); // Range for 3D view.
00354     else view->SetRange( -23.0, -23.0, -20.0, 23.0, 23.0, 50.0 );  // Range for all other views.
00355 
00356   }
00357 
00358   if ( opt & kShowAxes ) {  // This option causes crash for some reason!
00359 
00360     view->ShowAxis();
00361 
00362   }
00363 
00364 }
00365 
00366 
00367 
00368 
00369 void DisplayCanvas::DrawEventInfo( TPad *pad ) {
00370 
00371   pad->cd();
00372 
00373   Char_t evt_num[ 50 ];
00374 
00375 
00376   // Allert if there was a gamma convertion
00377   if (m_CAL->m_Gammas) {
00378 
00379     TPaveText *gammas = new TPaveText( 0., 0.12, 0.9, 0.15, "NDC" );
00380 
00381     gammas->SetTextColor(2);
00382     gammas->SetBorderSize( 0 );
00383     gammas->SetTextSize(0.05);
00384 
00385     sprintf( evt_num, "Gamma convertion!!!");
00386 
00387     gammas->AddText( evt_num );
00388 
00389     gammas->Draw();
00390 
00391     m_eventTextList->Add( gammas );  // Add to list of TPaveTexts for event.
00392 
00393   }
00394 
00395   // Info on reconstructed energy in CAL.
00396 
00397   Float_t eTot=0, eCorr=0, eLeak=0;
00398 
00399   if ( rTree ) {
00400 
00401     eTot = m_CAL->m_eTot;
00402     eCorr = m_CAL->m_eCorr;
00403     eLeak = m_CAL->m_eLeak;
00404 
00405   
00406 
00407     TPaveText *ecal = new TPaveText( 0., 0., 0.9, 0.1, "NDC" );
00408 
00409     ecal->SetFillColor( 0 );
00410     ecal->SetBorderSize( 0 );
00411     ecal->SetTextSize(0.05);
00412     ecal->SetTextAlign(12);
00413 
00414     sprintf( evt_num, "CAL: Etot(GeV): %4.2f\n", eTot);
00415 
00416     ecal->AddText( evt_num );
00417 
00418     ecal->Draw();
00419 
00420     sprintf( evt_num, "      Ecorr(GeV): %4.2f\n", eCorr);
00421  
00422     ecal->AddText( evt_num );
00423 
00424     ecal->Draw();
00425 
00426     sprintf( evt_num, "      Eleak(GeV): %4.2f\n", eLeak);
00427  
00428     ecal->AddText( evt_num );
00429     
00430     ecal->Draw();
00431 
00432     m_eventTextList->Add( ecal );  // Add to list of TPaveTexts for event.
00433 
00434   }
00435 
00436   // Event identifier and run number
00437 
00438   TPaveText *text = new TPaveText( 0.0, 0.95, 0.85, 0.98, "NDC" );
00439 
00440   text->SetFillColor( 0 );
00441   text->SetBorderSize( 0 );
00442   text->SetTextSize(0.05);
00443   text->SetTextAlign(12);
00444 
00445   Int_t runID;
00446   Int_t rawEventID;
00447 
00448 
00449   if ( m_event ) {
00450 
00451     runID = m_event->getRunId();
00452     rawEventID = m_event->getEventId();
00453 
00454   }
00455 
00456   else { runID = 0; rawEventID = 0; }
00457 
00458   sprintf( evt_num, " Event Id: %d  --  Run. %d ", rawEventID, runID );
00459 
00460   text->AddText( evt_num );
00461 
00462   text->Draw();
00463 
00464   m_eventTextList->Add( text );  // Add to list of TPaveTexts for event.
00465 
00466 }
00467 
00468 
00469 
00471 
00472 void DisplayCanvas::addEnergyScale(){
00473 
00474    // Add energy scale for CAL and ACDs 
00475 
00476   Int_t colors[ 4 ] = { 3, 4, 2 ,5 };//green,blue,red,yellow
00477 
00478   Float_t calLev[ 4 ] = { m_cal_lev1, m_cal_lev2, m_cal_lev3, m_cal_lev4 };
00479 
00480   Float_t xOffset;
00481 
00482   Float_t x[ 5 ];
00483   Float_t y[ 5 ];
00484 
00485   y[ 0 ] = y[ 1 ] = y[ 4 ] = 0.3;
00486   y[ 2 ] = y[ 3 ] = 0.7;
00487 
00488   m_infoPad->cd();
00489 
00490   TPaveText *CALtext = new TPaveText( 0.6, 0.5, 0.69, 0.9, "NDC" );
00491   CALtext->SetTextSize(0.35);
00492   CALtext->SetFillColor( 0 );
00493   CALtext->SetBorderSize( 0 );
00494   CALtext->AddText( "CAL (MeV): " );
00495   CALtext->Draw();
00496    
00497   TPaveText *CALtext1 = new TPaveText( 0.55, 0.1, 0.69, 0.5, "NDC" );
00498   CALtext1->SetTextSize(0.35); 
00499   CALtext1->SetFillColor( 0 );
00500   CALtext1->SetBorderSize( 0 );
00501   CALtext1->SetTextAlign(32);
00502   CALtext1->AddText( "ACD/CAL (MIP) " );
00503   CALtext1->Draw();
00504   
00505   Char_t text[ 10 ];
00506   Float_t mip;
00507 
00508   for ( Int_t color=0; color<4; ++color ) {
00509 
00510     xOffset = 0.7 + 0.065*color;
00511     
00512     x[ 0 ] = x[ 3 ] = x[ 4 ] = xOffset;
00513     x[ 1 ] = x[ 2 ] = xOffset + 0.02;
00514 
00515     TPolyLine *box = new TPolyLine( 5, x, y );
00516 
00517     box->SetLineColor( colors[ color ] );
00518 
00519     box->Draw();
00520 
00521     TPaveText *CALtext3 = new TPaveText( xOffset+0.025, 0.5, xOffset+0.06, 0.9, "NDC" );
00522     CALtext3->SetTextSize(0.35);
00523     CALtext3->SetFillColor( 0 );
00524     CALtext3->SetBorderSize( 0 );
00525     sprintf( text, "%5.1f ", calLev[ color ] );
00526     CALtext3->AddText( text );
00527     CALtext3->Draw();
00528     TPaveText *CALtext4 = new TPaveText( xOffset+0.025, 0.1, xOffset+0.06, 0.5, "NDC" );
00529     CALtext4->SetTextSize(0.35);
00530     CALtext4->SetFillColor( 0 );
00531     CALtext4->SetBorderSize( 0 );
00532     mip = calLev[ color ]/13.;
00533     sprintf( text, "%5.1f ", mip );
00534     CALtext4->AddText( text );
00535     CALtext4->Draw();
00536   }
00537 
00538 
00539   // Add energy scale for XGTs (in MIP)
00540 
00541   Float_t xgtLev[ 4 ] = { m_xgt_lev1, m_xgt_lev2, m_xgt_lev3, m_xgt_lev4 };
00542 
00543   TPaveText *CALtext5 = new TPaveText( 0.0, 0.3, 0.1, 0.8, "NDC" );
00544   CALtext5->SetTextSize(0.35); 
00545   CALtext5->SetFillColor( 0 );
00546   CALtext5->SetBorderSize( 0 );
00547   CALtext5->AddText( "XGT (MIP) " );
00548   CALtext5->Draw();
00549 
00550 
00551   for ( Int_t color=0; color<4; ++color ) {
00552 
00553     xOffset = 0.1 + 0.065*color;
00554     
00555     x[ 0 ] = x[ 3 ] = x[ 4 ] = xOffset;
00556     x[ 1 ] = x[ 2 ] = xOffset + 0.02;
00557 
00558     TPolyLine *box = new TPolyLine( 5, x, y );
00559 
00560     box->SetLineColor( colors[ color ] );
00561 
00562     box->Draw();
00563 
00564     TPaveText *CALtext4 = new TPaveText( xOffset+0.025, 0.3, xOffset+0.06, 0.8, "NDC" );
00565     CALtext4->SetTextSize(0.35);
00566     CALtext4->SetFillColor( 0 );
00567     CALtext4->SetBorderSize( 0 );
00568     mip = xgtLev[ color ];
00569     sprintf( text, "%5.1f ", mip );
00570     CALtext4->AddText( text );
00571     CALtext4->Draw();
00572 
00573   }
00574 
00575 }
00576 
00578 
00579 void DisplayCanvas::drawAxes(){
00580 
00581 
00582 
00583    TBRIK* x_axis = new TBRIK("x_axis","x_axis","void",frame_x/2.0,m_axis_width,m_axis_width);
00584 
00585    x_axis->SetLineColor(5);
00586 
00587    TBRIK* y_axis = new TBRIK("y_axis","y_axis","void",m_axis_width,frame_y/2.0,m_axis_width);
00588 
00589    y_axis->SetLineColor(6);
00590 
00591    TBRIK* z_axis = new TBRIK("z_axis","z_axis","void",m_axis_width,m_axis_width,frame_z/2.0);
00592 
00593    z_axis->SetLineColor(6);
00594 
00595 }
00596 
00597 
00598 
00600 
00601 Char_t* DisplayCanvas::getText(TString color, Float_t energy){
00602 
00603    Char_t lev[40];
00604 
00605 
00606 
00607    m_TextLine = new TString(color);
00608 
00609    m_TextLine->Append(" > ");
00610 
00611    sprintf(lev,"%6.4f",energy);
00612 
00613    m_TextLine->Append(lev);
00614 
00615    m_TextLine->Append(" GeV"); 
00616 
00617    return (Char_t*)m_TextLine->Data();
00618 
00619 
00620 
00621 }
00622 
00623 
00624 
00626 
00627 Char_t* DisplayCanvas::getTextInt(TString str, Int_t number){
00628 
00629    Char_t lev[40];
00630 
00631 
00632 
00633    m_TextLine = new TString(str);
00634 
00635    sprintf(lev,"%i",number);
00636 
00637    m_TextLine->Append(lev);
00638 
00639    return (Char_t*)m_TextLine->Data();
00640 
00641 
00642 
00643 }
00644 
00645 
00646 
00647 
00648 
00650 
00651 /*void DisplayCanvas::setCalDisplay(Float_t cal1, Float_t cal2, Float_t cal3){
00652 
00653    if ( cal1 < cal2 || cal2 < cal3) {
00654 
00655       printf("invalid input numbers\n");
00656 
00657       return;
00658 
00659    } else {
00660 
00661       cal_lev1 = (Float_t)cal1;
00662 
00663       cal_lev2 = (Float_t)cal2;
00664 
00665       cal_lev3 = (Float_t)cal3;
00666 
00667       return;
00668 
00669    }
00670 
00671 }*/
00672 
00673 
00674 
00675 
00676 
00677 
00678 
00679 
00680 
00681 
00682 
00683 
00684 
00685 
00686 
00687 
00688 
00689 
00690 
00691 
00692 
00693 
00694 
00695 
00696 
00697 
00698 
00699 
00700 
00701 
00702 
00703 
00704 

Generated at Mon Nov 26 18:20:06 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000