00001
00002
00004 #include "GaudiKernel/MsgStream.h"
00005 #include "GaudiKernel/AlgFactory.h"
00006 #include "GaudiKernel/IDataProviderSvc.h"
00007 #include "GaudiKernel/SmartDataPtr.h"
00008
00009
00010 #include "GuiSvc/IGuiSvc.h"
00011 #include "gui/DisplayControl.h"
00012 #include "gui/GuiMgr.h"
00013 #include "CalRecon/CsIClusters.h"
00014 #include "CalRecon/CalRecLogs.h"
00015 #include "CalRecon/ICalGeometrySvc.h"
00016 #include "CalRecon/CalDisplay.h"
00017
00018
00019
00020 static const AlgFactory<CalDisplay> Factory;
00021 const IAlgFactory& CalDisplayFactory = Factory;
00022
00023
00024 CalDisplay::CalDisplay(const std::string& name, ISvcLocator* pSvcLocator) :
00025 Algorithm(name, pSvcLocator)
00026 {
00027
00028 }
00029
00030
00031 class CalRep : public gui::DisplayRep {
00032 private:
00033 CalRecLogs** m_pp_crl;
00034 CsIClusterList** m_pp_cls;
00035 float m_logheight;
00036 float m_calZtop;
00037 float m_calZbottom;
00038
00039 public:
00040 CalRep(CalRecLogs** pp_crl, CsIClusterList** pp_cls, float logheight,
00041 float calZtop, float calZbottom)
00042 :m_pp_crl(pp_crl),m_pp_cls(pp_cls),m_logheight(logheight),
00043 m_calZtop(calZtop), m_calZbottom(calZbottom){}
00044 void update(){
00045
00046 const Point p0(0.,0.,0.);
00047 CalRecLogs* crl = *m_pp_crl;
00048 if(crl){
00049
00050
00051
00052 setColor("red");
00053
00054 int nLogs = crl->num();
00055 double emax = 0.;
00056 for (int jlog = 0; jlog < nLogs ; jlog++) {
00057 CalRecLog* recLog = crl->Log(jlog);
00058 double eneLog = recLog->energy();
00059 if(eneLog>emax)emax=eneLog;
00060 }
00061 if(emax>0){
00062 for (jlog = 0; jlog < nLogs ; jlog++) {
00063 CalRecLog* recLog = crl->Log(jlog);
00064 double eneLog = recLog->energy();
00065 if(eneLog>0.01*emax){
00066 Vector pLog = recLog->position() - p0;
00067 double x = pLog.x();
00068 double y = pLog.y();
00069 double z = pLog.z();
00070 double s = 0.45*m_logheight*eneLog/emax;
00071 moveTo(Point(x-s, y-s, z-s));
00072 lineTo(Point(x+s, y-s, z-s));
00073 lineTo(Point(x+s, y-s, z+s));
00074 lineTo(Point(x-s, y-s, z+s));
00075 lineTo(Point(x-s, y-s, z-s));
00076 moveTo(Point(x-s, y+s, z-s));
00077 lineTo(Point(x+s, y+s, z-s));
00078 lineTo(Point(x+s, y+s, z+s));
00079 lineTo(Point(x-s, y+s, z+s));
00080 lineTo(Point(x-s, y+s, z-s));
00081 moveTo(Point(x-s, y-s, z-s));
00082 lineTo(Point(x-s, y+s, z-s));
00083 moveTo(Point(x+s, y-s, z-s));
00084 lineTo(Point(x+s, y+s, z-s));
00085 moveTo(Point(x-s, y-s, z+s));
00086 lineTo(Point(x-s, y+s, z+s));
00087 moveTo(Point(x+s, y-s, z+s));
00088 lineTo(Point(x+s, y+s, z+s));
00089 }
00090 }
00091 }
00092 }
00093
00094
00095 CsIClusterList* cls = *m_pp_cls;
00096 if(cls){
00097 double s=0.1*m_logheight;
00098 setColor("blue");
00099 ICsICluster* cl = cls->Cluster(0);
00100 double energy_sum = cl->energySum();
00101 const std::vector<double>& eneLayer = cl->getEneLayer();
00102 const std::vector<Vector>& posLayer = cl->getPosLayer();
00103 for( int l=0;l<8;l++){
00104 double x=(posLayer[l]).x();
00105 double y=(posLayer[l]).y();
00106 double z=(posLayer[l]).z();
00107 moveTo(Point(x-s, y, z));
00108 lineTo(Point(x+s, y, z));
00109 moveTo(Point(x, y-s, z));
00110 lineTo(Point(x, y+s, z));
00111 moveTo(Point(x, y, z-s));
00112 lineTo(Point(x, y, z+s));
00113 }
00114
00115
00116
00117 setColor("green");
00118 double x = (cl->position()).x();
00119 double y = (cl->position()).y();
00120 double z = (cl->position()).z();
00121 moveTo(Point(x-s, y, z));
00122 lineTo(Point(x, y, z+s));
00123 lineTo(Point(x+s, y, z));
00124 lineTo(Point(x, y, z-s));
00125 lineTo(Point(x-s, y, z));
00126 lineTo(Point(x, y+s, z));
00127 lineTo(Point(x+s, y, z));
00128 lineTo(Point(x, y-s, z));
00129 lineTo(Point(x-s, y, z));
00130 moveTo(Point(x, y-s, z));
00131 lineTo(Point(x, y, z+s));
00132 lineTo(Point(x, y+s, z));
00133 lineTo(Point(x, y, z-s));
00134 lineTo(Point(x, y-s, z));
00135
00136 double dirX = (cl->direction()).x();
00137 double dirY = (cl->direction()).y();
00138 double dirZ = (cl->direction()).z();
00139
00140 if(dirZ >= -1. && dirZ != 0.){
00141
00142 double xTop = x+dirX*(m_calZtop-z)/dirZ;
00143 double yTop = y+dirY*(m_calZtop-z)/dirZ;
00144 double xBottom = x+dirX*(m_calZbottom-z)/dirZ;
00145 double yBottom = y+dirY*(m_calZbottom-z)/dirZ;
00146
00147 moveTo(Point(xTop,yTop,m_calZtop));
00148 lineTo(Point(xBottom,yBottom,m_calZbottom));
00149
00150
00151 }
00152
00153 }
00154 }
00155 };
00156
00157
00158 StatusCode CalDisplay::initialize()
00159 {
00160
00161 MsgStream log(msgSvc(), name());
00162 IGuiSvc* guiSvc = 0;
00163 StatusCode sc = service("GuiSvc", guiSvc);
00164
00165 m_crl = 0;
00166 m_cls = 0;
00167
00168 sc = service("CalGeometrySvc", m_CalGeo);
00169
00170 if(sc.isFailure())
00171 {
00172 log << MSG::ERROR << "ICalGeometrySvc could not be found" <<endreq;
00173 return sc;
00174 }
00175
00176
00177 float logheight = m_CalGeo->logHeight();
00178 float layerheight = m_CalGeo->layerHeight();
00179 int nlayers = m_CalGeo->numLayers()*m_CalGeo->numViews();
00180 float Z0 = m_CalGeo->Z0();
00181 float calZtop = Z0+(nlayers-1)*layerheight;
00182 float calZbottom = Z0;
00183
00184
00185
00186
00187 if (sc.isSuccess()) {
00188
00189 guiSvc->guiMgr()->display().add(
00190 new CalRep(&m_crl,&m_cls,logheight,calZtop,calZbottom), "Cal recon");
00191 }
00192
00193 return sc;
00194 }
00195
00196 StatusCode CalDisplay::execute()
00197 {
00198 StatusCode sc = StatusCode::SUCCESS;
00199 MsgStream log(msgSvc(), name());
00200
00201
00202 m_crl = SmartDataPtr<CalRecLogs>(eventSvc(),"/Event/CalRecon/CalRecLogs");
00203 if (m_crl == 0){ sc = StatusCode::FAILURE;
00204
00205 log << MSG::ERROR << "CalDisplay failed to access CalRecLogs" << endreq;
00206 return sc;
00207 } else { m_crl->setCalDisplay(this);}
00208
00209
00210 m_cls = SmartDataPtr<CsIClusterList>(eventSvc(),"/Event/CalRecon/CsIClusterList");
00211
00212 if (m_cls == 0){ sc = StatusCode::FAILURE;
00213
00214 log << MSG::ERROR << "CalDisplay failed to access CsIClusterList" << endreq;
00215 return sc;
00216 } else {m_cls->setCalDisplay(this);}
00217
00218 return sc;
00219 }
00220
00221