Commit 647cbcb1 authored by Muzalevsky I.A's avatar Muzalevsky I.A

new script for converting data into root file added

parent 3fb4f668
void read1() {
gSystem->Load("../libData.so");
Double_t A1[1000],A2[1000],A3[1000],A4[1000];
Double_t T[1000];
Int_t i,j,k,n,p,Nchannel,Nlines;
TString line1,line2,line3,line4,fileName;
Double_t amp1,amp2,amp3,amp4,time;
TFile *f1 = new TFile("exp2.root","RECREATE");
TTree *tree = new TTree("rtree","signal");
tree->Branch("A1",A1,"A1[1000]/D");
tree->Branch("A2",A2,"A2[1000]/D");
tree->Branch("A3",A3,"A3[1000]/D");
tree->Branch("A4",A4,"A4[1000]/D");
tree->Branch("T",T,"T[1000]/D");
RawEvent *event1 = new RawEvent(1000);
tree->Bronch("ch0.", "RawEvent", &event1);
RawEvent *event2 = new RawEvent(1000);
tree->Bronch("ch1.", "RawEvent", &event2);
RawEvent *event3 = new RawEvent(1000);
tree->Bronch("ch2.", "RawEvent", &event3);
RawEvent *event4 = new RawEvent(1000);
tree->Bronch("ch3.", "RawEvent", &event4);
////////
RawEvent **Nevent;
Nevent = new RawEvent *[4];
Nevent[0] = event1;
Nevent[1] = event2;
Nevent[2] = event3;
Nevent[3] = event4;
/////////
ifstream myfile;
ifstream myfile1;
ifstream myfile2;
ifstream myfile3;
ifstream myfile4;
myfile.open("../data/rawDataTektronix/infiles.dat"); // открываю файл с названиями файлов с данными для подсчёта общего количества файлов
if (myfile.is_open()) { /// для создания динамического массива с путями к файлам с данными
while(1){
fileName.ReadLine(myfile);
if ( fileName.IsNull() ) break;
Nlines++;
}
myfile.close();
}
else {Error("read.cpp", "Some error when opening file","infiles.dat");return;}
TString *NameLines = new TString[Nlines]; // создание массива в котором хранятся строки из файла "infiles.dat"
// TString NameLines[Nlines];
myfile.open("../data/rawDataTektronix/infiles.dat");
for(i=0;;i++){
fileName.ReadLine(myfile);
NameLines[i] = fileName;
if ( fileName.IsNull() ) break;
}
myfile.close();
for(i=0;i<(-1+Nlines/4);i++){
cout<<NameLines[i+1]<<endl; // открываю i - ый файл с данными для всех каналов
cout<<NameLines[i+1+Nlines/4]<<endl;
cout<<NameLines[i+1+Nlines/2]<<endl;
cout<<NameLines[i+1+3*Nlines/4]<<endl;
}
// return;
for(i=0;i<(-1+Nlines/4);i++){
myfile1.open( NameLines[i+1] ); // открываю i - ый файл с данными для всех каналов
myfile2.open( NameLines[i+1+Nlines/4] );
myfile3.open( NameLines[i+1+Nlines/2] );
myfile4.open( NameLines[i+1+3*Nlines/4] );
if( ( myfile1.is_open() ) && ( myfile2.is_open() ) && ( myfile3.is_open() ) && ( myfile4.is_open() ) ) {
amp1=amp2=amp3=amp4=time=0;
j=0;
while (1) {
line1.ReadLine(myfile1);
line2.ReadLine(myfile2);
line3.ReadLine(myfile3);
line4.ReadLine(myfile4);
if( line1.IsNull() ) break;
time = 5e-04+ (j-1000*n)*1e-01;
sscanf(line1.Data(), "%lf", &amp1);
sscanf(line2.Data(), "%lf", &amp2);
sscanf(line3.Data(), "%lf", &amp3);
sscanf(line4.Data(), "%lf", &amp4);
n=j/1000;
A1[j-1000*n] = amp1;
A2[j-1000*n] = amp2;
A3[j-1000*n] = amp3;
A4[j-1000*n] = amp4;
T[j-1000*n] = time;
event1->SetAmp(amp1, j-1000*n);
event2->SetAmp(amp2, j-1000*n);
event3->SetAmp(amp3, j-1000*n);
event4->SetAmp(amp4, j-1000*n);
event1->SetTime(time, j-1000*n);
event2->SetTime(time, j-1000*n);
event3->SetTime(time, j-1000*n);
event4->SetTime(time, j-1000*n);
if(j-1000*n == 999) {
tree->Fill();
for(k=0;k<1000;k++){
T[k]=0;
A1[k]=0;A2[k]=0;A3[k]=0;A4[k]=0;
}
event1->Reset();
event2->Reset();
event3->Reset();
event4->Reset();
}
j++;
}
myfile1.close();
myfile2.close();
myfile3.close();
myfile4.close();
}
else {
Error("read.cpp", "Some error when opening data file number of %d", i);
return;
}
}//for i
tree->Write();
f1->Close();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment