00001 #include "Stiostream.h"
00002 #include <stdexcept>
00003 #include <cmath>
00004 #include <stdio.h>
00005 #include "StEvent.h"
00006 #include "StEventTypes.h"
00007 #include "StDbUtilities/StTpcCoordinateTransform.hh"
00008 #include "StDbUtilities/StTpcLocalSectorCoordinate.hh"
00009 #include "StDbUtilities/StGlobalCoordinate.hh"
00010 #include "StTpcDb/StTpcDb.h"
00011 #include "Sti/Base/Factory.h"
00012 #include "Sti/StiHit.h"
00013 #include "Sti/StiHitContainer.h"
00014 #include "Sti/StiDetector.h"
00015 #include "Sti/StiDetectorBuilder.h"
00016 #include "StiTpcHitLoader.h"
00017 #include "Sti/StiHitTest.h"
00018 #include "Sti/StiKalmanTrackNode.h"
00019 #include "RTS/src/DAQ_TPX/tpxFCF_flags.h"
00020 #include "StDetectorDbMaker/St_tpcPadPlanesC.h"
00021
00022 StiTpcHitLoader::StiTpcHitLoader(): StiHitLoader<StEvent,StiDetectorBuilder>("TpcHitLoader"),
00023 _minRow(1), _maxRow(-1), _minSector(1), _maxSector(24) {}
00024
00025 StiTpcHitLoader::StiTpcHitLoader(StiHitContainer* hitContainer,
00026 Factory<StiHit>*hitFactory,
00027 StiDetectorBuilder * detector)
00028 : StiHitLoader<StEvent,StiDetectorBuilder>("TpcHitLoader",hitContainer,hitFactory,detector),
00029 _minRow(1), _maxRow(-1), _minSector(1), _maxSector(24) {}
00030
00031 void StiTpcHitLoader::loadHits(StEvent* source,
00032 Filter<StiTrack> * trackFilter,
00033 Filter<StiHit> * hitFilter)
00034 {
00035 Int_t debug = 0;
00036 _maxRow = St_tpcPadPlanesC::instance()->padRows();
00037 cout << "StiTpcHitLoader::loadHits(StEvent*) -I- Started" << endl;
00038 if (!_detector)
00039 throw runtime_error("StiTpcHitLoader::loadHits(StEvent*) - FATAL - _detector==0");
00040 if(!_hitContainer)
00041 throw runtime_error("StiTpcHitLoader::loadHits(StEvent*) - FATAL - _hitContainer==0");
00042
00043 StiDetector * detector;
00044 StiHit* stiHit;
00045 const StTpcHitCollection* tpcHits = source->tpcHitCollection();
00046 if (!tpcHits) return;
00047 UInt_t stiSector;
00048 UInt_t noHitsLoaded = 0;
00049 for (UInt_t sector=_minSector-1; sector<_maxSector; sector++) {
00050 #if 0
00051 stiSector = sector;
00052 #else
00053 if (sector<12) stiSector = sector;
00054 else stiSector = 11 - (sector-11)%12;
00055 #endif
00056 const StTpcSectorHitCollection* secHits = tpcHits->sector(sector);
00057 if (!secHits) {
00058 cout << "StiTpcHitLoader::loadHits(StEvent* source) -W- no hits for sector:"<<sector<<endl;
00059 break;
00060 }
00061 Float_t driftvel = 1e-6*gStTpcDb->DriftVelocity(sector+1);
00062 for (UInt_t row=_minRow-1; row<_maxRow; row++) {
00063
00064 const StTpcPadrowHitCollection* padrowHits = secHits->padrow(row);
00065 if (!padrowHits) break;
00066 const StSPtrVecTpcHit& hitvec = padrowHits->hits();
00067 detector = _detector->getDetector(row,stiSector);
00068
00069 if (!detector) throw runtime_error("StiTpcHitLoader::loadHits(StEvent*) -E- Detector element not found");
00070 const_StTpcHitIterator iter;
00071 StiHitTest hitTest;
00072 for (iter = hitvec.begin();iter != hitvec.end();++iter) {
00073 StTpcHit*hit=*iter;
00074 if (StiKalmanTrackNode::IsLaser() && hit->flag()) continue;
00075 if (hit->flag() & FCF_CHOPPED || hit->flag() & FCF_SANITY) continue;
00076 if (hit->pad() > 182 || hit->timeBucket() > 511) continue;
00077 if(!_hitFactory) throw runtime_error("StiTpcHitLoader::loadHits(StEvent*) -E- _hitFactory==0");
00078 stiHit = _hitFactory->getInstance();
00079 if(!stiHit) throw runtime_error("StiTpcHitLoader::loadHits(StEvent*) -E- stiHit==0");
00080 stiHit->reset();
00081 stiHit->setGlobal(detector,hit,hit->position().x(),hit->position().y(), hit->position().z(),hit->charge());
00082 hitTest.add(hit->position().x(),hit->position().y(), hit->position().z());
00083 if (hit->sector() <= 12) stiHit->setVz( driftvel);
00084 else stiHit->setVz(-driftvel);
00085 _hitContainer->add( stiHit );
00086 noHitsLoaded++;
00087 if (debug) {
00088 cout << "add hit S/R =" << sector << "/" << row << " to detector " << *detector << endl;
00089 }
00090 }
00091 if (hitTest.width()>0.1) {
00092 printf("**** TPC hits too wide (%g) sector=%d row%d\n"
00093 ,hitTest.width(),sector,row);
00094 }
00095
00096 }
00097 }
00098 cout << "StiTpcHitLoader::loadHits(StEvent*) -I- Done with " << noHitsLoaded << " hits" << endl;
00099 }
00100