diff --git a/src/THcScalerEvtHandler.cxx b/src/THcScalerEvtHandler.cxx index 208b4747d6a9d4290f138d13c927d2384f1ad175..12094698a9ef6444a1862ac8049b71a4d63cfaa3 100644 --- a/src/THcScalerEvtHandler.cxx +++ b/src/THcScalerEvtHandler.cxx @@ -63,7 +63,7 @@ static const UInt_t defaultDT = 4; THcScalerEvtHandler::THcScalerEvtHandler(const char *name, const char* description) : THaEvtTypeHandler(name,description), evcount(0), ifound(0), fNormIdx(-1), - dvars(0), fScalerTree(0) + dvars(0), dvarsFirst(0), fScalerTree(0) { rdata = new UInt_t[MAXTEVT]; } @@ -147,8 +147,8 @@ Int_t THcScalerEvtHandler::Analyze(THaEvData *evdata) ifound = 0; while (p < pstop && j < ndata) { - if (fDebugFile) { - *fDebugFile << "p and pstop "<<j++<<" "<<p<<" "<<pstop<<" "<<hex<<*p<<" "<<dec<<endl; + if (fDebugFile) { + *fDebugFile << "p and pstop "<<j++<<" "<<p<<" "<<pstop<<" "<<hex<<*p<<" "<<dec<<endl; } nskip = 1; for (UInt_t j=0; j<scalers.size(); j++) { @@ -170,11 +170,8 @@ Int_t THcScalerEvtHandler::Analyze(THaEvData *evdata) *fDebugFile << " Found flag = "<<ifound<<endl; } - // FIXME: What are the HMS and SOS headers? Are there header words? - // - // L-HRS has headers which are different from R-HRS, but both are - // event type 140 and come here. If you found no headers, it was - // the other arms event type. (The arm is fName). + // HMS has headers which are different from SOS, but both are + // event type 0 and come here. If you found no headers, return. if (!ifound) return 0; @@ -185,15 +182,28 @@ Int_t THcScalerEvtHandler::Analyze(THaEvData *evdata) UInt_t ivar = scalerloc[i]->ivar; UInt_t isca = scalerloc[i]->iscaler; UInt_t ichan = scalerloc[i]->ichan; - if (fDebugFile) *fDebugFile << "Debug dvars "<<i<<" "<<ivar<<" "<<isca<<" "<<ichan<<endl; - if ((ivar >= 0 && ivar < scalerloc.size()) && - (isca >= 0 && isca < scalers.size()) && - (ichan >= 0 && ichan < MAXCHAN)) { - if (scalerloc[ivar]->ikind == ICOUNT) dvars[ivar] = scalers[isca]->GetData(ichan); - if (scalerloc[ivar]->ikind == IRATE) dvars[ivar] = scalers[isca]->GetRate(ichan); - if (fDebugFile) *fDebugFile << " dvars "<<scalerloc[ivar]->ikind<<" "<<dvars[ivar]<<endl; - } else { - cout << "THcScalerEvtHandler:: ERROR:: incorrect index "<<ivar<<" "<<isca<<" "<<ichan<<endl; + if (evcount==0) { + if (fDebugFile) *fDebugFile << "Debug dvarsFirst "<<i<<" "<<ivar<<" "<<isca<<" "<<ichan<<endl; + if ((ivar >= 0 && ivar < scalerloc.size()) && + (isca >= 0 && isca < scalers.size()) && + (ichan >= 0 && ichan < MAXCHAN)) { + if (scalerloc[ivar]->ikind == ICOUNT) dvarsFirst[ivar] = scalers[isca]->GetData(ichan); + if (scalerloc[ivar]->ikind == IRATE) dvarsFirst[ivar] = scalers[isca]->GetRate(ichan); + if (fDebugFile) *fDebugFile << " dvarsFirst "<<scalerloc[ivar]->ikind<<" "<<dvarsFirst[ivar]<<endl; + } else { + cout << "THcScalerEvtHandler:: ERROR:: incorrect index "<<ivar<<" "<<isca<<" "<<ichan<<endl; + } + }else{ + if (fDebugFile) *fDebugFile << "Debug dvars "<<i<<" "<<ivar<<" "<<isca<<" "<<ichan<<endl; + if ((ivar >= 0 && ivar < scalerloc.size()) && + (isca >= 0 && isca < scalers.size()) && + (ichan >= 0 && ichan < MAXCHAN)) { + if (scalerloc[ivar]->ikind == ICOUNT) dvars[ivar] = scalers[isca]->GetData(ichan)-dvarsFirst[ivar]; + if (scalerloc[ivar]->ikind == IRATE) dvars[ivar] = scalers[isca]->GetRate(ichan); + if (fDebugFile) *fDebugFile << " dvars "<<scalerloc[ivar]->ikind<<" "<<dvars[ivar]<<endl; + } else { + cout << "THcScalerEvtHandler:: ERROR:: incorrect index "<<ivar<<" "<<isca<<" "<<ichan<<endl; + } } } @@ -298,7 +308,12 @@ THaAnalysisObject::EStatus THcScalerEvtHandler::Init(const TDatime& date) if (scalers.size() > 0) { UInt_t idx = scalers.size()-1; scalers[idx]->SetHeader(header, mask); - if (clkchan >= 0) scalers[idx]->SetClock(defaultDT, clkchan, clkfreq); + if (clkchan >= 0) { + scalers[idx]->SetClock(defaultDT, clkchan, clkfreq); + cout << "Setting scaler clock ... channel = "<<clkchan<<" ... freq = "<<clkfreq<<endl; + if (fDebugFile) *fDebugFile <<"Setting scaler clock ... channel = "<<clkchan<<" ... freq = "<<clkfreq<<endl; + fNormIdx = idx; + } } } } @@ -306,7 +321,8 @@ THaAnalysisObject::EStatus THcScalerEvtHandler::Init(const TDatime& date) // can't compare UInt_t to Int_t (compiler warning), so do this nscalers=0; for (UInt_t i=0; i<scalers.size(); i++) nscalers++; - // need to do LoadNormScaler after scalers created and if fNormIdx found. + // need to do LoadNormScaler after scalers created and if fNormIdx found + if (fDebugFile) *fDebugFile <<"fNormIdx = "<<fNormIdx<<endl; if ((fNormIdx >= 0) && fNormIdx < nscalers) { for (Int_t i = 0; i < nscalers; i++) { if (i==fNormIdx) continue; @@ -391,7 +407,9 @@ void THcScalerEvtHandler::DefVars() Nvars = scalerloc.size(); if (Nvars == 0) return; dvars = new Double_t[Nvars]; // dvars is a member of this class + dvarsFirst = new Double_t[Nvars]; // dvarsFirst is a member of this class memset(dvars, 0, Nvars*sizeof(Double_t)); + memset(dvarsFirst, 0, Nvars*sizeof(Double_t)); if (gHaVars) { if(fDebugFile) *fDebugFile << "THcScalerEVtHandler:: Have gHaVars "<<gHaVars<<endl; } else { @@ -403,6 +421,8 @@ void THcScalerEvtHandler::DefVars() for (UInt_t i = 0; i < scalerloc.size(); i++) { gHaVars->DefineByType(scalerloc[i]->name.Data(), scalerloc[i]->description.Data(), &dvars[i], kDouble, count); + //gHaVars->DefineByType(scalerloc[i]->name.Data(), scalerloc[i]->description.Data(), + // &dvarsFirst[i], kDouble, count); } } diff --git a/src/THcScalerEvtHandler.h b/src/THcScalerEvtHandler.h index edc680787501e7c6f090d64c55e9b40cd2a44af1..7e596ecd179a946c756b0ae9126caa780d372465 100644 --- a/src/THcScalerEvtHandler.h +++ b/src/THcScalerEvtHandler.h @@ -51,6 +51,7 @@ private: std::vector<Int_t> index; Int_t Nvars, ifound, fNormIdx, nscalers; Double_t *dvars; + Double_t *dvarsFirst; TTree *fScalerTree; THcScalerEvtHandler(const THcScalerEvtHandler& fh);