StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiTpcHitLoader.cxx
1 #include "Stiostream.h"
2 #include <stdexcept>
3 #include <cmath>
4 #include <stdio.h>
5 #include "StEvent.h"
6 #include "StEventTypes.h"
7 #include "StDbUtilities/StTpcCoordinateTransform.hh"
8 #include "StDbUtilities/StTpcLocalSectorCoordinate.hh"
9 #include "StDbUtilities/StGlobalCoordinate.hh"
10 #include "StTpcDb/StTpcDb.h"
11 #include "Sti/Base/Factory.h"
12 #include "Sti/StiHit.h"
13 #include "Sti/StiHitContainer.h"
14 #include "Sti/StiDetector.h"
15 #include "Sti/StiDetectorBuilder.h"
16 #include "StiTpcHitLoader.h"
17 #include "Sti/StiHitTest.h"
18 #include "Sti/StiKalmanTrackNode.h"
19 #include "StiTpc/StiTpcDetectorBuilder.h"
20 #include "RTS/src/DAQ_TPX/tpxFCF_flags.h" // for FCF flag definition
21 #include "StDetectorDbMaker/St_tpcPadConfigC.h"
22 //________________________________________________________________________________
23 StiTpcHitLoader::StiTpcHitLoader(): StiHitLoader<StEvent,StiDetectorBuilder>("TpcHitLoader"),
24  _minRow(1), _maxRow(100), _minSector(1), _maxSector(24) {}
25 //________________________________________________________________________________
26 StiTpcHitLoader::StiTpcHitLoader(StiHitContainer* hitContainer,
27  Factory<StiHit>*hitFactory,
28  StiDetectorBuilder * detector)
29 : StiHitLoader<StEvent,StiDetectorBuilder>("TpcHitLoader",hitContainer,hitFactory,detector),
30  _minRow(1), _maxRow(100), _minSector(1), _maxSector(24) {}
31 //________________________________________________________________________________
32 void StiTpcHitLoader::loadHits(StEvent* source,
33  Filter<StiTrack> * trackFilter,
34  Filter<StiHit> * hitFilter)
35 {
36  static Int_t debug = 0;
37 // cout << "StiTpcHitLoader::loadHits(StEvent*) -I- Started" << endl;
38  assert(_detector);
39  assert(_hitContainer);
40  const StTpcHitCollection* tpcHits = source->tpcHitCollection();
41  if (!tpcHits) return;
42  UInt_t noHitsLoaded = 0;
43  for (UInt_t sector=_minSector-1; sector<_maxSector; sector++) {
44  const StTpcSectorHitCollection* secHits = tpcHits->sector(sector);
45  if (!secHits) {
46  cout << "StiTpcHitLoader::loadHits(StEvent* source) -W- no hits for sector:"<<sector<<endl;
47  break;
48  }
49  Float_t driftvel = 1e-6*gStTpcDb->DriftVelocity(sector+1); // cm/mkmsec
50 
51  _maxRow = St_tpcPadConfigC::instance()->numberOfRows(sector+1);
52 
53  for (UInt_t row=_minRow-1; row<_maxRow; row++) {
54  //cout << "StiTpcHitLoader:loadHits() -I- Loading row:"<<row<<" sector:"<<sector<<endl;
55 
56  // Negative Sti indices indicate a problem with Sti TPC geometry layout
57  int stiSector, stiRow;
58  std::tie(stiSector, stiRow) = StiTpcDetectorBuilder::toStiLayer(sector+1, row+1);
59 
60  const StTpcPadrowHitCollection* padrowHits = secHits->padrow(row);
61  if (!padrowHits) break;
62  const StSPtrVecTpcHit& hitvec = padrowHits->hits();
63  StiDetector * detector = _detector->getDetector(stiRow,stiSector);
64  if (!detector) throw runtime_error("StiTpcHitLoader::loadHits(StEvent*) -E- Detector element not found");
65  StiHitTest hitTest;
66  for (const StTpcHit* hit : hitvec)
67  {
68  if (StiKalmanTrackNode::IsLaser() && hit->flag()) continue;
69  if (hit->flag() & FCF_CHOPPED || hit->flag() & FCF_SANITY) continue; // ignore hits marked by AfterBurner as chopped or bad sanity
70  if (hit->pad() > 182 || hit->timeBucket() > 511) continue; // some garbadge for y2001 daq
71  assert(_hitFactory);
72  StiHit* stiHit = _hitFactory->getInstance();
73  stiHit->reset();
74  stiHit->setGlobal(detector,hit,hit->position().x(),hit->position().y(), hit->position().z(),hit->charge());
75  hitTest.add(hit->position().x(),hit->position().y(), hit->position().z());
76  if (hit->sector() <= 12) stiHit->setVz( driftvel);
77  else stiHit->setVz(-driftvel);
78  _hitContainer->add( stiHit );
79  noHitsLoaded++;
80  if (debug) {
81  cout << "add hit S/R =" << sector << "/" << row << " to detector " << *detector << endl;
82  }
83  }
84  if (hitTest.width()>0.1) {
85  printf("**** TPC hits too wide (%g) sector=%d row%d\n"
86  ,hitTest.width(),sector,row);
87  }
88 
89  }
90  }
91 // cout << "StiTpcHitLoader::loadHits(StEvent*) -I- Done with " << noHitsLoaded << " hits" << endl;
92 }
93 //________________________________________________________________________________
virtual void add(StiHit *)
void setGlobal(const StiDetector *detector, const StMeasuredPoint *stHit, Float_t x, Float_t y, Float_t z, Float_t energy)
Definition: StiHit.cxx:133
Definition: StiHit.h:51
virtual Abstract * getInstance()=0
Get a pointer to instance of objects served by this factory.