diff --git a/StRoot/StETofCalibMaker/StETofCalibMaker.cxx b/StRoot/StETofCalibMaker/StETofCalibMaker.cxx index 528d9a47d3e..5cb3fb32dae 100644 --- a/StRoot/StETofCalibMaker/StETofCalibMaker.cxx +++ b/StRoot/StETofCalibMaker/StETofCalibMaker.cxx @@ -127,7 +127,9 @@ StETofCalibMaker::StETofCalibMaker( const char* name ) mStateMapStop(0), mDbEntryStart(0), mDbEntryStop(0), - mGlobalCounter(1) + mGlobalCounter(1), + mCalState(true) + { /// default constructor @@ -201,7 +203,12 @@ StETofCalibMaker::InitRun( Int_t runnumber ) // -------------------------------------------------------------------------------------------- //Get4 status map - + for(int i=0; i < eTofConst::nGet4sInSystem; i++){ + mGet4StateMap[i] = 0; + if(i < (eTofConst::nGet4sInSystem/2)){ + mGet4DefaultStateMap[i] = 0; + } + } readGet4State(mGlobalCounter , 0); // electronics-to-hardware map @@ -1459,7 +1466,7 @@ StETofCalibMaker::processMuDst() if (hasPulsersVec.size() == 108){ etofHeader->setHasPulsersVec(hasPulsersVec); } - + //fill good event flag into header for( unsigned int iGet4 = 0; iGet4 < 1728; iGet4++){ goodEventFlagVec.push_back(!etofHeader->missMatchFlagVec().at(iGet4)); @@ -2166,9 +2173,18 @@ StETofCalibMaker::applyCalibration( StETofDigi* aDigi, StETofHeader* etofHeader int get4Id = 144 * ( aDigi->sector() - 13 ) + 48 * ( aDigi->zPlane() -1 ) + 16 * ( aDigi->counter() - 1 ) + 8 * ( aDigi->side() - 1 ) + ( ( aDigi->strip() - 1 ) / 4 ); double stateCorr =0; - if(mGet4StateMap[get4Id] == 1) stateCorr = 6.25; - else if(mGet4StateMap[get4Id] == 2) stateCorr = -6.25; - // else if(mGet4StateMap[get4Id] == 3) stateCorr = 0.0; + if(mGet4StateMap[get4Id] == 1){ + stateCorr = 6.25; + }else if(mGet4StateMap[get4Id] == 2){ + stateCorr = -6.25; + }else if(mGet4StateMap[get4Id] == 3){ + stateCorr = 6.25; + }else if(mGet4StateMap[get4Id] == 4){ + stateCorr = -6.25; + } + // only calibrate here if flag is set + if(!mCalState) stateCorr = 0; + double calibTime = aDigi->rawTime() - mResetTime - resetTimeCorr() @@ -2178,7 +2194,7 @@ StETofCalibMaker::applyCalibration( StETofDigi* aDigi, StETofHeader* etofHeader + stateCorr; - if(mGet4StateMap[get4Id] == 3){ + if(mGet4StateMap[get4Id] == 5){ calibTime = 0; // mask digis with undefined state (e.g. one hit with jump and one without in same event) } @@ -2689,12 +2705,12 @@ void StETofCalibMaker::readGet4State(int fileNr, short forward){ std::vector< unsigned long int > intVec; //first read - if(forward == 0) mGlobalCounter = 1; + if(forward == 0) mGlobalCounter = 0; //jump forward - else if(forward > 0) mGlobalCounter++; + else if(forward > 0){ mGlobalCounter++; //jump backward - else mGlobalCounter--; // forward < 0 - + }else {mGlobalCounter--;} // forward < 0 + if(mGlobalCounter == 0){ mGlobalCounter++; fileZero = true; @@ -2743,7 +2759,7 @@ void StETofCalibMaker::readGet4State(int fileNr, short forward){ std::map> stateVec; std::map> get4IdVec; - decodeInt(intVec , mGet4StateMap , mGet4ZeroStateMap , startVec , mMasterStartVec , stateVec , get4IdVec); + decodeInt(intVec , startVec , stateVec , get4IdVec); // fill stateMap & steering vecs with EvtZero entries: read in first 1728 states & times for(int i = 0; i< eTofConst::nGet4sInSystem;i++){ @@ -2772,6 +2788,7 @@ void StETofCalibMaker::readGet4State(int fileNr, short forward){ if(fileZero){ mDbEntryStart = 0; + mDbEntryStop = 99999999; } sort( mMasterStartVec.begin(), mMasterStartVec.end() ); @@ -2858,9 +2875,11 @@ void StETofCalibMaker::checkGet4State(unsigned long int eventNr){ } //----------------------------------------------------- -void StETofCalibMaker::decodeInt( std::vector intVec ,std::map& mGet4StateMap ,std::map& mGet4ZeroStateMap ,std::vector& startVec ,std::vector& mMasterStartVec ,std::map>& stateVec ,std::map>& get4IdVec){ +void StETofCalibMaker::decodeInt( std::vector& intVec ,std::vector& startVec ,std::map>& stateVec ,std::map>& get4IdVec){ unsigned long int lastEvtId =0; + std::map > stateMap; + for(unsigned int i = 0; i < intVec.size(); i++){ @@ -2873,9 +2892,40 @@ void StETofCalibMaker::decodeInt( std::vector intVec ,std::ma int Get4Id2; int get4state2; - // decode nonZero/stateChange ints ( int = 42.xxx.xxx.xxx = 2 states only) + stateStruct struct1; + stateStruct struct2; + switch (intVec.at(i) / 100000000) { - + + //decode default jump states + case 39 : + + tmp = intVec.at(i) % 3900000000; + stateInt1 = tmp / 10000; + stateInt2 = tmp % 10000; + + Get4Id1 = -1; + get4state1 = -1; + Get4Id2 = -1; + get4state2 = -1; + + if(stateInt1 < 6912){ + Get4Id1 = stateInt1 % (eTofConst::nGet4sInSystem/2); + get4state1 = stateInt1 / (eTofConst::nGet4sInSystem/2); + } + if(stateInt2 < 6912){ + Get4Id2 = stateInt2 % (eTofConst::nGet4sInSystem/2); + get4state2 = stateInt2 / (eTofConst::nGet4sInSystem/2); + } + + if(i < (eTofConst::nGet4sInSystem/4) ){ + mGet4DefaultStateMap[Get4Id1] = get4state1 + 1; // counting from 1 here + mGet4DefaultStateMap[Get4Id2] = get4state2 + 1; // counting from 1 here + } + + break; + + // decode nonZero/stateChange ints ( int = 42.xxx.xxx.xxx = 2 states only) case 42 : tmp = intVec.at(i) % 4200000000; stateInt1 = tmp / 10000; @@ -2895,7 +2945,8 @@ void StETofCalibMaker::decodeInt( std::vector intVec ,std::ma get4state2 = stateInt2 / eTofConst::nGet4sInSystem; } - if(i < 864){ + if(i >= (eTofConst::nGet4sInSystem/4) && i < ((eTofConst::nGet4sInSystem/4) + (eTofConst::nGet4sInSystem/2))){ + mGet4StateMap[Get4Id1] = get4state1; mGet4StateMap[Get4Id2] = get4state2; mGet4ZeroStateMap[Get4Id1] = get4state1; @@ -2906,6 +2957,18 @@ void StETofCalibMaker::decodeInt( std::vector intVec ,std::ma stateVec[lastEvtId].push_back(get4state2); get4IdVec[lastEvtId].push_back(Get4Id2); + //stateStruct struct1; + struct1.get4Id = Get4Id1; + struct1.state = get4state1; + struct1.evtId = lastEvtId; + //stateStruct struct2; + struct2.get4Id = Get4Id2; + struct2.state = get4state2; + struct2.evtId = lastEvtId; + + stateMap[Get4Id1].push_back(struct1); + stateMap[Get4Id2].push_back(struct2); + break; //decode eventnumber ( int = 40.xxx.xxx.xxx = event number ) @@ -2936,10 +2999,37 @@ void StETofCalibMaker::decodeInt( std::vector intVec ,std::ma stateVec[lastEvtId].push_back(get4state1); get4IdVec[lastEvtId].push_back(Get4Id1); + //stateStruct struct1; + struct1.get4Id = Get4Id1; + struct1.state = get4state1; + struct1.evtId = lastEvtId; + + stateMap[Get4Id1].push_back(struct1); + break; default: LOG_ERROR << "Get4 state not well defined -> Check db / state file !" << endm; } } + + //sort vecs (necessary due to get4 splitting) + std::sort(startVec.begin(), startVec.end()); + std::sort(mMasterStartVec.begin(), mMasterStartVec.end()); + + for(unsigned int i=0; i< eTofConst::nGet4sInSystem;i++){ + + std::vector tmpVec = stateMap.at(i); + + for(unsigned int j=0; j < stateMap.at(i).size();j++){ + tmpVec.push_back(stateMap.at(i).at(j)); + } + std::sort(tmpVec.begin(), tmpVec.end(), [] (stateStruct x, stateStruct y) { return x.evtId < y.evtId; } ); + + for(unsigned int j=0; j< tmpVec.size();j++){ + + stateVec[tmpVec.at(j).evtId].push_back(tmpVec.at(j).state); + get4IdVec[tmpVec.at(j).evtId].push_back(tmpVec.at(j).get4Id); + } + } } diff --git a/StRoot/StETofCalibMaker/StETofCalibMaker.h b/StRoot/StETofCalibMaker/StETofCalibMaker.h index bfab902152e..421b9892327 100644 --- a/StRoot/StETofCalibMaker/StETofCalibMaker.h +++ b/StRoot/StETofCalibMaker/StETofCalibMaker.h @@ -84,6 +84,8 @@ class StETofCalibMaker: public StMaker { void setFileNameResetTimeCorr( const char* fileName ); void setFileNamePulserTotPeak( const char* fileName ); void setFileNamePulserTimeDiffGbtx( const char* fileName ); + void setCalState( const bool calTrue ); + bool calState(); void setDoQA( const bool doQA ); void setDebug( const bool debug ); @@ -91,6 +93,8 @@ class StETofCalibMaker: public StMaker { void setReferencePulserIndex( const int index ); short GetState(int); + short GetDefaultState(int); + //moved to public to avoid problem with root6 struct StructStuckFwDigi{ @@ -103,6 +107,12 @@ class StETofCalibMaker: public StMaker { } }; + struct stateStruct{ + int get4Id; + unsigned long int evtId; + Double_t state; + }; + private: bool isFileExisting( const std::string fileName ); @@ -206,19 +216,28 @@ class StETofCalibMaker: public StMaker { std::vector mMasterStartVec; std::map mGet4StateMap; std::map mGet4ZeroStateMap; + std::map mGet4DefaultStateMap; + unsigned long int mStateMapStart; unsigned long int mStateMapStop; unsigned long int mDbEntryStart; unsigned long int mDbEntryStop; int mGlobalCounter; + bool mCalState; + + void decodeInt( std::vector& intVec ,std::vector& startVec ,std::map>& stateVec ,std::map>& get4IdVec); - void decodeInt( std::vector intVec ,std::map& mGet4StateMap ,std::map& mGet4ZeroStateMap ,std::vector& startVec ,std::vector& mMasterStartVec ,std::map>& stateVec ,std::map>& get4IdVec); virtual const Char_t *GetCVS() const { static const char cvs[]="Tag $Name: $Id: built " __DATE__ " " __TIME__ ; return cvs; } ClassDef( StETofCalibMaker, 0 ) }; -inline short StETofCalibMaker::GetState( int get4 ) { return mGet4StateMap.at(get4); } + +inline bool StETofCalibMaker::calState( ) { return mCalState; } +inline short StETofCalibMaker::GetDefaultState( int get4 ) { return mGet4DefaultStateMap.at(get4); } +inline short StETofCalibMaker::GetState( int get4 ) { return mGet4StateMap.at(get4); } +inline void StETofCalibMaker::setCalState( const bool calTrue ) { mCalState = calTrue; } + inline void StETofCalibMaker::setFileNameCalibParam( const char* fileName ) { mFileNameCalibParam = fileName; } inline void StETofCalibMaker::setFileNameElectronicsMap( const char* fileName ) { mFileNameElectronicsMap = fileName; } inline void StETofCalibMaker::setFileNameStatusMap( const char* fileName ) { mFileNameStatusMap = fileName; } diff --git a/StRoot/StETofHitMaker/StETofHitMaker.cxx b/StRoot/StETofHitMaker/StETofHitMaker.cxx index f32dabff026..eb8087cc643 100644 --- a/StRoot/StETofHitMaker/StETofHitMaker.cxx +++ b/StRoot/StETofHitMaker/StETofHitMaker.cxx @@ -74,6 +74,7 @@ #include "StChain/StChainOpt.h" // for renaming the histogram file #include "StETofHitMaker.h" +#include "StETofCalibMaker/StETofCalibMaker.h" #include "StETofUtil/StETofConstants.h" #include "StETofUtil/StETofGeometry.h" @@ -106,7 +107,7 @@ StETofHitMaker::StETofHitMaker( const char* name ) mSigVel(), mSoftwareDeadTime( 150. ), mDoClockJumpShift( true ), - mDoDoubleClockJumpShift( true ), + mDoDoubleClockJumpShift( false ), mClockJumpDirection(), mModMatrix(), mGet4doublejumpTmin(-1.0), @@ -137,7 +138,49 @@ StETofHitMaker::Init() bookHistograms(); - return kStOk; + // fill get4Id to partner to pair map + int count =0; + int pairId = 0; + int pairId2 = 0; + std::vector nll; + for(int i=0;i 8){ + } + + if(reset){ + partnerId -= 8; + + }else{ + if(count <= 8 ) { + partnerId += 8; + }else{ + partnerId -= 8; + } + } + mGet4PartnerPairMap[i].push_back(partnerId); + + if(count <= 8 && !reset){ + + // cout << "get4 " << i << " partnerId " << partnerId << " pairId " << pairId << endl; + mGet4PartnerPairMap[i].push_back(pairId); + pairId++; + + }else if(count < 16 || reset){ + + //cout << "get4 " << i << " partnerId " << partnerId << " pairId " << pairId2 << endl; + mGet4PartnerPairMap[i].push_back(pairId2); + pairId2++; + } + } + + return kStOk; } //_____________________________________________________________ @@ -146,9 +189,23 @@ StETofHitMaker::InitRun( Int_t runnumber ) { LOG_INFO << "StETofHitMaker::InitRun()" << endm; + //fill default jump map + StETofCalibMaker* mETofCalibMaker; + mETofCalibMaker = ( StETofCalibMaker* ) GetMaker( "etofCalib" ); + if(mETofCalibMaker){ + for(int i = 0; i < 864; i++){ + mGet4DefaultMap[i] = mETofCalibMaker->GetDefaultState(i); + } + }else{ + for(int i = 0; i < 864; i++){ + mGet4DefaultMap[i] = 0; + } + } + TDataSet* dbDataSet = nullptr; std::ifstream paramFile; + // -------------------------------------------------------------------------------------------- // initialize hit building parameters from parameter file (if filename is provided) or database: // -- hit param @@ -1262,10 +1319,66 @@ StETofHitMaker::matchSides() if( mDoQA ) { LOG_INFO << "shifted hit time in direction: " << mClockJumpDirection.at( detIndex * 10 + ( strip - 1 ) / 4 + 1 ) << endm; } - - time -= eTofConst::coarseClockCycle * 0.5 * mClockJumpDirection.at( detIndex * 10 + ( strip - 1 ) / 4 + 1 ); - timeDiff -= eTofConst::coarseClockCycle * ( ( timeDiff < 0 ) ? -1 : ( timeDiff > 0 ) ); - + + + int keyGet4 = -1; + int keyGet4_comp = -1; + int side = xDigiA->side(); + if(side == 1){ + keyGet4 = 144 * ( sector - 13 ) + 48 * ( plane -1 ) + 16 * ( counter - 1 ) + 8 * ( 1 - 1 ) + ( ( strip - 1 ) / 4 ); + keyGet4_comp = 144 * ( sector - 13 ) + 48 * ( plane -1 ) + 16 * ( counter - 1 ) + 8 * ( 2 - 1 ) + ( ( strip - 1 ) / 4 ); + }else{ + keyGet4 = 144 * ( sector - 13 ) + 48 * ( plane -1 ) + 16 * ( counter - 1 ) + 8 * ( 2 - 1 ) + ( ( strip - 1 ) / 4 ); + keyGet4_comp = 144 * ( sector - 13 ) + 48 * ( plane -1 ) + 16 * ( counter - 1 ) + 8 * ( 1 - 1 ) + ( ( strip - 1 ) / 4 ); + } + int def = mGet4DefaultMap.at(mGet4PartnerPairMap.at(keyGet4).at(1)); + + //old corr + if(0 == def){ + time -= eTofConst::coarseClockCycle * 0.5 * mClockJumpDirection.at( detIndex * 10 + ( strip - 1 ) / 4 + 1 ); + timeDiff -= eTofConst::coarseClockCycle * ( ( timeDiff < 0 ) ? -1 : ( timeDiff > 0 ) ); + + }else{ + //new corr + + StETofCalibMaker* mETofCalibMaker; + mETofCalibMaker = ( StETofCalibMaker* ) GetMaker( "etofCalib" ); + + if(!mETofCalibMaker->calState()){ + if(mETofCalibMaker->GetState(keyGet4) != 0 || mETofCalibMaker->GetState(keyGet4_comp) != 0){ + switch (def) { + case 1 : def = 3; break; + case 2 : def = 4; break; + case 3 : def = 1; break; + case 4 : def = 2; break; + default : LOG_ERROR << "Unknown default state" << endm; + } + } + } + + if(def == 1 ){ + time -= eTofConst::coarseClockCycle * 0.5; + } + if(def == 3){ + time += eTofConst::coarseClockCycle * 0.5; + } + if(def == 2){ + if(posY > 0){ + time -= eTofConst::coarseClockCycle * 0.5; + }else{ + time += eTofConst::coarseClockCycle * 0.5; + } + } + if(def == 4){ + if(posY > 0){ + time += eTofConst::coarseClockCycle * 0.5; + }else{ + time -= eTofConst::coarseClockCycle * 0.5; + } + } + timeDiff -= eTofConst::coarseClockCycle * ( ( timeDiff < 0 ) ? -1 : ( timeDiff > 0 ) ); + } + if(leftjump && mDoDoubleClockJumpShift){ time += 2*(eTofConst::coarseClockCycle * 0.5 * mClockJumpDirection.at( detIndex * 10 + ( strip - 1 ) / 4 + 1 )); } @@ -1307,7 +1420,7 @@ StETofHitMaker::matchSides() modifyHit(mode, posX , posY , time); } - StETofHit* constructedHit = new StETofHit( sector, plane, counter, time, totSum, clusterSize, posX, posY ); + StETofHit* constructedHit = new StETofHit( sector, plane, counter, time, totSum, clusterSize, posX, posY ); //Check for "same direction double clockjumps" and update FlagMap if(mDoDoubleClockJumpShift){ diff --git a/StRoot/StETofHitMaker/StETofHitMaker.h b/StRoot/StETofHitMaker/StETofHitMaker.h index a8e1142fc39..8c577d30439 100644 --- a/StRoot/StETofHitMaker/StETofHitMaker.h +++ b/StRoot/StETofHitMaker/StETofHitMaker.h @@ -127,6 +127,8 @@ class StETofHitMaker: public StMaker { StMuDst* mMuDst; StETofGeometry* mETofGeom; // pointer to the ETof geometry utility class + std::map< int, std::vector< int > > mGet4PartnerPairMap; + std::map< int , int > mGet4DefaultMap; std::string mFileNameHitParam; // name of parameter file for hit parameters std::string mFileNameSignalVelocity; // name of parameter file for signal velocity @@ -201,3 +203,4 @@ inline void StETofHitMaker::setDebug( const bool debug ) inline void StETofHitMaker::setDoAfterPulseCorr( const bool apcorr ) { mApCorr = apcorr; } #endif + diff --git a/StRoot/StETofMatchMaker/StETofMatchMaker.cxx b/StRoot/StETofMatchMaker/StETofMatchMaker.cxx index 70bb202e807..257b14ee257 100644 --- a/StRoot/StETofMatchMaker/StETofMatchMaker.cxx +++ b/StRoot/StETofMatchMaker/StETofMatchMaker.cxx @@ -3920,13 +3920,9 @@ StETofMatchMaker::sortandcluster(eTofHitVec& matchCandVec , eTofHitVec& detector }// loop over MMMap }//loop over counters - //set clustersize for jumped hits: +100 if early , +200 if late, + 300 if still jumped - + //set clustersize for jumped hits: +100 if default , +200 if cal/def2 for(unsigned int i=0;iGetState(keyGet4up) == 1 || mETofCalibMaker->GetState(keyGet4down) == 1){ - finalMatchVec.at(i).clusterSize += 100; - } - if(mETofCalibMaker->GetState(keyGet4up) == 2 || mETofCalibMaker->GetState(keyGet4down) == 2 ){ - finalMatchVec.at(i).clusterSize += 200; + if(!mETofCalibMaker){ + if(jumpHitMap.at(finalMatchVec.at(i).index2ETofHit)){ + finalMatchVec.at(i).clusterSize += 100; + } + }else{ + if(!mETofCalibMaker->calState()){ + if(jumpHitMap.at(finalMatchVec.at(i).index2ETofHit)){ + if(mETofCalibMaker->GetState(keyGet4up) != 0 || mETofCalibMaker->GetState(keyGet4down) != 0){ + finalMatchVec.at(i).clusterSize += 200; + }else{ + finalMatchVec.at(i).clusterSize += 100; + } + } + }else{ + if(jumpHitMap.at(finalMatchVec.at(i).index2ETofHit)){ + finalMatchVec.at(i).clusterSize += 100; + } + if(mETofCalibMaker->GetState(keyGet4up) != 0 || mETofCalibMaker->GetState(keyGet4down) != 0){ + finalMatchVec.at(i).clusterSize += 200; + } + } } } - + sortOutOlDoubles(finalMatchVec); } @@ -4036,9 +4048,9 @@ StETofMatchMaker::sortOutOlDoubles(eTofHitVec& finalMatchVec){ for(unsigned int i =0; i< finalMatchVec.size(); i++){ - char singlemixdouble = 9; - char matchcase = 9; - char isOl = 9; + unsigned char singlemixdouble = 9; + unsigned char matchcase = 9; + unsigned char isOl = 9; switch (finalMatchVec.at(i).matchFlag / 100) { case 1 : matchcase = 4; break; @@ -4064,7 +4076,7 @@ StETofMatchMaker::sortOutOlDoubles(eTofHitVec& finalMatchVec){ default : { LOG_WARN << "Errant ETOF match flag for singlemixdouble!" << endm; } } - char newFlag = (singlemixdouble*100) + (isOl*10) + (matchcase); + unsigned char newFlag = (singlemixdouble*100) + (isOl*10) + (matchcase); if(singlemixdouble == 9 || isOl == 9 || matchcase == 9) newFlag = 0;