Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

TkrDigiAlg.cpp

Go to the documentation of this file.
00001 #define GlastDigi_TkrDigiAlg_CPP 
00002 
00003 
00004 #include <list>
00005 
00006 
00007 // Include files
00008 #include "TkrDigiAlg.h"
00009 
00011 #include "GaudiKernel/MsgStream.h"
00012 #include "GaudiKernel/AlgFactory.h"
00013 #include "GaudiKernel/IDataProviderSvc.h"
00014 #include "GaudiKernel/SmartDataPtr.h"
00015 
00017 #include "GlastEvent/TopLevel/EventModel.h"
00018 #include "GlastEvent/TopLevel/Event.h"
00019 #include "GaudiKernel/ObjectVector.h"
00020 
00022 #include "GlastEvent/TopLevel/IrfEvent.h"
00023 
00025 //#include "xml/IFile.h"
00026 
00028 #include "instrument/SiTracker.h"
00029 
00031 static const AlgFactory<TkrDigiAlg>  Factory;
00032 const IAlgFactory& TkrDigiAlgFactory = Factory;
00033 
00034 //------------------------------------------------------------------------------
00037 TkrDigiAlg::TkrDigiAlg(const std::string& name, ISvcLocator* pSvcLocator) :
00038 Algorithm(name, pSvcLocator) 
00039 {
00040     return;
00041 }
00042 
00043 
00044 //------------------------------------------------------------------------------
00049 StatusCode TkrDigiAlg::initialize() 
00050 {    
00051     MsgStream log(msgSvc(), name());
00052     log << MSG::INFO << "initialize" << endreq;
00053     
00054     nTrayMax = SiTracker::numTrays();
00055 
00056     if (nTrayMax <= 0) nTrayMax = 18;
00057 
00058     return StatusCode::SUCCESS;
00059 }
00060 
00061 
00062 //------------------------------------------------------------------------------
00065 StatusCode TkrDigiAlg::execute()
00066 {
00067     
00068     StatusCode  sc = StatusCode::SUCCESS;
00069     MsgStream   log( msgSvc(), name() );
00070     log << MSG::INFO << "execute" << endreq;
00071 
00072     //Create the collection of digi objects - will be empty at this point
00073     TkrDigiCol*  pTkrDigi   = new TkrDigiCol;
00074 
00075     //Look to see if the TdGlastData object is in the TDS
00076     SmartDataPtr<TdGlastData> glastData(eventSvc(), "/Event/TdGlastData");
00077     
00078     //If TdGlastData doesn't exist, presume that SiLayers does...
00079     if( 0 == glastData) 
00080     { 
00081         log << MSG::DEBUG << "could not find \""<< "/Event/TdGlastData" <<"\"" << endreq;
00082 
00083         //Look to see if the TbRecon format data exists (SiLayers)
00084         SiLayers*    pSiLayers  = SmartDataPtr<SiLayers>(eventSvc(),"/Event/TkrRecon/SiLayers");
00085 
00086         if (pSiLayers != 0)
00087         {
00088             fillTkrDigis(pSiLayers, pTkrDigi);
00089         }
00090         else
00091         {
00092             log << MSG::ERROR << "no TKR data is available" << endreq;
00093             return StatusCode::FAILURE;
00094         }
00095     }
00096     else
00097     //Fill the TkrDigis from the IRF data
00098     {
00099         TdGlastData* pGlastData = glastData;
00100         fillTkrDigis((const SiData*)pGlastData->getSiData(), pTkrDigi);
00101     }
00102 
00103     //Take care of insuring that data area has been created
00104     DataObject* pNode = 0;
00105     sc = eventSvc()->retrieveObject( "/Event/TkrRecon", pNode);
00106 
00107     if (sc.isFailure())
00108     {
00109         sc = eventSvc()->registerObject("/Event/TkrRecon",new DataObject);
00110         if( sc.isFailure() ) 
00111         {
00112             return sc;
00113         }
00114     }
00115 
00118     sc = eventSvc()->registerObject("/Event/TkrRecon/TkrDigis", pTkrDigi);
00119 
00120     if (sc != StatusCode::SUCCESS) log << MSG::INFO << "Failed to register TKR digi vector" << endreq;
00121 
00125 
00126     return sc;
00127 }
00128 
00129 
00130 //------------------------------------------------------------------------------
00131 /*
00132 Finalize is called once at the end of event processing.
00133 Any cleanup to occur - will occur here.
00134 */
00135 StatusCode TkrDigiAlg::finalize() {
00136     
00137     MsgStream log(msgSvc(), name());
00138     log << MSG::INFO << "finalize" << endreq;
00139     
00140     return StatusCode::SUCCESS;
00141 }
00142 
00143 
00144 //------------------------------------------------------------------------------
00145 /*
00146 This routine is used to fill the TkrDigi's depending upon what kind of 
00147 input data we have... Here we fill from IRF format data
00148 */
00149 void TkrDigiAlg::fillTkrDigis(const SiData* pSiData, TkrDigiCol* pTkrDigi)
00150 {
00151     // loop in number of layers - conversion to planes!
00152     int nTrays   = pSiData->nTrays(SiData::X);
00153 
00154     while (nTrays--) 
00155     {
00156         fillALayer(pSiData, SiData::X, nTrays, pTkrDigi);
00157         fillALayer(pSiData, SiData::Y, nTrays, pTkrDigi);
00158     }
00159 
00160     return;
00161 }
00162 
00163 //------------------------------------------------------------------------------
00164 /*
00165 This function does the actual work of filling TkrDigi's from the SiData 
00166 objects for a given layer and X-Y view. 
00167 */
00168 
00169 void TkrDigiAlg::fillALayer(const SiData* pSiData, enum SiData::Axis view, int trayIdx, TkrDigiCol* pTkrDigi)
00170 {
00171     int layerIdx = pSiData->layerNum(view, trayIdx);
00172     int ToT[2] = {0,0};
00173     std::list<unsigned int> hitStripList;
00174 
00175     //Start with the X view
00176     //How many hit strips this view?
00177     int nHitStrips = pSiData->nHits(view, trayIdx);
00178 
00179     //Clear the hit strip list
00180     hitStripList.clear();
00181 
00182     //Extract the hit strip info and fill the list with tower and strip info
00183     while(nHitStrips--)
00184     {
00185         unsigned int towerId  = pSiData->moduleId(view, trayIdx, nHitStrips);
00186         unsigned int stripId  = pSiData->hitId(view, trayIdx, nHitStrips);
00187 
00188         unsigned int hitStrip = ((towerId & 0xFF) << 16) | (stripId & 0xFFFF);
00189             
00190         hitStripList.push_back(hitStrip);
00191     }
00192 
00193     //Sort the list
00194     hitStripList.sort();
00195 
00196     //Now go back and extract the hit strip info by tower
00197     int      lastTowerId = -9999;
00198     TkrDigi* pDigi       = 0;
00199 
00200     std::list<unsigned int>::iterator pHitList = hitStripList.begin();
00201 
00202     nHitStrips = hitStripList.size();
00203 
00204     //Now go through the properly sorted list of strip hits and make digis
00205     while(nHitStrips--)
00206     {
00207         unsigned int hitStrip = *pHitList++;
00208 
00209         unsigned int towerId  = (hitStrip >> 16) & 0xFF;
00210         unsigned int stripId  = (hitStrip & 0xFFFF);
00211 
00212         //Have we encountered a new tower?
00213         if (towerId != lastTowerId)
00214         {
00215             pDigi       = new TkrDigi(layerIdx, view, towerId, ToT);
00216             lastTowerId = towerId;
00217 
00218             pTkrDigi->push_back(pDigi);
00219         }
00220 
00221         //Copy the hits into TkrDigi...
00222         pDigi->addHit(stripId);
00223     }
00224 
00225     return;
00226 }
00227 
00228 
00229 //------------------------------------------------------------------------------
00230 /*
00231 This routine is used to fill the TkrDigi's depending upon what kind of 
00232 input data we have... Here we fill from Test Beam format data
00233 */
00234 void TkrDigiAlg::fillTkrDigis(SiLayers* pSiLayers, TkrDigiCol* pTkrDigi)
00235 {
00236 
00237     // loop in number of layers - conversion to planes!
00238     int nlayers = pSiLayers->num();
00239 
00240     for (int ilayer = 0; ilayer < nlayers; ilayer++) {
00241         SiLayer* layer  = pSiLayers->Layer(ilayer);
00242         
00243         int      klayer = layer->layer();
00244         int      iview  = layer->view();
00245         int      nHits  = layer->nstrips();
00246         int      tower  = 0;
00247         int      tot[2] = {0,0};
00248 
00249         //Create the new TkrDigi object
00250         TkrDigi* pDigi  = new TkrDigi(klayer, iview, tower, tot);
00251         
00252         //Copy the hits into TkrDigi...
00253         while(nHits--) pDigi->addHit(layer->idstrip(nHits));
00254 
00255         pTkrDigi->push_back(pDigi);
00256    }
00257 
00258     return;
00259 }
00260 

Generated at Wed Nov 21 12:22:37 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000