00001
00002
00003
00004 #include "CalRecon/CalIRFAlg.h"
00005 #include "CalRecon/CalRecLogs.h"
00006 #include "CalRecon/CalDetGeo.h"
00007 #include "GaudiKernel/MsgStream.h"
00008 #include "GaudiKernel/AlgFactory.h"
00009 #include "GaudiKernel/IDataProviderSvc.h"
00010 #include "GaudiKernel/SmartDataPtr.h"
00011
00012 #include "GlastSvc/GlastDetSvc/IGlastDetSvc.h"
00013
00014
00015 #include "GlastEvent/data/TdGlastData.h"
00016 #include "data/CsIData.h"
00017 #include "gui/DisplayControl.h"
00018 #include "GuiSvc/IGuiSvc.h"
00019 #include "gui/GuiMgr.h"
00020
00021
00022 static const AlgFactory<CalIRFAlg> Factory;
00023 const IAlgFactory& CalIRFAlgFactory = Factory;
00024
00025
00026
00029
00030 Algorithm(name, pSvcLocator), m_detSvc(0) {
00031 }
00032
00033
00034
00041 StatusCode CalIRFAlg::initialize() {
00042
00043 MsgStream log(msgSvc(), name());
00044 log << MSG::INFO << "initialize" << endreq;
00045
00046
00047
00048
00049 setProperties();
00050
00051
00052 StatusCode sc = service("CalGeometrySvc", m_CalGeo);
00053
00054 if (!sc.isSuccess ()){
00055 log << MSG::ERROR << "Couldn't find the CalGeometrySvc!" << endreq;
00056 return sc;
00057 }
00058
00059
00060 sc = service("GlastDetSvc", m_detSvc);
00061
00062
00063 if (!sc.isSuccess ()){
00064 log << MSG::ERROR << "Couldn't find the GlastDetSvc!" << endreq;
00065 }
00066
00067
00068
00069 return sc;
00070 }
00071
00072
00073
00074 StatusCode CalIRFAlg::execute() {
00075
00076 StatusCode sc = StatusCode::SUCCESS;
00077 MsgStream log( msgSvc(), name() );
00078 log << MSG::INFO << "execute" << endreq;
00079
00080 int nModX = m_CalGeo->numModulesX();
00081 int nModY = m_CalGeo->numModulesY();
00082 int nLogs = m_CalGeo->numLogs();
00083 int nLayers = m_CalGeo->numLayers();
00084 int nViews = m_CalGeo->numViews();
00085 CalRecLogs* crl = new CalRecLogs(nModX,nModY,nLogs,nLayers,nViews);
00086 DataObject* pnode=0;
00087
00088 sc = eventSvc()->retrieveObject( "/Event/CalRecon", pnode );
00089
00090 if( sc.isFailure() ) {
00091 sc = eventSvc()->registerObject("/Event/CalRecon",new DataObject);
00092 if( sc.isFailure() ) {
00093
00094 log << MSG::ERROR << "Could not create CalRecon directory" << endreq;
00095 return sc;
00096 }
00097 }
00098 sc = eventSvc()->registerObject("/Event/CalRecon/CalRecLogs",crl);
00099
00100
00101
00102
00103
00104 SmartDataPtr<TdGlastData> glastData(eventSvc(),"/Event/TdGlastData");
00105
00106 if( 0==glastData) {
00107 log << MSG::ERROR << "could not find \""<< "/Event/TdGlastData" <<"\"" << endreq;
00108 return StatusCode::FAILURE;
00109 }
00110
00111
00112 const CsIData* csi = glastData->getCsIData();
00113
00114
00115
00116
00117
00118
00119 double latt = m_CalGeo->light_att();
00120 double slope = (2-latt)/latt;
00121 double ene = 0.0;
00122 for (int l=0; l < m_CalGeo->numLayers();l++){
00123 for (int v=0; v< m_CalGeo->numViews(); v++){
00124 CalDetGeo::axis view = CalDetGeo::makeAxis(v);
00125 int ilayer = l*(m_CalGeo->numViews())+v;
00126 int nhits = csi->nHits(ilayer);
00127 if(nhits == 0)continue;
00128 for ( int ihit = 0; ihit < nhits; ihit++){
00129 idents::ModuleId mod = csi->moduleId(ilayer, ihit);
00130 idents::XtalId xtalid = csi->xtalId(ilayer,ihit);
00131 int icol = xtalid.xtal()-1;
00132
00133
00134 if(v == 1) icol = m_CalGeo->numLogs()-1 - icol;
00135
00136 float enePos = csi->Rresp(ilayer,ihit)*1000.;
00137 float eneNeg = csi->Lresp(ilayer,ihit)*1000.;
00138 ene += (enePos+eneNeg)/2;
00139 CalRecLog* recLog = crl->getLogID(CalLogID::ID(l,view,icol,mod));
00140 recLog->setNegEnergy(eneNeg);
00141 recLog->setPosEnergy(enePos);
00142 CalDetGeo geoLog = m_CalGeo->getLog(l,view,icol,mod);
00143
00144 Point pCenter = geoLog.position();
00145 Point pSize = geoLog.size();
00146
00147 double xdir = 0.;
00148 double ydir = 0.;
00149 ydir = (view == CalDetGeo::X? pSize.y() : 0);
00150 xdir = (view == CalDetGeo::Y? pSize.x() : 0);
00151
00152 Vector dirLog(xdir,ydir,0.);
00153 double asym = recLog->asymmetry();
00154
00155 Point pLog = pCenter+dirLog*asym*slope;
00156 ;
00157
00158 recLog->setPosition(pLog);
00159
00160 }
00161 }
00162 }
00163
00164
00165
00166
00167 return sc;
00168 }
00169
00170
00171
00172 StatusCode CalIRFAlg::finalize() {
00173
00174 MsgStream log(msgSvc(), name());
00175 log << MSG::INFO << "finalize" << endreq;
00176
00177 return StatusCode::SUCCESS;
00178 }
00179
00180
00181
00182
00183