read2.cpp 2.71 KB
Newer Older
Muzalevsky I.A's avatar
Muzalevsky I.A committed
1 2 3 4 5 6 7
#include <fstream>

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

8 9
//#include "../dataClasses/RawEvent.h"

Muzalevsky I.A's avatar
Muzalevsky I.A committed
10 11
void read2()
{
12 13
	// find . -type f | wc -l для подсчёта файлов в папке
//	cout << gSystem->Load("../libData.so") << endl;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
14
	gSystem->Load("../libData.so");
15 16 17 18 19

	using std::cout;
	using std::endl;

	Int_t k,n,p,Nchannel,nHun,nDec,counter;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
20 21
	TString line1,line2,filename1,filename2;
	Double_t amp1,amp2,time1,time2;
22 23 24 25 26 27 28 29
	const Int_t nfiles = 5000;
	const Int_t NEvents = 1000;
	//Double_t A1[1000],A2[1000];
	//Double_t T1[1000],T2[1000];
	p=0;
	TFile *f1 = new TFile("../data/rawDataTektronix/GSItests/1000v_5mv.root","RECREATE");
	//TFile *f1 = new TFile("1000V_10mv.root","RECREATE");
	TTree *rtree = new TTree("rtree","signal");
Muzalevsky I.A's avatar
Muzalevsky I.A committed
30

31 32
/*	rtree->Branch("A1",A1,"A1[1000]/D");
	rtree->Branch("A2",A2,"A2[1000]/D");
Muzalevsky I.A's avatar
Muzalevsky I.A committed
33

34 35
	rtree->Branch("T1",T1,"T1[1000]/D");
	rtree->Branch("T2",T2,"T2[1000]/D");*/
Muzalevsky I.A's avatar
Muzalevsky I.A committed
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
	RawEvent *event1 = new RawEvent(1000);
	rtree->Bronch("ch0.", "RawEvent", &event1);
	RawEvent *event2 = new RawEvent(1000);
	rtree->Bronch("ch1.", "RawEvent", &event2);
	RawEvent *event3 = new RawEvent(1000);
	rtree->Bronch("ch2.", "RawEvent", &event3);
	RawEvent *event4 = new RawEvent(1000);
	rtree->Bronch("ch3.", "RawEvent", &event4);
	counter = 0;
	ifstream myfile1,myfile2; //	i=0;
	for(Int_t i=0; i<nfiles; i++) {	if(i%1000==0){ cout<<i<<endl;}
		filename1.Form("../data/rawDataTektronix/muzalevsky/1000V_trigg5mv_nosurce/1000V_5.2mv_nosource%dWfm_Ch1.txt",i+1);
		myfile1.open(filename1.Data());
		if (myfile1.is_open()) {
			filename2.Form("../data/rawDataTektronix/muzalevsky/1000V_trigg5mv_nosurce/1000V_5.2mv_nosource%dWfm_Ch2.txt",i+1);
			myfile2.open(filename2.Data()); 
			if (myfile2.is_open()) {
				p++;
				for(Int_t j =0;j<NEvents;j++){
					line1.ReadLine(myfile1);
					line2.ReadLine(myfile2);
					//cout<<line1<<endl;
					if( line1.IsNull() || line2.IsNull() ) break;	
Muzalevsky I.A's avatar
Muzalevsky I.A committed
60

61 62 63 64 65 66
					sscanf(line1.Data(), "%lf", &amp1);
					sscanf(line2.Data(), "%lf", &amp2);
					//cout<<line1.Data()<<endl;
					//cout<<amp1<<" "<<j<<endl;
					time1  = j*0.1;
					time2 = j*0.1;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
67

68 69 70 71 72 73 74 75
					event1->SetAmp(amp1, j);
					event2->SetAmp(amp2, j);
					event1->SetTime(time1, j);
					event2->SetTime(time2, j);
				}
				rtree->Fill();
				counter++;
				//cout<<counter<<" events founded"<<endl;
Muzalevsky I.A's avatar
Muzalevsky I.A committed
76

77 78 79 80 81 82 83 84 85 86 87
				for(j=0;j<NEvents;j++){ // reset			
					event1->Reset();
					event2->Reset();
				}
				myfile1.close();
				myfile2.close();
			}			
			else{
				Error("read2.cpp", "Some error when opening file %s", filename2.Data());
				return;
			}
Muzalevsky I.A's avatar
Muzalevsky I.A committed
88
		}
89 90 91 92 93 94 95
		else{
			Error("read2.cpp", "Some error when opening file %s", filename1.Data());
			return;
		}//*/
	} //for
	cout << p << " files processed" << endl;
	rtree->Write();
Muzalevsky I.A's avatar
Muzalevsky I.A committed
96 97
	f1->Close();
}