@@ -744,41 +744,39 @@ void ITSThresholdCalibrator::extractThresholdRow(const short int& chipID, const
744744
745745 } else { // threshold, vcasn, ithr
746746
747- for (int scan_i = 0 ; scan_i < ((mScanType == ' r' ) ? N_RANGE : N_RANGE2); scan_i++) {
748-
747+ short int iRU = getRUID (chipID);
749748#ifdef WITH_OPENMP
750- omp_set_num_threads (mNThreads );
749+ omp_set_num_threads (mNThreads );
751750#pragma omp parallel for schedule(dynamic)
752751#endif
753- // Loop over all columns (pixels) in the row
754- for (short int col_i = 0 ; col_i < this ->N_COL ; col_i++) {
755-
756- // Do the threshold fit
757- float thresh = 0 ., noise = 0 . ;
758- bool success = false ;
759- int spoints = 0 ;
760- if (isDumpS) { // already protected for multi-thread in the init
761- mFitHist ->SetName (Form (" scurve_chip%d_row%d_col%d_scani%d" , chipID, row, col_i, scan_i));
762- }
752+ // Loop over all columns (pixels) in the row
753+ for (short int col_i = 0 ; col_i < this ->N_COL ; col_i++) {
754+ // Do the threshold fit
755+ float thresh = 0 ., noise = 0 .;
756+ bool success = false ;
757+ int spoints = 0 ;
758+ int scan_i = mScanType == ' r ' ? ( mLoopVal [iRU][row] - mMin ) / mStep : 0 ;
759+ if (isDumpS) { // already protected for multi-thread in the init
760+ mFitHist ->SetName (Form (" scurve_chip%d_row%d_col%d_scani%d" , chipID, row, col_i, scan_i));
761+ }
763762
764- success = this ->findThreshold (chipID, mPixelHits [chipID][row][col_i],
765- this ->mX , mScanType == ' r' ? N_RANGE2 : N_RANGE, thresh, noise, spoints, scan_i);
763+ success = this ->findThreshold (chipID, mPixelHits [chipID][row][col_i],
764+ this ->mX , mScanType == ' r' ? N_RANGE2 : N_RANGE, thresh, noise, spoints, scan_i);
766765
767- vChipid[col_i] = chipID;
768- vRow[col_i] = row;
769- vThreshold[col_i] = (mScanType == ' T' || mScanType == ' r' ) ? (short int )(thresh * 10 .) : (short int )(thresh);
770- vNoise[col_i] = (float )(noise * 10 .); // always factor 10 also for ITHR/VCASN to not have all zeros
771- vSuccess[col_i] = success;
772- vPoints[col_i] = spoints > 0 ? (unsigned char )(spoints) : 0 ;
766+ vChipid[col_i] = chipID;
767+ vRow[col_i] = row;
768+ vThreshold[col_i] = (mScanType == ' T' || mScanType == ' r' ) ? (short int )(thresh * 10 .) : (short int )(thresh);
769+ vNoise[col_i] = (float )(noise * 10 .); // always factor 10 also for ITHR/VCASN to not have all zeros
770+ vSuccess[col_i] = success;
771+ vPoints[col_i] = spoints > 0 ? (unsigned char )(spoints) : 0 ;
773772
774- if (mScanType == ' r' ) {
775- vMixData[col_i] = (scan_i * this ->mStep ) + mMin ;
776- }
777- }
778773 if (mScanType == ' r' ) {
779- this -> saveThreshold (); // save before moving to the next vresetd
774+ vMixData[col_i] = mLoopVal [iRU][row];
780775 }
781776 }
777+ if (mScanType == ' r' ) {
778+ this ->saveThreshold (); // save before moving to the next vresetd
779+ }
782780
783781 // Fill the ScTree tree
784782 if (mScanType == ' T' ) { // TODO: store also for other scans?
@@ -1311,10 +1309,12 @@ void ITSThresholdCalibrator::run(ProcessingContext& pc)
13111309 short int row = -1 ;
13121310 short int cwcnt = -1 ;
13131311 bool isAllZero = true ;
1312+ short int ruIndex = -1 ;
13141313 for (short int iRU = 0 ; iRU < this ->N_RU ; iRU++) {
13151314 const auto & calib = calibs[iROF * this ->N_RU + iRU];
13161315 if (calib.calibUserField != 0 ) {
13171316 mRuSet .insert (iRU);
1317+ ruIndex = iRU;
13181318 isAllZero = false ;
13191319
13201320 if (loopval >= 0 ) {
@@ -1363,9 +1363,9 @@ void ITSThresholdCalibrator::run(ProcessingContext& pc)
13631363 cwcnt = (short int )(calib.calibCounter );
13641364 // count the last N injections
13651365 short int checkVal = (mScanType == ' I' ) ? mMin : mMax ;
1366- if (loopval == checkVal && realcharge == mMin2 ) { // the second condition is relevant only for mScanType=p
1366+ if (( mScanType != ' r ' && loopval == checkVal) || ( mScanType == ' r ' && realcharge == mMax2 )) {
13671367 mCdwCntRU [iRU][row]++;
1368- mRowRU [iRU] = row ; // keep the row
1368+ mLoopVal [iRU][row] = loopval ; // keep loop val (relevant for VRESET2D scan only)
13691369 }
13701370 if (this ->mVerboseOutput ) {
13711371 LOG (info) << " RU: " << iRU << " CDWcounter: " << cwcnt << " row: " << row << " Loopval: " << loopval << " realcharge: " << realcharge << " confDBv: " << mCdwVersion ;
@@ -1425,7 +1425,7 @@ void ITSThresholdCalibrator::run(ProcessingContext& pc)
14251425 short int ru = getRUID (chipID);
14261426 mActiveLinks [ru][getLinkID (chipID, ru)] = true ;
14271427 // check rows and allocate memory
1428- if (mForbiddenRows .count (chipID)) {
1428+ if (mScanType != ' r ' && mForbiddenRows .count (chipID)) {
14291429 for (int iforb = mForbiddenRows [chipID].size () - 1 ; iforb >= 0 ; iforb--) {
14301430 if (mForbiddenRows [chipID][iforb] == row) {
14311431 mChipsForbRows [chipID] = true ;
@@ -1467,30 +1467,32 @@ void ITSThresholdCalibrator::run(ProcessingContext& pc)
14671467 }
14681468 }
14691469 } // if (charge)
1470- } // for (ROFs)
14711470
1472- // Prepare the ChipDone object for QC + extract data if the row is completed
1473- for (auto & iRU : mRuSet ) {
1471+ // //
1472+ // Prepare the ChipDone object for QC + extract data if the row is completed
1473+ if (ruIndex < 0 ) {
1474+ continue ;
1475+ }
14741476 short int nL = 0 ;
14751477 for (int iL = 0 ; iL < 3 ; iL++) {
1476- if (mActiveLinks [iRU ][iL]) {
1478+ if (mActiveLinks [ruIndex ][iL]) {
14771479 nL++; // count active links
14781480 }
14791481 }
1480- std::vector<short int > chipEnabled = getChipListFromRu (iRU , mActiveLinks [iRU ]); // chip boundaries
1482+ std::vector<short int > chipEnabled = getChipListFromRu (ruIndex , mActiveLinks [ruIndex ]); // chip boundaries
14811483 // Fill the chipDone info string
1482- if (mRunTypeRUCopy [iRU ] == nInjScaled * nL) {
1484+ if (mRunTypeRUCopy [ruIndex ] == nInjScaled * nL) {
14831485 for (short int iChip = 0 ; iChip < chipEnabled.size (); iChip++) {
14841486 if ((chipEnabled[iChip] % mChipModBase ) != mChipModSel ) {
14851487 continue ;
14861488 }
14871489 addDatabaseEntry (chipEnabled[iChip], " " , std::vector<float >(), true );
14881490 }
1489- mRunTypeRUCopy [iRU ] = 0 ; // reset here is safer (the other counter is reset in finalize)
1491+ mRunTypeRUCopy [ruIndex ] = 0 ; // reset here is safer (the other counter is reset in finalize)
14901492 }
14911493 // Check if scan of a row is finished: only for specific scans!
1492- bool passCondition = (mCdwCntRU [iRU][ mRowRU [iRU] ] >= nInjScaled * nL);
1493- if (mScanType != ' D' && mScanType != ' A' && mScanType != ' P' && mScanType != ' p' && mScanType != ' R' && mScanType != ' r ' && passCondition) {
1494+ bool passCondition = (mCdwCntRU [ruIndex][row ] >= nInjScaled * nL);
1495+ if (mScanType != ' D' && mScanType != ' A' && mScanType != ' P' && mScanType != ' p' && mScanType != ' R' && passCondition) {
14941496 // extract data from the row
14951497 for (short int iChip = 0 ; iChip < chipEnabled.size (); iChip++) {
14961498 short int chipID = chipEnabled[iChip];
@@ -1499,17 +1501,19 @@ void ITSThresholdCalibrator::run(ProcessingContext& pc)
14991501 }
15001502 if (!isDumpS || (std::find (chipDumpList.begin (), chipDumpList.end (), chipID) != chipDumpList.end () || !chipDumpList.size ())) { // to dump s-curves as histograms
15011503 if (mPixelHits .count (chipID)) {
1502- if (mPixelHits [chipID].count (mRowRU [iRU])) { // make sure the row exists
1503- extractAndUpdate (chipID, mRowRU [iRU]);
1504- mPixelHits [chipID].erase (mRowRU [iRU]);
1505- mForbiddenRows [chipID].push_back (mRowRU [iRU]);
1504+ if (mPixelHits [chipID].count (row)) { // make sure the row exists
1505+ extractAndUpdate (chipID, row);
1506+ if (mScanType != ' r' || (mScanType == ' r' && mLoopVal [ruIndex][row] == mMax )) {
1507+ mPixelHits [chipID].erase (row);
1508+ }
1509+ mForbiddenRows [chipID].push_back (row);
15061510 }
15071511 }
15081512 }
15091513 }
1510- mCdwCntRU [iRU][ mRowRU [iRU] ] = 0 ; // reset
1514+ mCdwCntRU [ruIndex][row ] = 0 ; // reset
15111515 }
1512- } // end loop on RuSet
1516+ } // for (ROFs)
15131517
15141518 if (!(this ->mRunTypeUp )) {
15151519 finalize ();
@@ -1871,7 +1875,7 @@ void ITSThresholdCalibrator::finalize()
18711875 this ->addDatabaseEntry (it_ineff->first , name, std::vector<float >(), false );
18721876 it_ineff = this ->mIneffPixID .erase (it_ineff);
18731877 }
1874- } else if (this ->mScanType == ' P' || this ->mScanType == ' p' || this -> mScanType == ' r ' || mScanType == ' R' ) { // pulse length scan 1D and 2D, vresetd scan 1D & 2D
1878+ } else if (this ->mScanType == ' P' || this ->mScanType == ' p' || mScanType == ' R' ) { // pulse length scan 1D and 2D, vresetd scan 1D (2D already extracted in run())
18751879 name = " Pulse" ;
18761880 // extract hits for the available row(s)
18771881 auto itchip = this ->mPixelHits .cbegin ();
0 commit comments