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 "StETofCalibMaker/StETofCalibMaker.h"
94 #include "StETofUtil/StETofGeometry.h"
95 #include "StETofUtil/StETofConstants.h"
97 #include "tables/St_etofMatchParam_Table.h"
102 namespace etofProjection {
104 const double safetyMargins[ 2 ] = { 2., 2. };
106 const float minEtaCut = 0.0;
108 const float minEtaProjCut = -1.0;
109 const float maxEtaProjCut = -1.7;
113 const double deltaXoffset[ 108 ] = { 0 };
115 const double deltaYoffset[ 108 ] = { 0 };
117 const double deltaRcut = 4.;
121 static const double kaon_minus_mass_c2 = 493.68 * MeV;
124 namespace etofHybridT0 {
125 const unsigned int minCand = 2;
126 const unsigned int nSwitch = 5;
127 const unsigned int nMin = 10;
128 const unsigned int nUpdate = 5;
129 const float lowCut = 0.10;
130 const float highCut = 0.85;
131 const float diffToClear = 2.;
132 const float biasOffset = 0.075;
138 StETofMatchMaker::StETofMatchMaker(
const char* name )
139 :
StMaker(
"etofMatch", name ),
142 mETofGeom( nullptr ),
143 mFileNameMatchParam(
"" ),
144 mFileNameAlignParam(
"" ),
145 mIsStEventIn( false ),
147 mOuterTrackGeometry( true ),
148 mUseHelixSwimmer( false ),
149 mUseOnlyBTofHeaderStartTime( true ),
155 mMatchDistT( 99999. ),
164 mClockJumpDirection(),
173 mT0corrVec.reserve( 500 );
174 mTrackCuts.push_back( 0. );
175 mTrackCuts.push_back( 0. );
176 mTrackCuts.push_back( 0. );
182 StETofMatchMaker::~StETofMatchMaker()
190 StETofMatchMaker::Init()
192 LOG_INFO <<
"StETofMatchMaker::Init()" << endm;
194 LOG_INFO <<
"isSimulation flag was set to: " << mIsSim << endm;
204 StETofMatchMaker::InitRun( Int_t runnumber )
206 LOG_INFO <<
"StETofMatchMaker::InitRun()" << endm;
209 std::ifstream paramFile;
217 if( mFileNameMatchParam.empty() ) {
218 LOG_INFO <<
"etofMatchParam: no filename provided --> load database table" << endm;
220 dbDataSet = GetDataBase(
"Calibrations/etof/etofMatchParam" );
222 St_etofMatchParam* etofMatchParam =
static_cast< St_etofMatchParam*
> ( dbDataSet->
Find(
"etofMatchParam" ) );
223 if( !etofMatchParam ) {
224 LOG_ERROR <<
"unable to get the match params from the database" << endm;
228 etofMatchParam_st* matchParamTable = etofMatchParam->GetTable();
230 mMatchRadius = matchParamTable->matchRadius;
232 mTrackCuts.at( 0 ) = matchParamTable->trackCutNHitsFit;
233 mTrackCuts.at( 1 ) = matchParamTable->trackCutNHitsRatio;
234 mTrackCuts.at( 2 ) = matchParamTable->trackCutLowPt;
238 LOG_INFO <<
"etofMatchParam: filename provided --> use parameter file: " << mFileNameMatchParam.c_str() << endm;
240 paramFile.open( mFileNameMatchParam.c_str() );
242 if( !paramFile.is_open() ) {
243 LOG_ERROR <<
"unable to get the 'etofMatchParam' parameters from file --> file does not exist" << endm;
247 std::vector< float > param;
249 while( paramFile >> temp ) {
250 param.push_back( temp );
255 if( param.size() != 4 ) {
256 LOG_ERROR <<
"parameter file for 'etofMatchParam' has not the right amount of entries: ";
257 LOG_ERROR << param.size() <<
" instead of 4 !!!!" << endm;
261 mMatchRadius = param.at( 0 );
263 mTrackCuts.at( 0 ) = param.at( 1 );
264 mTrackCuts.at( 1 ) = param.at( 2 );
265 mTrackCuts.at( 2 ) = param.at( 3 );
269 LOG_INFO <<
" match radius: " << mMatchRadius << endm;
270 LOG_INFO <<
" track cut (nHitsFit): " << mTrackCuts.at( 0 ) << endm;
271 LOG_INFO <<
" track cut (nHitsRatio): " << mTrackCuts.at( 1 ) << endm;
272 LOG_INFO <<
" track cut (low pt): " << mTrackCuts.at( 2 ) << endm;
281 LOG_INFO <<
" creating a new eTOF geometry . . . " << endm;
282 mETofGeom =
new StETofGeometry(
"etofGeometry",
"etofGeometry in MatchMaker" );
285 if( mETofGeom && !mETofGeom->isInitDone() ) {
286 LOG_INFO <<
" eTOF geometry initialization ... " << endm;
288 if( !gGeoManager ) GetDataBase(
"VmcGeometry" );
291 LOG_ERROR <<
"Cannot get GeoManager" << endm;
295 LOG_DEBUG <<
" gGeoManager: " << gGeoManager << endm;
297 if (mFileNameAlignParam !=
""){
298 LOG_DEBUG <<
" gGeoManager: Setting alignment file: " << mFileNameAlignParam << endm;
299 mETofGeom->setFileNameAlignParam(mFileNameAlignParam);
302 mETofGeom->init( gGeoManager, etofProjection::safetyMargins, mUseHelixSwimmer );
305 if ( mETofGeom && !mETofGeom->isInitDone() ) {
306 LOG_ERROR <<
"Initialization of StEtofGeometry failed" << endm;
316 LOG_DEBUG <<
"StETofMatchMaker::InitRun() -- pointer to eTOF hit maker: " << mETofHitMaker << endm;
320 for(
unsigned int i=0; i<mETofGeom->nValidModules(); i++ ) {
324 int sector = mETofGeom->module( i )->sector();
325 int plane = mETofGeom->module( i )->plane();
327 for(
int j=0; j<sector; j++ ) {
328 mHistograms.at(
"eTofSectors" )->Fill( pos.x(), pos.y() );
330 for(
int j=0; j<plane; j++ ) {
331 mHistograms.at(
"eTofModules" )->Fill( pos.x(), pos.y() );
337 int nBinsX = mHistograms2d.at(
"bfield_z" )->GetNbinsX();
338 int nBinsY = mHistograms2d.at(
"bfield_z" )->GetNbinsY();
339 for(
int i=0; i<nBinsX; i++ ) {
340 for(
int j=0; j<nBinsY; j++ ) {
341 double z = mHistograms2d.at(
"bfield_z" )->GetXaxis()->GetBinCenter( i );
342 double y = mHistograms2d.at(
"bfield_z" )->GetYaxis()->GetBinCenter( j );
344 mHistograms2d.at(
"bfield_z" )->Fill( z, y, mETofGeom->getFieldZ( 0., y, z ) );
355 StETofMatchMaker::FinishRun( Int_t runnumber )
357 LOG_DEBUG <<
"StETofMatchMaker::FinishRun() -- cleaning up the geometry" << endm;
371 LOG_DEBUG <<
"StETofMatchMaker::Finish()" << endm;
374 LOG_INFO <<
"Finish() - writing *.etofMatch.root ..." << endm;
392 LOG_DEBUG <<
"StETofMatchMaker::Make(): starting ..." << endm;
394 mIsStEventIn =
false;
397 mEvent = (
StEvent* ) GetInputDS(
"StEvent" );
401 LOG_DEBUG <<
"Make() - running on StEvent" << endm;
405 if( !etofCollection ) {
406 LOG_WARN <<
"Make() - Found StEvent data structure, but no eTOF collection. Try MuDst processing instead" << endm;
407 mMuDst = (
StMuDst* ) GetInputDS(
"MuDst" );
410 LOG_DEBUG <<
"Make() - running on MuDsts" << endm;
414 fillIndexToPrimaryMap();
425 LOG_DEBUG <<
"Make(): no StEvent found" << endm;
427 mMuDst = (
StMuDst* ) GetInputDS(
"MuDst" );
430 LOG_DEBUG <<
"Make() - running on MuDsts" << endm;
434 fillIndexToPrimaryMap();
439 LOG_DEBUG <<
"Make() - no StMuDst found" << endm;
444 if( !mIsStEventIn && !mIsMuDstIn ) {
445 LOG_WARN <<
"Make() - neither StEvent nor MuDst available ... bye-bye" << endm;
450 mHistograms.at(
"eventCounter" )->Fill( 1 );
456 eTofHitVec detectorHitVec;
458 readETofDetectorHits( detectorHitVec );
460 if( detectorHitVec.size() == 0 ) {
469 eTofHitVec intersectionVec;
470 int nPrimaryWithIntersection = 0;
472 float bFieldFromGeom = mETofGeom->getFieldZ( 100., 100., 0. );
475 bField = mMuDst->
event()->runInfo().magneticField();
478 bField = mEvent->runInfo()->magneticField();
481 if( mUseHelixSwimmer && fabs( bFieldFromGeom - bField ) > 0.2 ) {
482 LOG_WARN <<
"Wrong magnetc field bField = " << bField <<
" bFieldFromGeom = " << bFieldFromGeom <<
" --> check the magF input!" << endm;
485 findTrackIntersections( intersectionVec, nPrimaryWithIntersection );
487 if( intersectionVec.size() == 0 ) {
493 mHistograms.at(
"intersectionMult_etofMult" )->Fill( detectorHitVec.size(), intersectionVec.size() );
498 eTofHitVec matchCandVec;
500 matchETofHits( detectorHitVec, intersectionVec, matchCandVec );
502 if( matchCandVec.size() == 0 ) {
509 eTofHitVec finalMatchVec;
510 sortandcluster(matchCandVec , detectorHitVec , intersectionVec , finalMatchVec);
517 eTofHitVec singleTrackMatchVec;
518 vector< eTofHitVec > multiTrackMatchVec;
533 if( finalMatchVec.size() == 0 ) {
545 fillPidTraits( finalMatchVec );
550 int nPrimaryWithPid = 0;
552 calculatePidVariables( finalMatchVec, nPrimaryWithPid );
554 mHistograms.at(
"primaryIntersect_validMatch" )->Fill( nPrimaryWithIntersection, nPrimaryWithPid );
559 fillQaHistograms( finalMatchVec );
561 fillSlewHistograms( finalMatchVec );
571 void StETofMatchMaker::fillIndexToPrimaryMap()
574 mIndex2Primary.clear();
576 for(
int i = 0; i < mMuDst->
array( muPrimary )->GetEntries(); i++ ) {
582 if( index2Global < 0 ) {
585 mIndex2Primary[ index2Global ] = i;
590 void StETofMatchMaker::cleanUpTraits()
594 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
595 size_t nNodes = nodes.size();
596 for(
size_t iNode = 0; iNode < nNodes; iNode++ ) {
598 if( !gTrack )
continue;
601 StSPtrVecTrackPidTraits& traits = gTrack->pidTraits();
602 for(
auto it = traits.begin(); it != traits.end(); it++ ) {
603 if( ( *it )->detector() == kETofId ) {
608 LOG_INFO <<
"cleanUpTraits() - etof traits on global track " << iNode <<
" already exist" << endm;
609 LOG_INFO <<
"matchFlag: " << etofTraits->
matchFlag() <<
" localX: " << etofTraits->localX() <<
" localY: " << etofTraits->localY();
610 LOG_INFO <<
" tof: " << etofTraits->
timeOfFlight() <<
" pathlength: " << etofTraits->pathLength() <<
" beta: " << etofTraits->beta() << endm;
612 if( etofTraits->etofHit() ) {
613 LOG_INFO <<
"time: " << etofTraits->etofHit()->
time() << endm;
620 LOG_INFO <<
" ... erased" << endm;
630 StSPtrVecTrackPidTraits& ptraits = pTrack->pidTraits();
631 for(
auto it = ptraits.begin(); it != ptraits.end(); it++ ) {
632 if( ( *it )->detector() == kETofId ) {
637 LOG_INFO <<
"cleanUpTraits() - etof traits on primary track corresponding to node " << iNode <<
" already exist" << endm;
638 LOG_INFO <<
"matchFlag: " << etofTraits->
matchFlag() <<
" localX: " << etofTraits->localX() <<
" localY: " << etofTraits->localY();
639 LOG_INFO <<
" tof: " << etofTraits->
timeOfFlight() <<
" pathlength: " << etofTraits->pathLength() <<
" beta: " << etofTraits->beta() << endm;
641 if( etofTraits->etofHit() ) {
642 LOG_INFO <<
"time: " << etofTraits->etofHit()->
time() << endm;
649 LOG_INFO <<
" ... erased" << endm;
659 size_t nHits = mEvent->etofCollection()->etofHits().size();
660 for(
size_t i=0; i<nHits; i++ ) {
661 StETofHit* aHit = mEvent->etofCollection()->etofHits().at( i );
662 if( !aHit )
continue;
663 aHit->setAssociatedTrack(
nullptr );
668 size_t nNodes = mMuDst->numberOfGlobalTracks();
669 for(
size_t iNode=0; iNode<nNodes; iNode++ ) {
671 if( !track )
continue;
677 LOG_INFO <<
"cleanUpTraits() - etof traits on global track " << iNode <<
" already exist" << endm;
678 LOG_INFO <<
"matchFlag: " << etofTraits.
matchFlag() <<
" localX: " << etofTraits.localX() <<
" localY: " << etofTraits.localY();
679 LOG_INFO <<
" tof: " << etofTraits.
timeOfFlight() <<
" pathlength: " << etofTraits.pathLength() <<
" beta: " << etofTraits.beta() << endm;
692 LOG_INFO <<
" ... erased" << endm;
696 auto it = mIndex2Primary.find( iNode );
697 if( it != mIndex2Primary.end() ) {
707 LOG_INFO <<
"cleanUpTraits() - etof traits on primary track " << pIndex <<
" already exist" << endm;
708 LOG_INFO <<
"matchFlag: " << etofTraits.
matchFlag() <<
" localX: " << etofTraits.localX() <<
" localY: " << etofTraits.localY();
709 LOG_INFO <<
" tof: " << etofTraits.
timeOfFlight() <<
" pathlength: " << etofTraits.pathLength() <<
" beta: " << etofTraits.beta() << endm;
721 LOG_INFO <<
" ... erased" << endm;
727 size_t nHits = mMuDst->numberOfETofHit();
728 for(
size_t i=0; i<nHits; i++ ) {
730 if( !aHit )
continue;
731 aHit->setIndex2Primary( -1 );
732 aHit->setIndex2Global( -1 );
733 aHit->setAssociatedTrackId( -1 );
745 StETofMatchMaker::readETofDetectorHits( eTofHitVec& detectorHitVec )
751 if( !mEvent->etofCollection() ) {
752 LOG_WARN <<
"readETofDetectorHits() - no etof collection --> nothing to do ... bye-bye" << endm;
755 if( !mEvent->etofCollection()->hitsPresent() ) {
756 LOG_WARN <<
"readETofDetectorHits() - no etof hits present --> nothing to do ... bye-bye" << endm;
760 nHits = mEvent->etofCollection()->etofHits().size();
763 else if( mIsMuDstIn ) {
765 LOG_WARN <<
"readETofDetectorHits() - no digi array --> nothing to do ... bye-bye" << endm;
769 if( !mMuDst->numberOfETofHit() ) {
770 LOG_WARN <<
"readETofDetectorHits() - no hits present --> nothing to do ... bye-bye" << endm;
774 nHits = mMuDst->numberOfETofHit();
779 mHistograms.at(
"eventCounter" )->Fill( 2 );
785 for(
size_t i=0; i<nHits; i++ ) {
786 StETofHit* aHit = mEvent->etofCollection()->etofHits().at( i );
792 if( fabs(aHit->
localY()) > mLocalYmax ) {
796 StructETofHit detectorHit;
798 detectorHit.sector = aHit->
sector();
806 detectorHit.plane = aHit->
zPlane();
807 detectorHit.counter = aHit->
counter();
808 detectorHit.hitTime = aHit->
time();
809 detectorHit.localX = aHit->
localX();
810 detectorHit.localY = aHit->
localY();
813 detectorHit.index2ETofHit = i;
815 detectorHitVec.push_back( detectorHit );
819 for(
size_t i=0; i<nHits; i++ ) {
826 if( fabs(aHit->
localY()) > mLocalYmax ) {
830 StructETofHit detectorHit;
840 detectorHit.plane = aHit->
zPlane();
841 detectorHit.counter = aHit->
counter();
842 detectorHit.hitTime = aHit->
time();
843 detectorHit.localX = aHit->
localX();
844 detectorHit.localY = aHit->
localY();
847 detectorHit.index2ETofHit = i;
849 detectorHitVec.push_back( detectorHit );
860 for(
auto&
hit : detectorHitVec ) {
861 double xl[ 3 ] = {
hit.localX,
hit.localY, 0 };
863 int moduleId = mETofGeom->calcModuleIndex(
hit.sector,
hit.plane );
864 int counterId =
hit.counter - 1;
867 mETofGeom->hitLocal2Master( moduleId, counterId, xl, xg );
871 hit.globalPos = globalPos;
873 hit.strip = ( (
StETofGeomCounter* ) mETofGeom->findETofNode( moduleId, counterId ) )->findStrip( xl );
876 LOG_DEBUG <<
"hit( " <<
hit.index2ETofHit <<
" ) at sector: " <<
hit.sector;
877 LOG_DEBUG <<
" zPlane: " <<
hit.plane <<
" counter: " <<
hit.counter;
878 LOG_DEBUG <<
" with local (X, Y): (" << xl[ 0 ] <<
", " << xl[ 1 ] <<
")" << endm;
879 LOG_DEBUG <<
"global (X, Y, Z): " << xg[ 0 ] <<
", " << xg[ 1 ] <<
", " << xg[ 2 ] << endm;
880 LOG_DEBUG <<
" strip: " <<
hit.strip << endm;
884 float hit_eta = globalPos.pseudoRapidity();
885 float hit_phi = globalPos.phi();
887 if ( hit_phi < 0. ) hit_phi += 2. * M_PI;
889 LOG_DEBUG <<
"global (eta, phi): " << hit_eta <<
", " << hit_phi << endm;
891 if( fabs(
hit.localY ) < eTofConst::stripLength / 2. * 1.5 ) {
892 mHistograms.at(
"eTofHits_globalXY" )->Fill( globalPos.x(), globalPos.y() );
896 if( fabs(
hit.localY ) < eTofConst::stripLength / 2. * 1.5 ) {
897 mHistograms.at(
"eTofHits_phi_eta" )->Fill( hit_phi, hit_eta );
900 if(
hit.sector == 18 ||
hit.sector == 24 ) {
901 mHistograms.at(
"eTofHits_globalYZ" )->Fill( globalPos.y(), globalPos.z() );
904 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 );
905 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 );
906 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 );
908 mHistograms.at( histName_hit_localXY )->Fill(
hit.localX,
hit.localY );
909 mHistograms.at( histName_hit_globalXY )->Fill(
hit.globalPos.x(),
hit.globalPos.y() );
910 mHistograms.at( histName_hit_eta_phi )->Fill( hit_phi, hit_eta );
915 mHistograms.at(
"detectorHitMult" )->Fill( detectorHitVec.size() );
916 if( detectorHitVec.size() > 0 ) {
917 mHistograms.at(
"eventCounter" )->Fill( 3 );
928 StETofMatchMaker::findTrackIntersections( eTofHitVec& intersectionVec,
int& nPrimaryWithIntersection )
931 size_t nPrimaryCrossings = 0;
935 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
937 nNodes = nodes.size();
940 LOG_INFO <<
"# tracks in the event: " << nNodes << endm;
943 for(
size_t iNode = 0; iNode < nNodes; iNode++ ) {
945 LOG_DEBUG <<
"track : " << iNode << endm;
949 if( !validTrack( theTrack ) )
continue;
951 bool isPrimary =
false;
956 LOG_DEBUG <<
"track : " << iNode <<
" is a primary track" << endm;
960 StPhysicalHelixD theHelix = mOuterTrackGeometry ? theTrack->outerGeometry()->helix() : theTrack->geometry()->helix();
964 extrapolateTrackToETof( intersectionVec, theHelix, iNode, nCrossings, isPrimary );
968 nPrimaryCrossings += nCrossings;
969 if( nCrossings > 0 ) {
970 nPrimaryWithIntersection++;
973 int charge = pTrack->geometry()->charge();
974 float pMom = pTrack->geometry()->momentum().mag();
976 mHistograms.at(
"intersection_primaryTrack_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
977 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackpos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
978 else mHistograms.at(
"intersection_primaryTrackneg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
981 mHistograms.at(
"intersection_primaryTrackMom0_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
982 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom0pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
983 else mHistograms.at(
"intersection_primaryTrackMom0neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
985 else if( pMom > 0.5 ) {
986 mHistograms.at(
"intersection_primaryTrackMom1_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
987 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom1pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
988 else mHistograms.at(
"intersection_primaryTrackMom1neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
991 mHistograms.at(
"intersection_primaryTrackMom2_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
992 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom2pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
993 else mHistograms.at(
"intersection_primaryTrackMom2neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
999 if( mDoQA && nCrossings > 0 ) {
1002 mHistograms.at(
"intersection_track_pt_eta" )->Fill( eTrack.pt, eTrack.eta );
1003 mHistograms.at(
"intersection_track_pt_phi" )->Fill( eTrack.pt, eTrack.phi );
1004 mHistograms.at(
"intersection_track_phi_eta" )->Fill( eTrack.phi, eTrack.eta );
1006 mHistograms.at(
"intersection_track_nHitsTpc" )->Fill( eTrack.nFtPts );
1008 if( eTrack.dEdx > -999. ) mHistograms.at(
"intersection_track_mom_dEdx" )->Fill( eTrack.pt * cosh( eTrack.eta ), eTrack.dEdx );
1009 if( eTrack.nSigmaPion > -999. ) mHistograms.at(
"intersection_track_mom_nsigmaPi" )->Fill( eTrack.pt * cosh( eTrack.eta ), eTrack.nSigmaPion );
1014 nNodes = mMuDst->numberOfGlobalTracks();
1017 LOG_INFO <<
"# tracks in the event: " << nNodes << endm;
1020 for(
size_t iNode = 0; iNode < nNodes; iNode++ ) {
1022 LOG_DEBUG <<
"track : " << iNode << endm;
1027 if( !validTrack( theTrack ) )
continue;
1029 bool isPrimary=
false;
1032 auto it = mIndex2Primary.find( iNode );
1033 if( it != mIndex2Primary.end() ) {
1034 pIndex = it->second;
1039 LOG_DEBUG <<
"track : " << iNode <<
" is a primary track" << endm;
1047 extrapolateTrackToETof( intersectionVec, theHelix, iNode, nCrossings, isPrimary );
1050 nPrimaryCrossings += nCrossings;
1051 if( nCrossings > 0 ) {
1052 nPrimaryWithIntersection++;
1058 mHistograms.at(
"intersection_primaryTrack_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1059 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackpos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1060 else mHistograms.at(
"intersection_primaryTrackneg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1063 mHistograms.at(
"intersection_primaryTrackMom0_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1064 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom0pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1065 else mHistograms.at(
"intersection_primaryTrackMom0neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1067 else if( pMom > 0.5 ) {
1068 mHistograms.at(
"intersection_primaryTrackMom1_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1069 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom1pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1070 else mHistograms.at(
"intersection_primaryTrackMom1neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1073 mHistograms.at(
"intersection_primaryTrackMom2_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1074 if( charge > 0 ) mHistograms.at(
"intersection_primaryTrackMom2pos_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1075 else mHistograms.at(
"intersection_primaryTrackMom2neg_globalXY" )->Fill( intersectionVec.back().globalPos.x() , intersectionVec.back().globalPos.y() );
1081 if( mDoQA && nCrossings > 0 ) {
1084 mHistograms.at(
"intersection_track_pt_eta" )->Fill( eTrack.pt, eTrack.eta );
1085 mHistograms.at(
"intersection_track_pt_phi" )->Fill( eTrack.pt, eTrack.phi );
1086 mHistograms.at(
"intersection_track_phi_eta" )->Fill( eTrack.phi, eTrack.eta );
1088 mHistograms.at(
"intersection_track_nHitsTpc" )->Fill( eTrack.nFtPts );
1090 if( eTrack.dEdx > 0. ) mHistograms.at(
"intersection_track_mom_dEdx" )->Fill( eTrack.pt * cosh( eTrack.eta ), eTrack.dEdx );
1091 if( eTrack.nSigmaPion > -999. ) mHistograms.at(
"intersection_track_mom_nsigmaPi" )->Fill( eTrack.pt * cosh( eTrack.eta ), eTrack.nSigmaPion );
1099 mHistograms.at(
"intersectionMult" )->Fill( intersectionVec.size() );
1100 mHistograms.at(
"intersectionMult_primary" )->Fill( nPrimaryCrossings );
1102 if( intersectionVec.size() > 0 ) {
1103 mHistograms.at(
"eventCounter" )->Fill( 4 );
1112 StETofMatchMaker::validTrack(
const StTrack* track )
1115 return validTrack(
ETofTrack( track ) );
1125 StETofMatchMaker::validTrack(
const StMuTrack* track )
1128 return validTrack(
ETofTrack( track ) );
1138 StETofMatchMaker::validTrack(
const ETofTrack& track )
1140 double ratioFitToPoss = 1. * track.nFtPts / track.nHitsPoss;
1143 mHistograms.at(
"track_phi_eta" ) ->Fill( track.phi, track.eta );
1144 mHistograms.at(
"track_phi_pt" ) ->Fill( track.phi, track.pt );
1145 mHistograms.at(
"nHits" ) ->Fill( track.nFtPts );
1146 mHistograms.at(
"track_pt_nHits" )->Fill( track.pt, track.nFtPts );
1151 if( track.eta > etofProjection::minEtaCut )
return false;
1153 if( mDoQA && track.eta > -1.65 && track.eta < -1.05 ) {
1154 mHistograms.at(
"nHits_etofregion" )->Fill( track.nFtPts );
1160 if( track.nFtPts < mTrackCuts.at( 0 ) )
return false;
1161 if( ratioFitToPoss < mTrackCuts.at( 1 ) )
return false;
1162 if( track.pt < mTrackCuts.at( 2 ) )
return false;
1166 LOG_DEBUG <<
"valid track for extrapolation to eTOF with nHitsFit: " << track.nFtPts;
1167 LOG_DEBUG <<
" mom: " << track.mom <<
" pt: " << track.pt <<
" phi: " << track.phi <<
" eta: " << track.eta << endm;
1175 StETofMatchMaker::extrapolateTrackToETof( eTofHitVec& intersectionVec,
const StPhysicalHelixD& theHelix,
const int& iNode,
int& nCrossings,
bool isPrimary )
1178 StThreeVectorD projection = mETofGeom->helixCrossPlane( theHelix, eTofConst::zplanes[ 1 ] );
1181 float projEta = projection.pseudoRapidity();
1183 if( projEta < etofProjection::maxEtaProjCut )
return;
1184 if( projEta > etofProjection::minEtaProjCut )
return;
1186 float projPhi = projection.phi();
1187 if ( projPhi < 0. ) projPhi += 2. * M_PI;
1191 mHistograms.at(
"trackProj_globalXY" )->Fill( projection.x(), projection.y() );
1192 mHistograms.at(
"trackProj_phi_eta" )->Fill( projPhi, projEta );
1195 vector< int > idVec;
1196 vector< StThreeVectorD > globalVec;
1197 vector< StThreeVectorD > localVec;
1198 vector< double > thetaVec;
1199 vector< double > pathLenVec;
1202 mETofGeom->
helixCrossCounter( theHelix, idVec, globalVec, localVec, thetaVec, pathLenVec );
1204 nCrossings = idVec.size();
1208 for(
int i = nCrossings-1; i >= 0; i-- ) {
1210 LOG_INFO <<
" ------> crossing with volume index: " << idVec.at( i ) << endm;
1211 LOG_INFO <<
"track intersection: " << globalVec.at( i ).x() <<
", " << globalVec.at( i ).y() <<
", " << globalVec.at( i ).z() << endm;
1212 LOG_INFO <<
"local coordinates: " << localVec.at( i ).x() <<
", " << localVec.at( i ).y() <<
", " << localVec.at( i ).z() << endm;
1215 StructETofHit intersect;
1217 mETofGeom->decodeVolumeIndex( idVec.at( i ), intersect.sector, intersect.plane, intersect.counter, intersect.strip );
1219 intersect.localX = localVec.at( i ).x();
1220 intersect.localY = localVec.at( i ).y();
1221 intersect.globalPos = globalVec.at( i );
1222 intersect.trackId = iNode;
1223 intersect.theta = thetaVec.at( i );
1224 intersect.pathLength = pathLenVec.at( i );
1225 intersect.isPrimary = isPrimary;
1228 intersectionVec.push_back( intersect );
1232 float intersectPhi = intersect.globalPos.phi();
1233 if( intersectPhi < 0. ) intersectPhi += 2. * M_PI;
1235 mHistograms.at(
"intersection_globalXY" )->Fill( intersect.globalPos.x(), intersect.globalPos.y() );
1236 mHistograms.at(
"intersection_phi_eta" )->Fill( intersectPhi, intersect.globalPos.pseudoRapidity() );
1241 mHistograms.at(
"intersection_perTrack" )->Fill( idVec.size() );
1251 StETofMatchMaker::matchETofHits( eTofHitVec& detectorHitVec, eTofHitVec& intersectionVec, eTofHitVec& matchCandVec )
1253 for(
auto detHitIter = detectorHitVec.begin(); detHitIter != detectorHitVec.end(); detHitIter++ ) {
1254 for(
auto interIter = intersectionVec.begin(); interIter != intersectionVec.end(); interIter++ ) {
1257 int sector = detHitIter->sector;
1258 int plane = detHitIter->plane;
1260 int moduleId = ( sector - eTofConst::sectorStart ) * eTofConst::nPlanes + plane - eTofConst::zPlaneStart;
1263 int detHitIndex = ( detHitIter->counter - eTofConst::counterStart ) * eTofConst::nStrips + detHitIter->strip - eTofConst::stripStart;
1264 int intersecIndex = ( interIter->counter - eTofConst::counterStart ) * eTofConst::nStrips + interIter->strip - eTofConst::stripStart;
1266 mHistograms.at(
"detHitvsInter_strip_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) )->Fill( detHitIndex, intersecIndex );
1268 mHistograms.at(
"detHitvsInter_X" )->Fill( detHitIter->globalPos.x(), interIter->globalPos.x() );
1269 mHistograms.at(
"detHitvsInter_Y" )->Fill( detHitIter->globalPos.y(), interIter->globalPos.y() );
1271 mHistograms.at(
"moduleIndex_deltaX" )->Fill( moduleId, detHitIter->localX - interIter->localX );
1272 mHistograms.at(
"moduleIndex_deltaY" )->Fill( moduleId, detHitIter->localY - interIter->localY );
1274 mHistograms.at(
"detHitvsInter_localX" )->Fill(detHitIter->localX, interIter->localX );
1275 mHistograms.at(
"detHitvsInter_localY" )->Fill(detHitIter->localY, interIter->localY );
1280 bool isMatch =
false;
1283 float deltaX = detHitIter->localX - interIter->localX;
1284 float deltaY = detHitIter->localY - interIter->localY;
1285 double tstart = startTimeBTof();
1286 double deltaT = detHitIter->hitTime - tstart;
1288 int counterIndex = ( detHitIter->sector - eTofConst::sectorStart ) * eTofConst::nPlanes * eTofConst::nCounters
1289 + ( detHitIter->plane - eTofConst::zPlaneStart ) * eTofConst::nCounters
1290 + ( detHitIter->counter - eTofConst::counterStart );
1292 deltaX -= etofProjection::deltaXoffset[ counterIndex ];
1293 deltaY -= etofProjection::deltaYoffset[ counterIndex ];
1295 bool corrTime=
false;
1297 if( detHitIter->sector == interIter->sector ) {
1298 if( detHitIter->plane == interIter->plane ) {
1299 if( detHitIter->counter == interIter->counter ) {
1301 if(detHitIter->clusterSize < 999){
1306 if( ( ( (deltaY*deltaY) / (mMatchDistY*mMatchDistY) ) + ( (deltaX*deltaX) / (mMatchDistX*mMatchDistX) ) ) < 2. ) {
1307 if( fabs( deltaT ) < mMatchDistT ) {
1313 float mMatchDistYSingleSided = 15;
1317 if( fabs( deltaX ) < mMatchDistX ) {
1318 if( fabs( deltaY ) < mMatchDistYSingleSided ) {
1319 if( fabs( deltaT ) < mMatchDistT ) {
1335 StructETofHit matchCand;
1337 matchCand.sector = detHitIter->sector;
1338 matchCand.plane = detHitIter->plane;
1339 matchCand.counter = detHitIter->counter;
1340 matchCand.strip = detHitIter->strip;
1341 matchCand.localX = detHitIter->localX;
1342 matchCand.localY = detHitIter->localY;
1343 matchCand.hitTime = detHitIter->hitTime;
1344 matchCand.tot = detHitIter->tot;
1345 matchCand.clusterSize = detHitIter->clusterSize;
1346 matchCand.index2ETofHit = detHitIter->index2ETofHit;
1347 matchCand.IdTruthHit = detHitIter->IdTruth;
1349 matchCand.globalPos = interIter->globalPos;
1350 matchCand.trackId = interIter->trackId;
1351 matchCand.theta = interIter->theta;
1352 matchCand.pathLength = interIter->pathLength;
1353 matchCand.isPrimary = interIter->isPrimary;
1354 matchCand.IdTruth = interIter->IdTruth;
1356 matchCand.matchFlag = 0;
1357 matchCand.deltaX = deltaX;
1358 matchCand.deltaY = deltaY;
1360 matchCand.tof = -999.;
1361 matchCand.beta = -999.;
1365 matchCand.localY = interIter->localY;
1370 if(sector == 15 || sector == 17 || sector == 21 || sector == 22 ){
1375 if(detHitIter->localY < 0){
1376 matchCand.hitTime = detHitIter->hitTime - (((13.5 + interIter->localY ) / tcorr )) + (13.5/tcorr);
1378 corr = (((13.5 - interIter->localY ) / tcorr ));
1381 matchCand.hitTime = detHitIter->hitTime - (((13.5 - interIter->localY ) / tcorr )) + (13.5/tcorr);
1383 corr = (((13.5 + interIter->localY ) / tcorr ));
1386 matchCand.totDiff = matchCand.totDiff * corr;
1394 matchCandVec.push_back( matchCand );
1397 LOG_INFO <<
" * * FOUND MATCH CAND : " << matchCand.sector <<
" " << matchCand.plane <<
" " << matchCand.counter;
1398 LOG_INFO <<
" with (deltaX, deltaY) = (" << deltaX <<
", " << deltaY <<
")" << endm;
1401 mHistograms.at(
"matchCand_globalXY" )->Fill( matchCand.globalPos.x(), matchCand.globalPos.y() );
1404 float matchCandPhi = matchCand.globalPos.phi();
1405 if ( matchCandPhi < 0. ) matchCandPhi += 2. * M_PI;
1407 mHistograms.at(
"matchCand_phi_eta" )->Fill( matchCandPhi, matchCand.globalPos.pseudoRapidity() );
1409 mHistograms.at(
"matchCand_deltaX" )->Fill( deltaX );
1410 mHistograms.at(
"matchCand_deltaY" )->Fill( deltaY );
1412 std::string histName_deltaX =
"matchCand_deltaX_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
1413 std::string histName_deltaY =
"matchCand_deltaY_s" + std::to_string( matchCand.sector ) +
"m" + std::to_string( matchCand.plane ) +
"c" + std::to_string( matchCand.counter );
1415 mHistograms.at( histName_deltaX )->Fill( deltaX );
1416 mHistograms.at( histName_deltaY )->Fill( deltaY );
1420 if( mIsStEventIn ) {
1421 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
1423 if( matchCandTrack ) {
1424 int nFitPts = matchCandTrack->fitTraits().numberOfFitPoints( kTpcId );
1426 mHistograms.at(
"matchCand_deltaX_nHitsTpc" )->Fill( nFitPts, deltaX );
1427 mHistograms.at(
"matchCand_deltaY_nHitsTpc" )->Fill( nFitPts, deltaY );
1432 if( matchCandTrack ) {
1433 int nFitPts = matchCandTrack->
nHitsFit( kTpcId );
1435 mHistograms.at(
"matchCand_deltaX_nHitsTpc" )->Fill( nFitPts, deltaX );
1436 mHistograms.at(
"matchCand_deltaY_nHitsTpc" )->Fill( nFitPts, deltaY );
1446 mHistograms.at(
"matchCandMult" )->Fill( matchCandVec.size() );
1448 if( matchCandVec.size() > 0 ) {
1449 mHistograms.at(
"eventCounter" )->Fill( 5 );
1460 StETofMatchMaker::sortSingleMultipleHits( eTofHitVec& matchCandVec, eTofHitVec& singleTrackMatchVec, std::vector< eTofHitVec >& multiTrackMatchVec )
1462 int nSingleTrackMatch = 0;
1463 int nMultiTrackMatch = 0;
1467 eTofHitVec tempVec = matchCandVec;
1468 eTofHitVec erasedVec = tempVec;
1470 while( tempVec.size() != 0 ) {
1476 eTofHitVecIter tempIter = tempVec.begin();
1477 eTofHitVecIter erasedIter = erasedVec.begin();
1479 while( erasedIter != erasedVec.end() ) {
1481 if( tempIter->index2ETofHit == erasedIter->index2ETofHit ) {
1483 candVec.push_back( *erasedIter );
1485 erasedVec.erase( erasedIter );
1491 tempVec = erasedVec;
1493 StructETofHit cand = candVec.front();
1496 LOG_INFO <<
"matchCand at sector " << cand.sector <<
" plane " << cand.plane <<
" counter " << cand.counter <<
" with local (X,Y) = (" << cand.localX <<
"," << cand.localY <<
")";
1497 LOG_INFO <<
" has " << nTracks <<
" track(s) pointing to it:" << endm;
1500 if( nTracks == 1 ) {
1501 nSingleTrackMatch++;
1502 singleTrackMatchVec.push_back( cand );
1505 LOG_INFO <<
"track id: " << cand.trackId <<
" and matching distance " << cand.deltaX <<
" " << cand.deltaY << endm;
1508 else if( nTracks > 1 ) {
1513 multiTrackMatchVec.push_back( candVec );
1515 float bestResidual = 999.;
1518 for(
size_t i=0; i<candVec.size(); i++ ) {
1520 LOG_INFO <<
"track id: " << candVec.at( i ).trackId <<
" and matching distance " << candVec.at( i ).deltaX <<
" " << candVec.at( i ).deltaY << endm;
1522 float residual = pow( candVec.at( i ).deltaX, 2 ) + pow( candVec.at( i ).deltaY, 2 );
1524 if( residual < bestResidual ) {
1525 bestResidual = residual;
1530 if( bestIndex > -1 ) {
1531 singleTrackMatchVec.push_back( candVec.at( bestIndex ) );
1533 LOG_INFO <<
"best candidate has track id: " << candVec.at( bestIndex ).trackId << endm;
1538 for(
const auto& c: candVec ) {
1539 LOG_INFO <<
"track id: " << c.trackId <<
" and matching distance " << c.deltaX <<
" " << c.deltaY << endm;
1545 mHistograms.at(
"trackMatchMultPerDetectorHit" )->Fill( nTracks );
1552 mHistograms.at(
"singleTrackMatchMult" )->Fill( singleTrackMatchVec.size() );
1554 if( singleTrackMatchVec.size() > 0 ) {
1555 mHistograms.at(
"eventCounter" )->Fill( 6 );
1567 StETofMatchMaker::finalizeMatching( eTofHitVec& singleTrackMatchVec, eTofHitVec& finalMatchVec )
1570 eTofHitVec tempVec = singleTrackMatchVec;
1571 eTofHitVec erasedVec = tempVec;
1573 while( tempVec.size() != 0 ) {
1579 eTofHitVecIter tempIter = tempVec.begin();
1580 eTofHitVecIter erasedIter = erasedVec.begin();
1582 while( erasedIter != erasedVec.end() ) {
1584 if( tempIter->trackId == erasedIter->trackId ) {
1586 candVec.push_back( *erasedIter );
1588 erasedVec.erase( erasedIter );
1594 tempVec = erasedVec;
1598 candVec.front().matchFlag = 1;
1599 finalMatchVec.push_back( candVec.front() );
1602 LOG_INFO <<
"one-to-one match (track id: " << candVec.front().trackId <<
") -> pushed into final match vector" << endm;
1606 else if ( nHits > 1 ) {
1608 LOG_INFO <<
"one-to-many match -> needs further treatment" << endm;
1612 double bestMatchDist = pow( candVec.front().deltaX, 2 ) + pow( candVec.front().deltaY, 2 );
1613 StructETofHit bestCand = candVec.front();
1615 bool isOverlapHit =
false;
1617 for(
const auto& c: candVec ) {
1618 double candMatchDist = pow( c.deltaX, 2 ) + pow( c.deltaY, 2 );
1621 LOG_INFO <<
"candidate match distance: " << sqrt( candMatchDist ) << endm;
1624 if( candMatchDist < bestMatchDist ) {
1625 bestMatchDist = candMatchDist;
1629 LOG_INFO <<
" --> new best match candidate" << endm;
1633 if( ( bestCand.sector * 100 + bestCand.plane * 10 + bestCand.counter ) != ( c.sector * 100 + c.plane * 10 + c.counter ) ) {
1634 isOverlapHit =
true;
1638 if( isOverlapHit ) {
1639 bestCand.matchFlag = 3;
1642 mHistograms.at(
"overlapHit_globalXY" )->Fill( bestCand.globalPos.x(), bestCand.globalPos.y() );
1646 bestCand.matchFlag = 2;
1649 finalMatchVec.push_back( bestCand );
1652 LOG_INFO <<
"one-to-many match resolved (track id: " << bestCand.trackId <<
", cand deltaX: " << bestCand.deltaX <<
") -> pushed into final match vector" << endm;
1657 mHistograms.at(
"hitMultPerTrack" )->Fill( nHits );
1662 if( mIsStEventIn ) {
1663 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
1664 for(
const auto& v: finalMatchVec ) {
1667 mHistograms.at(
"finalMatch_pt" )->Fill( track->geometry()->momentum().perp() );
1671 for(
const auto& v: finalMatchVec ) {
1674 mHistograms.at(
"finalMatch_pt" )->Fill( track->
momentum().perp() );
1678 mHistograms.at(
"finalMatchMult" )->Fill( finalMatchVec.size() );
1680 if( finalMatchVec.size() > 0 ) {
1681 mHistograms.at(
"eventCounter" )->Fill( 7 );
1692 StETofMatchMaker::fillPidTraits( eTofHitVec& finalMatchVec )
1694 size_t nFinalMatchesGlobal = 0;
1695 size_t nFinalMatchesPrimary = 0;
1697 if( mIsStEventIn ) {
1699 StSPtrVecETofHit& etofHits = mEvent->etofCollection()->etofHits();
1700 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
1702 for(
const auto& match : finalMatchVec ) {
1705 if( !globalTrack ) {
1706 LOG_WARN <<
"fillPidTraits() - global track does not exist" << endm;
1713 LOG_WARN <<
"fillPidTraits() - eTof hit does not exist" << endm;
1716 hit->setAssociatedTrack( globalTrack );
1718 nFinalMatchesGlobal++;
1724 pidTraits->setMatchFlag( match.matchFlag );
1725 pidTraits->setLocalX( match.localX );
1726 pidTraits->setLocalY( match.localY );
1727 pidTraits->setThetaLocal( match.theta );
1728 pidTraits->setDeltaX( match.deltaX );
1729 pidTraits->setDeltaY( match.deltaY );
1730 pidTraits->setPosition( match.globalPos );
1732 pidTraits->setPathLength( match.pathLength );
1734 pidTraits->setTimeOfFlight( -999. );
1735 pidTraits->setBeta( -999. );
1737 globalTrack->addPidTraits( pidTraits );
1742 nFinalMatchesPrimary++;
1745 mHistograms.at(
"finalMatchPrimary_globalXY" )->Fill( match.globalPos.x(), match.globalPos.y() );
1747 float mom = pTrack->geometry()->momentum().mag();
1749 mHistograms.at(
"finalMatchPrimaryMom0_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1751 else if( mom > 0.5 ) {
1752 mHistograms.at(
"finalMatchPrimaryMom1_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1755 mHistograms.at(
"finalMatchPrimaryMom2_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1762 ppidTraits->setMatchFlag( match.matchFlag );
1763 ppidTraits->setLocalX( match.localX );
1764 ppidTraits->setLocalY( match.localY );
1765 ppidTraits->setThetaLocal( match.theta );
1766 ppidTraits->setDeltaX( match.deltaX );
1767 ppidTraits->setDeltaY( match.deltaY );
1768 ppidTraits->setPosition( match.globalPos );
1770 ppidTraits->setPathLength( match.pathLength );
1772 ppidTraits->setTimeOfFlight( -999. );
1773 ppidTraits->setBeta( -999. );
1775 pTrack->addPidTraits( ppidTraits );
1780 for(
const auto& match : finalMatchVec ) {
1784 LOG_WARN <<
"fillPidTraits() - global track does not exist" << endm;
1791 LOG_WARN <<
"fillPidTraits() - eTof hit does not exist" << endm;
1794 hit->setAssociatedTrackId( gTrack->
id() );
1795 hit->setIndex2Global( match.trackId );
1798 nFinalMatchesGlobal++;
1802 pidTraits.setMatchFlag( match.matchFlag );
1803 pidTraits.setLocalX( match.localX );
1804 pidTraits.setLocalY( match.localY );
1805 pidTraits.setThetaLocal( match.theta );
1806 pidTraits.setDeltaX( match.deltaX );
1807 pidTraits.setDeltaY( match.deltaY );
1808 pidTraits.setPosition( match.globalPos );
1810 pidTraits.setPathLength( match.pathLength );
1812 pidTraits.setTimeOfFlight( -999. );
1813 pidTraits.setBeta( -999. );
1818 auto it = mIndex2Primary.find( match.trackId );
1819 if( it != mIndex2Primary.end() ) {
1820 pIndex = it->second;
1822 if( pIndex < 0 )
continue;
1826 nFinalMatchesPrimary++;
1829 mHistograms.at(
"finalMatchPrimary_globalXY" )->Fill( match.globalPos.x(), match.globalPos.y() );
1831 float mom = pTrack->
momentum().mag();
1833 mHistograms.at(
"finalMatchPrimaryMom0_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1835 else if( mom > 0.5 ) {
1836 mHistograms.at(
"finalMatchPrimaryMom1_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1839 mHistograms.at(
"finalMatchPrimaryMom2_globalXY" )->Fill( match.globalPos.x() , match.globalPos.y() );
1844 hit->setIndex2Primary( pIndex );
1848 ppidTraits.setMatchFlag( match.matchFlag );
1849 ppidTraits.setLocalX( match.localX );
1850 ppidTraits.setLocalY( match.localY );
1851 ppidTraits.setThetaLocal( match.theta );
1852 ppidTraits.setDeltaX( match.deltaX );
1853 ppidTraits.setDeltaY( match.deltaY );
1854 ppidTraits.setPosition( match.globalPos );
1856 ppidTraits.setPathLength( match.pathLength );
1858 ppidTraits.setTimeOfFlight( -999. );
1859 ppidTraits.setBeta( -999. );
1867 mHistograms.at(
"finalMatchMultGlobal" )->Fill( nFinalMatchesGlobal );
1868 mHistograms.at(
"finalMatchMultPrimary" )->Fill( nFinalMatchesPrimary );
1878 StETofMatchMaker::calculatePidVariables( eTofHitVec& finalMatchVec,
int& nPrimaryWithPid )
1881 double tstart = startTime( finalMatchVec );
1883 if( fabs( tstart + 9999. ) < 1.e-5 ) {
1884 LOG_WARN <<
"calculatePidVariables() -- no valid start time available ... skip filling pidTraits with more information" << endm;
1885 nPrimaryWithPid = -1;
1889 if( mIsStEventIn ) {
1891 for(
auto& matchCand : finalMatchVec ) {
1893 StETofHit* aHit =
dynamic_cast< StETofHit*
> ( mEvent->etofCollection()->etofHits().at( matchCand.index2ETofHit ) );
1895 LOG_ERROR <<
"calculatePidVariables() - no hit" << endm;
1902 LOG_ERROR <<
"calculatePidVariables() - no associated track" << endm;
1907 StSPtrVecTrackPidTraits& traits = gTrack->pidTraits();
1909 for(
size_t i=0; i<traits.size(); i++ ) {
1910 if( traits[ i ]->detector() == kETofId ) {
1915 if( !pidTraits )
continue;
1918 double tof = timeOfFlight( tstart, aHit->
time() );
1921 matchCand.tof = tof;
1923 pidTraits->setTimeOfFlight( tof );
1927 StTrack* pTrack = gTrack->node()->track( primary );
1930 StSPtrVecTrackPidTraits& ptraits = pTrack->pidTraits();
1931 for(
size_t i=0; i<ptraits.size(); i++ ) {
1932 if( ptraits[ i ]->detector() == kETofId ) {
1938 ppidTraits->setTimeOfFlight( tof );
1943 LOG_INFO <<
"calculatePidVariables() - time-of-flight assigned to pid traits: " << tof <<
" ..." << endm;
1950 double pathLength = matchCand.pathLength;
1955 LOG_INFO <<
"calculatePidVariables() - the associated track is not a primary one. Skip PID calculation! " << endm;
1959 const StVertex* pVtx = pTrack->vertex();
1962 LOG_INFO <<
"calculatePidVariables() - the associated track is not coming from any vertex. Skip PID calculation! " << endm;
1967 StPhysicalHelixD theHelix = mOuterTrackGeometry ? gTrack->outerGeometry()->helix() : gTrack->geometry()->helix();
1975 if( !doPID )
continue;
1978 matchCand.pathLength = pathLength;
1981 double beta = pathLength / ( tof * nanosecond * c_light );
1984 matchCand.beta = beta;
1987 LOG_INFO <<
"calculatePidVariables() - pathlength: " << pathLength <<
" time-of-flight: " << tof <<
" and beta: " << beta <<
" are set" << endm;
1991 mHistograms.at(
"matchCand_timeOfFlight" )->Fill( tof );
1992 mHistograms.at(
"matchCand_timeOfFlight_pathLength" )->Fill( tof, pathLength );
1994 mHistograms.at(
"matchCand_timeOfFlight_pathLength_zoom" )->Fill( tof, pathLength );
1996 pidTraits->setPathLength( pathLength );
1997 pidTraits->setBeta( beta );
2000 ppidTraits->setPathLength( pathLength );
2001 ppidTraits->setBeta( beta );
2007 LOG_INFO <<
"calculatePidVariables() - pathlength and beta assigned to pid traits ..." << endm;
2013 for(
auto& matchCand : finalMatchVec ) {
2017 LOG_ERROR <<
"calculatePidVariables() - no hit" << endm;
2022 StMuTrack* gTrack = aHit->globalTrack();
2024 LOG_ERROR <<
"calculatePidVariables() - no associated track" << endm;
2032 double tof = timeOfFlight( tstart, matchCand.hitTime );
2036 matchCand.tof = tof;
2039 pidTraits.setTimeOfFlight( tof );
2043 StMuTrack* pTrack = aHit->primaryTrack();
2048 ppidTraits.setTimeOfFlight( tof );
2053 LOG_INFO <<
"calculatePidVariables() - time-of-flight assigned to pid traits: " << tof <<
" ..." << endm;
2060 double pathLength = matchCand.pathLength;
2064 LOG_INFO <<
"calculatePidVariables() - the associated track is not a primary one. Skip PID calculation!" << endm;
2071 LOG_INFO <<
"calculatePidVariables() - the associated track is not coming from any vertex. Skip PID calculation!" << endm;
2084 if( !doPID )
continue;
2087 matchCand.pathLength = pathLength;
2090 double beta = pathLength / ( tof * nanosecond * c_light );
2093 matchCand.beta = beta;
2096 if( matchCand.clusterSize > 999 ){
2098 mHistograms.at(
"AAA_beta_mom_SD")->Fill( pTrack->
momentum().mag() , 1/beta );
2105 LOG_INFO <<
"calculatePidVariables() - pathlength: " << pathLength <<
" time-of-flight: " << tof <<
" and beta: " << beta <<
" are set" << endm;
2109 mHistograms.at(
"matchCand_timeOfFlight" )->Fill( tof );
2110 mHistograms.at(
"matchCand_timeOfFlight_pathLength" )->Fill( tof, pathLength );
2112 mHistograms.at(
"matchCand_timeOfFlight_pathLength_zoom" )->Fill( tof, pathLength );
2114 pidTraits.setPathLength( pathLength );
2115 pidTraits.setBeta( beta );
2119 ppidTraits.setPathLength( pathLength );
2120 ppidTraits.setBeta( beta );
2127 LOG_INFO <<
"calculatePidVariables() - pathlength and beta assigned to pid traits ..." << endm;
2137 StETofMatchMaker::startTimeBTof()
2140 LOG_INFO <<
"startTimeBTof(): -- loading start time from bTOF header" << endm;
2145 if( mIsStEventIn ) {
2148 if ( btofCollection ) {
2149 btofHeader = btofCollection->tofHeader();
2152 LOG_DEBUG <<
"startTimeBTof(): -- no StBTofCollection found by getTstart" << endm;
2156 else if( mIsMuDstIn ) {
2161 LOG_DEBUG <<
"startTimeBTof(): -- no bTOF header --> no start time avaiable" << endm;
2165 double tstart = btofHeader->tStart();
2167 if( !isfinite( tstart ) ) {
2168 LOG_DEBUG <<
"startTimeBTof(): -- from bTOF header is NaN" << endm;
2172 if( tstart != -9999. ) {
2173 tstart = fmod( tstart, eTofConst::bTofClockCycle );
2174 if( tstart < 0 ) tstart += eTofConst::bTofClockCycle;
2178 LOG_DEBUG <<
"startTimeBTof(): -- start time: " << tstart << endm;
2187 StETofMatchMaker::startTimeETof(
const eTofHitVec& finalMatchVec,
unsigned int& nCand_etofT0 )
2190 LOG_INFO <<
"startTimeETof(): -- calculating start time from eTOF matches" << endm;
2192 std::vector< double > t0_cand;
2197 for(
auto& match : finalMatchVec ) {
2198 if( !match.isPrimary )
continue;
2200 if( sqrt( pow( match.deltaX, 2 ) + pow( match.deltaY, 2 ) ) > etofProjection::deltaRcut )
continue;
2202 double pathLength = match.pathLength;
2207 double nsigmaPi = -999.;
2208 double nsigmaK = -999.;
2209 double nsigmaP = -999.;
2211 if( mIsStEventIn ) {
2212 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
2227 momentum = pTrack->geometry()->momentum().mag();
2228 charge = pTrack->geometry()->charge();
2231 static StPionPlus* Pion = StPionPlus::instance();
2232 static StKaonPlus* Kaon = StKaonPlus::instance();
2233 static StProton* Proton = StProton::instance();
2236 if( pd && PidAlgorithm.traits() ) {
2237 nsigmaPi = PidAlgorithm.numberOfSigma( Pion );
2238 nsigmaK = PidAlgorithm.numberOfSigma( Kaon );
2239 nsigmaP = PidAlgorithm.numberOfSigma( Proton );
2242 StPhysicalHelixD theHelix = mOuterTrackGeometry ? gTrack->outerGeometry()->helix() : gTrack->geometry()->helix();
2243 pathLength -= theHelix.
pathLength( pTrack->vertex()->position() );
2247 if( !aHit )
continue;
2250 StMuTrack* gTrack = aHit->globalTrack();
2251 if( !gTrack )
continue;
2254 StMuTrack* pTrack = aHit->primaryTrack();
2255 if( !pTrack )
continue;
2258 momentum = pTrack->
momentum().mag();
2259 charge = pTrack->
charge();
2269 if( momentum < 0.2 )
continue;
2274 if( momentum < 0.6 && fabs( nsigmaPi ) < 2. ) {
2275 tofExpect = expectedTimeOfFlight( pathLength, momentum, pion_minus_mass_c2 );
2277 LOG_INFO <<
"startTimeETof(): -- using a pion as start time candidate" << endm;
2280 else if( momentum < 0.5 && fabs( nsigmaK ) < 1. ) {
2281 tofExpect = expectedTimeOfFlight( pathLength, momentum, kaon_minus_mass_c2 );
2283 LOG_INFO <<
"startTimeETof(): -- using a kaon as start time candidate" << endm;
2286 else if( momentum < 0.9 && charge == 1 && fabs( nsigmaP ) < 2. ) {
2287 tofExpect = expectedTimeOfFlight( pathLength, momentum, proton_mass_c2 );
2289 LOG_INFO <<
"startTimeETof(): -- using a proton as start time candidate" << endm;
2296 t0_cand.push_back( match.hitTime - tofExpect );
2297 t0_sum += t0_cand.back();
2300 LOG_INFO << match.hitTime <<
" " << tofExpect <<
" " << t0_cand.back() << endm;
2304 nCand_etofT0 = t0_cand.size();
2306 if( nCand_etofT0 == 0 ) {
2309 else if( nCand_etofT0 > 1 ) {
2310 for(
unsigned int i=0; i < nCand_etofT0; i++ ) {
2312 double t0_diff = t0_cand.at( i ) - ( t0_sum - t0_cand.at( i ) ) / ( nCand_etofT0 - 1 );
2314 if( fabs( t0_diff ) > 5.0 ) {
2315 t0_sum -= t0_cand.at( i );
2321 if( nCand_etofT0 < 2 ) {
2326 double tStart = fmod( t0_sum / nCand_etofT0, eTofConst::bTofClockCycle );
2327 if( tStart < 0 ) tStart += eTofConst::bTofClockCycle;
2336 StETofMatchMaker::moduloDist(
const double& dist,
const double& mod ) {
2337 return dist - mod * round( dist / mod );
2343 StETofMatchMaker::startTime(
const eTofHitVec& finalMatchVec ) {
2349 double tstartBTof = startTimeBTof();
2351 if( mUseOnlyBTofHeaderStartTime ) {
2356 unsigned int nCand_etofT0 = 0;
2357 double tstartETof = startTimeETof( finalMatchVec, nCand_etofT0 );
2359 double t0Diff = moduloDist( tstartETof - tstartBTof, eTofConst::bTofClockCycle );
2364 if( mDoQA && tstartBTof != -9999. && tstartETof != -9999. ) {
2365 mHistograms.at(
"startTimeDiff" )->Fill( t0Diff );
2366 mHistograms.at(
"startTimeDiff_nCand" )->Fill( t0Diff, nCand_etofT0 );
2371 if( tstartBTof != -9999. && tstartETof != -9999. && nCand_etofT0 > etofHybridT0::minCand ) {
2372 if( mT0corr != 0 && fabs( moduloDist( t0Diff - mT0corr, eTofConst::bTofClockCycle ) ) > etofHybridT0::diffToClear ) {
2375 LOG_INFO <<
"mT0switch: " << mT0switch << endm;
2378 if( mT0switch > etofHybridT0::nSwitch ) {
2380 mT0corrVec.push_back( t0Diff );
2384 LOG_INFO <<
"startTime(): -- cleared T0 correction vector since the start time (eTof <-> bTOF) seems to have changed" << endm;
2389 mT0corrVec.push_back( t0Diff );
2393 if( ( mT0corr != 0. || mT0corrVec.size() >= etofHybridT0::nMin ) && mT0corrVec.size() % etofHybridT0::nUpdate == 0 ) {
2394 std::sort( mT0corrVec.begin(), mT0corrVec.end() );
2397 for(
const auto& v : mT0corrVec ) {
2398 LOG_DEBUG <<
"startTime(): -- T0corrVec: " << v << endm;
2405 if( mT0corr == 0. ) {
2406 mT0corr = mT0corrVec.at( mT0corrVec.size() / 2 );
2407 for(
auto it = mT0corrVec.begin(); it != mT0corrVec.end(); it++ ) {
2408 if( fabs( *it - mT0corr ) > 0.5 ) {
2409 mT0corrVec.erase( it-- );
2412 mT0corr = mT0corrVec.at( mT0corrVec.size() / 2 );
2415 for(
auto it = mT0corrVec.begin(); it != mT0corrVec.end(); it++ ) {
2416 if( fabs( *it - mT0corr ) > 0.2 ) {
2417 mT0corrVec.erase( it-- );
2420 mT0corr = mT0corrVec.at( mT0corrVec.size() / 2 );
2425 for(
auto it = mT0corrVec.begin(); it != mT0corrVec.end(); it++ ) {
2426 if( fabs( *it - mT0corr ) > 0.5 ) {
2427 mT0corrVec.erase( it-- );
2432 for(
const auto& v : mT0corrVec ) {
2433 LOG_DEBUG <<
"startTime(): -- cleaned T0corrVec: " << v << endm;
2439 int low = floor( mT0corrVec.size() * etofHybridT0::lowCut );
2440 int high = floor( mT0corrVec.size() * etofHybridT0::highCut );
2444 for(
int i = low; i < high; i++ ) {
2446 LOG_DEBUG <<
"startTime(): -- T0corrVec: " << mT0corrVec.at( i ) << endm;
2449 temp += mT0corrVec.at( i );
2453 if( nAccept >= 5 ) {
2454 mT0corr = ( temp / nAccept ) - etofHybridT0::biasOffset;
2458 LOG_INFO <<
"startTime(): -- hybrid T0 correction between eTOF & bTOF (update " << mNupdatesT0 <<
"): " << mT0corr <<
" (" << nAccept <<
")" << endm;
2460 mHistograms.at(
"startTime_T0corr" )->SetBinContent( mNupdatesT0 , mT0corr );
2469 if( mT0corr != 0. && tstartBTof != -9999. ) {
2470 tstart = fmod( moduloDist( tstartBTof + mT0corr, eTofConst::bTofClockCycle ), eTofConst::bTofClockCycle );
2471 if( tstart < 0. ) tstart += eTofConst::bTofClockCycle;
2474 LOG_INFO <<
"startTime(): -- returning hybrid start time (BTof/VPD T0: " << tstartBTof <<
" T0 corr: " << mT0corr <<
"): " << tstart << endm;
2477 else if( tstartETof != -9999. && nCand_etofT0 > etofHybridT0::minCand ) {
2478 tstart = tstartETof;
2480 LOG_INFO <<
"startTime(): -- returning eTOF-only start time: " << tstart << endm;
2484 tstart = tstartBTof;
2487 LOG_INFO <<
"startTime(): -- returning bTOF/VPD start time: " << tstart << endm;
2498 StETofMatchMaker::timeOfFlight(
const double& startTime,
const double& stopTime )
2500 return moduloDist( stopTime - startTime, eTofConst::bTofClockCycle );
2507 StETofMatchMaker::expectedTimeOfFlight(
const double& pathLength,
const double& momentum,
const double& mass )
2509 double inverseBeta = sqrt( 1 + mass * mass / ( momentum * momentum ) );
2511 return pathLength * centimeter * ( 1. / c_light ) * inverseBeta / nanosecond;
2520 StETofMatchMaker::fillQaHistograms( eTofHitVec& finalMatchVec )
2523 vector< int > nPidMatches( 36 );
2525 for(
auto& matchCand : finalMatchVec ) {
2535 float nSigmaPion = -999;
2537 if( mIsStEventIn ) {
2539 StSPtrVecTrackNode& nodes = mEvent->trackNodes();
2542 if( !gTrack )
continue;
2545 if( !pTrack )
continue;
2547 charge = pTrack->geometry()->charge();
2548 mom = pTrack->geometry()->momentum().mag();
2551 static StPionPlus* Pion = StPionPlus::instance();
2554 if( pd && PidAlgorithm.traits() ) {
2555 dEdx = PidAlgorithm.traits()->mean() * 1.e6;
2556 nSigmaPion = PidAlgorithm.numberOfSigma( Pion );
2562 if( !aHit )
continue;
2564 StMuTrack* pTrack = aHit->primaryTrack();
2565 if( !pTrack )
continue;
2571 charge = pTrack->
charge();
2574 dEdx = pTrack->
dEdx() * 1.e6;
2578 int sign = ( charge < 0 ) ? -1 : ( charge > 0 );
2579 float beta = matchCand.beta;
2582 if( fabs( beta + 999. ) < 0.001 ) {
2584 LOG_WARN <<
"beta not set --> no start time available???" << endm;
2590 float tofpi = expectedTimeOfFlight( matchCand.pathLength, mom, pion_plus_mass_c2 );
2592 mHistograms.at(
"matchCand_beta_signmom" )->Fill( sign * mom, 1. / beta );
2593 if( mom > 0.6 && mom < 1.5 ) {
2594 mHistograms.at(
"matchCand_t0corr_1d" )->Fill( matchCand.tof - tofpi );
2598 float tof = matchCand.tof;
2599 float pathlength = matchCand.pathLength;
2600 float m2 = mom * mom * ( -1 + 1 / ( beta * beta ) );
2605 if( fabs( tof+999. ) < 1.e-5 || fabs( pathlength+999. ) < 1.e-5 ) {
2606 LOG_INFO <<
"tof==0 or pathlength==0 ..." << endl;
2610 mHistograms.at(
"matchCand_beta_mom" )->Fill( mom, 1. / beta );
2611 mHistograms.at(
"matchCand_m2_mom" )->Fill( mom, m2 );
2612 mHistograms.at(
"matchCand_m2_signmom" )->Fill( sign * mom, m2 );
2617 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 );
2618 mHistograms.at( histName_beta_mom )->Fill( mom, 1. / beta );
2620 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 );
2621 mHistograms.at( histName_t0corr_mom )->Fill( mom, tof - tofpi );
2623 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 );
2624 mHistograms.at( histName_t0corr_mom_zoom )->Fill( mom, tof - tofpi );
2626 if( nSigmaPion < 1.5 ) {
2627 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 );
2628 mHistograms.at( histName_t0corr_strip )->Fill( matchCand.localX, tof - tofpi );
2631 if( nSigmaPion < 2. ) {
2632 if( matchCand.clusterSize >= 100 ) {
2634 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 );
2635 mHistograms.at( histName_t0corr_jump )->Fill( matchCand.localX, tof - tofpi );
2637 int get4Index = matchCand.sector * 1000 + matchCand.plane * 100 + matchCand.counter * 10 + ( matchCand.localX + 16 ) / 4 + 1;
2638 mClockJumpCand[ get4Index ]++;
2643 if( sqrt( pow( matchCand.deltaX, 2 ) + pow( matchCand.deltaY, 2 ) ) < etofProjection::deltaRcut ) {
2645 mHistograms.at(
"matchCand_beta_mom_matchDistCut" )->Fill( mom, 1. / beta );
2646 mHistograms.at(
"matchCand_m2_mom_matchDistCut" )->Fill( mom, m2 );
2648 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 );
2650 mHistograms.at( histName_t0corr_mom_zoom_cut )->Fill( mom, tof - tofpi );
2652 nPidMatches.at( ( matchCand.sector - 13 ) * 3 + matchCand.plane - 1 ) += 1;
2655 if( fabs( mom - 1 ) < 0.1 && dEdx > 0 ) mHistograms.at(
"matchCand_dEdx_beta_mom1gev" )->Fill( 1. / beta, dEdx );
2656 if( fabs( mom - 2 ) < 0.1 && dEdx > 0 ) mHistograms.at(
"matchCand_dEdx_beta_mom2gev" )->Fill( 1. / beta, dEdx );
2661 for(
size_t i=0; i<36; i++ ) {
2662 mHistograms.at(
"matchCandMultPerSector_matchDistCut" )->Fill( i, nPidMatches.at( i ) );
2668 StETofMatchMaker::fillSlewHistograms( eTofHitVec& finalMatchVec )
2670 if( !mDoQA || !mIsMuDstIn )
return;
2672 map< int, float > hitIndexToDeltaTmap;
2674 for(
auto& matchCand : finalMatchVec ) {
2676 if( !aHit )
continue;
2678 StMuTrack* pTrack = aHit->primaryTrack();
2679 if( !pTrack )
continue;
2681 float mom = pTrack->
momentum().mag();
2684 if( fabs( nSigmaPion > 1.5 ) )
continue;
2688 if( fabs( matchCand.beta + 999. ) < 0.001 ) {
2689 LOG_INFO <<
"beta not set --> no start time available???" << endm;
2693 float tof = matchCand.tof;
2694 float pathlength = matchCand.pathLength;
2696 if( fabs( tof+999. ) < 1.e-5 || fabs( pathlength+999. ) < 1.e-5 ) {
2697 LOG_INFO <<
"tof==0 or pathlength==0 ..." << endl;
2701 LOG_DEBUG <<
"for slewing: momentum: " << mom <<
" ... nsigmaPi: " << nSigmaPion <<
" tof:" << tof << endm;
2704 float tofpi = expectedTimeOfFlight( pathlength , mom, pion_plus_mass_c2 );
2705 hitIndexToDeltaTmap[ matchCand.index2ETofHit ] = tof - tofpi;
2709 size_t nDigis = mMuDst->numberOfETofDigi();
2710 for(
size_t i=0; i<nDigis; i++ ) {
2712 if( !aDigi )
continue;
2715 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() );
2716 mHistograms.at( histName_slewing )->Fill( aDigi->
calibTot(), hitIndexToDeltaTmap.at( aDigi->
associatedHitId() ) );
2725 StETofMatchMaker::trackGeometry(
StTrack* track )
const
2728 if ( !track )
return nullptr;
2732 if ( mOuterTrackGeometry ) {
2733 thisTrackGeometry = track->outerGeometry();
2736 thisTrackGeometry = track->geometry();
2739 return thisTrackGeometry;
2747 StETofMatchMaker::setHistFileName()
2749 string extension =
".etofMatch.root";
2751 if( GetChainOpt()->GetFileOut() !=
nullptr ) {
2752 TString outFile = GetChainOpt()->GetFileOut();
2754 mHistFileName = ( string ) outFile;
2757 size_t lastindex = mHistFileName.find_last_of(
"." );
2758 mHistFileName = mHistFileName.substr( 0, lastindex );
2761 lastindex = mHistFileName.find_last_of(
"." );
2762 mHistFileName = mHistFileName.substr( 0, lastindex );
2765 lastindex = mHistFileName.find_last_of(
"/" );
2766 mHistFileName = mHistFileName.substr( lastindex + 1, mHistFileName.length() );
2768 mHistFileName = mHistFileName + extension;
2770 LOG_ERROR <<
"Cannot set the output filename for histograms" << endm;
2777 StETofMatchMaker::bookHistograms()
2779 LOG_INFO <<
"bookHistograms" << endm;
2781 mHistograms[
"eTofHits_globalXY" ] =
new TH2F(
"A_eTofHits_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2782 mHistograms[
"intersectionMult_etofMult" ] =
new TH2F(
"B_intersectionMult_etofMult",
"multiplicity correlation;# eTOF hits;#track intersections;# events", 300, 0., 300., 200, 0., 200. );
2783 mHistograms[
"matchCand_globalXY" ] =
new TH2F(
"C_matchCand_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2784 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. );
2785 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. );
2786 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. );
2787 mHistograms[
"matchCand_t0corr_1d" ] =
new TH1F(
"H_matchCand_t0corr_1d",
"measured tof - tof_{#pi};#Delta time (ns);counts", 3000, -15., 15. );
2790 AddHist( mHistograms.at(
"eTofHits_globalXY" ) );
2791 AddHist( mHistograms.at(
"intersectionMult_etofMult" ) );
2792 AddHist( mHistograms.at(
"matchCand_globalXY" ) );
2793 AddHist( mHistograms.at(
"matchCand_beta_signmom" ) );
2794 AddHist( mHistograms.at(
"matchCand_timeOfFlight_pathLength_zoom" ) );
2795 AddHist( mHistograms.at(
"primaryIntersect_validMatch" ) );
2796 AddHist( mHistograms.at(
"matchCand_t0corr_1d" ) );
2800 mHistograms[
"eTofSectors" ] =
new TH2F(
"QA_eTofSectors",
"center of modules in global XY;x (cm);y (cm)", 100, -300, 300, 100, -300, 300 );
2801 mHistograms[
"eTofModules" ] =
new TH2F(
"QA_eTofModules",
"center of modules in global XY;x (cm);y (cm)", 100, -300, 300, 100, -300, 300 );
2804 mHistograms2d[
"bfield_z" ] =
new TH2F(
"QA_bField_z",
"magnetic field (z);z (cm);y (cm)", 350, -350., 0., 300, 0., 300. );
2808 mHistograms[
"eventCounter" ] =
new TH1F(
"QA_eventCounter",
"eventCounter;;# events", 10, 0.5, 10.5 );
2814 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 );
2816 mHistograms[
"eTofHits_globalYZ" ] =
new TH2F(
"A_eTofHits_globalYZ",
"global YZ for sector 18 & 24;y (cm);z (cm)", 400, -300., 300., 100, -310., -270. );
2818 for(
int sector = eTofConst::sectorStart; sector <= eTofConst::sectorStop; sector++ ) {
2819 for(
int plane = eTofConst::zPlaneStart; plane <= eTofConst::zPlaneStop; plane++ ) {
2820 for(
int counter = eTofConst::counterStart; counter <= eTofConst::counterStop; counter++ ) {
2823 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 );
2825 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. );
2828 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 );
2830 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. );
2837 std::string histName_hit_localXY =
"eTofHits_localXY_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2838 std::string histName_hit_globalXY =
"eTofHits_globalXY_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2839 std::string histName_hit_eta_phi =
"eTofHits_phi_eta_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2842 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. );
2845 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. );
2848 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 );
2851 std::string histName_t0corr_jump =
"matchCand_t0corr_jump_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2852 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. );
2860 mHistograms[
"detectorHitMult" ] =
new TH1F(
"A_detectorHitMult",
"detectorHitMult;multiplicity;# events", 200, 0., 200. );
2866 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 );
2867 mHistograms[
"track_phi_pt" ] =
new TH2F(
"QA_track_phi_pt",
"pt vs. phi; #phi; p_{T}", 400, 0., 2 * M_PI, 400, 0., 5. );
2869 mHistograms[
"nHits" ] =
new TH1F(
"QA_nHits",
"nHitsTpc;nHitsFit;# tracks", 75, 0., 75. );
2870 mHistograms[
"nHits_etofregion" ] =
new TH1F(
"QA_nHits_etofregion",
"nHitsTpc in etof region;nHitsFit;# tracks", 75, 0., 75. );
2872 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. );
2874 mHistograms[
"trackProj_globalXY" ] =
new TH2F(
"QA_trackProj_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2875 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 );
2882 mHistograms[
"intersection_globalXY" ] =
new TH2F(
"B_intersection_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2883 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 );
2885 mHistograms[
"intersectionMult" ] =
new TH1F(
"B_intersectionMult",
"intersectionMult;multiplicity;# events", 200, 0., 200. );
2886 mHistograms[
"intersectionMult_primary" ] =
new TH1F(
"B_intersectionMult_primary",
"intersectionMult for primary tracks;multiplicity;# events", 200, 0., 200. );
2888 mHistograms[
"intersection_perTrack" ] =
new TH1F(
"B_intersection_perTrack",
"intersections per track;# intersections;# tracks", 50, 0., 50. );
2892 mHistograms[
"intersection_primaryTrack_globalXY" ] =
new TH2F(
"B_intersection_primaryTrack_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2893 mHistograms[
"intersection_primaryTrackMom0_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom0_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2894 mHistograms[
"intersection_primaryTrackMom1_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom1_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2895 mHistograms[
"intersection_primaryTrackMom2_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom2_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2897 mHistograms[
"intersection_primaryTrackpos_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackpos_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2898 mHistograms[
"intersection_primaryTrackMom0pos_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom0pos_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2899 mHistograms[
"intersection_primaryTrackMom1pos_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom1pos_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2900 mHistograms[
"intersection_primaryTrackMom2pos_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom2pos_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2902 mHistograms[
"intersection_primaryTrackneg_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackneg_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2903 mHistograms[
"intersection_primaryTrackMom0neg_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom0neg_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2904 mHistograms[
"intersection_primaryTrackMom1neg_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom1neg_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2905 mHistograms[
"intersection_primaryTrackMom2neg_globalXY" ] =
new TH2F(
"B_intersection_primaryTrackMom2neg_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2909 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 );
2910 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 );
2911 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 );
2913 mHistograms[
"intersection_track_nHitsTpc" ] =
new TH1F(
"B_intersection_track_nHitsTpc",
"nHitsTpc;nHitsFit;# tracks", 75, 0., 75. );
2915 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. );
2916 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. );
2922 mHistograms[
"detHitvsInter_X" ] =
new TH2F(
"C_detHitvsInter_X" ,
"detectorHit vs. intersection X;detectorHit X (cm);intersection X (cm)", 400, -300., 300., 400, -300., 300.);
2923 mHistograms[
"detHitvsInter_Y" ] =
new TH2F(
"C_detHitvsInter_Y" ,
"detectorHit vs. intersection Y;detectorHit Y (cm);intersection Y (cm)", 400, -300., 300., 400, -300., 300.);
2925 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.);
2926 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.);
2929 for(
int sector = eTofConst::sectorStart; sector <= eTofConst::sectorStop; sector++ ) {
2930 for(
int plane = eTofConst::zPlaneStart; plane <= eTofConst::zPlaneStop; plane++ ) {
2931 std::string histName_detHitvsInter_strip =
"detHitvsInter_strip_s" + std::to_string( sector ) +
"m" + std::to_string( plane );
2933 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 );
2937 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. );
2938 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. );
2940 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 );
2942 mHistograms[
"matchCand_deltaX" ] =
new TH1F(
"C_matchCand_deltaX" ,
"match candidate delta X;match candidate #DeltaX (cm); #match cand", 400, -15., 15. );
2943 mHistograms[
"matchCand_deltaY" ] =
new TH1F(
"C_matchCand_deltaY" ,
"match candidate delta Y;match candidate #DeltaY (cm); #match cand", 400, -15., 15. );
2946 for(
int sector = eTofConst::sectorStart; sector <= eTofConst::sectorStop; sector++ ) {
2947 for(
int plane = eTofConst::zPlaneStart; plane <= eTofConst::zPlaneStop; plane++ ) {
2948 for(
int counter = eTofConst::counterStart; counter <= eTofConst::counterStop; counter++ ) {
2949 std::string histName_deltaX =
"matchCand_deltaX_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2950 std::string histName_deltaY =
"matchCand_deltaY_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
2952 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. );
2953 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. );
2958 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. );
2959 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. );
2961 mHistograms[
"matchCandMult" ] =
new TH1F(
"C_matchCandMult",
"matchCandMult;multiplicity;# events", 200, 0., 200. );
2967 mHistograms[
"trackMatchMultPerDetectorHit" ] =
new TH1F(
"D_trackMatchMultPerDetectorHit",
"multiplicity of tracks pointing to the same detector hit;#tracks;#detector hits", 15, 0., 15. );
2969 mHistograms[
"singleTrackMatchMult" ] =
new TH1F(
"D_singleTrackMatchMult",
"singleTrackMatchMult;multiplicity;# events", 200, 0., 200. );
2975 mHistograms[
"hitMultPerTrack" ] =
new TH1F(
"E_hitMultPerTrack",
"multiplicity of hit matched to the same track;#hits;#tracks", 15, 0., 15. );
2977 mHistograms[
"finalMatch_pt" ] =
new TH1F(
"E_finalMatch_pt",
"p_{T} distribution of matched tracks", 200, 0., 2. );
2979 mHistograms[
"finalMatchMult" ] =
new TH1F(
"E_finalMatchMult",
"finalMatchMult;multiplicity;# events", 200, 0., 200. );
2981 mHistograms[
"overlapHit_globalXY" ] =
new TH2F(
"E_overlapHit_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2987 mHistograms[
"finalMatchMultGlobal" ] =
new TH1F(
"F_finalMatchMultGlobal",
"finalMatchMultGlobal;multiplicity;# events", 200, 0., 200. );
2988 mHistograms[
"finalMatchMultPrimary" ] =
new TH1F(
"F_finalMatchMultPrimary",
"finalMatchMultPrimary;multiplicity;# events", 200, 0., 200. );
2990 mHistograms[
"finalMatchPrimary_globalXY" ] =
new TH2F(
"F_finalMatchPrimary_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2991 mHistograms[
"finalMatchPrimaryMom0_globalXY" ] =
new TH2F(
"F_finalMatchPrimaryMom0_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2992 mHistograms[
"finalMatchPrimaryMom1_globalXY" ] =
new TH2F(
"F_finalMatchPrimaryMom1_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2993 mHistograms[
"finalMatchPrimaryMom2_globalXY" ] =
new TH2F(
"F_finalMatchPrimaryMom2_globalXY",
"global XY;x (cm);y (cm)", 400, -300., 300., 400, -300., 300. );
2999 mHistograms[
"startTimeDiff" ] =
new TH1F(
"G_startTimeDiff",
"bTOF - eTOF start time;#DeltaT;#events", 1000, -20., 20. );
3000 mHistograms[
"startTimeDiff_nCand" ] =
new TH2F(
"G_startTimeDiff_nCand",
"bTOF - eTOF start time;#DeltaT;#nCand tracks", 1000, -20., 20., 50, 0, 50 );
3001 mHistograms[
"startTime_T0corr" ] =
new TH1F(
"G_startTime_T0corr",
"T0corr evolution;#updates;T0 corr. (ns)", 1000, 0., 1000. );
3003 mHistograms[
"matchCand_timeOfFlight" ] =
new TH1F(
"G_matchCand_timeOfFlight",
"match candidate time of flight;ToF (ns);# match candidates", 2000, -400., 600. );
3004 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. );
3010 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. );
3012 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. );
3014 mHistograms[
"matchCandMultPerSector_matchDistCut" ] =
new TH2F(
"H_matchCandMultPerSector_matchDistCut" ,
"matchCandMultPerSector_matchDistCut;module;# matches per event", 36, 0, 36, 25, 0, 25 );
3017 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 );
3018 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 );
3020 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 );
3023 for(
int sector = eTofConst::sectorStart; sector <= eTofConst::sectorStop; sector++ ) {
3024 for(
int plane = eTofConst::zPlaneStart; plane <= eTofConst::zPlaneStop; plane++ ) {
3025 for(
int counter = eTofConst::counterStart; counter <= eTofConst::counterStop; counter++ ) {
3027 std::string histName_beta_mom =
"matchCand_beta_mom_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3028 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. );
3030 std::string histName_t0corr_mom =
"matchCand_t0corr_mom_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3031 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. );
3033 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 );
3034 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 );
3036 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. );
3037 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. );
3039 std::string histName_t0corr_strip =
"matchCand_t0corr_strip_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3040 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. );
3042 std::string histName_slewing_digi =
"matchCand_slewing_digi_s" + std::to_string( sector ) +
"m" + std::to_string( plane ) +
"c" + std::to_string( counter );
3043 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. );
3048 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. );
3049 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. );
3053 for(
auto& kv : mHistograms ) {
3054 kv.second->SetDirectory( 0 );
3056 for(
auto& kv : mHistograms2d ) {
3057 kv.second->SetDirectory( 0 );
3064 StETofMatchMaker::writeHistograms()
3066 if( mHistFileName !=
"" ) {
3067 LOG_INFO <<
"writing histograms to: " << mHistFileName.c_str() << endm;
3069 TFile histFile( mHistFileName.c_str(),
"RECREATE",
"etofMatch" );
3072 for (
const auto& kv : mHistograms ) {
3073 if( kv.second->GetEntries() > 0 ) kv.second->Write();
3075 for (
const auto& kv : mHistograms2d ) {
3076 if( kv.second->GetEntries() > 0 ) kv.second->Write();
3081 LOG_INFO <<
"histogram file name is empty string --> cannot write histograms" << endm;
3088 StETofMatchMaker::setMatchDistXYT(
double x,
double y,
double t = 99999. )
3090 mMatchDistX = fabs( x );
3091 mMatchDistY = fabs( y );
3092 mMatchDistT = fabs( t );
3097 StETofMatchMaker::rotateHit(
const int& sector,
const int& rot )
3099 int sec = 13 + ( sector - 13 + rot ) % 12;
3100 LOG_DEBUG <<
"hit rotated from: " << sector <<
" to " << sec << endm;
3106 ETofTrack::ETofTrack(
const StTrack* sttrack )
3120 mom = sttrack->geometry()->momentum().mag();
3121 pt = sttrack->geometry()->momentum().perp();
3122 eta = sttrack->geometry()->momentum().pseudoRapidity();
3123 phi = sttrack->geometry()->momentum().phi();
3124 nFtPts = sttrack->fitTraits().numberOfFitPoints( kTpcId );
3127 static StPionPlus* Pion = StPionPlus::instance();
3130 nSigmaPion = PidAlgorithm.numberOfSigma( Pion );
3131 if(PidAlgorithm.traits()){
3132 dEdx = PidAlgorithm.traits()->mean() * 1.e6;
3133 nDedxPts = PidAlgorithm.traits()->numberOfPoints();
3136 flag = sttrack->flag();
3137 nHitsPoss = sttrack->numberOfPossiblePoints( kTpcId );
3139 if ( phi < 0. ) phi += 2. * M_PI;
3144 ETofTrack::ETofTrack(
const StMuTrack* mutrack )
3160 eta = mutrack->
momentum().pseudoRapidity();
3162 nFtPts = mutrack->
nHitsFit( kTpcId );
3164 flag = mutrack->
flag();
3165 nHitsPoss = mutrack->
nHitsPoss( kTpcId );
3166 dEdx = mutrack->
dEdx() * 1.e6;
3169 if ( phi < 0. ) phi += 2. * M_PI;
3174 void StETofMatchMaker::checkClockJumps()
3176 if (mClockJumpCand.size() == 0)
return;
3179 int binmax = mHistograms.at(
"matchCand_t0corr_1d")->GetMaximumBin();
3180 float mainPeakT0 = mHistograms.at(
"matchCand_t0corr_1d")->GetXaxis()->GetBinCenter(binmax);
3182 LOG_DEBUG <<
"mainPeakT0: " << mainPeakT0 << endm;
3184 bool needsUpdate =
false;
3186 for (
const auto& kv : mClockJumpCand) {
3187 LOG_DEBUG <<
"clock jump candidate: " << kv.first <<
" " << kv.second << endm;
3189 int sector = kv.first / 1000;
3190 int plane = (kv.first % 1000) / 100;
3191 int counter = (kv.first % 100) / 10;
3192 int binX = kv.first % 10;
3194 std::string histName_t0corr_jump =
"matchCand_t0corr_jump_s" + std::to_string(sector) +
"m" + std::to_string(plane) +
"c" + std::to_string(counter);
3195 TH2D* h = (TH2D*) mHistograms.at(histName_t0corr_jump);
3197 int binYmain_neg = h->GetYaxis()->FindBin(mainPeakT0 - 1.5);
3198 int binYmain_pos = h->GetYaxis()->FindBin(mainPeakT0 + 3.0);
3199 int binYearly_neg = h->GetYaxis()->FindBin(mainPeakT0 - 1.5 - eTofConst::coarseClockCycle);
3200 int binYearly_pos = h->GetYaxis()->FindBin(mainPeakT0 + 3.0 - eTofConst::coarseClockCycle);
3201 int binYlate_neg = h->GetYaxis()->FindBin(mainPeakT0 - 1.5 + eTofConst::coarseClockCycle);
3202 int binYlate_pos = h->GetYaxis()->FindBin(mainPeakT0 + 3.0 + eTofConst::coarseClockCycle);
3204 LOG_DEBUG <<
"binYmain_neg " << binYmain_neg <<
" " << binYmain_pos <<
" binYmain_pos " << binYearly_neg <<
" binYearly_neg " << binYearly_pos <<
" binYearly_pos " << endm;
3206 int nMain = h->Integral(binX, binX, binYmain_neg, binYmain_pos);
3207 int nEarly = h->Integral(binX, binX, binYearly_neg, binYearly_pos);
3208 int nLate = h->Integral(binX, binX, binYlate_neg, binYlate_pos);
3210 LOG_DEBUG <<
"nMain " << nMain <<
" " << nEarly <<
" nEarly " << endm;
3212 if (nEarly > nMain && nEarly >= 2) {
3213 LOG_DEBUG <<
"clock jump detected --> give it to hit maker" << endm;
3215 mClockJumpDirection[ kv.first ] = -1.;
3219 if (nLate > nMain && nLate >= 2) {
3220 LOG_DEBUG <<
"clock jump detected --> give it to hit maker" << endm;
3222 mClockJumpDirection[ kv.first ] = 1.;
3227 mClockJumpCand.clear();
3230 if( needsUpdate && mETofHitMaker ) {
3231 mETofHitMaker->updateClockJumpMap( mClockJumpDirection );
3237 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;
3253 eTofHitVecIter tempIter = tempVec.begin();
3255 if(tempVec.size() < 1 )
return;
3257 eTofHitVec storeVecTmp;
3259 while(tempVec.size() > 0){
3261 std::vector< int > trackIdVec;
3262 std::vector< int > hitIdVec;
3265 tempIter = tempVec.begin();
3266 storeVecTmp.push_back(tempVec.at(0));
3267 trackIdVec.push_back(tempVec.at(0).trackId);
3268 hitIdVec.push_back(tempVec.at(0).index2ETofHit);
3269 tempVec.erase(tempVec.begin());
3274 unsigned int sizeOld = storeVecTmp.size();
3275 unsigned int size = tempVec.size();
3276 tempIter= tempVec.begin();
3278 for(
unsigned int i=0; i < size; i++){
3280 if( (std::find(trackIdVec.begin(), trackIdVec.end(), tempVec.at(i).trackId) != trackIdVec.end()) || (std::find(hitIdVec.begin(), hitIdVec.end(), tempVec.at(i).index2ETofHit) != hitIdVec.end()) ){
3282 storeVecTmp.push_back(tempVec.at(i));
3283 trackIdVec.push_back(tempVec.at(i).trackId);
3284 hitIdVec.push_back(tempVec.at(i).index2ETofHit);
3285 tempVec.erase(tempIter);
3288 size = tempVec.size();
3289 tempIter = tempVec.begin();
3294 done = ( sizeOld == storeVecTmp.size() );
3298 MMMap[storeVecTmp.begin()->trackId] = storeVecTmp;
3299 storeVecTmp.clear();
3307 StETofMatchMaker::sortandcluster(eTofHitVec& matchCandVec , eTofHitVec& detectorHitVec , eTofHitVec& intersectionVec , eTofHitVec& finalMatchVec){
3312 std::map< Int_t, eTofHitVec > overlapHitMap;
3313 eTofHitVec overlapHitVec;
3314 eTofHitVec tempVecOL = matchCandVec;
3315 eTofHitVecIter detHitIter;
3316 eTofHitVecIter detHitIter2;
3318 std::map< int, bool > jumpHitMap;
3320 for(
unsigned int i=0; i<matchCandVec.size();i++){
3321 if(matchCandVec.at(i).clusterSize > 100){
3322 jumpHitMap[matchCandVec.at(i).index2ETofHit] =
true;
3324 jumpHitMap[matchCandVec.at(i).index2ETofHit] =
false;
3328 for(
auto detHitIter = tempVecOL.begin(); detHitIter != tempVecOL.end(); ) {
3330 detHitIter = tempVecOL.begin();
3331 detHitIter2 = tempVecOL.begin();
3333 bool isOverlap =
false;
3334 int counterId1 = (detHitIter->sector*100) + (detHitIter->plane*10) + (detHitIter->counter);
3336 for(
auto detHitIter2 = tempVecOL.begin(); detHitIter2 != tempVecOL.end(); ) {
3338 int counterId2 = (detHitIter2->sector*100) + (detHitIter2->plane*10) + (detHitIter2->counter);
3340 if(counterId1 != counterId2 && detHitIter->trackId == detHitIter2->trackId){
3342 int mf2 = counterId2 ;
3344 detHitIter2->matchFlag = mf2;
3346 matchCandVec.at(detHitIter2 - tempVecOL.begin()).matchFlag = 1;
3348 overlapHitVec.push_back(*detHitIter2);
3349 tempVecOL.erase(detHitIter2);
3354 if( tempVecOL.size() <= 0 )
break;
3355 if( detHitIter2 == tempVecOL.end())
break;
3362 detHitIter->matchFlag = counterId1;
3364 matchCandVec.at(detHitIter - tempVecOL.begin()).matchFlag = 1;
3366 overlapHitVec.push_back(*detHitIter);
3369 overlapHitMap[overlapHitVec.begin()->trackId] = overlapHitVec;
3371 overlapHitVec.clear();
3374 tempVecOL.erase(detHitIter);
3376 if( tempVecOL.size() <= 0 )
break;
3377 if( detHitIter == tempVecOL.end())
break;
3383 std::vector< eTofHitVec > matchCandVecCounter(108);
3385 for(
int i =0; i < 108; i++){
3387 for(
unsigned int n = 0; n < matchCandVec.size(); n++){
3389 int sector = matchCandVec.at(n).sector;
3390 int plane = matchCandVec.at(n).plane;
3391 int counter = matchCandVec.at(n).counter;
3393 int counterId = 9*(sector - 13) + 3*(plane - 1) + (counter -1);
3395 if(counterId == i ) {
3396 matchCandVecCounter.at(i).push_back(matchCandVec.at(n));
3403 for(
int counterNr = 0; counterNr < 108; counterNr++){
3406 eTofHitVec tempVec = matchCandVecCounter.at(counterNr);
3407 eTofHitVec tempVec2 = matchCandVecCounter.at(counterNr);
3408 std::map< Int_t, eTofHitVec > MMMap;
3410 sortMatchCases(tempVec, MMMap);
3413 std::map< Int_t, eTofHitVec > MultMultMap;
3414 std::map< Int_t, eTofHitVec > SingleHitMap;
3415 std::map< Int_t, eTofHitVec > SingleTrackMap;
3418 map<Int_t, eTofHitVec >::iterator it;
3420 for (it = MMMap.begin(); it != MMMap.end(); it++)
3425 for(
unsigned int l =0; l< it->second.size(); l++){
3426 for(
unsigned int j = l; j< it->second.size(); j++){
3428 if( it->second.at(l).trackId != it->second.at(j).trackId) nTracks++;
3429 if( it->second.at(l).index2ETofHit != it->second.at(j).index2ETofHit ) nHits++;
3437 if(nTracks == 1 && nHits == 1) {
3439 ssVec.push_back(it->second.front() );
3442 int isOl = it->second.front().matchFlag;
3444 if( it->second.front().clusterSize > 999 ) {
3447 it->second.front().clusterSize = 1;
3450 it->second.front().matchFlag = 100 + isMerged + isOl;
3451 finalMatchVec.push_back(it->second.front());
3456 if( nTracks > 1 && nHits == 1) {
3459 double dr_best = 99999.0;
3460 unsigned int ind = 0;
3461 unsigned int ind_best = 0;
3463 for(
unsigned int l =0; l < it->second.size(); l++){
3465 dr = (it->second.at(l).deltaX * it->second.at(l).deltaX) + (it->second.at(l).deltaY * it->second.at(l).deltaY);
3474 SingleHitMap[it->first] = it->second;
3478 int isOl = it->second.at(ind_best).matchFlag;
3480 if( it->second.at(ind_best).clusterSize > 999 ){
3483 it->second.at(ind_best).clusterSize = 1;
3486 it->second.at(ind_best).matchFlag = 300 + isMerged + isOl;
3487 finalMatchVec.push_back(it->second.at(ind_best));
3492 if( nTracks ==1 && nHits > 1) {
3497 for(
unsigned int l =0; l < it->second.size(); l++){
3499 if(it->second.at(l).clusterSize < 999){
3506 SingleTrackMap[it->first] = it->second;
3512 std::vector< std::vector<int> > mergeIndVec(it->second.size());
3519 double dr_best = 99999.0;
3520 unsigned int ind = 0;
3521 unsigned int ind_best = 0;
3523 for(
unsigned int l =0; l < it->second.size(); l++){
3525 dr = sqrt((it->second.at(l).deltaX * it->second.at(l).deltaX) + (it->second.at(l).deltaY * it->second.at(l).deltaY));
3536 dr_mean = dr_sum / it->second.size();
3538 for(
unsigned int c =0; c < it->second.size(); c++){
3540 dr = sqrt((it->second.at(c).deltaX * it->second.at(c).deltaX) + (it->second.at(c).deltaY * it->second.at(c).deltaY));
3541 dr_diff += abs(dr - dr_mean);
3546 int mergedCluSz = 0;
3547 int mergedMatchFlag = 0;
3549 int isOl = it->second.at(ind_best).matchFlag;
3551 if(it->second.at(ind_best).clusterSize > 100 && it->second.at(ind_best).clusterSize < 200){
3553 mergedCluSz = it->second.at(ind_best).clusterSize % 100;
3557 mergedCluSz = it->second.at(ind_best).clusterSize;
3560 if(mergedCluSz > 1){ isMerged = 30;
3565 mergedMatchFlag = 200 + isMerged + isOl;
3566 it->second.at(ind_best).matchFlag = mergedMatchFlag;
3568 finalMatchVec.push_back(it->second.at(ind_best));
3574 std::vector< std::vector<int> > mergeIndVec(it->second.size());
3576 for(
unsigned int l =0; l < it->second.size(); l++){
3577 mergeIndVec.at(l).push_back(0);
3581 double dr_best = 99999.0;
3582 unsigned int ind = 0;
3583 unsigned int ind_best = 0;
3585 for(
unsigned int l =0; l < it->second.size(); l++){
3588 dr = it->second.at(l).deltaX;
3599 eTofHitVec hitVec = it->second ;
3601 double mergedTime = it->second.at(ind_best).hitTime;
3602 double mergedToT = it->second.at(ind_best).tot;
3603 double mergedPosY = it->second.at(ind_best).localY;
3604 double mergedPosX = it->second.at(ind_best).localX;
3605 int mergedCluSz = 1;
3606 int mergedMatchFlag = 0;
3607 int mergedIdTruth = it->second.at(ind_best).IdTruth;
3609 for(
unsigned int j=0; j < hitVec.size(); j++) {
3611 if( j == ind_best)
continue;
3613 double dx = it->second.at(ind_best).localX - hitVec.at(j).localX;
3614 double dy = it->second.at(ind_best).localY - hitVec.at(j).localY;
3615 double dt = abs( it->second.at(ind_best).hitTime - hitVec.at(j).hitTime);
3618 if( abs(dx) < dx_3sig && abs(dy) < dy_3sig && abs(dt) < dt_3sig ){
3620 mergedTime += hitVec.at(j).hitTime;
3621 mergedToT += hitVec.at(j).tot;
3622 mergedPosY += hitVec.at(j).localY;
3623 mergedPosX += hitVec.at(j).localX;
3626 if(mergedIdTruth != hitVec.at(j).IdTruth) mergedIdTruth =0;
3632 mergedTime /= mergedCluSz;
3633 mergedToT /= mergedCluSz;
3634 mergedPosY /= mergedCluSz;
3635 mergedPosX /= mergedCluSz;
3637 int isOl = it->second.at(ind_best).matchFlag;
3639 if(mergedCluSz > 1){ isMerged = 40;
3644 mergedMatchFlag = 200 + isMerged + isOl;
3647 mergedTime = fmod( mergedTime, eTofConst::bTofClockCycle );
3648 if( mergedTime < 0 ) mergedTime += eTofConst::bTofClockCycle;
3650 it->second.at(ind_best).hitTime = mergedTime;
3651 it->second.at(ind_best).tot = mergedToT;
3652 it->second.at(ind_best).localX = mergedPosX;
3653 it->second.at(ind_best).localY = mergedPosY;
3654 it->second.at(ind_best).IdTruth = mergedIdTruth;
3655 it->second.at(ind_best).matchFlag = mergedMatchFlag;
3656 it->second.at(ind_best).clusterSize = mergedCluSz;
3659 finalMatchVec.push_back(it->second.at(ind_best));
3665 std::vector< std::vector<int> > mergeIndVec(it->second.size());
3667 for(
unsigned int l =0; l < it->second.size(); l++){
3668 mergeIndVec.at(l).push_back(0);
3672 double dr_best = 99999.0;
3673 unsigned int ind = 0;
3674 unsigned int ind_best = 0;
3676 for(
unsigned int l =0; l < it->second.size(); l++){
3678 if(it->second.at(l).clusterSize > 999)
continue;
3681 dr = it->second.at(l).deltaX*it->second.at(l).deltaX + it->second.at(l).deltaY*it->second.at(l).deltaY;
3692 eTofHitVec hitVec = it->second ;
3694 double mergedTime = it->second.at(ind_best).hitTime;
3695 double mergedToT = it->second.at(ind_best).tot;
3696 double mergedPosY = it->second.at(ind_best).localY;
3697 double mergedPosX = it->second.at(ind_best).localX;
3698 int mergedCluSz = 1;
3699 int mergedMatchFlag = 0;
3700 int mergedIdTruth = it->second.at(ind_best).IdTruth;
3702 for(
unsigned int j=0; j < hitVec.size(); j++) {
3704 if( j == ind_best)
continue;
3706 double dx = it->second.at(ind_best).localX - hitVec.at(j).localX;
3707 double dy = it->second.at(ind_best).localY - hitVec.at(j).localY;
3708 double dt = abs( it->second.at(ind_best).hitTime - hitVec.at(j).hitTime);
3711 if( abs(dx) < dx_3sig && abs(dy) < dy_3sig && abs(dt) < dt_3sig ){
3713 mergedTime += hitVec.at(j).hitTime;
3714 mergedToT += hitVec.at(j).tot;
3715 mergedPosY += hitVec.at(j).localY;
3716 mergedPosX += hitVec.at(j).localX;
3719 if(mergedIdTruth != hitVec.at(j).IdTruth) mergedIdTruth =0;
3724 mergedTime /= mergedCluSz;
3725 mergedToT /= mergedCluSz;
3726 mergedPosY /= mergedCluSz;
3727 mergedPosX /= mergedCluSz;
3729 int isOl = it->second.at(ind_best).matchFlag;
3731 if(mergedCluSz > 1){ isMerged = 50;
3736 mergedMatchFlag = 200 + isMerged + isOl;
3739 mergedTime = fmod( mergedTime, eTofConst::bTofClockCycle );
3740 if( mergedTime < 0 ) mergedTime += eTofConst::bTofClockCycle;
3742 it->second.at(ind_best).hitTime = mergedTime;
3743 it->second.at(ind_best).tot = mergedToT;
3744 it->second.at(ind_best).localX = mergedPosX;
3745 it->second.at(ind_best).localY = mergedPosY;
3746 it->second.at(ind_best).IdTruth = mergedIdTruth;
3747 it->second.at(ind_best).matchFlag = mergedMatchFlag;
3748 it->second.at(ind_best).clusterSize = mergedCluSz ;
3750 finalMatchVec.push_back(it->second.at(ind_best));
3756 if(nTracks > 1 && nHits > 1) {
3759 eTofHitVec hitVec = it->second ;
3760 eTofHitVec bestMatchVec;
3761 eTofHitVec mergeCandVec;
3762 eTofHitVec ambigVec;
3763 std::map< Int_t, StructETofHit > bestMatchMap;
3764 std::map< Int_t, eTofHitVec > mergeCandMap;
3765 std::map< Int_t, eTofHitVec > mergeCandMap2;
3766 std::map< Int_t, eTofHitVec > ambigMap;
3767 std::vector<int> indVec;
3769 for(
unsigned int l =0; l < it->second.size(); l++){
3771 double dr = it->second.at(l).deltaX*it->second.at(l).deltaX + it->second.at(l).deltaY*it->second.at(l).deltaY;
3772 double dr_best = 99999.0;
3773 unsigned int ind = 0;
3774 unsigned int ind_best = l;
3775 int trackId = it->second.at(l).trackId;
3778 if(std::find(indVec.begin(), indVec.end(), trackId) != indVec.end())
continue;
3780 for(
unsigned int n = 0; n < it->second.size(); n++){
3782 if(it->second.at(n).trackId != trackId)
continue;
3785 dr = it->second.at(n).deltaX*it->second.at(n).deltaX + it->second.at(n).deltaY*it->second.at(n).deltaY;
3791 mergeCandVec.push_back(it->second.at(ind_best));
3800 mergeCandVec.push_back(it->second.at(n));
3804 indVec.push_back(trackId);
3805 bestMatchMap[trackId] = it->second.at(ind_best);
3806 bestMatchVec.push_back(it->second.at(ind_best));
3810 std::vector<int> indVecBMtrack;
3811 std::vector<int> indVecBMhit;
3813 for(
unsigned int b =0; b < bestMatchVec.size() ; b++){
3814 indVecBMtrack.push_back(bestMatchVec.at(b).trackId);
3815 indVecBMhit.push_back(bestMatchVec.at(b).index2ETofHit);
3818 std::vector<int> indVecUsedTrack;
3819 std::vector<int> indVecReplaceTrack;
3820 std::vector<int> indVecUsedHit;
3821 eTofHitVec MatchVecTemp = bestMatchVec;
3822 eTofHitVec finalbestMatchVec;
3824 while(MatchVecTemp.size() > 0){
3827 double dr_best = 99999.0;
3828 unsigned int ind = 0;
3829 unsigned int ind_best = 0;
3830 for(
unsigned int b =0; b < MatchVecTemp.size() ; b++){
3834 dr = MatchVecTemp.at(b).deltaX * MatchVecTemp.at(b).deltaX + MatchVecTemp.at(b).deltaY * MatchVecTemp.at(b).deltaY;
3841 finalbestMatchVec.push_back(MatchVecTemp.at(ind_best));
3842 indVecUsedTrack.push_back(MatchVecTemp.at(ind_best).trackId);
3843 indVecUsedHit.push_back(MatchVecTemp.at(ind_best).index2ETofHit);
3844 MatchVecTemp.erase(MatchVecTemp.begin() + ind_best);
3847 for(
unsigned int b =0; b < MatchVecTemp.size() ; b++){
3849 if(std::find(indVecUsedHit.begin(), indVecUsedHit.end(), MatchVecTemp.at(b).index2ETofHit) != indVecUsedHit.end()) {
3851 indVecReplaceTrack.push_back(MatchVecTemp.at(b).trackId);
3852 MatchVecTemp.erase(MatchVecTemp.begin() + b);
3858 std::sort( indVecReplaceTrack.begin(), indVecReplaceTrack.end() );
3859 indVecReplaceTrack.erase( unique( indVecReplaceTrack.begin(), indVecReplaceTrack.end() ), indVecReplaceTrack.end() );
3861 bool found1 =
false;
3864 double dx_best1 = 99999.0;
3865 double dy_best1 = 99999.0;
3866 unsigned int ind1 = 0;
3867 unsigned int ind_best1 = 0;
3868 for(
unsigned int i = 0; i < mergeCandVec.size();i++){
3872 if(!(std::find(indVecReplaceTrack.begin(), indVecReplaceTrack.end(), mergeCandVec.at(i).trackId) != indVecReplaceTrack.end()))
continue;
3873 if(std::find(indVecUsedTrack.begin(), indVecUsedTrack.end(), mergeCandVec.at(i).index2ETofHit) != indVecUsedTrack.end())
continue;
3874 if(std::find(indVecUsedHit.begin(), indVecUsedHit.end(), mergeCandVec.at(i).index2ETofHit) != indVecUsedHit.end())
continue;
3875 if(std::find(indVecBMhit.begin(), indVecBMhit.end(), mergeCandVec.at(i).index2ETofHit) != indVecBMhit.end())
continue;
3877 dx1 = mergeCandVec.at(i).deltaX;
3878 dy1 = mergeCandVec.at(i).deltaY;
3880 if(dy1 < dy_best1){ dy_best1 = dy1;}
3886 }
else if(dx1 == dx_best1){
3888 if(dy1 < dy_best1 && dy1 < dy_max && dy1 != 27.0){
3891 }
else if( dy1 == 27.0){
3900 finalbestMatchVec.push_back(mergeCandVec.at(ind_best1));
3901 indVecUsedTrack.push_back(mergeCandVec.at(ind_best1).trackId);
3902 indVecUsedHit.push_back(mergeCandVec.at(ind_best1).index2ETofHit);
3903 mergeCandVec.erase(mergeCandVec.begin() + ind_best1);
3906 bestMatchVec = finalbestMatchVec;
3908 for(
unsigned int i=0;i< bestMatchVec.size();i++){
3910 if(bestMatchVec.at(i).clusterSize < 999 ){
3911 bestMatchVec.at(i).matchFlag = 410;
3913 bestMatchVec.at(i).matchFlag = 420;
3914 bestMatchVec.at(i).clusterSize -= 1000;
3916 finalMatchVec.push_back(bestMatchVec.at(i));
3924 for(
unsigned int i=0;i<finalMatchVec.size();i++){
3930 int keyGet4up = 144 * ( finalMatchVec.at(i).sector - 13 ) + 48 * ( finalMatchVec.at(i).plane -1 ) + 16 * ( finalMatchVec.at(i).counter - 1 ) + 8 * ( 1 - 1 ) + ( ( finalMatchVec.at(i).strip - 1 ) / 4 );
3931 int keyGet4down = 144 * ( finalMatchVec.at(i).sector - 13 ) + 48 * ( finalMatchVec.at(i).plane -1 ) + 16 * ( finalMatchVec.at(i).counter - 1 ) + 8 * ( 2 - 1 ) + ( ( finalMatchVec.at(i).strip - 1 ) / 4 );
3933 if(!mETofCalibMaker){
3934 if(jumpHitMap.at(finalMatchVec.at(i).index2ETofHit)){
3935 finalMatchVec.at(i).clusterSize += 100;
3938 if(!mETofCalibMaker->calState()){
3939 if(jumpHitMap.at(finalMatchVec.at(i).index2ETofHit)){
3940 if(mETofCalibMaker->GetState(keyGet4up) != 0 || mETofCalibMaker->GetState(keyGet4down) != 0){
3941 finalMatchVec.at(i).clusterSize += 200;
3943 finalMatchVec.at(i).clusterSize += 100;
3947 if(jumpHitMap.at(finalMatchVec.at(i).index2ETofHit)){
3948 finalMatchVec.at(i).clusterSize += 100;
3950 if(mETofCalibMaker->GetState(keyGet4up) != 0 || mETofCalibMaker->GetState(keyGet4down) != 0){
3951 finalMatchVec.at(i).clusterSize += 200;
3957 sortOutOlDoubles(finalMatchVec);
3961 StETofMatchMaker::sortOutOlDoubles(eTofHitVec& finalMatchVec){
3963 eTofHitVec overlapHitVec;
3965 eTofHitVec tempVecOL = finalMatchVec;
3967 std::vector<int> trackIdVec;
3969 for(
unsigned int i =0; i< finalMatchVec.size(); i++){
3971 if( !(std::find(trackIdVec.begin(), trackIdVec.end(), finalMatchVec.at(i).trackId) != trackIdVec.end())){
3973 trackIdVec.push_back(finalMatchVec.at(i).trackId);
3975 int counterId1 = (finalMatchVec.at(i).sector*100) + (finalMatchVec.at(i).plane*10) + (finalMatchVec.at(i).counter);
3977 for(
unsigned int j =0; j< finalMatchVec.size(); j++){
3979 int counterId2 = (finalMatchVec.at(j).sector*100) + (finalMatchVec.at(j).plane*10) + (finalMatchVec.at(j).counter);
3981 if(counterId1 != counterId2 && finalMatchVec.at(i).trackId == finalMatchVec.at(j).trackId){
3983 if(!(finalMatchVec.at(j).matchFlag % 2)) finalMatchVec.at(j).matchFlag++;
3984 if(!(finalMatchVec.at(i).matchFlag % 2)) finalMatchVec.at(i).matchFlag++;
3993 std::map< int , eTofHitVec > overlapHitMap;
3995 tmpVec = finalMatchVec;
3996 finalMatchVec.clear();
3997 finalMatchVec.resize(0);
3999 for(
unsigned int i=0; i< tmpVec.size(); i++){
4001 if(tmpVec.at(i).matchFlag%2 == 0){
4002 finalMatchVec.push_back(tmpVec.at(i));
4004 OlVec.push_back(tmpVec.at(i));
4009 for(
unsigned int i =0; i < OlVec.size(); i++){
4010 overlapHitMap[OlVec.at(i).trackId].push_back(OlVec.at(i));
4013 map<Int_t, eTofHitVec >::iterator it;
4015 for (it = overlapHitMap.begin(); it != overlapHitMap.end(); it++){
4017 eTofHitVec trackVec = it->second;
4021 for(
unsigned int n=0; n< trackVec.size();n++){
4023 float dr = sqrt((trackVec.at(n).deltaX * trackVec.at(n).deltaX ) + (trackVec.at(n).deltaY * trackVec.at(n).deltaY ));
4030 finalMatchVec.push_back(trackVec.at(ind_best));
4049 for(
unsigned int i =0; i< finalMatchVec.size(); i++){
4051 unsigned char singlemixdouble = 9;
4052 unsigned char matchcase = 9;
4053 unsigned char isOl = 9;
4055 switch (finalMatchVec.at(i).matchFlag / 100) {
4056 case 1 : matchcase = 4;
break;
4057 case 2 : matchcase = 3;
break;
4058 case 3 : matchcase = 2;
break;
4059 case 4 : matchcase = 1;
break;
4060 default : { LOG_WARN <<
"Errant ETOF match flag for matchcase!" << endm; }
4063 isOl = 1 - ( finalMatchVec.at(i).matchFlag % 2 );
4065 switch (finalMatchVec.at(i).matchFlag % 100) {
4069 case 31 : singlemixdouble = 2;
break;
4073 case 41 : singlemixdouble = 0;
break;
4075 case 51 : singlemixdouble = 1;
break;
4076 default : { LOG_WARN <<
"Errant ETOF match flag for singlemixdouble!" << endm; }
4079 unsigned char newFlag = (singlemixdouble*100) + (isOl*10) + (matchcase);
4081 if(singlemixdouble == 9 || isOl == 9 || matchcase == 9) newFlag = 0;
4083 finalMatchVec.at(i).matchFlag = newFlag;
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