Пример #1
0
ALsoundfont *ALsoundfont_getDefSoundfont(ALCcontext *context)
{
    ALCdevice *device = context->Device;
    al_string fname = AL_STRING_INIT_STATIC();
    const char *namelist;

    if(device->DefaultSfont)
        return device->DefaultSfont;

    device->DefaultSfont = calloc(1, sizeof(device->DefaultSfont[0]));
    ALsoundfont_Construct(device->DefaultSfont);

    namelist = getenv("ALSOFT_SOUNDFONT");
    if(!namelist || !namelist[0])
        ConfigValueStr("midi", "soundfont", &namelist);
    while(namelist && namelist[0])
    {
        const char *next, *end;
        FILE *f;

        while(*namelist && (isspace(*namelist) || *namelist == ','))
            namelist++;
        if(!*namelist)
            break;
        next = strchr(namelist, ',');
        end = next ? next++ : (namelist+strlen(namelist));
        while(--end != namelist && isspace(*end)) {
        }
        if(end == namelist)
            continue;
        al_string_append_range(&fname, namelist, end+1);
        namelist = next;

        f = OpenDataFile(al_string_get_cstr(fname), "openal/soundfonts");
        if(f == NULL)
            ERR("Failed to open %s\n", al_string_get_cstr(fname));
        else
        {
            Reader reader;
            reader.cb = ALsoundfont_read;
            reader.ptr = f;
            reader.error = 0;
            TRACE("Loading %s\n", al_string_get_cstr(fname));
            loadSf2(&reader, device->DefaultSfont, context);
            fclose(f);
        }

        al_string_clear(&fname);
    }
    AL_STRING_DEINIT(fname);

    return device->DefaultSfont;
}
Пример #2
0
void CApplicationImpl::OpenLastDataFile()
{
	// open last datafile

	CString csLastFile;
	CApplicationImpl::Get().m_mru.GetFromList(ID_FILE_MRU_FIRST, csLastFile);
	
	CString csDefFileName = GetDefaultDataFileName();

	if (csLastFile.IsEmpty())
	{
		csLastFile = csDefFileName;
	}
	else if (csLastFile != csDefFileName && !::PathFileExists(csLastFile))
	{
		GuiUtils::ErrorMessage(resutils::resstring_fmt(IDS_FILE_NOT_FOUND, csLastFile).c_str());
		csLastFile = csDefFileName;
	}
	try
	{
		OpenDataFile(csLastFile);
		return; // no error
	}
	CATCH_ALL_ERRORS(GetMainViewHwnd())

	// error opening default datafile - show open dialog

	CSSFileDialog dlg(TRUE, _T("*.adx"), GetDefaultDataFileName(), OFN_HIDEREADONLY, CResString<64>(IDS_DATA_FILE_FILTER), NULL);
	if (dlg.DoModal() == IDOK)
	{
		OpenDataFile(dlg.m_szFileName);
	}
	else
	{
		ThrowError(_T("No file selected"));
	}
}
Пример #3
0
HANDLE NLSTable::OpenDataFile(LPCWSTR pFileName)
{
    THROWSCOMPLUSEXCEPTION();
    // The following marco will delete pAnsiFileName when
    // getting out of the scope of this function.
    MAKE_ANSIPTR_FROMWIDE(pAnsiFileName, pFileName);
    if (!pAnsiFileName)
    {
        COMPlusThrowOM();
    }

    HANDLE hFile = OpenDataFile((LPCSTR)pAnsiFileName);
    _ASSERTE(hFile != INVALID_HANDLE_VALUE);
    return (hFile);
}
Пример #4
0
/**
 * Open recent datafile
 */
void CApplicationImpl::OpenDataFile(int wID)
{
	TCHAR szFile[MAX_PATH];
	if (m_mru.GetFromList(wID, szFile, MAX_PATH))
	{
		if (::PathFileExists(szFile))
		{
			OpenDataFile(szFile);
		}
		else
		{
			m_mru.RemoveFromList(wID);
			m_mru.WriteToRegistry(GetOptionsPath(_T("Application")));
			ThrowError(resutils::resstring_fmt(IDS_FILE_NOT_FOUND, szFile).c_str());
		}
	}
}
Пример #5
0
LPVOID NLSTable::MapDataFile(LPCWSTR pMappingName, LPCSTR pFileName, HANDLE *hFileMap) {
    _ASSERTE(pMappingName != NULL); // Must be a named file mapping object.
    _ASSERTE(pFileName != NULL);    // Must have a valid file name.
    _ASSERTE(hFileMap != NULL);     // Must have a valid location for the handle.

    THROWSCOMPLUSEXCEPTION();

    *hFileMap = NULL;
    LPVOID pData=NULL; //It's silly to have this up here, but it makes the compiler happy.

    HANDLE hFile = OpenDataFile(pFileName);

    if (hFile == INVALID_HANDLE_VALUE) {
        goto ErrorExit;
    }
    *hFileMap = WszCreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
    CloseHandle(hFile);
    if (*hFileMap == NULL) {
        _ASSERTE(!"Error in CreateFileMapping");
        goto ErrorExit;
    }

    //
    // Map a view of the file mapping.
    //
    pData = MapViewOfFile(*hFileMap, FILE_MAP_READ, 0, 0, 0);
    if (pData == NULL)
    {
        _ASSERTE(!"Error in MapViewOfFile");
        goto ErrorExit;
    }

    return (pData);
            
 ErrorExit:
    if (*hFileMap) {
        CloseHandle(*hFileMap);
    }

    //If we can't get the table, we're in trouble anyway.  Throw an EE Exception.
    FATAL_EE_ERROR();
    return NULL;
}
Пример #6
0
void    _HYObjectInspector::OpenObject (void)
{
    _HYPullDown*    p1 = (_HYPullDown*)GetCellObject (0,2);
    switch (p1->GetSelection()) {
    case 0: {
        OpenTreeFile();
        break;
    }
    case 1: {
        OpenDataFile();
        break;
    }
    case 2: {
        OpenModelFile();
        break;
    }
    default:
        return;
    }
    BuildListOfObjects (p1->GetSelection());
}
Пример #7
0
void AnalyzeData(char *DataFile = "drs4_peds_5buffers.dat", Int_t nevt,
		Int_t startEv = 1, char *PedFile, Int_t DrawExtraGraphs = 0) {


	// Redefine DOMINO Depth in ADC counts
	const Float_t DominoDepthADC = pow(2, DOMINO_DEPTH);

	// open file

	FILE *fdata = OpenDataFile(DataFile);
	struct channel_struct *p;
	struct channel_struct *dep;

	// create histograms
	// create list of histograms for channels and distribution

	TList *DistChList = new TList();
	TH1F *distch; // histo with distribution of cell-charge, for each channel

	TList *DistChSubList = new TList();
	TH1F *distchsub; // histo with distribution of cell-charge, pedestals subtracted, for each channel

	TList *DistCh0SubList = new TList();
	TH1F *distch0sub; // histo with distribution of cell-charge, pedestals subtracted,
	// channel 0 subtracted for each channel

	TList *grPedList = new TList();
	TGraphErrors *grPed; // for each channel, pedestal value and RMS for each cell is plotted

	TList *hCellList = new TList();
	TH1F *hCell; // charge distribution for each cell (DOMINO_NCELL x DOMINO_NCH histos)
	TList *hCellSubList = new TList();
	TH1F *hCellSub; // charge distribution for each cell (DOMINO_NCELL x DOMINO_NCH histos), pedestal subtracted

	TList *hRMSList = new TList();
	TH1F *hRMSdist; // histo with RMS distribution (statistical RMS of distribution)
	TList *hRMSFitList = new TList();
	TH1F *hRMSFitdist; // histo with RMS distribution (RMS of Gaussian fit)

	TList *grDataList = new TList();
	TGraphErrors *grData; // charge-cell and RMS for each cell is plotted

	TList *grDataSubList = new TList();
	TGraphErrors *grDataSub; // pedestal subtracted charge-cell and RMS for each cell is plotted


	for (int h = 0; h < DOMINO_NCH; h++) {
		//
		TString title = "Data Dist channel";
		title += h;
		distch = new TH1F(title, title, DominoDepthADC, 0., DominoDepthADC);
		DistChList->Add(distch);
		//
		TString title = "Data Dist Ped Sub channel";
		title += h;
		distchsub = new TH1F(title, title, DominoDepthADC, -DominoDepthADC/2, DominoDepthADC/2);
		DistChSubList->Add(distchsub);
		//
		TString title = "Data Dist Ped Ch0 Sub channel";
		title += h;
		distch0sub = new TH1F(title, title, DominoDepthADC, -DominoDepthADC/2, DominoDepthADC/2);
		DistCh0SubList->Add(distch0sub);
		//
		TString title = "Pedestal ch";
		title += h;
		grPed = new TGraphErrors(DOMINO_NCELL);
		grPed->SetTitle(title);
		grPedList->Add(grPed);
		//
		TString title = "Data ch";
		title += h;
		grData = new TGraphErrors(DOMINO_NCELL);
		grData->SetTitle(title);
		grDataList->Add(grData);
		//
		// Mean data and RMS for each channel and cell
		TString title = "Data PedSubtracted ch";
		title += h;
		grDataSub = new TGraphErrors(DOMINO_NCELL);
		grDataSub->SetTitle(title);
		grDataSubList->Add(grDataSub);
		//
		for (int ch = 0; ch < DOMINO_NCELL; ch++) {
			// data distribution histos
			TString title = "Data ch";
			title += h;
			title += " cell";
			title += ch;
			hCell = new TH1F(title, title, DominoDepthADC, 0., DominoDepthADC);
			hCellList->Add(hCell);
			// data (ped subtracted) distribution histos
			TString title = "Data PedSub ch";
			title += h;
			title += " cell ";
			title += ch;
			hCellSub = new TH1F(title, title, 2 * DominoDepthADC, -1
					* DominoDepthADC, DominoDepthADC);
			hCellSubList->Add(hCellSub);
		}
		// Data-RMS distribution histos
		TString title = "RMSDist channel";
		title += h;
		hRMSdist = new TH1F(title, title, 100, 0, 20.);
		hRMSList->Add(hRMSdist);
		// Data-RMS (calculated through a fit) distribution histos
		TString title = "RMSFitDist channel";
		title += h;
		hRMSFitdist = new TH1F(title, title, 100, 0, 20.);
		hRMSFitList->Add(hRMSFitdist);
	}
	//--------------
	//
	// calculate or read pedestals from file
	grPedList = OpenPedestals(PedFile);

	//    return;
	//
	// ====== Read data file and subtract the pedestals
	//
	// Count number of events in data file
	int nevtDataMax = 0;
	while (!feof(fdata)) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		nevtDataMax++;
	}
	printf("nevtDataMax: %d\n", nevtDataMax);

	if (nevt > (nevtDataMax - startEv) || nevt == 0)
		nevt = nevtDataMax - startEv;
	cout << endl << "==>> Processing " << nevt << " events from file "
			<< DataFile << endl;

	rewind(fdata);

	Int_t ievt = 1;
	// go to first event (startEv)
	while (ievt < startEv) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		if (feof(fdata))
			break;
		ievt++;
	}
	// filling
	ievt = 1;
	Int_t flagEnd = 0;
	Double_t chtmp;
	Double_t PedVal, itmp, Ch0Val;
	// loop on events
	cout << endl << " --- read DATA file:" << fdata << endl;
	while (ievt <= nevt && !flagEnd) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		if (feof(fdata))
			flagEnd = 1;
		if (ievt % (nevt / 10 + 1) == 0)
			cout << "*" << endl;
		p = (struct channel_struct *) &event_data.ch[0]; // read bunch of data
		dep = (struct channel_struct *) &event_data.ch[1]; // read bunch of data

		TGraphErrors *grCh0 = new TGraphErrors(DOMINO_NCELL);

		// loop on channels
		for (int h = 0; h < DOMINO_NCH; h++) {
			// loop on cells
			distch = (TH1F *) DistChList->At(h);
			distchsub = (TH1F *) DistChSubList->At(h);
			grPed = (TGraphErrors *) grPedList->At(h);
			distch0sub = (TH1F *) DistCh0SubList->At(h);
			if(h==0) {
				for(i = 0; i < DOMINO_NCELL;i++) {
					grPed->GetPoint(i, itmp, PedVal);
					chtmp = (Double_t)(p->data[i]);
					chtmp = chtmp - PedVal;
					grCh0->SetPoint(i,itmp, chtmp);
				}
			}
			for (int i = 0; i < DOMINO_NCELL; i++) {
				// Read pedestal value for this cell
				grPed->GetPoint(i, itmp, PedVal);
				grCh0->GetPoint(i, itmp, Ch0Val);
				//                cout << itmp << ", " << PedVal << endl;
				// Read calibration correction for this cell
				//                CalFact =

				//charge distribution for each cell, pedestal subtracted
				chtmp = (Double_t)(p->data[i]); // data value
				//                cout  << "tcell, tcell, depth: " << chtmp << ","  << p->data[i] << "," << deptmp << endl;
				distch->Fill(chtmp);
				// Check data value: must be within DOMINO Depth
				//                if(chtmp > DominoDepthADC)
				//                    cout << " === WARNING!!! Channel " << h << " Cell " << i << " has value " << chtmp << endl;
				//                cout << "Charge: " << p->data[i] << endl;
				((TH1 *) hCellList->At(h * DOMINO_NCELL + i))->Fill(chtmp);
				// Now the pedestal is subtracted
				chtmp = chtmp - PedVal;
				distchsub->Fill(chtmp);
				((TH1 *) hCellSubList->At(h * DOMINO_NCELL + i))->Fill(chtmp);
				chtmp = chtmp - Ch0Val;
				distch0sub->Fill(chtmp);
			}
			p++; // next channel
		}
		ievt++; // next event
	}
	cout << endl;

	// now mean and RMS for each cell are computed and save in histos and graphs
	cout << " --- filling data histos and grphs " << endl;
	TF1 *fgauss = new TF1("fgauss", Gauss, -10., 10., 3);
	fgauss->SetParLimits(0, 0.1, 10000.);
	fgauss->SetParLimits(1, 0., 4096.);
	fgauss->SetParLimits(2, 0.1, 20.);
	Float_t mean, rms, meansub, rmssub;
	for (int h = 0; h < DOMINO_NCH; h++) {
		//        for (int h=5; h<6; h++){
		cout << " Channel:" << h << endl;
		hRMSdist = (TH1F *) hRMSList->At(h);
		hRMSFitdist = (TH1F *) hRMSFitList->At(h);
		grData = (TGraphErrors *) grDataList->At(h);
		grDataSub = (TGraphErrors *) grDataSubList->At(h);
		for (int ch = 0; ch < DOMINO_NCELL; ch++) {
			// data distribution histos
			//            cout << "cell:" << ch << " index:" << h*DOMINO_NCELL+ch << " Mean,RMS:"<<hCell->GetMean()<< "," << hCell->GetRMS()<<endl;
			hCell = (TH1F *) hCellList->At(h * DOMINO_NCELL + ch);
			mean = hCell->GetMean();
			rms = hCell->GetRMS();
			hCellSub = (TH1F *) hCellSubList->At(h * DOMINO_NCELL + ch);
			meansub = hCellSub->GetMean();
			rmssub = hCellSub->GetRMS();
			fgauss->SetParameter(0, (Double_t) nevt / 4.);
			fgauss->SetParameter(1, mean);
			fgauss->SetParameter(2, rms);
			//            hCell->Fit("fgauss","QN0");
			grData->SetPoint(ch, ch, mean);
			grData->SetPointError(ch, 0, rms);
			grDataSub->SetPoint(ch, ch, meansub);
			//            grDataSub->SetPointError(ch,0.5,rmssub);
			grDataSub->SetPointError(ch, 0.5, 2.1);
			hRMSdist->Fill(rms);
			hRMSFitdist->Fill(fgauss->GetParameter(2));
			//           cout << "cell:" << ch << " index:" << h*DOMINO_NCELL+ch << " Mean,RMS:"<< mean << "," << rms<<endl;
		}
	}

	Double_t x, y, chtmp, x1, x2, y1, y2;

	/*TList *grCellCalibList = OpenCalibFile("CalibrationData1000events.root");

	TGraphErrors *grCellCalib;
	TGraphErrors *grDataSubCalib = new TGraphErrors(DOMINO_NCELL);
	grDataSubCalib->SetTitle("Data after calibration correction");
	grDataSub = (TGraphErrors *) grDataSubList->At(anaChannel);


	for(ch = 0; ch < DOMINO_NCELL; ch++) {
		grCellCalib = ((TGraphErrors *) grCellCalibList->At(ch));
		grCellCalib->Fit("pol3", "Q");
		TF1 *pol3fit = ((TF1 *) grCellCalib->GetFunction("pol3"));
		grDataSub->GetPoint(ch, x, y);
		chtmp = y - (Double_t)(pol3fit->Eval(y/3.25));
		grDataSubCalib->SetPoint(ch, x, chtmp);
	}

	TCanvas *cGrTest = new TCanvas("grTest", "test per vedere i dati", 1000,1000);

	grDataSubCalib->Draw("APEL");*/


	TString Title = "Charge Distribution per channel";
	gStyle->SetOptFit(111);
	TCanvas *cdistch = new TCanvas("cdistch", Title, 1000, 1000);
	cdistch->Divide(3, 3);
	for (int i = 0; i < DOMINO_NCH; i++) {
		cdistch->cd(i + 1);
		TH1 *dhist = (TH1 *) DistChList->At(i);
		dhist->DrawCopy();
		dhist->SetLineWidth(1);
		dhist->Fit("gaus", "Q");
		dhist->GetFunction("gaus")->SetLineColor(4);
		dhist->GetFunction("gaus")->SetLineWidth(2);
	}

	TString Title = "Charge Distribution Pedestals Subtracted per channel";
	TCanvas *cdistchsub = new TCanvas("cdistchsub", Title, 1000, 1000);
	cdistchsub->Divide(3, 3);
	for (int i = 0; i < DOMINO_NCH; i++) {
		cdistchsub->cd(i + 1);
		TH1 *dsubhist = (TH1 *) DistChSubList->At(i);
		dsubhist->DrawCopy();
		dsubhist->SetLineWidth(1);
		dsubhist->Fit("gaus", "Q");
		dsubhist->GetFunction("gaus")->SetLineColor(4);
		dsubhist->GetFunction("gaus")->SetLineWidth(2);
	}

	TString Title = "Charge Distribution Pedestals and Ch0 Subtracted per channel";
	TCanvas *cdistch0sub = new TCanvas("cdistch0sub", Title, 1000, 1000);
	cdistch0sub->Divide(3, 3);
	for (int i = 0; i < DOMINO_NCH; i++) {
		cdistch0sub->cd(i + 1);
		TH1 *dch0subhist = (TH1 *) DistCh0SubList->At(i);
		dch0subhist->DrawCopy();
		dch0subhist->SetLineWidth(1);
		dch0subhist->Fit("gaus", "Q");
		dch0subhist->GetFunction("gaus")->SetLineColor(4);
		dch0subhist->GetFunction("gaus")->SetLineWidth(2);
	}

	TCanvas *cDataSubTest = new TCanvas("cDataSubTest", "Data after pedestal subtraction", 1000, 1000);
	cDataSubTest->Divide(1,8);
	for (h = 0; h< DOMINO_NCH; h++) {
		grDataSub = (TGraphErrors *) grDataSubList->At(h);
		cDataSubTest->cd(h+1);
		grDataSub->GetYaxis()->SetLabelSize(0.06);
		grDataSub->GetXaxis()->SetLabelSize(0.06);
		grDataSub->Draw("APE");
	}

	TCanvas *cDataSubTestCh5 = new TCanvas("cDataSubTestCh5", "Data after pedestal subtraction Ch5", 1200, 800);
	grDataSub = (TGraphErrors *) grDataSubList->At(anaChannel);
	grDataSub->GetYaxis()->SetLabelSize(0.06);
	grDataSub->GetYaxis()->SetTitle("ADC Counts");
	grDataSub->GetXaxis()->SetTitle("Cell");
	grDataSub->GetXaxis()->SetLabelSize(0.06);
	TLine *refval = new TLine(0,350,1024,350);
	refval->SetLineWidth(3);
	refval->SetLineStyle(2);
	refval->SetLineColor(2);
	TLine *i1 = new TLine(121,-50,121,800);
	i1->SetLineStyle(2);
	TLine *i2 = new TLine(291,-50,291,800);
	i2->SetLineStyle(2);
	TLine *i3 = new TLine(461,-50,461,800);
	i3->SetLineStyle(2);
	TLine *i4 = new TLine(632,-50,632,800);
	i4->SetLineStyle(2);
	TLine *i5 = new TLine(803,-50,803,800);
	i5->SetLineStyle(2);
	TLine *i6 = new TLine(975,-50,975,800);
	i6->SetLineStyle(2);
	TLine *ireal1 = new TLine(121+20,600,121+20,800);
	ireal1->SetLineWidth(3);
	ireal1->SetLineColor(4);
	TLine *ireal2 = new TLine(291-20,600,291-20,800);
	ireal2->SetLineWidth(3);
	ireal2->SetLineColor(4);
	TLine *ireal3 = new TLine(461+20,600,461+20,800);
	ireal3->SetLineWidth(3);
	ireal3->SetLineColor(4);
	TLine *ireal4 = new TLine(632-20,600,632-20,800);
	ireal4->SetLineWidth(3);
	ireal4->SetLineColor(4);
	TLine *ireal5 = new TLine(803+20,600,803+20,800);
	ireal5->SetLineWidth(3);
	ireal5->SetLineColor(4);
	TLine *ireal6 = new TLine(975-20,600,975-20,800);
	ireal6->SetLineWidth(3);
	ireal6->SetLineColor(4);
	grDataSub->Draw("APE");
	refval->Draw("SAME");
	i1->Draw("SAME");
	i2->Draw("SAME");
	i3->Draw("SAME");
	i4->Draw("SAME");
	i5->Draw("SAME");
	i6->Draw("SAME");
	ireal1->Draw("SAME");
	ireal2->Draw("SAME");
	ireal3->Draw("SAME");
	ireal4->Draw("SAME");
	ireal5->Draw("SAME");
	ireal6->Draw("SAME");


	TCanvas *cDataTest = new TCanvas("cDataTest", "Raw Data", 1000,1000);
	cDataTest->Divide(1,8);
	for(h = 0; h < DOMINO_NCH; h++) {
		cDataTest->cd(h+1);
		grData = (TGraphErrors *) grDataList->At(h);
		grData->SetMarkerStyle(20);
		grData->SetMarkerSize(0.5);
		grData->Draw("APE");

	}

	// save root file with graph containing channel 5 data after pedestals subtraction.
	/*
	cout << "test" << endl;

	TString OutFile = DataSubFile;
	TFile *f = new TFile(OutFile,"RECREATE");
	int h = anaChannel;
	TString key="DataSubGraph";
	key += h;
	((TGraphErrors*)grDataSubList->At(h))->Write(key);
	f->Close();
	cout << " ---- Write data on file " << endl;
	 */

	// =======================================================//
	// =====================Matteo's Code=====================//
	// =======================================================//
	/*
	Int_t cht, incCht, decCht, xflag, nPeriods, iMax, iMin;
	Double_t xdiff, incDiff, decDiff, incDiffTemp, decDiffTemp, incXDiff, decXDiff;
	Double_t fitMax, fitMin, fitPeriod, chisquare;
	Double_t DominoXval[DOMINO_NCELL];
	Double_t DominoYval[DOMINO_NCELL];
	Double_t FitXval[DOMINO_NCELL];
	Double_t FitYval[DOMINO_NCELL];


        // opens grDataSub.root

        TString FileName = DataSubFile;
        TGraphErrors *grDataSub;
        int h = anaChannel;
        TFile *f = new TFile(FileName);
        TString key = "DataSubGraph";
        key += h;
        grDataSub = (TGraphErrors *) f->Get(key);
        f->Close();


	// Create a new graph with channel 5 data
	TGraphErrors *grDataSubAnaCh;
	int h = anaChannel;
	grDataSubAnaCh = (TGraphErrors *) grDataSubList->At(h);

	TGraphErrors *grDataSubFix = grDataSubAnaCh->Clone();
	TGraphErrors *grRes = new TGraphErrors(DOMINO_NCELL);
	TList *grResPeriodList = new TList();



	Double_t xtemp, ytemp, DominoMax, DominoMin;

	for (int ch = 0; ch < DOMINO_NCELL; ch++){
		// get domino-output point and save in array
		grDataSubAnaCh->GetPoint(ch, DominoXval[ch], DominoYval[ch]);
	}

	// find the domino point with max y-value
	iMax = 0;
	for(int ch = 0; ch < DOMINO_NCELL; ch++) {
		if(DominoYval[ch] > DominoYval[iMax]) {
			DominoMax = DominoYval[ch];
			iMax = ch;
		}
	}

	cout << "DominoMax e': " << DominoMax << endl;

	// find the domino point with min y-value
	iMin = 0;
	for (int ch = 0; ch < DOMINO_NCELL; ch++) {
		if(DominoYval[ch] < DominoYval[iMin]) {
			DominoMin = DominoYval[ch];
			iMin = ch;
		}
	}

	cout << "DominoMin e': " << DominoMin << endl;

	// remove points from the graph that will be used for fit
	for (int ch = 0; ch < DOMINO_NCELL; ch++){
		grDataSubFix->GetPoint(ch, xtemp, ytemp);
		if(ytemp > 0.8*DominoMax || ytemp < 0.2*DominoMin)
			grDataSubFix->RemovePoint(ch);
	}


	TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4);
	fsin->SetParameters(600., DOMINO_NCELL / 4., 150., 150.);
	fsin->SetParNames("amplitude", "Period", "Phase", "DC-Offset");
	grDataSubFix->Fit("fsin");
	TF1 *fsinFit = grDataSubFix->GetFunction("fsin");
	fsinFit->SetParNames("amplitude", "Period", "Phase", "DC-Offset");
	chisquare = grDataSub->Chisquare(fsinFit);
	cout << "il chi quadro della funzione di fit e' : " << chisquare << endl;

	for (int ch = 0; ch < DOMINO_NCELL; ch++) {
		// get Fit-value and save in array
		FitXval[ch] = DominoXval[ch];
		FitYval[ch] = fsinFit->Eval(FitXval[ch]);
	}

	fitPeriod = fsinFit->GetParameter("Period");
	cout << "il periodo della funzione e': " << fitPeriod << endl;

	nPeriods = (Int_t) (DOMINO_NCELL/fitPeriod);
	cout << "il numero di periodi della funzione e': " << nPeriods << endl;

	fitMax = fsinFit->GetMaximum();
	cout << "il massimo della funzione e': " << fitMax << endl;

	fitMin = fsinFit->GetMinimum();
	cout << "il minimo della funzione e': " << fitMin << endl;




	// computes the y difference between the ch-domino point and the i-fit point
	// and stops when the difference changes sign
	//
	// first and last points are not included in the cicle
	//
	// if the fit point y-value is bigger or smaller than the fit function max*0.8 or min*0.2
	// the point is removed

	for (int ch = 1; ch < DOMINO_NCELL - 1; ch++) {

		if(FitYval[ch] > 0.8*fitMax || FitYval[ch] < 0.2*fitMin) {
			grRes->RemovePoint(ch);
			continue;
		}

		incDiff = DominoYval[ch] - FitYval[ch];
		incDiffTemp = DominoYval[ch] - FitYval[ch + 1];

		decDiff = DominoYval[ch] - FitYval[ch];
		decDiffTemp = DominoYval[ch] - FitYval[ch - 1];

		if(abs(incDiffTemp) < abs(incDiff) || (sign(incDiff) != sign(incDiffTemp) && abs(decDiffTemp) > abs(decDiff))) {
			for (int i = ch; i < DOMINO_NCELL; i++, incDiff = incDiffTemp) {
				incDiffTemp = DominoYval[ch] - FitYval[i];

				if (sign(incDiff) != sign(incDiffTemp)) {
					if(abs(incDiffTemp) < abs(incDiff))
						incCht = i;
					else
						incCht = i - 1;
					break;
				}
			}
			xflag = 1;
		}
		else if(abs(decDiffTemp) < abs(decDiff) || (sign(decDiff) != sign(decDiffTemp) && abs(incDiffTemp) > abs(incDiff))) {
			for (int j = ch; j >= 0 ; j--, decDiff = decDiffTemp) {
				decDiffTemp = DominoYval[ch] - FitYval[j];

				if (sign(decDiff) != sign(decDiffTemp)) {
					if(abs(decDiffTemp) < abs(decDiff))
						decCht = j;
					else
						decCht = j + 1;
					break;
				}
			}
			xflag = -1;
		}

		if(xflag == 1)
			xdiff = FitXval[incCht] - DominoXval[ch];
		else
			xdiff = FitXval[decCht] - DominoXval[ch];

		grRes->SetPoint(ch, (Double_t) ch, xdiff);
	}

	cout << "Draw Time Residuals" << endl;
	TString Title = "Time Residuals";
	TCanvas *timeres = new TCanvas("timeres", Title, 1200, 780);
	grRes->SetMarkerStyle(20);
	grRes->SetMarkerSize(0.3);
	grRes->GetYaxis()->SetLabelSize(0.12);
	grRes->GetXaxis()->SetLabelSize(0.12);
	grRes->Draw("APE");


	// The previous graph is now split in N graphs, where N is the number of fit periods

	// this will be needed to set the function phase
	//
    //    iMax = 0;
	//
    //    for(ch = 0; ch < fitPeriod - 1; ch++) {
    //            if(FitYval[ch] > FitYval[iMax]) iMax = ch;
    //    }

	cout << "il primo massimo ha l'indice : " << iMax << endl;

	for (i = 0; i < nPeriods; i++) {
		TGraphErrors *grResPeriod = new TGraphErrors((Int_t) fitPeriod);
		grResPeriodList->Add(grResPeriod);

		for(ch = i*fitPeriod + 1; ch < fitPeriod + (i*fitPeriod); ch++) {

			if(FitYval[ch] > 0.8*fitMax || FitYval[ch] < 0.2*fitMin) {
				grResPeriod->RemovePoint(ch);
				continue;
			}

			incDiff = DominoYval[ch] - FitYval[ch];
			incDiffTemp = DominoYval[ch] - FitYval[ch + 1];

			decDiff = DominoYval[ch] - FitYval[ch];
			decDiffTemp = DominoYval[ch] - FitYval[ch - 1];

			if(abs(incDiffTemp) < abs(incDiff) || (sign(incDiff) != sign(incDiffTemp) && abs(decDiffTemp) > abs(decDiff))) {
				for (int k = ch; k < k*fitPeriod + fitPeriod; k++, incDiff = incDiffTemp) {
					incDiffTemp = DominoYval[ch] - FitYval[k];

					if (sign(incDiff) != sign(incDiffTemp)) {
						if(abs(incDiffTemp) < abs(incDiff))
							incCht = k;
						else
							incCht = k - 1;
						break;
					}
				}
				xflag = 1;
			}
			else if(abs(decDiffTemp) < abs(decDiff) || (sign(decDiff) != sign(decDiffTemp) && abs(incDiffTemp) > abs(incDiff))) {
				for (int j = ch; j > i*fitPeriod; j--, decDiff = decDiffTemp) {
					decDiffTemp = DominoYval[ch] - FitYval[j];

					if (sign(decDiff) != sign(decDiffTemp)) {
						if(abs(decDiffTemp) < abs(decDiff))
							decCht = j;
						else
							decCht = j + 1;
						break;
					}
				}
				xflag = -1;
			}

			if(xflag == 1)
				xdiff = FitXval[incCht] - DominoXval[ch];
			else
				xdiff = FitXval[decCht] - DominoXval[ch];

			grResPeriod->SetPoint(ch - i*fitPeriod, (Double_t) (ch - i*fitPeriod), xdiff);
		}
	}

	TCanvas *timeresperiod = new TCanvas("timeresperiod", "Time Residuals Period", 1200, 780);
	for(i = 0; i < nPeriods; i++) {
		grResPeriod = ((TGraphErrors *) grResPeriodList->At(i));
		grResPeriod->SetMarkerStyle(20);
		grResPeriod->SetMarkerSize(0.3);
		grResPeriod->GetYaxis()->SetLabelSize(0.12);
		grResPeriod->GetXaxis()->SetLabelSize(0.12);
		grResPeriod->Draw("APEsame");
	}

	cout << "Draw Data - Pedestals Subtracted" << endl;
	TString Title = "Average Charge - Pedestal subtracted";
	TCanvas *csubdata = new TCanvas("csubdata", Title, 1200, 780);
	grDataSubAnaCh->SetMarkerStyle(20);
	grDataSubAnaCh->SetMarkerSize(0.3);
	grDataSubAnaCh->GetYaxis()->SetLabelSize(0.12);
	grDataSubAnaCh->GetXaxis()->SetLabelSize(0.12);
	grDataSubAnaCh->Draw("APE");
	fsinFit->Draw("same");
	 */
	// draw extra graphs
	if (DrawExtraGraphs == 1) {
		cout << " ----- DRAW Results ------" << endl;
		//================ DRAW Results ==================

		TCanvas *c = new TCanvas("ctmp", "test", 800, 800);
		c->Divide(3, 3);
		for (int pad = 1; pad < 10; pad++) {
			c->cd(pad);
			((TH1 *) hCellList->At(pad * 512 + 219))->DrawCopy();
			hCellSub = (TH1F *) hCellSubList->At(pad * 512 + 219);
			hCellSub->SetLineColor(2);
			hCellSub->DrawCopy("same");
		}

		cout << "Draw RMS distributions" << endl;
		TString Title = "RMS distributions per channel";
		TCanvas *c4 = new TCanvas("c4", Title, 700, 700);
		c4->Divide(3, 3);
		for (int i = 0; i < DOMINO_NCH; i++) {
			c4->cd(i + 2);
			hRMSdist = (TH1F *) hRMSList->At(i);
			hRMSFitdist = (TH1F *) hRMSFitList->At(i);
			hRMSFitdist->SetLineColor(2);
			hRMSFitdist->DrawCopy();
			hRMSdist->DrawCopy("same");
		}


		TList *grDataCh0SubList = new TList();
		TGraphErrors *grDataCh0Sub;
		for(h = 0; h< DOMINO_NCELL; h++) {
			grDataCh0Sub = new TGraphErrors(DOMINO_NCELL);
			grDataCh0SubList->Add(grDataCh0Sub);
		}

		TGraphErrors *grDataSubCh0 = (TGraphErrors *) grDataSubList->At(6);
		for(h = 0; h < DOMINO_NCH; h++) {
			grDataSub = (TGraphErrors *) grDataSubList->At(h);
			grDataCh0Sub = (TGraphErrors *) grDataCh0SubList->At(h);
			for(ch = 0; ch < DOMINO_NCELL; ch++) {
				grDataSubCh0->GetPoint(ch, x1, y1);
				grDataSub->GetPoint(ch, x2, y2);
				grDataCh0Sub->SetPoint(ch, x1 , y2 - y1);
			}
		}

		TCanvas *cDataCH0Sub = new TCanvas("cDataCH0Sub","cDataCH0Sub", 1000,1000);
		cDataCH0Sub->Divide(1,8);
		for(h = 0; h < DOMINO_NCH; h++) {
			cDataCH0Sub->cd(h+1);
			grDataCh0Sub = (TGraphErrors *) grDataCh0SubList->At(h);
			grDataCh0Sub->GetYaxis()->SetLabelSize(0.12);
			grDataCh0Sub->GetXaxis()->SetLabelSize(0.12);
			grDataCh0Sub->Draw("APEL");
		}



		cout << "Draw Data - Pedestals Subtracted" << endl;
		TString Title = "Average Charge - Pedestal subtracted";
		TCanvas *csubdata = new TCanvas("csubdata", Title, 1000, 1000);
		csubdata->Divide(3,3);

		for(h = 0; h < DOMINO_NCH; h++) {
			csubdata->cd(h+1);
			TString title = "DataSub channel ";
			title += h;
			TH1F *hCellDataSub = new TH1F(title, title, 100, -20, 20);
			grDataSub = (TGraphErrors *) grDataSubList->At(h);
			for(ch = 0; ch < DOMINO_NCELL; ch++) {
				grDataSub->GetPoint(ch, x, y);
				hCellDataSub->Fill(y);
			}
			hCellDataSub->Fit("gaus", "Q");
			hCellDataSub->GetXaxis()->SetTitle("ADC Counts");
			hCellDataSub->GetFunction("gaus")->SetLineColor(4);
			hCellDataSub->DrawCopy();
		}

		cout << "breakpoint" << endl;
		TCanvas *csubdata2 = new TCanvas("csubdata2", "DataSub for every channel", 1000, 1000);
		TString title = "DataSub every channel ";
		TH1F *hCellChDataSubTot = new TH1F(title, title, 100, -20, 20);
		for(h = 0; h < DOMINO_NCH; h++) {
			grDataSub = (TGraphErrors *) grDataSubList->At(h);
			for(ch = 0; ch < DOMINO_NCELL; ch++) {
				grDataSub->GetPoint(ch, x, y);
				hCellChDataSubTot->Fill(y);
			}
			hCellChDataSubTot->Fit("gaus", "Q");
			hCellChDataSubTot->GetXaxis()->SetTitle("ADC Counts");
			hCellChDataSubTot->GetFunction("gaus")->SetLineColor(4);
			hCellChDataSubTot->Draw();
		}

		cout << "Draw Pedestals" << endl;
		TString Title = "Pedestals";
		TCanvas *c2 = new TCanvas("c2", Title, 1050, 780);
		c2->SetBorderMode(0);
		c2->SetBorderSize(0.);
		c2->Divide(1, 8);
		//    gStyle->SetCanvasBorderMode(0.);
		//    gStyle->SetCanvasBorderSize(0.);
		Double_t x, y;
		for (int h = 0; h < DOMINO_NCH; h++) {
			c2->cd(h + 1);
			grPed = ((TGraphErrors *) grPedList->At(h));
			grPed->SetMarkerStyle(20);
			grPed->SetMarkerSize(0.5);
			grPed->GetYaxis()->SetLabelSize(0.12);
			grPed->GetXaxis()->SetLabelSize(0.12);
			//        cout <<  " err:" << grPed->GetErrorY(102) << " " ;
			//        cout << x << "--" << y << endl;
			grPed->Draw("APE");
		}

		cout << "Draw Data - Average charge" << endl;
		TString Title = "Average_Charge";
		TCanvas *cdata = new TCanvas("cdata", Title, 1050, 780);
		cdata->Divide(1, 8);
		Double_t x, y;
		for (int h = 0; h < DOMINO_NCH; h++) {
			cdata->cd(h + 1);
			grData = ((TGraphErrors *) grDataList->At(h));
			grData->SetMarkerStyle(20);
			grData->SetMarkerSize(0.3);
			grData->GetYaxis()->SetLabelSize(0.12);
			grData->GetXaxis()->SetLabelSize(0.12);
			grData->GetPoint(10, x, y);
			//        cout << x << "-" << y << endl;
			grData->Draw("APE");
		}

		cout << "Draw Data - Pedestals Subtracted" << endl;
		TString Title = "Average Charge - Pedestal subtracted";
		TCanvas *csubdata = new TCanvas("csubdata", Title, 1200, 780);
		csubdata->Divide(1, 8);
		TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4);
		TH1D *resDist = new TH1D("resDist", "Residuals Signal", 100, -100., 100.);

		cout << "Draw Data - Pedestals Subtracted" << endl;
		TString Title = "Residuals";
		TCanvas *residuals = new TCanvas("residuals", Title, 1200, 780);
		resDist->DrawCopy();

	}

	fclose(fdata);

	hCellList->Delete();
	hCellSubList->Delete();
	hRMSList->Delete();
	hRMSFitList->Delete();
}
Пример #8
0
void ReadFissionYields()
{
  double E, yield, sum;
  long n, m, i, loc0, loc1, ZA, NWD, I, LE, NFP, ptr, ZAI, Z, A, yld, pta;
  char line[256], *eof;
  FILE *fp;

  /***************************************************************************/

  /***** Neutron-induced fission  ********************************************/

  if ((pta = (long)RDB[DATA_PTR_NFYDATA_FNAME_LIST]) > 0)
    {
      /* Print */

      fprintf(out, "Reading neutron-induced fission yields...\n");

      /* Loop over files */

      while ((long)RDB[pta] > 0)
	{      
	  /*******************************************************************/

	  /***** Independent yields ******************************************/

	  /* Test format */

	  WDB[DATA_DUMMY] = RDB[pta];
	  TestDOSFile(GetText(DATA_DUMMY));
	  
	  /* Open file for reading */
  
	  fp = OpenDataFile(pta, "NFY data");

	  /* Loop over endf file */
	      
	  do 
	    {
	      /* Loop until in comment section */
	      
	      do 
		eof = fgets(line, 82, fp);
	      while ((atoi(&line[71]) != 1451) && (eof != NULL));
	      
	      /* Check EOF */
	      
	      if (eof == NULL)
		break;
	      
	      /* Read ZA */
	      
	      ZA = (long)rint(ENDFColF(1, line));

	      /* Check that value is reasonable, if not, this is not */
	      /* a fission yield file. */

	      if (ZA < 89000)
		Error(0, "No fission yield data available in file \"%s\"", 
		      GetText(pta));
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "ZA", "", ZA, 89000, 120000);
	      
	      /* Read isomeric state number */

	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      I = ENDFColI(4, line);
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "I", "", I, 0, 1);
	      
	      /* Convert to ZAI (this is the parent, ZA and I are re-used */
	      /* in the next loop). */
	      
	      ZAI = 10*ZA + I;
	      
	      /* Skip line */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      
	      /* Read header size */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      NWD = ENDFColI(5, line);
	      
	      /* Skip header */
	      
	      fseek(fp, 81*(NWD + 1), SEEK_CUR);
	      
	      /* Skip remaining comment block */
	      
	      do
		ENDFNewLine(FUNCTION_NAME, line, fp);
	      while (atoi(&line[71]) == 1451);
	      
	      /* Loop until fission product yield data. */
	      
	      do 
		eof = fgets(line, 82, fp);
	      while ((atoi(&line[71]) != 8454) && (eof != NULL));
	      
	      /* Check EOF */
	      
	      if (eof == NULL)
		Die(FUNCTION_NAME, "Error reading fission yield file \"%s\"",
		    GetText(pta));
	      
	      /* Get number of incident energies */
	      
	      LE = ENDFColI(3, line);
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "LE", "", LE, 0, 4);
	      
	      /* Loop over energies */
	      
	      for (n = 0; n < LE; n++)
		{
		  /***********************************************************/
		  
		  /***** Store data ******************************************/
		  
		  /* Allocate memory for data */
		  
		  yld = ReallocMem(ACE_ARRAY, FISSION_YIELD_BLOCK_SIZE);
		  
		  /* Set null pointer to next */
		  
		  ACE[yld + FISSION_YIELD_PTR_NEXT] = NULLPTR;
		  
		  /* Check if previous exists (ei voi käyttää VALID_PTR) */
		  
		  if ((ptr = (long)RDB[DATA_PTR_ACE_NFY_DATA]) < 0)
		    {
		      /* First definition, set pointer */
		      
		      WDB[DATA_PTR_ACE_NFY_DATA] = (double)yld;
		    }
		  else
		    {
		      /* Find last block  (tohon ei VALID_PTR) */
		      
		      while ((long)ACE[ptr + FISSION_YIELD_PTR_NEXT] > 0)
			ptr = (long)ACE[ptr + FISSION_YIELD_PTR_NEXT];
		      
		      /* Set pointer to new */
		      
		      ACE[ptr + FISSION_YIELD_PTR_NEXT] = (double)yld;
		    }
		  
		  /* Put parent ZAI */
		  
		  ACE[yld + FISSION_YIELD_PARENT_ZAI] = (double)ZAI;
		  
		  /* Get energy */
		  
		  ENDFNewLine(FUNCTION_NAME, line, fp);
		  E = 1E-6*ENDFColF(1, line);
		  
		  /* Check value */
		  
		  CheckValue(FUNCTION_NAME, "E", "(independent)", E, 0.0, 20.0);
		  
		  /* Put value */
		  
		  ACE[yld + FISSION_YIELD_E] = E;
		  
		  /* Get number of fission products */
		  
		  NFP = ENDFColI(6, line);
		  
		  /* Check value */
		  
		  CheckValue(FUNCTION_NAME, "NFP", "", NFP, 700, 
			     MAX_FP_NUCLIDES);
	      
		  /* Additional check for upper limit */
		  
		  if (NFP > MAX_FP_NUCLIDES)
		    Die(FUNCTION_NAME, 
			"Number of FP nuclides exceeds maximum");

		  /* Put value */
		  
		  ACE[yld + FISSION_YIELD_NFP] = (double)NFP;
		  
		  /* Allocate memory for data */
		  
		  loc0 = ReallocMem(ACE_ARRAY, NFP + 1);
		  
		  /* Set pointer */
		  
		  ACE[yld + FISSION_YIELD_PTR_DISTR] = (double)loc0;
		  
		  /* Read first line */
		  
		  ENDFNewLine(FUNCTION_NAME, line, fp);
		  
		  /* Loop over data */
		  
		  i = 1;
		  sum = 0.0;
		  
		  for (m = 0; m < NFP; m++)
		    {
		      /* Read isotope ZA */
		      
		      ZA = (long)ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "ZA", "", ZA, 1001, 80000);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Separate Z and A (only needed for bug check) */
		      
		      Z = (long)((double)ZA/1000.0);
		      A = ZA - 1000*Z;
		      
		      /* Check values */
		      
		      CheckValue(FUNCTION_NAME, "Z", "", Z, 1, 80);
		      CheckValue(FUNCTION_NAME, "A", "", A, 1, 210);
		      
		      /* Read isomeric state */
		      
		      I = (long)ENDFColF(i++, line);
		  
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "I", "", I, 0, 2);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Read yield */
		      
		      yield = ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "yield", "",yield, 0.0, 1.0);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Skip uncertainty */
		      
		      i++;
		      
		      if ((i > 6) && (m < NFP - 1))
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Allocate memory */
		      
		      loc1 = ReallocMem(ACE_ARRAY, FY_BLOCK_SIZE);
		      
		      /* Put pointer */
		      
		      ACE[loc0++] = (double)loc1;
		      
		      /* Put values */
		      
		      ACE[loc1 + FY_TGT_ZAI] = (double)(10*ZA + I);
		      ACE[loc1 + FY_INDEPENDENT_FRAC] = yield;
		      
		      /* Add to sum */
		      
		      sum = sum + yield;
		    }
		  
		  /* Put null pointer */
		  
		  ACE[loc0] = NULLPTR;
		  
		  /* Check sum (may differ from 2 due to cut-off and ternary */
		  /* fission) */
		  
		  CheckValue(FUNCTION_NAME, "sum", "", sum, 1.5, 2.5);
		  
		  /* Set warning flag */
		  
		  if ((sum < 1.9999) || (sum > 2.01))
		    WDB[DATA_WARN_NFY_SUM] = RDB[DATA_WARN_NFY_SUM] + 1.0;
		}
	    }
	  while (1 != 2);
	  
	  /* Close file */
	  
	  fclose(fp);

	  /*******************************************************************/

	  /***** Cumulative yields *******************************************/

	  fp = OpenDataFile(pta, "NFY data");

	  /* Pointer to data (tässä oletetaan että noi independent yieldit on */
	  /* luettu ja cumulative yieldit on samassa järjestyksessä). */

	  yld = (long)RDB[DATA_PTR_ACE_NFY_DATA];

	  /* Loop over endf file */
	      
	  do 
	    {
	      /* Loop until in comment section */
	      
	      do 
		eof = fgets(line, 82, fp);
	      while ((atoi(&line[71]) != 1451) && (eof != NULL));
	      
	      /* Check EOF */
	      
	      if (eof == NULL)
		break;
	      
	      /* Read ZA */
	      
	      ZA = (long)rint(ENDFColF(1, line));
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "ZA", "", ZA, 89000, 120000);
	      
	      /* Read isomeric state number */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      I = ENDFColI(4, line);
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "I", "", I, 0, 1);
	      
	      /* Convert to ZAI (this is the parent, ZA and I are re-used */
	      /* in the next loop). */
	      
	      ZAI = 10*ZA + I;
	      
	      /* Skip line */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      
	      /* Read header size */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      NWD = ENDFColI(5, line);
	      
	      /* Skip header */
	      
	      fseek(fp, 81*(NWD + 1), SEEK_CUR);
	      
	      /* Skip remaining comment block */
	      
	      do
		ENDFNewLine(FUNCTION_NAME, line, fp);
	      while (atoi(&line[71]) == 1451);
	      
	      /* Loop until fission product yield data. */
	      
	      do 
		eof = fgets(line, 82, fp);
	      while ((atoi(&line[71]) != 8459) && (eof != NULL));
	      
	      /* Check EOF */
	      
	      if (eof == NULL)
		Die(FUNCTION_NAME, "Error reading fission yield file \"%s\"",
		    GetText(pta));
	      
	      /* Get number of incident energies */
	      
	      LE = ENDFColI(3, line);
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "LE", "", LE, 0, 4);
	      
	      /* Loop over energies */
	      
	      for (n = 0; n < LE; n++)
		{
		  /***********************************************************/
		  
		  /***** Store data ******************************************/
		  
		  /* Compare ZAI */
		  
		  if ((long)ACE[yld + FISSION_YIELD_PARENT_ZAI] != ZAI)
		    Die(FUNCTION_NAME, "Mismatch in parent ZAI");
		  
		  /* Get energy */
		  
		  ENDFNewLine(FUNCTION_NAME, line, fp);
		  E = 1E-6*ENDFColF(1, line);
		  
		  /* Compare energy */
		  
		  if (ACE[yld + FISSION_YIELD_E] != E)
		    Die(FUNCTION_NAME, "Mismatch in energy");
		  
		  /* Get number of fission products */
		  
		  NFP = ENDFColI(6, line);
		  
		  /* compare value */
		  
		  if ((long)ACE[yld + FISSION_YIELD_NFP] != NFP)
		    Die(FUNCTION_NAME, "Mismatch in NFP");
	      
		  /* Set pointer to data */
		  
		  loc0 = (long)ACE[yld + FISSION_YIELD_PTR_DISTR];
		  
		  /* Read first line */
		  
		  ENDFNewLine(FUNCTION_NAME, line, fp);
		  
		  /* Loop over data */
		  
		  i = 1;
		  sum = 0.0;
		  
		  for (m = 0; m < NFP; m++)
		    {
		      /* Read isotope ZA */
		      
		      ZA = (long)ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "ZA", "", ZA, 1001, 80000);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Read isomeric state */
		      
		      I = (long)ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "I", "", I, 0, 2);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Read yield */
		      
		      yield = ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "yield", "",yield, 0.0, 1.0);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Skip uncertainty */
		      
		      i++;
		      
		      if ((i > 6) && (m < NFP - 1))
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Get pointer */
		      
		      loc1 = (long)ACE[loc0++];
		      
		      /* Compare ZAI */
		      
		      if ((long)ACE[loc1 + FY_TGT_ZAI] != 10*ZA + I)
			Die(FUNCTION_NAME, "Mismatch in product ZAI");
		      
		      /* Compare yield (ENDF/B-VI.8 and -VII datassa pieniä */
		      /* ylityksiä) */
		      
		      if ((yield > 0.0) && 
			  (ACE[loc1 + FY_INDEPENDENT_FRAC]/yield- 1.0 > 1E-4))
			Warn(FUNCTION_NAME, 
			     "Independent yield exceeds cumulative (%ld %E %E)",
			     ZAI, yield, ACE[loc1 + FY_INDEPENDENT_FRAC]);
		      
		      /* Put yield */
		      
		      ACE[loc1 + FY_CUMULATIVE_FRAC] = yield;
		    }
		  
		  /* Next yield */
		  
		  yld = (long)ACE[yld + FISSION_YIELD_PTR_NEXT];
		}
	    }
	  while (1 != 2);

	  /* Close file */

	  fclose(fp);

	  /*******************************************************************/
	
	  /* Next file */

	  pta++;
	}

      /***********************************************************************/

      fprintf(out, "OK.\n\n");
    }

  /***************************************************************************/

  /***** Sponteneous fission  ************************************************/

  if ((pta = (long)RDB[DATA_PTR_SFYDATA_FNAME_LIST]) > 0)
    {
      /* Print */

      fprintf(out, "Reading spontaneous fission yields...\n");

      /* Loop over files */

      while ((long)RDB[pta] > 0)
	{      
	  /*******************************************************************/
	  
	  /***** Independent yields ******************************************/

	  /* Open file for reading */
  
	  fp = OpenDataFile(pta, "NFY data");

	  /* Loop over endf file */
	  
	  do 
	    {
	      /* Loop until in comment section */
	      
	      do 
		eof = fgets(line, 82, fp);
	      while ((atoi(&line[71]) != 1451) && (eof != NULL));
	      
	      /* Check EOF */
	      
	      if (eof == NULL)
		break;
	      
	      /* Read ZA */
	      
	      ZA = (long)rint(ENDFColF(1, line));

	      /* Check that value is reasonable, if not, this is not */
	      /* a fission yield file. */

	      if (ZA < 89000)
		Error(0, "No fission yield data available in file \"%s\"", 
		      GetText(pta));
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "ZA", "", ZA, 89000, 120000);
	      
	      /* Read isomeric state number */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      I = ENDFColI(4, line);
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "I", "", I, 0, 1);
	      
	      /* Convert to ZAI (this is the parent, ZA and I are re-used */
	      /* in the next loop). */
	      
	      ZAI = 10*ZA + I;
	      
	      /* Skip line */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      
	      /* Read header size */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      NWD = ENDFColI(5, line);
	      
	      /* Skip header */
	      
	      fseek(fp, 81*(NWD + 1), SEEK_CUR);
	      
	      /* Skip remaining comment block */
	      
	      do
		ENDFNewLine(FUNCTION_NAME, line, fp);
	      while (atoi(&line[71]) == 1451);
	      
	      /* Loop until fission product yield data. */
	      
	      do 
		eof = fgets(line, 82, fp);
	      while ((atoi(&line[71]) != 8454) && (eof != NULL));
	      
	      /* Check EOF */
	      
	      if (eof == NULL)
		Die(FUNCTION_NAME, "Error reading fission yield file \"%s\"",
		    GetText(pta));
	  
	      /* Get number of incident energies */
	      
	      LE = ENDFColI(3, line);
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "LE", "", LE, 1, 1);
	      
	      /* Loop over energies */
	      
	      for (n = 0; n < LE; n++)
		{
		  /***********************************************************/

		  /***** Store data ******************************************/
	      
		  /* Allocate memory for data */
		  
		  yld = ReallocMem(ACE_ARRAY, FISSION_YIELD_BLOCK_SIZE);
	      
		  /* Set null pointer to next */
		  
		  ACE[yld + FISSION_YIELD_PTR_NEXT] = NULLPTR;
		  
		  /* Check if previous exists (ei voi käyttää VALID_PTR) */
		  
		  if ((ptr = (long)RDB[DATA_PTR_ACE_SFY_DATA]) < 0)
		    {
		      /* First definition, set pointer */
		      
		      WDB[DATA_PTR_ACE_SFY_DATA] = (double)yld;
		    }
		  else
		    {
		      /* Find last block  (tohon ei VALID_PTR) */
		      
		      while ((long)ACE[ptr + FISSION_YIELD_PTR_NEXT] > 0)
			ptr = (long)ACE[ptr + FISSION_YIELD_PTR_NEXT];
		      
		      /* Set pointer to new */
		      
		      ACE[ptr + FISSION_YIELD_PTR_NEXT] = (double)yld;
		    }
		  
		  /* Put parent ZAI */
		  
		  ACE[yld + FISSION_YIELD_PARENT_ZAI] = (double)ZAI;
		  
		  /* Get energy */
		  
		  ENDFNewLine(FUNCTION_NAME, line, fp);
		  E = 1E-6*ENDFColF(1, line);
		  
		  /* Check value */
		  
		  CheckValue(FUNCTION_NAME, "E", "(independent)", E, 0.0, 20.0);
		  
		  /* Put value */
		  
		  ACE[yld + FISSION_YIELD_E] = E;
		  
		  /* Get number of fission products */
		  
		  NFP = ENDFColI(6, line);
		  
		  /* Check value */
		  
		  CheckValue(FUNCTION_NAME, "NFP", "", NFP, 700, 
			     MAX_FP_NUCLIDES);
	      
		  /* Additional check for upper limit */
		  
		  if (NFP > MAX_FP_NUCLIDES)
		    Die(FUNCTION_NAME, 
			"Number of FP nuclides exceeds maximum");

		  /* Put value */
		  
		  ACE[yld + FISSION_YIELD_NFP] = (double)NFP;
		  
		  /* Allocate memory for data */
		  
		  loc0 = ReallocMem(ACE_ARRAY, NFP + 1);
		  
		  /* Set pointer */
		  
		  ACE[yld + FISSION_YIELD_PTR_DISTR] = (double)loc0;
		  
		  /* Read first line */
		  
		  ENDFNewLine(FUNCTION_NAME, line, fp);
		  
		  /* Loop over data */
		  
		  i = 1;
		  sum = 0.0;
		  
		  for (m = 0; m < NFP; m++)
		    {
		      /* Read isotope ZA */
		      
		      ZA = (long)ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "ZA", "", ZA, 1001, 80000);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Separate Z and A (only needed for bug check) */
		      
		      Z = (long)((double)ZA/1000.0);
		      A = ZA - 1000*Z;
		      
		      /* Check values */
		      
		      if ((Z < 1) || (Z > 80))
			Die(FUNCTION_NAME, "Error in Z");

		      if ((A < 1) || (A > 210))
			Die(FUNCTION_NAME, "Error in A");
		      
		      /* Read isomeric state */
		      
		      I = (long)ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "I", "", I, 0, 2);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Read yield */
		      
		      yield = ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "yield", "",yield, 0.0, 1.0);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Skip uncertainty */
		      
		      i++;
		      
		      if ((i > 6) && (m < NFP - 1))
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Allocate memory */
		      
		      loc1 = ReallocMem(ACE_ARRAY, FY_BLOCK_SIZE);
		      
		      /* Put pointer */
		      
		      ACE[loc0++] = (double)loc1;
		      
		      /* Put values */
		      
		      ACE[loc1 + FY_TGT_ZAI] = (double)(10*ZA + I);
		      ACE[loc1 + FY_INDEPENDENT_FRAC] = yield;
		      
		      /* Add to sum */
		      
		      sum = sum + yield;
		    }
		  
		  /* Put null pointer */
		  
		  ACE[loc0] = NULLPTR;
		  
		  /* Check sum (may differ from 2 due to cut-off and ternary */
		  /* fission) */
		  
		  CheckValue(FUNCTION_NAME, "sum", "", sum, 1.5, 2.5);
		  
		  /* Set warning flag */
		  
		  if ((sum < 1.9999) || (sum > 2.01))
		    WDB[DATA_WARN_SFY_SUM] = RDB[DATA_WARN_SFY_SUM] + 1.0;
		}
	    }
	  while (1 != 2);
	  
	  /* Close file */
	  
	  fclose(fp);
	  
	  /*******************************************************************/

	  /***** Cumulative yields *******************************************/

	  fp = OpenDataFile(pta, "SFY data");

	  /* Pointer to data (tässä oletetaan että noi independent yieldit */
	  /* on luettu ja cumulative yieldit on samassa järjestyksessä). */

	  yld = (long)RDB[DATA_PTR_ACE_SFY_DATA];

	  /* Loop over endf file */
	  
	  do 
	    {
	      /* Loop until in comment section */
	      
	      do 
		eof = fgets(line, 82, fp);
	      while ((atoi(&line[71]) != 1451) && (eof != NULL));
	      
	      /* Check EOF */
	      
	      if (eof == NULL)
		break;
	      
	      /* Read ZA */
	      
	      ZA = (long)rint(ENDFColF(1, line));
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "ZA", "", ZA, 89000, 120000);
	      
	      /* Read isomeric state number */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      I = ENDFColI(4, line);
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "I", "", I, 0, 1);
	      
	      /* Convert to ZAI (this is the parent, ZA and I are re-used */
	      /* in the next loop). */
	      
	      ZAI = 10*ZA + I;
	      
	      /* Skip line */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      
	      /* Read header size */
	      
	      ENDFNewLine(FUNCTION_NAME, line, fp);
	      NWD = ENDFColI(5, line);
	      
	      /* Skip header */
	      
	      fseek(fp, 81*(NWD + 1), SEEK_CUR);
	      
	      /* Skip remaining comment block */
	      
	      do
		ENDFNewLine(FUNCTION_NAME, line, fp);
	      while (atoi(&line[71]) == 1451);
	      
	      /* Loop until fission product yield data. */
	      
	      do 
		eof = fgets(line, 82, fp);
	      while ((atoi(&line[71]) != 8459) && (eof != NULL));
	      
	      /* Check EOF */
	      
	      if (eof == NULL)
		Die(FUNCTION_NAME, "Error reading fission yield file \"%s\"",
		    GetText(pta));
	      
	      /* Get number of incident energies */
	      
	      LE = ENDFColI(3, line);
	      
	      /* Check value */
	      
	      CheckValue(FUNCTION_NAME, "LE", "", LE, 1, 1);
	      
	      /* Loop over energies */
	      
	      for (n = 0; n < LE; n++)
		{
		  /***********************************************************/

		  /***** Store data ******************************************/

		  /* Compare ZAI */
		  
		  if ((long)ACE[yld + FISSION_YIELD_PARENT_ZAI] != ZAI)
		    Die(FUNCTION_NAME, "Mismatch in parent ZAI");
		  
		  /* Get energy */
		  
		  ENDFNewLine(FUNCTION_NAME, line, fp);
		  E = 1E-6*ENDFColF(1, line);
		  
		  /* Compare energy */
		  /*
		    if (ACE[yld + FISSION_YIELD_E] != E)
		    Die(FUNCTION_NAME, "Mismatch in energy");
		  */
		  /* Get number of fission products */
		  
		  NFP = ENDFColI(6, line);
		  
		  /* compare value */
		  
		  if ((long)ACE[yld + FISSION_YIELD_NFP] != NFP)
		    Die(FUNCTION_NAME, "Mismatch in NFP");
		  
		  /* Set pointer to data */
		  
		  loc0 = (long)ACE[yld + FISSION_YIELD_PTR_DISTR];
		  
		  /* Read first line */
		  
		  ENDFNewLine(FUNCTION_NAME, line, fp);
		  
		  /* Loop over data */
		  
		  i = 1;
		  sum = 0.0;
		  
		  for (m = 0; m < NFP; m++)
		    {
		      /* Read isotope ZA */
		      
		      ZA = (long)ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "ZA", "", ZA, 1001, 80000);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Read isomeric state */
		      
		      I = (long)ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "I", "", I, 0, 2);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Read yield */
		      
		      yield = ENDFColF(i++, line);
		      
		      /* Check value */
		      
		      CheckValue(FUNCTION_NAME, "yield", "",yield, 0.0, 1.0);
		      
		      if (i > 6)
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Skip uncertainty */
		      
		      i++;
		      
		      if ((i > 6) && (m < NFP - 1))
			{
			  ENDFNewLine(FUNCTION_NAME, line, fp);
			  i = i - 6;
			}
		      
		      /* Get pointer */
		      
		      loc1 = (long)ACE[loc0++];
		      
		      /* Compare ZAI */
		      
		      if ((long)ACE[loc1 + FY_TGT_ZAI] != 10*ZA + I)
			Die(FUNCTION_NAME, "Mismatch in product ZAI");
		      
		      /* Compare yield (ENDF/B-VI.8 and -VII datassa pieniä */
		      /* ylityksiä) */
		      
		      if ((yield > 0.0) && 
			  (ACE[loc1 + FY_INDEPENDENT_FRAC]/yield- 1.0 > 2E-4))
			Warn(FUNCTION_NAME, 
			     "Independent yield exceeds cumulative (%ld %E %E)",
			     ZAI, yield, ACE[loc1 + FY_INDEPENDENT_FRAC]);
		  
		      /* Put yield */
		      
		      ACE[loc1 + FY_CUMULATIVE_FRAC] = yield;
		    }
		  
		  /* Next yield */
		  
		  yld = (long)ACE[yld + FISSION_YIELD_PTR_NEXT];
		}
	    }
	  while (1 != 2);
	  
	  /* Close file */
	  
	  fclose(fp);
	  
	  /*******************************************************************/

	  /* Next file */

	  pta++;
	}
      
      fprintf(out, "OK.\n\n");
    }

  /***************************************************************************/
}
//
//	Declaration:
//	bool CBinaryDataFile::ReadEvtHeader(const CString &strNameWithPath, CString *pstrErrorMsg)
//
//	Input:	strNameWithPath		filename with full path that is to be opened
//			
//	Output:	pstrErrorMsg	error, if any
//
//			mdVersionNumber		version number read from header
//			msStaNum			station number read from header
//			miYr				year read from header
//			miMon				month read from header
//			miDay				day read from header
//			mulTimestampOfFirstRecordInFile		julian time of first record in the file
//
//	Return:	true (header read) / false (some kind of error, see pstrErroMsg)
//	
//  date    /	author	revision
//  -----------------	--------
//	17-Oct-2002	SFK		Created from ReadBIDHeader in GrandDataFile.cpp in GRAND COM
//	21-Jun-2005 SFK		Pick up station number from first record rather than getting it
//						out of the header due to a problem in MIC 1.9.0.7
//////////////////////////////////////////////////////////////////
bool CBinaryDataFile::ReadEvtHeader(const CString &strNameWithPath, CString *pstrErrorMsg)
{
    int iHdrSize;
    char str[54];
	struct BinaryEventFileRec Rec;
	struct OpCode OpRec;
	fpos_t pos;
	CMyDateTime MyDate;

   /* ------------------------------------------------------------------
    *	Open the file
    * ----------------------------------------------------------------*/
	if (!OpenDataFile(strNameWithPath, pstrErrorMsg)) return(false);

	// generate an error message in case we get an error in any of the reads,
	// will clear at end of function if all okay
	if (pstrErrorMsg) {
		miErrorNum = iFILE_READ_ERR;
		pstrErrorMsg->Format("\nError: Unexpected error reading header for file %s", strNameWithPath);
	}
	
   /* ------------------------------------------------------------------
    *	Read the first 4 bytes to get the number of bytes in header.
    *	Based on the location of the number, determine whether the data
    *	file is from CDMPC or LANL GRAND Collect.  The CDMPC number
    *	must be decremented by 1.
    * ----------------------------------------------------------------*/
    if (fread(str, 4, 1, mpFile) != 1) return(false);
    str[4] = '\0';    
    iHdrSize = atoi(str);
    if (str[3] == ' ') iHdrSize = iHdrSize - 1; // this file formed by CDMPC
	if (iHdrSize <= 22) return(false);

   /* ------------------------------------------------------------------
    *	The next 5 bytes no longer contain useful information,	just
    *	skip by them.
    * ----------------------------------------------------------------*/
    if (fread(str, 5, 1, mpFile) != 1) return(false);
       
   /* ------------------------------------------------------------------
    *	Read past the version number in the next 5 bytes.
    * ----------------------------------------------------------------*/
    if (fread(str, 5, 1, mpFile) != 1) return(false);
	str[5] = '\0';
	mdVersionNumber = atof(str);

   /* ------------------------------------------------------------------
    *  Read station of logging node and put it in return variable.
    * ----------------------------------------------------------------*/
    if (fread(str, 3, 1, mpFile) != 1) return(false);
    str[3] = '\0';
    msStaNum = atoi(str);
//	msStaNum += 1000;

   /* ------------------------------------------------------------------
    *	Read year and put it in return variable.
    * ----------------------------------------------------------------*/
    if (fread(str, 3, 1, mpFile) != 1) return(false);
    str[3] = '\0';
    miYr = atoi(str);
	//3-aug-2005 hn Added a four digit year.
	if (miYr < 86)
	{
		miYr4 = miYr + 2000;
	}
	else
	{
		miYr4 = miYr + 1900;
	}


   /* ------------------------------------------------------------------
    *	Read month and put it in return variable.
    * ----------------------------------------------------------------*/
    if (fread(str, 3, 1, mpFile) != 1) return(false);
    str[3] = '\0';
    miMon = atoi(str);
	if ((miMon < 1) || (miMon >12)) return(false);

   /* ------------------------------------------------------------------
    *	Read day and put it in return variable.
    * ----------------------------------------------------------------*/
    if (fread(str, 3, 1, mpFile) != 1) return(false);
    str[3] = '\0';
    miDay = atoi(str);
	if ((miDay < 1) || (miDay >31)) return(false);

	/* ------------------------------------------------------------------
    *	Read past the expansion space in the header so the file pointer
    *	is positioned at the beginning of the first data point at exit.
    * ----------------------------------------------------------------*/
    if (fread(str, (iHdrSize - 22), 1, mpFile)!= 1) return(false);
    
   /* ------------------------------------------------------------------
    *	Save the position of the file pointer.
	*	Read the first record in the file to get the time of it.  Will
	*	read the first record as if it is a binary record since we are
	*	only interested in the julian time in the record and that is in
	*	the same position in all types of records in an .evt/.bny file.
    *	Restore file pointer to just at the first record.
    * ----------------------------------------------------------------*/
	if(fgetpos(mpFile, &pos ) != 0) return(false);
	// 01-Sep-2005 SFK Fixed for reading old files that might have other types
	//					of records interspersed with binary records.
	bool bFoundBinaryRecord = false;
	do {
		if (fread(&OpRec, sizeof(struct OpCode), 1, mpFile) == 0) return(false);
		if ((OpRec.RecTypeA == '3') && (OpRec.RecTypeB == '2')) {
			if (fread(&Rec, sizeof(struct BinaryEventFileRec), 1, mpFile) == 0) return(false);
			msStaNum = Rec.usNode;		// 21-Jun-2005 SFK  Pick up station number from first record
			mdTimestampOfFirstRecordInFile = MyDate.MyTimestampToDATETimestamp((double)Rec.uiTime);
			if(fsetpos(mpFile, &pos ) != 0) return(false);
			bFoundBinaryRecord = true;
		}
		else {	// was not a binary record -- skip past the record
			fpos_t FilePosition;
			fgetpos(mpFile, &FilePosition);
			FilePosition += OpRec.sRecSize - 2;	// subtract the opcode bytes that you've already read
			fsetpos(mpFile, &FilePosition);
		}
	} while (!bFoundBinaryRecord);
               
	if (pstrErrorMsg) pstrErrorMsg->Empty();
	miErrorNum = 0;	// no error
    return(true);

}
Пример #10
0
////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Name	 : ReadBinHeader
//
//	Description:
//  Read header from binary raw data file (.BIN).  Bin files were created for use
//	with an early version of Media Tracker.  Defintion of header file
//	proposed in email from Pelowitz defines this format for the header structure:
//		struct TRGAcquireHeader	{	// 73 characters
//			char SizeOfHeader[4];
//			char unused1[5];
//			char Version[5];
//			char StationId[3];//node number
//			char Year[3];
//			char Month[3];
//			char Day[3];
//			char Year4[4];
//			char unused2[43];
//		};
//
//	Declaration:
//	int CBinaryDataFile::ReadBinHeader(char *szFilename, short *psSta,int *piYr, int *piMon, int *piDay, FILE **pHandle, double *pdVer, unsigned long *pulFirstRecordTime)
//
//	Input:	
//			strNameWithPath		filename with full path that is to be opened
//			
//	Output:	pstrErrorMsg	error, if any
//
//			mdVersionNumber		version number read from header
//			msStaNum			station number read from header
//			miYr				year read from header
//			miMon				month read from header
//			miDay				day read from header
//			mdTimestampOfFirstRecordInFile	time of first record in the file in DATE
//
//	Return:	true (header read) / false (some kind of error, see pstrErroMsg)
//	
//  date    /	author	revision
//  -----------------	--------
//	17-Oct-2002	SFK		Created from ReadBIDHeader in GrandDataFile.cpp in GRAND COM
////////////////////////////////////////////////////////////////////////////////////////////////
bool CBinaryDataFile::ReadBinHeader(const CString &strNameWithPath, CString *pstrErrorMsg)
{

    int iHdrSize;
    char str[54];
	fpos_t pos;
	struct TRGAcquireRecord BinaryRawPt;
	CMyDateTime MyDate;

	//	Open the file
	if (!OpenDataFile(strNameWithPath, pstrErrorMsg)) return(false);

	// generate an error message in case we get an error in any of the reads,
	// will clear at end of function if all okay
	if (pstrErrorMsg) {
		miErrorNum = iFILE_READ_ERR;
		pstrErrorMsg->Format("\nError: Unexpected error reading header for file %s", strNameWithPath);
	}
	
	//	Read the first 4 bytes to get the number of bytes in header.
    if (fread(str, 4, 1, mpFile) != 1) return(false);
    str[4] = '\0';    
    iHdrSize = atoi(str);
	if (iHdrSize <= 22) return(false);

    //	The next 5 bytes no longer contain useful information,	just
    //	skip by them.
    if (fread(str, 5, 1, mpFile) != 1) return(false);
       
    //	Read past the version number in the next 5 bytes.
    if (fread(str, 5, 1, mpFile) != 1) return(false);
	str[5] = '\0';
	mdVersionNumber = atof(str);

    //  Read station.
    if (fread(str, 3, 1, mpFile) != 1) return(false);
    str[3] = '\0';
    msStaNum = atoi(str);

    //	Read year.
    if (fread(str, 3, 1, mpFile) != 1) return(false);
    str[3] = '\0';
    miYr = atoi(str);

    //	Read month.
    if (fread(str, 3, 1, mpFile) != 1) return(false);
    str[3] = '\0';
    miMon = atoi(str);
	if ((miMon < 1) || (miMon >12)) return(false);

    //	Read day and put it in return variable.
    if (fread(str, 3, 1, mpFile) != 1) return(false);
    str[3] = '\0';
    miDay = atoi(str);
	if ((miDay < 1) || (miDay >31)) return(false);

    //	Read 4 digit year.
    if (fread(str, 4, 1, mpFile) != 1) return(false);
    str[4] = '\0';
    miYr4 = atoi(str);

    //	Read past the expansion space in the header so the file pointer
    //	is positioned at the beginning of the first data point at exit.
    if (fread(str, (iHdrSize - 26), 1, mpFile)!= 1) return(false);
    
    //	Save the position of the file pointer.
	//	Read the first record in the file to get the time of it.
    //	Restore file pointer to be positioned at the first record.
	if(fgetpos(mpFile, &pos ) != 0) return(false);
	if (fread(&BinaryRawPt, sizeof(struct TRGAcquireRecord), 1, mpFile) == 0) return(false);
	mdTimestampOfFirstRecordInFile = MyDate.MyTimestampToDATETimestamp((double)BinaryRawPt.uiJulianSeconds);
	if(fsetpos(mpFile, &pos ) != 0) return(false);
                    
    if (pstrErrorMsg) pstrErrorMsg->Empty();
	miErrorNum = 0;	// no error
    return(true);
}
Пример #11
0
bool        _HYConsoleWindow::_ProcessMenuSelection (long msel)
{
    switch (msel) {
    case HY_WINDOW_MENU_ID_FILE+1:
        SaveConsole ();
        return true;

    case 14:
        _DoPrint ();
        return true;

    case 16:
        ((_HYTextBox*)GetObject(0))->_DoUndo(true);
        return true;

    case 17:
        ((_HYTextBox*)GetObject(0))->_DoCut(true);
        return true;

    case 18:
        ((_HYTextBox*)GetObject(0))->_DoCopy(true);
        return true;

    case HY_WINDOW_MENU_ID_EDIT+5:
        ((_HYTextBox*)GetObject(0))->_DoSelectAll(true);
        return true;

    case 21:
        SetStatusLine ("Canceling");
        terminateExecution = true;
        return true;

    case 22: {
        GtkWidget * suspendItem = gtk_item_factory_get_widget_by_action(menu_items,22);
        if (!isSuspended) {
            isSuspended = true;
            SetStatusLine (empty,empty,empty,-1,HY_SL_SUSPEND);
            gtk_label_set_text (GTK_LABEL (gtk_bin_get_child(GTK_BIN(suspendItem))), "Resume");
            updateTimer = false;
            while (isSuspended) {
                gtk_main_iteration_do(true);
            }
        } else {
            isSuspended = false;
            SetStatusLine (empty,empty,empty,-1,HY_SL_RESUME);
            gtk_label_set_text (GTK_LABEL (gtk_bin_get_child(GTK_BIN(suspendItem))), "Suspend execution");
            timerStart += clock()-lastTimer;
            updateTimer = true;
        }
        return true;
    }
    case 23:
        ShowMessagesLog();
        return true;

    case 24:
        RunStandardAnalyses();
        return true;

    case 25:
        displayAbout(false);
        return true;

    case HY_WINDOW_MENU_ID_EDIT+4:
        ((_HYTextBox*)GetObject(0))->_DoClear (true,true);
        return true;

    case 27:
        HandlePreferences (globalPreferencesList,"HYPHY Preferences");
        return true;

    case 29:
        //WinExec ("hh HYPHY HELP.chm",SW_SHOWNORMAL);
        return true;

    case 30:
        if (OpenBatchFile (false)) {
            ExecuteBatchFile();
            PopFilePath();
        }
        return true;

    case 31:
        ((_HYTextBox*)GetObject(0))->_DoRedo(true);
        return true;

    case 15:
        postWindowCloseEvent (GetID());
        gtk_main_quit ();
        return true;

    case 60: // expression calculator
        if (calculatorMode) {
            _HYTextBox         *ib = (_HYTextBox*)hyphyConsoleWindow->GetObject(1);
            ib->SetText ("exit");
            hyphyConsoleWindow->ProcessEvent (generateTextEditChangeEvent(ib->GetID(),2));
            calculatorMode         = false;
            //ib->SetText (empty);
        } else {
            calculatorMode = true;
            while(calculatorMode&&ExpressionCalculator()) {}
            calculatorMode = false;
        }
        return true;

    case 61: { // execute selection
        ExecuteSelection();
        return true;
    }

    case 70: // New Tree
        NewTreeWindow(-1);
        return true;

    case 71: // New Model
        NewModel(nil);
        return true;

    case 72: // New Chart
        NewChartWindow();
        return true;

    case 73: // New Genetic Code
        NewGeneticCodeTable(0);
        return true;

    case 74: // New Database
        NewDatabaseFile(0);
        return true;

    case 80: // Open Batch File
        if (OpenBatchFile()) {
            ExecuteBatchFile ();
        }
        return true;

    case 81: // Open Data File
        OpenDataFile();
        return true;

    case 82: // Open Tree
        OpenTreeFile();
        return true;

    case 83: // Open Text
        OpenTextFile();
        return true;

    case 84: // Open Table
        OpenTable ();
        return true;

    case 85: // Open SQLite database
        OpenDatabaseFile (nil);
        return true;

    case HY_WINDOW_MENU_ID_FILE-2:
        ShowObjectInspector ();
        return true;

    default: {
        msel -= 1000;
        if (msel<availablePostProcessors.lLength) {
            ExecuteAPostProcessor (*(_String*)(*(_List*)availablePostProcessors(msel))(1));
            return 0;
        }

        msel-=1000;
        if (msel<(long)recentPaths.lLength) {
            if (msel == -1) {
                for (long mi=0; mi<recentFiles.lLength; mi++) {
                    GtkWidget * recFile = gtk_item_factory_get_widget_by_action(hyphyConsoleWindow->menu_items,2000+mi);
                    if (recFile) {
                        gtk_item_factory_delete_item(hyphyConsoleWindow->menu_items,gtk_item_factory_path_from_widget(recFile));
                    }
                }
                recentPaths.Clear();
                recentFiles.Clear();
            } else {
                if (argFileName) {
                    *argFileName = *(_String*)recentPaths(msel);
                } else {
                    argFileName = new _String (*(_String*)recentPaths(msel));
                }
                if (OpenBatchFile(false)) {
                    ExecuteBatchFile ();
                }
            }
            return true;
        }
        return true;
    }
    }

    return _HYTWindow::_ProcessMenuSelection(msel);
}
Пример #12
0
///////////////////////////////////////////////////////////////////////////
//	Name:	ReadHeader
//
//	Description:
//	Read header from GRAND raw data file (.BID).  See GRAND Collect Users 
//	Manual or MIC Users Manual for detailed definition of header format.
//
//	Declaration:
//	bool CGrandDataFile::ReadHeader(const CString &strNameWithPath, CString *pstrErrorMsg)
//
//	Input:	
//			strNameWithPath		filename with full path that is to be opened
//			
//	Output:	pstrErrorMsg	error, if any
//
//			mdVersionNumber		version number read from header
//			msStaNum			station number read from header
//			miYr				year read from header
//			miMon				month read from header
//			miDay				day read from header
//			mdTimestampOfFirstRecordInFile	time of first record in the file in DATE
//
//			
//			
//
//	Return:	true (header read) / false (some kind of error, see pstrErroMsg)
//	
//  date    /	author	revision
//  -----------------	--------
//	10-Dec-2001	SFK		Created from ReadBIDHeader in DbImport.cpp
//////////////////////////////////////////////////////////////////
bool CGrandDataFile::ReadHeader(const CString &strNameWithPath, CString *pstrErrorMsg) // Joe start here, identify by suffix, then branch at end of header read using code in RAD V6 side as guide, then move on to data read and trasnlation
{
    int iHdrSize;
    char str[54];
	struct GRAND_DATA_PT GrandPt;
	fpos_t pos = fpos_t(m_lFileOffset);
	
	miErrorNum = 0;		// 13-Jan-2005 Added setting error num to 0.

   /* ------------------------------------------------------------------
    *	Open the file
    * ----------------------------------------------------------------*/
	if (!OpenDataFile(strNameWithPath, pstrErrorMsg)) 
		return(false);

	// generate an error message in case we get an error in any of the reads,
	// will clear at end of function if all okay
	if (pstrErrorMsg && !(pstrErrorMsg->IsEmpty())) 
	{
		miErrorNum = iFILE_READ_ERR;
		pstrErrorMsg->Format("\nError: Unexpected error during read of %s", strNameWithPath);
	}
	
	if (strNameWithPath.Right(4).CompareNoCase(".BI0") == 0)
		BI0 = true;
   /* ------------------------------------------------------------------
    *	Read the first 4 bytes to get the number of bytes in header.
    *	Based on the location of the number, determine whether the data
    *	file is from CDMPC or LANL GRAND Collect.  The CDMPC number
    *	must be decremented by 1.
    * ----------------------------------------------------------------*/

	//skip over the SnF header if there is one
	int itemp = fsetpos(mpFile, &pos); //SCR00227

    if (fread(str, 4, 1, mpFile) != 1) return(false);
	m_lUsableBytesReadIn += 4; //SCR00227

    str[4] = '\0';    
    iHdrSize = atoi(str);
    if (str[3] == ' ') iHdrSize = iHdrSize - 1; // this file formed by CDMPC
	if (iHdrSize <= 22) return(false);
   /* ------------------------------------------------------------------
    *	The next 5 bytes no longer contain useful information,	just
    *	skip by them.
    * ----------------------------------------------------------------*/
    if (fread(str, 5, 1, mpFile) != 1) return(false);
	m_lUsableBytesReadIn += 5; //SCR00227
       
   /* ------------------------------------------------------------------
    *	Read past the version number in the next 5 bytes.
    * ----------------------------------------------------------------*/
    if (fread(str, 5, 1, mpFile) != 1) return(false);
	m_lUsableBytesReadIn += 5; //SCR00227
	str[5] = '\0';
	mdVersionNumber = atof(str);

   /* ------------------------------------------------------------------
    *  Read station number
    * ----------------------------------------------------------------*/
    if (fread(str, 3, 1, mpFile) != 1) return(false);
	m_lUsableBytesReadIn += 3; //SCR00227
    str[3] = '\0';
    msStaNum = atoi(str);

   /* ------------------------------------------------------------------
    *	Read year
    * ----------------------------------------------------------------*/
    if (fread(str, 3, 1, mpFile) != 1) return(false);
	m_lUsableBytesReadIn += 3; //SCR00227
    str[3] = '\0';
    miYr = atoi(str);
	//3-aug-2005 hn Added a four digit year.
	if (miYr < 86)
	{
		miYr4 = miYr + 2000;
	}
	else
	{
		miYr4 = miYr + 1900;
	}

   /* ------------------------------------------------------------------
    *	Read month
    * ----------------------------------------------------------------*/
    if (fread(str, 3, 1, mpFile) != 1) 
		return(false);

	m_lUsableBytesReadIn += 3; //SCR00227
    str[3] = '\0';
    miMon = atoi(str);

	if ((miMon < 1) || (miMon >12)) 
		return(false);

   /* ------------------------------------------------------------------
    *	Read day.
    * ----------------------------------------------------------------*/
    if (fread(str, 3, 1, mpFile) != 1) 
		return(false);

	m_lUsableBytesReadIn += 3; //SCR00227
    str[3] = '\0';
    miDay = atoi(str);

	if ((miDay < 1) || (miDay >31)) 
		return(false);

   /* ------------------------------------------------------------------
    *	Read past the expansion space in the header so the file pointer
    *	is positioned at the beginning of the first data point at exit.
    * ----------------------------------------------------------------*/
    if (fread(str, (iHdrSize - 22), 1, mpFile)!= 1) 
		return(false);

	m_lUsableBytesReadIn += iHdrSize - 22; //SCR00227
    
   /* ------------------------------------------------------------------
    *	Save the position of the file pointer.
	*	Read the first record in the file to get the time of it.
    *	Restore file pointer to just at the first record.
    * ----------------------------------------------------------------*/
	if(fgetpos(mpFile, &pos ) != 0) 
		return(false);

	if (BI0)   // todo: jfl skip first 5 a la Bob?
	{
		struct DMGGRAND_DATA_PT_HDR DGrandPt;
		// read 4 bytes at a time looking for the first data record (0xffffffff)
		unsigned int tag;
		while (fread(&tag, sizeof(unsigned int),1, mpFile))
		{
			if (tag ^ 0xFFFFFFFF) // ^ anything but the data mask shown here
				OutputDebugString("skipping non-data record\r\n");
			else
				break;
		}
		if (fread(&DGrandPt, sizeof(struct DMGGRAND_DATA_PT_HDR), 1, mpFile) == 0) return(false);
		DGrandPt.ulJulianTime = _byteswap_ulong(DGrandPt.ulJulianTime);
		DGrandPt.usJSCS = _byteswap_ushort(DGrandPt.usJSCS);
		if (checksum_ulong(&(DGrandPt.ulJulianTime)) != DGrandPt.usJSCS)
			OutputDebugString("skip this record\r\n"); // todo: jfl return false?
		mdTimestampOfFirstRecordInFile = m_MyDateTime.MyTimestampToDATETimestamp((double)DGrandPt.ulJulianTime);
	}
	else
	{
		if (fread(&GrandPt, sizeof(struct GRAND_DATA_PT), 1, mpFile) == 0) 
			return(false);
		mdTimestampOfFirstRecordInFile = m_MyDateTime.MyTimestampToDATETimestamp((double)GrandPt.ulJulianTime);
	}
	if(fsetpos(mpFile, &pos ) != 0) 
		return(false);
               
	if (pstrErrorMsg) // wtf?
		pstrErrorMsg->Empty();

	miErrorNum = 0;	// no error
    return(true);
}
Пример #13
0
void ReadACEFile(long nuc)
{
  long ace, ptr, rea, n, sz, NXS[16], JXS[32], NES, L0, L, NTR, nr, mt, nc, I0;
  double *XSS, awr, Emax, T;
  char HZ1[MAX_STR], HZ2[MAX_STR], dummy[MAX_STR], name[MAX_STR];
  char file[MAX_STR], date[MAX_STR];
  FILE *fp;

  /* Check nuclide type */

  if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_DECAY)
    if (!((long)RDB[nuc + NUCLIDE_TYPE_FLAGS] & NUCLIDE_FLAG_TRANSMU_DATA))
      Die(FUNCTION_NAME, "Decay data");

  /* Get pointer to ACE data */

  ace = (long)RDB[nuc + NUCLIDE_PTR_ACE];
  CheckPointer(FUNCTION_NAME, "ace", ACE_ARRAY, ace);

  /* Put name */
  
  WDB[DATA_DUMMY] = ACE[ace + ACE_PTR_NAME];
  strcpy(name, GetText(DATA_DUMMY));

  /* Get file name */

  WDB[DATA_DUMMY] = ACE[ace + ACE_PTR_FILE];
  strcpy(file, GetText(DATA_DUMMY));
  
  /* Test format */

  TestDOSFile(GetText(DATA_DUMMY));

  /* Open file for writing */
  
  fp = OpenDataFile(DATA_DUMMY, "ACE data file");

  /***************************************************************************/
  
  /***** Read data ***********************************************************/

  /* Reset HZ */
  
  *HZ1 = '\0';
  *HZ2 = '\0';

  /* Read ZAID and data */
  
  while (fscanf(fp, "%s", HZ1) != EOF)
    {
      /* Check for new format (assuming here that the character string  */
      /* is '2.0.0' -- this is something that may need to be checked in */
      /* the future). */

      if (!strcmp(HZ1, "2.0.0"))
	{
	  /* New format, read reminder of line */

	  if (fgets(dummy, 81, fp) == NULL)
	    Die(FUNCTION_NAME, "fgets error");
  
	  /* Get new HZ */

	  sscanf(dummy, "%s", HZ2);

	  /* Next line */
	  
	  if (fgets(dummy, 81, fp) == NULL)
	    Die(FUNCTION_NAME, "fgets error");

	  /* Reset number of comment lines */

	  nc = 0;

	  /* Get atomic weight ratio, temperature, date and number of */
	  /* comment lines (new ACE format). Only the last entry is   */
	  /* used here. */

	  sscanf(dummy, "%lf %lf %s %ld", &awr, &T, date, &nc);
	  CheckValue(FUNCTION_NAME, "nc", "", nc, 3, 10000);

	  /* Skip comment lines */
      
	  for (n = 0; n < nc - 2; n++)
	    if (fgets(dummy, 82, fp) == NULL)
	      Die(FUNCTION_NAME, "fgets error");

	  /* The next line is the first line of 'old-style' ACE, get ZAID */

	  if (fscanf(fp, "%s", HZ1) == EOF)
	    Die(FUNCTION_NAME, "fscanf error");
	}

      /* Get atomic weight ratio. Temperature is the next entry after */
      /* AWR, but it is not used. The value is taken from the directory */
      /* file. */
      
      if (fgets(dummy, 81, fp) == NULL)
	Die(FUNCTION_NAME, "fgets error");
      
      sscanf(dummy, "%lf", &awr);
      
      /* Skip comment line */
      
      if (fgets(dummy, 81, fp) == NULL)
	Die(FUNCTION_NAME, "fgets error");

      /* Preserve decay awr */

      if ((long)RDB[nuc + NUCLIDE_TYPE] != NUCLIDE_TYPE_DECAY)
	{	    
	  /* Put atomic weight ratio */

	  WDB[nuc + NUCLIDE_AWR] = awr;
	  
	  /* Use value read from directory file for atomic weight */
	  
	  WDB[nuc + NUCLIDE_AW] = ACE[ace + ACE_AW];
	}

      /* 16 IZ AW pairs */
      
      for (n = 0; n < 32; n++)
	if (fscanf(fp, "%s", dummy) == EOF)
	  Die(FUNCTION_NAME, "fscanf error");

      /* Read the NXS array */
      
      for (n = 0; n < 16; n++)
	if (fscanf(fp, "%ld", &NXS[n]) == EOF)
      	  Die(FUNCTION_NAME, "Error in NXS array (%s)", 
	      GetText(nuc + NUCLIDE_PTR_NAME));

      /* Get data size (NXS[0]) */
      
      if ((sz = NXS[0]) < 10)
	Die(FUNCTION_NAME, "Error in ACE file");
      
      /* Read the JXS array */
      
      for (n = 0; n < 32; n++)
	if (fscanf(fp, "%ld", &JXS[n]) == EOF)
      	  Die(FUNCTION_NAME, "Error in JXS array (%s)",
	      GetText(nuc + NUCLIDE_PTR_NAME));

      /* Compare ZAIDs */
      
      if ((!strcmp(HZ1, name)) || (!strcmp(HZ2, name)))
	{
	  /* Allocate memory for NXS array */

	  ptr = ReallocMem(ACE_ARRAY, 16);
	  ACE[ace + ACE_PTR_NXS] = (double)ptr;	  

	  /* Copy data */

	  for (n = 0; n < 16; n++)
	    ACE[ptr++] = (double)NXS[n];

	  /* Allocate memory for JXS array */

	  ptr = ReallocMem(ACE_ARRAY, 32);
	  ACE[ace + ACE_PTR_JXS] = (double)ptr;	  

	  /* Copy data */

	  for (n = 0; n < 32; n++)
	    ACE[ptr++] = (double)JXS[n];

	  /* Allocate memory for XSS array */
	  
	  ptr = ReallocMem(ACE_ARRAY, sz);
	  
	  /* Set pointer */
	  
	  ACE[ace + ACE_PTR_XSS] = (double)ptr;

	  /* Read data */
	  
	  for (n = 0; n < sz; n++)  
	    if (fscanf(fp, "%lf", &ACE[ptr + n]) == EOF)
	      {
		/* Print warning */

		Warn(FUNCTION_NAME, "Error in XSS array (%s)", 
		     GetText(nuc + NUCLIDE_PTR_NAME));

		/* Break */

		break;
	      }

	  /* Break loop */

	  break;
	}
      
      /* Seek to next header (muutettu 25.6.2013, katso Martin Magillin */
      /* meili 13.6.2014)) */

      /*
      fseek(fp, 81*sz/4 + 1, SEEK_CUR);
      */

      fseek(fp, 81*sz/4, SEEK_CUR);
      if (fgets(dummy, 81, fp) == NULL)
	Die(FUNCTION_NAME, "fgets error");
    }
  
  /* Check that data was found */
  
  if ((strcmp(HZ1, name)) && (strcmp(HZ2, name)))
    Die(FUNCTION_NAME, "Unable to find isotope %s in file %s", name, file);
  
  /* Pointer to XSS array */
      
  ptr = (long)ACE[ace + ACE_PTR_XSS];
  XSS = &ACE[ptr];
  
  /* Set ures energy boundaries */

  if ((L = JXS[22] - 1) > 0)
    {
      /* Get number of energy points */

      NES = (long)XSS[L];

      /* Set minimum and maximum energies */
      
      WDB[nuc + NUCLIDE_URES_EMIN] = XSS[L + 6];
      WDB[nuc + NUCLIDE_URES_EMAX] = XSS[L + 6 + NES - 1];
    }
  else
    {
      /* Reset boundaries */
      
      WDB[nuc + NUCLIDE_URES_EMIN] = INFTY;
      WDB[nuc + NUCLIDE_URES_EMAX] = -INFTY;
    }  

  /**************************************************************************/

  /***** Add reaction channels for transport data ***************************/
  
  /* Check type */

  if (((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_TRANSPORT) ||
      ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_DBRC))
    {
      /**********************************************************************/

      /***** Transport nuclide **********************************************/

      /* Number of energy points */
      
      NES = NXS[2];

      /* Put pointer to nuclide energy grid and nuber of points */

      WDB[nuc + NUCLIDE_PTR_EGRID] = (double)(JXS[0] - 1);
      WDB[nuc + NUCLIDE_EGRID_NE] = NES;
     
      /* Get number of reactions (minus elastic scattering). Include */
      /* only elastic scattering for DBRC nuclides. */

      if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_DBRC)
	NTR = 0;
      else
	NTR = NXS[3]; 
      
      /* Compare minimum and maximum value to XS limits */

      if (XSS[JXS[0] - 1] < RDB[DATA_NEUTRON_XS_EMIN])
	WDB[DATA_NEUTRON_XS_EMIN] = XSS[JXS[0] - 1];
      
      if (XSS[JXS[0] + NES - 2] > RDB[DATA_NEUTRON_XS_EMAX])
	WDB[DATA_NEUTRON_XS_EMAX] = XSS[JXS[0] + NES - 2];

      /* Number of delayed neutron precursor groups */

      WDB[nuc + NUCLIDE_ACE_PREC_GROUPS] = NXS[7];
     
      /* Add elastic scattering */
      
      rea = NewItem(nuc + NUCLIDE_PTR_REA, REACTION_BLOCK_SIZE);

      /* Put nuclide pointer */

      WDB[rea + REACTION_PTR_NUCLIDE] = (double)nuc;

      /* Reaction index (used for energy distributions) */

      WDB[rea + REACTION_NR] = -1.0;

      /* Put type and MT */
      
      WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_PARTIAL;
      WDB[rea + REACTION_MT] = 2.0;

      /* Put awr */

      WDB[rea + REACTION_AWR] = RDB[nuc + NUCLIDE_AWR];

      /* Set minimum and maximum energy */

      WDB[rea + REACTION_EMIN] = XSS[JXS[0] - 1];
      WDB[rea + REACTION_EMAX] = XSS[JXS[0] + NES - 2];

      WDB[nuc + NUCLIDE_EMIN] = XSS[JXS[0] - 1];
      WDB[nuc + NUCLIDE_EMAX] = XSS[JXS[0] + NES - 2];

      /* Store number of energy points, pointer to grid and */
      /* index to first point */

      WDB[rea + REACTION_PTR_EGRID] = (double)(JXS[0] - 1);
      WDB[rea + REACTION_XS_NE] = (double)NES;
      WDB[rea + REACTION_XS_I0] = 0.0;

      /* Store pointer to XS data */
	      
      WDB[rea + REACTION_PTR_XS] = (double)(JXS[0] - 1 + 3*NES);

      /* Set ures energy boundaries */

      WDB[rea + REACTION_URES_EMIN] = RDB[nuc + NUCLIDE_URES_EMIN];
      WDB[rea + REACTION_URES_EMAX] = RDB[nuc + NUCLIDE_URES_EMIN];
	
      /* Set Q-value */

      WDB[rea + REACTION_Q] = 0.0;

      /* Multiplication and frame of reference */
      
      WDB[rea + REACTION_TY] = -1.0;
      WDB[rea + REACTION_WGT_F] = 1.0;

      /* Set branching fraction to 1.0 */

      WDB[rea + REACTION_BR] = 1.0;

      /* Set interpolation mode */

      WDB[rea + REACTION_ITP] = 0.0;

      /* Pointer to angular distribution (Tables F-11 and F-12) */

      if ((L = (long)XSS[JXS[7] - 1]) > 0)
	WDB[rea + REACTION_PTR_ANG] = (double)(L - 1 + JXS[8]);
      else
	WDB[rea + REACTION_PTR_ANG] = NULLPTR;

      /* Include heat production */
      
      if ((long)RDB[DATA_INCLUDE_HEAT_PROD_XS] == YES)
	{
	  rea = NewItem(nuc + NUCLIDE_PTR_REA, REACTION_BLOCK_SIZE);
	  WDB[nuc + NUCLIDE_PTR_HEATPRODXS] = (double)rea;
	  
	  /* Put nuclide pointer */
	  
	  WDB[rea + REACTION_PTR_NUCLIDE] = (double)nuc;
	  
	  /* Put type and MT */
	  
	  WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;
	  WDB[rea + REACTION_MT] = 301.0;
	  
	  /* Put awr */
	  
	  WDB[rea + REACTION_AWR] = RDB[nuc + NUCLIDE_AWR];
	  
	  /* Set minimum and maximum energy */
	  
	  WDB[rea + REACTION_EMIN] = XSS[JXS[0] - 1];
	  WDB[rea + REACTION_EMAX] = XSS[JXS[0] + NES - 2];
	  
	  /* Store number of energy points, pointer to grid and */
	  /* index to first point */
	  
	  WDB[rea + REACTION_PTR_EGRID] = (double)(JXS[0] - 1);
	  WDB[rea + REACTION_XS_NE] = (double)NES;
	  WDB[rea + REACTION_XS_I0] = 0.0;
	  
	  /* Store pointer to XS data */
	  
	  WDB[rea + REACTION_PTR_XS] = (double)(JXS[0] - 1 + 4*NES);
	  
	  /* Set ures energy boundaries (mites nää?) */
	  
	  WDB[rea + REACTION_URES_EMIN] = RDB[nuc + NUCLIDE_URES_EMIN];
	  WDB[rea + REACTION_URES_EMAX] = RDB[nuc + NUCLIDE_URES_EMIN];
	  
	  /* Multiplication (not used but must be set to avoid error) */
	  
	  WDB[rea + REACTION_WGT_F] = 1.0;
	}
      
      /* Include photon production from total block */

      if (((long)RDB[DATA_INCLUDE_PHOT_PROD_XS] == YES)	&& (JXS[11] > 0))
	  {
	    /* Add photon production */

	    rea = NewItem(nuc + NUCLIDE_PTR_REA, REACTION_BLOCK_SIZE);
	    WDB[nuc + NUCLIDE_PTR_PHOTPRODXS] = (double)rea;
	    
	    /* Put nuclide pointer */
	    
	    WDB[rea + REACTION_PTR_NUCLIDE] = (double)nuc;
	    
	    /* Put type and MT */
	    
	    WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;
	    WDB[rea + REACTION_MT] = 202.0;
	    
	    /* Put awr */
	    
	    WDB[rea + REACTION_AWR] = RDB[nuc + NUCLIDE_AWR];
	    
	    /* Set minimum and maximum energy */
	    
	    WDB[rea + REACTION_EMIN] = XSS[JXS[0] - 1];
	    WDB[rea + REACTION_EMAX] = XSS[JXS[0] + NES - 2];
	    
	    /* Store number of energy points, pointer to grid and */
	    /* index to first point */
	    
	    WDB[rea + REACTION_PTR_EGRID] = (double)(JXS[0] - 1);
	    WDB[rea + REACTION_XS_NE] = (double)NES;
	    WDB[rea + REACTION_XS_I0] = 0.0;
	    
	    /* Store pointer to XS data */
	    
	    WDB[rea + REACTION_PTR_XS] = (double)(JXS[11] - 1);
	    
	    /* Set ures energy boundaries (mites nää?) */
	    
	    WDB[rea + REACTION_URES_EMIN] = INFTY;
	    WDB[rea + REACTION_URES_EMAX] = -INFTY;
	    
	    /* Multiplication (not used but must be set to avoid error) */
	    
	    WDB[rea + REACTION_WGT_F] = 1.0;
	  }
      
      /* Loop over reaction channels in SIG block*/
      
      for (nr = 0; nr < NTR; nr++)
	{
	  /* Get pointer to SIG-block (Table F-10, page F-17) */
	  
	  L = (long)XSS[JXS[5] - 1 + nr] + JXS[6] - 1;
	  
	  /* Get number of energy points */
	  
	  NES = (long)XSS[L];

	  /* Pointer to energy array */
	  
	  L0 = JXS[0] - 1 + NXS[2] - NES;

	  /* Tässä oli 22.8.2011 asti tarkistus > 2, mutta se jättää */
	  /* mt 37:n 94244 / endfb68 pois */	 

	  if (NES > 0)
	    {
	      /* Allocate memory */
	      
	      rea = NewItem(nuc + NUCLIDE_PTR_REA, REACTION_BLOCK_SIZE);
	      
	      /* Put nuclide pointer */

	      WDB[rea + REACTION_PTR_NUCLIDE] = (double)nuc;

	      /* Reaction index (used for energy distributions) */

	      WDB[rea + REACTION_NR] = (double)nr;

	      /* Get mt */
	      
	      mt = (long)XSS[JXS[2] + nr - 1];
	      WDB[rea + REACTION_MT] = (double)mt;

	      /* Check fissile */

	      if (((mt > 17) && (mt < 22)) || (mt == 38))
		{
		  /* Set flag */

		  SetOption(nuc + NUCLIDE_TYPE_FLAGS, NUCLIDE_FLAG_FISSILE);

		  /* Set default energy boundaries */

		  WDB[rea + REACTION_FISSY_IE0] = -INFTY;
		  WDB[rea + REACTION_FISSY_IE1] = 1E+6;
		  WDB[rea + REACTION_FISSY_IE2] = 1E+9;
		}

	      /* Store minimum and maximum energy */

	      WDB[rea + REACTION_EMIN] = XSS[L0];
	      WDB[rea + REACTION_EMAX] = XSS[L0 + NES - 1];

	      /* Store number of energy points, pointer to grid and */
	      /* index to first point */

	      WDB[rea + REACTION_PTR_EGRID] = (double)(JXS[0] - 1);
	      WDB[rea + REACTION_XS_NE] = (double)NES;
	      WDB[rea + REACTION_XS_I0] = (double)(NXS[2] - NES);

	      /* Store pointer to XS data */
	      
	      WDB[rea + REACTION_PTR_XS] = (double)(L + 1);

	      /* Set ures energy boundaries */

	      if ((mt == 102) || (mt == 18) || (mt == 19))
		{
		  /* Set ures energy boundaries */

		  WDB[rea + REACTION_URES_EMIN] = 
		    RDB[nuc + NUCLIDE_URES_EMIN];
		  WDB[rea + REACTION_URES_EMAX] = 
		    RDB[nuc + NUCLIDE_URES_EMIN];
		}
	      else
		{
		  /* Reset boundaries */
		  
		  WDB[rea + REACTION_URES_EMIN] = INFTY;
		  WDB[rea + REACTION_URES_EMAX] = -INFTY;
		}

	      /* Put awr */

	      WDB[rea + REACTION_AWR] = RDB[nuc + NUCLIDE_AWR];

	      /* Store Q-value */

	      WDB[rea + REACTION_Q] = XSS[JXS[3] - 1 + nr];

	      /* Multiplication and frame of reference */

	      WDB[rea + REACTION_TY] = XSS[JXS[4] - 1 + nr];

	      /* Check known error in ACE files */

	      if ((XSS[JXS[4] - 1 + nr] == 0.0) &&
		  (((mt > 17) && (mt < 22)) || (mt == 38)))
		{
		  /* Print warning */
		  
#ifdef DEBUG

		  Warn(FUNCTION_NAME, 
		       "Conflicting reaction type for fission (%s mt %ld)", 
		       GetText(nuc + NUCLIDE_PTR_NAME), mt);

#endif
		  /* Set ty for fission */

		  WDB[rea + REACTION_TY] = 19.0;
		}

	      /* Put weight multiplicator */

	      if((RDB[rea + REACTION_TY] == 0.0) || 
		 (RDB[rea + REACTION_TY] == 19.0) ||
		 (fabs(RDB[rea + REACTION_TY]) > 100.0))
		WDB[rea + REACTION_WGT_F] = 1.0;
	      else if (fabs(RDB[rea + REACTION_TY]) < 5)
		WDB[rea + REACTION_WGT_F] = fabs(RDB[rea + REACTION_TY]);
	      else
		Die(FUNCTION_NAME, "Invalid TYR value: %ld\n",
		    (long)RDB[rea + REACTION_TY]);

	      /* Override fission if switched off (18.7.2013 / 2.1.15) */

	      if (((long)RDB[DATA_NPHYS_SAMPLE_FISS] == NO) &&
		  ((long)RDB[rea + REACTION_TY] == 19.0))
		WDB[rea + REACTION_TY] = 0.0;

	      /* Set interpolation mode */

	      WDB[rea + REACTION_ITP] = 0.0;
	      
	      /* Set branching fraction to 1.0 */
	      
	      WDB[rea + REACTION_BR] = 1.0;
      
	      /* Pointer to angular distribution (NOTE: L is re-used) */

	      if ((L = (long)XSS[JXS[7] + nr]) > 0)
		WDB[rea + REACTION_PTR_ANG] = (double)(L - 1 + JXS[8]);
	      else
		WDB[rea + REACTION_PTR_ANG] = NULLPTR;

	      /* Check type */
	      
	      if (((mt > 10) && (mt < 100)) || ((mt > 101) && (mt < 200)) ||
		  ((mt > 599) && (mt < 851)) || ((mt > 874) && (mt < 892)))
		{
		  /* Partial reaction */
		  
		  WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_PARTIAL;
		}
	      else if (mt == 5)
		{
		  /* Combination of multiple inelastic channels */
		  /* (this used to be a problem) */

		  WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_PARTIAL;
		}
	      else
		{
		  /* Special */

		  WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;
		}
	    }
	}

      /* Get number of photon production reactions */

      if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_DBRC)
	NTR = 0;
      else
	NTR = NXS[5]; 

      /* Loop over reaction channels in SIGP block*/
      
      for (nr = 0; nr < NTR; nr++)
	{
	  /* Get pointer to SIGP-block (Table F-10, page F-17) */
	  
	  L = (long)XSS[JXS[13] - 1 + nr] + JXS[14] - 1;

	  /* Tää on ihan vaiheessa */

	  I0 = (long)XSS[L - 1];
	  NES = (long)XSS[L];
	}
    
      /***********************************************************************/
      
      /***** URES data *******************************************************/

      /* Check if ures probability table data is available (ures data */
      /* is now read for DBRC nuclides as well). */
      
      if ((L = JXS[22] - 1) > 0)
	{
	  /* Add to ures counter */

	  WDB[DATA_URES_AVAIL] = RDB[DATA_URES_AVAIL] + 1.0;

	  /* Set available flag */

	  SetOption(nuc + NUCLIDE_TYPE_FLAGS, NUCLIDE_FLAG_URES_AVAIL);

	  /* Check ures option */

	  if ((long)RDB[DATA_USE_URES] == NO)
	    {
	      /* Pointer to list */

	      if ((ptr = (long)RDB[DATA_URES_PTR_USE_LIST]) < VALID_PTR)
		L = -1;
	      else
		{
		  /* Loop over list and compare */

		  while ((long)RDB[ptr] > 0)
		    {
		      if (!strcmp(GetText(ptr),
				  GetText(nuc + NUCLIDE_PTR_NAME)))
			{
			  L = -1;
			  break;
			}
		      
		      ptr++;
		    }
		}
	    }
	  else if ((ptr = (long)RDB[DATA_URES_PTR_USE_LIST]) > VALID_PTR)
	    {
	      /* Loop over list and compare */
      
	      while ((long)RDB[ptr] > 0)
		{
		  if (!strcmp(GetText(ptr), GetText(nuc + NUCLIDE_PTR_NAME)))
		    break;
		  
		  ptr++;
		}
	      
	      if ((long)RDB[ptr] < 1)
		L = -1;
	    }
	}

      /* Check if data is available and used */

      if (L > 0)
	{
	  /* Set flag */

	  SetOption(nuc + NUCLIDE_TYPE_FLAGS, NUCLIDE_FLAG_URES_USED);

	  /* Add counter */

	  WDB[DATA_URES_USED] = RDB[DATA_URES_USED] + 1.0;
	}

      /**********************************************************************/
    }
  else if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_DOSIMETRY)
    {
      /**********************************************************************/

      /***** Dosimetry data *************************************************/

      /* Get number of reactions */
      
      NTR = NXS[3];

      /* Reset nuclide-wise minimum and maximum energy */

      WDB[nuc + NUCLIDE_EMIN] = INFTY;
      WDB[nuc + NUCLIDE_EMAX] = -INFTY;

      /* Loop over reaction channels */
      
      for (nr = 0; nr < NTR; nr++)
	{
	  /* Get pointer to SIGD-block (Table F-22, page F-35) */
	  
	  L0 = (long)XSS[JXS[5] - 1 + nr] + JXS[6] - 1;
	  
	  /* Get reaction MT (Table F-6, page F-15) */
	  
	  mt = (long)XSS[JXS[2] - 1 + nr]; 

	  /* Check number of interpolation regions */
	
	  if ((long)XSS[L0 - 1] > 0)
	    Die(FUNCTION_NAME, "Non-linear interpolation (%s mt %ld)",
		GetText(nuc + NUCLIDE_PTR_NAME), mt);

	  /* Get number original energy points */
	
	  NES = (long)XSS[L0];
	  CheckValue(FUNCTION_NAME, "NES", " (dosimetry)", NES, 0, INFTY);

	  /* Allocate memory for data */
	      
	  rea = NewItem(nuc + NUCLIDE_PTR_REA, REACTION_BLOCK_SIZE);
	  
	  /* Put nuclide pointer */
	  
	  WDB[rea + REACTION_PTR_NUCLIDE] = (double)nuc;
	  
	  /* Reaction index (used for energy distributions) */
	  
	  WDB[rea + REACTION_NR] = (double)nr;
	  
	  /* Set mt */
	  
	  WDB[rea + REACTION_MT] = (double)mt;
	  
	  /* Put awr */
	  
	  WDB[rea + REACTION_AWR] = RDB[nuc + NUCLIDE_AWR];
	  
	  /* Store minimum and maximum energy */
	  
	  WDB[rea + REACTION_EMIN] = XSS[L0 + 1];
	  WDB[rea + REACTION_EMAX] = XSS[L0 + NES];
	  
	  /* Compare to nuclide-wise values */

	  if (RDB[rea + REACTION_EMIN] < RDB[nuc + NUCLIDE_EMIN])
	    WDB[nuc + NUCLIDE_EMIN] = RDB[rea + REACTION_EMIN];

	  if (RDB[rea + REACTION_EMAX] > RDB[nuc + NUCLIDE_EMAX])
	    WDB[nuc + NUCLIDE_EMAX] = RDB[rea + REACTION_EMAX];
	  
	  /* Store number of energy points, pointer to grid and */
	  /* index to first point */
	  
	  WDB[rea + REACTION_PTR_EGRID] = (double)(L0 + 1);
	  WDB[rea + REACTION_XS_NE] = (double)NES;
	  
	  /* Store pointer to XS data */
	  
	  WDB[rea + REACTION_PTR_XS] = (double)(L0 + NES + 1);
	  
	  /* Set reaction type */
	  
	  WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;
	}

      /**********************************************************************/
    }

  else if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_SAB)
    {
      /**********************************************************************/

      /***** S(a,b) data ****************************************************/

      /* Set S(a,b) flag */

      SetOption(nuc + NUCLIDE_TYPE_FLAGS, NUCLIDE_FLAG_SAB_DATA);

      /* Number of reaction modes */

      if (JXS[3] - 1 > 0)
	NTR = 2;
      else
	NTR = 1;

      /* Reset nuclide energy boundaries */

      WDB[nuc + NUCLIDE_EMIN] = INFTY;
      WDB[nuc + NUCLIDE_EMAX] = -INFTY;

      /* Avoid compiler warning */

      Emax = -1.0;

      /* Loop over reaction channels */
      
      for (nr = 0; nr < NTR; nr++)
	{
	  /* Pointer to (in)elastic data (Table F-23, page F-36) */

	  if (nr == 0)
	    L0 = JXS[0] - 1;
	  else
	    L0 = JXS[3] - 1;

	  /* Get number of energy points */
	  
	  NES = (long)XSS[L0];
	  
	  /* Allocate memory for reaction data */
	      
	  rea = NewItem(nuc + NUCLIDE_PTR_REA, REACTION_BLOCK_SIZE);

	  /* Put nuclide pointer */

	  WDB[rea + REACTION_PTR_NUCLIDE] = (double)nuc;

	  /* Put awr */

	  WDB[rea + REACTION_AWR] = RDB[nuc + NUCLIDE_AWR];

	  /* Set mt */
	  
	  if (nr == 0)
	    WDB[rea + REACTION_MT] = 1004.0;
	  else
	    WDB[rea + REACTION_MT] = 1002.0;
	  
	  /* Set interpolation mode */

	  if ((nr == 1) && (NXS[4] == 4))
	    WDB[rea + REACTION_ITP] = 4.0;
	  else
	    WDB[rea + REACTION_ITP] = 0.0;

	  /* Store minimum and maximum energy */

	  WDB[rea + REACTION_EMIN] = XSS[L0 + 1];
	  WDB[rea + REACTION_EMAX] = XSS[L0 + NES];

	  /* Reset minimum and maximum emission energy */

	  WDB[rea + REACTION_SAB_MIN_EM_E] = INFTY;
	  WDB[rea + REACTION_SAB_MAX_EM_E] = -INFTY;

	  /* Maximum S(a,b) energy (needed to get the extra point in */
	  /* elastic channel */

	  if (nr == 0)
	    Emax = XSS[L0 + NES];
	  else if (Emax < XSS[L0 + NES])
	    Emax = XSS[L0 + NES];

	  /* Store */

	  WDB[rea + REACTION_SAB_EMAX] = Emax;

	  /* Compare to nuclide minimum */

	  if (RDB[rea + REACTION_EMIN] < RDB[nuc + NUCLIDE_EMIN])
	    WDB[nuc + NUCLIDE_EMIN] = RDB[rea + REACTION_EMIN];

	  /* Compare to nuclide maximum */

	  if (RDB[rea + REACTION_EMAX] > RDB[nuc + NUCLIDE_EMAX])
	    WDB[nuc + NUCLIDE_EMAX] = RDB[rea + REACTION_EMAX];

	  /* Store number of energy points, pointer to grid and */
	  /* index to first point */

	  WDB[rea + REACTION_PTR_EGRID] = (double)(L0 + 1);
	  WDB[rea + REACTION_XS_NE] = (double)NES;
	  WDB[rea + REACTION_XS_I0] = 0.0;

	  /* Store pointer to XS data */

	  WDB[rea + REACTION_PTR_XS] = (double)(L0 + 1 + NES);

	  /* Reset ures energy boundaries */

	  WDB[rea + REACTION_URES_EMIN] = INFTY;
	  WDB[rea + REACTION_URES_EMAX] = -INFTY;

	  /* Store Q-value */

	  WDB[rea + REACTION_Q] = 0.0;

	  /* Multiplication and frame of reference */

	  WDB[rea + REACTION_TY] = 1.0;
	  WDB[rea + REACTION_WGT_F] = 1.0;

	  /* Set branching fraction to 1.0 */
	      
	  WDB[rea + REACTION_BR] = 1.0;

	  /* Set type */
		  
	  WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_PARTIAL;
	}

      /**********************************************************************/
    }
  else if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_PHOTON)
    {
      /**********************************************************************/

      /***** Photon interaction data ****************************************/

      /* Number of energy points */
      
      NES = NXS[2];
      
      /* Put pointer to nuclide energy grid and nuber of points */

      WDB[nuc + NUCLIDE_PTR_EGRID] = (double)(JXS[0] - 1);
      WDB[nuc + NUCLIDE_EGRID_NE] = NES;

      /* Compare minimum and maximum value to XS limits */

      if (exp(XSS[JXS[0] - 1]) < RDB[DATA_PHOTON_XS_EMIN])
	WDB[DATA_PHOTON_XS_EMIN] = exp(XSS[JXS[0] - 1]);
      
      if (exp(XSS[JXS[0] + NES - 2]) > RDB[DATA_PHOTON_XS_EMAX])
	WDB[DATA_PHOTON_XS_EMAX] = exp(XSS[JXS[0] + NES - 2]);

      /* Loop over 4 reaction modes (incoherent, coherent, photoelectric */
      /* and pair production) and average heating numbers. */

      for (nr = 0; nr < 5; nr++)
	{
	  /* Add reaction */
      
	  rea = NewItem(nuc + NUCLIDE_PTR_REA, REACTION_BLOCK_SIZE);

	  /* Put nuclide pointer */

	  WDB[rea + REACTION_PTR_NUCLIDE] = (double)nuc;

	  /* Reaction index (used for energy distributions) */

	  WDB[rea + REACTION_NR] = -1.0;

	  /* Put type */
      
	  if (nr < 4)
	    WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_PARTIAL;
	  else
	    WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;

	  /* Put mt */

	  if (nr == 0)
	    WDB[rea + REACTION_MT] = 504.0;
	  else if (nr == 1)
	    WDB[rea + REACTION_MT] = 502.0;
	  else if (nr == 2)
	    WDB[rea + REACTION_MT] = 522.0;
	  else if (nr == 3)
	    WDB[rea + REACTION_MT] = 516.0;
	  else if (nr == 4)
	    WDB[rea + REACTION_MT] = 301.0;

	  /* Set minimum and maximum energy */

	  WDB[rea + REACTION_EMIN] = exp(XSS[JXS[0] - 1]);
	  WDB[rea + REACTION_EMAX] = exp(XSS[JXS[0] + NES - 2]);
	  
	  WDB[nuc + NUCLIDE_EMIN] = exp(XSS[JXS[0] - 1]);
	  WDB[nuc + NUCLIDE_EMAX] = exp(XSS[JXS[0] + NES - 2]);

	  /* Store number of energy points, pointer to grid and */
	  /* index to first point */

	  WDB[rea + REACTION_PTR_EGRID] = (double)(JXS[0] - 1);
	  WDB[rea + REACTION_XS_NE] = (double)NES;
	  WDB[rea + REACTION_XS_I0] = 0.0;

	  /* Store pointer to XS data */
	      
	  if (nr < 4)
	    WDB[rea + REACTION_PTR_XS] = (double)(JXS[0] - 1 + (nr + 1)*NES);
	  else
	    WDB[rea + REACTION_PTR_XS] = (double)(JXS[4] - 1);

	  /* Multiplication */
      
	  WDB[rea + REACTION_WGT_F] = 1.0;
	}

      /**********************************************************************/
    }
  else if ((long)RDB[nuc + NUCLIDE_TYPE] == NUCLIDE_TYPE_DECAY)
    {
      /**********************************************************************/

      /***** Transmutation data *********************************************/

      /* Check ace type */

      if ((long)ACE[ace + ACE_TYPE] != NUCLIDE_TYPE_TRANSMUXS)
	Die(FUNCTION_NAME, "Invalid ace type");

      /* Number of energy points */
      
      NES = NXS[2];

      /* Put pointer to nuclide energy grid and nuber of points */

      WDB[nuc + NUCLIDE_PTR_EGRID] = (double)(JXS[0] - 1);
      WDB[nuc + NUCLIDE_EGRID_NE] = NES;

      /* Set minimum and maximum energy */

      WDB[nuc + NUCLIDE_EMIN] = XSS[JXS[0] - 1];
      WDB[nuc + NUCLIDE_EMAX] = XSS[JXS[0] + NES - 2];
     
      /* Get number of reactions (minus elastic scattering). Include */
      /* only elastic scattering for DBRC nuclides. */
      
      NTR = NXS[3]; 

      /* Loop over reaction channels */
      
      for (nr = 0; nr < NTR; nr++)
	{
	  /* Get pointer to SIG-block (Table F-10, page F-17) */
	  
	  L = (long)XSS[JXS[5] - 1 + nr] + JXS[6] - 1;
	  
	  /* Get number of energy points */
	  
	  NES = (long)XSS[L];
      
	  /* Pointer to energy array (tää vaikuttaa epäilyttävältä) */
	  
	  L0 = JXS[0] - 1 + NXS[2] - NES;
	  
	  /* Get mt */
	  
	  mt = (long)XSS[JXS[2] + nr - 1];
      
	  /* Check number of energy points and mt (ei fissiota nyt) */
      
	  if ((NES > 0) && ((mt > 101) && (mt < 200)))
	    {
	      /* Allocate memory */
	  
	      rea = NewItem(nuc + NUCLIDE_PTR_REA, REACTION_BLOCK_SIZE);
	      
	      /* Put nuclide pointer */

	      WDB[rea + REACTION_PTR_NUCLIDE] = (double)nuc;
	      
	      /* Put mt */
	      
	      WDB[rea + REACTION_MT] = (double)mt;
	      
	      /* Store minimum and maximum energy */

	      WDB[rea + REACTION_EMIN] = XSS[L0];
	      WDB[rea + REACTION_EMAX] = XSS[L0 + NES - 1];
	      
	      /* Store number of energy points, pointer to grid and */
	      /* index to first point */
	      
	      WDB[rea + REACTION_PTR_EGRID] = (double)(JXS[0] - 1);
	      WDB[rea + REACTION_XS_NE] = (double)NES;
	      WDB[rea + REACTION_XS_I0] = (double)(NXS[2] - NES);

	      /* Store pointer to XS data */
	      
	      WDB[rea + REACTION_PTR_XS] = (double)(L + 1);

	      /* Put awr */

	      WDB[rea + REACTION_AWR] = RDB[nuc + NUCLIDE_AWR];
	  
	      /* Store Q-value */
	      
	      WDB[rea + REACTION_Q] = XSS[JXS[3] - 1 + nr];
	      
	      /* Multiplication and frame of reference */
	      
	      WDB[rea + REACTION_TY] = XSS[JXS[4] - 1 + nr];
	      
	      /* Check known error in ACE files (jos fissio joskus lisätään) */
	      
	      if ((XSS[JXS[4] - 1 + nr] == 0.0) &&
		  (((mt > 17) && (mt < 22)) || (mt == 38)))
		{
		  /* Print warning */
		  
#ifdef DEBUG

		  Warn(FUNCTION_NAME, 
		       "Conflicting reaction type for fission (%s mt %ld)", 
		       GetText(nuc + NUCLIDE_PTR_NAME), mt);

#endif		  
		  /* Set ty for fission */
		  
		  WDB[rea + REACTION_TY] = 19.0;
		}
	  
	      /* Set branching fraction to 1.0 */
	  
	      WDB[rea + REACTION_BR] = 1.0;

	      /* Set type */
	      
	      WDB[rea + REACTION_TYPE] = (double)REACTION_TYPE_PARTIAL;
	    }
	}

      /**********************************************************************/
    }
  else
    Die(FUNCTION_NAME, "Invalid nuclide type (%s)", name);

  /**************************************************************************/

  /***** Remove redundant reaction modes ************************************/

  rea = (long)RDB[nuc + NUCLIDE_PTR_REA];
  while (rea > VALID_PTR)
    {
      /* Redundant (n,p) */

      if ((long)RDB[rea + REACTION_MT] == 103)
	{
	  /* Loop over reactions */

	  ptr = (long)RDB[nuc + NUCLIDE_PTR_REA];
	  while (ptr > VALID_PTR)
	    {
	      /* Check mt and set type to special */

	      if (((long)RDB[ptr + REACTION_MT] > 599) && 
		  ((long)RDB[ptr + REACTION_MT] < 650))
		WDB[ptr + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;

	      /* Next reaction */

	      ptr = NextItem(ptr);
	    }
	}

      /* Redundant (n,d) */

      if ((long)RDB[rea + REACTION_MT] == 104)
	{
	  /* Loop over reactions */

	  ptr = (long)RDB[nuc + NUCLIDE_PTR_REA];
	  while (ptr > VALID_PTR)
	    {
	      /* Check mt and set type to special */

	      if (((long)RDB[ptr + REACTION_MT] > 649) && 
		  ((long)RDB[ptr + REACTION_MT] < 700))
		WDB[ptr + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;

	      /* Next reaction */

	      ptr = NextItem(ptr);
	    }
	}

      /* Redundant (n,t) */

      if ((long)RDB[rea + REACTION_MT] == 105)
	{
	  /* Loop over reactions */

	  ptr = (long)RDB[nuc + NUCLIDE_PTR_REA];
	  while (ptr > VALID_PTR)
	    {
	      /* Check mt and set type to special */

	      if (((long)RDB[ptr + REACTION_MT] > 699) && 
		  ((long)RDB[ptr + REACTION_MT] < 750))
		WDB[ptr + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;

	      /* Next reaction */

	      ptr = NextItem(ptr);
	    }
	}

      /* Redundant (n,He-3) */

      if ((long)RDB[rea + REACTION_MT] == 106)
	{
	  /* Loop over reactions */

	  ptr = (long)RDB[nuc + NUCLIDE_PTR_REA];
	  while (ptr > VALID_PTR)
	    {
	      /* Check mt and set type to special */

	      if (((long)RDB[ptr + REACTION_MT] > 749) && 
		  ((long)RDB[ptr + REACTION_MT] < 800))
		WDB[ptr + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;

	      /* Next reaction */

	      ptr = NextItem(ptr);
	    }
	}

      /* Redundant (n,a) */

      if ((long)RDB[rea + REACTION_MT] == 107)
	{
	  /* Loop over reactions */

	  ptr = (long)RDB[nuc + NUCLIDE_PTR_REA];
	  while (ptr > VALID_PTR)
	    {
	      /* Check mt and set type to special */

	      if (((long)RDB[ptr + REACTION_MT] > 799) && 
		  ((long)RDB[ptr + REACTION_MT] < 850))
		WDB[ptr + REACTION_TYPE] = (double)REACTION_TYPE_SPECIAL;

	      /* Next reaction */

	      ptr = NextItem(ptr);
	    }
	}

      /* Next reaction */

      rea = NextItem(rea);
    }
  
  /**************************************************************************/

  /* Close file  */
  
  fclose(fp);	  
}
Пример #14
0
void CalibrateData(Int_t nevt,Int_t startEv = 1, char *PedFile = "drs4_20100311_t_ped.root") {

	// create progress bar
	TGHProgressBar *gProgress = ProgressBar("Calibrazione dati");

	// Redefine DOMINO Depth in ADC counts
	const Float_t DominoDepthADC = pow(2, DOMINO_DEPTH);

	// create list of histograms for pedestals
	TList *grPedList = new TList();
	TGraphErrors *grPed;

	// create list of histograms for channels
	TList *hCellCalibList = new TList();
	TH1F *hCellCalib;

	TList *grCellCalibList = new TList();
	TGraphErrors *grCellCalib;

	int mV[NCALIBFILES] = {-500,-400,-300,-200,-100,0,100,200,300,400,500};

	/*for (int iFile = 0; iFile < NCALIBFILES; iFile++) {
		mV[iFile] = mVStart;
		mVStart += mVStep;
	}*/

	char *calibrationFile;
	char *calibrationFileArray[NCALIBFILES];
	calibrationFileArray[0] = "drs4_1000ev_dcm500mv.dat";
	calibrationFileArray[1] = "drs4_1000ev_dcm400mv.dat";
	calibrationFileArray[2] = "drs4_1000ev_dcm300mv.dat";
	calibrationFileArray[3] = "drs4_1000ev_dcm200mv.dat";
	calibrationFileArray[4] = "drs4_1000ev_dcm100mv.dat";
	calibrationFileArray[5] = "drs4_1000ev_dc1mv.dat";
	calibrationFileArray[6] = "drs4_1000ev_dc100mv.dat";
	calibrationFileArray[7] = "drs4_1000ev_dc200mv.dat";
	calibrationFileArray[8] = "drs4_1000ev_dc300mv.dat";
	calibrationFileArray[9] = "drs4_1000ev_dc400mv.dat";
	calibrationFileArray[10] = "drs4_1000ev_dc500mv.dat";

	for (int iFile = 0; iFile < NCALIBFILES; iFile++) {
		for (int ch = 0; ch < DOMINO_NCELL; ch++) {
			//
			TString title = "Calibration signal file:";
			title += iFile;
			title += " ch:";
			title += ch;
			hCellCalib = new TH1F(title,title, DominoDepthADC, -DominoDepthADC, DominoDepthADC);
			hCellCalibList->Add(hCellCalib);
		}
	}


	for (int ch = 0; ch < DOMINO_NCELL; ch++) {
		grCellCalib = new TGraphErrors(NCALIBFILES);
		grCellCalibList->Add(grCellCalib);
	}


	// calculate or read pedestals from file
	grPedList = OpenPedestals(PedFile);
	grPedData = (TGraphErrors *) grPedList->At(anaChannel);
	grPedTrig = (TGraphErrors *) grPedList->At(trigChannel);

	// create gauss function
	TF1 *fgauss = new TF1("fgauss", "TMath::Gaus(x,[0],[1],0)", -DOMINO_NCELL, DOMINO_NCELL);
	fgauss->SetParameter(0,0.);
	fgauss->SetParameter(1,1.);
	fgauss->SetParLimits(0, 0., DominoDepthADC);
	fgauss->SetParLimits(1, 0.1, 20.);

	TCanvas *ctest = new TCanvas("ChannelTest", "ChannelTest", 800, 600);
	ctest->Divide(3, 4);

	gProgress->Reset();
	gProgress->SetMax(nevt*NCALIBFILES);

	gSystem->ProcessEvents();


	for (int iFile = 0; iFile < NCALIBFILES; iFile++) {

		// open file

		calibrationFile = calibrationFileArray[iFile];
		FILE *fdata = OpenDataFile(calibrationFile);
		struct channel_struct *p;
		struct channel_struct *dep;

		Double_t refval=0, reftmp = 0;
		Double_t PedVal, itmp;

		// Count number of events in data file
		int nevtDataMax = 0;
		while (!feof(fdata)) {
			fread((void *) &event_data, 1, sizeof(event_data), fdata);
			nevtDataMax++;
		}
		printf("nevtDataMax: %d\n", nevtDataMax);

		if (nevt > (nevtDataMax - startEv) || nevt == 0)
			nevt = nevtDataMax - startEv;
		cout << endl << "==>> Processing " << nevt << " events from file "
				<< calibrationFile << endl;

		rewind(fdata);

		for (int j = 0; j < 1; j++) {
			fread((void *) &event_data, 1, sizeof(event_data), fdata);
			p = (struct channel_struct *) &event_data.ch[0]; // read bunch of data
			p += anaChannel;
			for (ch = 0; ch < DOMINO_NCELL; ch++) {
				grPedData->GetPoint(ch, itmp, PedVal);
				reftmp = TMath::Abs((Double_t)(p->data[ch])-PedVal);
				if (reftmp > 0.8* refval)
					refval = 0.2*reftmp+0.8*refval;
				//					cout << ch << " " <<p->data[ch] << " " <<reftmp << " " << refval <<endl ;
			}
		}
		cout << "refval="<< refval<<endl;
		rewind(fdata);

		Int_t ievt = 1;
		// go to first event (startEv)
		while (ievt < startEv) {
			fread((void *) &event_data, 1, sizeof(event_data), fdata);
			if (feof(fdata))
				break;
			ievt++;
		}

		ievt = 1;
		Int_t iTrig = 0;
		Int_t flagEnd = 0;
		Double_t chtmp, chtrig;
		Double_t ratio;
		Double_t mean, rms;

		// loop on events

		while (ievt <= nevt && !flagEnd) {

			fread((void *) &event_data, 1, sizeof(event_data), fdata);
			if (feof(fdata))
				flagEnd = 1;

			p = (struct channel_struct *) &event_data.ch[0]; // read bunch of data
			dep = (struct channel_struct *) &event_data.ch[1]; // read bunch of data

			//now anaChannel analysis

			p += anaChannel;

			// read data, subtract pedestals values and fill hCellCalibList.

			for (int ch = 0; ch < DOMINO_NCELL; ch++) {
				// Read pedestal value for this cell
				grPedData->GetPoint(ch, itmp, PedVal);
				chtmp = (Double_t)(p->data[ch]); // data value
				chtmp = chtmp - PedVal;
				//if (TMath::Abs(chtmp) > 0.9 * refval)
				((TH1 *) hCellCalibList->At(iFile*DOMINO_NCELL+ch))->Fill(chtmp);
				//cout << ch << " " << iFile << " " << chtmp << endl;
			}

			gProgress->Increment(1);
			gSystem->DispatchOneEvent(kTRUE);
			ievt++; // next event
		}


		TH1 *hCellTmp;
		for(ch = 0; ch < DOMINO_NCELL;ch++) {
			hCellTmp = ((TH1 *) hCellCalibList->At(iFile*DOMINO_NCELL+ch));
			//hCellTmp->Fit("gaus", "Q");
			//mean = (hCellTmp->GetFunction("gaus"))->GetParameter(1);
			//rms = (hCellTmp->GetFunction("gaus"))->GetParameter(2);
			mean = hCellTmp->GetMean();
			rms = hCellTmp->GetRMS();
			((TGraphErrors *) (grCellCalibList->At(ch)))->SetPoint(iFile, (Double_t) mV[iFile], mean);
			((TGraphErrors *) (grCellCalibList->At(ch)))->SetPointError(iFile, 0., rms);
		}


		ctest->cd(iFile + 1);
		hCellTmp = ((TH1 *) hCellCalibList->At(567 + iFile*DOMINO_NCELL));
		hCellTmp->Fit("gaus","Q");
		hCellTmp->DrawCopy();
	}

	TString OutFile = "CalibrationDataNew";
	OutFile += nevt;
	OutFile += "events.root";
	TFile *f = new TFile(OutFile, "RECREATE");
	for (int ch = 0; ch < DOMINO_NCELL; ch++) {
		TString key = "CalibDataCell";
		key += ch;
		((TGraphErrors*) grCellCalibList->At(ch))->Write(key);
	}
	f->Close();

	hCellCalibList->Delete();

	((TGMainFrame *) gProgress->GetParent())->CloseWindow();
	fclose(fdata);
}
Пример #15
0
void CalcPeriod(char *DataFile = "drs4_peds_5buffers.dat", Int_t nevt,
		Int_t startEv = 1, char *PedFile) {

	// create progress bar
	TGHProgressBar *gProgress = ProgressBar("Calcolo periodo");

	// Redefine DOMINO Depth in ADC counts
	const Float_t DominoDepthADC = pow(2, DOMINO_DEPTH);

	// open file

	FILE *fdata = OpenDataFile(DataFile);
	struct channel_struct *p;
	struct channel_struct *dep;

	// create list of graphs for pedestals
	TList *grPedList = new TList();
	TGraphErrors *grPed;

	// create period histogram

	TString title = "Period histogram";
	TH1 *hPeriod = new TH1F(title,title, 2*((Int_t) DOMINO_NCELL), (Double_t) -DOMINO_NCELL, (Double_t) DOMINO_NCELL);

	// calculate or read pedestals from file
	grPedList = OpenPedestals(PedFile);
	grPed = (TGraphErrors *) grPedList->At(anaChannel);


	// Count number of events in data file
	int nevtDataMax = 0;
	while (!feof(fdata)) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		nevtDataMax++;
	}
	printf("nevtDataMax: %d\n", nevtDataMax - 1);

	if (nevt > (nevtDataMax - startEv) || nevt == 0)
		nevt = nevtDataMax - startEv;
	cout << endl << "==>> Processing " << nevt << " events from file "
			<< DataFile << endl;

	rewind(fdata);


	Int_t ievt = 1;
	// go to first event (startEv)
	while (ievt < startEv) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		if (feof(fdata))
			break;
		ievt++;
	}

	ievt = 1;
	Int_t flagEnd = 0;
	Int_t fitusati = 0;
	Double_t chtmp;
	Double_t PedVal, itmp;
	Double_t mean, rms;
	Double_t ratio;



	//debug canvas
	TCanvas *cfitTest = new TCanvas("cfitTest", "fit tests", 1200, 780);
	cfitTest->Divide(1,nevt);

	// loop on events

	gProgress->Reset();
	gProgress->SetMax(nevt);

	gSystem->ProcessEvents();

	while (ievt <= nevt && !flagEnd) {
		fread((void *) &event_data, 1, sizeof(event_data), fdata);
		if (feof(fdata))
			flagEnd = 1;

		p = (struct channel_struct *) &event_data.ch[0]; // read bunch of data
		dep = (struct channel_struct *) &event_data.ch[1]; // read bunch of data
		// goes to channel to analyze
		p += anaChannel;

		// read data, subtract pedestals values and save results in grAnaChDataTemp graph with
		// fixed error for each point (x = 0.5 and y = 2.1). Also generate an array with Domino
		// X and Y values

		TGraphErrors *grAnaChDataTemp = new TGraphErrors(DOMINO_NCELL);

		for (int ch = 0; ch < DOMINO_NCELL; ch++) {
			// Read pedestal value for this cell
			grPed->GetPoint(ch, itmp, PedVal);
			chtmp = (Double_t)(p->data[ch]); // data value
			chtmp = chtmp - PedVal;
			grAnaChDataTemp->SetPoint(ch, (Double_t) ch, chtmp);
			grAnaChDataTemp->SetPointError(ch, 0.5, 2.1);
		}
		// create fit functions
		TF1 *fsin = new TF1("fsin", sigSin, 0., 1024., 4);
		fsin->SetParameters(600., 255., 150., 150.);
		fsin->SetParNames("amplitude", "Period", "Phase", "DC-Offset");

		grAnaChDataTemp->Fit("fsin", "Q");
		TF1 *fsinFit = grAnaChDataTemp->GetFunction("fsin");
		fsinFit->SetParNames("amplitude", "Period", "Phase", "DC-Offset");

		// debug
		cfitTest->cd(ievt);
		grAnaChDataTemp->SetMarkerStyle(20);
		grAnaChDataTemp->SetMarkerSize(0.3);
		grAnaChDataTemp->GetYaxis()->SetLabelSize(0.12);
		grAnaChDataTemp->GetXaxis()->SetLabelSize(0.12);
		grAnaChDataTemp->Draw("APE");

		Double_t fitPeriod, fitAmplitude, chisquare;
		fitPeriod = fsinFit->GetParameter("Period");
		fitAmplitude = TMath::Abs(fsinFit->GetParameter("amplitude"));
		chisquare = fsinFit->GetChisquare();

		cout << "period: " << fitPeriod << " amplitude: " << fitAmplitude << " chisquare: " << chisquare << endl;

		if(chisquare > 0.1e+06) {
			gProgress->Increment(1);
			gSystem->DispatchOneEvent(kTRUE);
			ievt++;
			continue;
		}

		gProgress->Increment(1);
		gSystem->DispatchOneEvent(kTRUE);

		hPeriod->Fill(fitPeriod);
		fitusati++;

		ievt++;

	}

	cout << "fit scartati :" << nevt - fitusati << endl;
	//draw
	TString Title = "Period distribution for nevt events";
	TCanvas *cPeriod = new TCanvas("cPeriod", Title, 700, 700);
	hPeriod->Draw();
	hPeriod->Fit("gaus");

	TF1 *fgausFit = hPeriod->GetFunction("gaus");
	//mean = fgausFit->GetParameter(1);
	//	rms = fgausFit->GetParameter(2);

	mean = hPeriod->GetMean();
	rms = hPeriod->GetRMS();

	TString OutFile = "Period";
	OutFile += nevt;
	OutFile += "events.dat";
	FILE *f = fopen(OutFile.Data(), "w");
	fwrite(&mean, sizeof(mean), 1, f);
	fwrite(&rms, sizeof(rms), 1, f);

	((TGMainFrame *) gProgress->GetParent())->CloseWindow();
	fclose(f);

	cout << "mean: " << mean << " rms: " << rms << endl;

	fclose(fdata);

}