10 #include "StTrackMateMaker.h"
11 #include "StTrackPing.hh"
18 #include "StPrimaryVertex.h"
19 #include "StTpcHitCollection.h"
20 #include "StContainers.h"
21 #include "StTrackNode.h"
22 #include "StPrimaryTrack.h"
24 #include "StTrackDetectorInfo.h"
26 #include "StTrackGeometry.h"
28 #include "StEventUtilities/StuRefMult.hh"
29 #include "StMessMgr.h"
36 #ifndef ST_NO_NAMESPACES
39 size_t buildRecHitTrackMap(
const StSPtrVecTrackNode& nodes,map<StHit*,StTrack*>& htMap);
42 static const char rcsid[] =
"$Id: StTrackMateMaker.cxx,v 1.4 2013/01/16 21:56:45 fisyak Exp $";
47 TString names("oldPtGl/F:newPtGl/F:oldEtaGl/F:newEtaGl/F:oldPhiGl/F:newPhiGl/F:oldPGl/F:newPGl/F:oldFitPtsGl/F:"
48 "newFitPtsGl/F:oldPtPr/F:newPtPr/F:oldEtaPr/F:newEtaPr/F:oldPhiPr/F:newPhiPr/F:oldPPr/F:newPPr/F:"
49 "oldFitPtsPr/F:newFitPtsPr/F:oldDedx/F:newDedx/F:oldCharge/F:newCharge/F:maxPing/F:Prim/F:"
50 "oldChi2Gl0/F:newChi2Gl0/F:oldChi2Gl1/F:newChi2Gl1/F:oldChi2Pr0/F:newChi2Pr0/F:oldChi2Pr1/F:"
51 "newChi2Pr1/F:firstHitsDist/F:lastHitsDist/F:"
52 "oldPrimX/F:oldPrimY/F:oldPrimZ/F:newPrimX/F:newPrimY/F:newPrimZ/F");
99 void set() {memset(&begin, 0, &end-&begin);}
103 Int_t StTrackMateMaker::Init() {
104 TFile *f = GetTFile();
108 LOG_INFO <<
"StTrackMateMaker::Init() - creating histogram" << endm;
109 TString evNames =
"refMult/F";
110 trackTree =
new TTree(
"trackMateComp",
"trackMateComp");
111 trackBr = trackTree->Branch(
"data_array",&data.oldPtGl,names.Data());
112 eventBr = trackTree->Branch(
"ev_array",evOutput,evNames.Data());
113 LOG_INFO <<
"StTrackMateMaker::Init() - successful" << endm;
115 return StMaker::Init();
118 void StTrackMateMaker::Clear(
const char* c)
124 LOG_INFO <<
"In StTrackMateMaker::Make " << endm;
129 rEvent1 = (
StEvent*) GetDataSet(
"IO1/.make/IO1_Root/.data/bfcTree/eventBranch/StEvent");
130 rEvent2 = (
StEvent*) GetDataSet(
"IO2/.make/IO2_Root/.data/bfcTree/eventBranch/StEvent");
132 LOG_INFO <<
"Pointers obtained from GetDataSet" << endm;
133 LOG_INFO <<
"Event1 At: " << rEvent1 << endm;
134 LOG_INFO <<
"Event2 At: " << rEvent2 << endm;
136 if (!rEvent1 || !rEvent2) {
137 LOG_WARN <<
"Bailing out! One of the StEvent's is missing!" << endm;
140 LOG_INFO <<
"Run # and Event #, should be the same for both StEvents" << endm;
141 LOG_INFO <<
"Event1: Run "<< rEvent1->runId() <<
" Event1 No: " << rEvent1->id() << endm;
142 LOG_INFO <<
"Event2: Run "<< rEvent2->runId() <<
" Event2 No: " << rEvent2->id() << endm;
143 LOG_INFO <<
"Vertex Positions" << endm;
144 assert (rEvent1->runId() == rEvent2->runId() && rEvent1->id() == rEvent2->id());
145 if (rEvent1->primaryVertex() ) {
146 LOG_INFO <<
"Event1: Vertex Position " << rEvent1->primaryVertex()->position() << endm;
149 LOG_INFO <<
"Event1: Vertex Not Found" << endm;
151 if (rEvent2->primaryVertex() ) {
152 LOG_INFO <<
"Event2: Vertex Position " << rEvent2->primaryVertex()->position() << endm;
155 LOG_INFO <<
"Event2: Vertex Not Found" << endm;
158 if (rEvent1->runInfo()->spaceChargeCorrectionMode() != 21 ||
159 rEvent2->runInfo()->spaceChargeCorrectionMode() != 21) {
160 LOG_INFO <<
"Event1: spaceChargeCorrectionMode "
161 << rEvent1->runInfo()->spaceChargeCorrectionMode() << endm;
162 LOG_INFO <<
"Event2: spaceChargeCorrectionMode "
163 << rEvent2->runInfo()->spaceChargeCorrectionMode() << endm;
164 LOG_INFO <<
" Skip it " << endm;
168 LOG_INFO <<
"Size of track containers" << endm;
169 const StSPtrVecTrackNode& trackNodes1 = rEvent1->trackNodes();
170 LOG_INFO <<
"Event1: Track Nodes " << trackNodes1.size() << endm;
172 const StSPtrVecTrackNode& trackNodes2 = rEvent2->trackNodes();
173 LOG_INFO <<
"Event2: Track Nodes " << trackNodes2.size() << endm;
174 if (! trackNodes1.size() || ! trackNodes2.size())
return kStWarn;
176 evOutput[0] = uncorrectedNumberOfPrimaries(*rEvent2);
178 LOG_INFO <<
"Tpc Hits" << endm;
184 if (! tpchitcoll1 || ! tpchitcoll2) {
185 LOG_WARN <<
"Empty tpc hit collection in one of the events" << endm;
189 for (
size_t iSec=0; iSec<tpchitcoll1->numberOfSectors(); ++iSec) {
192 for (
size_t iPadR=0; iPadR<sectorcoll1->numberOfPadrows(); ++iPadR) {
195 LOG_INFO <<
"Sector(+1) " << iSec+1 <<
", Padrow(+1) " << iPadR+1 << endm;
196 LOG_INFO <<
"hits1 " << padrowcoll1->hits().size() << endm;
197 LOG_INFO <<
"hits2 " << padrowcoll2->hits().size() << endm;
198 if (padrowcoll1->hits().size()) {
199 LOG_INFO <<
"hits1[0] position " << padrowcoll1->hits()[0]->position() << endm;
200 LOG_INFO <<
"hits2[0] position " << padrowcoll2->hits()[0]->position() << endm;
229 map<StHit*,StTrack*> hitTrackMap2;
230 size_t failedTries = buildRecHitTrackMap(trackNodes2,hitTrackMap2);
231 LOG_INFO <<
"Hits used by more than 1 track: " << failedTries << endm;
234 LOG_INFO <<
"Begin Track Association..." << endm;
235 int matcTrkCounter = 0;
236 int origTrkCounter = 0;
237 int oldOnlyCounter = 0;
238 int oldDoubCounter = 0;
251 initTrackPing.mTrack=0;
252 initTrackPing.mNPings=0;
258 set<StTrack*> assocTracks2;
259 for (
size_t iTrk=0; iTrk<trackNodes1.size();++iTrk) {
260 StTrack* trk1 = trackNodes1[iTrk]->track(global);
261 if (!trk1 || trk1->flag()<=0 || trk1->topologyMap().trackFtpc())
continue;
262 StTrack* ptrk1 = trackNodes1[iTrk]->track(primary);
263 if (Debug()>2) LOG_INFO <<
"Processing Track " << iTrk << endm;
265 vector<StTrackPing> candidates(20,initTrackPing);
266 size_t nCandidates = 0;
267 if (! trk1->detectorInfo())
continue;
268 StPtrVecHit trkhits1 = trk1->detectorInfo()->hits(kTpcId);
270 for (StPtrVecHitIterator hIterTrk = trkhits1.begin(); hIterTrk != trkhits1.end(); ++hIterTrk) {
274 if (! tpchitcoll1->sector(hit1->sector()-1)->padrow(hit1->padrow()-1))
continue;
275 const StSPtrVecTpcHit& hits1 = tpchitcoll1->sector(hit1->sector()-1)->padrow(hit1->padrow()-1)->hits();
276 if (! hits1.size())
continue;
278 StPtrVecTpcHitConstIterator hIterColl = find(hits1.begin(),hits1.end(),hit1);
279 int index = hIterColl - hits1.begin();
282 if (! tpchitcoll2->sector(hit1->sector()-1)->padrow(hit1->padrow()-1))
continue;
283 const StSPtrVecTpcHit& hits2 = tpchitcoll2->sector(hit1->sector()-1)->padrow(hit1->padrow()-1)->hits();
284 if (! hits2.size())
continue;
288 StTrack* trackCand = hitTrackMap2[hit2];
298 if (nCandidates == 0) {
299 candidates[0].mTrack = trackCand;
300 candidates[0].mNPings = 1;
305 for (
unsigned int iCandidate=0; iCandidate<nCandidates; iCandidate++){
306 if (trackCand==candidates[iCandidate].mTrack){
307 candidates[iCandidate].mNPings++;
310 if (iCandidate == (nCandidates-1)){
311 candidates[nCandidates].mTrack = trackCand;
312 candidates[nCandidates].mNPings = 1;
316 if (nCandidates>=candidates.size()) {
317 candidates.resize(nCandidates+20);
318 if (Debug()) LOG_INFO <<
"Resizing in the TPC hits of the track " << endm;
334 Fill(trk1,ptrk1,0,0,0);
337 vector<StTrackPing>::iterator max = max_element(candidates.begin(),candidates.end(),compStTrackPing);
340 LOG_INFO <<
"Matching track " << (*max).mTrack <<
" has " << (*max).mNPings <<
", index " << max-candidates.begin() << endm;
344 StTrack* ptrk2 = trk2->node()->track(primary);
345 if (trk2->flag()<=0 || trk2->topologyMap().trackFtpc()) {
347 Fill(trk1,ptrk1,0,0,-1);
351 if (assocTracks2.find(trk2)!=assocTracks2.end()) {
356 Fill(trk1,ptrk1,trk2,ptrk2,(*max).mNPings);
361 assocTracks2.insert(trk2);
362 Fill(trk1,ptrk1,trk2,ptrk2,(*max).mNPings);
366 int newgTrkCounter = 0;
367 int newOnlyCounter = 0;
368 for (
size_t iTrk=0; iTrk<trackNodes2.size();++iTrk) {
369 StTrack* trk2 = trackNodes2[iTrk]->track(global);
370 if (!trk2 || trk2->flag()<=0 || trk2->topologyMap().trackFtpc())
continue;
373 set<StTrack*>::iterator itTrk2 = find(assocTracks2.begin(),assocTracks2.end(),trk2);
374 if (itTrk2==assocTracks2.end()) {
377 if (trk2->node()) ptrk2 = trk2->node()->track(primary);
378 Fill(0,0,trk2,ptrk2,-2);
382 LOG_INFO <<
"Old+EGR Global Tracks (flag>0) " << origTrkCounter << endm;
383 LOG_INFO <<
"New Global Tracks (flag>0) " << newgTrkCounter << endm;
384 LOG_INFO <<
"Matched Global Tracks (flag>0) " << matcTrkCounter << endm;
385 LOG_INFO <<
"Old+EGR Only Tracks (flag>0) " << oldOnlyCounter << endm;
386 LOG_INFO <<
"Old+EGR Double Matches to New " << oldDoubCounter << endm;
387 LOG_INFO <<
"size of Set, should = Matched.. " << assocTracks2.size() << endm;
388 LOG_INFO <<
"New Only Tracks (flag>0) " << newOnlyCounter << endm;
396 data.firstHitsDist = data.lastHitsDist = -999.;
399 data.oldPtGl = mom1.perp();
400 data.oldEtaGl = mom1.pseudoRapidity();
401 data.oldPhiGl = mom1.phi();
402 data.oldPGl = mom1.mag();
403 data.oldFitPtsGl = trk1->fitTraits().numberOfFitPoints(kTpcId);
404 data.oldDedx = getTpcDedx(trk1);
405 data.oldCharge = trk1->geometry()->charge();
406 data.oldChi2Gl0 = trk1->fitTraits().chi2(0);
407 data.oldChi2Gl1 = trk1->fitTraits().chi2(1);
411 data.oldPtPr = pmom1.perp();
412 data.oldEtaPr = pmom1.pseudoRapidity();
413 data.oldPhiPr = pmom1.phi();
414 data.oldPPr = pmom1.mag();
415 data.oldFitPtsPr = trk1->fitTraits().numberOfFitPoints(kTpcId);
417 data.oldChi2Pr0 = ptrk1->fitTraits().chi2(0);
418 data.oldChi2Pr1 = ptrk1->fitTraits().chi2(1);
422 data.oldPrimX = vertex->position().x();
423 data.oldPrimY = vertex->position().y();
424 data.oldPrimZ = vertex->position().z();
430 data.newPtGl = mom2.perp();
431 data.newEtaGl = mom2.pseudoRapidity();
432 data.newPhiGl = mom2.phi();
433 data.newPGl = mom2.mag();
434 data.newFitPtsGl = trk2->fitTraits().numberOfFitPoints(kTpcId);
435 data.newDedx = getTpcDedx(trk2);
436 data.newCharge = trk2->geometry()->charge();
437 data.newChi2Gl0 = trk2->fitTraits().chi2(0);
438 data.newChi2Gl1 = trk2->fitTraits().chi2(1);
442 data.newPtPr = pmom2.perp();
443 data.newEtaPr = pmom2.pseudoRapidity();
444 data.newPhiPr = pmom2.phi();
445 data.newPPr = pmom2.mag();
446 data.newFitPtsPr = trk2->fitTraits().numberOfFitPoints(kTpcId);
448 data.newChi2Pr0 = ptrk2->fitTraits().chi2(0);
449 data.newChi2Pr1 = ptrk2->fitTraits().chi2(1);
451 const StVertex *vertex = prim->vertex();
453 data.newPrimX = vertex->position().x();
454 data.newPrimY = vertex->position().y();
455 data.newPrimZ = vertex->position().z();
459 data.maxPing = maxPing;
464 StThreeVectorF difFirst = det1->firstPoint() - det2->firstPoint();
465 data.firstHitsDist = difFirst.mag();
467 data.lastHitsDist = difLast.mag();
virtual void Clear(Option_t *option="")
User defined functions.