00001 #include "UserDisplayModule.h"
00002
00003 #include <Midad/Base/Mint.h>
00004 #include <Midad/Base/PageDisplay.h>
00005 #include <Midad/Base/CanvasSignals.h>
00006 #include <Midad/Base/SteelOutline.h>
00007
00008 #include <JobControl/JobC.h>
00009 #include <RecoBase/CandTrackHandle.h>
00010 #include <RecoBase/CandTrackListHandle.h>
00011 #include <RecoBase/CandStripHandle.h>
00012 #include <MinosObjectMap/MomNavigator.h>
00013
00014 #include <DataUtil/GetDetector.h>
00015 #include <DataUtil/CDL2STL.h>
00016 using namespace DataUtil;
00017
00018
00019 #include <MessageService/MsgService.h>
00020 CVSID("$Id: UserDisplayModule.cxx,v 1.11 2007/11/11 07:13:48 rhatcher Exp $");
00021
00022
00023 #include <JobControl/JobCModuleRegistry.h>
00024 JOBMODULE(UserDisplayModule,"UserDisplay","Example of adding a Midad display in a Job Module\n");
00025
00026
00027 #include <TList.h>
00028 #include <TH2D.h>
00029 #include <TCanvas.h>
00030 #include <TEllipse.h>
00031 #include <TText.h>
00032
00033 UserDisplayModule::UserDisplayModule()
00034 : fCanvas(0)
00035 , fUZview(0)
00036 , fVZview(0)
00037 , fUVview(0)
00038 , fSteelOutline(0)
00039 , fCleanup(0)
00040 {
00041 fCleanup = new TList;
00042 fCleanup->SetOwner();
00043 }
00044
00045 UserDisplayModule::~UserDisplayModule()
00046 {
00047 if (fUZview) delete fUZview;
00048 if (fVZview) delete fVZview;
00049 if (fUVview) delete fUVview;
00050 if (fCleanup) delete fCleanup;
00051 }
00052
00053 void UserDisplayModule::BeginRun()
00054 {
00055 if (gMint && !fCanvas) this->BuildDisplay();
00056 }
00057
00058 JobCResult UserDisplayModule::Ana(const MomNavigator *mom)
00059 {
00060 if (gMint) {
00061 if (&gMint->GetJobC().Mom != mom) {
00062 MSG("User",kError) << "Module's mom and JobC's mom differ: "
00063 << (void*)&gMint->GetJobC().Mom << " != "
00064 << (void*) mom << endl;
00065 }
00066 }
00067
00068 if (!fCanvas) {
00069
00070
00071 MSG("User",kWarning) << "I have no canvas!\n";
00072 return JobCResult::kAOK;
00073 }
00074
00075 this->UpdateDisplay();
00076
00077 return JobCResult::kAOK;
00078 }
00079
00080 void UserDisplayModule::BuildDisplay()
00081 {
00082
00083 UgliGeomHandle ugh = gMint->GetUgliGeomHandle();
00084 if (! ugh.IsValid()) {
00085 MSG("User",kWarning) << "Got invalid Ugli\n";
00086 return;
00087 }
00088
00089
00090 const int width = 1000, height = 500;
00091
00092 CanvasSignals* cs = 0;
00093 PageDisplay* pd = gMint->GetDisplay();
00094
00095
00096 if (!pd) {
00097 pd = gMint->SpawnDisplay(width,height);
00098 cs = dynamic_cast<CanvasSignals*>
00099 (pd->AddPage("UserCanvas"));
00100 }
00101
00102
00103
00104 else {
00105 cs = dynamic_cast<CanvasSignals*>
00106 (pd->SpawnSinglePage("UserCanvas",width,height));
00107 }
00108
00109 if (!cs) {
00110 MSG("User",kWarning) << "Failed to get UserCanvas's CanvasSignals\n";
00111 return;
00112 }
00113
00114
00115
00116
00117
00118 fCanvas = &cs->GetCanvas();
00119
00120
00121
00122
00123 fCanvas->Divide(2,1);
00124
00125
00126
00127
00128
00129 vector<UgliScintPlnHandle> sph = ugh.GetScintPlnHandleVector();
00130 int first_plane = sph.begin()->GetPlaneNumber();
00131 int last_plane = (sph.end()-1)->GetPlaneNumber();
00132
00133 int nstrips = sph.begin()->NumberOfStrips();
00134
00135 fCanvas->cd(1);
00136 fHistPad = new TPad("fHistPad","UZ and VZ views",0,0,1,1);
00137 fHistPad->Draw();
00138
00139 fHistPad->cd();
00140 fHistPad->Divide(1,2);
00141
00142
00143 fHistPad->cd(1);
00144 fUZview = new TH2D("UZview","Strip vs. Plane, U view",
00145 last_plane-first_plane+1,first_plane,last_plane+1,
00146 nstrips,0,nstrips);
00147 fUZview->SetStats(false);
00148 fUZview->Draw("COLZ");
00149
00150
00151 fHistPad->cd(2);
00152 fVZview = new TH2D("VZview","Strip vs. Plane, V view",
00153 last_plane-first_plane+1,first_plane,last_plane+1,
00154 nstrips,0,nstrips);
00155 fVZview->SetStats(false);
00156 fVZview->Draw("COLZ");
00157
00158
00159 fCanvas->cd(2);
00160 fUVview = new TPad("UVview","U vs V view",0,0,1,1);
00161 fUVview->SetFillStyle(4000);
00162
00163 float t[4];
00164 ugh.GetTransverseExtent(PlaneView::kU,t[0],t[1]);
00165 ugh.GetTransverseExtent(PlaneView::kV,t[2],t[3]);
00166 for (int ind=0; ind<4;++ind) t[ind] = TMath::Abs(t[ind]);
00167 int maxind = TMath::LocMax(4,t);
00168 float tsize = TMath::Sqrt(2.0) * t[maxind];
00169
00170 fUVview->Range(-tsize,-tsize,tsize,tsize);
00171 fUVview->Draw();
00172
00173 fSteelOutline = new SteelOutline(DataUtil::GetDetector(gMint->GetJobC().Mom));
00174 }
00175
00176 void UserDisplayModule::AddTrack(const CandTrackHandle* cth)
00177 {
00178 UgliGeomHandle ugh = gMint->GetUgliGeomHandle();
00179 if (! ugh.IsValid()) {
00180 MSG("User",kWarning) << "Got invalid Ugli\n";
00181 return;
00182 }
00183
00184
00185 TIter titr(cth->GetDaughterIterator());
00186
00187 while (CandStripHandle* csh = dynamic_cast<CandStripHandle*>(titr())) {
00188 int plane = csh->GetPlane();
00189 int strip = csh->GetStrip();
00190 float charge = csh->GetCharge();
00191
00192 switch (csh->GetPlaneView()) {
00193 case PlaneView::kU:
00194 fUZview->Fill(plane,strip,charge);
00195 break;
00196 case PlaneView::kV:
00197 fVZview->Fill(plane,strip,charge);
00198 break;
00199 default:
00200 break;
00201 }
00202
00203 double radius = 4.0*Munits::centimeter;
00204 double x,y, u = cth->GetU(plane), v = cth->GetV(plane);
00205 ugh.uv2xy(u,v,x,y);
00206
00207 fUVview->cd();
00208 TEllipse* el = new TEllipse(x,y,radius,radius);
00209 el->Draw();
00210 fCleanup->Add(el);
00211 }
00212
00213 }
00214
00215 static void clear_hist(TH2D* hist)
00216 {
00217 hist->Reset();
00218 hist->GetXaxis()->UnZoom();
00219 hist->GetYaxis()->UnZoom();
00220 }
00221
00222 void UserDisplayModule::UpdateDisplay()
00223 {
00224 static TText* no_tracks = 0;
00225
00226 if (! no_tracks) {
00227 no_tracks = new TText(0.,0.,"No Tracks");
00228 no_tracks->SetTextSizePixels(100);
00229 no_tracks->SetTextColor(2);
00230 }
00231
00232 clear_hist(fUZview);
00233 clear_hist(fVZview);
00234 fUVview->Clear();
00235 fCleanup->Delete();
00236
00237 fUVview->cd();
00238 fSteelOutline->Draw();
00239
00240
00241 const CandTrackListHandle* ctlh = gMint->GetTracks();
00242
00243 if (ctlh && ctlh->GetNDaughters()) {
00244 typedef vector<const CandTrackHandle*> TrackVector_t;
00245 TrackVector_t tv = CDL2STLvector<const CandTrackHandle>(*ctlh);
00246 for (unsigned int ind = 0; ind < tv.size(); ++ind) {
00247 this->AddTrack(tv[ind]);
00248 }
00249 }
00250 else no_tracks->Draw();
00251
00252
00253 fUVview->Modified();
00254 fHistPad->cd(1);
00255 gPad->Modified();
00256 fHistPad->cd(2);
00257 gPad->Modified();
00258 fCanvas->Modified();
00259 fCanvas->Update();
00260 }
00261