12 #include "StEventTypes.h"
17 #include "TopologyMap.hh"
18 #include "StBeamBackMaker.h"
20 #define MAX_R_DISTANCE 5. // cm
21 #define MAX_Z_DISTANCE 10. // cm
22 #define MIN_TRACK_SEED_HITS 60
25 bool operator()(
const StHit* hit1,
const StHit* hit2)
const
27 return hit1->position().z() < hit2->position().z();
31 typedef multiset<StHit*, LessHit> HitSet;
32 typedef HitSet::iterator HitSetIter;
35 bool operator()(
const Track* track1,
const Track* track2)
const
37 return track1->size() < track2->size();
41 typedef multiset<Track*, LessTrack> TrackSet;
42 typedef TrackSet::iterator TrackSetIter;
48 info() <<
"Processing run=" << GetRunNumber()
49 <<
", event=" << GetEventNumber() << endm;
53 warning(
"No StEvent");
63 info() << tpc->numberOfHits() <<
" TPC hits in event" << endm;
72 for (UInt_t sector = 0; sector < tpc->numberOfSectors(); ++sector) {
73 for (UInt_t padrow = 0; padrow < tpc->sector(sector)->numberOfPadrows(); ++padrow) {
74 for (UInt_t i = 0; i < tpc->sector(sector)->padrow(padrow)->hits().size(); ++i) {
75 StHit*
hit = tpc->sector(sector)->padrow(padrow)->hits()[i];
76 if (!hit->trackReferenceCount()) {
82 info() << hits.size() <<
" unused TPC hits in event" << endm;
87 info(
"Find track seeds");
90 Track* bufEnd = bufBeg;
92 while (!hits.empty()) {
96 track->push_back(hit);
97 hits.erase(hits.begin());
99 double sumX = hit->position().x();
100 double sumY = hit->position().y();
104 for (HitSetIter i = hits.begin(); i != hits.end();) {
106 double dz = hit->position().z() - track->
lastHit()->position().z();
107 if (fabs(dz) > MAX_Z_DISTANCE)
break;
108 double dx = meanX - hit->position().x();
109 double dy = meanY - hit->position().y();
110 double dr = hypot(dx, dy);
111 if (dr < MAX_R_DISTANCE) {
112 track->push_back(hit);
118 sumX += hit->position().x();
119 sumY += hit->position().y();
120 meanX = sumX / track->size();
121 meanY = sumY / track->size();
127 tracks.insert(track);
129 info() << tracks.size() <<
" track seeds found" << endm;
135 info() <<
"Removing track seeds with less than "
136 << MIN_TRACK_SEED_HITS <<
" hits" << endm;
137 for (TrackSetIter i = tracks.begin(); i != tracks.end();) {
139 if (track->size() < MIN_TRACK_SEED_HITS) {
140 for (Track::iterator j = track->begin(); j != track->end(); ++j) {
144 TrackSetIter next = i;
153 info() << tracks.size() <<
" track seeds left with " << MIN_TRACK_SEED_HITS <<
" hits or more" << endm;
159 info(
"Find linear tracks");
160 vector<Track*> linearTracks;
161 for (TrackSetIter i = tracks.begin(); i != tracks.end(); ++i) {
163 if (track->
fit() && track->
ok()) {
169 for (HitSetIter j = hits.begin(); j != hits.end();) {
172 track->push_back(hit);
174 nth_element(track->begin(), track->rbegin().base(), track->end(),
LessHit());
185 linearTracks.push_back(track);
188 info() << linearTracks.size() <<
" linear tracks found" << endm;
194 info(
"Start merging tracks");
195 for (
unsigned int i = 0; i < linearTracks.size(); ++i) {
196 if (!linearTracks[i])
continue;
197 for (
unsigned int j = i + 1; j < linearTracks.size(); ++j) {
198 if (!linearTracks[j])
continue;
199 if (linearTracks[i]->accept(linearTracks[j]->firstHit()) &&
200 linearTracks[i]->accept(linearTracks[j]->lastHit())) {
201 linearTracks[i]->merge(linearTracks[j]);
210 linearTracks.erase(
remove(linearTracks.begin(), linearTracks.end(),
211 (
Track*)0), linearTracks.end());
212 info() << linearTracks.size() <<
" merged tracks" << endm;
217 info(
"Refit and remove outliers");
218 for (
unsigned int i = 0; i < linearTracks.size(); ++i) {
221 for (Track::iterator j = track->begin(); j != track->end();) {
233 info() << hits.size() <<
" unused TPC hits" << endm;
239 for (
unsigned int i = 0; i < linearTracks.size(); ++i)
240 nHits += linearTracks[i]->size();
241 info() << nHits <<
" TPC hits in linear tracks" << endm;
249 info(
"Converting Track to StTrack");
251 for (
unsigned int i = 0; i <
event->trackNodes().size(); ++i) {
252 Int_t key2 =
event->trackNodes()[i]->track(global)->key();
253 if (key < key2) key = key2;
257 for (
unsigned int i = 0; i < linearTracks.size(); ++i) {
258 if (pileup(linearTracks[i]))
continue;
261 track->setKey(++key);
262 trackNode->addTrack(track);
263 event->trackNodes().push_back(trackNode);
264 event->trackDetectorInfo().push_back(track->detectorInfo());
267 info() << nStTrack <<
" StTrack saved" << endm;
281 gTrack->setLength(track->
length());
282 gTrack->setFlag(901);
286 Line line(origin, momentum);
287 momentum.setMag(999);
288 double dipAngle = atan2(1, hypot(track->
dxdz(), track->
dydz()));
293 line.perigee(track->
firstHit()->position()),
296 gTrack->setEncodedMethod(kLine2StepId);
299 outerGeometry->setOrigin(line.perigee(track->
lastHit()->position()));
300 gTrack->setOuterGeometry(outerGeometry);
304 detInfo->setFirstPoint(track->
firstHit()->position());
305 detInfo->setLastPoint(track->
lastHit()->position());
306 for (Track::iterator i = track->begin(); i != track->end(); ++i)
309 detInfo->setNumberOfPoints(track->size() < 256 ? track->size() : 255, kTpcId);
310 gTrack->setDetectorInfo(detInfo);
314 fitTraits.setNumberOfFitPoints(track->size() < 256 ? track->size() : 255, kTpcId);
315 gTrack->setFitTraits(fitTraits);
320 inline bool StBeamBackMaker::pileup(
Track* track)
const
323 return (topoMap.nearEast() < 4 || topoMap.farEast() < 4 ||
324 topoMap.nearWest() < 4 || topoMap.farWest() < 4);
327 inline ostream& StBeamBackMaker::info(
const Char_t* message)
330 return gMessMgr->Info(Form(
"%s: %s", GetName(), message));
331 return gMessMgr->Info() << GetName() <<
": ";
334 inline ostream& StBeamBackMaker::warning(
const Char_t* message)
337 return gMessMgr->Warning(Form(
"%s: %s", GetName(), message));
338 return gMessMgr->Warning() << GetName() <<
": ";
Number of hits in diffent zones of the TPC for a given track.
double y0() const
y-intercept at z = 0
bool fit()
Perform linear fits in zx- and zy-plane.
Beam background tracker in the TPC.
double x0() const
x-intercept at z = 0
bool ok() const
Good track?
double dydz() const
dy/dz slope
bool accept(StHit *hit) const
Is hit close enough to track?
StHit * firstHit() const
First hit.
StHit * lastHit() const
Last hit.
double dxdz() const
dx/dz slope
double length() const
Track length.