WCSimVertexViewer.cc

Go to the documentation of this file.
00001 #include "WCSimVertexViewer.hh"
00002 #include "WCSimVertexGeometry.hh"
00003 
00004 #include "TCanvas.h"
00005 #include "TPad.h"
00006 #include "TH1D.h"
00007 #include "TH2D.h"
00008 #include "TMarker.h"
00009 #include "TLegend.h"
00010 #include "TMath.h"
00011 #include "TF1.h"
00012 
00013 #include "WCSimRecoEvent.hh"
00014 #include "WCSimRecoDigit.hh"
00015 #include "WCSimRecoVertex.hh"
00016 
00017 #include "WCSimParameters.hh"
00018 
00019 #include <iostream>
00020 #include <cmath>
00021 #include <cassert>
00022 
00023 ClassImp(WCSimVertexViewer)
00024 
00025 WCSimVertexViewer::WCSimVertexViewer() :  WCSimDisplay(), 
00026   fVertexCanvas2D(0),
00027   fVertexHistTimeFit(0),
00028   fVertexMarkerDigits(0),
00029   fVertexMarkerFilterDigits(0),
00030   fVertexTimeFit(0),
00031   fVertexLegend2D(0),
00032   fVertexCanvas1D(0),
00033   fVertexHistDigitsAll(0),
00034   fVertexHistDigitsCone(0),
00035   fVertexHistFilterDigitsCone(0),
00036   fVertexLegend1D(0),
00037   fTimeCanvas(0),
00038   fTimeHistDigitsAll(0),
00039   fTimeHistDigitsCone(0),
00040   fTimeHistFilterDigitsCone(0),
00041   fTimeLegend(0),
00042   fTransCanvas(0),
00043   fTransHistDigits(0),
00044   fTransHistFilterDigits(0),
00045   fTransLegend(0),  
00046   fLongCanvas(0),
00047   fLongHistDigits(0),
00048   fLongHistFilterDigits(0),
00049   fLongLegend(0)
00050 {
00051   std::cout << " *** WCSimVertexViewer::WCSimVertexViewer() *** " << std::endl;
00052 
00053   this->Initialize();
00054 }
00055 
00056 void WCSimVertexViewer::Initialize()
00057 {
00058   std::cout << " *** WCSimVertexViewer::Initialize() *** " << std::endl;
00059 
00060   this->BuildDisplay();
00061 }
00062 
00063 WCSimVertexViewer::~WCSimVertexViewer()
00064 { 
00065 
00066 }
00067 
00068 void WCSimVertexViewer::Reset()
00069 {
00070   std::cout << " *** WCSimVertexViewer::Reset() *** " << std::endl;
00071 
00072   if( fVertexCanvas2D )             delete fVertexCanvas2D;  
00073   if( fVertexHistTimeFit )          delete fVertexHistTimeFit;
00074   if( fVertexLegend2D )             delete fVertexLegend2D;  
00075 
00076   if( fVertexCanvas1D )             delete fVertexCanvas1D;
00077   if( fVertexHistDigitsAll )        delete fVertexHistDigitsAll;
00078   if( fVertexHistDigitsCone )       delete fVertexHistDigitsCone;
00079   if( fVertexHistFilterDigitsCone ) delete fVertexHistFilterDigitsCone;
00080   if( fVertexTimeFit )              delete fVertexTimeFit;
00081   if( fVertexLegend1D )             delete fVertexLegend1D;  
00082 
00083   if( fTimeCanvas )                 delete fTimeCanvas;
00084   if( fTimeHistDigitsAll )          delete fTimeHistDigitsAll;
00085   if( fTimeHistDigitsCone )         delete fTimeHistDigitsCone;
00086   if( fTimeHistFilterDigitsCone )   delete fTimeHistFilterDigitsCone;
00087   if( fTimeLegend )                 delete fTimeLegend;  
00088 
00089   if( fTransCanvas )                delete fTransCanvas;
00090   if( fTransHistDigits )            delete fTransHistDigits;
00091   if( fTransHistFilterDigits )      delete fTransHistFilterDigits;
00092   if( fTransLegend )                delete fTransLegend;  
00093 
00094   if( fLongCanvas )                 delete fLongCanvas;
00095   if( fLongHistDigits )             delete fLongHistDigits;
00096   if( fLongHistFilterDigits )       delete fLongHistFilterDigits;
00097   if( fLongLegend )                 delete fLongLegend;
00098 
00099   return;
00100 }
00101 
00102 void WCSimVertexViewer::BuildDisplay()
00103 {
00104   std::cout << " *** WCSimVertexViewer::BuildDisplay() *** " << std::endl;
00105 
00106   // common binning
00107   // ==============
00108   fRbins = 300;
00109   fRmin = -3000.0;
00110   fRmax = +33000.0;  
00111   fNewRmin = fRmin;
00112   fNewRmax = fRmax;  
00113 
00114   fLbins = 240;
00115   fLmin = -1000.0;
00116   fLmax = +11000.0;  
00117   fNewLmin = fLmin;
00118   fNewLmax = fLmax;
00119 
00120   fTbins = 720;
00121   fTmin = -300.0;
00122   fTmax = +3300.0;
00123   fNewTmin = fTmin;
00124   fNewTmax = fTmax;
00125 
00126   // speed of light
00127   // ==============
00128   Double_t fC = WCSimParameters::SpeedOfLight();
00129 
00130 
00131   // set up 1D display
00132   // =================
00133   fVertexCanvas1D = new TCanvas("wcsim_vertex_timefit_1d","WCSim Vertex TimeFit Display (1D)",750,800);
00134   fVertexCanvas1D->SetLeftMargin(0.2);
00135 
00136   fVertexHistDigitsAll = new TH1D("hVertexTimeDigitsAll","",60,-20.0,+40.0);
00137   fVertexHistDigitsAll->GetXaxis()->SetTitle(" Residual / ns");
00138   fVertexHistDigitsAll->GetYaxis()->SetTitle(" Digits ");  
00139   fVertexHistDigitsAll->GetXaxis()->SetLabelSize(0.05);
00140   fVertexHistDigitsAll->GetYaxis()->SetLabelSize(0.05);
00141   fVertexHistDigitsAll->GetXaxis()->SetTitleSize(0.06);
00142   fVertexHistDigitsAll->GetYaxis()->SetTitleSize(0.06);
00143   fVertexHistDigitsAll->GetYaxis()->SetTitleOffset(1.5);
00144   fVertexHistDigitsAll->GetXaxis()->CenterTitle();
00145   fVertexHistDigitsAll->GetYaxis()->CenterTitle();
00146   fVertexHistDigitsAll->SetLineWidth(2);
00147   fVertexHistDigitsAll->SetLineStyle(7);
00148 
00149   fVertexHistDigitsCone = new TH1D("hVertexTimeDigitsCone","",60,-20.0,+40.0);
00150   fVertexHistDigitsCone->SetLineWidth(2);
00151 
00152   fVertexHistFilterDigitsCone = new TH1D("hVertexTimeFilterDigitsCone","",60,-20.0,+40.0);
00153   fVertexHistFilterDigitsCone->SetLineWidth(1);
00154   fVertexHistFilterDigitsCone->SetLineColor(kBlue+1);
00155   fVertexHistFilterDigitsCone->SetFillColor(kBlue+1);
00156 
00157   fVertexLegend1D = new TLegend(0.51,0.74,0.92,0.88);
00158   fVertexLegend1D->AddEntry(fVertexHistDigitsAll,"All Digits","l");
00159   fVertexLegend1D->AddEntry(fVertexHistDigitsCone,"All Digits (Cone)","l");
00160   fVertexLegend1D->AddEntry(fVertexHistFilterDigitsCone,"Filtered Digits (Cone)","lf");
00161   fVertexLegend1D->SetFillColor(kWhite);
00162   fVertexLegend1D->SetFillStyle(0);
00163   fVertexLegend1D->SetLineColor(kWhite);
00164 
00165 
00166   // set up 2D display
00167   // =================
00168   fVertexCanvas2D = new TCanvas("wcsim_vertex_timefit_2d","WCSim Vertex TimeFit Display (2D)",900,800);
00169 
00170   fVertexHistTimeFit = new TH2D("hVertexHistTimeFit","",fRbins,fRmin,fRmax,
00171                                                         fTbins,fTmin,fTmax);
00172 
00173   fVertexHistTimeFit->GetXaxis()->SetTitle(" Optical Path From Vertex / cm");
00174   fVertexHistTimeFit->GetYaxis()->SetTitle(" Time From Vertex / ns");
00175   fVertexHistTimeFit->GetXaxis()->SetLabelSize(0.05);
00176   fVertexHistTimeFit->GetYaxis()->SetLabelSize(0.05);
00177   fVertexHistTimeFit->GetXaxis()->SetTitleSize(0.06);
00178   fVertexHistTimeFit->GetYaxis()->SetTitleSize(0.06);
00179   fVertexHistTimeFit->GetYaxis()->SetTitleOffset(1.4);
00180   fVertexHistTimeFit->GetXaxis()->CenterTitle();
00181   fVertexHistTimeFit->GetYaxis()->CenterTitle();
00182 
00183   fVertexTimeFit = new TF1("VertexTimeFit","[0]*x",-1000.0,+10000.0);
00184   fVertexTimeFit->SetParameter(0,1.0/fC);
00185   fVertexTimeFit->SetLineWidth(2);
00186   fVertexTimeFit->SetLineColor(kRed);
00187 
00188   fVertexMarkerDigits = new TMarker(-99999.9,-99999.9,4);
00189   fVertexMarkerFilterDigits = new TMarker(-99999.9,-99999.9,8);
00190 
00191   fVertexMarkerDigits->SetMarkerColor(kGray);
00192   fVertexMarkerDigits->SetMarkerSize(2.0);
00193 
00194   fVertexMarkerFilterDigits->SetMarkerColor(kBlack);
00195   fVertexMarkerFilterDigits->SetMarkerSize(2.0);
00196 
00197   fVertexLegend2D = new TLegend(0.21,0.73,0.56,0.88);
00198   fVertexLegend2D->AddEntry(fVertexMarkerDigits,"All Digits","p");
00199   fVertexLegend2D->AddEntry(fVertexMarkerFilterDigits,"Filtered Digits","p");
00200   fVertexLegend2D->AddEntry(fVertexTimeFit,"Timing Fit","l");
00201   fVertexLegend2D->SetLineColor(kWhite);
00202   fVertexLegend2D->SetFillColor(kWhite);
00203   fVertexLegend2D->SetFillStyle(0);
00204 
00205 
00206   // set up time display
00207   // ====================
00208   fTimeCanvas = new TCanvas("wcsim_vertex_timeprofile","WCSim Vertex TimeProfile Display",1050,800);
00209   fTimeCanvas->SetLeftMargin(0.2);
00210 
00211   fTimeHistDigitsAll = new TH1D("hTimeDigitsAll","",fTbins,fTmin,fTmax);
00212   fTimeHistDigitsAll->GetXaxis()->SetTitle(" Time / ns");
00213   fTimeHistDigitsAll->GetYaxis()->SetTitle(" Digits ");  
00214   fTimeHistDigitsAll->GetXaxis()->SetLabelSize(0.05);
00215   fTimeHistDigitsAll->GetYaxis()->SetLabelSize(0.05);
00216   fTimeHistDigitsAll->GetXaxis()->SetTitleSize(0.06);
00217   fTimeHistDigitsAll->GetYaxis()->SetTitleSize(0.06);
00218   fTimeHistDigitsAll->GetYaxis()->SetTitleOffset(1.1);
00219   fTimeHistDigitsAll->GetXaxis()->CenterTitle();
00220   fTimeHistDigitsAll->GetYaxis()->CenterTitle();
00221   fTimeHistDigitsAll->SetLineWidth(2);
00222   fTimeHistDigitsAll->SetLineStyle(7);
00223 
00224   fTimeHistDigitsCone = new TH1D("hTimeDigitsCone","",fTbins,fTmin,fTmax);
00225   fTimeHistDigitsCone->SetLineWidth(2);
00226 
00227   fTimeHistFilterDigitsCone = new TH1D("hTimeFilterDigitsCone","",fTbins,fTmin,fTmax);
00228   fTimeHistFilterDigitsCone->SetLineWidth(1);
00229   fTimeHistFilterDigitsCone->SetLineColor(kBlue+1);
00230   fTimeHistFilterDigitsCone->SetFillColor(kBlue+1);
00231 
00232   fTimeLegend = new TLegend(0.51,0.74,0.92,0.88);
00233   fTimeLegend->AddEntry(fTimeHistDigitsAll,"All Digits","l");
00234   fTimeLegend->AddEntry(fTimeHistDigitsCone,"All Digits (Cone)","l");
00235   fTimeLegend->AddEntry(fTimeHistFilterDigitsCone,"Filtered Digits (Cone)","lf");
00236   fTimeLegend->SetFillColor(kWhite);
00237   fTimeLegend->SetFillStyle(0);
00238   fTimeLegend->SetLineColor(kWhite);
00239 
00240 
00241   // set up transverse display
00242   // =========================
00243   fTransCanvas = new TCanvas("wcsim_transverse_display","WCSim Transverse Display",750,800);
00244   fTransCanvas->SetLeftMargin(0.2);
00245 
00246   fTransHistDigits = new TH1D("hTransHistDigits ","",65,0,130.0);
00247   fTransHistDigits->GetXaxis()->SetTitle(" Angle / Degrees ");
00248   fTransHistDigits->GetYaxis()->SetTitle(" Digits ");
00249   fTransHistDigits->GetXaxis()->SetLabelSize(0.05);
00250   fTransHistDigits->GetYaxis()->SetLabelSize(0.05);
00251   fTransHistDigits->GetXaxis()->SetTitleSize(0.06);
00252   fTransHistDigits->GetYaxis()->SetTitleSize(0.06);
00253   fTransHistDigits->GetYaxis()->SetTitleOffset(1.5);
00254   fTransHistDigits->GetXaxis()->CenterTitle();
00255   fTransHistDigits->GetYaxis()->CenterTitle();
00256   fTransHistDigits->SetLineWidth(2);
00257 
00258   fTransHistFilterDigits = new TH1D("hTransHistFilterDigits","",65,0,130.0);
00259   fTransHistFilterDigits->SetLineWidth(1);
00260   fTransHistFilterDigits->SetLineColor(kBlue+1);
00261   fTransHistFilterDigits->SetFillColor(kBlue+1);
00262 
00263   fTransLegend = new TLegend(0.51,0.78,0.88,0.88);
00264   fTransLegend->AddEntry(fTransHistDigits,"All Digits","l");
00265   fTransLegend->AddEntry(fTransHistFilterDigits,"Filtered Digits","lf");
00266   fTransLegend->SetFillColor(kWhite);
00267   fTransLegend->SetFillStyle(0);
00268   fTransLegend->SetLineColor(kWhite);
00269 
00270 
00271   // set up longitudinal display
00272   // ===========================
00273   fLongCanvas = new TCanvas("wcsim_longitudinal_display","WCSim Longitudinal Display",1050,800);
00274   
00275   fLongHistDigits = new TH1D("hLongHistDigits ","",fLbins,fLmin,fLmax);
00276   fLongHistDigits->GetXaxis()->SetTitle(" Distance Along Track / cm ");
00277   fLongHistDigits->GetYaxis()->SetTitle(" Digits ");
00278   fLongHistDigits->GetXaxis()->SetLabelSize(0.05);
00279   fLongHistDigits->GetYaxis()->SetLabelSize(0.05);
00280   fLongHistDigits->GetXaxis()->SetTitleSize(0.06);
00281   fLongHistDigits->GetYaxis()->SetTitleSize(0.06);
00282   fLongHistDigits->GetYaxis()->SetTitleOffset(1.1);
00283   fLongHistDigits->GetXaxis()->CenterTitle();
00284   fLongHistDigits->GetYaxis()->CenterTitle();
00285   fLongHistDigits->SetLineWidth(2);
00286 
00287   fLongHistFilterDigits = new TH1D("hLongHistFilterDigits","",fLbins,fLmin,fLmax);
00288   fLongHistFilterDigits->SetLineWidth(1);
00289   fLongHistFilterDigits->SetLineColor(kBlue+1);
00290   fLongHistFilterDigits->SetFillColor(kBlue+1);
00291 
00292   fLongLegend = new TLegend(0.51,0.78,0.88,0.88);
00293   fLongLegend->AddEntry(fLongHistDigits,"All Digits","l");
00294   fLongLegend->AddEntry(fLongHistFilterDigits,"Filtered Digits","lf");
00295   fLongLegend->SetFillColor(kWhite);
00296   fLongLegend->SetFillStyle(0);
00297   fLongLegend->SetLineColor(kWhite);
00298 
00299 
00300   // Draw everything
00301   // ===============
00302   this->DrawNewDisplay();
00303 
00304   return;
00305 }
00306 
00307 void WCSimVertexViewer::DrawRecoEvent(WCSimRecoEvent* myEvent)
00308 {
00309   // check event
00310   // ===========
00311   if( myEvent==0 ){
00312     return;
00313   }
00314 
00315   // draw display
00316   // ============
00317   this->DrawNewRecoEvent(myEvent);
00318 
00319 }
00320 
00321 void WCSimVertexViewer::ResetDisplay()
00322 { 
00323   // all digits
00324   // ==========  
00325   for( UInt_t i=0; i<wcVertexDigits.size(); i++ ){
00326     delete (TMarker*)(wcVertexDigits.at(i));
00327   }
00328   
00329   wcVertexDigits.clear();
00330 
00331   // filtered digits
00332   // ===============  
00333   for( UInt_t i=0; i<wcVertexFilterDigits.size(); i++ ){
00334     delete (TMarker*)(wcVertexFilterDigits.at(i));
00335   }
00336 
00337   wcVertexFilterDigits.clear();
00338  
00339   // reset histograms
00340   // ================
00341   if( fVertexHistDigitsAll )        fVertexHistDigitsAll->Reset();
00342   if( fVertexHistDigitsCone )       fVertexHistDigitsCone->Reset();
00343   if( fVertexHistFilterDigitsCone ) fVertexHistFilterDigitsCone->Reset();
00344   if( fTimeHistDigitsAll )          fTimeHistDigitsAll->Reset();
00345   if( fTimeHistDigitsCone )         fTimeHistDigitsCone->Reset();
00346   if( fTimeHistFilterDigitsCone )   fTimeHistFilterDigitsCone->Reset();
00347   if( fTransHistDigits )            fTransHistDigits->Reset();
00348   if( fTransHistFilterDigits )      fTransHistFilterDigits->Reset();
00349   if( fLongHistDigits )             fLongHistDigits->Reset();
00350   if( fLongHistFilterDigits )       fLongHistFilterDigits->Reset();
00351 
00352   // reset event info
00353   // ================
00354   fRunNumber = -1;
00355   fEventNumber = -1;
00356   fTriggerNumber = -1;
00357 
00358   // draw new display
00359   // ================
00360   this->DrawNewDisplay();
00361 
00362   return;
00363 }
00364   
00365 void WCSimVertexViewer::DrawNewDisplay()
00366 { 
00367   // Generate Title String
00368   // =====================
00369   fTitleString="";
00370 
00371   if( fRunNumber>=0 ){
00372     fTitleString.Append("Run: "); 
00373     fTitleString+=fRunNumber;
00374     fTitleString.Append("  ");
00375     fTitleString.Append("Event: "); 
00376     fTitleString+=fEventNumber;
00377     fTitleString.Append("  ");
00378     fTitleString.Append("SubEvent: "); 
00379     fTitleString+=fTriggerNumber;
00380 
00381     fTitleLatex.SetTextFont(42);
00382     fTitleLatex.SetTextSize(0.04);
00383     fTitleLatex.SetTextAlign(11);
00384   }
00385 
00386   // Draw 1D Display
00387   // ===============
00388   if( fVertexCanvas1D ){
00389     fVertexCanvas1D->cd();
00390     fVertexCanvas1D->Clear();
00391     fVertexHistDigitsAll->Draw();
00392     fVertexHistDigitsCone->Draw("same");
00393     fVertexHistFilterDigitsCone->Draw("same");
00394     fVertexLegend1D->Draw();
00395     fVertexCanvas1D->Update();  
00396   }
00397 
00398   // Draw 2D Display
00399   // ===============
00400   if( fVertexCanvas2D ){
00401     fVertexCanvas2D->cd();
00402     fVertexHistTimeFit->Draw();
00403     fVertexLegend2D->Draw();
00404     fVertexCanvas2D->Update();
00405   }
00406 
00407   // Draw TimeProfile Display
00408   // ========================
00409   if( fTimeCanvas ){
00410     fTimeCanvas->cd();
00411     fTimeCanvas->Clear();
00412     fTimeHistDigitsAll->Draw();
00413     fTimeHistDigitsCone->Draw("same");
00414     fTimeHistFilterDigitsCone->Draw("same");
00415     fTimeLegend->Draw();
00416     fTimeCanvas->Update();  
00417   }
00418 
00419   // Draw Transverse Display
00420   // =======================
00421   if( fTransCanvas ){
00422     fTransCanvas->cd();
00423     fTransHistDigits->Draw();
00424     fTransHistFilterDigits->Draw("same");
00425     fTransLegend->Draw();
00426     fTransCanvas->Update();
00427   }  
00428 
00429   // Draw Longitidinal Display
00430   // =========================
00431   if( fLongCanvas ){
00432     fLongCanvas->cd();
00433     fLongHistDigits->Draw();
00434     fLongHistFilterDigits->Draw("same");
00435     fLongLegend->Draw();
00436     fLongCanvas->Update();
00437   }
00438 
00439   return;
00440 }
00441 
00442 void WCSimVertexViewer::PrintDisplay()
00443 {  
00444   // print GIF
00445   if( fPrintGIF ) this->PrintDisplayGIF();
00446 
00447   // print EPS
00448   if( fPrintEPS ) this->PrintDisplayEPS();
00449 
00450   return;
00451 }
00452 
00453 void WCSimVertexViewer::PrintDisplayGIF()
00454 {   
00455   if( fVertexCanvas1D ){
00456     TString outfile("wcresiduals");
00457     outfile.Append(".");
00458     outfile+=fRunNumber;
00459     outfile.Append(".");
00460     outfile+=fEventNumber;
00461     outfile.Append(".gif");
00462     fVertexCanvas1D->SaveAs(outfile.Data());
00463   }  
00464 
00465   if( fVertexCanvas2D ){
00466     TString outfile("wctimefit");
00467     outfile.Append(".");
00468     outfile+=fRunNumber;
00469     outfile.Append(".");
00470     outfile+=fEventNumber;
00471     outfile.Append(".gif");
00472     fVertexCanvas2D->SaveAs(outfile.Data());
00473   }
00474 
00475   if( fTimeCanvas ){
00476     TString outfile("wctimeprofile");
00477     outfile.Append(".");
00478     outfile+=fRunNumber;
00479     outfile.Append(".");
00480     outfile+=fEventNumber;
00481     outfile.Append(".gif");
00482     fTimeCanvas->SaveAs(outfile.Data());
00483   } 
00484 
00485   if( fTransCanvas ){
00486     TString outfile("wctransverse");
00487     outfile.Append(".");
00488     outfile+=fRunNumber;
00489     outfile.Append(".");
00490     outfile+=fEventNumber;
00491     outfile.Append(".gif");
00492     fTransCanvas->SaveAs(outfile.Data());
00493   } 
00494 
00495   if( fLongCanvas ){
00496     TString outfile("wclongitudinal");
00497     outfile.Append(".");
00498     outfile+=fRunNumber;
00499     outfile.Append(".");
00500     outfile+=fEventNumber;
00501     outfile.Append(".gif");
00502     fLongCanvas->SaveAs(outfile.Data());
00503   }
00504 
00505   return;
00506 }
00507 
00508 void WCSimVertexViewer::PrintDisplayEPS()
00509 {  
00510   if( fVertexCanvas1D ){
00511     TString outfile("wcresiduals");
00512     outfile.Append(".");
00513     outfile+=fRunNumber;
00514     outfile.Append(".");
00515     outfile+=fEventNumber;
00516     outfile.Append(".eps");
00517     fVertexCanvas1D->SaveAs(outfile.Data());
00518   }  
00519 
00520   if( fVertexCanvas2D ){
00521     TString outfile("wctimefit");
00522     outfile.Append(".");
00523     outfile+=fRunNumber;
00524     outfile.Append(".");
00525     outfile+=fEventNumber;
00526     outfile.Append(".eps");
00527     fVertexCanvas2D->SaveAs(outfile.Data());
00528   }
00529 
00530   if( fTimeCanvas ){
00531     TString outfile("wctimeprofile");
00532     outfile.Append(".");
00533     outfile+=fRunNumber;
00534     outfile.Append(".");
00535     outfile+=fEventNumber;
00536     outfile.Append(".eps");
00537     fTimeCanvas->SaveAs(outfile.Data());
00538   } 
00539 
00540   if( fTransCanvas ){
00541     TString outfile("wctransverse");
00542     outfile.Append(".");
00543     outfile+=fRunNumber;
00544     outfile.Append(".");
00545     outfile+=fEventNumber;
00546     outfile.Append(".eps");
00547     fTransCanvas->SaveAs(outfile.Data());
00548   } 
00549 
00550   if( fLongCanvas ){
00551     TString outfile("wclongitudinal");
00552     outfile.Append(".");
00553     outfile+=fRunNumber;
00554     outfile.Append(".");
00555     outfile+=fEventNumber;
00556     outfile.Append(".eps");
00557     fLongCanvas->SaveAs(outfile.Data());
00558   }
00559 
00560   return;
00561 }
00562 
00563 void WCSimVertexViewer::DrawNewRecoEvent(WCSimRecoEvent* myEvent, WCSimRecoVertex* myVertex)
00564 {  
00565   std::cout << " *** WCSimVertexViewer::DrawEvent(...) *** " << std::endl;
00566 
00567   // reset display
00568   // =============
00569   this->ResetDisplay();
00570 
00571   // Check for Event and Digits
00572   // ==========================
00573   if( myEvent==0 
00574    || myEvent->GetNDigits()==0 ) return;
00575 
00576   // Check for Vertex
00577   // ================
00578   WCSimRecoVertex* inputVertex = 0;
00579 
00580   if( myVertex ){
00581     inputVertex = myVertex;
00582   }
00583   else if( myEvent->FoundVertex() ){
00584     inputVertex = myEvent->GetVertex();
00585   }
00586 
00587   if( inputVertex==0 ) {
00588     std::cout << " <warning>: running vertex viewer with no vertex! " << std::endl;
00589     return;
00590   }
00591 
00592   // Get Event Info
00593   // ==============
00594   fRunNumber = myEvent->GetRun();
00595   fEventNumber = myEvent->GetEvent();
00596   fTriggerNumber = myEvent->GetTrigger();
00597 
00598   fTitleString="";
00599   
00600   fTitleString.Append("Run: "); 
00601   fTitleString+=fRunNumber;
00602   fTitleString.Append("  ");
00603   fTitleString.Append("Event: "); 
00604   fTitleString+=fEventNumber;
00605   fTitleString.Append("  ");
00606   fTitleString.Append("SubEvent: "); 
00607   fTitleString+=fTriggerNumber;
00608 
00609   fTitleLatex.SetTextFont(42);
00610   fTitleLatex.SetTextSize(0.04);
00611   fTitleLatex.SetTextAlign(11);
00612   
00613 
00614   // Reco Vertex
00615   // ===========
00616   Double_t vtxX = inputVertex->GetX();
00617   Double_t vtxY = inputVertex->GetY();
00618   Double_t vtxZ = inputVertex->GetZ();
00619   Double_t vtxTime = inputVertex->GetTime();
00620 
00621   Double_t dirX = inputVertex->GetDirX();
00622   Double_t dirY = inputVertex->GetDirY();
00623   Double_t dirZ = inputVertex->GetDirZ();
00624 
00625   std::cout << "  Displaying vertex: (vx,vy,vz,vt)=(" << vtxX << "," << vtxY << "," << vtxZ << "," << vtxTime << ") " << std::endl;
00626   std::cout << "                     (px,py,pz,th)=(" << dirX << "," << dirY << "," << dirZ << ") " << std::endl;
00627 
00628 
00629   // Useful Variables
00630   // ================
00631   Double_t min = 0.0;
00632   Double_t max = 0.0;
00633   Double_t hmax = 0.0;
00634 
00635   Double_t fNewRmin = fRmax;
00636   Double_t fNewRmax = fRmin;
00637   Double_t fNewLmin = fLmax;
00638   Double_t fNewLmax = fLmin;
00639   Double_t fNewTmin = fTmax;
00640   Double_t fNewTmax = fTmin;
00641  
00642   TMarker* marker = 0;
00643 
00644   // Calculate Residuals
00645   // ===================
00646   WCSimVertexGeometry::Instance()->CalcResiduals(myEvent,inputVertex);
00647 
00648   // Loop over Digits
00649   // ================
00650   for( Int_t idigit=0; idigit<WCSimVertexGeometry::Instance()->GetNDigits(); idigit++ ){
00651 
00652     Bool_t Pass = WCSimVertexGeometry::Instance()->IsFiltered(idigit);
00653     Double_t Q = WCSimVertexGeometry::Instance()->GetDigitQ(idigit);
00654 
00655     if( Q<GetPulseHeightCut() ) continue;
00656 
00657     Double_t thetadeg = WCSimVertexGeometry::Instance()->GetConeAngle(idigit);
00658     Double_t phideg   = WCSimVertexGeometry::Instance()->GetAngle(idigit);
00659     Double_t dt       = WCSimVertexGeometry::Instance()->GetDeltaTime(idigit);
00660     Double_t Ltrack   = WCSimVertexGeometry::Instance()->GetDistTrack(idigit);
00661     Double_t delta    = WCSimVertexGeometry::Instance()->GetExtendedResidual(idigit);
00662     Double_t path     = WCSimVertexGeometry::Instance()->GetExtendedPath(idigit);
00663 
00664     // all digits    
00665     // ==========
00666     marker = new TMarker(path,dt,4);
00667     marker->SetMarkerSize(1.0);
00668     marker->SetMarkerColor(kGray);
00669 
00670     fTransHistDigits->Fill(phideg); 
00671     fVertexHistDigitsAll->Fill(delta);
00672     fTimeHistDigitsAll->Fill(dt);
00673     if( phideg<thetadeg ){
00674       fLongHistDigits->Fill(Ltrack);
00675       fVertexHistDigitsCone->Fill(delta);
00676       fTimeHistDigitsCone->Fill(dt);
00677     }
00678 
00679     wcVertexDigits.push_back(marker);
00680 
00681     // filter digits
00682     // =============
00683     if( Pass ){
00684       marker = new TMarker(path,dt,8);
00685       marker->SetMarkerSize(1.0);
00686       marker->SetMarkerColor(kBlack);
00687 
00688       //
00689       // Int_t markercolor = this->QPEtoCOL(Q);
00690       // marker->SetMarkerColor(markercolor);
00691       // marker->SetMarkerSize(1.0);
00692       //
00693       // Double_t markersize = this->QPEtoSIZE(Q);
00694       // marker->SetMarkerSize(markersize);
00695       // marker->SetMarkerColor(kBlack);
00696       //
00697 
00698       fTransHistFilterDigits->Fill(phideg);
00699       if( phideg<thetadeg ){
00700         fLongHistFilterDigits->Fill(Ltrack);
00701         fVertexHistFilterDigitsCone->Fill(delta);
00702         fTimeHistFilterDigitsCone->Fill(dt);
00703       }
00704 
00705       if( dt<fNewTmin )   fNewTmin = dt;
00706       if( dt>fNewTmax )   fNewTmax = dt;
00707       if( path<fNewRmin ) fNewRmin = path;
00708       if( path>fNewRmax ) fNewRmax = path;
00709       if( Ltrack<fNewLmin ) fNewLmin = Ltrack;
00710       if( Ltrack>fNewLmax ) fNewLmax = Ltrack;
00711 
00712       wcVertexFilterDigits.push_back(marker);
00713     }
00714   }  
00715 
00716 
00717   // set T limits
00718   // ============
00719   fNewTmin -= 10.0;
00720   fNewTmax += 100.0;
00721 
00722   if( fNewTmax<fNewTmin ){
00723     fNewTmin = fTmin;
00724     fNewTmax = fTmax;
00725   }
00726 
00727   fVertexHistTimeFit->GetYaxis()->SetLimits(fNewTmin,fNewTmax);
00728   fTimeHistDigitsAll->GetXaxis()->SetRangeUser(fNewTmin,fNewTmax);
00729 
00730 
00731   // set R limits
00732   // ============
00733   fNewRmin -= 100.0;
00734   fNewRmax += 100.0;
00735 
00736   if( fNewRmax<fNewRmin ){
00737     fNewRmin = fRmin;
00738     fNewRmax = fRmax;
00739   }
00740 
00741   fVertexHistTimeFit->GetXaxis()->SetLimits(fNewRmin,fNewRmax);
00742 
00743 
00744   // set L limits
00745   // ============
00746   fNewLmin -= 50.0;
00747   fNewLmax += 50.0;
00748 
00749   if( fNewLmax<fNewLmin ){
00750     fNewLmin = fLmin;
00751     fNewLmax = fLmax;
00752   }
00753 
00754   fLongHistDigits->GetXaxis()->SetRangeUser(fNewLmin,fNewLmax);
00755 
00756 
00757   // set digits min/max (timing residuals)
00758   // =====================================
00759   hmax = 0.0;
00760   for( Int_t i=0; i<fVertexHistDigitsAll->GetXaxis()->GetNbins(); i++ ){
00761     if( fVertexHistDigitsAll->GetBinContent(i+1)>hmax ){
00762       hmax = fVertexHistDigitsAll->GetBinContent(i+1);
00763     }
00764   }
00765 
00766   max = (Double_t)( 100.0*(1.5+(Int_t)(hmax/100.0)) ); 
00767   min = 0.0;
00768 
00769   fVertexHistDigitsAll->SetMinimum(min);
00770   fVertexHistDigitsAll->SetMaximum(max);  
00771 
00772 
00773   // set digits min/max (timing profile)
00774   // ===================================
00775   hmax = 0.0;
00776   for( Int_t i=0; i<fTimeHistDigitsAll->GetXaxis()->GetNbins(); i++ ){
00777     if( fTimeHistDigitsAll->GetBinContent(i+1)>hmax ){
00778       hmax = fTimeHistDigitsAll->GetBinContent(i+1);
00779     }
00780   }
00781 
00782   max = (Double_t)( 100.0*(1.5+(Int_t)(hmax/100.0)) ); 
00783   min = 0.0;
00784 
00785   fTimeHistDigitsAll->SetMinimum(min);
00786   fTimeHistDigitsAll->SetMaximum(max);
00787 
00788 
00789   // set digits min/max (transverse)
00790   // ===============================
00791   hmax = 0.0; 
00792   for( Int_t i=0; i<fTransHistDigits->GetXaxis()->GetNbins(); i++ ){
00793     if( fTransHistDigits->GetBinContent(i+1)>hmax ){
00794       hmax = fTransHistDigits->GetBinContent(i+1);
00795     }
00796   }
00797   
00798   max = (Double_t)( 100.0*(1.5+(Int_t)(hmax/100.0)) ); 
00799   min = 0.0;
00800 
00801   fTransHistDigits->SetMinimum(min);
00802   fTransHistDigits->SetMaximum(max);  
00803 
00804 
00805   // set digits min/max (longitudinal)
00806   // =================================
00807   hmax = 0.0; 
00808   for( Int_t i=0; i<fLongHistDigits->GetXaxis()->GetNbins(); i++ ){
00809     if( fLongHistDigits->GetBinContent(i+1)>hmax ){
00810       hmax = fLongHistDigits->GetBinContent(i+1);
00811     }
00812   }
00813   
00814   max = (Double_t)( 100.0*(1.5+(Int_t)(hmax/100.0)) ); 
00815   min = 0.0;
00816 
00817   fLongHistDigits->SetMinimum(min);
00818   fLongHistDigits->SetMaximum(max);
00819 
00820 
00821   // draw 1D canvas
00822   // ==============
00823   if( fVertexCanvas1D ){
00824 
00825     fVertexCanvas1D->cd();
00826     fVertexCanvas1D->Clear();
00827     fVertexHistDigitsAll->Draw();
00828     fVertexHistDigitsCone->Draw("same");
00829     fVertexHistFilterDigitsCone->Draw("same");
00830     fVertexLegend1D->Draw();
00831 
00832     min = fVertexHistDigitsAll->GetMinimum();
00833     max = fVertexHistDigitsAll->GetMaximum();
00834     fTitleLatex.DrawLatex(-20.0,
00835                           max+0.015*(max-min),
00836                           fTitleString.Data());
00837     
00838     fVertexCanvas1D->Update();  
00839   }
00840 
00841 
00842   // draw 2D canvas
00843   // ==============
00844   if( fVertexCanvas2D ){
00845  
00846     fVertexCanvas2D->cd();
00847     fVertexCanvas2D->Clear();
00848 
00849     fVertexHistTimeFit->Draw();
00850 
00851     for( UInt_t idigit=0; idigit<wcVertexDigits.size(); idigit++ ){
00852       TMarker* marker = (TMarker*)(wcVertexDigits.at(idigit));
00853       if( marker->GetX()>fNewRmin && marker->GetX()<fNewRmax 
00854        && marker->GetY()>fNewTmin && marker->GetY()<fNewTmax ){
00855         marker->Draw();
00856       }
00857     }
00858 
00859     for( UInt_t idigit=0; idigit<wcVertexFilterDigits.size(); idigit++ ){
00860       TMarker* marker = (TMarker*)(wcVertexFilterDigits.at(idigit));
00861       if( marker->GetX()>fNewRmin && marker->GetX()<fNewRmax 
00862        && marker->GetY()>fNewTmin && marker->GetY()<fNewTmax ){
00863         marker->Draw();
00864       }
00865     }
00866 
00867     fVertexTimeFit->Draw("same");
00868     fVertexLegend2D->Draw();
00869 
00870     fTitleLatex.DrawLatex(fNewRmin,
00871                           fNewTmax+0.015*(fNewTmax-fNewTmin),
00872                           fTitleString.Data());
00873 
00874     fVertexCanvas2D->Update();
00875   }
00876 
00877   // draw canvas
00878   // ===========
00879   if( fTimeCanvas ){
00880 
00881     fTimeCanvas->cd();
00882     fTimeCanvas->Clear();
00883 
00884     fTimeHistDigitsAll->Draw();
00885     fTimeHistDigitsCone->Draw("same");
00886     fTimeHistFilterDigitsCone->Draw("same");
00887     fTimeLegend->Draw();
00888 
00889     min = fTimeHistDigitsAll->GetMinimum();
00890     max = fTimeHistDigitsAll->GetMaximum();
00891 
00892     fTitleLatex.DrawLatex(fNewTmin,
00893                           max+0.015*(max-min),
00894                           fTitleString.Data());
00895 
00896     fTimeCanvas->Update();
00897   }
00898 
00899   // draw canvas
00900   // ===========
00901   if( fTransCanvas ){
00902 
00903     fTransCanvas->cd();
00904     fTransCanvas->Clear();
00905 
00906     fTransHistDigits->Draw();
00907     fTransHistFilterDigits->Draw("same");
00908     fTransLegend->Draw();
00909 
00910     min = fTransHistDigits->GetMinimum();
00911     max = fTransHistDigits->GetMaximum();
00912 
00913     fTitleLatex.DrawLatex(0.0,
00914                           max+0.015*(max-min),
00915                           fTitleString.Data());
00916 
00917     fTransCanvas->Update();
00918   }
00919 
00920   // draw canvas
00921   // ===========
00922   if( fLongCanvas ){
00923 
00924     fLongCanvas->cd();
00925     fLongCanvas->Clear();
00926 
00927     fLongHistDigits->Draw();
00928     fLongHistFilterDigits->Draw("same");
00929     fLongLegend->Draw();
00930 
00931     min = fLongHistDigits->GetMinimum();
00932     max = fLongHistDigits->GetMaximum();
00933 
00934     fTitleLatex.DrawLatex(fNewLmin,
00935                           max+0.015*(max-min),
00936                           fTitleString.Data());
00937 
00938     fLongCanvas->Update();
00939   }
00940 
00941   return;
00942 }
00943 
00944 
00945 Int_t WCSimVertexViewer::QPEtoCOL(Double_t Q)
00946 {
00947   Int_t colourCode = kWhite;
00948 
00949   if( Q<0.8 )             colourCode = kYellow-7;
00950   if( Q>=0.8 && Q<1.5 )   colourCode = kCyan-7;
00951   if( Q>=1.5 && Q<2.5 )   colourCode = kCyan+1;
00952   if( Q>=2.5 && Q<5.0 )   colourCode = kBlue-4;
00953   if( Q>=5.0 && Q<10.0 )  colourCode = kBlue+1;
00954   if( Q>=10.0 && Q<15.0 ) colourCode = kMagenta+1;
00955   if( Q>=15.0 && Q<20.0 ) colourCode = kMagenta+2;
00956   if( Q>=20.0 && Q<30.0 ) colourCode = kRed-4;
00957   if( Q>=30.0 )           colourCode = kRed;
00958 
00959   return colourCode;
00960 }
00961 
00962 Double_t WCSimVertexViewer::QPEtoSIZE(Double_t Q)
00963 {
00964   Double_t markerSize = 0.2;
00965 
00966   if( Q>=0.0  && Q<1.0  ) markerSize = 0.2;  
00967   if( Q>=1.0  && Q<2.5  ) markerSize = 0.5;
00968   if( Q>=2.5  && Q<5.0  ) markerSize = 0.8;
00969   if( Q>=5.0  && Q<7.5  ) markerSize = 1.0;
00970   if( Q>=7.5  && Q<10.0 ) markerSize = 1.2;
00971   if( Q>=10.0 && Q<15.0 ) markerSize = 1.4;
00972   if( Q>=15.0 && Q<20.0 ) markerSize = 1.7;
00973   if( Q>=20.0 && Q<25.0 ) markerSize = 2.0;
00974   if( Q>=25.0 && Q<50.0 ) markerSize = 2.3;
00975   if( Q>=50.0 )           markerSize = 2.7;
00976 
00977   return markerSize;
00978 }