@@ -628,6 +628,8 @@ void CTPRunScalers::printLMBRateVsT() const
628628
629629// returns the pair of global (levelled) interaction rate, as well as instantaneous interpolated
630630// rate in Hz at a certain orbit number within the run
631+ // type - 7 : inputs
632+ // type - 1..6 : lmb,lma,l0b,l0a,l1b,l1a
631633std::pair<double , double > CTPRunScalers::getRate (uint32_t orbit, int classindex, int type) const
632634{
633635 if (mScalerRecordO2 .size () <= 1 ) {
@@ -646,23 +648,49 @@ std::pair<double, double> CTPRunScalers::getRate(uint32_t orbit, int classindex,
646648 auto next = &mScalerRecordO2 [index2];
647649 auto prev = &mScalerRecordO2 [index1];
648650 auto timedelta = (next->intRecord .orbit - prev->intRecord .orbit ) * 88 .e -6 ; // converts orbits into time
649- auto s0 = &(prev->scalers [classindex]); // type CTPScalerO2*
650- auto s1 = &(next->scalers [classindex]);
651- return (s1->lmBefore - s0->lmBefore ) / timedelta; // rate --> should be made better by selecting on type
651+ if (type < 7 ) {
652+ auto s0 = &(prev->scalers [classindex]); // type CTPScalerO2*
653+ auto s1 = &(next->scalers [classindex]);
654+ switch (type) {
655+ case 1 :
656+ return (s1->lmBefore - s0->lmBefore ) / timedelta;
657+ case 2 :
658+ return (s1->lmAfter - s0->lmAfter ) / timedelta;
659+ case 3 :
660+ return (s1->l0Before - s0->l0Before ) / timedelta;
661+ case 4 :
662+ return (s1->l0After - s0->l0After ) / timedelta;
663+ case 5 :
664+ return (s1->l1Before - s0->l1Before ) / timedelta;
665+ case 6 :
666+ return (s1->l1After - s0->l1After ) / timedelta;
667+ default :
668+ LOG (error) << " Wrong type:" << type;
669+ return -1 ; // wrong type
670+ }
671+ } else if (type == 7 ) {
672+ auto s0 = &(prev->scalersInps [classindex]); // type CTPScalerO2*
673+ auto s1 = &(next->scalersInps [classindex]);
674+ return (s1 - s0) / timedelta;
675+ } else {
676+ LOG (error) << " Wrong type:" << type;
677+ return -1 ; // wrong type
678+ }
652679 };
653680
654681 if (nextindex == 0 || nextindex == mScalerRecordO2 .size ()) {
655682 // orbit is out of bounds
656683 LOG (info) << " query orbit " << orbit << " out of bounds; Just returning the global rate" ;
657684 return std::make_pair (/* global mean rate*/ calcRate (0 , mScalerRecordO2 .size () - 1 ), /* current rate */ -1 );
658685 } else {
659-
660686 return std::make_pair (/* global mean rate*/ calcRate (0 , mScalerRecordO2 .size () - 1 ), /* current rate */ calcRate (nextindex - 1 , nextindex));
661687 }
662688 return std::make_pair (-1 ., -1 .);
663689}
664690// returns the pair of global (levelled) interaction rate, as well as instantaneous interpolated
665691// rate in Hz at a certain orbit number within the run
692+ // type - 7 : inputs
693+ // type - 1..6 : lmb,lma,l0b,l0a,l1b,l1a
666694std::pair<double , double > CTPRunScalers::getRateGivenT (double timestamp, int classindex, int type) const
667695{
668696 if (mScalerRecordO2 .size () <= 1 ) {
@@ -681,11 +709,37 @@ std::pair<double, double> CTPRunScalers::getRateGivenT(double timestamp, int cla
681709 auto next = &mScalerRecordO2 [index2];
682710 auto prev = &mScalerRecordO2 [index1];
683711 auto timedelta = (next->intRecord .orbit - prev->intRecord .orbit ) * 88 .e -6 ; // converts orbits into time
684- auto s0 = &(prev->scalers [classindex]); // type CTPScalerO2*
685- auto s1 = &(next->scalers [classindex]);
686- return (s1->lmBefore - s0->lmBefore ) / timedelta; // rate --> should be made better by selecting on type
712+ // std::cout << "timedelta:" << timedelta << std::endl;
713+ if (type < 7 ) {
714+ auto s0 = &(prev->scalers [classindex]); // type CTPScalerO2*
715+ auto s1 = &(next->scalers [classindex]);
716+ switch (type) {
717+ case 1 :
718+ return (s1->lmBefore - s0->lmBefore ) / timedelta;
719+ case 2 :
720+ return (s1->lmAfter - s0->lmAfter ) / timedelta;
721+ case 3 :
722+ return (s1->l0Before - s0->l0Before ) / timedelta;
723+ case 4 :
724+ return (s1->l0After - s0->l0After ) / timedelta;
725+ case 5 :
726+ return (s1->l1Before - s0->l1Before ) / timedelta;
727+ case 6 :
728+ return (s1->l1After - s0->l1After ) / timedelta;
729+ default :
730+ LOG (error) << " Wrong type:" << type;
731+ return -1 ; // wrong type
732+ }
733+ } else if (type == 7 ) {
734+ // LOG(info) << "doing input:";
735+ auto s0 = prev->scalersInps [classindex]; // type CTPScalerO2*
736+ auto s1 = next->scalersInps [classindex];
737+ return (s1 - s0) / timedelta;
738+ } else {
739+ LOG (error) << " Wrong type:" << type;
740+ return -1 ; // wrong type
741+ }
687742 };
688-
689743 if (nextindex == 0 || nextindex == mScalerRecordO2 .size ()) {
690744 // orbit is out of bounds
691745 LOG (info) << " query timestamp " << timestamp << " out of bounds; Just returning the global rate" ;
0 commit comments