47static const UInt_t ICOUNT = 1;
48static const UInt_t IRATE = 2;
53static const UInt_t MAXCHAN = 32;
54static const UInt_t defaultDT = 4;
60 fUseFirstEvent(
kTRUE), fDelayedType(-1),fHelicityCycleOffset(-3),
61 fBCM_Gain(0), fBCM_Offset(0), fBCM_SatOffset(0), fBCM_SatQuadratic(0), fBCM_delta_charge(0),
62 evcount(0), evcountR(0.0), ifound(0),
63 fNormIdx(-1), fNormSlot(-1),
64 dvars(0), dvarsFirst(0),
65 fScalerTree(0), fOnlyBanks(
kFALSE),
66 fClockChan(-1), fLastClock(0)
75 fNScalerChannels = 32;
105 delete [] fDelayedEvent;
120 delete [] fDelayedEvent;
191 std::map<std::string, Int_t> bcmindex;
192 bcmindex[
"BCM1_Hel.scal"] = 0;
193 bcmindex[
"BCM2_Hel.scal"] = 2;
194 bcmindex[
"Unser_Hel.scal"] = 6;
195 bcmindex[
"BCM4A_Hel.scal"] = 10;
196 bcmindex[
"BCM4B_Hel.scal"] = 4;
197 bcmindex[
"BCM4C_Hel.scal"] = 12;
280 {
"BCM_Names", &bcm_namelist, kString},
294 vector<string> bcm_names = Podd::vsplit(bcm_namelist);
296 fBCM_Name.push_back(bcm_names[i]+
"_Hel.scal");
350 *
fDebugFile << endl <<
"---------------------------------- "<<endl<<endl;
385 name =
"actualHelicity";
390 name =
"quartetPhase";
394 for (
size_t i = 0; i <
scalerloc.size(); i++) {
407 auto *datacopy =
new UInt_t[evlen];
409 memcpy(datacopy,rdata,evlen*
sizeof(
UInt_t));
445 *
fDebugFile <<
"Bank: " << hex << *
p << dec <<
" len: " << *(
p-1) << endl;
447 if((*p & 0xff00) == 0x1000) {
448 if(evlen-*(p-1) > 1) {
449 roc = (*
p>>16) & 0xf;
450 if(
fDebugFile) *
fDebugFile <<
"ROC: " << roc <<
" " << evlen <<
" " << *(
p-1) << hex <<
" " << *p << dec << endl;
457 }
else if (((*p & 0xff00) == 0x100) && (*p != 0xC0000100)) {
465 UInt_t tag = (*
p>>16) & 0xffff;
484 cout <<
"Error! Beam off for too long" << endl;
490 for (
UInt_t iev = 0; iev < nevents; iev++) {
502 *
fDebugFile <<
"Scaler Header: " << hex << *
p << dec;
521 *
fDebugFile <<
"Finished with decoding. "<<endl;
534 Int_t hbits = (
p[0]>>30) & 0x3;
535 Bool_t isquartet = (hbits&2) != 0;
537 Int_t actualhelicity = 0;
546 if(quartetphase == 0) {
551 cout <<
"THcHelicityScaler: Helicity Prediction Failed" << endl;
553 cout <<
"Predicted " << bitset<32>(predicted) << endl;
562 cout <<
"THcHelicityScaler: Quartet bit expected but not set (" <<
572 cout <<
"THcHelicityScaler: Quartet bit expected but not set (" <<
600 if(quartetphase == 3) {
605 if(quartetphase == 0 || quartetphase == 1) {
606 actualhelicity = -actualhelicity;
609 quartetphase = (quartetphase+1)%4;
612 if(quartetphase == 1 || quartetphase == 2) {
613 actualhelicity = -actualhelicity;
636 Int_t count =
p[i]&0xFFFFFF;
644 if(actualhelicity!=0) {
647 Int_t hindex = (actualhelicity>0)?0:1;
655 Int_t count =
p[i]&0xFFFFFF;
669 cout <<
" ******************* Severe Warning ****************************" << endl;
670 cout <<
" In THcHelicityScaler have found fDeltaTime is zero !! " << endl;
671 cout <<
" ******************* Alert DAQ experts ***************************" << endl;
672 if (
fDebugFile) *
fDebugFile <<
" In THcHelicityScaler have found fDeltaTime is zero !! " << endl;
682 for (
size_t i = 0; i <
scalerloc.size(); i++) {
724 if (match!=string::npos)
740 dvars[ivar]=cur_temp;
786 if (match!=string::npos)
819 cout <<
"THcHelicityScaler:: ERROR:: incorrect index "<<ivar<<
" "<<idx<<
" "<<ichan<<endl;
848 if (match!=string::npos)
861 dvars[ivar]=cur_temp;
883 cout <<
"THcHelicityScaler:: ERROR:: incorrect index "<<ivar<<
" "<<idx<<
" "<<ichan<<endl;
892 size_t ivar = i->ivar;
893 size_t ichan = i->ichan;
906 if (match!=string::npos)
928 if(actualhelicity!=0) {
931 if(quartetphase==0) {
1039 UInt_t bit7 = (ranseed & 0x00000040) != 0;
1040 UInt_t bit28 = (ranseed & 0x08000000) != 0;
1041 UInt_t bit29 = (ranseed & 0x10000000) != 0;
1042 UInt_t bit30 = (ranseed & 0x20000000) != 0;
1044 UInt_t newbit = (bit30 ^ bit29 ^ bit28 ^ bit7) & 0x1;
1046 ranseed = ( (ranseed<<1) | newbit ) & 0x3FFFFFFF;
1056 const int LEN = 200;
1063 delete [] fDelayedEvent;
1066 cout <<
"Howdy ! We are initializing THcHelicityScaler !! name = "
1080 dfile =
fName +
"scaler.txt";
1084 sname =
"hel"+
fName+sname0;
1087 FILE *fi = Podd::OpenDBFile(sname.
Data(), date);
1089 cout <<
"Cannot find db file for "<<
fName<<
" scaler event handler"<<endl;
1095 string scomment =
"#";
1096 string svariable =
"variable";
1097 string smap =
"map";
1098 vector<string> dbline;
1100 while( fgets(cbuf, LEN, fi) ) {
1101 std::string
sin(cbuf);
1102 std::string sinput(
sin.substr(0,
sin.find_first_of(
'#')));
1104 dbline = Podd::vsplit(sinput);
1105 if (!dbline.empty()) {
1107 if (pos1 != minus1)
continue;
1110 if (pos1 != minus1 && dbline.size()>4) {
1112 for (
size_t j=5; j<dbline.size(); j++) sdesc = sdesc+
" "+dbline[j];
1113 UInt_t islot = atoi(dbline[1].c_str());
1114 UInt_t ichan = atoi(dbline[2].c_str());
1115 UInt_t ikind = atoi(dbline[3].c_str());
1117 *
fDebugFile <<
"add var "<<dbline[1]<<
" desc = "<<sdesc<<
" islot= "<<islot<<
" "<<ichan<<
" "<<ikind<<endl;
1118 TString tsname(dbline[4].c_str());
1119 TString tsdesc(sdesc.c_str());
1120 AddVars(tsname,tsdesc,islot,ichan,ikind);
1122 if (ikind == ICOUNT ||ikind ==
ITIME ||ikind ==
ICHARGE ) {
1123 tsname=tsname+
"Cut";
1129 if (
fDebugFile) *
fDebugFile <<
"map ? "<<dbline[0]<<
" "<<smap<<
" "<<pos1<<
" "<<dbline.size()<<endl;
1130 if (pos1 != minus1 && dbline.size()>6) {
1131 Int_t imodel, icrate, islot, inorm;
1134 sscanf(sinput.c_str(),
"%s %d %d %d %x %x %d \n",cdum,&imodel,&icrate,&islot, &header, &mask, &inorm);
1135 if ((
fNormSlot >= 0) && (
fNormSlot != inorm)) cout <<
"THcHelicityScaler::WARN: contradictory norm slot "<<
fNormSlot<<
" "<<inorm<<endl;
1139 if (dbline.size()>8) {
1140 clkchan = atoi(dbline[7].c_str());
1141 clkfreq = 1.0*atoi(dbline[8].c_str());
1146 *
fDebugFile <<
"map line "<<dec<<imodel<<
" "<<icrate<<
" "<<islot<<endl;
1147 *
fDebugFile <<
" header 0x"<<hex<<header<<
" 0x"<<
mask<<dec<<
" "<<inorm<<
" "<<clkchan<<
" "<<clkfreq<<endl;
1163 scalers[idx]->SetHeader(header, mask);
1168 scalers[idx]->SetClock(defaultDT, clkchan, clkfreq);
1169 cout <<
"Setting scaler clock ... channel = "<<clkchan<<
" ... freq = "<<clkfreq<<endl;
1170 if (
fDebugFile) *
fDebugFile <<
"Setting scaler clock ... channel = "<<clkchan<<
" ... freq = "<<clkfreq<<endl;
1172 if (islot !=
fNormSlot) cout <<
"THcHelicityScaler:: WARN: contradictory norm slot ! "<<islot<<endl;
1201 cout <<
"THcHelicityScaler:: WARN: same slot defined twice"<<endl;
1207 if( j->islot ==
static_cast<UInt_t>(
scalers[i]->GetSlot()) )
1213 for (
size_t i=0; i<
scalers.size(); i++) {
1251 for(
Int_t i=0; i<4; i++) {
1326 "Plus Helcity Scalers",*(
fHScalers[0]));
1329 "Minus Helcity Scalers",*(
fHScalers[1]));
1335 "Total Helicity Scaler Triggers",
fNTriggers);
1372 "Helicity Gated Time (sec)",
fTimeSum);
1406 if (
Nvars == 0)
return;
1414 cout <<
"No gHaVars ?! Well, that's a problem !!"<<endl;
1418 const Int_t* count =
nullptr;
1419 for (
size_t i = 0; i <
scalerloc.size(); i++) {
1421 &
dvars[i], kDouble, count);
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
R__EXTERN class THaVarList * gHaVars
ClassImp(VDC::AnalyticTTDConv) using namespace std
R__EXTERN class THcParmList * gHcParms
static const UInt_t ICURRENT
static const UInt_t ITIME
static const UInt_t ICHARGE
char * Form(const char *fmt,...)
virtual void Clear(Option_t *="")
const UInt_t * GetRawDataBuffer() const
UInt_t GetEvLength() const
std::vector< UInt_t > eventtypes
virtual Bool_t IsMyEvent(UInt_t type) const
virtual void EvDump(THaEvData *evdata) const
std::ofstream * fDebugFile
THaVar * Define(const char *name, const Byte_t &var, const Int_t *count=nullptr)
virtual THaVar * DefineByType(const char *name, const char *desc, const void *loc, VarType type, const Int_t *count, const char *errloc="DefineByType")
virtual Int_t End(THaRunBase *r=0)
std::set< UInt_t > fRocSet
Double_t * fScalAsymmetry
Int_t fHelicityHistory[200]
std::vector< HCScalerLoc * > scalerloc
Int_t AnalyzeBuffer(UInt_t *rdata)
std::set< UInt_t > fModuleSet
THcHelicityScaler(const char *, const char *)
void AddVars(const TString &name, const TString &desc, UInt_t iscal, UInt_t ichan, UInt_t ikind)
Double_t * fBCM_delta_charge
Double_t * fScalAsymmetryError
virtual Int_t ReadDatabase(const TDatime &date)
Double_t fTimeAsymmetryError
Int_t fHelicityCycleOffset
virtual void SetDelayedType(int evtype)
Int_t Analyze(THaEvData *evdata)
Double_t * fChargeAsymSum2
Double_t fbcm_Current_Threshold
Double_t * fChargeAsymmetryError
Double_t * fChargeAsymSum
Double_t * fChargeAsymmetry
Int_t AnalyzeHelicityScaler(const UInt_t *p)
Double_t * fBCM_SatOffset
std::vector< Decoder::GenScaler * > scalers
Double_t fTriggerAsymmetry
std::vector< std::string > fBCM_Name
Double_t * fChargeCycle[4]
Int_t fbcm_Current_Threshold_Index
std::vector< UInt_t * > fDelayedEvents
Double_t * fBCM_SatQuadratic
static Int_t RanBit30(Int_t ranseed)
virtual ~THcHelicityScaler()
Int_t LoadParmValues(const DBRequest *list, const char *prefix="")
Retrieve parameter values from the parameter cache.
static Bool_t Initialized()
const char * Data() const
virtual void SetAutoSave(Long64_t autos=-300000000)
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const override
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
RVec< PromoteType< T > > sin(const RVec< T > &v)
double max(double x, double y)
string::size_type FindNoCase(string data, string chunk)
Double_t Power(Double_t x, Double_t y)
Double_t Sqrt(Double_t x)
Double_t Max(Double_t a, Double_t b)