// Book some histograms void RICHDB::bookhist(){ #ifdef __AMSDEBUG__ dump(); cout <<"RICH BOOKING"<<endl; HBOOK1(123456,"Error de los directos",50,-1.,1.,0.); HBOOK1(123457,"Error de los reflejados",50,-1.,1.,0.); HBOOK1(123000,"Generados",300,0.,100.,0.); HBOOK1(123001,"Radiador",300,0.,100.,0.); HBOOK1(123002,"Base",300,0.,100.,0.); HBOOK1(123003,"Detectados",300,0.,100.,0.); HBOOK1(123100,"LG TRAN",100,0.,1.,0.); HBOOK1(1231001,"f",100,0.,1.,0.); HBOOK1(1231002,"lglength",100,0.,6.,0.); HBOOK1(123100,"Numero de hits ",300,0.,50.,0.); HBOOK1(123100,"Numero de hits reflejados",300,0.,50.,0.); HBOOK1(123100,"Numero de hits sin reflejar",300,0.,50.,0.); HBOOK2(124000,"Posicion de los PMT",300,-70.,70.,300,-70.,70.,0.); HBOOK2(124010,"Posicion de los PMT",300,-60.,60.,300,-60.,60.,0.); HBOOK1(12345,"Probabilidad de scattering",2,0.,2.,0.); HBOOK1(12346,"Angulo ph",50,0.,3.141592,0.); HBOOK1(12347,"Angulo th",100,0.,2e-1,0.); #endif }
thStatus thBookaHist(char *line, thHistSpecList **thHistNext) { int nargs, nd, n, id; char *long_title; daVarStruct *(varp[2]),*testp,*weightp; int vind[2],tind,wind; thHistOpaque *histpars; char *args[20]; /* int type; thTokenType toktyp; int nd,n; */ int userflag; /* 0 for normal hist, 1 for user hist */ { char *s; s = line; long_title = 0; while(*s != 0) { if(*s == HTITLECHAR){ *s++ = 0; long_title = (char *) malloc(strlen(s)+1); strcpy(long_title,s); /* Make sure to free this */ break; } else s++; } } if(!long_title) { long_title = (char *) malloc(strlen(line)+1); strcpy(long_title,line); } /* All between # and title char, comment char, or EOL is the weight */ { char *s; if((s=strchr(line,WEIGHTCHAR))) { *s++=0; s = thSpaceStrip(s); if(thVarResolve(s,&weightp,&wind,0,0) != S_SUCCESS) { free(long_title); return(S_FAILURE); } } else { weightp = 0; wind = 0; } } nargs = thCommas(line,args); args[0] = thSpaceStrip(args[0]); userflag = 0; if(nargs >= 4 && nargs <=6) { nd = 1; if(nargs == 4) userflag = 1; } else if(nargs == 7) { nd = 2; userflag = 1; } else if(nargs >= 9 && nargs <= 10){ nd = 2; } else { fprintf(stderr,"Incorrect number of arguments\n"); free(long_title); return(S_FAILURE); } varp[1] = 0; vind[1] = 0; testp = 0; tind = 0; if(userflag) { varp[0] = 0; vind[0] = 0; } else { for(n=0;n<nd;n++){ /* Interpret the data sources */ args[n+1] = thSpaceStrip(args[n+1]); if(thVarResolve(args[n+1],&varp[n],&vind[n],0,0) != S_SUCCESS) { free(long_title); return(S_FAILURE); } } /* Data sources now defined */ if((nd==1&&nargs==6)||(nd==2&&nargs==10)){ args[nargs-1] = thSpaceStrip(args[nargs-1]); if(thVarResolve(args[nargs-1],&testp,&tind,1,0) != S_SUCCESS) { free(long_title); return(S_FAILURE); } if(testp->type != DAVARINT){ fprintf(stderr,"Test flag %s must be an integer\n",args[nargs-1]); free(long_title); return(S_FAILURE); } } else { /* printf("Test is NULL\n");*/ testp = NULL; } } /* Find/Create the variable to hold hist def stuff */ { char *name; daVarStruct var; thHistSpecList *Hist; name = (char *) malloc(strlen(HISTSTR)+strlen(args[0])+2); strcpy(name,HISTSTR); strcat(name,"."); strcat(name,args[0]); if(daVarLookup(name,&var)!=S_SUCCESS){ var.name = name; var.size = 1; var.varptr = (void *) malloc(sizeof(DAINT)); *((DAINT *) var.varptr) = ++thMaxID; var.type = DAVARINT; var.flag = DAVAR_READONLY | DAVAR_REPOINTOK; if(userflag) var.opaque = 0; else var.opaque = (void *) malloc(sizeof(thHistOpaque)); var.whook = 0; #ifndef NOHBOOK var.rhook = thHistRHandler; #endif var.title = long_title; /* printf("Registering %s\n",var.name);*/ daVarRegister((int) 0,&var); /* Create variable for histogram */ } /* Make sure that we don't use an existing histogram id */ while(HEXIST((id= *((DAINT *) var.varptr))) != 0) { *((DAINT *) var.varptr) = ++thMaxID; } id = *((DAINT *) var.varptr); if(!userflag) { histpars = var.opaque; } /* Perhaps we don't want to put the user hists in this list?? */ Hist = *thHistNext = (thHistSpecList *) malloc(sizeof(thHistSpecList)); Hist->next = (thHistSpecList *) NULL; if(daVarLookupP(name,&Hist->varname)!=S_SUCCESS){ fprintf(stderr,"This can't happen\n"); free(long_title); return(S_FAILURE); } free(name); } if(!userflag) { histpars->nd = nd; histpars->x = varp[0]; histpars->xindex = vind[0]; histpars->y = varp[1]; histpars->yindex = vind[1]; histpars->test = testp; histpars->testindex = tind; histpars->weight = weightp; histpars->weightindex = wind; } /* Data sources and test result now interpreted */ { int nbinx,nbiny; double xlow,xhigh,ylow,yhigh; int ixargoffset, iyargoffset; if(userflag) { ixargoffset = 1; } else { ixargoffset = 1 + nd; } iyargoffset = ixargoffset + 3; if((thEvalImed(args[ixargoffset],0,&nbinx) != S_SUCCESS) || (thEvalImed(args[ixargoffset+1],&xlow,0) != S_SUCCESS) || (thEvalImed(args[ixargoffset+2],&xhigh,0) != S_SUCCESS)) fprintf(stderr,"Error intrepreting histogram arguments\n"); if(nd == 2){ thEvalImed(args[iyargoffset],0,&nbiny); thEvalImed(args[iyargoffset+1],&ylow,0); thEvalImed(args[iyargoffset+2],&yhigh,0); } if(nd==1){ HBOOK1(id,long_title,nbinx,(float) xlow,(float) xhigh,0.0);; } else { HBOOK2(id,long_title,nbinx,(float) xlow,(float) xhigh,nbiny, (float) ylow,(float) yhigh,0.0);; } } /* Need to add to alias file */ free(long_title); return(S_SUCCESS); }