57 #include "StParticleTypes.hh"
58 #include "StParticleDefinition.hh"
59 #include "SystemOfUnits.h"
60 #include "PhysicalConstants.h"
62 #include "StChainOpt.h"
65 #include "StTrackNode.h"
66 #include "StTrackGeometry.h"
67 #include "StGlobalTrack.h"
68 #include "StPrimaryTrack.h"
69 #include "StPrimaryVertex.h"
70 #include "StETofCollection.h"
71 #include "StETofHit.h"
72 #include "StTrackPidTraits.h"
73 #include "StETofPidTraits.h"
74 #include "StTpcDedxPidAlgorithm.h"
75 #include "StDedxPidTraits.h"
77 #include "StDetectorDbMaker/St_MagFactorC.h"
79 #include "StBTofCollection.h"
80 #include "StBTofHeader.h"
82 #include "StMuDSTMaker/COMMON/StMuDst.h"
83 #include "StMuDSTMaker/COMMON/StMuArrays.h"
84 #include "StMuDSTMaker/COMMON/StMuTrack.h"
85 #include "StMuDSTMaker/COMMON/StMuPrimaryVertex.h"
86 #include "StMuDSTMaker/COMMON/StMuETofHit.h"
87 #include "StMuDSTMaker/COMMON/StMuETofPidTraits.h"
88 #include "StMuDSTMaker/COMMON/StMuETofDigi.h"
89 #include "StMuDSTMaker/COMMON/StMuETofHeader.h"
91 #include "StETofMatchMaker.h"
92 #include "StETofHitMaker/StETofHitMaker.h"
93 #include "StETofUtil/StETofGeometry.h"
94 #include "StETofUtil/StETofConstants.h"
96 #include "tables/St_etofMatchParam_Table.h"
101 namespace etofProjection {
103 const double safetyMargins[ 2 ] = { 2., 2. };
105 const float minEtaCut = 0.0;
107 const float minEtaProjCut = -1.0;
108 const float maxEtaProjCut = -1.7;
112 const double deltaXoffset[ 108 ] = { 0 };
114 const double deltaYoffset[ 108 ] = { 0 };
116 const double deltaRcut = 4.;
120 static const double kaon_minus_mass_c2 = 493.68 * MeV;
123 namespace etofHybridT0 {
124 const unsigned int minCand = 2;
125 const unsigned int nSwitch = 5;
126 const unsigned int nMin = 10;
127 const unsigned int nUpdate = 5;
128 const float lowCut = 0.10;
129 const float highCut = 0.85;
130 const float diffToClear = 2.;
131 const float biasOffset = 0.075;
137 StETofMatchMaker::StETofMatchMaker(
const char* name )
138 :
StMaker(
"etofMatch", name ),
141 mETofGeom( nullptr ),
142 mFileNameMatchParam(
"" ),
143 mFileNameAlignParam(
"" ),
144 mIsStEventIn( false ),
146 mOuterTrackGeometry( true ),
147 mUseHelixSwimmer( false ),
148 mUseOnlyBTofHeaderStartTime( true ),
154 mMatchDistT( 99999. ),
163 mClockJumpDirection(),
172 mT0corrVec.reserve( 500 );
173 mTrackCuts.push_back( 0. );
174 mTrackCuts.push_back( 0. );
175 mTrackCuts.push_back( 0. );
181 StETofMatchMaker::~StETofMatchMaker()
189 StETofMatchMaker::Init()
191 LOG_INFO <<
"StETofMatchMaker::Init()" << endm;
193 LOG_INFO <<
"isSimulation flag was set to: " << mIsSim << endm;
203 StETofMatchMaker::InitRun( Int_t runnumber )
205 LOG_INFO <<
"StETofMatchMaker::InitRun()" << endm;
208 std::ifstream paramFile;
216 if( mFileNameMatchParam.empty() ) {
217 LOG_INFO <<
"etofMatchParam: no filename provided --> load database table" << endm;
219 dbDataSet = GetDataBase(
"Calibrations/etof/etofMatchParam" );
221 St_etofMatchParam* etofMatchParam =
static_cast< St_etofMatchParam*
> ( dbDataSet->
Find(
"etofMatchParam" ) );
222 if( !etofMatchParam ) {
223 LOG_ERROR <<
"unable to get the match params from the database" << endm;
227 etofMatchParam_st* matchParamTable = etofMatchParam->GetTable();
229 mMatchRadius = matchParamTable->matchRadius;
231 mTrackCuts.at( 0 ) = matchParamTable->trackCutNHitsFit;
232 mTrackCuts.at( 1 ) = matchParamTable->trackCutNHitsRatio;
233 mTrackCuts.at( 2 ) = matchParamTable->trackCutLowPt;
237 LOG_INFO <<
"etofMatchParam: filename provided --> use parameter file: " << mFileNameMatchParam.c_str() << endm;
239 paramFile.open( mFileNameMatchParam.c_str() );
241 if( !paramFile.is_open() ) {
242 LOG_ERROR <<
"unable to get the 'etofMatchParam' parameters from file --> file does not exist" << endm;
246 std::vector< float > param;
248 while( paramFile >> temp ) {
249 param.push_back( temp );
254 if( param.size() != 4 ) {
255 LOG_ERROR <<
"parameter file for 'etofMatchParam' has not the right amount of entries: ";
256 LOG_ERROR << param.size() <<
" instead of 4 !!!!" << endm;
260 mMatchRadius = param.at( 0 );
262 mTrackCuts.at( 0 ) = param.at( 1 );
263 mTrackCuts.at( 1 ) = param.at( 2 );
264 mTrackCuts.at( 2 ) = param.at( 3 );
268 LOG_INFO <<
" match radius: " << mMatchRadius << endm;
269 LOG_INFO <<
" track cut (nHitsFit): " << mTrackCuts.at( 0 ) << endm;
270 LOG_INFO <<
" track cut (nHitsRatio): " << mTrackCuts.at( 1 ) << endm;
271 LOG_INFO <<
" track cut (low pt): " << mTrackCuts.at( 2 ) << endm;
280 LOG_INFO <<
" creating a new eTOF geometry . . . " << endm;
281 mETofGeom =
new StETofGeometry(
"etofGeometry",
"etofGeometry in MatchMaker" );
284 if( mETofGeom && !mETofGeom->isInitDone() ) {
285 LOG_INFO <<
" eTOF geometry initialization ... " << endm;
287 if( !gGeoManager ) GetDataBase(
"VmcGeometry" );
290 LOG_ERROR <<
"Cannot get GeoManager" << endm;
294 LOG_DEBUG <<
" gGeoManager: " << gGeoManager << endm;
296 if (mFileNameAlignParam !=
""){
297 LOG_DEBUG <<
" gGeoManager: Setting alignment file: " << mFileNameAlignParam << endm;
298 mETofGeom->setFileNameAlignParam(mFileNameAlignParam);
301 mETofGeom->init( gGeoManager, etofProjection::safetyMargins, mUseHelixSwimmer );
304 if ( mETofGeom && !mETofGeom->isInitDone() ) {
305 LOG_ERROR <<
"Initialization of StEtofGeometry failed" << endm;
315 LOG_DEBUG <<
"StETofMatchMaker::InitRun() -- pointer to eTOF hit maker: " << mETofHitMaker << endm;
319 for(
unsigned int i=0; i<mETofGeom->nValidModules(); i++ ) {
323 int sector = mETofGeom->module( i )->sector();
324 int plane = mETofGeom->module( i )->plane();
326 for(
int j=0; j<sector; j++ ) {
327 mHistograms.at(
"eTofSectors" )->Fill( pos.x(), pos.y() );
329 for(
int j=0; j<plane; j++ ) {
330 mHistograms.at(
"eTofModules" )->Fill( pos.x(), pos.y() );
336 int nBinsX = mHistograms2d.at(
"bfield_z" )->GetNbinsX();
337 int nBinsY = mHistograms2d.at(
"bfield_z" )->GetNbinsY();
338 for(
int i=0; i<nBinsX; i++ ) {
339 for(
int j=0; j<nBinsY; j++ ) {
340 double z = mHistograms2d.at(
"bfield_z" )->GetXaxis()->GetBinCenter( i );
341 double y = mHistograms2d.at(
"bfield_z" )->GetYaxis()->GetBinCenter( j );
343 mHistograms2d.at(
"bfield_z" )->Fill( z, y, mETofGeom->getFieldZ( 0., y, z ) );
354 StETofMatchMaker::FinishRun( Int_t runnumber )
356 LOG_DEBUG <<
"StETofMatchMaker::FinishRun() -- cleaning up the geometry" << endm;
370 LOG_DEBUG <<
"StETofMatchMaker::Finish()" << endm;
373 LOG_INFO <<
"Finish() - writing *.etofMatch.root ..." << endm;
391 LOG_DEBUG <<
"StETofMatchMaker::Make(): starting ..." << endm;
393 mIsStEventIn =
false;
396 mEvent = (
StEvent* ) GetInputDS(
"StEvent" );
400 LOG_DEBUG <<
"Make() - running on StEvent" << endm;
404 if( !etofCollection ) {
405 LOG_WARN <<
"Make() - Found StEvent data structure, but no eTOF collection. Try MuDst processing instead" << endm;
406 mMuDst = (
StMuDst* ) GetInputDS(
"MuDst" );
409 LOG_DEBUG <<
"Make() - running on MuDsts" << endm;
413 fillIndexToPrimaryMap();
424 LOG_DEBUG <<
"Make(): no StEvent found" << endm;
426 mMuDst = (
StMuDst* ) GetInputDS(
"MuDst" );
429 LOG_DEBUG <<
"Make() - running on MuDsts" << endm;
433 fillIndexToPrimaryMap();
438 LOG_DEBUG <<
"Make() - no StMuDst found" << endm;
443 if( !mIsStEventIn && !mIsMuDstIn ) {
444 LOG_WARN <<
"Make() - neither StEvent nor MuDst available ... bye-bye" << endm;
449 mHistograms.at(
"eventCounter" )->Fill( 1 );
455 eTofHitVec detectorHitVec;
457 readETofDetectorHits( detectorHitVec );
459 if( detectorHitVec.size() == 0 ) {
468 eTofHitVec intersectionVec;
469 int nPrimaryWithIntersection = 0;
471 float bFieldFromGeom = mETofGeom->getFieldZ( 100., 100., 0. );
474 bField = mMuDst->
event()->runInfo().magneticField();
477 bField = mEvent->runInfo()->magneticField();
480 if( mUseHelixSwimmer && fabs( bFieldFromGeom - bField ) > 0.2 ) {
481 LOG_WARN <<
"Wrong magnetc field bField = " << bField <<
" bFieldFromGeom = " << bFieldFromGeom <<
" --> check the magF input!" << endm;
484 findTrackIntersections( intersectionVec, nPrimaryWithIntersection );
486 if( intersectionVec.size() == 0 ) {
492 mHistograms.at(
"intersectionMult_etofMult" )->Fill( detectorHitVec.size(), intersectionVec.size() );
497 eTofHitVec matchCandVec;
499 matchETofHits( detectorHitVec, intersectionVec, matchCandVec );
501 if( matchCandVec.size() == 0 ) {
508 eTofHitVec finalMatchVec;
509 sortandcluster(matchCandVec , detectorHitVec , intersectionVec , finalMatchVec);
516 eTofHitVec singleTrackMatchVec;
517 vector< eTofHitVec > multiTrackMatchVec;
532 if( finalMatchVec.size() == 0 ) {
544 fillPidTraits( finalMatchVec );
549 int nPrimaryWithPid = 0;
551 calculatePidVariables( finalMatchVec, nPrimaryWithPid );
553 mHistograms.at(
"primaryIntersect_validMatch" )->Fill( nPrimaryWithIntersection, nPrimaryWithPid );
558 fillQaHistograms( finalMatchVec );
560 fillSlewHistograms( finalMatchVec );
570 void StETofMatchMaker::fillIndexToPrimaryMap()
573 mIndex2Primary.clear();
575 for(
int i = 0; i < mMuDst->
array( muPrimary )->GetEntries(); i++ ) {
581 if( index2Global < 0 ) {
584 mIndex2Primary[ index2Global ] = i;
589 void StETofMatchMaker::cleanUpTraits()
593 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
594 size_t nNodes = nodes.size();
595 for(
size_t iNode = 0; iNode < nNodes; iNode++ ) {
597 if( !gTrack )
continue;
600 StSPtrVecTrackPidTraits& traits = gTrack->pidTraits();
601 for(
auto it = traits.begin(); it != traits.end(); it++ ) {
602 if( ( *it )->detector() == kETofId ) {
607 LOG_INFO <<
"cleanUpTraits() - etof traits on global track " << iNode <<
" already exist" << endm;
608 LOG_INFO <<
"matchFlag: " << etofTraits->
matchFlag() <<
" localX: " << etofTraits->localX() <<
" localY: " << etofTraits->localY();
609 LOG_INFO <<
" tof: " << etofTraits->
timeOfFlight() <<
" pathlength: " << etofTraits->pathLength() <<
" beta: " << etofTraits->beta() << endm;
611 if( etofTraits->etofHit() ) {
612 LOG_INFO <<
"time: " << etofTraits->etofHit()->
time() << endm;
619 LOG_INFO <<
" ... erased" << endm;
629 StSPtrVecTrackPidTraits& ptraits = pTrack->pidTraits();
630 for(
auto it = ptraits.begin(); it != ptraits.end(); it++ ) {
631 if( ( *it )->detector() == kETofId ) {
636 LOG_INFO <<
"cleanUpTraits() - etof traits on primary track corresponding to node " << iNode <<
" already exist" << endm;
637 LOG_INFO <<
"matchFlag: " << etofTraits->
matchFlag() <<
" localX: " << etofTraits->localX() <<
" localY: " << etofTraits->localY();
638 LOG_INFO <<
" tof: " << etofTraits->
timeOfFlight() <<
" pathlength: " << etofTraits->pathLength() <<
" beta: " << etofTraits->beta() << endm;
640 if( etofTraits->etofHit() ) {
641 LOG_INFO <<
"time: " << etofTraits->etofHit()->
time() << endm;
648 LOG_INFO <<
" ... erased" << endm;
658 size_t nHits = mEvent->etofCollection()->etofHits().size();
659 for(
size_t i=0; i<nHits; i++ ) {
660 StETofHit* aHit = mEvent->etofCollection()->etofHits().at( i );
661 if( !aHit )
continue;
662 aHit->setAssociatedTrack(
nullptr );
667 size_t nNodes = mMuDst->numberOfGlobalTracks();
668 for(
size_t iNode=0; iNode<nNodes; iNode++ ) {
670 if( !track )
continue;
676 LOG_INFO <<
"cleanUpTraits() - etof traits on global track " << iNode <<
" already exist" << endm;
677 LOG_INFO <<
"matchFlag: " << etofTraits.
matchFlag() <<
" localX: " << etofTraits.localX() <<
" localY: " << etofTraits.localY();
678 LOG_INFO <<
" tof: " << etofTraits.
timeOfFlight() <<
" pathlength: " << etofTraits.pathLength() <<
" beta: " << etofTraits.beta() << endm;
691 LOG_INFO <<
" ... erased" << endm;
695 auto it = mIndex2Primary.find( iNode );
696 if( it != mIndex2Primary.end() ) {
706 LOG_INFO <<
"cleanUpTraits() - etof traits on primary track " << pIndex <<
" already exist" << endm;
707 LOG_INFO <<
"matchFlag: " << etofTraits.
matchFlag() <<
" localX: " << etofTraits.localX() <<
" localY: " << etofTraits.localY();
708 LOG_INFO <<
" tof: " << etofTraits.
timeOfFlight() <<
" pathlength: " << etofTraits.pathLength() <<
" beta: " << etofTraits.beta() << endm;
720 LOG_INFO <<
" ... erased" << endm;
726 size_t nHits = mMuDst->numberOfETofHit();
727 for(
size_t i=0; i<nHits; i++ ) {
729 if( !aHit )
continue;
730 aHit->setIndex2Primary( -1 );
731 aHit->setIndex2Global( -1 );
732 aHit->setAssociatedTrackId( -1 );
744 StETofMatchMaker::readETofDetectorHits( eTofHitVec& detectorHitVec )
750 if( !mEvent->etofCollection() ) {
751 LOG_WARN <<
"readETofDetectorHits() - no etof collection --> nothing to do ... bye-bye" << endm;
754 if( !mEvent->etofCollection()->hitsPresent() ) {
755 LOG_WARN <<
"readETofDetectorHits() - no etof hits present --> nothing to do ... bye-bye" << endm;
759 nHits = mEvent->etofCollection()->etofHits().size();
762 else if( mIsMuDstIn ) {
764 LOG_WARN <<
"readETofDetectorHits() - no digi array --> nothing to do ... bye-bye" << endm;
768 if( !mMuDst->numberOfETofHit() ) {
769 LOG_WARN <<
"readETofDetectorHits() - no hits present --> nothing to do ... bye-bye" << endm;
773 nHits = mMuDst->numberOfETofHit();
778 mHistograms.at(
"eventCounter" )->Fill( 2 );
784 for(
size_t i=0; i<nHits; i++ ) {
785 StETofHit* aHit = mEvent->etofCollection()->etofHits().at( i );
791 if( fabs(aHit->
localY()) > mLocalYmax ) {
795 StructETofHit detectorHit;
797 detectorHit.sector = aHit->
sector();
805 detectorHit.plane = aHit->
zPlane();
806 detectorHit.counter = aHit->
counter();
807 detectorHit.hitTime = aHit->
time();
808 detectorHit.localX = aHit->
localX();
809 detectorHit.localY = aHit->
localY();
812 detectorHit.index2ETofHit = i;
814 detectorHitVec.push_back( detectorHit );
818 for(
size_t i=0; i<nHits; i++ ) {
825 if( fabs(aHit->
localY()) > mLocalYmax ) {
829 StructETofHit detectorHit;
839 detectorHit.plane = aHit->
zPlane();
840 detectorHit.counter = aHit->
counter();
841 detectorHit.hitTime = aHit->
time();
842 detectorHit.localX = aHit->
localX();
843 detectorHit.localY = aHit->
localY();
846 detectorHit.index2ETofHit = i;
848 detectorHitVec.push_back( detectorHit );
859 for(
auto&
hit : detectorHitVec ) {
860 double xl[ 3 ] = {
hit.localX,
hit.localY, 0 };
862 int moduleId = mETofGeom->calcModuleIndex(
hit.sector,
hit.plane );
863 int counterId =
hit.counter - 1;
866 mETofGeom->hitLocal2Master( moduleId, counterId, xl, xg );
870 hit.globalPos = globalPos;
872 hit.strip = ( (
StETofGeomCounter* ) mETofGeom->findETofNode( moduleId, counterId ) )->findStrip( xl );
875 LOG_DEBUG <<
"hit( " <<
hit.index2ETofHit <<
" ) at sector: " <<
hit.sector;
876 LOG_DEBUG <<
" zPlane: " <<
hit.plane <<
" counter: " <<
hit.counter;
877 LOG_DEBUG <<
" with local (X, Y): (" << xl[ 0 ] <<
", " << xl[ 1 ] <<
")" << endm;
878 LOG_DEBUG <<
"global (X, Y, Z): " << xg[ 0 ] <<
", " << xg[ 1 ] <<
", " << xg[ 2 ] << endm;
879 LOG_DEBUG <<
" strip: " <<
hit.strip << endm;
883 float hit_eta = globalPos.pseudoRapidity();
884 float hit_phi = globalPos.phi();
886 if ( hit_phi < 0. ) hit_phi += 2. * M_PI;
888 LOG_DEBUG <<
"global (eta, phi): " << hit_eta <<
", " << hit_phi << endm;
890 if( fabs(
hit.localY ) < eTofConst::stripLength / 2. * 1.5 ) {
891 mHistograms.at(
"eTofHits_globalXY" )->Fill( globalPos.x(), globalPos.y() );
895 if( fabs(
hit.localY ) < eTofConst::stripLength / 2. * 1.5 ) {
896 mHistograms.at(
"eTofHits_phi_eta" )->Fill( hit_phi, hit_eta );
899 if(
hit.sector == 18 ||
hit.sector == 24 ) {
900 mHistograms.at(
"eTofHits_globalYZ" )->Fill( globalPos.y(), globalPos.z() );
903 std::string histName_hit_localXY =
"eTofHits_localXY_s" + std::to_string(
hit.sector ) +
"m" + std::to_string(
hit.plane ) +
"c" + std::to_string(
hit.counter );
904 std::string histName_hit_globalXY =
"eTofHits_globalXY_s" + std::to_string(
hit.sector ) +
"m" + std::to_string(
hit.plane ) +
"c" + std::to_string(
hit.counter );
905 std::string histName_hit_eta_phi =
"eTofHits_phi_eta_s" + std::to_string(
hit.sector ) +
"m" + std::to_string(
hit.plane ) +
"c" + std::to_string(
hit.counter );
907 mHistograms.at( histName_hit_localXY )->Fill(
hit.localX,
hit.localY );
908 mHistograms.at( histName_hit_globalXY )->Fill(
hit.globalPos.x(),
hit.globalPos.y() );
909 mHistograms.at( histName_hit_eta_phi )->Fill( hit_phi, hit_eta );
914 mHistograms.at(
"detectorHitMult" )->Fill( detectorHitVec.size() );
915 if( detectorHitVec.size() > 0 ) {
916 mHistograms.at(
"eventCounter" )->Fill( 3 );
927 StETofMatchMaker::findTrackIntersections( eTofHitVec& intersectionVec,
int& nPrimaryWithIntersection )
930 size_t nPrimaryCrossings = 0;
934 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
936 nNodes = nodes.size();
939 LOG_INFO <<
"# tracks in the event: " << nNodes << endm;
942 for(
size_t iNode = 0; iNode < nNodes; iNode++ ) {
944 LOG_DEBUG <<
"track : " << iNode << endm;
948 if( !validTrack( theTrack ) )
continue;
950 bool isPrimary =
false;
955 LOG_DEBUG <<
"track : " << iNode <<
" is a primary track" << endm;
959 StPhysicalHelixD theHelix = mOuterTrackGeometry ? theTrack->outerGeometry()->helix() : theTrack->geometry()->helix();
963 extrapolateTrackToETof( intersectionVec, theHelix, iNode, nCrossings, isPrimary );
967 nPrimaryCrossings += nCrossings;
968 if( nCrossings > 0 ) {
969 nPrimaryWithIntersection++;
972 int charge = pTrack->geometry()->charge();
973 float pMom = pTrack->geometry()->momentum().mag();
975 mHistograms.at(
"intersection_primaryTrack_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
976 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackpos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
977 else mHistograms.at(
"intersection_primaryTrackneg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
980 mHistograms.at(
"intersection_primaryTrackMom0_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
981 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom0pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
982 else mHistograms.at(
"intersection_primaryTrackMom0neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
984 else if( pMom > 0.5 ) {
985 mHistograms.at(
"intersection_primaryTrackMom1_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
986 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom1pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
987 else mHistograms.at(
"intersection_primaryTrackMom1neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
990 mHistograms.at(
"intersection_primaryTrackMom2_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
991 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom2pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
992 else mHistograms.at(
"intersection_primaryTrackMom2neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
998 if( mDoQA && nCrossings > 0 ) {
1001 mHistograms.at(
"intersection_track_pt_eta" )->Fill( eTrack.pt, eTrack.eta );
1002 mHistograms.at(
"intersection_track_pt_phi" )->Fill( eTrack.pt, eTrack.phi );
1003 mHistograms.at(
"intersection_track_phi_eta" )->Fill( eTrack.phi, eTrack.eta );
1005 mHistograms.at(
"intersection_track_nHitsTpc" )->Fill( eTrack.nFtPts );
1007 if( eTrack.dEdx > -999. ) mHistograms.at(
"intersection_track_mom_dEdx" )->Fill( eTrack.pt * cosh( eTrack.eta ), eTrack.dEdx );
1008 if( eTrack.nSigmaPion > -999. ) mHistograms.at(
"intersection_track_mom_nsigmaPi" )->Fill( eTrack.pt * cosh( eTrack.eta ), eTrack.nSigmaPion );
1013 nNodes = mMuDst->numberOfGlobalTracks();
1016 LOG_INFO <<
"# tracks in the event: " << nNodes << endm;
1019 for(
size_t iNode = 0; iNode < nNodes; iNode++ ) {
1021 LOG_DEBUG <<
"track : " << iNode << endm;
1026 if( !validTrack( theTrack ) )
continue;
1028 bool isPrimary=
false;
1031 auto it = mIndex2Primary.find( iNode );
1032 if( it != mIndex2Primary.end() ) {
1033 pIndex = it->second;
1038 LOG_DEBUG <<
"track : " << iNode <<
" is a primary track" << endm;
1046 extrapolateTrackToETof( intersectionVec, theHelix, iNode, nCrossings, isPrimary );
1049 nPrimaryCrossings += nCrossings;
1050 if( nCrossings > 0 ) {
1051 nPrimaryWithIntersection++;
1057 mHistograms.at(
"intersection_primaryTrack_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1058 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackpos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1059 else mHistograms.at(
"intersection_primaryTrackneg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1062 mHistograms.at(
"intersection_primaryTrackMom0_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1063 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom0pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1064 else mHistograms.at(
"intersection_primaryTrackMom0neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1066 else if( pMom > 0.5 ) {
1067 mHistograms.at(
"intersection_primaryTrackMom1_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1068 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom1pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1069 else mHistograms.at(
"intersection_primaryTrackMom1neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1072 mHistograms.at(
"intersection_primaryTrackMom2_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1073 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom2pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1074 else mHistograms.at(
"intersection_primaryTrackMom2neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1080 if( mDoQA && nCrossings > 0 ) {
1083 mHistograms.at(
"intersection_track_pt_eta" )->Fill( eTrack.pt, eTrack.eta );
1084 mHistograms.at(
"intersection_track_pt_phi" )->Fill( eTrack.pt, eTrack.phi );
1085 mHistograms.at(
"intersection_track_phi_eta" )->Fill( eTrack.phi, eTrack.eta );
1087 mHistograms.at(
"intersection_track_nHitsTpc" )->Fill( eTrack.nFtPts );
1089 if( eTrack.dEdx > 0. ) mHistograms.at(
"intersection_track_mom_dEdx" )->Fill( eTrack.pt * cosh( eTrack.eta ), eTrack.dEdx );
1090 if( eTrack.nSigmaPion > -999. ) mHistograms.at(
"intersection_track_mom_nsigmaPi" )->Fill( eTrack.pt * cosh( eTrack.eta ), eTrack.nSigmaPion );
1098 mHistograms.at(
"intersectionMult" )->Fill( intersectionVec.size() );
1099 mHistograms.at(
"intersectionMult_primary" )->Fill( nPrimaryCrossings );
1101 if( intersectionVec.size() > 0 ) {
1102 mHistograms.at(
"eventCounter" )->Fill( 4 );
1111 StETofMatchMaker::validTrack(
const StTrack* track )
1114 return validTrack(
ETofTrack( track ) );
1124 StETofMatchMaker::validTrack(
const StMuTrack* track )
1127 return validTrack(
ETofTrack( track ) );
1137 StETofMatchMaker::validTrack(
const ETofTrack& track )
1139 double ratioFitToPoss = 1. * track.nFtPts / track.nHitsPoss;
1142 mHistograms.at(
"track_phi_eta" ) ->Fill( track.phi, track.eta );
1143 mHistograms.at(
"track_phi_pt" ) ->Fill( track.phi, track.pt );
1144 mHistograms.at(
"nHits" ) ->Fill( track.nFtPts );
1145 mHistograms.at(
"track_pt_nHits" )->Fill( track.pt, track.nFtPts );
1150 if( track.eta > etofProjection::minEtaCut )
return false;
1152 if( mDoQA && track.eta > -1.65 && track.eta < -1.05 ) {
1153 mHistograms.at(
"nHits_etofregion" )->Fill( track.nFtPts );
1159 if( track.nFtPts < mTrackCuts.at( 0 ) )
return false;
1160 if( ratioFitToPoss < mTrackCuts.at( 1 ) )
return false;
1161 if( track.pt < mTrackCuts.at( 2 ) )
return false;
1165 LOG_DEBUG <<
"valid track for extrapolation to eTOF with nHitsFit: " << track.nFtPts;
1166 LOG_DEBUG <<
" mom: " << track.mom <<
" pt: " << track.pt <<
" phi: " << track.phi <<
" eta: " << track.eta << endm;
1174 StETofMatchMaker::extrapolateTrackToETof( eTofHitVec& intersectionVec,
const StPhysicalHelixD& theHelix,
const int& iNode,
int& nCrossings,
bool isPrimary )
1177 StThreeVectorD projection = mETofGeom->helixCrossPlane( theHelix, eTofConst::zplanes[ 1 ] );
1180 float projEta = projection.pseudoRapidity();
1182 if( projEta < etofProjection::maxEtaProjCut )
return;
1183 if( projEta > etofProjection::minEtaProjCut )
return;
1185 float projPhi = projection.phi();
1186 if ( projPhi < 0. ) projPhi += 2. * M_PI;
1190 mHistograms.at(
"trackProj_globalXY" )->Fill( projection.x(), projection.y() );
1191 mHistograms.at(
"trackProj_phi_eta" )->Fill( projPhi, projEta );
1194 vector< int > idVec;
1195 vector< StThreeVectorD > globalVec;
1196 vector< StThreeVectorD > localVec;
1197 vector< double > thetaVec;
1198 vector< double > pathLenVec;
1201 mETofGeom->
helixCrossCounter( theHelix, idVec, globalVec, localVec, thetaVec, pathLenVec );
1203 nCrossings = idVec.size();
1207 for(
int i = nCrossings-1; i >= 0; i-- ) {
1209 LOG_INFO <<
" ------> crossing with volume index: " << idVec.at( i ) << endm;
1210 LOG_INFO <<
"track intersection: " << globalVec.at( i ).x() <<
", " << globalVec.at( i ).y() <<
", " << globalVec.at( i ).z() << endm;
1211 LOG_INFO <<
"local coordinates: " << localVec.at( i ).x() <<
", " << localVec.at( i ).y() <<
", " << localVec.at( i ).z() << endm;
1214 StructETofHit intersect;
1216 mETofGeom->decodeVolumeIndex( idVec.at( i ), intersect.sector, intersect.plane, intersect.counter, intersect.strip );
1218 intersect.localX = localVec.at( i ).x();
1219 intersect.localY = localVec.at( i ).y();
1220 intersect.globalPos = globalVec.at( i );
1221 intersect.trackId = iNode;
1222 intersect.theta = thetaVec.at( i );
1223 intersect.pathLength = pathLenVec.at( i );
1224 intersect.isPrimary = isPrimary;
1227 intersectionVec.push_back( intersect );
1231 float intersectPhi = intersect.globalPos.phi();
1232 if( intersectPhi < 0. ) intersectPhi += 2. * M_PI;
1234 mHistograms.at(
"intersection_globalXY" )->Fill( intersect.globalPos.x(), intersect.globalPos.y() );
1235 mHistograms.at(
"intersection_phi_eta" )->Fill( intersectPhi, intersect.globalPos.pseudoRapidity() );
1240 mHistograms.at(
"intersection_perTrack" )->Fill( idVec.size() );
1250 StETofMatchMaker::matchETofHits( eTofHitVec& detectorHitVec, eTofHitVec& intersectionVec, eTofHitVec& matchCandVec )
1252 for(
auto detHitIter = detectorHitVec.begin(); detHitIter != detectorHitVec.end(); detHitIter++ ) {
1253 for(
auto interIter = intersectionVec.begin(); interIter != intersectionVec.end(); interIter++ ) {
1256 int sector = detHitIter->sector;
1257 int plane = detHitIter->plane;
1259 int moduleId = ( sector - eTofConst::sectorStart ) * eTofConst::nPlanes + plane - eTofConst::zPlaneStart;
1262 int detHitIndex = ( detHitIter->counter - eTofConst::counterStart ) * eTofConst::nStrips + detHitIter->strip - eTofConst::stripStart;
1263 int intersecIndex = ( interIter->counter - eTofConst::counterStart ) * eTofConst::nStrips + interIter->strip - eTofConst::stripStart;
1265 mHistograms.at(
"detHitvsInter_strip_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) )->Fill( detHitIndex, intersecIndex );
1267 mHistograms.at(
"detHitvsInter_X" )->Fill( detHitIter->globalPos.x(), interIter->globalPos.x() );
1268 mHistograms.at(
"detHitvsInter_Y" )->Fill( detHitIter->globalPos.y(), interIter->globalPos.y() );
1270 mHistograms.at(
"moduleIndex_deltaX" )->Fill( moduleId, detHitIter->localX - interIter->localX );
1271 mHistograms.at(
"moduleIndex_deltaY" )->Fill( moduleId, detHitIter->localY - interIter->localY );
1273 mHistograms.at(
"detHitvsInter_localX" )->Fill(detHitIter->localX, interIter->localX );
1274 mHistograms.at(
"detHitvsInter_localY" )->Fill(detHitIter->localY, interIter->localY );
1279 bool isMatch =
false;
1282 float deltaX = detHitIter->localX - interIter->localX;
1283 float deltaY = detHitIter->localY - interIter->localY;
1284 double tstart = startTimeBTof();
1285 double deltaT = detHitIter->hitTime - tstart;
1287 int counterIndex = ( detHitIter->sector - eTofConst::sectorStart ) * eTofConst::nPlanes * eTofConst::nCounters
1288 + ( detHitIter->plane - eTofConst::zPlaneStart ) * eTofConst::nCounters
1289 + ( detHitIter->counter - eTofConst::counterStart );
1291 deltaX -= etofProjection::deltaXoffset[ counterIndex ];
1292 deltaY -= etofProjection::deltaYoffset[ counterIndex ];
1294 bool corrTime=
false;
1296 if( detHitIter->sector == interIter->sector ) {
1297 if( detHitIter->plane == interIter->plane ) {
1298 if( detHitIter->counter == interIter->counter ) {
1300 if(detHitIter->clusterSize < 999){
1305 if( ( ( (deltaY*deltaY) / (mMatchDistY*mMatchDistY) ) + ( (deltaX*deltaX) / (mMatchDistX*mMatchDistX) ) ) < 2. ) {
1306 if( fabs( deltaT ) < mMatchDistT ) {
1312 float mMatchDistYSingleSided = 15;
1316 if( fabs( deltaX ) < mMatchDistX ) {
1317 if( fabs( deltaY ) < mMatchDistYSingleSided ) {
1318 if( fabs( deltaT ) < mMatchDistT ) {
1334 StructETofHit matchCand;
1336 matchCand.sector = detHitIter->sector;
1337 matchCand.plane = detHitIter->plane;
1338 matchCand.counter = detHitIter->counter;
1339 matchCand.strip = detHitIter->strip;
1340 matchCand.localX = detHitIter->localX;
1341 matchCand.localY = detHitIter->localY;
1342 matchCand.hitTime = detHitIter->hitTime;
1343 matchCand.tot = detHitIter->tot;
1344 matchCand.clusterSize = detHitIter->clusterSize;
1345 matchCand.index2ETofHit = detHitIter->index2ETofHit;
1346 matchCand.IdTruthHit = detHitIter->IdTruth;
1348 matchCand.globalPos = interIter->globalPos;
1349 matchCand.trackId = interIter->trackId;
1350 matchCand.theta = interIter->theta;
1351 matchCand.pathLength = interIter->pathLength;
1352 matchCand.isPrimary = interIter->isPrimary;
1353 matchCand.IdTruth = interIter->IdTruth;
1355 matchCand.matchFlag = 0;
1356 matchCand.deltaX = deltaX;
1357 matchCand.deltaY = deltaY;
1359 matchCand.tof = -999.;
1360 matchCand.beta = -999.;
1364 matchCand.localY = interIter->localY;
1369 if(sector == 15 || sector == 17 || sector == 21 || sector == 22 ){
1374 if(detHitIter->localY < 0){
1375 matchCand.hitTime = detHitIter->hitTime - (((13.5 + interIter->localY ) / tcorr )) + (13.5/tcorr);
1377 corr = (((13.5 - interIter->localY ) / tcorr ));
1380 matchCand.hitTime = detHitIter->hitTime - (((13.5 - interIter->localY ) / tcorr )) + (13.5/tcorr);
1382 corr = (((13.5 + interIter->localY ) / tcorr ));
1385 matchCand.totDiff = matchCand.totDiff * corr;
1393 matchCandVec.push_back( matchCand );
1396 LOG_INFO <<
" * * FOUND MATCH CAND : " << matchCand.sector <<
" " << matchCand.plane <<
" " << matchCand.counter;
1397 LOG_INFO <<
" with (deltaX, deltaY) = (" << deltaX <<
", " << deltaY <<
")" << endm;
1400 mHistograms.at(
"matchCand_globalXY" )->Fill( matchCand.globalPos.x(), matchCand.globalPos.y() );
1403 float matchCandPhi = matchCand.globalPos.phi();
1404 if ( matchCandPhi < 0. ) matchCandPhi += 2. * M_PI;
1406 mHistograms.at(
"matchCand_phi_eta" )->Fill( matchCandPhi, matchCand.globalPos.pseudoRapidity() );
1408 mHistograms.at(
"matchCand_deltaX" )->Fill( deltaX );
1409 mHistograms.at(
"matchCand_deltaY" )->Fill( deltaY );
1411 std::string histName_deltaX =
"matchCand_deltaX_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
1412 std::string histName_deltaY =
"matchCand_deltaY_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
1414 mHistograms.at( histName_deltaX )->Fill( deltaX );
1415 mHistograms.at( histName_deltaY )->Fill( deltaY );
1419 if( mIsStEventIn ) {
1420 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
1422 if( matchCandTrack ) {
1423 int nFitPts = matchCandTrack->fitTraits().numberOfFitPoints( kTpcId );
1425 mHistograms.at(
"matchCand_deltaX_nHitsTpc" )->Fill( nFitPts, deltaX );
1426 mHistograms.at(
"matchCand_deltaY_nHitsTpc" )->Fill( nFitPts, deltaY );
1431 if( matchCandTrack ) {
1432 int nFitPts = matchCandTrack->
nHitsFit( kTpcId );
1434 mHistograms.at(
"matchCand_deltaX_nHitsTpc" )->Fill( nFitPts, deltaX );
1435 mHistograms.at(
"matchCand_deltaY_nHitsTpc" )->Fill( nFitPts, deltaY );
1445 mHistograms.at(
"matchCandMult" )->Fill( matchCandVec.size() );
1447 if( matchCandVec.size() > 0 ) {
1448 mHistograms.at(
"eventCounter" )->Fill( 5 );
1459 StETofMatchMaker::sortSingleMultipleHits( eTofHitVec& matchCandVec, eTofHitVec& singleTrackMatchVec, std::vector< eTofHitVec >& multiTrackMatchVec )
1461 int nSingleTrackMatch = 0;
1462 int nMultiTrackMatch = 0;
1466 eTofHitVec tempVec = matchCandVec;
1467 eTofHitVec erasedVec = tempVec;
1469 while( tempVec.size() != 0 ) {
1475 eTofHitVecIter tempIter = tempVec.begin();
1476 eTofHitVecIter erasedIter = erasedVec.begin();
1478 while( erasedIter != erasedVec.end() ) {
1480 if( tempIter->index2ETofHit == erasedIter->index2ETofHit ) {
1482 candVec.push_back( *erasedIter );
1484 erasedVec.erase( erasedIter );
1490 tempVec = erasedVec;
1492 StructETofHit cand = candVec.front();
1495 LOG_INFO <<
"matchCand at sector " << cand.sector <<
" plane " << cand.plane <<
" counter " << cand.counter <<
" with local (X,Y) = (" << cand.localX <<
"," << cand.localY <<
")";
1496 LOG_INFO <<
" has " << nTracks <<
" track(s) pointing to it:" << endm;
1499 if( nTracks == 1 ) {
1500 nSingleTrackMatch++;
1501 singleTrackMatchVec.push_back( cand );
1504 LOG_INFO <<
"track id: " << cand.trackId <<
" and matching distance " << cand.deltaX <<
" " << cand.deltaY << endm;
1507 else if( nTracks > 1 ) {
1512 multiTrackMatchVec.push_back( candVec );
1514 float bestResidual = 999.;
1517 for(
size_t i=0; i<candVec.size(); i++ ) {
1519 LOG_INFO <<
"track id: " << candVec.at( i ).trackId <<
" and matching distance " << candVec.at( i ).deltaX <<
" " << candVec.at( i ).deltaY << endm;
1521 float residual = pow( candVec.at( i ).deltaX, 2 ) + pow( candVec.at( i ).deltaY, 2 );
1523 if( residual < bestResidual ) {
1524 bestResidual = residual;
1529 if( bestIndex > -1 ) {
1530 singleTrackMatchVec.push_back( candVec.at( bestIndex ) );
1532 LOG_INFO <<
"best candidate has track id: " << candVec.at( bestIndex ).trackId << endm;
1537 for(
const auto& c: candVec ) {
1538 LOG_INFO <<
"track id: " << c.trackId <<
" and matching distance " << c.deltaX <<
" " << c.deltaY << endm;
1544 mHistograms.at(
"trackMatchMultPerDetectorHit" )->Fill( nTracks );
1551 mHistograms.at(
"singleTrackMatchMult" )->Fill( singleTrackMatchVec.size() );
1553 if( singleTrackMatchVec.size() > 0 ) {
1554 mHistograms.at(
"eventCounter" )->Fill( 6 );
1566 StETofMatchMaker::finalizeMatching( eTofHitVec& singleTrackMatchVec, eTofHitVec& finalMatchVec )
1569 eTofHitVec tempVec = singleTrackMatchVec;
1570 eTofHitVec erasedVec = tempVec;
1572 while( tempVec.size() != 0 ) {
1578 eTofHitVecIter tempIter = tempVec.begin();
1579 eTofHitVecIter erasedIter = erasedVec.begin();
1581 while( erasedIter != erasedVec.end() ) {
1583 if( tempIter->trackId == erasedIter->trackId ) {
1585 candVec.push_back( *erasedIter );
1587 erasedVec.erase( erasedIter );
1593 tempVec = erasedVec;
1597 candVec.front().matchFlag = 1;
1598 finalMatchVec.push_back( candVec.front() );
1601 LOG_INFO <<
"one-to-one match (track id: " << candVec.front().trackId <<
") -> pushed into final match vector" << endm;
1605 else if ( nHits > 1 ) {
1607 LOG_INFO <<
"one-to-many match -> needs further treatment" << endm;
1611 double bestMatchDist = pow( candVec.front().deltaX, 2 ) + pow( candVec.front().deltaY, 2 );
1612 StructETofHit bestCand = candVec.front();
1614 bool isOverlapHit =
false;
1616 for(
const auto& c: candVec ) {
1617 double candMatchDist = pow( c.deltaX, 2 ) + pow( c.deltaY, 2 );
1620 LOG_INFO <<
"candidate match distance: " << sqrt( candMatchDist ) << endm;
1623 if( candMatchDist < bestMatchDist ) {
1624 bestMatchDist = candMatchDist;
1628 LOG_INFO <<
" --> new best match candidate" << endm;
1632 if( ( bestCand.sector * 100 + bestCand.plane * 10 + bestCand.counter ) != ( c.sector * 100 + c.plane * 10 + c.counter ) ) {
1633 isOverlapHit =
true;
1637 if( isOverlapHit ) {
1638 bestCand.matchFlag = 3;
1641 mHistograms.at(
"overlapHit_globalXY" )->Fill( bestCand.globalPos.x(), bestCand.globalPos.y() );
1645 bestCand.matchFlag = 2;
1648 finalMatchVec.push_back( bestCand );
1651 LOG_INFO <<
"one-to-many match resolved (track id: " << bestCand.trackId <<
", cand deltaX: " << bestCand.deltaX <<
") -> pushed into final match vector" << endm;
1656 mHistograms.at(
"hitMultPerTrack" )->Fill( nHits );
1661 if( mIsStEventIn ) {
1662 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
1663 for(
const auto& v: finalMatchVec ) {
1666 mHistograms.at(
"finalMatch_pt" )->Fill( track->geometry()->momentum().perp() );
1670 for(
const auto& v: finalMatchVec ) {
1673 mHistograms.at(
"finalMatch_pt" )->Fill( track->
momentum().perp() );
1677 mHistograms.at(
"finalMatchMult" )->Fill( finalMatchVec.size() );
1679 if( finalMatchVec.size() > 0 ) {
1680 mHistograms.at(
"eventCounter" )->Fill( 7 );
1691 StETofMatchMaker::fillPidTraits( eTofHitVec& finalMatchVec )
1693 size_t nFinalMatchesGlobal = 0;
1694 size_t nFinalMatchesPrimary = 0;
1696 if( mIsStEventIn ) {
1698 StSPtrVecETofHit& etofHits = mEvent->etofCollection()->etofHits();
1699 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
1701 for(
const auto& match : finalMatchVec ) {
1704 if( !globalTrack ) {
1705 LOG_WARN <<
"fillPidTraits() - global track does not exist" << endm;
1712 LOG_WARN <<
"fillPidTraits() - eTof hit does not exist" << endm;
1715 hit->setAssociatedTrack( globalTrack );
1717 nFinalMatchesGlobal++;
1723 pidTraits->setMatchFlag( match.matchFlag );
1724 pidTraits->setLocalX( match.localX );
1725 pidTraits->setLocalY( match.localY );
1726 pidTraits->setThetaLocal( match.theta );
1727 pidTraits->setDeltaX( match.deltaX );
1728 pidTraits->setDeltaY( match.deltaY );
1729 pidTraits->setPosition( match.globalPos );
1731 pidTraits->setPathLength( match.pathLength );
1733 pidTraits->setTimeOfFlight( -999. );
1734 pidTraits->setBeta( -999. );
1736 globalTrack->addPidTraits( pidTraits );
1741 nFinalMatchesPrimary++;
1744 mHistograms.at(
"finalMatchPrimary_globalXY" )->Fill( match.globalPos.x(), match.globalPos.y() );
1746 float mom = pTrack->geometry()->momentum().mag();
1748 mHistograms.at(
"finalMatchPrimaryMom0_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1750 else if( mom > 0.5 ) {
1751 mHistograms.at(
"finalMatchPrimaryMom1_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1754 mHistograms.at(
"finalMatchPrimaryMom2_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1761 ppidTraits->setMatchFlag( match.matchFlag );
1762 ppidTraits->setLocalX( match.localX );
1763 ppidTraits->setLocalY( match.localY );
1764 ppidTraits->setThetaLocal( match.theta );
1765 ppidTraits->setDeltaX( match.deltaX );
1766 ppidTraits->setDeltaY( match.deltaY );
1767 ppidTraits->setPosition( match.globalPos );
1769 ppidTraits->setPathLength( match.pathLength );
1771 ppidTraits->setTimeOfFlight( -999. );
1772 ppidTraits->setBeta( -999. );
1774 pTrack->addPidTraits( ppidTraits );
1779 for(
const auto& match : finalMatchVec ) {
1783 LOG_WARN <<
"fillPidTraits() - global track does not exist" << endm;
1790 LOG_WARN <<
"fillPidTraits() - eTof hit does not exist" << endm;
1793 hit->setAssociatedTrackId( gTrack->
id() );
1794 hit->setIndex2Global( match.trackId );
1797 nFinalMatchesGlobal++;
1801 pidTraits.setMatchFlag( match.matchFlag );
1802 pidTraits.setLocalX( match.localX );
1803 pidTraits.setLocalY( match.localY );
1804 pidTraits.setThetaLocal( match.theta );
1805 pidTraits.setDeltaX( match.deltaX );
1806 pidTraits.setDeltaY( match.deltaY );
1807 pidTraits.setPosition( match.globalPos );
1809 pidTraits.setPathLength( match.pathLength );
1811 pidTraits.setTimeOfFlight( -999. );
1812 pidTraits.setBeta( -999. );
1817 auto it = mIndex2Primary.find( match.trackId );
1818 if( it != mIndex2Primary.end() ) {
1819 pIndex = it->second;
1821 if( pIndex < 0 )
continue;
1825 nFinalMatchesPrimary++;
1828 mHistograms.at(
"finalMatchPrimary_globalXY" )->Fill( match.globalPos.x(), match.globalPos.y() );
1830 float mom = pTrack->
momentum().mag();
1832 mHistograms.at(
"finalMatchPrimaryMom0_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1834 else if( mom > 0.5 ) {
1835 mHistograms.at(
"finalMatchPrimaryMom1_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1838 mHistograms.at(
"finalMatchPrimaryMom2_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1843 hit->setIndex2Primary( pIndex );
1847 ppidTraits.setMatchFlag( match.matchFlag );
1848 ppidTraits.setLocalX( match.localX );
1849 ppidTraits.setLocalY( match.localY );
1850 ppidTraits.setThetaLocal( match.theta );
1851 ppidTraits.setDeltaX( match.deltaX );
1852 ppidTraits.setDeltaY( match.deltaY );
1853 ppidTraits.setPosition( match.globalPos );
1855 ppidTraits.setPathLength( match.pathLength );
1857 ppidTraits.setTimeOfFlight( -999. );
1858 ppidTraits.setBeta( -999. );
1866 mHistograms.at(
"finalMatchMultGlobal" )->Fill( nFinalMatchesGlobal );
1867 mHistograms.at(
"finalMatchMultPrimary" )->Fill( nFinalMatchesPrimary );
1877 StETofMatchMaker::calculatePidVariables( eTofHitVec& finalMatchVec,
int& nPrimaryWithPid )
1880 double tstart = startTime( finalMatchVec );
1882 if( fabs( tstart + 9999. ) < 1.e-5 ) {
1883 LOG_WARN <<
"calculatePidVariables() -- no valid start time available ... skip filling pidTraits with more information" << endm;
1884 nPrimaryWithPid = -1;
1888 if( mIsStEventIn ) {
1890 for(
auto& matchCand : finalMatchVec ) {
1892 StETofHit* aHit =
dynamic_cast< StETofHit*
> ( mEvent->etofCollection()->etofHits().at( matchCand.index2ETofHit ) );
1894 LOG_ERROR <<
"calculatePidVariables() - no hit" << endm;
1901 LOG_ERROR <<
"calculatePidVariables() - no associated track" << endm;
1906 StSPtrVecTrackPidTraits& traits = gTrack->pidTraits();
1908 for(
size_t i=0; i<traits.size(); i++ ) {
1909 if( traits[ i ]->detector() == kETofId ) {
1914 if( !pidTraits )
continue;
1917 double tof = timeOfFlight( tstart, aHit->
time() );
1920 matchCand.tof = tof;
1922 pidTraits->setTimeOfFlight( tof );
1926 StTrack* pTrack = gTrack->node()->track( primary );
1929 StSPtrVecTrackPidTraits& ptraits = pTrack->pidTraits();
1930 for(
size_t i=0; i<ptraits.size(); i++ ) {
1931 if( ptraits[ i ]->detector() == kETofId ) {
1937 ppidTraits->setTimeOfFlight( tof );
1942 LOG_INFO <<
"calculatePidVariables() - time-of-flight assigned to pid traits: " << tof <<
" ..." << endm;
1949 double pathLength = matchCand.pathLength;
1954 LOG_INFO <<
"calculatePidVariables() - the associated track is not a primary one. Skip PID calculation! " << endm;
1958 const StVertex* pVtx = pTrack->vertex();
1961 LOG_INFO <<
"calculatePidVariables() - the associated track is not coming from any vertex. Skip PID calculation! " << endm;
1966 StPhysicalHelixD theHelix = mOuterTrackGeometry ? gTrack->outerGeometry()->helix() : gTrack->geometry()->helix();
1974 if( !doPID )
continue;
1977 matchCand.pathLength = pathLength;
1980 double beta = pathLength / ( tof * nanosecond * c_light );
1983 matchCand.beta = beta;
1986 LOG_INFO <<
"calculatePidVariables() - pathlength: " << pathLength <<
" time-of-flight: " << tof <<
" and beta: " << beta <<
" are set" << endm;
1990 mHistograms.at(
"matchCand_timeOfFlight" )->Fill( tof );
1991 mHistograms.at(
"matchCand_timeOfFlight_pathLength" )->Fill( tof, pathLength );
1993 mHistograms.at(
"matchCand_timeOfFlight_pathLength_zoom" )->Fill( tof, pathLength );
1995 pidTraits->setPathLength( pathLength );
1996 pidTraits->setBeta( beta );
1999 ppidTraits->setPathLength( pathLength );
2000 ppidTraits->setBeta( beta );
2006 LOG_INFO <<
"calculatePidVariables() - pathlength and beta assigned to pid traits ..." << endm;
2012 for(
auto& matchCand : finalMatchVec ) {
2016 LOG_ERROR <<
"calculatePidVariables() - no hit" << endm;
2021 StMuTrack* gTrack = aHit->globalTrack();
2023 LOG_ERROR <<
"calculatePidVariables() - no associated track" << endm;
2031 double tof = timeOfFlight( tstart, matchCand.hitTime );
2035 matchCand.tof = tof;
2038 pidTraits.setTimeOfFlight( tof );
2042 StMuTrack* pTrack = aHit->primaryTrack();
2047 ppidTraits.setTimeOfFlight( tof );
2052 LOG_INFO <<
"calculatePidVariables() - time-of-flight assigned to pid traits: " << tof <<
" ..." << endm;
2059 double pathLength = matchCand.pathLength;
2063 LOG_INFO <<
"calculatePidVariables() - the associated track is not a primary one. Skip PID calculation!" << endm;
2070 LOG_INFO <<
"calculatePidVariables() - the associated track is not coming from any vertex. Skip PID calculation!" << endm;
2083 if( !doPID )
continue;
2086 matchCand.pathLength = pathLength;
2089 double beta = pathLength / ( tof * nanosecond * c_light );
2092 matchCand.beta = beta;
2095 if( matchCand.clusterSize > 999 ){
2097 mHistograms.at(
"AAA_beta_mom_SD")->Fill( pTrack->
momentum().mag() , 1/beta );
2104 LOG_INFO <<
"calculatePidVariables() - pathlength: " << pathLength <<
" time-of-flight: " << tof <<
" and beta: " << beta <<
" are set" << endm;
2108 mHistograms.at(
"matchCand_timeOfFlight" )->Fill( tof );
2109 mHistograms.at(
"matchCand_timeOfFlight_pathLength" )->Fill( tof, pathLength );
2111 mHistograms.at(
"matchCand_timeOfFlight_pathLength_zoom" )->Fill( tof, pathLength );
2113 pidTraits.setPathLength( pathLength );
2114 pidTraits.setBeta( beta );
2118 ppidTraits.setPathLength( pathLength );
2119 ppidTraits.setBeta( beta );
2126 LOG_INFO <<
"calculatePidVariables() - pathlength and beta assigned to pid traits ..." << endm;
2136 StETofMatchMaker::startTimeBTof()
2139 LOG_INFO <<
"startTimeBTof(): -- loading start time from bTOF header" << endm;
2144 if( mIsStEventIn ) {
2147 if ( btofCollection ) {
2148 btofHeader = btofCollection->tofHeader();
2151 LOG_DEBUG <<
"startTimeBTof(): -- no StBTofCollection found by getTstart" << endm;
2155 else if( mIsMuDstIn ) {
2160 LOG_DEBUG <<
"startTimeBTof(): -- no bTOF header --> no start time avaiable" << endm;
2164 double tstart = btofHeader->tStart();
2166 if( !isfinite( tstart ) ) {
2167 LOG_DEBUG <<
"startTimeBTof(): -- from bTOF header is NaN" << endm;
2171 if( tstart != -9999. ) {
2172 tstart = fmod( tstart, eTofConst::bTofClockCycle );
2173 if( tstart < 0 ) tstart += eTofConst::bTofClockCycle;
2177 LOG_DEBUG <<
"startTimeBTof(): -- start time: " << tstart << endm;
2186 StETofMatchMaker::startTimeETof(
const eTofHitVec& finalMatchVec,
unsigned int& nCand_etofT0 )
2189 LOG_INFO <<
"startTimeETof(): -- calculating start time from eTOF matches" << endm;
2191 std::vector< double > t0_cand;
2196 for(
auto& match : finalMatchVec ) {
2197 if( !match.isPrimary )
continue;
2199 if( sqrt( pow( match.deltaX, 2 ) + pow( match.deltaY, 2 ) ) > etofProjection::deltaRcut )
continue;
2201 double pathLength = match.pathLength;
2206 double nsigmaPi = -999.;
2207 double nsigmaK = -999.;
2208 double nsigmaP = -999.;
2210 if( mIsStEventIn ) {
2211 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
2226 momentum = pTrack->geometry()->momentum().mag();
2227 charge = pTrack->geometry()->charge();
2230 static StPionPlus* Pion = StPionPlus::instance();
2231 static StKaonPlus* Kaon = StKaonPlus::instance();
2232 static StProton* Proton = StProton::instance();
2235 if( pd && PidAlgorithm.traits() ) {
2236 nsigmaPi = PidAlgorithm.numberOfSigma( Pion );
2237 nsigmaK = PidAlgorithm.numberOfSigma( Kaon );
2238 nsigmaP = PidAlgorithm.numberOfSigma( Proton );
2241 StPhysicalHelixD theHelix = mOuterTrackGeometry ? gTrack->outerGeometry()->helix() : gTrack->geometry()->helix();
2242 pathLength -= theHelix.
pathLength( pTrack->vertex()->position() );
2246 if( !aHit )
continue;
2249 StMuTrack* gTrack = aHit->globalTrack();
2250 if( !gTrack )
continue;
2253 StMuTrack* pTrack = aHit->primaryTrack();
2254 if( !pTrack )
continue;
2257 momentum = pTrack->
momentum().mag();
2258 charge = pTrack->
charge();
2268 if( momentum < 0.2 )
continue;
2273 if( momentum < 0.6 && fabs( nsigmaPi ) < 2. ) {
2274 tofExpect = expectedTimeOfFlight( pathLength, momentum, pion_minus_mass_c2 );
2276 LOG_INFO <<
"startTimeETof(): -- using a pion as start time candidate" << endm;
2279 else if( momentum < 0.5 && fabs( nsigmaK ) < 1. ) {
2280 tofExpect = expectedTimeOfFlight( pathLength, momentum, kaon_minus_mass_c2 );
2282 LOG_INFO <<
"startTimeETof(): -- using a kaon as start time candidate" << endm;
2285 else if( momentum < 0.9 && charge == 1 && fabs( nsigmaP ) < 2. ) {
2286 tofExpect = expectedTimeOfFlight( pathLength, momentum, proton_mass_c2 );
2288 LOG_INFO <<
"startTimeETof(): -- using a proton as start time candidate" << endm;
2295 t0_cand.push_back( match.hitTime - tofExpect );
2296 t0_sum += t0_cand.back();
2299 LOG_INFO << match.hitTime <<
" " << tofExpect <<
" " << t0_cand.back() << endm;
2303 nCand_etofT0 = t0_cand.size();
2305 if( nCand_etofT0 == 0 ) {
2308 else if( nCand_etofT0 > 1 ) {
2309 for(
unsigned int i=0; i < nCand_etofT0; i++ ) {
2311 double t0_diff = t0_cand.at( i ) - ( t0_sum - t0_cand.at( i ) ) / ( nCand_etofT0 - 1 );
2313 if( fabs( t0_diff ) > 5.0 ) {
2314 t0_sum -= t0_cand.at( i );
2320 if( nCand_etofT0 < 2 ) {
2325 double tStart = fmod( t0_sum / nCand_etofT0, eTofConst::bTofClockCycle );
2326 if( tStart < 0 ) tStart += eTofConst::bTofClockCycle;
2335 StETofMatchMaker::moduloDist(
const double& dist,
const double& mod ) {
2336 return dist - mod * round( dist / mod );
2342 StETofMatchMaker::startTime(
const eTofHitVec& finalMatchVec ) {
2348 double tstartBTof = startTimeBTof();
2350 if( mUseOnlyBTofHeaderStartTime ) {
2355 unsigned int nCand_etofT0 = 0;
2356 double tstartETof = startTimeETof( finalMatchVec, nCand_etofT0 );
2358 double t0Diff = moduloDist( tstartETof - tstartBTof, eTofConst::bTofClockCycle );
2363 if( mDoQA && tstartBTof != -9999. && tstartETof != -9999. ) {
2364 mHistograms.at(
"startTimeDiff" )->Fill( t0Diff );
2365 mHistograms.at(
"startTimeDiff_nCand" )->Fill( t0Diff, nCand_etofT0 );
2370 if( tstartBTof != -9999. && tstartETof != -9999. && nCand_etofT0 > etofHybridT0::minCand ) {
2371 if( mT0corr != 0 && fabs( moduloDist( t0Diff - mT0corr, eTofConst::bTofClockCycle ) ) > etofHybridT0::diffToClear ) {
2374 LOG_INFO <<
"mT0switch: " << mT0switch << endm;
2377 if( mT0switch > etofHybridT0::nSwitch ) {
2379 mT0corrVec.push_back( t0Diff );
2383 LOG_INFO <<
"startTime(): -- cleared T0 correction vector since the start time (eTof <-> bTOF) seems to have changed" << endm;
2388 mT0corrVec.push_back( t0Diff );
2392 if( ( mT0corr != 0. || mT0corrVec.size() >= etofHybridT0::nMin ) && mT0corrVec.size() % etofHybridT0::nUpdate == 0 ) {
2393 std::sort( mT0corrVec.begin(), mT0corrVec.end() );
2396 for(
const auto& v : mT0corrVec ) {
2397 LOG_DEBUG <<
"startTime(): -- T0corrVec: " << v << endm;
2404 if( mT0corr == 0. ) {
2405 mT0corr = mT0corrVec.at( mT0corrVec.size() / 2 );
2406 for(
auto it = mT0corrVec.begin(); it != mT0corrVec.end(); it++ ) {
2407 if( fabs( *it - mT0corr ) > 0.5 ) {
2408 mT0corrVec.erase( it-- );
2411 mT0corr = mT0corrVec.at( mT0corrVec.size() / 2 );
2414 for(
auto it = mT0corrVec.begin(); it != mT0corrVec.end(); it++ ) {
2415 if( fabs( *it - mT0corr ) > 0.2 ) {
2416 mT0corrVec.erase( it-- );
2419 mT0corr = mT0corrVec.at( mT0corrVec.size() / 2 );
2424 for(
auto it = mT0corrVec.begin(); it != mT0corrVec.end(); it++ ) {
2425 if( fabs( *it - mT0corr ) > 0.5 ) {
2426 mT0corrVec.erase( it-- );
2431 for(
const auto& v : mT0corrVec ) {
2432 LOG_DEBUG <<
"startTime(): -- cleaned T0corrVec: " << v << endm;
2438 int low = floor( mT0corrVec.size() * etofHybridT0::lowCut );
2439 int high = floor( mT0corrVec.size() * etofHybridT0::highCut );
2443 for(
int i = low; i < high; i++ ) {
2445 LOG_DEBUG <<
"startTime(): -- T0corrVec: " << mT0corrVec.at( i ) << endm;
2448 temp += mT0corrVec.at( i );
2452 if( nAccept >= 5 ) {
2453 mT0corr = ( temp / nAccept ) - etofHybridT0::biasOffset;
2457 LOG_INFO <<
"startTime(): -- hybrid T0 correction between eTOF & bTOF (update " << mNupdatesT0 <<
"): " << mT0corr <<
" (" << nAccept <<
")" << endm;
2459 mHistograms.at(
"startTime_T0corr" )->SetBinContent( mNupdatesT0 , mT0corr );
2468 if( mT0corr != 0. && tstartBTof != -9999. ) {
2469 tstart = fmod( moduloDist( tstartBTof + mT0corr, eTofConst::bTofClockCycle ), eTofConst::bTofClockCycle );
2470 if( tstart < 0. ) tstart += eTofConst::bTofClockCycle;
2473 LOG_INFO <<
"startTime(): -- returning hybrid start time (BTof/VPD T0: " << tstartBTof <<
" T0 corr: " << mT0corr <<
"): " << tstart << endm;
2476 else if( tstartETof != -9999. && nCand_etofT0 > etofHybridT0::minCand ) {
2477 tstart = tstartETof;
2479 LOG_INFO <<
"startTime(): -- returning eTOF-only start time: " << tstart << endm;
2483 tstart = tstartBTof;
2486 LOG_INFO <<
"startTime(): -- returning bTOF/VPD start time: " << tstart << endm;
2497 StETofMatchMaker::timeOfFlight(
const double& startTime,
const double& stopTime )
2499 return moduloDist( stopTime - startTime, eTofConst::bTofClockCycle );
2506 StETofMatchMaker::expectedTimeOfFlight(
const double& pathLength,
const double& momentum,
const double& mass )
2508 double inverseBeta = sqrt( 1 + mass * mass / ( momentum * momentum ) );
2510 return pathLength * centimeter * ( 1. / c_light ) * inverseBeta / nanosecond;
2519 StETofMatchMaker::fillQaHistograms( eTofHitVec& finalMatchVec )
2522 vector< int > nPidMatches( 36 );
2524 for(
auto& matchCand : finalMatchVec ) {
2534 float nSigmaPion = -999;
2536 if( mIsStEventIn ) {
2538 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
2541 if( !gTrack )
continue;
2544 if( !pTrack )
continue;
2546 charge = pTrack->geometry()->charge();
2547 mom = pTrack->geometry()->momentum().mag();
2550 static StPionPlus* Pion = StPionPlus::instance();
2553 if( pd && PidAlgorithm.traits() ) {
2554 dEdx = PidAlgorithm.traits()->mean() * 1.e6;
2555 nSigmaPion = PidAlgorithm.numberOfSigma( Pion );
2561 if( !aHit )
continue;
2563 StMuTrack* pTrack = aHit->primaryTrack();
2564 if( !pTrack )
continue;
2570 charge = pTrack->
charge();
2573 dEdx = pTrack->
dEdx() * 1.e6;
2577 int sign = ( charge < 0 ) ? -1 : ( charge > 0 );
2578 float beta = matchCand.beta;
2581 if( fabs( beta + 999. ) < 0.001 ) {
2583 LOG_WARN <<
"beta not set --> no start time available???" << endm;
2589 float tofpi = expectedTimeOfFlight( matchCand.pathLength, mom, pion_plus_mass_c2 );
2591 mHistograms.at(
"matchCand_beta_signmom" )->Fill( sign * mom, 1. / beta );
2592 if( mom > 0.6 && mom < 1.5 ) {
2593 mHistograms.at(
"matchCand_t0corr_1d" )->Fill( matchCand.tof - tofpi );
2597 float tof = matchCand.tof;
2598 float pathlength = matchCand.pathLength;
2599 float m2 = mom * mom * ( -1 + 1 / ( beta * beta ) );
2604 if( fabs( tof+999. ) < 1.e-5 || fabs( pathlength+999. ) < 1.e-5 ) {
2605 LOG_INFO <<
"tof==0 or pathlength==0 ..." << endl;
2609 mHistograms.at(
"matchCand_beta_mom" )->Fill( mom, 1. / beta );
2610 mHistograms.at(
"matchCand_m2_mom" )->Fill( mom, m2 );
2611 mHistograms.at(
"matchCand_m2_signmom" )->Fill( sign * mom, m2 );
2616 std::string histName_beta_mom =
"matchCand_beta_mom_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
2617 mHistograms.at( histName_beta_mom )->Fill( mom, 1. / beta );
2619 std::string histName_t0corr_mom =
"matchCand_t0corr_mom_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
2620 mHistograms.at( histName_t0corr_mom )->Fill( mom, tof - tofpi );
2622 std::string histName_t0corr_mom_zoom =
"matchCand_t0corr_mom_zoom_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
2623 mHistograms.at( histName_t0corr_mom_zoom )->Fill( mom, tof - tofpi );
2625 if( nSigmaPion < 1.5 ) {
2626 std::string histName_t0corr_strip =
"matchCand_t0corr_strip_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
2627 mHistograms.at( histName_t0corr_strip )->Fill( matchCand.localX, tof - tofpi );
2630 if( nSigmaPion < 2. ) {
2631 if( matchCand.clusterSize >= 100 ) {
2633 std::string histName_t0corr_jump =
"matchCand_t0corr_jump_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
2634 mHistograms.at( histName_t0corr_jump )->Fill( matchCand.localX, tof - tofpi );
2636 int get4Index = matchCand.sector * 1000 + matchCand.plane * 100 + matchCand.counter * 10 + ( matchCand.localX + 16 ) / 4 + 1;
2637 mClockJumpCand[ get4Index ]++;
2642 if( sqrt( pow( matchCand.deltaX, 2 ) + pow( matchCand.deltaY, 2 ) ) < etofProjection::deltaRcut ) {
2644 mHistograms.at(
"matchCand_beta_mom_matchDistCut" )->Fill( mom, 1. / beta );
2645 mHistograms.at(
"matchCand_m2_mom_matchDistCut" )->Fill( mom, m2 );
2647 std::string histName_t0corr_mom_zoom_cut =
"matchCand_t0corr_mom_zoom_cut_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
2649 mHistograms.at( histName_t0corr_mom_zoom_cut )->Fill( mom, tof - tofpi );
2651 nPidMatches.at( ( matchCand.sector - 13 ) * 3 + matchCand.plane - 1 ) += 1;
2654 if( fabs( mom - 1 ) < 0.1 && dEdx > 0 ) mHistograms.at(
"matchCand_dEdx_beta_mom1gev" )->Fill( 1. / beta, dEdx );
2655 if( fabs( mom - 2 ) < 0.1 && dEdx > 0 ) mHistograms.at(
"matchCand_dEdx_beta_mom2gev" )->Fill( 1. / beta, dEdx );
2660 for(
size_t i=0; i<36; i++ ) {
2661 mHistograms.at(
"matchCandMultPerSector_matchDistCut" )->Fill( i, nPidMatches.at( i ) );
2667 StETofMatchMaker::fillSlewHistograms( eTofHitVec& finalMatchVec )
2669 if( !mDoQA || !mIsMuDstIn )
return;
2671 map< int, float > hitIndexToDeltaTmap;
2673 for(
auto& matchCand : finalMatchVec ) {
2675 if( !aHit )
continue;
2677 StMuTrack* pTrack = aHit->primaryTrack();
2678 if( !pTrack )
continue;
2680 float mom = pTrack->
momentum().mag();
2683 if( fabs( nSigmaPion > 1.5 ) )
continue;
2687 if( fabs( matchCand.beta + 999. ) < 0.001 ) {
2688 LOG_INFO <<
"beta not set --> no start time available???" << endm;
2692 float tof = matchCand.tof;
2693 float pathlength = matchCand.pathLength;
2695 if( fabs( tof+999. ) < 1.e-5 || fabs( pathlength+999. ) < 1.e-5 ) {
2696 LOG_INFO <<
"tof==0 or pathlength==0 ..." << endl;
2700 LOG_DEBUG <<
"for slewing: momentum: " << mom <<
" ... nsigmaPi: " << nSigmaPion <<
" tof:" << tof << endm;
2703 float tofpi = expectedTimeOfFlight( pathlength , mom, pion_plus_mass_c2 );
2704 hitIndexToDeltaTmap[ matchCand.index2ETofHit ] = tof - tofpi;
2708 size_t nDigis = mMuDst->numberOfETofDigi();
2709 for(
size_t i=0; i<nDigis; i++ ) {
2711 if( !aDigi )
continue;
2714 std::string histName_slewing =
"matchCand_slewing_digi_s" + std::to_string( aDigi->
sector() ) +
"m" + std::to_string( aDigi->
zPlane() ) +
"c" + std::to_string( aDigi->
counter() );
2715 mHistograms.at( histName_slewing )->Fill( aDigi->
calibTot(), hitIndexToDeltaTmap.at( aDigi->
associatedHitId() ) );
2724 StETofMatchMaker::trackGeometry(
StTrack* track )
const
2727 if ( !track )
return nullptr;
2731 if ( mOuterTrackGeometry ) {
2732 thisTrackGeometry = track->outerGeometry();
2735 thisTrackGeometry = track->geometry();
2738 return thisTrackGeometry;
2746 StETofMatchMaker::setHistFileName()
2748 string extension =
".etofMatch.root";
2750 if( GetChainOpt()->GetFileOut() !=
nullptr ) {
2751 TString outFile = GetChainOpt()->GetFileOut();
2753 mHistFileName = ( string ) outFile;
2756 size_t lastindex = mHistFileName.find_last_of(
"." );
2757 mHistFileName = mHistFileName.substr( 0, lastindex );
2760 lastindex = mHistFileName.find_last_of(
"." );
2761 mHistFileName = mHistFileName.substr( 0, lastindex );
2764 lastindex = mHistFileName.find_last_of(
"/" );
2765 mHistFileName = mHistFileName.substr( lastindex + 1, mHistFileName.length() );
2767 mHistFileName = mHistFileName + extension;
2769 LOG_ERROR <<
"Cannot set the output filename for histograms" << endm;
2776 StETofMatchMaker::bookHistograms()
2778 LOG_INFO <<
"bookHistograms" << endm;
2780 mHistograms[
"eTofHits_globalXY" ] =
new TH2F(
"A_eTofHits_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2781 mHistograms[
"intersectionMult_etofMult" ] =
new TH2F(
"B_intersectionMult_etofMult",
"multiplicity correlation;# eTOF hits;#track intersections;# events", 300, 0., 300., 200, 0., 200. );
2782 mHistograms[
"matchCand_globalXY" ] =
new TH2F(
"C_matchCand_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2783 mHistograms[
"matchCand_beta_signmom" ] =
new TH2F(
"G_matchCand_beta_signmom" ,
"match candidate 1/beta vs. momentum;q/|q| * p (GeV/c);1/#beta", 400, -4., 6., 1000, 0.8, 2. );
2784 mHistograms[
"matchCand_timeOfFlight_pathLength_zoom" ] =
new TH2F(
"G_matchCand_timeOfFlight_pathLength",
"match candidate pathlength vs. time of flight;ToF (ns);pathlength (cm)", 800, -25., 75., 800, 200., 600. );
2785 mHistograms[
"primaryIntersect_validMatch" ] =
new TH2F(
"G_primary_Intersection_validMatch",
"primary tracks at eTOF;# tracks with intersection;# tracks with valid PID", 200, 0., 200., 100, 0., 100. );
2786 mHistograms[
"matchCand_t0corr_1d" ] =
new TH1F(
"H_matchCand_t0corr_1d",
"measured tof - tof_{#pi};#Delta time (ns);counts", 3000, -15., 15. );
2789 AddHist( mHistograms.at(
"eTofHits_globalXY" ) );
2790 AddHist( mHistograms.at(
"intersectionMult_etofMult" ) );
2791 AddHist( mHistograms.at(
"matchCand_globalXY" ) );
2792 AddHist( mHistograms.at(
"matchCand_beta_signmom" ) );
2793 AddHist( mHistograms.at(
"matchCand_timeOfFlight_pathLength_zoom" ) );
2794 AddHist( mHistograms.at(
"primaryIntersect_validMatch" ) );
2795 AddHist( mHistograms.at(
"matchCand_t0corr_1d" ) );
2799 mHistograms[
"eTofSectors" ] =
new TH2F(
"QA_eTofSectors",
"center of modules in global XY;x (cm);y (cm)", 100, -300, 300, 100, -300, 300 );
2800 mHistograms[
"eTofModules" ] =
new TH2F(
"QA_eTofModules",
"center of modules in global XY;x (cm);y (cm)", 100, -300, 300, 100, -300, 300 );
2803 mHistograms2d[
"bfield_z" ] =
new TH2F(
"QA_bField_z",
"magnetic field (z);z (cm);y (cm)", 350, -350., 0., 300, 0., 300. );
2807 mHistograms[
"eventCounter" ] =
new TH1F(
"QA_eventCounter",
"eventCounter;;# events", 10, 0.5, 10.5 );
2813 mHistograms[
"eTofHits_phi_eta" ] =
new TH2F(
"A_eTofHits_phi_eta",
"eta vs. phi; #phi; #eta", 400, 0., 2 * M_PI, 400, -1.7, -0.9 );
2815 mHistograms[
"eTofHits_globalYZ" ] =
new TH2F(
"A_eTofHits_globalYZ",
"global YZ for sector 18 & 24;y (cm);z (cm)", 400, -300., 300., 100, -310., -270. );
2817 for(
int sector = eTofConst::sectorStart; sector <= eTofConst::sectorStop; sector++ ) {
2818 for(
int plane = eTofConst::zPlaneStart; plane <= eTofConst::zPlaneStop; plane++ ) {
2819 for(
int counter = eTofConst::counterStart; counter <= eTofConst::counterStop; counter++ ) {
2822 std::string histName_t0corr_mom_zoom =
"matched_t0corr_mom_zoom_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2824 mHistograms2d[ histName_t0corr_mom_zoom ] =
new TH2F( Form(
"T_matched_t0corr_mom_zoom_s%dm%dc%d", sector, plane, counter ), Form(
"measured tof - tof_{#pi} vs. momentum in sector %d module %d counter %d;mom (GeV/c);#Delta time (ns)", sector, plane, counter ), 200, 0., 3., 500, -5., 5. );
2827 std::string histName_t0corr_mom_zoom_SD =
"matched_t0corr_mom_zoom_SD_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2829 mHistograms2d[ histName_t0corr_mom_zoom_SD ] =
new TH2F( Form(
"T_matched_t0corr_mom_zoom_SD_s%dm%dc%d", sector, plane, counter ), Form(
"measured tof - tof_{#pi} vs. momentum in sector %d module %d counter %d;mom (GeV/c);#Delta time (ns)", sector, plane, counter ), 200, 0., 3., 500, -5., 5. );
2836 std::string histName_hit_localXY =
"eTofHits_localXY_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2837 std::string histName_hit_globalXY =
"eTofHits_globalXY_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2838 std::string histName_hit_eta_phi =
"eTofHits_phi_eta_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2841 mHistograms[ histName_hit_localXY ] =
new TH2F( Form(
"A_eTofHits_localXY_s%dm%dc%d", sector, plane, counter ), Form(
"local XY sector %d module %d counter %d;x (cm);y (cm)", sector, plane, counter ), 40, -20., 20., 50, -25., 25. );
2844 mHistograms[ histName_hit_globalXY ] =
new TH2F( Form(
"A_eTofHits_globalXY_s%dm%dc%d", sector, plane, counter ), Form(
"global XY sector %d module %d counter %d;x (cm);y (cm)", sector, plane, counter ), 200, -300., 300., 200, -300., 300. );
2847 mHistograms[ histName_hit_eta_phi ] =
new TH2F( Form(
"A_eTofHits_phi_eta_s%dm%dc%d", sector, plane, counter ), Form(
"eta vs. phi sector %d module %d counter %d; #phi; #eta", sector, plane, counter ), 200, 0., 2 * M_PI, 200, -1.7, -0.9 );
2850 std::string histName_t0corr_jump =
"matchCand_t0corr_jump_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2851 mHistograms[ histName_t0corr_jump ] =
new TH2F( Form(
"H_matchCand_t0corr_jump_s%dm%dc%d", sector, plane, counter ), Form(
"measured tof - tof_{#pi} vs. momentum in sector %d module %d counter %d;localX (cm) grouped by Get4;#Delta time (ns)", sector, plane, counter ), 8, -16., 16., 80, -20., 20. );
2859 mHistograms[
"detectorHitMult" ] =
new TH1F(
"A_detectorHitMult",
"detectorHitMult;multiplicity;# events", 200, 0., 200. );
2865 mHistograms[
"track_phi_eta" ] =
new TH2F(
"QA_track_phi_eta",
"eta vs. phi; #phi; #eta", 400, 0., 2 * M_PI, 800, -1.9, 1.9 );
2866 mHistograms[
"track_phi_pt" ] =
new TH2F(
"QA_track_phi_pt",
"pt vs. phi; #phi; p_{T}", 400, 0., 2 * M_PI, 400, 0., 5. );
2868 mHistograms[
"nHits" ] =
new TH1F(
"QA_nHits",
"nHitsTpc;nHitsFit;# tracks", 75, 0., 75. );
2869 mHistograms[
"nHits_etofregion" ] =
new TH1F(
"QA_nHits_etofregion",
"nHitsTpc in etof region;nHitsFit;# tracks", 75, 0., 75. );
2871 mHistograms[
"track_pt_nHits" ] =
new TH2F(
"QA_track_pt_nHits",
"track nHitsTpc vs. p_{T};p_{T} (GeV/c);nHitsFit", 400, 0., 2., 75, 0., 75. );
2873 mHistograms[
"trackProj_globalXY" ] =
new TH2F(
"QA_trackProj_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2874 mHistograms[
"trackProj_phi_eta" ] =
new TH2F(
"QA_trackProj_phi_eta",
"eta vs. phi; #phi; #eta", 400, 0., 2 * M_PI, 400, -1.7, -1.0 );
2881 mHistograms[
"intersection_globalXY" ] =
new TH2F(
"B_intersection_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2882 mHistograms[
"intersection_phi_eta" ] =
new TH2F(
"B_intersection_phi_eta",
"eta vs. phi; #phi; #eta", 400, 0., 2 * M_PI, 400, -1.7, -1.0 );
2884 mHistograms[
"intersectionMult" ] =
new TH1F(
"B_intersectionMult",
"intersectionMult;multiplicity;# events", 200, 0., 200. );
2885 mHistograms[
"intersectionMult_primary" ] =
new TH1F(
"B_intersectionMult_primary",
"intersectionMult for primary tracks;multiplicity;# events", 200, 0., 200. );
2887 mHistograms[
"intersection_perTrack" ] =
new TH1F(
"B_intersection_perTrack",
"intersections per track;# intersections;# tracks", 50, 0., 50. );
2891 mHistograms[
"intersection_primaryTrack_globalXY" ] =
new TH2F(
"B_intersection_primaryTrack_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2892 mHistograms[
"intersection_primaryTrackMom0_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom0_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2893 mHistograms[
"intersection_primaryTrackMom1_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom1_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2894 mHistograms[
"intersection_primaryTrackMom2_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom2_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2896 mHistograms[
"intersection_primaryTrackpos_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackpos_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2897 mHistograms[
"intersection_primaryTrackMom0pos_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom0pos_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2898 mHistograms[
"intersection_primaryTrackMom1pos_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom1pos_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2899 mHistograms[
"intersection_primaryTrackMom2pos_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom2pos_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2901 mHistograms[
"intersection_primaryTrackneg_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackneg_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2902 mHistograms[
"intersection_primaryTrackMom0neg_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom0neg_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2903 mHistograms[
"intersection_primaryTrackMom1neg_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom1neg_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2904 mHistograms[
"intersection_primaryTrackMom2neg_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom2neg_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2908 mHistograms[
"intersection_track_pt_eta" ] =
new TH2F(
"B_intersection_track_pt_eta",
"eta vs. pt;p_{T} (GeV/c);#eta", 400, 0., 5., 400, -2., -0.7 );
2909 mHistograms[
"intersection_track_pt_phi" ] =
new TH2F(
"B_intersection_track_pt_phi",
"phi vs. pt;p_{T} (GeV/c);#phi", 400, 0., 5., 400, 0., 2 * M_PI );
2910 mHistograms[
"intersection_track_phi_eta" ] =
new TH2F(
"B_intersection_track_phi_eta",
"eta vs. phi;#phi;#eta", 400, 0., 2 * M_PI, 400, -2., -0.9 );
2912 mHistograms[
"intersection_track_nHitsTpc" ] =
new TH1F(
"B_intersection_track_nHitsTpc",
"nHitsTpc;nHitsFit;# tracks", 75, 0., 75. );
2914 mHistograms[
"intersection_track_mom_dEdx" ] =
new TH2F(
"B_intersection_track_mom_dEdx",
"dE/dx vs. mom;mom (GeV/c);dE/dx (keV/cm)", 100, 0., 5., 100, 0., 10. );
2915 mHistograms[
"intersection_track_mom_nsigmaPi" ] =
new TH2F(
"B_intersection_track_mom_nsigmaPi",
"n#sigma_{#pi} vs. mom; mom (GeV/c);n#sigma_{#pi}", 100, 0., 5., 100, -10., 10. );
2921 mHistograms[
"detHitvsInter_X" ] =
new TH2F(
"C_detHitvsInter_X" ,
"detectorHit vs. intersection X;detectorHit X (cm);intersection X (cm)", 400, -300., 300., 400, -300., 300.);
2922 mHistograms[
"detHitvsInter_Y" ] =
new TH2F(
"C_detHitvsInter_Y" ,
"detectorHit vs. intersection Y;detectorHit Y (cm);intersection Y (cm)", 400, -300., 300., 400, -300., 300.);
2924 mHistograms[
"detHitvsInter_localX" ] =
new TH2F(
"C_detHitvsInter_localX" ,
"detectorHit vs. intersection X;detectorHit local X (cm);intersection local X (cm)", 40, -20., 20., 80, -20., 20.);
2925 mHistograms[
"detHitvsInter_localY" ] =
new TH2F(
"C_detHitvsInter_localY" ,
"detectorHit vs. intersection Y;detectorHit local Y (cm);intersection local Y (cm)", 200, -50., 50., 80, -20., 20.);
2928 for(
int sector = eTofConst::sectorStart; sector <= eTofConst::sectorStop; sector++ ) {
2929 for(
int plane = eTofConst::zPlaneStart; plane <= eTofConst::zPlaneStop; plane++ ) {
2930 std::string histName_detHitvsInter_strip =
"detHitvsInter_strip_s" + std::to_string( sector ) +
"m" + std::to_string( plane );
2932 mHistograms[ histName_detHitvsInter_strip ] =
new TH2F( Form(
"C_detHitvsInter_strip_s%dm%d", sector, plane ), Form(
"detectorHit vs. intersection on sector %d module %d;detectorHit strip;intersection strip", sector, plane ), 96, -0.5, 95.5, 96, -0.5, 95.5 );
2936 mHistograms[
"moduleIndex_deltaX" ] =
new TH2F(
"C_moduleIndex_deltaX",
"module index vs. local #Delta X;module index;#DeltaX (cm)", 36, -0.5, 35.5, 100, -50., 50. );
2937 mHistograms[
"moduleIndex_deltaY" ] =
new TH2F(
"C_moduleIndex_deltaY",
"module index vs. local #Delta Y;module index;#DeltaY (cm)", 36, -0.5, 35.5, 100, -50., 50. );
2939 mHistograms[
"matchCand_phi_eta" ] =
new TH2F(
"C_matchCand_phi_eta",
"eta vs. phi; #phi; #eta", 400, 0., 2 * M_PI, 400, -1.7, -0.9 );
2941 mHistograms[
"matchCand_deltaX" ] =
new TH1F(
"C_matchCand_deltaX" ,
"match candidate delta X;match candidate #DeltaX (cm); #match cand", 400, -15., 15. );
2942 mHistograms[
"matchCand_deltaY" ] =
new TH1F(
"C_matchCand_deltaY" ,
"match candidate delta Y;match candidate #DeltaY (cm); #match cand", 400, -15., 15. );
2945 for(
int sector = eTofConst::sectorStart; sector <= eTofConst::sectorStop; sector++ ) {
2946 for(
int plane = eTofConst::zPlaneStart; plane <= eTofConst::zPlaneStop; plane++ ) {
2947 for(
int counter = eTofConst::counterStart; counter <= eTofConst::counterStop; counter++ ) {
2948 std::string histName_deltaX =
"matchCand_deltaX_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2949 std::string histName_deltaY =
"matchCand_deltaY_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2951 mHistograms[ histName_deltaX ] =
new TH1F( Form(
"C_matchCand_deltaX_s%dm%dc%d", sector, plane, counter ) , Form(
"match candidate delta X in sector %d module %d counter %d;match candidate #DeltaX (cm); #match cand", sector, plane, counter ), 400, -15., 15. );
2952 mHistograms[ histName_deltaY ] =
new TH1F( Form(
"C_matchCand_deltaY_s%dm%dc%d", sector, plane, counter ) , Form(
"match candidate delta Y in sector %d module %d counter %d;match candidate #DeltaY (cm); #match cand", sector, plane, counter ), 400, -15., 15. );
2957 mHistograms[
"matchCand_deltaX_nHitsTpc" ] =
new TH2F(
"C_matchCand_deltaX_nHitsTpc" ,
"match candidate delta X vs. nHitsFit in TPC;nHitsFit in TPC;match candidate #DeltaX (cm)", 75, 0., 75., 400, -15., 15. );
2958 mHistograms[
"matchCand_deltaY_nHitsTpc" ] =
new TH2F(
"C_matchCand_deltaY_nHitsTpc" ,
"match candidate delta Y vs. nHitsFit in TPC;nHitsFit in TPC;match candidate #DeltaY (cm)", 75, 0., 75., 400, -15., 15. );
2960 mHistograms[
"matchCandMult" ] =
new TH1F(
"C_matchCandMult",
"matchCandMult;multiplicity;# events", 200, 0., 200. );
2966 mHistograms[
"trackMatchMultPerDetectorHit" ] =
new TH1F(
"D_trackMatchMultPerDetectorHit",
"multiplicity of tracks pointing to the same detector hit;#tracks;#detector hits", 15, 0., 15. );
2968 mHistograms[
"singleTrackMatchMult" ] =
new TH1F(
"D_singleTrackMatchMult",
"singleTrackMatchMult;multiplicity;# events", 200, 0., 200. );
2974 mHistograms[
"hitMultPerTrack" ] =
new TH1F(
"E_hitMultPerTrack",
"multiplicity of hit matched to the same track;#hits;#tracks", 15, 0., 15. );
2976 mHistograms[
"finalMatch_pt" ] =
new TH1F(
"E_finalMatch_pt",
"p_{T} distribution of matched tracks", 200, 0., 2. );
2978 mHistograms[
"finalMatchMult" ] =
new TH1F(
"E_finalMatchMult",
"finalMatchMult;multiplicity;# events", 200, 0., 200. );
2980 mHistograms[
"overlapHit_globalXY" ] =
new TH2F(
"E_overlapHit_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2986 mHistograms[
"finalMatchMultGlobal" ] =
new TH1F(
"F_finalMatchMultGlobal",
"finalMatchMultGlobal;multiplicity;# events", 200, 0., 200. );
2987 mHistograms[
"finalMatchMultPrimary" ] =
new TH1F(
"F_finalMatchMultPrimary",
"finalMatchMultPrimary;multiplicity;# events", 200, 0., 200. );
2989 mHistograms[
"finalMatchPrimary_globalXY" ] =
new TH2F(
"F_finalMatchPrimary_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2990 mHistograms[
"finalMatchPrimaryMom0_globalXY" ] =
new TH2F(
"F_finalMatchPrimaryMom0_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2991 mHistograms[
"finalMatchPrimaryMom1_globalXY" ] =
new TH2F(
"F_finalMatchPrimaryMom1_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2992 mHistograms[
"finalMatchPrimaryMom2_globalXY" ] =
new TH2F(
"F_finalMatchPrimaryMom2_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2998 mHistograms[
"startTimeDiff" ] =
new TH1F(
"G_startTimeDiff",
"bTOF - eTOF start time;#DeltaT;#events", 1000, -20., 20. );
2999 mHistograms[
"startTimeDiff_nCand" ] =
new TH2F(
"G_startTimeDiff_nCand",
"bTOF - eTOF start time;#DeltaT;#nCand tracks", 1000, -20., 20., 50, 0, 50 );
3000 mHistograms[
"startTime_T0corr" ] =
new TH1F(
"G_startTime_T0corr",
"T0corr evolution;#updates;T0 corr. (ns)", 1000, 0., 1000. );
3002 mHistograms[
"matchCand_timeOfFlight" ] =
new TH1F(
"G_matchCand_timeOfFlight",
"match candidate time of flight;ToF (ns);# match candidates", 2000, -400., 600. );
3003 mHistograms[
"matchCand_timeOfFlight_pathLength" ] =
new TH2F(
"G_matchCand_timeOfFlight_pathLength",
"match candidate pathlength vs. time of flight;ToF (ns);pathlength (cm)", 1000, -400., 600., 800, 200., 600. );
3009 mHistograms[
"matchCand_beta_mom" ] =
new TH2F(
"H_matchCand_beta_mom" ,
"match candidate 1/beta vs. momentum;p (GeV/c);1/#beta", 400, 0., 10., 1000, 0.0, 2. );
3011 mHistograms[
"matchCand_beta_mom_matchDistCut" ] =
new TH2F(
"H_matchCand_beta_mom_matchDistCut" ,
"match candidate 1/beta vs. momentum;p (GeV/c);1/#beta", 400, 0., 10., 1000, 0.8, 2. );
3013 mHistograms[
"matchCandMultPerSector_matchDistCut" ] =
new TH2F(
"H_matchCandMultPerSector_matchDistCut" ,
"matchCandMultPerSector_matchDistCut;module;# matches per event", 36, 0, 36, 25, 0, 25 );
3016 mHistograms[
"matchCand_m2_signmom" ] =
new TH2F(
"H_matchCand_m2_signmom" ,
"match candidate m^{2} vs. momentum;q/|q| * p (GeV/c);m^{2} (GeV^{2}/c^{4})", 400, -10., 10., 1000, -0.2, 1.3 );
3017 mHistograms[
"matchCand_m2_mom" ] =
new TH2F(
"H_matchCand_m2_mom" ,
"match candidate m^{2} vs. momentum;p (GeV/c);m^{2} (GeV^{2}/c^{4})", 400, 0., 10., 1000, -0.2, 1.3 );
3019 mHistograms[
"matchCand_m2_mom_matchDistCut" ] =
new TH2F(
"H_matchCand_m2_mom_matchDistCut" ,
"match candidate m^{2} vs. momentum;p (GeV/c);m^{2} (GeV^{2}/c^{4})", 400, 0., 10., 1000, -0.2, 1.3 );
3022 for(
int sector = eTofConst::sectorStart; sector <= eTofConst::sectorStop; sector++ ) {
3023 for(
int plane = eTofConst::zPlaneStart; plane <= eTofConst::zPlaneStop; plane++ ) {
3024 for(
int counter = eTofConst::counterStart; counter <= eTofConst::counterStop; counter++ ) {
3026 std::string histName_beta_mom =
"matchCand_beta_mom_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3027 mHistograms[ histName_beta_mom ] =
new TH2F( Form(
"H_matchCand_beta_mom_s%dm%dc%d", sector, plane, counter ), Form(
"match candidate 1/beta vs. momentum in sector %d module %d counter %d;p (GeV/c);1/#beta", sector, plane, counter), 200, 0., 10., 500, 0.0, 2. );
3029 std::string histName_t0corr_mom =
"matchCand_t0corr_mom_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3030 mHistograms[ histName_t0corr_mom ] =
new TH2F( Form(
"H_matchCand_t0corr_mom_s%dm%dc%d", sector, plane, counter ), Form(
"measured tof - tof_{#pi} vs. momentum in sector %d module %d counter %d;mom (GeV/c);#Delta time (ns)", sector, plane, counter ), 400, 0., 10., 1000, -500., 500. );
3032 std::string histName_t0corr_mom_zoom =
"matchCand_t0corr_mom_zoom_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3033 std::string histName_t0corr_mom_zoom_cut =
"matchCand_t0corr_mom_zoom_cut_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3035 mHistograms[ histName_t0corr_mom_zoom ] =
new TH2F( Form(
"H_matchCand_t0corr_mom_zoom_s%dm%dc%d", sector, plane, counter ), Form(
"measured tof - tof_{#pi} vs. momentum in sector %d module %d counter %d;mom (GeV/c);#Delta time (ns)", sector, plane, counter ), 200, 0., 3., 2000, -10., 10. );
3036 mHistograms[ histName_t0corr_mom_zoom_cut ] =
new TH2F( Form(
"H_matchCand_t0corr_mom_zoom_cut_s%dm%dc%d", sector, plane, counter ), Form(
"measured tof - tof_{#pi} vs. momentum in sector %d module %d counter %d;mom (GeV/c);#Delta time (ns)", sector, plane, counter ), 200, 0., 3., 2000, -10., 10. );
3038 std::string histName_t0corr_strip =
"matchCand_t0corr_strip_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3039 mHistograms[ histName_t0corr_strip ] =
new TH2F( Form(
"H_matchCand_t0corr_strip_s%dm%dc%d", sector, plane, counter ), Form(
"measured tof - tof_{#pi} vs. momentum in sector %d module %d counter %d;local X (cm);#Delta time (ns)", sector, plane, counter ), 32, -16., 16., 2000, -10., 10. );
3041 std::string histName_slewing_digi =
"matchCand_slewing_digi_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3042 mHistograms[ histName_slewing_digi ] =
new TH2F( Form(
"H_matchCand_slewing_digi_s%dm%dc%d", sector, plane, counter ), Form(
"measured tof - tof_{#pi} vs. digi ToT in sector %d module %d counter %d;digi Tot (arb. units);#Delta time (ns)", sector, plane, counter ), 400, 0., 20., 1000, -3., 3. );
3047 mHistograms[
"matchCand_dEdx_beta_mom1gev" ] =
new TH2F(
"H_matchCand_dEdx_beta_mom1gev",
"dE/dx vs. 1/#beta at p=1 GeV;1/#beta;dE/dx (keV/cm)", 800, 0.8, 1.8, 800, 0., 15. );
3048 mHistograms[
"matchCand_dEdx_beta_mom2gev" ] =
new TH2F(
"H_matchCand_dEdx_beta_mom2gev",
"dE/dx vs. 1/#beta at p=2 GeV;1/#beta;dE/dx (keV/cm)", 800, 0.8, 1.8, 800, 0., 15. );
3052 for(
auto& kv : mHistograms ) {
3053 kv.second->SetDirectory( 0 );
3055 for(
auto& kv : mHistograms2d ) {
3056 kv.second->SetDirectory( 0 );
3063 StETofMatchMaker::writeHistograms()
3065 if( mHistFileName !=
"" ) {
3066 LOG_INFO <<
"writing histograms to: " << mHistFileName.c_str() << endm;
3068 TFile histFile( mHistFileName.c_str(),
"RECREATE",
"etofMatch" );
3071 for (
const auto& kv : mHistograms ) {
3072 if( kv.second->GetEntries() > 0 ) kv.second->Write();
3074 for (
const auto& kv : mHistograms2d ) {
3075 if( kv.second->GetEntries() > 0 ) kv.second->Write();
3080 LOG_INFO <<
"histogram file name is empty string --> cannot write histograms" << endm;
3087 StETofMatchMaker::setMatchDistXYT(
double x,
double y,
double t = 99999. )
3089 mMatchDistX = fabs( x );
3090 mMatchDistY = fabs( y );
3091 mMatchDistT = fabs( t );
3096 StETofMatchMaker::rotateHit(
const int& sector,
const int& rot )
3098 int sec = 13 + ( sector - 13 + rot ) % 12;
3099 LOG_DEBUG <<
"hit rotated from: " << sector <<
" to " << sec << endm;
3105 ETofTrack::ETofTrack(
const StTrack* sttrack )
3119 mom = sttrack->geometry()->momentum().mag();
3120 pt = sttrack->geometry()->momentum().perp();
3121 eta = sttrack->geometry()->momentum().pseudoRapidity();
3122 phi = sttrack->geometry()->momentum().phi();
3123 nFtPts = sttrack->fitTraits().numberOfFitPoints( kTpcId );
3126 static StPionPlus* Pion = StPionPlus::instance();
3129 nSigmaPion = PidAlgorithm.numberOfSigma( Pion );
3130 if(PidAlgorithm.traits()){
3131 dEdx = PidAlgorithm.traits()->mean() * 1.e6;
3132 nDedxPts = PidAlgorithm.traits()->numberOfPoints();
3135 flag = sttrack->flag();
3136 nHitsPoss = sttrack->numberOfPossiblePoints( kTpcId );
3138 if ( phi < 0. ) phi += 2. * M_PI;
3143 ETofTrack::ETofTrack(
const StMuTrack* mutrack )
3159 eta = mutrack->
momentum().pseudoRapidity();
3161 nFtPts = mutrack->
nHitsFit( kTpcId );
3163 flag = mutrack->
flag();
3164 nHitsPoss = mutrack->
nHitsPoss( kTpcId );
3165 dEdx = mutrack->
dEdx() * 1.e6;
3168 if ( phi < 0. ) phi += 2. * M_PI;
3173 void StETofMatchMaker::checkClockJumps()
3175 if (mClockJumpCand.size() == 0)
return;
3178 int binmax = mHistograms.at(
"matchCand_t0corr_1d")->GetMaximumBin();
3179 float mainPeakT0 = mHistograms.at(
"matchCand_t0corr_1d")->GetXaxis()->GetBinCenter(binmax);
3181 LOG_DEBUG <<
"mainPeakT0: " << mainPeakT0 << endm;
3183 bool needsUpdate =
false;
3185 for (
const auto& kv : mClockJumpCand) {
3186 LOG_DEBUG <<
"clock jump candidate: " << kv.first <<
" " << kv.second << endm;
3188 int sector = kv.first / 1000;
3189 int plane = (kv.first % 1000) / 100;
3190 int counter = (kv.first % 100) / 10;
3191 int binX = kv.first % 10;
3193 std::string histName_t0corr_jump =
"matchCand_t0corr_jump_s" + std::to_string(sector) +
"m" + std::to_string(plane) +
"c" + std::to_string(counter);
3194 TH2D* h = (TH2D*) mHistograms.at(histName_t0corr_jump);
3196 int binYmain_neg = h->GetYaxis()->FindBin(mainPeakT0 - 1.5);
3197 int binYmain_pos = h->GetYaxis()->FindBin(mainPeakT0 + 3.0);
3198 int binYearly_neg = h->GetYaxis()->FindBin(mainPeakT0 - 1.5 - eTofConst::coarseClockCycle);
3199 int binYearly_pos = h->GetYaxis()->FindBin(mainPeakT0 + 3.0 - eTofConst::coarseClockCycle);
3200 int binYlate_neg = h->GetYaxis()->FindBin(mainPeakT0 - 1.5 + eTofConst::coarseClockCycle);
3201 int binYlate_pos = h->GetYaxis()->FindBin(mainPeakT0 + 3.0 + eTofConst::coarseClockCycle);
3203 LOG_DEBUG <<
"binYmain_neg " << binYmain_neg <<
" " << binYmain_pos <<
" binYmain_pos " << binYearly_neg <<
" binYearly_neg " << binYearly_pos <<
" binYearly_pos " << endm;
3205 int nMain = h->Integral(binX, binX, binYmain_neg, binYmain_pos);
3206 int nEarly = h->Integral(binX, binX, binYearly_neg, binYearly_pos);
3207 int nLate = h->Integral(binX, binX, binYlate_neg, binYlate_pos);
3209 LOG_DEBUG <<
"nMain " << nMain <<
" " << nEarly <<
" nEarly " << endm;
3211 if (nEarly > nMain && nEarly >= 2) {
3212 LOG_DEBUG <<
"clock jump detected --> give it to hit maker" << endm;
3214 mClockJumpDirection[ kv.first ] = -1.;
3218 if (nLate > nMain && nLate >= 2) {
3219 LOG_DEBUG <<
"clock jump detected --> give it to hit maker" << endm;
3221 mClockJumpDirection[ kv.first ] = 1.;
3226 mClockJumpCand.clear();
3229 if( needsUpdate && mETofHitMaker ) {
3230 mETofHitMaker->updateClockJumpMap( mClockJumpDirection );
3236 StETofMatchMaker::sortMatchCases( eTofHitVec inputVec , std::map< Int_t, eTofHitVec >& outputMap )
3243 eTofHitVec tempVec = inputVec;
3244 eTofHitVec erasedVec = tempVec;
3245 eTofHitVec tempMMVec;
3247 std::map< Int_t, eTofHitVec > MMMap;
3255 eTofHitVecIter tempIter = tempVec.begin();
3256 eTofHitVecIter erasedIter = erasedVec.begin();
3259 if(tempVec.size() < 1 )
return;
3261 while( tempVec.size() != 0 ) {
3263 tempIter = tempVec.begin();
3264 erasedIter = erasedVec.begin();
3267 tempMMVec.push_back(*tempIter);
3268 erasedVec.erase( erasedIter );
3274 for(
unsigned int s =0; s < tempMMVec.size(); s++){
3278 erasedIter = erasedVec.begin();
3280 if(erasedVec.size() <= 0 )
continue;
3284 while( erasedIter != erasedVec.end() ) {
3288 if(tempMMVec.at(s).trackId == erasedIter->trackId && tempMMVec.at(s).index2ETofHit == erasedIter->index2ETofHit){
3290 erasedVec.erase( erasedIter );
3293 if(tempMMVec.at(s).trackId == erasedIter->trackId || tempMMVec.at(s).index2ETofHit == erasedIter->index2ETofHit){
3297 tempMMVec.push_back(*erasedIter);
3299 erasedVec.erase( erasedIter );
3302 if( erasedVec.size() <= 0 )
break;
3303 if( erasedIter == erasedVec.end())
break;
3312 MMMap[tempMMVec.begin()->trackId] = tempMMVec;
3315 tempVec = erasedVec;
3325 StETofMatchMaker::sortandcluster(eTofHitVec& matchCandVec , eTofHitVec& detectorHitVec , eTofHitVec& intersectionVec , eTofHitVec& finalMatchVec){
3329 std::map< Int_t, eTofHitVec > overlapHitMap;
3330 eTofHitVec overlapHitVec;
3331 eTofHitVec tempVecOL = matchCandVec;
3332 eTofHitVecIter detHitIter;
3333 eTofHitVecIter detHitIter2;
3335 for(
auto detHitIter = tempVecOL.begin(); detHitIter != tempVecOL.end(); ) {
3337 detHitIter = tempVecOL.begin();
3338 detHitIter2 = tempVecOL.begin();
3340 bool isOverlap =
false;
3341 int counterId1 = (detHitIter->sector*100) + (detHitIter->plane*10) + (detHitIter->counter);
3343 for(
auto detHitIter2 = tempVecOL.begin(); detHitIter2 != tempVecOL.end(); ) {
3345 int counterId2 = (detHitIter2->sector*100) + (detHitIter2->plane*10) + (detHitIter2->counter);
3347 if(counterId1 != counterId2 && detHitIter->trackId == detHitIter2->trackId){
3349 int mf2 = counterId2 ;
3351 detHitIter2->matchFlag = mf2;
3353 matchCandVec.at(detHitIter2 - tempVecOL.begin()).matchFlag = 1;
3355 overlapHitVec.push_back(*detHitIter2);
3356 tempVecOL.erase(detHitIter2);
3361 if( tempVecOL.size() <= 0 )
break;
3362 if( detHitIter2 == tempVecOL.end())
break;
3369 detHitIter->matchFlag = counterId1;
3371 matchCandVec.at(detHitIter - tempVecOL.begin()).matchFlag = 1;
3373 overlapHitVec.push_back(*detHitIter);
3376 overlapHitMap[overlapHitVec.begin()->trackId] = overlapHitVec;
3378 overlapHitVec.clear();
3381 tempVecOL.erase(detHitIter);
3383 if( tempVecOL.size() <= 0 )
break;
3384 if( detHitIter == tempVecOL.end())
break;
3390 std::vector< eTofHitVec > matchCandVecCounter(108);
3392 for(
int i =0; i < 108; i++){
3394 for(
unsigned int n = 0; n < matchCandVec.size(); n++){
3396 int sector = matchCandVec.at(n).sector;
3397 int plane = matchCandVec.at(n).plane;
3398 int counter = matchCandVec.at(n).counter;
3400 int counterId = 9*(sector - 13) + 3*(plane - 1) + (counter -1);
3402 if(counterId == i ) {
3403 matchCandVecCounter.at(i).push_back(matchCandVec.at(n));
3410 for(
int counterNr = 0; counterNr < 108; counterNr++){
3413 eTofHitVec tempVec = matchCandVecCounter.at(counterNr);
3414 eTofHitVec tempVec2 = matchCandVecCounter.at(counterNr);
3415 std::map< Int_t, eTofHitVec > MMMap;
3417 sortMatchCases(tempVec, MMMap);
3420 std::map< Int_t, eTofHitVec > MultMultMap;
3421 std::map< Int_t, eTofHitVec > SingleHitMap;
3422 std::map< Int_t, eTofHitVec > SingleTrackMap;
3425 map<Int_t, eTofHitVec >::iterator it;
3427 for (it = MMMap.begin(); it != MMMap.end(); it++)
3432 for(
unsigned int l =0; l< it->second.size(); l++){
3433 for(
unsigned int j = l; j< it->second.size(); j++){
3435 if( it->second.at(l).trackId != it->second.at(j).trackId) nTracks++;
3436 if( it->second.at(l).index2ETofHit != it->second.at(j).index2ETofHit ) nHits++;
3444 if(nTracks == 1 && nHits == 1) {
3446 ssVec.push_back(it->second.front() );
3449 int isOl = it->second.front().matchFlag;
3451 if( it->second.front().clusterSize > 999 ) {
3454 it->second.front().clusterSize = 1;
3457 it->second.front().matchFlag = 100 + isMerged + isOl;
3458 finalMatchVec.push_back(it->second.front());
3463 if( nTracks > 1 && nHits == 1) {
3466 double dr_best = 99999.0;
3467 unsigned int ind = 0;
3468 unsigned int ind_best = 0;
3470 for(
unsigned int l =0; l < it->second.size(); l++){
3472 dr = (it->second.at(l).deltaX * it->second.at(l).deltaX) + (it->second.at(l).deltaY * it->second.at(l).deltaY);
3481 SingleHitMap[it->first] = it->second;
3485 int isOl = it->second.at(ind_best).matchFlag;
3487 if( it->second.at(ind_best).clusterSize > 999 ){
3490 it->second.at(ind_best).clusterSize = 1;
3493 it->second.at(ind_best).matchFlag = 300 + isMerged + isOl;
3494 finalMatchVec.push_back(it->second.at(ind_best));
3499 if( nTracks ==1 && nHits > 1) {
3504 for(
unsigned int l =0; l < it->second.size(); l++){
3506 if(it->second.at(l).clusterSize < 999){
3513 SingleTrackMap[it->first] = it->second;
3519 std::vector< std::vector<int> > mergeIndVec(it->second.size());
3526 double dr_best = 99999.0;
3527 unsigned int ind = 0;
3528 unsigned int ind_best = 0;
3530 for(
unsigned int l =0; l < it->second.size(); l++){
3532 dr = sqrt((it->second.at(l).deltaX * it->second.at(l).deltaX) + (it->second.at(l).deltaY * it->second.at(l).deltaY));
3543 dr_mean = dr_sum / it->second.size();
3545 for(
unsigned int c =0; c < it->second.size(); c++){
3547 dr = sqrt((it->second.at(c).deltaX * it->second.at(c).deltaX) + (it->second.at(c).deltaY * it->second.at(c).deltaY));
3548 dr_diff += abs(dr - dr_mean);
3553 int mergedCluSz = 0;
3554 int mergedMatchFlag = 0;
3556 int isOl = it->second.at(ind_best).matchFlag;
3558 if(it->second.at(ind_best).clusterSize > 100 && it->second.at(ind_best).clusterSize < 200){
3560 mergedCluSz = it->second.at(ind_best).clusterSize % 100;
3564 mergedCluSz = it->second.at(ind_best).clusterSize;
3567 if(mergedCluSz > 1){ isMerged = 30;
3572 mergedMatchFlag = 200 + isMerged + isOl;
3573 it->second.at(ind_best).matchFlag = mergedMatchFlag;
3575 finalMatchVec.push_back(it->second.at(ind_best));
3581 std::vector< std::vector<int> > mergeIndVec(it->second.size());
3583 for(
unsigned int l =0; l < it->second.size(); l++){
3584 mergeIndVec.at(l).push_back(0);
3588 double dr_best = 99999.0;
3589 unsigned int ind = 0;
3590 unsigned int ind_best = 0;
3592 for(
unsigned int l =0; l < it->second.size(); l++){
3595 dr = it->second.at(l).deltaX;
3606 eTofHitVec hitVec = it->second ;
3608 double mergedTime = it->second.at(ind_best).hitTime;
3609 double mergedToT = it->second.at(ind_best).tot;
3610 double mergedPosY = it->second.at(ind_best).localY;
3611 double mergedPosX = it->second.at(ind_best).localX;
3612 int mergedCluSz = 1;
3613 int mergedMatchFlag = 0;
3614 int mergedIdTruth = it->second.at(ind_best).IdTruth;
3616 for(
unsigned int j=0; j < hitVec.size(); j++) {
3618 if( j == ind_best)
continue;
3620 double dx = it->second.at(ind_best).localX - hitVec.at(j).localX;
3621 double dy = it->second.at(ind_best).localY - hitVec.at(j).localY;
3622 double dt = abs( it->second.at(ind_best).hitTime - hitVec.at(j).hitTime);
3625 if( abs(dx) < dx_3sig && abs(dy) < dy_3sig && abs(dt) < dt_3sig ){
3627 mergedTime += hitVec.at(j).hitTime;
3628 mergedToT += hitVec.at(j).tot;
3629 mergedPosY += hitVec.at(j).localY;
3630 mergedPosX += hitVec.at(j).localX;
3633 if(mergedIdTruth != hitVec.at(j).IdTruth) mergedIdTruth =0;
3639 mergedTime /= mergedCluSz;
3640 mergedToT /= mergedCluSz;
3641 mergedPosY /= mergedCluSz;
3642 mergedPosX /= mergedCluSz;
3644 int isOl = it->second.at(ind_best).matchFlag;
3646 if(mergedCluSz > 1){ isMerged = 40;
3651 mergedMatchFlag = 200 + isMerged + isOl;
3654 mergedTime = fmod( mergedTime, eTofConst::bTofClockCycle );
3655 if( mergedTime < 0 ) mergedTime += eTofConst::bTofClockCycle;
3657 it->second.at(ind_best).hitTime = mergedTime;
3658 it->second.at(ind_best).tot = mergedToT;
3659 it->second.at(ind_best).localX = mergedPosX;
3660 it->second.at(ind_best).localY = mergedPosY;
3661 it->second.at(ind_best).IdTruth = mergedIdTruth;
3662 it->second.at(ind_best).matchFlag = mergedMatchFlag;
3663 it->second.at(ind_best).clusterSize = mergedCluSz;
3666 finalMatchVec.push_back(it->second.at(ind_best));
3672 std::vector< std::vector<int> > mergeIndVec(it->second.size());
3674 for(
unsigned int l =0; l < it->second.size(); l++){
3675 mergeIndVec.at(l).push_back(0);
3679 double dr_best = 99999.0;
3680 unsigned int ind = 0;
3681 unsigned int ind_best = 0;
3683 for(
unsigned int l =0; l < it->second.size(); l++){
3685 if(it->second.at(l).clusterSize > 999)
continue;
3688 dr = it->second.at(l).deltaX*it->second.at(l).deltaX + it->second.at(l).deltaY*it->second.at(l).deltaY;
3699 eTofHitVec hitVec = it->second ;
3701 double mergedTime = it->second.at(ind_best).hitTime;
3702 double mergedToT = it->second.at(ind_best).tot;
3703 double mergedPosY = it->second.at(ind_best).localY;
3704 double mergedPosX = it->second.at(ind_best).localX;
3705 int mergedCluSz = 1;
3706 int mergedMatchFlag = 0;
3707 int mergedIdTruth = it->second.at(ind_best).IdTruth;
3709 for(
unsigned int j=0; j < hitVec.size(); j++) {
3711 if( j == ind_best)
continue;
3713 double dx = it->second.at(ind_best).localX - hitVec.at(j).localX;
3714 double dy = it->second.at(ind_best).localY - hitVec.at(j).localY;
3715 double dt = abs( it->second.at(ind_best).hitTime - hitVec.at(j).hitTime);
3718 if( abs(dx) < dx_3sig && abs(dy) < dy_3sig && abs(dt) < dt_3sig ){
3720 mergedTime += hitVec.at(j).hitTime;
3721 mergedToT += hitVec.at(j).tot;
3722 mergedPosY += hitVec.at(j).localY;
3723 mergedPosX += hitVec.at(j).localX;
3726 if(mergedIdTruth != hitVec.at(j).IdTruth) mergedIdTruth =0;
3731 mergedTime /= mergedCluSz;
3732 mergedToT /= mergedCluSz;
3733 mergedPosY /= mergedCluSz;
3734 mergedPosX /= mergedCluSz;
3736 int isOl = it->second.at(ind_best).matchFlag;
3738 if(mergedCluSz > 1){ isMerged = 50;
3743 mergedMatchFlag = 200 + isMerged + isOl;
3746 mergedTime = fmod( mergedTime, eTofConst::bTofClockCycle );
3747 if( mergedTime < 0 ) mergedTime += eTofConst::bTofClockCycle;
3749 it->second.at(ind_best).hitTime = mergedTime;
3750 it->second.at(ind_best).tot = mergedToT;
3751 it->second.at(ind_best).localX = mergedPosX;
3752 it->second.at(ind_best).localY = mergedPosY;
3753 it->second.at(ind_best).IdTruth = mergedIdTruth;
3754 it->second.at(ind_best).matchFlag = mergedMatchFlag;
3755 it->second.at(ind_best).clusterSize = mergedCluSz ;
3757 finalMatchVec.push_back(it->second.at(ind_best));
3763 if(nTracks > 1 && nHits > 1) {
3766 eTofHitVec hitVec = it->second ;
3767 eTofHitVec bestMatchVec;
3768 eTofHitVec mergeCandVec;
3769 eTofHitVec ambigVec;
3770 std::map< Int_t, StructETofHit > bestMatchMap;
3771 std::map< Int_t, eTofHitVec > mergeCandMap;
3772 std::map< Int_t, eTofHitVec > mergeCandMap2;
3773 std::map< Int_t, eTofHitVec > ambigMap;
3774 std::vector<int> indVec;
3776 for(
unsigned int l =0; l < it->second.size(); l++){
3778 double dr = it->second.at(l).deltaX*it->second.at(l).deltaX + it->second.at(l).deltaY*it->second.at(l).deltaY;
3779 double dr_best = 99999.0;
3780 unsigned int ind = 0;
3781 unsigned int ind_best = l;
3782 int trackId = it->second.at(l).trackId;
3785 if(std::find(indVec.begin(), indVec.end(), trackId) != indVec.end())
continue;
3787 for(
unsigned int n = 0; n < it->second.size(); n++){
3789 if(it->second.at(n).trackId != trackId)
continue;
3792 dr = it->second.at(n).deltaX*it->second.at(n).deltaX + it->second.at(n).deltaY*it->second.at(n).deltaY;
3798 mergeCandVec.push_back(it->second.at(ind_best));
3807 mergeCandVec.push_back(it->second.at(n));
3811 indVec.push_back(trackId);
3812 bestMatchMap[trackId] = it->second.at(ind_best);
3813 bestMatchVec.push_back(it->second.at(ind_best));
3817 std::vector<int> indVecBMtrack;
3818 std::vector<int> indVecBMhit;
3820 for(
unsigned int b =0; b < bestMatchVec.size() ; b++){
3821 indVecBMtrack.push_back(bestMatchVec.at(b).trackId);
3822 indVecBMhit.push_back(bestMatchVec.at(b).index2ETofHit);
3825 std::vector<int> indVecUsedTrack;
3826 std::vector<int> indVecReplaceTrack;
3827 std::vector<int> indVecUsedHit;
3828 eTofHitVec MatchVecTemp = bestMatchVec;
3829 eTofHitVec finalbestMatchVec;
3831 while(MatchVecTemp.size() > 0){
3834 double dr_best = 99999.0;
3835 unsigned int ind = 0;
3836 unsigned int ind_best = 0;
3837 for(
unsigned int b =0; b < MatchVecTemp.size() ; b++){
3841 dr = MatchVecTemp.at(b).deltaX * MatchVecTemp.at(b).deltaX + MatchVecTemp.at(b).deltaY * MatchVecTemp.at(b).deltaY;
3848 finalbestMatchVec.push_back(MatchVecTemp.at(ind_best));
3849 indVecUsedTrack.push_back(MatchVecTemp.at(ind_best).trackId);
3850 indVecUsedHit.push_back(MatchVecTemp.at(ind_best).index2ETofHit);
3851 MatchVecTemp.erase(MatchVecTemp.begin() + ind_best);
3854 for(
unsigned int b =0; b < MatchVecTemp.size() ; b++){
3856 if(std::find(indVecUsedHit.begin(), indVecUsedHit.end(), MatchVecTemp.at(b).index2ETofHit) != indVecUsedHit.end()) {
3858 indVecReplaceTrack.push_back(MatchVecTemp.at(b).trackId);
3859 MatchVecTemp.erase(MatchVecTemp.begin() + b);
3865 std::sort( indVecReplaceTrack.begin(), indVecReplaceTrack.end() );
3866 indVecReplaceTrack.erase( unique( indVecReplaceTrack.begin(), indVecReplaceTrack.end() ), indVecReplaceTrack.end() );
3868 bool found1 =
false;
3871 double dx_best1 = 99999.0;
3872 double dy_best1 = 99999.0;
3873 unsigned int ind1 = 0;
3874 unsigned int ind_best1 = 0;
3875 for(
unsigned int i = 0; i < mergeCandVec.size();i++){
3879 if(!(std::find(indVecReplaceTrack.begin(), indVecReplaceTrack.end(), mergeCandVec.at(i).trackId) != indVecReplaceTrack.end()))
continue;
3880 if(std::find(indVecUsedTrack.begin(), indVecUsedTrack.end(), mergeCandVec.at(i).index2ETofHit) != indVecUsedTrack.end())
continue;
3881 if(std::find(indVecUsedHit.begin(), indVecUsedHit.end(), mergeCandVec.at(i).index2ETofHit) != indVecUsedHit.end())
continue;
3882 if(std::find(indVecBMhit.begin(), indVecBMhit.end(), mergeCandVec.at(i).index2ETofHit) != indVecBMhit.end())
continue;
3884 dx1 = mergeCandVec.at(i).deltaX;
3885 dy1 = mergeCandVec.at(i).deltaY;
3887 if(dy1 < dy_best1){ dy_best1 = dy1;}
3893 }
else if(dx1 == dx_best1){
3895 if(dy1 < dy_best1 && dy1 < dy_max && dy1 != 27.0){
3898 }
else if( dy1 == 27.0){
3907 finalbestMatchVec.push_back(mergeCandVec.at(ind_best1));
3908 indVecUsedTrack.push_back(mergeCandVec.at(ind_best1).trackId);
3909 indVecUsedHit.push_back(mergeCandVec.at(ind_best1).index2ETofHit);
3910 mergeCandVec.erase(mergeCandVec.begin() + ind_best1);
3913 bestMatchVec = finalbestMatchVec;
3915 for(
unsigned int i=0;i< bestMatchVec.size();i++){
3917 if(bestMatchVec.at(i).clusterSize < 999 ){
3918 bestMatchVec.at(i).matchFlag = 410;
3920 bestMatchVec.at(i).matchFlag = 420;
3921 bestMatchVec.at(i).clusterSize -= 1000;
3923 finalMatchVec.push_back(bestMatchVec.at(i));
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
double localY() const
Y-position.
int associatedHitId() const
unsigned int zPlane() const
ZPlane.
static TObjArray * globalTracks()
returns pointer to the global tracks list
unsigned int sector() const
Sector.
void setETofHit(StETofHit *hit)
PID functions – to be added (?)
Int_t vertexIndex() const
Returns index of associated primary vertex.
unsigned int clusterSize() const
Cluster size.
double time() const
Time.
Int_t index2Global() const
Returns index of associated global track. If not in order can be set with StMuDst::fixTrackIndeces() ...
short id() const
Returns the track id(or key), is unique for a track node, i.e. global and primary tracks have the sam...
UShort_t nHitsDedx() const
Return number of hits used for dEdx.
unsigned int counter() const
Counter.
void helixCrossCounter(const StPhysicalHelixD &helix, std::vector< int > &idVec, std::vector< StThreeVectorD > &crossVec, std::vector< StThreeVectorD > &localVec, std::vector< double > &thetaVec, std::vector< double > &pathLenVec)
unsigned int sector() const
Sector.
double time() const
Time.
static StMuETofHit * etofHit(int i)
returns pointer to the i-th StMuETofHit
const StMuETofPidTraits & etofPidTraits() const
dongx
unsigned int clusterSize() const
Cluster size.
unsigned int zPlane() const
ZPlane.
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
StPhysicalHelixD helix() const
Returns inner helix (first measured point)
UShort_t nHitsFit() const
Return total number of hits used in fit.
short flag() const
Returns flag, (see StEvent manual for type information)
Short_t charge() const
Returns charge.
Int_t index2ETofHit() const
dongx
Double_t nSigmaPion() const
Returns Craig's distance to the calculated dE/dx band for pions in units of sigma.
unsigned int counter() const
Counter.
static TClonesArray * etofArray(int type)
returns pointer to the n-th TClonesArray from the etof arrays // FS
double localX() const
X-position.
UShort_t nHitsPoss() const
Return number of possible hits on track.
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
StTrack * associatedTrack()
pointer to the track which has been matched to this hit
unsigned int zPlane() const
ZPlane.
const StThreeVectorF & momentum() const
Returns 3-momentum at dca to primary vertex.
static StMuETofDigi * etofDigi(int i)
returns pointer to the i-th StMuEtofDigi
float timeOfFlight() const
timing for PID
double localX() const
X-position.
double totalTot() const
Total Tot.
Double_t dEdx() const
Returns measured dE/dx value.
double totalTot() const
Total Tot.
double localY() const
Y-position.
static StBTofHeader * btofHeader()
returns pointer to the btofHeader - dongx
static TClonesArray * array(int type)
returns pointer to the n-th TClonesArray
const StMuTrack * primaryTrack() const
Returns pointer to associated primary track. Null pointer if no global track available.
unsigned int sector() const
Sector.
Double_t nSigmaProton() const
Returns Craig's distance to the calculated dE/dx band for protons in units of sigma.
unsigned short matchFlag() const
matching information
float timeOfFlight() const
timing for PID
Double_t nSigmaKaon() const
Returns Craig's distance to the calculated dE/dx band for kaons in units of sigma.
void setETofPidTraits(const StMuETofPidTraits &pid)
dongx
StPhysicalHelixD outerHelix() const
Returns outer helix (last measured point)
double calibTot() const
Getter for calibrated Tot.
unsigned int counter() const
Counter.
virtual TDataSet * Find(const char *path) const
void setIndex2ETofHit(Int_t i)
dongx
unsigned short matchFlag() const
matching information