Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:53

0001 #include <algorithm>
0002 #include <vector>
0003 #include <iostream>
0004 #include <cassert>
0005 using namespace std;
0006 
0007 #include "MEChanPanel.hh"
0008 #include "../../interface/MEGeom.h"
0009 #include "../../interface/MEChannel.h"
0010 
0011 #include "MusEcalGUI.hh"
0012 #include "MERunManager.hh"
0013 #include <TSystem.h>
0014 
0015 ClassImp(MEChanPanel);
0016 
0017 MEChanPanel::MEChanPanel(const TGWindow *p, MusEcalGUI* main,
0018              UInt_t w, UInt_t h)
0019 :  _gui( main )
0020 {
0021   
0022   fMain=0;
0023   fHframe1=0;
0024   f_Channel_Group=0;
0025   f_Channel_ID_Group=0;
0026   f_Channel_XY_Group=0;
0027   f_X_Group=0;
0028   f_Y_Group=0;
0029   f_X=0;
0030   f_Y=0;
0031   f_XY_Button=0;
0032   f_ID_Group=0;
0033   f_ID=0;
0034   f_ID_Button=0;
0035   //  f_Label_ID=0;
0036   fHint1=0;
0037   fHint2=0;
0038   fHint3=0;
0039 
0040   fHint1 = new TGLayoutHints( kLHintsTop | kLHintsLeft | kLHintsCenterX, 3, 3, 20, 1 );
0041   fHint2 = new TGLayoutHints( kLHintsTop | kLHintsCenterX | kLHintsExpandY, 3, 3, 5, 3);
0042   fHint3 = new TGLayoutHints( kLHintsTop | kLHintsLeft , 3 , 3 ,5 ,3 );
0043 
0044   // Dialog used to test the different supported progress bars.
0045 
0046   fClose = kTRUE;
0047 
0048   fMain = new TGTransientFrame(p, main, w, h);
0049   fMain->Connect( "CloseWindow()", "MEChanPanel", this, "DoClose()" );
0050   fMain->DontCallClose();
0051   fMain->SetCleanup(kDeepCleanup);
0052 
0053   fMain->ChangeOptions( (fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame );
0054 
0055   fHframe1 = new TGHorizontalFrame(fMain, 0, 0, 0);
0056 
0057   f_Channel_Group = new TGGroupFrame( fHframe1,"", kHorizontalFrame );
0058   f_Channel_Group->SetTitle(" Local ");
0059 
0060   f_Channel_ID_Group = new TGGroupFrame( f_Channel_Group,"", kVerticalFrame );
0061   f_Channel_ID_Group->SetTitle(" Crystal Number ");
0062 
0063   //  MEChannel* tree_ = _gui->curMgr()->tree();
0064   //  assert( tree_!=0 && tree_->m()!=0 );
0065   //  vector<MEChannel*> vec;
0066   //  tree_->m()->getListOfChannels( vec );  // at the sector level...
0067   //  sort( vec.begin(), vec.end() );
0068 
0069   f_Channel_XY_Group = new TGGroupFrame( f_Channel_Group,"", kVerticalFrame );
0070   f_Channel_XY_Group->SetTitle(" ix and iy ");
0071 
0072   f_X_Group = new TGHorizontalFrame( f_Channel_XY_Group, 5, 1 );
0073   f_Channel_XY_Group->AddFrame( f_X_Group, fHint3 );
0074   f_X      = new TGNumberEntry(f_X_Group, 0, 6, 1,
0075                    TGNumberFormat::kNESInteger, 
0076                    TGNumberFormat::kNEANonNegative,
0077                    TGNumberFormat::kNELLimitMinMax , 0, 84 );
0078   f_X_Group->AddFrame(f_X, fHint3 );
0079   f_X_Label = new TGLabel( f_X_Group, "   ix" );
0080   f_X_Group->AddFrame( f_X_Label, fHint3 );
0081 
0082   f_Y_Group = new TGHorizontalFrame( f_Channel_XY_Group, 10, 1 );
0083   f_Channel_XY_Group->AddFrame( f_Y_Group, fHint3 );
0084   f_Y      = new TGNumberEntry(f_Y_Group, 0, 6, 1,
0085                    TGNumberFormat::kNESInteger, 
0086                    TGNumberFormat::kNEANonNegative,
0087                    TGNumberFormat::kNELLimitMinMax , 0, 19 );
0088   f_Y_Group->AddFrame(f_Y, fHint3 );
0089   f_Y_Label = new TGLabel( f_Y_Group, "iy" );
0090   f_Y_Group->AddFrame( f_Y_Label, fHint3 );
0091 
0092   //   cout << "Creating the button " << endl;
0093 
0094   f_XY_Button = new TGTextButton( f_Channel_XY_Group, "   Select   " );
0095   f_Channel_XY_Group->AddFrame( f_XY_Button, fHint1 );
0096   f_XY_Button->Connect("Clicked()","MEChanPanel",this,"SelectXY()");
0097 
0098   // ++++++++++++++++++++++
0099 
0100   f_ID_Group = new TGHorizontalFrame( f_Channel_ID_Group, 10, 1 );
0101   f_ID      = new TGNumberEntry(f_ID_Group, 1, 6, 1,
0102                 TGNumberFormat::kNESInteger, 
0103                 TGNumberFormat::kNEAPositive,
0104                 TGNumberFormat::kNELLimitMinMax , 1, 1700 );
0105   f_ID_Group->AddFrame(f_ID, fHint3 );
0106   f_ID_Label = new TGLabel( f_ID_Group, "   id" );
0107   f_ID_Group->AddFrame( f_ID_Label, fHint3 );
0108   f_Channel_ID_Group->AddFrame( f_ID_Group, fHint3 );
0109  
0110   f_ID_Button = new TGTextButton( f_Channel_ID_Group, "   Select   " );
0111   f_ID_Button->Connect("Clicked()","MEChanPanel",this,"SelectID()");
0112   f_Channel_ID_Group->AddFrame( f_ID_Button, fHint1 );
0113 
0114 //   f_Channel_ID = new TGListBox( f_Channel_ID_Group, 70, 80 );
0115 //   f_Channel_ID->Connect("Selected(Int_t)","MEChanPanel",this,
0116 //             "SelectChannel(Int_t)");
0117 //   for( unsigned int ii=0; ii<vec.size(); ii++ )
0118 //     {
0119 //       int id = vec[ii]->id();
0120 //       TString str; str+=id;
0121 //       f_Channel_ID->AddEntry(str,id);
0122 //     }
0123 //   f_Channel_ID->Resize(60,90);
0124 //   f_Channel_ID->Select(1);   
0125 //  f_Channel_ID_Group->AddFrame( f_Channel_ID, fHint3 );
0126 
0127   f_XYZ_Group = new TGGroupFrame( fHframe1,"", kVerticalFrame );
0128   f_XYZ_Group->SetTitle(" Global ");
0129 
0130   f_XYZ_X_Group = new TGHorizontalFrame( f_XYZ_Group, 10, 1 );
0131   f_XYZ_Group->AddFrame( f_XYZ_X_Group, fHint3 );
0132   f_XYZ_X      = new TGNumberEntry(f_XYZ_X_Group, 1, 6, 1,
0133                    TGNumberFormat::kNESInteger, 
0134                    TGNumberFormat::kNEAAnyNumber,
0135                    TGNumberFormat::kNELLimitMinMax,-100,100);
0136   f_XYZ_X_Group->AddFrame( f_XYZ_X, fHint3 );
0137   f_XYZ_X_Label = new TGLabel( f_XYZ_X_Group, "   iX (iEta)" );
0138   f_XYZ_X_Group->AddFrame( f_XYZ_X_Label, fHint3 );
0139 
0140   f_XYZ_Y_Group = new TGHorizontalFrame( f_XYZ_Group, 10, 1 );
0141   f_XYZ_Group->AddFrame( f_XYZ_Y_Group, fHint3 );
0142   f_XYZ_Y      = new TGNumberEntry(f_XYZ_Y_Group, 1, 6, 1,
0143                    TGNumberFormat::kNESInteger, 
0144                    TGNumberFormat::kNEAPositive,
0145                    TGNumberFormat::kNELLimitMinMax,1,360);
0146   f_XYZ_Y_Group->AddFrame( f_XYZ_Y, fHint3 );
0147   f_XYZ_Y_Label = new TGLabel( f_XYZ_Y_Group, "   iY (iPhi)" );
0148   f_XYZ_Y_Group->AddFrame( f_XYZ_Y_Label, fHint3 );
0149 
0150   f_XYZ_Z_Group = new TGHorizontalFrame( f_XYZ_Group, 10, 1 );
0151   f_XYZ_Group->AddFrame( f_XYZ_Z_Group, fHint3 );
0152   f_XYZ_Z      = new TGNumberEntry(f_XYZ_Z_Group, 0, 6, 1,
0153                    TGNumberFormat::kNESInteger, 
0154                    TGNumberFormat::kNEAAnyNumber,
0155                    TGNumberFormat::kNELLimitMinMax,-1,1);
0156   f_XYZ_Z_Group->AddFrame( f_XYZ_Z, fHint3 );
0157   f_XYZ_Z_Label = new TGLabel( f_XYZ_Z_Group, "   iZ" );
0158   f_XYZ_Z_Group->AddFrame( f_XYZ_Z_Label, fHint3 );
0159 
0160   //   cout << "Creating the button " << endl;
0161 
0162   f_XYZ_Button = new TGTextButton( f_XYZ_Group, "   Select   " );
0163   f_XYZ_Group->AddFrame( f_XYZ_Button, fHint1 );
0164   f_XYZ_Button->Connect("Clicked()","MEChanPanel",this,"SelectXYZ()");
0165 
0166   //   f_ChannelXY_Group->Resize(50,30);
0167 
0168   //  fHframe1->Resize(30, 30);
0169 
0170   f_Channel_Group->AddFrame( f_Channel_ID_Group, fHint2 );   
0171   f_Channel_Group->AddFrame( f_Channel_XY_Group, fHint2 );   
0172 
0173   //  f_Global_Group->AddFrame( f_XYZ_Group, fHint2 );
0174 
0175   //    f_ChannelXY_Group->AddFrame( f_X_Group, fHint2 );
0176   //    f_ChannelXY_Group->AddFrame( f_Y_Group, fHint2 );
0177 
0178   //   fHframe1->AddFrame( f_RunList,   fHint1 );
0179   fHframe1->AddFrame( f_Channel_Group, fHint2 );
0180   fHframe1->AddFrame( f_XYZ_Group,  fHint2 );
0181 
0182   fMain->AddFrame( fHframe1, fHint2 );
0183 
0184   fMain->SetWindowName("Channel Selection Panel");
0185   TGDimension size = fMain->GetDefaultSize();
0186   fMain->Resize(size);
0187 
0188   // position relative to the parent's window
0189   //   fMain->CenterOnParent();
0190 
0191   fMain->MapSubwindows();
0192   fMain->MapWindow();
0193 }
0194 
0195 MEChanPanel::~MEChanPanel()
0196 {
0197   _gui->_fChanPanel=0;
0198   fMain->DeleteWindow();   // deletes fMain
0199 }
0200 
0201 void 
0202 MEChanPanel::CloseWindow()
0203 {
0204   // Called when window is closed via the window manager.
0205   delete this;
0206 }
0207 
0208 void 
0209 MEChanPanel::DoClose()
0210 {
0211   CloseWindow();
0212 }
0213 
0214 void 
0215 MEChanPanel::SelectXY()
0216 {
0217   //  _gui->_iG = MusEcalHist::iChannel;
0218   int iX = (int)f_X->GetNumber();
0219   int iY = (int)f_Y->GetNumber();
0220   cout << "Select iX=" << iX << " and iY=" << iY << endl;
0221   //  int channel = _gui->setChannelXY( iX, iY );
0222   // FIXME!!!
0223   MEChannel* lmr_ = _gui->curMgr()->tree(); // int ilmr = lmr_->id();
0224   MEChannel* sect_ = lmr_->m(); int isect = sect_->id();
0225   MEChannel* reg_  = sect_->m(); int ireg = reg_->id();
0226   int ix = iX;                      
0227   int iy = iY;
0228   if( ireg==ME::iEBM || ireg==ME::iEBP )
0229     {
0230       MEEBGeom::EtaPhiCoord etaphi_ = MEEBGeom::globalCoord( isect, iX, iY );
0231       ix = etaphi_.first;
0232       iy = etaphi_.second;      
0233     }
0234   MEChannel* chan_ = _gui->curMgr()->tree()->getChannel( ix, iy );
0235   if( chan_==0 ) 
0236     {                       
0237       cout << "channel not found" << endl;
0238       return;
0239     }
0240   _gui->setChannel( chan_ );
0241   //  f_ChannelID->Select( channel );
0242 }
0243 
0244 void 
0245 MEChanPanel::SelectXYZ()
0246 {
0247   int iX = (int)f_XYZ_X->GetNumber();
0248   int iY = (int)f_XYZ_Y->GetNumber();
0249   int iZ = (int)f_XYZ_Z->GetNumber();
0250   cout << "Select iX=" << iX << ", iY=" << iY << " and iZ=" << iZ << endl;
0251   if( iZ!=0 ) 
0252     {
0253       cout << "End-caps not implemented yet" << endl;
0254       return;
0255     }
0256   int iphi=iY;
0257   int ieta=iX;
0258   int ireg=0;
0259   assert( iphi>0 );
0260   assert( ieta!=0 && std::abs(ieta)<=85 );
0261   if( ieta>0 )      ireg=ME::iEBP;
0262   else if( ieta<0 ) ireg=ME::iEBM;
0263   vector< MEChannel* > vec;
0264   ME::regTree( ireg )->getListOfChannels( vec );
0265   MEChannel* chan_(0);
0266   for( unsigned int ii=0; ii<vec.size(); ii++ )
0267     {
0268       MEChannel* leaf_ = vec[ii];
0269       if( leaf_->ix()!=ieta ) continue;
0270       if( leaf_->iy()!=iphi ) continue;
0271       chan_ = leaf_;
0272     }
0273   if( chan_==0 ) return;
0274   _gui->setChannel( chan_ );
0275 }
0276 
0277 
0278 void 
0279 MEChanPanel::SelectChannel( Int_t channel )
0280 {
0281   MEChannel* chan_ = _gui->curMgr()->tree()->m()
0282     ->getDescendant( ME::iCrystal, channel );
0283   if( chan_==0 ) 
0284     {                       
0285       cout << "channel not found: " << channel <<  endl;
0286       return;
0287     }
0288   //  int iX=chan_->ix();
0289   //  int iY=chan_->iy();
0290   //  f_X->SetNumber( iX );
0291   //  f_Y->SetNumber( iY );
0292   //  cout << "Select channel=" << channel << " ---> iX=" << iX << " and iY=" << iY << endl;
0293   _gui->setChannel( chan_ );
0294 }
0295 
0296 void 
0297 MEChanPanel::SelectID()
0298 {
0299   //  _gui->_iG = MusEcalHist::iChannel;
0300   int ID = (int)f_ID->GetNumber();
0301   cout << "Select ID=" << ID << endl;
0302   SelectChannel( ID );
0303 }