Ejemplo n.º 1
0
void
fsm_print(void)
{	State *b; int cnt1, cnt2=0;
	extern void put_uform(void);

	if (tl_clutter) clutter();

	b = findstate("T0_init");
	if (Max_Red == 0)
		b->accepting = 1;

	mergestates(0); 
	b = findstate("T0_init");

	fprintf(tl_out, "never {    /* ");
		put_uform();
	fprintf(tl_out, " */\n");

	do {
		clr_reach();
		Dfs(b);
		cnt1 = mergetrans();
		cnt2 = mergestates(1);
		if (tl_verbose)
			printf("/* >>%d,%d<< */\n", cnt1, cnt2);
	} while (cnt2 > 0);

#ifdef BUCKY
	buckyballs();
	clr_reach();
	Dfs(b);
#endif
	if (b && b->accepting)
		fprintf(tl_out, "accept_init:\n");

	if (!b && !never)
	{	fprintf(tl_out, "	0 /* false */;\n");
	} else
	{	printstate(b);	/* init state must be first */
		for (b = never; b; b = b->nxt)
			printstate(b);
	}
	if (hitsall)
	fprintf(tl_out, "accept_all:\n	skip\n");
	fprintf(tl_out, "}\n");
}
Ejemplo n.º 2
0
static void
Dfs(State *b)
{	Transition *t;

	if (!b || b->reachable) return;
	b->reachable = 1;

	if (b->redundant)
		printf("/* redundant state %s */\n",
			b->name->name);
	for (t = b->trans; t; t = t->nxt)
	{	if (!t->redundant)
		{	Dfs(findstate(t->name->name));
			if (!hitsall
			&&  strcmp(t->name->name, "accept_all") == 0)
				hitsall = 1;
		}
	}
}
Ejemplo n.º 3
0
static State *
findstate(char *nm)
{	State *b;
	for (b = never; b; b = b->nxt)
		if (!strcmp(b->name->name, nm))
			return b;
	if (strcmp(nm, "accept_all"))
	{	if (strncmp(nm, "accept", 6))
		{	int i; char altnm[64];
			for (i = 0; i < 64; i++)
				if (nm[i] == '_')
					break;
			if (i >= 64)
				Fatal("name too long %s", nm);
			sprintf(altnm, "accept%s", &nm[i]);
			return findstate(altnm);
		}
	/*	Fatal("buchi: no state %s", nm); */
	}
	return (State *) 0;
}
Ejemplo n.º 4
0
void fit(const char *run="428211_429133_5s",
	 int key=1, int bmin=10, bool draw=true, bool pa=false) {
  int minentries=1000;
  gSystem->Exec( Form("mkdir -p %s/SEN%03d",run,key/128) );
  gSystem->Exec( Form("mkdir -p %s/SEN%03d",run,key/128) );
  int state = findstate(key);
  printf("state %d\n",state);
  // data
  TString inname = Form("%s/adc/HI_KEY%05d.root",run,key);
  TString outname = Form("HI_KEY%05d",key);
  TFile *file = new TFile( inname.Data() );
  cout << inname.Data() << endl;

  TH1D *out = (TH1D*) file->Get("out");
  double xfit_min=out->GetBinLowEdge(bmin);
  double xfit_max=122.5;
  int bmax = out->GetXaxis()->FindBin(xfit_max);
  int entries = out->Integral(bmin,bmax);
  if(entries<minentries) {
    cout << "not enough entries: ";
    cout << entries << endl;
    return;
  }

  // fit
  TCanvas *main = new TCanvas("main","main");
  int pkt=0;
  if(pa)
    pkt = (key%(8*4*12*64))/(4*12*64);
  TF1 *fitH = GetFit( Form("%s/SEN%03d/%s.dat",run,key/128,outname.Data()) ,pkt,xfit_min);
  out->Fit(fitH,"MELIR","",xfit_min,xfit_max);
  TF1 *MIPH1 = GetMIP(fitH,1,kCyan-3);
  TF1 *MIPH2 = GetMIP(fitH,2,kGreen-3);
  TF1 *MIPH3 = GetMIP(fitH,3,kOrange-3);
  TF1 *MIPH4 = GetMIP(fitH,4,kMagenta-3);
  TF1 *BGR = GetBGR(fitH,xfit_min);

  double amp = fitH->GetParameter(0);
  double eamp= fitH->GetParError(0);
  double lda = fitH->GetParameter(1);
  double elda= fitH->GetParError(1);
  double sg1 = fitH->GetParameter(2);
  double esg1= fitH->GetParError(2);
  double fr2 = fitH->GetParameter(3);
  double efr2= fitH->GetParError(3);
  double fr3 = fitH->GetParameter(4);
  double efr3= fitH->GetParError(4);
  double fr4 = fitH->GetParameter(5);
  double efr4= fitH->GetParError(5);
  double fr1 = 1 - fr2 - fr3 - fr4;
  double ncs = fitH->GetChisquare()/fitH->GetNDF();
  double ba = fitH->GetParameter(6);
  double eba= fitH->GetParError(6);
  double bsl = fitH->GetParameter(7);
  double ebsl= fitH->GetParError(7);

  // saving fit
  ofstream outfit;
  outfit.open( Form("%s/SEN%03d/%s.dat",run,key/128,outname.Data()) );
  outfit << amp << " " << eamp << endl;
  outfit << lda << " " << elda << endl;
  outfit << sg1 << " " << esg1 << endl;
  outfit << fr2 << " " << efr2 << endl;
  outfit << fr3 << " " << efr3 << endl;
  outfit << fr4 << " " << efr4 << endl;
  outfit << ba  << " " << eba  << endl;
  outfit << bsl << " " << ebsl << endl;
  outfit << ncs << endl;
  outfit.close();
  cout << "Parameters saved to ";
  cout << outname.Data() << ".dat" << endl;

  // draw
  if(!draw) return;

  gStyle->SetOptFit(0);
  gStyle->SetOptStat(0);
  out->Draw("HE");
  double ymax = out->GetBinContent( out->FindBin(xfit_min) )*1.5;
  out->GetYaxis()->SetRangeUser(0.5,ymax);
  out->GetXaxis()->SetRangeUser(-5,125);
  out->Sumw2();
  out->SetLineColor(kBlack);
  out->SetMarkerStyle(20);
  out->SetTitle("");
  out->GetXaxis()->SetTitle("ADC-PED (a.u.)");
  BGR->Draw("SAME");
  MIPH1->Draw("SAME");
  MIPH2->Draw("SAME");
  MIPH3->Draw("SAME");
  MIPH4->Draw("SAME");
  fitH->SetRange(xfit_min,xfit_max);
  fitH->Draw("SAME");
  TLatex *text = new TLatex();
  text->DrawLatex(0, (1.03*(ymax)), inname.Data() );
  text->DrawLatex(30, (0.83*(ymax)), Form("Entries  %d",entries) );
  text->DrawLatex(30, (0.73*(ymax)), Form("State  %d",state) );
  text->DrawLatex(30, (0.53*(ymax)), Form("#lambda  %.1f #pm %.1f",lda,elda) );
  text->DrawLatex(30, (0.43*(ymax)), Form("#sigma  %.1f #pm %.1f",sg1,esg1) );
  text->SetTextColor(kRed-3);
  text->DrawLatex(30, (0.63*(ymax)), Form("#Chi^{2} / NDF  %.2f",ncs) );
  text->SetTextColor(kBlue-3);
  text->DrawLatex(75, (0.73*(ymax)), Form("#Alpha  %.0f #pm %.0f",fitH->GetParameter(0),fitH->GetParError(0)) );
  text->SetTextColor(kCyan-3);
  text->DrawLatex(75, (0.63*(ymax)), Form("f_{1}  %.2f",fr1) );
  text->SetTextColor(kGreen-3);
  text->DrawLatex(75, (0.53*(ymax)), Form("f_{2}  %.2f #pm %.2f",fr2,efr2) );
  text->SetTextColor(kOrange-3);
  text->DrawLatex(75, (0.43*(ymax)), Form("f_{3}  %.2f #pm %.2f",fr3,efr3) );
  text->SetTextColor(kMagenta-3);
  text->DrawLatex(75, (0.33*(ymax)), Form("f_{4}  %.2f #pm %.2f",fr4,efr4) );
  text->SetTextColor(kGray);
  text->DrawLatex(75, (0.83*(ymax)), Form("b  %.2f",bsl) );
  text->SetTextColor(kBlack);
  text->SetTextSize(0.035);
  text->SetTextColor( kRed-3 );
  text->DrawLatex(30, (0.93*(ymax)), "e^{bx} + #Alpha ( f_{1} L_{1}(x) + f_{2} L_{2}(x) + f_{3} L_{3}(x) + f_{4} L_{4}(x))");
  main->SaveAs( Form("%s/SEN%03d/%s.eps",run,key/128,outname.Data()), "eps" );
  return;
}
Ejemplo n.º 5
0
int readstate (RECYCLE * recycle) 

{
	FILE *fp;
	if ((fp = fopen (recycle->statefilename, "r")) != (FILE *) (0)) 
	{
		char record [DATETIME_MAX + FILENAME_MAX];
		int line = 0;
		if ((recycle->flags & RECYCLE_B_VERBOSE) != 0) 
		{
			error (0, 0, "%s: opened state file", recycle->statefilename);
		}
		line++;
		if (fgets (record, sizeof (record) - 1, fp) == (char *) (0)) 
		{
			error (0, 0, "%s: can't read state file header", recycle->statefilename);
			fclose (fp);
			return (1);
		}
		if (strcmp (record, SIGNATURE)) 
		{
			error_on_line (0, 0, recycle->statefilename, line, "isempty state file header");
			fclose (fp);
			return (1);
		}
		for (line++; fgets (record, sizeof (record) - 1, fp) != (char *) (0); line++) 
		{
			int length = strlen (record);
			if (record [--length] != '\n') 
			{
				error_on_line (0, errno, recycle->statefilename, line, "line way too long");
				fclose (fp);
				return (1);
			}
			record [length] = '\0';
			if (length > 0) 
			{
				STATE *state;
				struct tm tm;
				char *fields [RECYCLESIZE];
				char *sp;
				int field = 0;
				for (fields [field++] = sp = record; (*sp != (char) (0)); ++sp) 
				{
					if ((*sp == ' ') && (field < RECYCLESIZE)) 
					{
						fields [field++] = sp + 1;
						*sp = (char) (0);
					}
				}
				fields [field] = (char *) (0);
				if (field != RECYCLESIZE) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "wrong number of fieldss");
					fclose (fp);
					return (1);
				}
				memset (&tm, 0, sizeof (tm));
				if (sscanf (fields [RECYCLEDATE], "%d-%d-%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday) != 3) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "datespec '%s' has isempty syntax.", fields [RECYCLEDATE]);
					fclose (fp);
					return (1);
				}
				if (sscanf (fields [RECYCLETIME], "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 3) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "timespec '%s' has isempty syntax", fields [RECYCLETIME]);
					fclose (fp);
					return (1);
				}
				if ((tm.tm_year != 1900) && (tm.tm_year < 1996 || tm.tm_year > 2035)) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "year in datespec '%s' is out of range", fields [RECYCLEDATE]);
					fclose (fp);
					return (1);
				}
				if ((tm.tm_mon < 1) || (tm.tm_mon > 12)) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "month in datespec '%s' is out of range.", fields [RECYCLEDATE]);
					fclose (fp);
					return (1);
				}
				if ((tm.tm_mday < 1) || (tm.tm_mday > 31)) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "day in datespec '%s' is out of range.", fields [RECYCLEDATE]);
					fclose (fp);
					return (1);
				}
				tm.tm_year -= 1900;
				tm.tm_mon--;
				mktime (&tm);
				if (!findstate (recycle, fields [RECYCLEFILE])) 
				{
					makestate (recycle, fields [RECYCLEFILE]);
				}
				state = &recycle->states [recycle->state];
				state->tm = tm;
			}
		}
		fclose (fp);
		return (0);
	}
	if (errno == ENOENT) 
	{
		if ((fp = fopen (recycle->statefilename, "w")) != (FILE *) (0)) 
		{
			fprintf (fp, "%s\n", SIGNATURE);
			fclose (fp);
			return (0);
		}
		error (0, errno, "can't init state file %s", recycle->statefilename);
		return (1);
	}
	error (0, errno, "can't read state file %s", recycle->statefilename);
	return (1);
}