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

DetectorView.cxx

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 #include <iostream>
00008 #include <vector>
00009 #include "TCanvas.h"
00010 #include "TPad.h"
00011 #include "TH3F.h"
00012 #include "TLine.h"
00013 #include "TBox.h"
00014 #include "TPolyLine3D.h"
00015 #include "RawData/RawDigit.h"
00016 #include "RawData/DAQHeader.h"
00017 #include "EventDataModel/EventHandle.h"
00018 #include "EventDisplayBase/IoModule.h"
00019 #include "EventDisplayBase/View3D.h"
00020 #include "EventDisplay/DetectorView.h"
00021 #include "EventDisplay/DetectorViewOption.h"
00022 #include "EventDisplay/Style.h"
00023 #include "Geometry/Geometry.h"
00024 #include "Geometry/PlaneGeo.h"
00025 #include "Geometry/CellGeo.h"
00026 #include "RecoBase/PlaneCluster.h"
00027 #include "RecoBase/TrackBase.h"
00028 #include "Simulation/MCTruth.h"
00029 #include "Simulation/Particle.h"
00030 #include "Simulation/ParticleList.h"
00031 
00032 using namespace evd;
00033 using namespace recobase;
00034 
00035 DetectorView::DetectorView(TGMainFrame* mf) : evdb::Canvas(mf) 
00036 {
00037   edm::EventHandle& evt = evdb::IoModule::Instance()->GetEvent();
00038   std::vector<const rawdata::DAQHeader*> header;
00039   short int det = rawdata::kFar;
00040   try{ evt.DAQ().Get("./",header); }
00041   catch(edm::Exception e){
00042     std::cerr << "Error retrieving daq header, while looking "<<
00043       "in DetectorView::DetectorView(), using default fardet geometry" << std::endl;
00044   }
00045   if(header.size() > 0) det = header[0]->DetId();
00046   geo::Geometry *geom = &geo::Geometry::Instance(evt.Header().Run(),det);
00047 
00048   evdb::Canvas::fCanvas->cd();
00049 
00050   f3DviewPad = new TPad("fYviewPad","Yview",0.0,0.0,0.75,0.9);
00051   f3DviewPad->Draw();
00052 
00053   f3DviewPad->cd();
00054   f3DviewHisto = new TH3F("f3DviewHisto",";z (cm);x (cm); y(cm)",
00055                           200,0.,geom->DetLength(),
00056                           32,-geom->DetHalfWidth(), geom->DetHalfWidth(),
00057                           32,-geom->DetHalfHeight(),geom->DetHalfHeight());
00058   f3DviewHisto->Draw();
00059 
00060   f3Dview = new evdb::View3D();
00061 
00062   fOption = &DetectorViewOption::Instance();
00063 }
00064 
00065 //......................................................................
00066 
00067 DetectorView::~DetectorView() { }
00068 
00069 //......................................................................
00070 
00071 void DetectorView::DrawMCTruth(edm::EventHandle& evt)
00072 {
00073   double zmin = 1e20, zmax = -1e20;
00074   double xmin = 1e20, xmax = -1e20;
00075   double ymin = 1e20, ymax = -1e20;
00076   
00077   std::vector<const sim::MCTruth*> mctruth;
00078   
00079   try { evt.MC().Get(".",mctruth); }
00080   catch (edm::Exception e) { }
00081   
00082   for (int i=0; i<mctruth[0]->NParticles(); ++i) {
00083     const TParticle& p = mctruth[0]->GetParticle(i);
00084     
00085     double xyz0[3];
00086     xyz0[0] = p.Vx();
00087     xyz0[1] = p.Vy();
00088     xyz0[2] = p.Vz();
00089     
00090     double xyz1[3];
00091     // Incident particles
00092     if (p.GetStatusCode()==0) {
00093       xyz1[0] = xyz0[0] - p.Px()/2E-3;
00094       xyz1[1] = xyz0[1] - p.Py()/2E-3;
00095       xyz1[2] = xyz0[2] - p.Pz()/2E-3;
00096     }
00097     // Particles to be tracked
00098     else if (p.GetStatusCode()==1) {
00099       xyz1[0] = xyz0[0] + p.Px()/2E-3;
00100       xyz1[1] = xyz0[1] + p.Py()/2E-3;
00101       xyz1[2] = xyz0[2] + p.Pz()/2E-3;
00102     }
00103     // Intermediate states
00104     else continue;
00105     
00106     // Find limits of display
00107     if (xyz0[0]<xmin) xmin = xyz0[0];
00108     if (xyz1[0]<xmin) xmin = xyz1[0];
00109     if (xyz0[0]>xmax) xmax = xyz0[0];
00110     if (xyz1[0]>xmax) xmax = xyz1[0];
00111     if (xyz0[1]<ymin) ymin = xyz0[1];
00112     if (xyz1[1]<ymin) ymin = xyz1[1];
00113     if (xyz0[1]>ymax) ymax = xyz0[1];
00114     if (xyz1[1]>ymax) ymax = xyz1[1];
00115     if (xyz0[2]<zmin) zmin = xyz0[2];
00116     if (xyz1[2]<zmin) zmin = xyz1[2];
00117     if (xyz0[2]>zmax) zmax = xyz0[2];
00118     if (xyz1[2]>zmax) zmax = xyz1[2];
00119     
00120     int ic = Style::ColorFromPDG(p.GetPdgCode());
00121     int iw = Style::LineWidthFromPDG(p.GetPdgCode());
00122     int is = Style::LineStyleFromPDG(p.GetPdgCode());
00123 
00124     TPolyLine3D& line = f3Dview->AddPolyLine3D(100,ic,iw,is);
00125     double dz = 2.;
00126     int npnt = (int)((xyz1[2]-xyz0[2])/dz); // 2 cm step sizes
00127     double dxdz = p.Px()/p.Pz();
00128     double dydz = p.Py()/p.Pz();
00129     double x, y, z;
00130     for (int i=0; i<npnt; ++i) {
00131       x = xyz0[0] + i*dz*dxdz;
00132       y = xyz0[1] + i*dz*dydz;
00133       z = xyz0[2] + i*dz;
00134       line.SetPoint(i,z,x,y);
00135     }
00136   }
00137 
00138   std::vector<const sim::ParticleList*> particleList;
00139   try {
00140     evt.DetSim().Get(".",particleList);
00141   }
00142   catch (edm::Exception e) { }
00143   
00144   std::cerr << "Interactions in this record=" 
00145             << particleList.size()<<std::endl;
00146   
00147   for (unsigned int iev=0; iev<particleList.size(); iev++) {
00148     std::vector<sim::Particle> particles=particleList[iev]->fParticles;
00149     std::cerr <<"Event "<<iev<<" has "<<particles.size()
00150               <<" particles."<<std::endl;
00151     for (unsigned int i=0; i<particles.size(); ++i) {
00152       std::cerr << particles[i].PdgCode()<<" ";
00153       if ( (i>0 && i%10==0) || i==particles.size()-1) std::cerr << std::endl;
00154     }
00155   }
00156 
00157   // Force the x and y views to have the same vertical scale
00158   if (xmax-xmin > ymax-ymin) {
00159     double tmp = 0.5*((xmax-xmin)-(ymax-ymin));
00160     ymax += tmp;
00161     ymin -= tmp;
00162   }
00163   else {
00164     double tmp = 0.5*((ymax-ymin)-(xmax-xmin));
00165     xmax += tmp;
00166     xmin -= tmp;
00167   }
00168   xmin -= 100;  xmax += 100;
00169   ymin -= 100;  ymax += 100;
00170   zmin -= 100;  zmax += 100;
00171   
00172   f3DviewHisto->GetXaxis()->SetRangeUser(zmin,zmax);
00173   f3DviewHisto->GetYaxis()->SetRangeUser(xmin,xmax);
00174   f3DviewHisto->GetZaxis()->SetRangeUser(ymin,ymax);
00175 
00176 }
00177 
00178 //......................................................................
00179 
00180 void DetectorView::Draw(const char* /*opt*/) 
00181 {
00182   edm::EventHandle& evt = evdb::IoModule::Instance()->GetEvent();
00183    
00184   std::vector<const rawdata::DAQHeader*> header;
00185   short int det = rawdata::kFar;
00186   try{ evt.DAQ().Get("./",header); }
00187   catch(edm::Exception e){
00188     std::cerr << "Error retrieving daq header, while looking "<<
00189       "in DetectorView::Draw(), using default fardet geometry" << std::endl;
00190   }
00191   if(header.size() > 0) det = header[0]->DetId();
00192   fGeo = &geo::Geometry::Instance(evt.Header().Run(),det);
00193   
00194   f3Dview->Clear();
00195 
00196   if (fOption->fDrawMCTruthVectors)
00197     DrawMCTruth(evt);
00198 
00199   f3DviewPad->cd();
00200   f3DviewHisto->Draw();
00201   f3Dview->Draw();
00202   
00203   evdb::Canvas::fCanvas->Update();
00204 }
00205 

Generated on Mon Dec 1 02:35:17 2008 for NOvA Offline by  doxygen 1.3.9.1