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

CheezyDisplay.cxx

Go to the documentation of this file.
00001 
00002 // $Id: CheezyDisplay.cxx,v 1.29 2005/08/26 19:07:29 rhatcher Exp $
00003 //
00004 // CheezyDisplay
00005 //
00006 // CheezyDisplay 
00007 //
00008 // Author:  R. Hatcher 2000.05.15
00009 //
00011 
00012 #include "RerootExodus/CheezyDisplay.h"
00013 
00014 #include "Conventions/Munits.h"
00015 #include "UgliGeometry/UgliGeomHandle.h"
00016 #include "UgliGeometry/UgliStripHandle.h"
00017 
00018 #include "TCanvas.h"
00019 #include "TPad.h"
00020 #include "TH2.h"
00021 #include "TPolyMarker.h"
00022 #include "TVector3.h"
00023 
00024 #include "MessageService/MsgService.h"
00025 CVSID("$Id: CheezyDisplay.cxx,v 1.29 2005/08/26 19:07:29 rhatcher Exp $");
00026 
00027 #include <cassert>
00028 
00029 ClassImp(CheezyDisplay)
00030 
00031 //_____________________________________________________________________________
00032 CheezyDisplay::CheezyDisplay()
00033    : TNamed("CheezyDisplay","quick and dirty uv vs. z display")
00034    , fCanvas(0)
00035 {
00036    // default constructor
00037    SetupDisplay();
00038 }
00039 
00040 //_____________________________________________________________________________
00041 CheezyDisplay::CheezyDisplay(const char *name, const char *title, TCanvas* canvas)
00042    : TNamed(name,title)
00043    , fCanvas(canvas)
00044 {
00045    // named constructor
00046    SetupDisplay();
00047 }
00048 
00049 //_____________________________________________________________________________
00050 void CheezyDisplay::SetupDisplay()
00051 {
00052    // Create the display
00053 
00054    // zero out pointer to objects not-yet-created
00055    fUview = fVview = 0;
00056    fPM_TU = fPM_TV = fPM_UE = fPM_VE = fPM_UW = fPM_VW = 0;
00057 
00058    // defaults
00059    fDrawSide[0]    = kTRUE;  // draw truth info
00060    fMarkerColor[0] = 16;     // kRed or 16=gray
00061    fMarkerType[0]  = 24;     // 24=circle, 25=box, 20=solid disk
00062    fMarkerSize[0]  = 0.65;
00063 
00064    fDrawSide[1]    = kTRUE;  // draw East info
00065    fMarkerColor[1] = kBlue;  // blue
00066    fMarkerType[1]  = 21;     //
00067    fMarkerSize[1]  = 0.55;
00068 
00069    fDrawSide[2]    = kTRUE;  // draw West info
00070    fMarkerColor[2] = kGreen; // green
00071    fMarkerType[2]  = 21;     //
00072    fMarkerSize[2]  = 0.45;   // smaller than East, drawn second
00073 
00074    fDrawTruth      = kTRUE;  // draw the Truth(tm)
00075    fDrawOnlyBest   = kFALSE; // draw all possibilities
00076    fWgtThresh      = -1;     // no real weight threshold cut
00077 
00078    // Create the canvas
00079    if (!fCanvas) 
00080        fCanvas = new TCanvas(GetName(),GetTitle(),600,600);
00081 
00082    // Create the pads;  Pad takes xlo, ylo, xhi, yhi in NC
00083    fUpad  = new TPad("upad","U pad",0.010,0.505,0.990,0.990);
00084    fVpad  = new TPad("vpad","V pad",0.010,0.010,0.990,0.495);
00085 
00086    // white background
00087    fUpad->SetFillColor(10);
00088    fVpad->SetFillColor(10);
00089 
00090    // tweak the margins to maximize histogram use of pads
00091    fUpad->SetLeftMargin(0.05);
00092    fUpad->SetRightMargin(0.0001);
00093    fUpad->SetTopMargin(0.0001);
00094    fUpad->SetBottomMargin(0.055);
00095    fVpad->SetLeftMargin(0.05);
00096    fVpad->SetRightMargin(0.0001);
00097    fVpad->SetTopMargin(0.0001);
00098    fVpad->SetBottomMargin(0.055);
00099 
00100    // draw the pads and the canvas
00101    fUpad->Draw();
00102    fVpad->Draw();
00103    fCanvas->Draw();
00104 
00105 }
00106 
00107 //_____________________________________________________________________________
00108 CheezyDisplay::~CheezyDisplay()
00109 {
00110    // delete all the owned sub-objects
00111    delete fUview;
00112    delete fVview;
00113    delete fUpad;
00114    delete fVpad;
00115    delete fCanvas;
00116 }
00117 
00118 //_____________________________________________________________________________
00119 void CheezyDisplay::SetVldContext(VldContext& vldc)
00120 {
00121    // Configure for a particular detector type
00122 
00123    Detector::Detector_t new_detector = vldc.GetDetector();
00124    Detector::Detector_t old_detector = fVldContext.GetDetector();
00125 
00126    // always set the current context (geometry builds off this)
00127    fVldContext = vldc; 
00128 
00129    if ( new_detector == old_detector ) return;
00130 
00131    // detector type changes - clear the lists
00132    ClearLists();
00133 
00134    Float_t zmin,zmax,tmin_u,tmax_u,tmin_v,tmax_v;
00135    Float_t spacing = 5.94;
00136    Float_t dt = 20;
00137 
00138    UgliGeomHandle ugh(fVldContext);
00139    ugh.GetZExtent(zmin,zmax);
00140    zmin /= Munits::cm;  // convert to cm
00141    zmax /= Munits::cm;  // convert to cm
00142 
00143    zmin -= 5*spacing;
00144    zmax += 5*spacing + 20;
00145 
00146    switch (new_detector) {
00147    case Detector::kNear:
00148 
00149 //      zmin =        -5.0 * spacing;
00150 //      zmax =  (float)282 * spacing + 20. + 5.0*spacing;
00151 
00152       tmin_u = -210  -dt;
00153       tmax_u =  275  +dt;
00154          
00155       tmin_v = -275  -dt;
00156       tmax_v =  210  +dt;
00157 
00158       fMarkerType[0]  = 24;     // 24=circle, 25=box, 20=solid disk
00159       fMarkerType[1]  = 20;     //
00160       fMarkerType[2]  = 20;     //
00161 
00162       fMarkerSize[0]  = 0.65;
00163       fMarkerSize[1]  = 0.5;
00164       fMarkerSize[2]  = 0.5;
00165 
00166       break;
00167 
00168    case Detector::kCalDet:
00169 
00170 //      zmin =        -5.0 * spacing;
00171 //      zmax =  (float)5*12 * spacing + 20. + 5.0*spacing;
00172 
00173       tmin_u = -50  -dt;
00174       tmax_u =  50  +dt;
00175          
00176       tmin_v = -50  -dt;
00177       tmax_v =  50  +dt;
00178 
00179       fMarkerType[0]  = 24;     // 24=circle, 25=box, 20=solid disk
00180       fMarkerType[1]  = 21;     //
00181       fMarkerType[2]  = 21;     //
00182 
00183       fMarkerSize[0]  = 0.65;
00184       fMarkerSize[1]  = 0.55;
00185       fMarkerSize[2]  = 0.45;   // smaller than East, drawn second
00186 
00187       break;
00188 
00189    case Detector::kFar:
00190    default:
00191 
00192 //      zmin =        -5.0 * spacing;
00193 //      zmax =  (float)484 * spacing  + 125. + 5.0*spacing;
00194 
00195       tmin_u = tmin_v = -405 -dt;
00196       tmax_u = tmax_v =  405 +dt;
00197 
00198       fMarkerType[0]  = 24;     // 24=circle, 25=box, 20=solid disk
00199       fMarkerType[1]  = 20;     //
00200       fMarkerType[2]  = 20;     //
00201 
00202       fMarkerSize[0]  = 0.65;
00203       fMarkerSize[1]  = 0.5;
00204       fMarkerSize[2]  = 0.5;
00205 
00206       break;
00207    }
00208 
00209    // clear the primitives from the pads
00210    fUpad->Clear("");
00211    fVpad->Clear("");
00212 
00213    // remove old histograms if they exists
00214    if ( fUview ) { delete fUview; fUview=0; }
00215    if ( fVview ) { delete fVview; fVview=0; }
00216 
00217    // create histograms that we'll use for World Coordinates
00218    fUview = new TH2F("Uview","U view",1,zmin,zmax,1,tmin_u,tmax_u);
00219    fVview = new TH2F("Vview","V view",1,zmin,zmax,1,tmin_v,tmax_v);
00220 
00221    // don't draw the Stats box
00222    fUview->SetStats(kFALSE);
00223    fVview->SetStats(kFALSE);
00224 
00225    // take away any association with a "directory" for these histograms
00226    fUview->SetDirectory(0);
00227    fVview->SetDirectory(0);
00228 }
00229 
00230 //_____________________________________________________________________________
00231 void CheezyDisplay::ClearLists()
00232 {
00233    // Clear the lists of SEIdAltL's
00234 
00235    fTrueSEIdUview.erase(fTrueSEIdUview.begin(),fTrueSEIdUview.end());
00236    fTrueSEIdVview.erase(fTrueSEIdVview.begin(),fTrueSEIdVview.end());
00237 
00238    fMuxSEIdUEast.erase(fMuxSEIdUEast.begin(),fMuxSEIdUEast.end());
00239    fMuxSEIdVEast.erase(fMuxSEIdVEast.begin(),fMuxSEIdVEast.end());
00240    fMuxSEIdUWest.erase(fMuxSEIdUWest.begin(),fMuxSEIdUWest.end());
00241    fMuxSEIdVWest.erase(fMuxSEIdVWest.begin(),fMuxSEIdVWest.end());
00242 
00243 }
00244 
00245 //_____________________________________________________________________________
00246 void CheezyDisplay::AddStripEndId(const PlexStripEndId seid, const Bool_t truth)
00247 {
00248    // Add an element to be drawn by encapulating it in a alt list
00249 
00250    PlexSEIdAltL altlist;
00251    altlist.AddStripEndId(seid,PlexPixelSpotId());
00252    AddSEIdAltL(altlist,truth);
00253 
00254 }
00255 //_____________________________________________________________________________
00256 void CheezyDisplay::AddSEIdAltL(const PlexSEIdAltL altl, const Bool_t truth)
00257 {
00258    // Add an element to be drawn to the right list
00259 
00260    if (altl.size() == 0) return;
00261 
00262    // determine view -- assume consistency within AltL
00263    PlaneView::PlaneView_t view = altl.GetPlaneView();
00264 
00265    Detector::Detector_t detector = altl.GetDetector();
00266 
00267    // If CalDet & PlaneView::kA or kB then print limited warning 
00268    // and ignore this entry
00269    static Int_t msgab = 2;
00270    if (Detector::kCalDet == detector) {
00271       if (PlaneView::kA == view || PlaneView::kB == view) {
00272          if (msgab>0) {
00273             MSG("Cheezy",Msg::kWarning)
00274                << " ignoring PlaneView kA and kB digits" << endl;
00275             msgab--;
00276          }
00277          return;
00278       }
00279    }
00280 
00281    switch (detector) {
00282    case Detector::kNear:
00283    case Detector::kFar:
00284    case Detector::kCalDet:
00285      break; // do nothing
00286    default:
00287      // unknown detector!
00288      MSG("Cheezy",Msg::kError)
00289        << "unknown detector in AltL" << endl;
00290      altl.Print();
00291      assert(0); 
00292    }
00293    static Int_t msgend  = 2;
00294    static Int_t msgview = 2;
00295    Bool_t badend  = kFALSE;
00296    Bool_t badview = kFALSE;
00297 
00298    if (truth) {
00299       switch (view) {
00300       case PlaneView::kU: fTrueSEIdUview.push_back(altl); break;
00301       case PlaneView::kV: fTrueSEIdVview.push_back(altl); break;
00302       default: badview = kTRUE;
00303       }
00304    } else {
00305       switch (altl.GetEnd()) {
00306       case StripEnd::kEast:
00307          switch (view) {
00308          case PlaneView::kU: fMuxSEIdUEast.push_back(altl); break;
00309          case PlaneView::kV: fMuxSEIdVEast.push_back(altl); break;
00310          default: badview = kTRUE;
00311          }
00312          break;
00313       case StripEnd::kWest:
00314          switch (view) {
00315          case PlaneView::kU: fMuxSEIdUWest.push_back(altl); break;
00316          case PlaneView::kV: fMuxSEIdVWest.push_back(altl); break;
00317          default: badview = kTRUE;
00318          }
00319          break;
00320       default:
00321          badend = kTRUE;
00322          break;
00323       }
00324    }
00325 
00326    if (badend && msgend>0) {
00327       MSG("Cheezy",Msg::kWarning)
00328          << "CheezyDisplay::AddSEIdAltL bad end \""
00329          << StripEnd::AsString(altl.GetEnd()) << "\""
00330          << endl;
00331       msgend--;
00332    }
00333    if (badview && msgview>0) {
00334       MSG("Cheezy",Msg::kWarning)
00335          << "CheezyDisplay::AddSEIdAltL bad view \""
00336          << PlaneView::AsString(view) << "\""
00337          << endl;
00338       msgview--;
00339    }
00340 
00341 
00342 }
00343 
00344 //_____________________________________________________________________________
00345 void CheezyDisplay::Draw(Option_t* /* opt */)
00346 {
00347    // Draw the display
00348 
00349    // delete all current polymarkers
00350    // safe to do even if pointer to 0
00351    SafeDelete(fPM_TU);
00352    SafeDelete(fPM_TV);
00353    SafeDelete(fPM_UE);
00354    SafeDelete(fPM_UW);
00355    SafeDelete(fPM_VE);
00356    SafeDelete(fPM_VW);
00357 
00358    MSG("Cheezy",Msg::kDebug) 
00359       << "Draw()  Truth " << (int)fDrawTruth
00360       << " OnlyBest " << (int)fDrawOnlyBest
00361       << " WgtThresh " << fWgtThresh << endl;
00362 
00363    // change to the U view pad
00364    fUpad->cd();
00365    if (fUview) fUview->Draw();
00366 
00367    if (fDrawSide[0] && fDrawTruth ) {
00368       fPM_TU = BuildPolyMarker(fTrueSEIdUview,0,0,kTRUE);
00369       if (fPM_TU) fPM_TU->Draw();
00370    }
00371 
00372    if (fDrawSide[1]) {
00373       fPM_UE = BuildPolyMarker(fMuxSEIdUEast,+1,1,kFALSE);
00374       if (fPM_UE) fPM_UE->Draw();
00375    }
00376 
00377    if (fDrawSide[2]) {
00378       fPM_UW = BuildPolyMarker(fMuxSEIdUWest,-1,2,kFALSE);
00379       if (fPM_UW) fPM_UW->Draw();
00380    }
00381 
00382    // change to the V view pad
00383    fVpad->cd();
00384    if (fVview) fVview->Draw();
00385 
00386    if (fDrawSide[0] && fDrawTruth ) {
00387       fPM_TV = BuildPolyMarker(fTrueSEIdVview,0,0,kTRUE);
00388       if (fPM_TV) fPM_TV->Draw();
00389    }
00390 
00391    if (fDrawSide[1]) {
00392       fPM_VE = BuildPolyMarker(fMuxSEIdVEast,+1,1,kFALSE);
00393       if (fPM_VE) fPM_VE->Draw();
00394    }
00395 
00396    if (fDrawSide[2]) {
00397       fPM_VW = BuildPolyMarker(fMuxSEIdVWest,-1,2,kFALSE);
00398       if (fPM_VW) fPM_VW->Draw();
00399    }
00400 
00401    fCanvas->Update();
00402 
00403 }
00404 
00405 //_____________________________________________________________________________
00406 void CheezyDisplay::SetMarkerStyle(const Int_t   iside,
00407                            const Int_t   color, 
00408                            const Int_t   mtype,
00409                            const Float_t size)
00410 {
00411    // Each view has three "sides" 0=Truth, 1=East, 2=West
00412 
00413    if (iside< 0 || iside > 2) return; // protection
00414 
00415    if (color < 0 || mtype < 0 || size < 0) {
00416       fDrawSide[iside] = kFALSE;
00417    } else {
00418       fDrawSide[iside]    = kTRUE;
00419       fMarkerColor[iside] = color;
00420       fMarkerType[iside]  = mtype;
00421       fMarkerSize[iside]  = size;
00422    }
00423 }
00424 
00425 //_____________________________________________________________________________
00426 TPolyMarker* CheezyDisplay::BuildPolyMarker(std::vector<PlexSEIdAltL>& altl_list,
00427                                             Float_t yoff, Int_t iside, Bool_t truth)
00428 {
00429    // Create a TPolyMarker from a PlexStripEndId list
00430 
00431    vector<PlexSEIdAltL>::iterator ilist;
00432    vector<PlexStripEndId>::iterator i;
00433    Int_t elements;
00434 
00435    TPolyMarker *pm = 0;
00436    vector<PlexStripEndId> seidlist;
00437 
00438    // make a list of the actual stripend id's to draw
00439    // makes use of automagic expansion of vector size
00440    elements = 0;
00441    for (ilist = altl_list.begin(); ilist != altl_list.end(); ++ilist) {
00442       PlexSEIdAltL altlist = (*ilist);
00443       if (truth) {
00444          PlexStripEndId truth = altlist.GetBestSEId();
00445          seidlist.push_back(truth);
00446       } else if (fDrawOnlyBest) {
00447          PlexStripEndId best = altlist.GetBestSEId();
00448          if (altlist.GetBestWeight() > fWgtThresh) 
00449             seidlist.push_back(best);
00450       } else {
00451          altlist.SetFirst();
00452          while ( altlist.IsValid() ) {
00453             PlexStripEndId seid = altlist.GetCurrentSEId();
00454             if (altlist.GetCurrentWeight() > fWgtThresh)
00455                seidlist.push_back(seid);
00456             altlist.Next();
00457          }
00458       }  
00459    }
00460 
00461    // count the relevant points
00462    elements = seidlist.size();
00463    // Allocate the PolyMarker
00464    if ( ! elements ) {
00465 //    no elements  -- return null pointer
00466       return 0;
00467    }
00468    pm = new TPolyMarker(elements);
00469 
00470    if (iside<0 || iside>2) iside = 0;  // protection
00471    pm->SetMarkerStyle(fMarkerType[iside]);
00472    pm->SetMarkerColor(fMarkerColor[iside]);
00473    pm->SetMarkerSize(fMarkerSize[iside]);
00474 
00475    Float_t x,y;
00476    x = y = 0;
00477       
00478    Int_t j = 0;
00479    for (i = seidlist.begin(); i != seidlist.end(); ++i) {
00480       PlaneStripToXY((*i),yoff,x,y);
00481       pm->SetPoint(j,x,y);
00482       j++;                       
00483    }
00484 
00485    return pm;
00486 
00487 }
00488 
00489 //_____________________________________________________________________________
00490 void CheezyDisplay::PlaneStripToXY(PlexStripEndId seid, Float_t xoff,
00491                                    Float_t &x, Float_t &y)
00492 {
00493 
00494 //   x = RerootExodus::RerootPlaneZ0(seid) + xoff;
00495 //   y = RerootExodus::SEIdToTPos(seid);
00496 //   return;
00497 
00498    UgliGeomHandle ugh(fVldContext);
00499    UgliStripHandle ush = ugh.GetStripHandle(seid);
00500 
00501    if (ush.IsValid()) {
00502       // Ugli uses Minos units
00503       // Cheezy expects "cm"
00504       x = ush.GlobalPos(0).Z()/Munits::cm + xoff;
00505       y = ush.GetTPos()/Munits::cm;
00506    } else {
00507       static Int_t msg_invalid = 5;
00508       if (msg_invalid>0) {
00509          MSG("Cheezy",Msg::kWarning)
00510             << "UgliStripHandle was invalid " << seid.AsString("c") <<
00511             endl;
00512          msg_invalid--;
00513       }
00514       // fake it
00515       x = seid.GetPlane() * 5.94 + xoff;
00516       const Float_t dy = 4.1;
00517       Float_t yoff = 0;
00518       switch (seid.GetDetector()) {
00519       case Detector::kNear:
00520          // in the near detector the offset depends on 
00521          // PlaneView and PlaneCoverage
00522          switch (seid.GetPlaneView()) {
00523          case PlaneView::kU:
00524             // in U view it matters whether it is a partial or full plane
00525             switch (seid.GetPlaneCoverage()) {
00526             case PlaneCoverage::kNearPartial:
00527                yoff = -6.4;
00528                break;
00529             case PlaneCoverage::kNearFull:
00530                yoff = -125.7;
00531                break;
00532             default:
00533                yoff = 0;
00534                break;
00535             }
00536             break;
00537          case PlaneView::kV:
00538             // in V view both partial and full planes start at same pos
00539             yoff = -273.8;
00540             break;
00541          default:  // not U or V in Near
00542             yoff = -100;
00543             break;
00544          }
00545          break;
00546       case Detector::kFar:
00547          yoff = (-96 + 0.5) * dy;
00548          break;
00549       case Detector::kCalDet:
00550          yoff = (-12 + 0.5) * dy;
00551          break;
00552       default:  // not Near, Far, CalDet
00553          yoff = 0;
00554          break;
00555       }
00556       y = yoff + seid.GetStrip() * dy;
00557    }
00558 
00559 }
00560 //_____________________________________________________________________________

Generated on Mon Feb 15 11:06:31 2010 for loon by  doxygen 1.3.9.1