read2.cpp 2.64 KB
Newer Older
Muzalevsky I.A's avatar
Muzalevsky I.A committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#include <fstream>

#include "TString.h"
#include "TFile.h"
#include "TError.h"
#include "TTree.h"

#include "../dataClasses/RawEvent.h"
void read2()
{
//	std::cout << argv[1] << "says hello, " << argv[2] << "!" << std::endl;
//	std::cout << infiles << "says hello, " << ofile << "!" << std::endl;
//	return 0;
	
	gSystem->Load("../libData.so");
	Double_t A1[1000],A2[1000];
	Double_t T1[1000],T2[1000];
	Int_t k,n,p,Nchannel,nHun,nDec;
	TString line1,line2,filename1,filename2;
	Double_t amp1,amp2,time1,time2;
	const Int_t nfiles = 400;	
	const Int_t Nlines = 500;

	TFile *f1 = new TFile("source.root","RECREATE");
	TTree *tree = new TTree("rtree","signal");
	tree->Branch("A1",A1,"A1[1000]/D");
	tree->Branch("A2",A2,"A2[1000]/D");

	tree->Branch("T1",T1,"T1[1000]/D");
	tree->Branch("T2",T2,"T2[1000]/D");	

	ifstream myfile1,myfile2; 	
	Int_t i=0;
	//for(Int_t i=0;i<nfiles;i++)
	{	
		nHun = (i%1000 - i%100)/100; // изза кривых названий файла приходится выяснять количетсво единиц, сотен, десятков, в данноом числе. 
		nDec = (i%100 - i%10)/10; // делю на соответствующие числа для получения цифры 
		n = i%10;

		filename1.Form("../data/rawDataTektronix/SORCE/trigger_10mv/C2BCF12_H9500_1000_ToT00%d%d%d.txt",nHun,nDec,n);
		myfile1.open("../data/rawDataTektronix/SORCE/trigger_10mv/try.txt");
		if (myfile1.is_open()) {cout<<"file opened "<<filename1.Data()<<endl;}
		else{
			Error("read2.cpp", "Some error when opening file %s", filename1.Data());
			return;
		}

		filename2.Form("../data/rawDataTektronix/SORCE/nontrigger_10mV/C3BCF12_H9500_1000_ToT00%d%d%d.txt",nHun,nDec,n);
		myfile2.open(filename2.Data());
		if (myfile2.is_open()) {/*cout<<"file opened "<<filename2.Data()<<endl;*/}
		else{
			Error("read2.cpp", "Some error when opening file %s", filename2.Data());
			return;
		}
		
		for(Int_t j=0;j<5;j++){// пропускаю первые 5 строк
			line1.ReadLine(myfile1);
			line2.ReadLine(myfile2);
			//cout<<line1<<endl;
		}

		for(Int_t j =0;j<Nlines;j++){
			if(j==1) break;
			line1.ReadLine(myfile1);
			line2.ReadLine(myfile2);
			//cout<<line1<<endl;
			if( line1.IsNull() || line2.IsNull() ) break;	


			sscanf(line1.Data(), "%e%*c%e", &amp1, &time1);
			sscanf(line2.Data(), "%f%*c%f", &amp2, &time2);
			cout<<line1.Data()<<endl;
			cout<<amp1<<" "<<time1<<endl;
			//cout<<amp2<<" "<<time2<<endl;
			A1[j] = amp1; T1[j] = time1;
			A2[j] = amp2; T2[j] = time2;
		}
		tree->Fill();

		for(j=0;j<Nlines;j++){ // reset
			T1[j]=0; T2[j]=0;
			A1[j]=0;A2[j]=0;
		}
		myfile1.close();
		myfile2.close();
	}

	tree->Write();
	f1->Close();
}