Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TridUVPage.cxx

Go to the documentation of this file.
00001 // Root stuff:
00002 #include <TStyle.h>
00003 #include <TColor.h>
00004 #include <TROOT.h>
00005 #include <TGeoManager.h>
00006 #include <TH1.h>
00007 
00008 // Trid Stuff:
00009 #include "TridUVPage.h"
00010 #include "TridModelStrip.h"
00011 #include "TridModelTrack.h"
00012 #include "TridModelShower.h"
00013 #include "TridGLFrame.h"
00014 #include "TridFlatGLFrame.h"
00015 #include "TridSketches.h"
00016 #include "TridControl.h"
00017 #include "TridModelMaker.h"
00018 
00019 // Midad:
00020 #include "Midad/Base/PageProxy.h"
00021 #include "Midad/Gui/GuiBox.h"
00022 #include "Midad/Gui/GuiCanvas.h"
00023 #include "Midad/Gui/GuiMainWindow.h"
00024 #include "Midad/Gui/GuiMenu.h"
00025 #include "Midad/Base/Mint.h"
00026 #include "Midad/Base/PageDisplay.h"
00027 #include "Midad/Base/DigitText.h"
00028 
00029 // SigC:
00030 #include <sigc++/sigc++.h>
00031 #include <sigc++/class_slot.h>
00032 
00033 // Offline:
00034 #include <DataUtil/GetCandidate.h>
00035 #include <JobControl/JobC.h>
00036 #include "MessageService/MsgService.h"
00037 #include "MinosObjectMap/MomNavigator.h"
00038 #include "Plex/PlexHandle.h"
00039 #include "Plex/PlexSEIdAltL.h"
00040 #include "Plex/PlexStripEndId.h"
00041 #include "Plex/PlexVetoShieldHack.h"
00042 #include "CandData/CandRecord.h"
00043 #include "CandDigit/CandDigitListHandle.h"
00044 #include "CandDigit/CandDigitHandle.h"
00045 #include "UgliGeometry/UgliGeomHandle.h"
00046 #include "UgliGeometry/UgliStripHandle.h"
00047 
00048 
00049 CVSID("$Id: TridUVPage.cxx,v 1.18 2007/07/09 21:56:17 tagg Exp $");
00050 
00051 using namespace SigC;
00052 
00053 // We don't use this here because we are just a base class.  But, any
00054 // subclass should have a version like it.
00055 static PageProxy<TridUVPage> gsTridPageProxy("TridUV");
00056 
00057 const Float_t kSize_Plane = 0.06; // Approximate pitch in m
00058 const Float_t kSize_Strip = 0.0205; // Approximate strip width in m
00059 const Float_t kSize_SM_Gap = 1.5297;
00060 const Float_t kSize_SM1_Start = 0;
00061 const Float_t kSize_SM1_End = kSize_Plane * 248;
00062 const Float_t kSize_SM2_Start = kSize_Plane * 248 + kSize_SM_Gap;
00063 const Float_t kSize_SM2_End = kSize_Plane * 480 + kSize_SM_Gap;
00064 const Float_t kSize_UV_Far = kSize_Strip * 192;
00065 const Float_t kSize_Calor = 7.1522;
00066 
00067 const Float_t kSize_UV_Caldet = kSize_Strip * 25;
00068 const Float_t kSize_UV_Near = kSize_Strip * 192;
00069 
00070 const Float_t kFarOffsetU = -4;
00071 const Float_t kFarOffsetV =  4;
00072 
00073 const Float_t kNearOffsetU = -2.65;
00074 const Float_t kNearOffsetV =  2.65;
00075 
00076 
00077 TridUVPage::TridUVPage()
00078   : TridPage(),
00079     fShowTracks(true),
00080     fShowShowerBlobs(true),
00081     fShowStrips(true),
00082     fBestDemuxOnly(true)
00083 {
00084   // Default view mode.
00085   fViewModesSupported = kView2D | kView3D;
00086   fViewMode = kView2D;
00087   fWindowName = "TridUV"; // Must be the same as the proxy name.
00088 }
00089 
00090 TridUVPage::~TridUVPage()
00091 {
00092   fModels.Clear();
00093   // This is now taken care of by the SigC::Ptr stuff.
00094   // if(fGLFrame) delete fGLFrame;
00095 }
00096 
00097 TObject* TridUVPage::Init(Mint* mint, PageDisplay* pd, GuiBox& box)
00098 { 
00099   TridPage::Init(mint,pd,box);
00100 
00101   // Add custom things for this view.
00102   fShowTracks.AddToMenu(fOptionsMenu,"Show Tracks");
00103   fShowTracks.Connect(slot_class(*this,&TridUVPage::ModifySketches));
00104   fShowShowerBlobs.AddToMenu(fOptionsMenu,"Show Showers");
00105   fShowShowerBlobs.Connect(slot_class(*this,&TridUVPage::ModifySketches));
00106   fShowStrips.AddToMenu(fOptionsMenu,"Show Strips");
00107   fShowStrips.Connect(slot_class(*this,&TridUVPage::ModifySketches));
00108 
00109   fBestDemuxOnly.AddToMenu(fOptionsMenu,"Best Demux Only");
00110   fBestDemuxOnly.Connect(slot_class(*(TridPage*)this,&TridPage::Update));
00111 
00112 
00113   MSG("TriD",Msg::kDebug) << "TridUVPage: Init()" << endl;
00114   
00115   return NULL;
00116 }
00117 
00118 TridGLFrame* TridUVPage::CreateNewGLFrame( TridPage::ViewMode_t mode )
00119 {
00120   TridPOV min(0,   0, -4,   0,  0, -180);
00121   TridPOV max(30,  0, +4, 1000, 90, 180);
00122   
00123   if(mode==kView2D) {
00124     MSG("TriD",Msg::kDebug) << "Changing to 2D" << endl;
00125     return new TridFlatGLFrame(this,*fGuiBox,fTridControl,min,max,1.5);
00126   };
00127 
00128   MSG("TriD",Msg::kDebug) << "Changing to 3D" << endl;
00129   return new TridGLFrame(this,*fGuiBox,fTridControl,min,max);
00130 }
00131 
00132 
00133 void TridUVPage::CreateModels()
00134 {
00135   fModels.Clear();
00136   fTridControl->ClearPicked();
00137   fTridControl->ClearSelected();
00138 
00139   TridModelMaker maker;
00140   maker.Prepare(&(fMint->GetJobC().Mom));
00141   maker.CreateStripModels(&(fMint->GetJobC().Mom),fModels);
00142   maker.CreateTrackModels(&(fMint->GetJobC().Mom),fModels);
00143   maker.CreateShowerModels(&(fMint->GetJobC().Mom),fModels);
00144 
00145 }
00146 
00147 
00148 
00149 void TridUVPage::CreateSketches()
00150 {
00151   fModels.ClearAssociations();
00152 
00153   double meanplane = 0;
00154   double meann = 0;
00155 
00156   
00157   UgliGeomHandle ugli(fContext);
00158   
00159   Float_t offsetU = 0;
00160   Float_t offsetV = 0;
00161 
00162   
00163   switch(fContext.GetDetector()) {
00164   case Detector::kCalDet: 
00165     offsetU =  0.25;
00166     offsetV =  0.25;
00167     break;
00168   case Detector::kFar:
00169     offsetU =  kFarOffsetU;
00170     offsetV =  kFarOffsetV; 
00171     break;
00172   case Detector::kNear:
00173     offsetU = kNearOffsetU;
00174     offsetV = kNearOffsetV; 
00175     break;
00176   default: break;
00177   } 
00178 
00179   TridModel*   basemodel;
00180   TridModelItr itr = fModels.GetIterator();
00181   while( (basemodel = itr.Next()) ) {    
00182     // Make a new sketch for this model.
00183     
00185     // Track models.
00187     TridModelTrack* track = dynamic_cast<TridModelTrack*>(basemodel);    
00188     if(track) { 
00189       int first = track->GetFirstPlane();
00190       int last  = track->GetLastPlane();
00191       double lastu=0., lastv=0., lastz=0.;
00192  
00193       for(int plane = first; plane<=last; plane++) {
00194         if(track->IsValid(plane)) {
00195           UgliScintPlnHandle upln = ugli.GetScintPlnHandle(PlexPlaneId(fContext.GetDetector(),plane));  
00196           if(! upln.IsValid()) continue;
00197           double u = track->GetU(plane);
00198           double v = track->GetV(plane);
00199           double z = upln.GetZ0();
00200           
00201           if(plane!=first) {
00202             TridSketch* sk;
00203             // U view:
00204             sk = new TridSketchLine( TVector3(lastz, 0.1, offsetU + lastu),
00205                                      TVector3(z,     0.1, offsetU + u    ) );
00206             sk->SetColor(1,0,0);
00207             fGLFrame->AddSketch(sk);
00208             fModels.AssociateModel(track,sk->GetId());
00209                 
00210             // V view:
00211             sk = new TridSketchLine( TVector3(lastz, 0.1, offsetV + lastv),
00212                                      TVector3(z,     0.1, offsetV + v    ) );
00213             sk->SetColor(1,0,0);
00214             fGLFrame->AddSketch(sk);
00215             fModels.AssociateModel(track,sk->GetId());
00216           }
00217           
00218           lastu=u;
00219           lastv=v;
00220           lastz=z;
00221         }      
00222       } 
00223       
00224     }
00225 
00227     // Shower models.
00229     TridModelShower* shower = dynamic_cast<TridModelShower*>(basemodel);    
00230     if(shower) {
00231       int first = shower->GetFirstPlane();
00232       int last  = shower->GetLastPlane();
00233       for(int plane = first; plane<= last; plane++) {
00234         if(shower->IsValid(plane)) {
00235           float u = shower->GetU(plane);
00236           float v = shower->GetV(plane);
00237           float width = shower->GetWidth(plane);
00238           PlexPlaneId planeid(fContext.GetDetector(),plane); //use steel to avoid ugli errors in ND spect
00239           float z = ugli.GetScintPlnHandle(planeid).GetZ0();    
00240           
00241           float y1, y2;
00242           if(planeid.GetPlaneView()==PlaneView::kU) {
00243             y1 = offsetU + u + width;
00244             y2 = offsetU + u - width;
00245           } else {
00246             y1 = offsetV + v + width;
00247             y2 = offsetV + v - width;
00248           }
00249 
00250           //cout << "Shower plane " << plane << "  " << y1 << " " << y2 << endl;
00251           
00252           TridSketch* sk = new TridSketchLine( TVector3(z, 0.1, y1),
00253                                                TVector3(z, 0.1, y2) );
00254           sk->SetColor(0,0,1);
00255           fGLFrame->AddSketch(sk);
00256           fModels.AssociateModel(shower,sk->GetId());
00257         }
00258       }
00259     }
00260 
00262     // Strip models.
00264     TridModelStrip* model = dynamic_cast<TridModelStrip*>(basemodel);    
00265     if(model) {      
00266       PlexStripEndId seid = model->fStrip;
00267       PlaneView::PlaneView_t view = seid.GetPlaneView();
00268       
00269       // Find offset pos.
00270       Float_t x,y,w,h;
00271       x = y = 0;
00272       
00273       UgliStripHandle ustrip = ugli.GetStripHandle(seid);
00274       
00275       x += ustrip.GlobalPos(0).z();
00276       if(view == PlaneView::kV)
00277         y = offsetV + ustrip.GetTPos();
00278       else
00279         y = offsetU + ustrip.GetTPos(); 
00280 
00281       if((fContext.GetDetector()==Detector::kFar) && (seid.GetPlane()>249)) // Put it in SM 2.
00282         x += kSize_SM_Gap;
00283       
00284       // NB half-widths.
00285       w = kSize_Plane*2;
00286       h = kSize_Strip*2;
00287       
00288       meanplane += x;
00289       meann += 1.0;
00290       
00291       TVector3 pos(x,0.1,y);
00292       
00293       TridSketch* sk;
00294       sk = new TridSketchEllipse( pos,
00295                                   w*kv_x,
00296                                   h*kv_z, 
00297                                   6
00298                                   );
00299         
00300       sk->SetTime(model->GetMeanTime());
00301       fGLFrame->AddSketch(sk);
00302       fModels.AssociateModel(model,sk->GetId());   
00303     }
00304   }
00305 
00306   ModifySketches(); // Set colors and transparencies.
00307 
00308   // Set up automatic and default viewing coordinates.
00309   double zloc = 15;
00310   if(meann>0) zloc = meanplane/meann;
00311   fAutoPOV.Set(zloc, 0, 0, 9, 90, 0 );  
00312   fFullPOV.Set(15,   0, 0, 21, 90, 0 );  
00313 
00314 }
00315 
00316 
00317 void TridUVPage::CreateScenery()
00318 {
00319   TridSketch::StartScenery();
00320   TridSketch::SetDefaultColor(fTridControl->GetForegroundColor());
00321 
00322   
00323   // Put a black quad behind everything so mouse movement works better.
00324   TridSketch* backplane = new TridSketchPlane
00325     ( TVector3(0.0, -1.0, 0.0),
00326       kv_x, 100.,
00327       kv_z, 100. 
00328       );
00329   backplane->SetColor(fTridControl->GetBackgroundColor());
00330   fGLFrame->AddSketch(backplane);
00331 
00332   // Line between views
00333   TridSketch* sk = new TridSketchLine( TVector3(kSize_SM1_Start,0,0), TVector3(kSize_SM2_End,0,0));
00334   fGLFrame->AddSketch(sk);
00335   
00336   // Labels
00337   TridSketchText* txt;
00338   txt = new TridSketchText( TVector3(-0.8,0,2.0), kv_x, kv_y, "U View");
00339   txt->SetScale(0.5);
00340   fGLFrame->AddSketch(txt);
00341 
00342   txt = new TridSketchText( TVector3(-0.8,0,-2.0), kv_x, kv_y, "V View");
00343   txt->SetScale(0.5);
00344   fGLFrame->AddSketch(txt);
00345 
00346   if(fContext.GetDetector()==Detector::kFar) {
00347     // SM 1 box.
00348     sk = new TridSketchLine( TVector3(kSize_SM1_Start, 0, -8), TVector3(kSize_SM1_Start,0,  8) ); fGLFrame->AddSketch(sk);    
00349     sk = new TridSketchLine( TVector3(kSize_SM1_End,   0, -8), TVector3(kSize_SM1_End,  0,  8) );  fGLFrame->AddSketch(sk);    
00350     sk = new TridSketchLine( TVector3(kSize_SM1_Start, 0,  8), TVector3(kSize_SM1_End,  0,  8) );      fGLFrame->AddSketch(sk);
00351     sk = new TridSketchLine( TVector3(kSize_SM1_Start, 0, -8), TVector3(kSize_SM1_End,  0, -8) );     fGLFrame->AddSketch(sk);
00352 
00353     // SM 2 box.
00354     sk = new TridSketchLine( TVector3(kSize_SM2_Start, 0, -8), TVector3(kSize_SM2_Start, 0, 8) ); fGLFrame->AddSketch(sk);
00355     sk = new TridSketchLine( TVector3(kSize_SM2_End,   0, -8), TVector3(kSize_SM2_End,  0, 8) );  fGLFrame->AddSketch(sk);
00356     sk = new TridSketchLine( TVector3(kSize_SM2_Start, 0, 8),  TVector3(kSize_SM2_End, 0, 8) );      fGLFrame->AddSketch(sk);
00357     sk = new TridSketchLine( TVector3(kSize_SM2_Start, 0,-8),  TVector3(kSize_SM2_End, 0, -8) );     fGLFrame->AddSketch(sk);  
00358   }
00359 
00360   else if(fContext.GetDetector()==Detector::kNear) {
00361     // Line at left
00362     fGLFrame->AddSketch(new TridSketchLine( TVector3(0,0,0), TVector3(0,0, 3.95) ) );
00363     fGLFrame->AddSketch(new TridSketchLine( TVector3(0,0,0), TVector3(0,0,-3.95) ) );
00364     // Line at spectrometer
00365     const float kspect = 7.1512;
00366     fGLFrame->AddSketch(new TridSketchLine( TVector3(kspect,0,0), TVector3(kspect,0, 3.95) ) );
00367     fGLFrame->AddSketch(new TridSketchLine( TVector3(kspect,0,0), TVector3(kspect,0,-3.95) ) );  
00368     // Fully instrumented region U
00369     const float fullu1 = -0.27;
00370     const float fullu2 =  2.57;
00371     const float fullv1 =  0.24;
00372     const float fullv2 =  -2.57;
00373 
00374     fGLFrame->AddSketch(new TridSketchLine( TVector3(0,0,kNearOffsetU+fullu1), TVector3(kspect,0,kNearOffsetU+fullu1) ) );
00375     fGLFrame->AddSketch(new TridSketchLine( TVector3(0,0,kNearOffsetU+fullu2), TVector3(kspect,0,kNearOffsetU+fullu2) ) ); 
00376     fGLFrame->AddSketch(new TridSketchLine( TVector3(0,0,kNearOffsetV+fullv1), TVector3(kspect,0,kNearOffsetV+fullv1) ) );
00377     fGLFrame->AddSketch(new TridSketchLine( TVector3(0,0,kNearOffsetV+fullv2), TVector3(kspect,0,kNearOffsetV+fullv2) ) );      
00378   }
00379 
00380   TridSketch::StopScenery();
00381 }
00382 
00383 void TridUVPage::ModifySketches()
00384 {
00385   // Go through all models. Modify they sketches to match the current
00386   // transparency and color maps.
00387 
00388   fColorHistogram->Reset();
00389   fTransHistogram->Reset();
00390 
00391   int nsketches =0;
00392 
00393   TridSketchListItr itr = fGLFrame->GetIterator();
00394   while( TridSketch* sketch = itr.Next() ) {
00395     int sketchnum = sketch->GetId();
00396     TridModel* model = fModels.GetModelFromSketch(sketchnum);
00397 
00398     if((sketch)&&(model)) {
00399       nsketches++;
00400 
00401       bool isToggled = false;
00402 
00403       // Get color and trans as number between 0 and 1,
00404       // interpolated in our current scale.
00405       Double_t color_x = fTridControl->GetRangedModelColor(model);
00406       Double_t trans_x = fTridControl->GetRangedModelTrans(model);
00407 
00408       // Modify the sketch.
00409       sketch->SetColor(fTridControl->GetColor(color_x));
00410       sketch->SetTransparency(trans_x);
00411 
00412       if(color_x>1)
00413         if(!fTridControl->ShowColorOverScale())
00414            sketch->SetDrawn(false);
00415 
00416       if(       dynamic_cast<TridModelStrip*>(model) )  {
00417         if(fShowStrips()) isToggled = true;
00418         // Fill our histograms.
00419         fColorHistogram->Fill(color_x);
00420         fTransHistogram->Fill(trans_x);      
00421       }
00422       else if(  dynamic_cast<TridModelTrack*>(model)  ) {
00423         if(fShowTracks()) isToggled = true;
00424         sketch->SetColor(1,0.3,0.3);
00425         sketch->SetTransparency(1.0);
00426       }
00427       else if( dynamic_cast<TridModelShower*>(model) )  {
00428         if(fShowShowerBlobs()) isToggled = true;
00429         sketch->SetColor(0.3,0.3,1);
00430         sketch->SetTransparency(0.5);
00431       }
00432 
00433       // Turn on/off the sketch.
00434       if(color_x<0)
00435         if(!fTridControl->ShowColorUnderScale())
00436           isToggled = false;
00437       sketch->SetDrawn(isToggled);
00438 
00439       // If picked, shine as white.
00440       if(fTridControl->IsPicked(model))
00441         sketch->SetColor(1,1,1);
00442 
00443       // Ditto selected.
00444       if(fTridControl->IsSelected(model))
00445         sketch->SetColor(1,1,1);
00446 
00447 
00448     } else {
00449       if(!(sketch->IsScenery())) {
00450         MSG("TriD",Msg::kError) << "Cannot find sketch or model "
00451                                 << "  ModelAdd: "     << model 
00452                                 << "  ModelKey: "     << ((model) ? (model->GetSortKey()) : 0)
00453                                 << "  SketchNumber: " << sketchnum
00454                                 << "  SketchAddr:   " << sketch << endl;
00455         if(sketch) sketch->Print();
00456         if(model) model->Print();
00457       }
00458     }
00459   }
00460 }
00461 
00462 
00463 
00464 void TridUVPage::ChangeSketches(void)
00465 {
00466   // Update display.
00467   fGLFrame->DeleteSketches();
00468   CreateSketches();
00469   CreateScenery();
00470   fGLFrame->Update();
00471 
00472 }

Generated on Mon Feb 15 11:07:46 2010 for loon by  doxygen 1.3.9.1