00001
00002
00003
00004
00005
00006
00007 #include "EventDisplay/Display3D.h"
00008 #include <vector>
00009 #include "TCanvas.h"
00010 #include "TView3D.h"
00011 #include "TGLViewer.h"
00012 #include "TMarker3DBox.h"
00013 #include "TPolyLine3D.h"
00014 #include "TPolyMarker3D.h"
00015 #include "TView.h"
00016 #include "TH1F.h"
00017 #include "EventDisplayBase/IoModule.h"
00018 #include "EventDisplayBase/View3D.h"
00019 #include "EventDataModel/edm.h"
00020 #include "Geometry/geo.h"
00021 #include "RawData/RawDigit.h"
00022 #include "RawData/DAQHeader.h"
00023 #include "Simulation/FLSHitList.h"
00024 #include "Simulation/FLSHit.h"
00025 #include "EventDisplay/Style.h"
00026 #include "EventDisplay/ColorScale.h"
00027 using namespace evd;
00028
00029 Display3D::Display3D(TGMainFrame* mf) :
00030 evdb::Canvas(mf),
00031 fQscale(new ColorScale(0.0, 512.0, kRainbow, kSqrt)),
00032 fPad3D(0),
00033 fTimePad(0),
00034 fGLViewer3D(0)
00035 {
00036 evdb::Canvas::fCanvas->cd();
00037
00038 fTimePad = new TPad("fTimePad","Hits vs. Time",0.7,0.7,1.0,1.0,0);
00039 fTimePad->Draw();
00040
00041 fChargePad = new TPad("fChargePad","Hits vs. Charge",0.7,0.4,1.0,0.7);
00042 fChargePad->SetLogx();
00043 fChargePad->SetLogy();
00044 fChargePad->Draw();
00045
00046 fPad3D = new TPad("fPad3D","NOvA Event Display",0.0,0.0,0.7,0.7,0);
00047 fPad3D->Draw();
00048
00049 fView = new evdb::View3D();
00050
00051 fXlo = 0.0;
00052 fXhi = 0.0;
00053 fYlo = 0.0;
00054 fYhi = 0.0;
00055 fZlo = 0.0;
00056 fZhi = 0.0;
00057 fTlo = -10.0;
00058 fThi = +20.0;
00059
00060 this->BookHistograms();
00061 }
00062
00063
00064
00065 void Display3D::BookHistograms()
00066 {
00067 fRawTHisto = new TH1F("fRawTHisto",";usec;hits",300,-10.0,20.0);
00068 this->StdHistoOpts(fRawTHisto);
00069
00070 fMCTHisto = new TH1F("fMCTHisto",";usec;hits",300,-10.0,20.0);
00071 this->StdHistoOpts(fMCTHisto);
00072 fMCTHisto->SetLineColor(2);
00073
00074 fRawQHisto = new TH1F("fRawQHisto",";'MeV';hits",200,0.0,100.0);
00075 this->StdHistoOpts(fRawQHisto);
00076
00077 fMCQHisto = new TH1F("fMCQHisto",";MeV;hits",200,0.0,100.0);
00078 this->StdHistoOpts(fMCQHisto);
00079 fMCQHisto->SetLineColor(2);
00080 }
00081
00082
00083
00084 void Display3D::StdHistoOpts(TH1F* h)
00085 {
00086 h->SetLabelFont(42,"X");
00087 h->SetLabelFont(42,"Y");
00088 h->SetLabelSize(0.06,"X");
00089 h->SetLabelSize(0.06,"X");
00090
00091 h->SetTitleFont(52,"X");
00092 h->SetTitleFont(52,"Y");
00093 h->SetTitleSize(0.08,"X");
00094 h->SetTitleSize(0.08,"Y");
00095 h->SetTitleOffset(0.55,"X");
00096 h->SetTitleOffset(0.45,"Y");
00097
00098 h->GetXaxis()->SetNdivisions(510);
00099 h->GetYaxis()->SetNdivisions(505);
00100 }
00101
00102
00103
00104 Display3D::~Display3D()
00105 {
00106 delete fView; fView = 0;
00107 delete fPad3D; fPad3D = 0;
00108 }
00109
00110
00111
00112 void Display3D::Draw(const char* )
00113 {
00114
00115 if (fXlo == fXhi && fYlo == fYhi && fZhi == fZlo) {
00116 edm::EventHandle& evt = evdb::IoModule::Instance()->GetEvent();
00117 std::vector<const rawdata::DAQHeader*> header;
00118 short int det = rawdata::kFar;
00119 try{ evt.DAQ().Get("./",header); }
00120 catch(edm::Exception e){
00121 std::cerr << "Error retrieving daq header, while looking "<<
00122 "in Display3D::Draw()" << std::endl;
00123 }
00124 if(header.size() > 0) det = header[0]->DetId();
00125
00126 geo::Geometry& geom = geo::Geometry::Instance(evt.Header().Run(),det);
00127 fXlo = -geom.DetHalfWidth();
00128 fXhi = geom.DetHalfWidth();
00129 fYlo = -geom.DetHalfHeight();
00130 fYhi = geom.DetHalfHeight();
00131 fZlo = 0.0;
00132 fZhi = geom.DetLength();
00133 }
00134
00135
00136
00137 double fBombFac = 0.05;
00138 fBomb =
00139 (fXhi-fXlo)>(fYhi-fYhi) ? fBombFac*(fXhi-fXlo):fBombFac*(fYhi-fYlo);
00140
00141 fView->Clear();
00142 fRawTHisto->Reset();
00143 fMCTHisto-> Reset();
00144 fRawQHisto->Reset();
00145 fMCQHisto-> Reset();
00146
00147 this->DrawOutline();
00148 this->DrawMCHits();
00149 this->DrawRawData();
00150
00151 int irep = 0;
00152 fPad3D->Clear();
00153 fPad3D->cd();
00154 fView->Draw();
00155 if (fPad3D->GetView()==0) {
00156 double sz = 1600.0;
00157 double rmin[] = {-sz,-sz,2500.0-sz};
00158 double rmax[] = { sz, sz,2500.0+sz};
00159 TView3D* v = new TView3D(1,rmin,rmax);
00160 v->SetPerspective();
00161 v->SetView(226.0,226.0,135.0,irep);
00162 fPad3D->SetView(v);
00163 }
00164 if (fGLViewer3D==0) {
00165 fGLViewer3D = (TGLViewer*)fPad3D->GetViewer3D("ogl");
00166 fGLViewer3D->SetClearColor(kWhite);
00167 fGLViewer3D->PreferLocalFrame();
00168 fGLViewer3D->SetResetCamerasOnUpdate(0);
00169 }
00170 else {
00171 fPad3D->GetViewer3D()->PadPaint(fPad3D);
00172 }
00173 fPad3D->Update();
00174
00175 fTimePad->Clear();
00176 fTimePad->cd();
00177 this->SetGoodMax(fRawTHisto,fMCTHisto);
00178 fRawTHisto->Draw();
00179 fMCTHisto->Draw("same");
00180 fTimePad->Update();
00181
00182 fChargePad->Clear();
00183 fChargePad->cd();
00184 this->SetGoodMax(fRawQHisto,fMCQHisto);
00185 fRawQHisto->Draw();
00186 fMCQHisto->Draw("same");
00187 fChargePad->Update();
00188 }
00189
00190
00191
00192 void Display3D::SetGoodMax(TH1F* h1, TH1F* h2)
00193 {
00194 if (h2->GetMaximum()>h1->GetMaximum()) {
00195 h1->SetMaximum(1.05*h2->GetMaximum());
00196 }
00197 }
00198
00199
00200
00201 void Display3D::DrawOutline()
00202 {
00203 int i, is;
00204 int cont;
00205 double x, y, z;
00206 double x0 = 0.5*(fXlo+fXhi);
00207 double y0 = 0.5*(fYlo+fYhi);
00208 double z0 = 0.5*(fZlo+fZhi);
00209 double dx = 100.0;
00210 double dy = 100.0;
00211 double dz = 100.0;
00212 int c = kBlue-10;
00213 int w = 1;
00214 int s = 1;
00215
00216 for (cont=1, i=0; cont==1 ; ++i) {
00217 cont = 0;
00218 for (is=-1; is<=1; is += 2) {
00219 x = x0+is*i*dx;
00220 if (x>=fXlo && x<=fXhi) {
00221 TPolyLine3D& p = fView->AddPolyLine3D(0,c,w,s);
00222 p.SetPoint(0,x,fYhi+fBomb,fZlo);
00223 p.SetPoint(1,x,fYhi+fBomb,fZhi);
00224 cont = 1;
00225 }
00226 }
00227 }
00228
00229 for (cont=1, i=0; cont==1 ; ++i) {
00230 cont = 0;
00231 for (is=-1; is<=1; is += 2) {
00232 y = y0+is*i*dy;
00233 if (y>=fYlo && y<=fYhi) {
00234 TPolyLine3D& p = fView->AddPolyLine3D(0,c,w,s);
00235 p.SetPoint(0,fXhi+fBomb,y,fZlo);
00236 p.SetPoint(1,fXhi+fBomb,y,fZhi);
00237 cont = 1;
00238 }
00239 }
00240 }
00241
00242 for (cont=1, i=0; cont==1 ; ++i) {
00243 cont = 0;
00244 for (is=-1; is<=1; is += 2) {
00245 z = z0+is*i*dz;
00246 if (z>=fZlo && z<=fZhi) {
00247 TPolyLine3D& p1 = fView->AddPolyLine3D(0,c,w,s);
00248 p1.SetPoint(0,fXhi+fBomb,fYlo,z);
00249 p1.SetPoint(1,fXhi+fBomb,fYhi,z);
00250
00251 TPolyLine3D& p2 = fView->AddPolyLine3D(0,c,w,s);
00252 p2.SetPoint(0,fXlo,fYhi+fBomb,z);
00253 p2.SetPoint(1,fXhi,fYhi+fBomb,z);
00254 cont = 1;
00255 }
00256 }
00257 }
00258
00259 TPolyLine3D& p1 = fView->AddPolyLine3D(0,c,w,s);
00260 p1.SetPoint(0,fXlo-fBomb,fYlo,fZlo);
00261 p1.SetPoint(1,fXlo-fBomb,fYhi,fZlo);
00262 p1.SetPoint(2,fXlo-fBomb,fYhi,fZhi);
00263 p1.SetPoint(3,fXlo-fBomb,fYlo,fZhi);
00264 p1.SetPoint(4,fXlo-fBomb,fYlo,fZlo);
00265
00266 TPolyLine3D& p3 = fView->AddPolyLine3D(0,c,w,s);
00267 p3.SetPoint(0,fXhi+fBomb,fYlo,fZlo);
00268 p3.SetPoint(1,fXhi+fBomb,fYhi,fZlo);
00269 p3.SetPoint(2,fXhi+fBomb,fYhi,fZhi);
00270 p3.SetPoint(3,fXhi+fBomb,fYlo,fZhi);
00271 p3.SetPoint(4,fXhi+fBomb,fYlo,fZlo);
00272
00273 TPolyLine3D& p2 = fView->AddPolyLine3D(0,c,w,s);
00274 p2.SetPoint(0,fXlo,fYlo-fBomb,fZlo);
00275 p2.SetPoint(1,fXhi,fYlo-fBomb,fZlo);
00276 p2.SetPoint(2,fXhi,fYlo-fBomb,fZhi);
00277 p2.SetPoint(3,fXlo,fYlo-fBomb,fZhi);
00278 p2.SetPoint(4,fXlo,fYlo-fBomb,fZlo);
00279
00280 TPolyLine3D& p4 = fView->AddPolyLine3D(0,c,w,s);
00281 p4.SetPoint(0,fXlo,fYhi+fBomb,fZlo);
00282 p4.SetPoint(1,fXhi,fYhi+fBomb,fZlo);
00283 p4.SetPoint(2,fXhi,fYhi+fBomb,fZhi);
00284 p4.SetPoint(3,fXlo,fYhi+fBomb,fZhi);
00285 p4.SetPoint(4,fXlo,fYhi+fBomb,fZlo);
00286 }
00287
00288
00289
00290 void Display3D::DrawMCHits()
00291 {
00292 edm::EventHandle& evt = evdb::IoModule::Instance()->GetEvent();
00293 std::vector<const rawdata::DAQHeader*> header;
00294 short int det = rawdata::kFar;
00295 try{ evt.DAQ().Get("./",header); }
00296 catch(edm::Exception e){
00297 std::cerr << "Error retrieving daq header, while looking "<<
00298 "in Display3D::DrawMCHits(), using default fardet geometry" << std::endl;
00299 }
00300 if(header.size() > 0) det = header[0]->DetId();
00301
00302 geo::Geometry& geom = geo::Geometry::Instance(evt.Header().Run(),det);
00303
00304 std::vector<const sim::FLSHitList*> hitlist;
00305 try { evt.DetSim().Get(".",hitlist); }
00306 catch (...) { return; }
00307
00308 for (unsigned int i=0; i<hitlist.size(); ++i) {
00309 for (unsigned int j=0; j<hitlist[i]->fHits.size(); ++j) {
00310 const sim::FLSHit& hit = hitlist[i]->fHits[j];
00311
00312
00313 fMCQHisto->Fill(hit.fEdep*1.0E3);
00314 fMCTHisto->Fill(hit.fT*1.0E6);
00315
00316 int c;
00317 double sz;
00318 double lpos[3], wpos[3];
00319
00320 lpos[0] = 0.5*(hit.fEntryX+hit.fExitX);
00321 lpos[1] = 0.5*(hit.fEntryY+hit.fExitY);
00322 lpos[2] = 0.5*(hit.fEntryZ+hit.fExitZ);
00323 geom.Plane(hit.fPlaneId).Cell(hit.fCellId).LocalToWorld(lpos,wpos);
00324
00325
00326
00327 sz = pow(1.0E0+1.E5*hit.fEdep,0.33);
00328 c = Style::ColorFromPDG(hit.fPDG);
00329 TPolyMarker3D& m = fView->AddPolyMarker3D(1,c,24,sz);
00330 m.SetPoint(0, wpos[0], wpos[1], wpos[2]);
00331 }
00332 }
00333 }
00334
00335
00336
00337 void Display3D::DrawRawData()
00338 {
00339 edm::EventHandle& evt = evdb::IoModule::Instance()->GetEvent();
00340 std::vector<const rawdata::DAQHeader*> header;
00341 short int det = rawdata::kFar;
00342 try{ evt.DAQ().Get("./",header); }
00343 catch(edm::Exception e){
00344 std::cerr << "Error retrieving daq header, while looking "<<
00345 "in Display3D::RawData(), using default fardet geometry" << std::endl;
00346 }
00347 if(header.size() > 0) det = header[0]->DetId();
00348 geo::Geometry& geom = geo::Geometry::Instance(evt.Header().Run(),det);
00349
00350 std::vector<const rawdata::RawDigit*> rd;
00351 try { evt.Raw().Get(".",rd); }
00352 catch (...) { return; }
00353
00354 double pos[3];
00355 double dx, dy, dz;
00356 for (unsigned int i=0; i<rd.size(); ++i) {
00357 const rawdata::RawDigit& r = (*rd[i]);
00358 const geo::PlaneGeo& p = geom.Plane(r.GetPlane());
00359 const geo::CellGeo& c = p.Cell(r.GetCell());
00360
00361 c.GetCenter(pos);
00362 for (int j=0; j<r.NADC(); ++j) {
00363 fRawTHisto->Fill(r.TDC(j));
00364 fRawQHisto->Fill(0.1*r.ADC(j));
00365 if (p.View()==geo::kX) {
00366 dx = c.HalfW();
00367 dy = 100.0*r.ADC(j)/1024.0;
00368 dz = c.HalfD();
00369 TMarker3DBox& m =
00370 fView->AddMarker3DBox(pos[0],fYhi+fBomb,pos[2], dx, dy, dz);
00371 m.SetLineColor(fQscale->GetColor(r.ADC(j)));
00372 }
00373 else if (p.View()==geo::kY) {
00374 dx = 100.0*r.ADC(j)/1024.0;
00375 dy = c.HalfW();
00376 dz = c.HalfD();
00377 TMarker3DBox& m =
00378 fView->AddMarker3DBox(fXhi+fBomb,pos[1],pos[2], dx, dy, dz);
00379 m.SetLineColor(fQscale->GetColor(r.ADC(j)));
00380 }
00381 else abort();
00382 }
00383 }
00384 }
00385