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

TridPageDetector.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 <TH1.h>
00006 #include <TGeoManager.h>
00007 
00008 // Trid Stuff:
00009 #include "TridPageDetector.h"
00010 #include "TridModelStrip.h"
00011 #include "TridModelIntersect.h"
00012 #include "TridGLFrame.h"
00013 #include "TridFlatGLFrame.h"
00014 #include "TridSketches.h"
00015 #include "TridControl.h"
00016 #include "TridModelTrack.h"
00017 #include "TridModelShower.h"
00018 #include "TridModelRecoStrip.h"
00019 #include "TridModelMaker.h"
00020 
00021 // Midad:
00022 #include "Midad/Base/PageProxy.h"
00023 #include "Midad/Gui/GuiBox.h"
00024 #include "Midad/Gui/GuiCanvas.h"
00025 #include "Midad/Gui/GuiMainWindow.h"
00026 #include "Midad/Gui/GuiMenu.h"
00027 #include "Midad/Base/Mint.h"
00028 #include "Midad/Base/PageDisplay.h"
00029 #include "Midad/Base/DigitText.h"
00030 
00031 // SigC:
00032 #include <sigc++/sigc++.h>
00033 #include <sigc++/class_slot.h>
00034 
00035 // Offline:
00036 #include <DataUtil/GetCandidate.h>
00037 #include <JobControl/JobC.h>
00038 #include "MessageService/MsgService.h"
00039 #include "MinosObjectMap/MomNavigator.h"
00040 #include "Plex/PlexHandle.h"
00041 #include "Plex/PlexSEIdAltL.h"
00042 #include "Plex/PlexStripEndId.h"
00043 #include "Plex/PlexVetoShieldHack.h"
00044 #include "CandData/CandRecord.h"
00045 #include "CandDigit/CandDigitListHandle.h"
00046 #include "CandDigit/CandDigitHandle.h"
00047 #include "UgliGeometry/UgliGeomHandle.h"
00048 #include "UgliGeometry/UgliStripHandle.h"
00049 
00050 // Reco:
00051 #include "RecoBase/CandTrackListHandle.h"
00052 #include "RecoBase/CandShowerListHandle.h"
00053 #include "RecoBase/CandStripHandle.h"
00054 
00055 #include <cmath>
00056 
00057 CVSID("$Id: TridPageDetector.cxx,v 1.34 2007/09/14 14:12:19 tagg Exp $");
00058 
00059 using namespace SigC;
00060 
00061 // We don't use this here because we are just a base class.  But, any
00062 // subclass should have a version like it.
00063 static PageProxy<TridPageDetector> gsTridPageProxy("TridDetector");
00064 
00065 
00066 TridPageDetector::TridPageDetector()
00067   : TridPage(),
00068     fShowTracks(true),
00069     fShowShowerBlobs(true),
00070     fShowShowerStrips(true),
00071     fShowClusters(true),
00072     fShowStrips(false),
00073     fShowIntersections(false),
00074     fShowLoneStrips(false),
00075     fExaggerateWidth(false),
00076     fExaggerateThickness(true),
00077     fBestDemuxOnly(true),
00078     fEndOnOrthoView(false)
00079 {
00080   // Default view mode.
00081   fViewModesSupported = kView3D | kView2D | kViewStereo | kViewCrossEyed | kViewRedBlue | kViewBlueRed;
00082   fViewMode = kView3D;
00083   fWindowName = "TridDetector";
00084 }
00085 
00086 TridPageDetector::~TridPageDetector()
00087 {
00088   fModels.Clear();
00089   // This is now taken care of by the SigC::Ptr stuff.
00090   // if(fGLFrame) delete fGLFrame;
00091 }
00092 
00093 TObject* TridPageDetector::Init(Mint* mint, PageDisplay* pd, GuiBox& box)
00094 { 
00095   TridPage::Init(mint,pd,box);
00096 
00097   // Add custom things for this view.
00098 
00099   MSG("TriD",Msg::kDebug) << "TridPageDetector: Init()" << endl;
00100   
00101   GuiMenu::GuiMenuList::iterator mit;
00102 
00103   fShowTracks.AddToMenu(fOptionsMenu,"Show Tracks");
00104   fShowTracks.Connect(slot_class(*this,&TridPageDetector::ModifySketches));
00105 
00106   fShowShowerBlobs.AddToMenu(fOptionsMenu,"Show Shower Blobs");
00107   fShowShowerBlobs.Connect(slot_class(*this,&TridPageDetector::ModifySketches));
00108 
00109   fShowShowerStrips.AddToMenu(fOptionsMenu,"Show Shower Strips");
00110   fShowShowerStrips.Connect(slot_class(*this,&TridPageDetector::ModifySketches));
00111 
00112   // fShowClusters.AddToMenu(fOptionsMenu,"Show Clusters");
00113   // fShowClusters.Connect(slot_class(*this,&TridPageDetector::ModifySketches));
00114 
00115   fShowStrips.AddToMenu(fOptionsMenu,"Show Strips");
00116   fShowStrips.Connect(slot_class(*this,&TridPageDetector::ModifySketches));
00117 
00118   fShowIntersections.AddToMenu(fOptionsMenu,"Show Intersections");
00119   fShowIntersections.Connect(slot_class(*this,&TridPageDetector::ModifySketches));
00120 
00121   fShowLoneStrips.AddToMenu(fOptionsMenu,"Show Lone Strips");
00122   fShowLoneStrips.Connect(slot_class(*this,&TridPageDetector::ModifySketches));
00123 
00124   fExaggerateWidth.AddToMenu(fOptionsMenu,"Exaggerate Strip Width");
00125   fExaggerateWidth.Connect(slot_class(*this,&TridPageDetector::ChangeSketches));
00126 
00127   fExaggerateThickness.AddToMenu(fOptionsMenu,"Exaggerate Strip Thickness");
00128   fExaggerateThickness.Connect(slot_class(*this,&TridPageDetector::ChangeSketches));
00129 
00130   //fBestDemuxOnly.AddToMenu(fOptionsMenu,"Best Demux Only");
00131   //fBestDemuxOnly.Connect(slot_class(*(TridPage*)this,&TridPage::Update));
00132 
00133   fEndOnOrthoView.AddToMenu(fOptionsMenu,"End-on Orthographic View");
00134   fEndOnOrthoView.Connect(slot_class(*this,&TridPageDetector::SnapToEndOnOrthoView));
00135   
00136   mit = fOptionsMenu->Add("Print Flyby Animation");
00137   (*mit)->Connect(slot_class(*this,&TridPageDetector::PrintAnimation));
00138 
00139 
00140   return NULL;
00141 }
00142 
00143 
00144 void TridPageDetector::CreateModels()
00145 {
00146   // Set the suggested time range.
00147   double tmin = fContext.GetTimeStamp().GetNanoSec()*1e9;
00148   double tmax = tmin + 10*Munits::microsecond;
00149 
00150   if(fContext.GetDetector()==Detector::kFar) {
00151     tmin -= 50*Munits::microsecond;
00152     tmax += 50*Munits::microsecond;
00153   }
00154   fTridControl->GetAnimator().SetTimeRange(tmin,tmax);
00155 
00156 
00157   fModels.Clear();
00158   fTridControl->ClearPicked();
00159   fTridControl->ClearSelected();
00160 
00161   TridModelMaker maker;
00162   maker.Prepare(&(fMint->GetJobC().Mom));
00163   maker.CreateTrackModels(&(fMint->GetJobC().Mom),fModels);
00164   maker.CreateShowerModels(&(fMint->GetJobC().Mom),fModels);
00165   maker.CreateStripModels(&(fMint->GetJobC().Mom),fModels);
00166   maker.CreateIntersectionModels(&(fMint->GetJobC().Mom),fModels);
00167 }
00168 
00169 
00170 
00171 void TridPageDetector::CreateSketches()
00172 {
00173   fModels.ClearAssociations();
00174   double meanz = 0;
00175   double meann = 1e-9;
00176 
00177   // Get an Ugli handle.
00178   UgliGeomHandle myUgli(fContext);
00179 
00180   TridModel*   basemodel;
00181   TridModelItr itr = fModels.GetIterator();
00182   while( (basemodel = itr.Next()) ) {    
00183     // Make a new sketch for this model.
00184     
00186     // Track models.
00188     if(TridModelTrack* trackmodel = dynamic_cast<TridModelTrack*>(basemodel)) {
00189       //cout << "Track:-------------" << endl;
00190       bool firstplane = true;
00191       TVector3 lastpos;
00192       for(int plane = 0; plane<500; plane++) {
00193         if(trackmodel->IsValid(plane)) {
00194           // find 3d position here.
00195           float z = myUgli.GetScintPlnHandle(PlexPlaneId(fContext.GetDetector(),plane)).GetZ0();
00196           TVector3 pos = 
00197               kv_u * trackmodel->GetU(plane)
00198             + kv_v * trackmodel->GetV(plane)
00199             + kv_z * z;
00200           
00201           if(!firstplane) {
00202             // Make new segment:
00203             TridSketch* sk = 
00204               //new TridSketchLine( lastpos,pos );
00205               new TridSketchTube(lastpos,pos,0.02,6,false);
00206             sk->SetTime(trackmodel->GetT(plane));
00207             
00208             sk->SetColor(1,0,0);
00209             fGLFrame->AddSketch(sk);
00210             fModels.AssociateModel(trackmodel,sk->GetId());
00211 
00212           } else {
00213             firstplane = false;
00214           }
00215           lastpos = pos;
00216         }
00217       }
00218     } 
00219 
00221     // Shower models.
00223     else if(    TridModelShower*  showermodel = dynamic_cast<TridModelShower*>(basemodel)) {
00224       //cout << "Shower:-------------" << endl;
00225 
00226       for(int plane = showermodel->GetFirstPlane(); plane<= showermodel->GetLastPlane(); plane++) {
00227         if((showermodel->IsValid(plane)) && (showermodel->IsValid(plane+1)) ) {
00228           // find 3d position here.
00229           PlexPlaneId planeId1(fContext.GetDetector(),plane);
00230           PlexPlaneId planeId2(fContext.GetDetector(),plane+1);
00231           double z = 0.5* ( myUgli.GetScintPlnHandle(planeId1).GetZ0()
00232                            +myUgli.GetScintPlnHandle(planeId2).GetZ0()
00233                            );
00234 
00235           double u,v;
00236           double u_size, v_size;
00237           if(planeId1.GetPlaneView()==PlaneView::kU) {
00238             u      = showermodel->GetU(plane);
00239             u_size = showermodel->GetWidth(plane);
00240             v      = showermodel->GetV(plane+1);
00241             v_size = showermodel->GetWidth(plane+1);        
00242           } else {      
00243             u      = showermodel->GetU(plane+1);
00244             u_size = showermodel->GetWidth(plane+1);
00245             v      = showermodel->GetV(plane);
00246             v_size = showermodel->GetWidth(plane);          
00247           }
00248           TVector3 pos = 
00249               kv_u * u
00250             + kv_v * v
00251             + kv_z * z;
00252           TVector3 axis1 = kv_u * u_size;
00253           TVector3 axis2 = kv_v * v_size;
00254                  
00255           //cout << "Showering: " << plane << " " << pos.X() << " " << pos.Y() << " " << pos.Z() 
00256           //    << " usize: " << u_size << "  vsize" << v_size << endl;
00257           
00258           // Make new segment:    
00259           TridSketch* sk = 
00260             new TridSketchEllipse(pos,axis1,axis2,16);
00261 
00262           sk->SetTime(showermodel->GetT(plane));
00263           sk->SetColor(0.1,0,1);
00264           sk->SetTransparency(0.5);
00265            
00266           fGLFrame->AddSketch(sk);
00267           fModels.AssociateModel(showermodel,sk->GetId());
00268         }
00269       }
00270     }
00271     
00273     // RecoStrip models.
00275     else if(TridModelRecoStrip* recostrip = dynamic_cast<TridModelRecoStrip*>(basemodel)) {
00276       TVector3 x0,x1;
00277       float halfwidth, halfthick;
00278       
00279       PlexStripEndId seid = recostrip->fStrip;
00280 
00281       x0 = recostrip->fPos;
00282       halfthick  = 0.01; // Hard-code 1cm.
00283       halfwidth  = 0.02; // Hard-code 2cm.
00284           
00285       if(fExaggerateThickness()) halfthick*=5.0;
00286       if(fExaggerateWidth())     halfwidth*=2.0;
00287       
00288       TridSketch* sk = 
00289         new TridSketchBox( recostrip->fPos,
00290                            recostrip->fLongitude, recostrip->fHalfLength,
00291                            recostrip->fTransverse, halfwidth,
00292                            kv_z, halfthick );
00293       sk->SetTime(recostrip->GetMeanTime());
00294    
00295       fGLFrame->AddSketch(sk);
00296       fModels.AssociateModel(recostrip,sk->GetId());
00297       MSG("TriD",Msg::kDebug) << "Created sketch - "
00298                               << " ModelAdd:"     << recostrip 
00299                               << " Model ID:"     << ((recostrip) ? (recostrip->GetId()) : 0)
00300                               << " ModelKey:"     << ((recostrip) ? (recostrip->GetSortKey()) : 0)
00301                               << " SketchNumber:" << sk->GetId()
00302                               << " SketchAddr: " << sk << endl;
00303     }
00304 
00306     // Strip models.
00308     else if(TridModelStrip* model = dynamic_cast<TridModelStrip*>(basemodel)) {
00309       TVector3 x0,x1;
00310       float halflength, halfwidth, halfthick;
00311       
00312       PlexStripEndId seid = model->fStrip;
00313 
00314       UgliStripHandle ustrip = myUgli.GetStripHandle(seid);
00315       x0 = ustrip.GlobalPos(0);
00316       halflength = ustrip.GetHalfLength();
00317       halfwidth  = ustrip.GetHalfWidth();
00318       halfthick  = ustrip.GetHalfThickness();
00319           
00320       PlaneView::PlaneView_t view = seid.GetPlaneView();
00321       
00322       TVector3 v1;
00323       TVector3 v2;
00324       TVector3 v3 = kv_z;      
00325       
00326       switch(view) {
00327       case PlaneView::kU:
00328         v1 = kv_v;
00329         v2 = kv_u;
00330         break;
00331       case PlaneView::kV:
00332         v1 = kv_u;
00333         v2 = kv_v;
00334         break;
00335       default:
00336         if(seid.IsVetoShield()) {
00337           v1 = kv_z;
00338           v2 = kv_y;
00339           v3 = kv_x;
00340         } else {
00341           MSG("TriD",Msg::kError) << "TridPageDetector::CreateSketches() -> Unknown plane view!" << endl;
00342         }
00343       }
00344       
00345       if(fContext.GetDetector()==Detector::kCalDet) {
00346         switch(view) {
00347         case PlaneView::kU:
00348           v1 = kv_y;
00349           v2 = kv_x;
00350           break;        
00351         case PlaneView::kV:
00352           v1 = kv_x;
00353           v2 = kv_y;
00354           break;
00355           
00356         default:
00357           MSG("TriD",Msg::kError) << "TridPageDetector::CreateSketches() -> Unknown plane view!" << endl;
00358         }
00359       } 
00360       
00361       if(fExaggerateThickness()) halfthick*=5.0;
00362       if(fExaggerateWidth())     halfwidth*=2.0;
00363     
00364       TridSketch* sk = 
00365         new TridSketchBox( x0,
00366                            v1, halflength,
00367                            v2, halfwidth,
00368                            v3, halfthick );
00369       
00370       sk->SetTime(model->GetMeanTime());
00371       meanz += x0.z();
00372       meann += 1;
00373    
00374       fGLFrame->AddSketch(sk);
00375       fModels.AssociateModel(model,sk->GetId());
00376       MSG("TriD",Msg::kDebug) << "Created sketch - "
00377                               << " ModelAdd:"     << model 
00378                               << " Model ID:"     << ((model) ? (model->GetId()) : 0)
00379                               << " ModelKey:"     << ((model) ? (model->GetSortKey()) : 0)
00380                               << " SketchNumber:" << sk->GetId()
00381                               << " SketchAddr: " << sk << endl;
00382     }
00383     
00385     // Intersection models.
00387     else if(TridModelIntersect* intersect = dynamic_cast<TridModelIntersect*>(basemodel) ){
00388       
00389       TVector3 x1,x2;
00390       TVector3 v1,v2;
00391       TVector3 p; // Point of intersection.
00392 
00393       float halflength, halfwidth, halfthick;
00394       UgliStripHandle ustrip1 = myUgli.GetStripHandle(intersect->fStrip2);
00395       UgliStripHandle ustrip2 = myUgli.GetStripHandle(intersect->fStrip1);
00396       x1 = ustrip1.GlobalPos(0);
00397       x2 = ustrip2.GlobalPos(0);
00398       halflength = ustrip1.GetHalfWidth();
00399       halfwidth  = ustrip2.GetHalfWidth();
00400       halfthick  = fabs(x2.z() - x1.z())*0.5 + ustrip1.GetHalfThickness();
00401      
00402       v1 = kv_v;
00403       v2 = kv_u;
00404       switch(intersect->fStrip1.GetPlaneView()) {
00405       case PlaneView::kU:
00406         v1 = kv_u; v2 = kv_v;
00407         break;
00408       case PlaneView::kV:
00409         v1 = kv_v; v2 = kv_u;
00410         break;
00411       default:
00412         MSG("TriD",Msg::kError) << "TridPageDetector::CreateSketches() -> Unknown plane view!" << endl;
00413         continue; // will throw another error about unfound sketch.
00414       }
00415         
00416       // Finds point of intersection in the uv plane
00417       // assuming v1 and v2 to be orthoganal:
00418       p = x1 + ((x2-x1)*v1)*v1;      
00419       
00420       // Add in the z-component. Do it 'right':
00421       //p+= v1.Cross(v2) * (x2-x1); 
00422       // Do it 'easy':
00423       p.SetZ(x1.z()*0.5 + x2.z()*0.5);
00424       
00425       if(fExaggerateThickness()) halfthick*=5.0; 
00426       if(fExaggerateWidth())     halfwidth*=2.0;
00427     
00428       TridSketch* ski = 
00429         new TridSketchBox( p,
00430                            v1, halflength,
00431                            v2, halfwidth,
00432                            kv_z, halfthick );
00433       
00434       ski->SetTime(intersect->GetMeanTime());
00435       meanz += p.z();
00436       meann += 1;
00437    
00438       fGLFrame->AddSketch(ski);
00439       fModels.AssociateModel(intersect,ski->GetId());
00440       MSG("TriD",Msg::kDebug) << "Created sketch - "
00441                               << " ModelAdd:"     << model 
00442                               << " Model ID:"     << ((model) ? (model->GetId()) : 0)
00443                               << " ModelKey:"     << ((model) ? (model->GetSortKey()) : 0)
00444                               << " SketchNumber:" << ski->GetId()
00445                               << " SketchAddr: " << ski << endl;
00446     } else {
00447 
00448       MSG("TriD",Msg::kError) << "Unrecognized model type! " << std::endl;
00449     }
00450    
00451   }
00452 
00453   ModifySketches(); // Set colors and transparencies.
00454 
00455   meanz /= meann;
00456 
00457   // Set up automatic and default viewing coordinates.
00458   double phi = fGLFrame->fPOV.fPhi;
00459   fAutoPOV.Set(0,0,meanz,25,25,phi);
00460   fFullPOV.Set(0,0,16,25,25,phi);
00461 
00462   if(fContext.GetDetector()==Detector::kCalDet) {
00463     fAutoPOV.Set(0,0,meanz,6,25,phi);
00464     fFullPOV.Set(0,0,1.7,6,25,phi);
00465   }
00466 }
00467 
00468 
00469 void TridPageDetector::CreateScenery()
00470 {
00471   TridSketch::StartScenery();
00472   TridSketch::SetDefaultColor(fTridControl->GetForegroundColor());
00473   //cout << "Color: ";  fTridControl->GetForegroundColor().Print();
00474 
00475   TridSketchLine* l;
00476   
00477   // Add basic shape of fardet.
00478   if(fContext.GetDetector()==Detector::kCalDet) {
00479     // Arrow.
00480     l = new TridSketchLine(   0, 0, -1,  0, 0, -0.2);  fGLFrame->AddSketch(l);
00481     l = new TridSketchLine(   0.3, 0, -0.5,  0, 0, -0.2);  fGLFrame->AddSketch(l);
00482     l = new TridSketchLine(  -0.3, 0, -0.5,  0, 0, -0.2);  fGLFrame->AddSketch(l);
00483     l = new TridSketchLine(     0, 0.3, -0.5,  0, 0, -0.2);  fGLFrame->AddSketch(l);
00484 
00485 
00486     l = new TridSketchLine(   -0.5, -0.5, 0,   -0.5,  0.5, 0);  fGLFrame->AddSketch(l);
00487     l = new TridSketchLine(   -0.5,  0.5, 0,    0.5,  0.5, 0);  fGLFrame->AddSketch(l);
00488     l = new TridSketchLine(    0.5,  0.5, 0,    0.5, -0.5, 0);  fGLFrame->AddSketch(l);
00489     l = new TridSketchLine(    0.5, -0.5, 0,   -0.5, -0.5, 0);  fGLFrame->AddSketch(l);
00490 
00491     l = new TridSketchLine(   -0.5, -0.5, 3.6,   -0.5,  0.5, 3.6);  fGLFrame->AddSketch(l);
00492     l = new TridSketchLine(   -0.5,  0.5, 3.6,    0.5,  0.5, 3.6);  fGLFrame->AddSketch(l);
00493     l = new TridSketchLine(    0.5,  0.5, 3.6,    0.5, -0.5, 3.6);  fGLFrame->AddSketch(l);
00494     l = new TridSketchLine(    0.5, -0.5, 3.6,   -0.5, -0.5, 3.6);  fGLFrame->AddSketch(l);
00495   }
00496 
00497   if(fContext.GetDetector()==Detector::kFar) {
00498     // Draw an octagon at start and ends of supermodules.
00499     float modz[4] = {0, 14.696, 16.3445, 30.2441};
00500     
00501     // Draw text.
00502     TridSketchText* txt;
00503     txt = new TridSketchText( TVector3(0,-4.2,modz[0]), kv_y, -kv_z, "Plane 0");
00504     txt->SetThickness(0.001);
00505     txt->SetScale(0.3);
00506     txt->SetTransparency(0.5);
00507     fGLFrame->AddSketch(txt);
00508 
00509     txt = new TridSketchText( TVector3(0,-4.2,modz[1]), kv_y, -kv_z, "Plane 248");
00510     txt->SetThickness(0.001);
00511     txt->SetScale(0.3);
00512     txt->SetTransparency(0.5); 
00513     fGLFrame->AddSketch(txt);
00514 
00515     txt = new TridSketchText( TVector3(0,-4.2,modz[2]), kv_y, kv_z, "Plane 250");
00516     txt->SetThickness(0.001);
00517     txt->SetScale(0.3);
00518     txt->SetTransparency(0.5);
00519     fGLFrame->AddSketch(txt);
00520 
00521     txt = new TridSketchText( TVector3(0,-4.2,modz[3]), kv_y, kv_z, "Plane 480");
00522     txt->SetThickness(0.001);
00523     txt->SetScale(0.3);
00524     txt->SetTransparency(0.5); 
00525     fGLFrame->AddSketch(txt);
00526 
00527     // horizontal lines
00528     for(int iz=0; iz<4; iz+=2) {
00529       l = new TridSketchLine(   -4,-1.66, modz[iz],    -4,-1.66, modz[iz+1]);
00530       l->SetWidth(0.3);
00531       fGLFrame->AddSketch(l);
00532 
00533       l = new TridSketchLine(   -4, 1.66, modz[iz],    -4, 1.66, modz[iz+1]);
00534       l->SetWidth(0.3);
00535       fGLFrame->AddSketch(l);
00536 
00537       l = new TridSketchLine(    4,-1.66, modz[iz],     4,-1.66, modz[iz+1]);
00538       l->SetWidth(0.3);
00539       fGLFrame->AddSketch(l);
00540 
00541       l = new TridSketchLine(    4, 1.66, modz[iz],     4, 1.66, modz[iz+1]);
00542       l->SetWidth(0.3);
00543       fGLFrame->AddSketch(l);
00544 
00545       l = new TridSketchLine(-1.66,    4, modz[iz],  -1.66,    4, modz[iz+1]);
00546       l->SetWidth(0.3);
00547       fGLFrame->AddSketch(l);
00548 
00549       l = new TridSketchLine(-1.66,   -4, modz[iz],  -1.66,   -4, modz[iz+1]);
00550       l->SetWidth(0.3);
00551       fGLFrame->AddSketch(l);
00552 
00553       l = new TridSketchLine( 1.66,    4, modz[iz],   1.66,    4, modz[iz+1]);
00554       l->SetWidth(0.3);
00555       fGLFrame->AddSketch(l);
00556 
00557       l = new TridSketchLine( 1.66,   -4, modz[iz],   1.66,   -4, modz[iz+1]);
00558       l->SetWidth(0.3);
00559       fGLFrame->AddSketch(l);
00560     }
00561     
00562     for(int iz = 0; iz<4; iz++) {
00563       // W
00564       l = new TridSketchLine(   -4,-1.66, modz[iz],    -4, 1.66, modz[iz]);
00565       fGLFrame->AddSketch(l);
00566       
00567        // E
00568       l = new TridSketchLine(    4, 1.66, modz[iz],     4,-1.66, modz[iz]);
00569       fGLFrame->AddSketch(l);  
00570 
00571       // NW and NW ear
00572       l = new TridSketchLine( -1.66,    4, modz[iz],     -4.707, 0.953, modz[iz]);
00573       fGLFrame->AddSketch(l);
00574 
00575       l = new TridSketchLine( -4.,    0.953, modz[iz],     -4.707, 0.953, modz[iz]);
00576       fGLFrame->AddSketch(l);
00577  
00578       // NE and NE Ear
00579       l = new TridSketchLine( 1.66,    4, modz[iz],       4.707, 0.953, modz[iz]);
00580       fGLFrame->AddSketch(l);
00581 
00582       l = new TridSketchLine(  4.,    0.953, modz[iz],     4.707, 0.953, modz[iz]);
00583       fGLFrame->AddSketch(l);
00584 
00585       // N
00586       l = new TridSketchLine(-1.66,    4, modz[iz],  1.66,    4, modz[iz]);
00587       fGLFrame->AddSketch(l);
00588 
00589       // S
00590       l = new TridSketchLine( 1.66,   -4, modz[iz], -1.66,   -4, modz[iz]);
00591       fGLFrame->AddSketch(l);
00592 
00593       // SE
00594       l = new TridSketchLine(    4,-1.66, modz[iz],  1.66,   -4, modz[iz]);
00595       fGLFrame->AddSketch(l);
00596 
00597       // SW
00598       l = new TridSketchLine(-1.66,   -4, modz[iz],    -4,-1.66, modz[iz]);
00599       fGLFrame->AddSketch(l);
00600     }
00601   }
00602   
00603   if(fContext.GetDetector()==Detector::kNear) {
00604 
00605     // Draw the plane profile:
00606     TridSketch* l;
00607     float zeds[] = {0,         // Detector start
00608                     //0.06*20,   // End of veto region
00609                     //0.06*60,   // End of target region
00610                     0.06*120,  // End of hadron shower region
00611                     0.06*281}; // end of detector.
00612 
00613     const char* znames[] = { 
00614       "Plane 0",
00615       "Plane 120",
00616       "Plane 281"};
00617 
00618     for(int iz=0;iz<3;iz++) {
00619       double z = zeds[iz];
00620       // Loop over lhs, rhs of detector
00621       for(double side=-1.; side<3. ; side+=2. ) {
00622         l = new TridSketchLine(        0, 1.9,  z,  side*1.7, 1.9,  z );  fGLFrame->AddSketch(l);
00623         l = new TridSketchLine( side*1.7, 1.9,  z,  side*1.7, 1.53, z );  fGLFrame->AddSketch(l);
00624         l = new TridSketchLine( side*1.7, 1.53, z,  side*3.1, 0,    z );  fGLFrame->AddSketch(l);
00625         l = new TridSketchLine( side*3.1, 0,    z,  side*3.1, -0.2, z );  fGLFrame->AddSketch(l);
00626         l = new TridSketchLine( side*3.1, -0.2, z,  side*2.4, -0.2, z );  fGLFrame->AddSketch(l);
00627         l = new TridSketchLine( side*2.4, -0.2, z,  side*2.4,-1.02, z );  fGLFrame->AddSketch(l);
00628         l = new TridSketchLine( side*2.4,-1.02, z,  side*1.7,-1.53, z );  fGLFrame->AddSketch(l);
00629         l = new TridSketchLine( side*1.7,-1.53, z,  side*1.7,-1.9,  z );  fGLFrame->AddSketch(l);
00630         l = new TridSketchLine( side*1.7,-1.9,  z,  0       ,-1.9,  z );  fGLFrame->AddSketch(l);
00631         //cout << "Actual: ";  l->GetColor().Print();
00632       }
00633       TridSketchText* txt;
00634       txt = new TridSketchText( TVector3(0,-2.2,z), kv_y, -kv_z, znames[iz]);
00635       txt->SetThickness(0.001);
00636       txt->SetScale(0.3);
00637       txt->SetTransparency(0.5);
00638       fGLFrame->AddSketch(txt);
00639     }
00640   }
00641   TridSketch::StopScenery();
00642 }
00643 
00644 void TridPageDetector::ModifySketches()
00645 {
00646   // Go through all models. Modify their sketches to match the current
00647   // transparency and color maps.
00648 
00649   fColorHistogram->Reset();
00650   fTransHistogram->Reset();
00651 
00652   int nsketches =0;
00653 
00654   TridSketchListItr itr = fGLFrame->GetIterator();
00655   while( TridSketch* sketch = itr.Next() ) {
00656     int sketchnum = sketch->GetId();
00657     TridModel* model = fModels.GetModelFromSketch(sketchnum);
00658 
00659     if((sketch)&&(model)) {
00660       nsketches++;
00661       // Get color and trans as number between 0 and 1,
00662       // interpolated in our current scale.
00663       Double_t color_x = fTridControl->GetRangedModelColor(model);
00664       Double_t trans_x = fTridControl->GetRangedModelTrans(model);
00665 
00666       // Modify the sketch.
00667       sketch->SetColor(fTridControl->GetColor(color_x));
00668       sketch->SetTransparency(trans_x);
00669 
00670       // Turn on/off the sketch.
00671       sketch->SetDrawn(true);
00672       if(color_x<0)
00673         if(!fTridControl->ShowColorUnderScale())
00674            sketch->SetDrawn(false);
00675 
00676       if(color_x>1)
00677         if(!fTridControl->ShowColorOverScale())
00678            sketch->SetDrawn(false);
00679 
00680       // Turn on/off based on menu toggles.
00681 
00682       bool isToggled = false;
00683       if( /*TridModelIntersect* intersectModel = */ dynamic_cast<TridModelIntersect*>(model) ) {
00684         if(fShowIntersections()) isToggled = true;
00685       }
00686       else if( TridModelStrip* stripModel = dynamic_cast<TridModelStrip*>(model) )  {
00687         if(fShowStrips()) isToggled = true;
00688         if((fShowLoneStrips()&&stripModel->fIntersections==0)) isToggled = true;
00689       }
00690       else if( /*TridModelTrack* trackmodel =*/ dynamic_cast<TridModelTrack*>(model)  ) {
00691         if(fShowTracks()) isToggled = true;
00692         sketch->SetColor(1,0.3,0.3);
00693         sketch->SetTransparency(1.0);
00694       }
00695       else if( /*TridModelShower* showermodel =*/ dynamic_cast<TridModelShower*>(model) )  {
00696         if(fShowShowerBlobs()) isToggled = true;
00697         sketch->SetColor(0.3,0.3,1);
00698         sketch->SetTransparency(0.5);
00699       }
00700       else if( TridModelRecoStrip* rstrip = dynamic_cast<TridModelRecoStrip*>(model) )  {
00701         switch(rstrip->fType) {
00702         case TridModelRecoStrip::kShower: 
00703             if(fShowShowerStrips()){ isToggled = true; }break;
00704         }
00705         sketch->SetTransparency(trans_x*0.5);
00706       }
00707 
00708       if(!isToggled) sketch->SetDrawn(false);
00709      
00710      // If picked, shine as white.
00711      if(fTridControl->IsPicked(model))
00712        sketch->SetColor(1,1,1);
00713      
00714      // Ditto selected.
00715      if(fTridControl->IsSelected(model))
00716        sketch->SetColor(1,1,1);
00717          
00718      if(isToggled) {
00719        // Fill our histograms.
00720        fColorHistogram->Fill(color_x);
00721        fTransHistogram->Fill(trans_x);
00722      }
00723 
00724 
00725     } else {
00726       if(!(sketch->IsScenery())) {
00727         MSG("TriD",Msg::kError) << "Cannot find sketch or model "
00728                                 << " ModelAdd:"     << model 
00729                                 << " Model ID:"     << ((model) ? (model->GetId()) : 0)
00730                                 << " ModelKey:"     << ((model) ? (model->GetSortKey()) : 0)
00731                                 << " SketchNumber:" << sketchnum
00732                                 << " SketchAddr: " << sketch << endl;
00733         //if(model) model->Print();
00734       }
00735     }
00736   }
00737 }
00738 
00739 
00740 
00741 void TridPageDetector::PrintAnimation()
00742 {
00743   char filename[100];
00744   const int nsnaps = 180;
00745   fGLFrame->fPOV.fPhi = 0;
00746   fGLFrame->Update();  
00747   for(int i=0;i<nsnaps; i++) {
00748     sprintf(filename,"anim%03d.gif",i);
00749     fGLFrame->fPOV.fPhi += 360.0 /(double)(nsnaps);
00750     fGLFrame->Print(filename);
00751     fGLFrame->Update();
00752   }
00753 }
00754 
00755 
00756 void TridPageDetector::ChangeSketches(void)
00757 {
00758   // Update display.
00759   fGLFrame->DeleteSketches();
00760   CreateSketches();
00761   CreateScenery();
00762   fGLFrame->Update();
00763 
00764 }
00765 
00766 
00767 /*
00768 void TridPageDetector::AnimationRedraw() 
00769 {
00770   // Animate view and objects in the view.
00771   // View animation takes the form of rotation in phi.
00772   fGLFrame->SetAnimTime(fTridControl->CurrentAnimTimeMin(), 
00773                         fTridControl->CurrentAnimTimeMax());
00774   if(fTridControl->AnimatingViews()) {
00775     MSG("TriD",Msg::kDebug) << "Rotating from " << fGLFrame->fPOV.GetPhi() 
00776                             << "to " << fGLFrame->fPOV.GetPhi() + fTridControl->GetAnimViewIncrement()*360.
00777                             << endl;
00778     //if(fViewMode!=kView2D) {
00779       fGLFrame->fPOV.fPhi = (fGLFrame->fPOV.fPhi+ fTridControl->GetAnimViewIncrement()*360.);
00780       fGLFrame->fPOV.Push();    
00781       // }
00782   }
00783   fGLFrame->Update();
00784 }
00785 */
00786 
00787 void TridPageDetector::SnapToEndOnOrthoView()
00788 {
00789   if(fEndOnOrthoView()) {
00790     SetupFrame(kView2D);
00791     TridPOV end_on(0,0,0,3,0,180);
00792     SetPOV(end_on);
00793   } else {
00794     SetupFrame(kView3D);
00795     FullZoom();
00796   }
00797 }

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