read_root.C 2.3 KB
Newer Older
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
void read_root() 
{
	TFile *f = new TFile("/home/dariak/NeuRad_tests/data/rawDataDSR4/NeuRad_test_07_1.root");
	TTree *tr = (TTree*)f->Get("rtree");
	tr->SetMakeClass(1);

//	TArrayD ampl1;
//	TArrayD time1;
//	ampl1.Set(ncellMax);
//	time1.Set(ncellMax);

	const int ncellMax = 1030;
	Double_t ampl1[ncellMax];
	Double_t time1[ncellMax];

	TFile *fw = new TFile("/home/dariak/NeuRad_tests/data/dataDSR4/analysis_07_1.root", "RECREATE");
	TTree *tw = new TTree("drs4analysis", "title of drs4 analysis tree");
	Double_t minAmplitude1;
	tw->Branch("minAmplitude1", &minAmplitude1, "minAmplitude1/D");
/*	Double_t ampl1[1024];
	Double_t time1[1024];*/

	tr->SetBranchAddress("amp_ch1", ampl1);
	tr->SetBranchAddress("time_ch1", time1);

	const Long64_t nEntries = tr->GetEntries();
	cout <<"Number of entries: "<<nEntries<<endl;

//----for pictures 
/*	TCanvas *c1 = new TCanvas();
	c1->Divide(3,4);

	for(Int_t i=12; i<24; i++) {
		c1->cd(i-11);
		tr->GetEntry(i);
		TGraph *gr1 = new TGraph(1023, time1, ampl1);
		gr1->SetTitle("Signal shape for one event");
		gr1->GetXaxis();
		gr1->Draw("Al*");
	}

	tr->GetEntry(428);
	TGraph *gr1 = new TGraph(1023, time1, ampl1);
	gr1->SetTitle("Signal shape for one event");
	gr1->Draw("Al*");*/
//-----
	Double_t minAmpl1 = 0.; 
	
	for(Int_t i=0; i<tr->GetEntries(); i++) {
		tr->GetEntry(i);
		minAmpl1 = ampl1[0];

		//find minimum by hand 
		for(Int_t j=0; j<1023; j++) {	
			//cout<<ampl1[j]<<" "<<j<<endl;
			if(ampl1[j] < minAmpl1) {
				minAmpl1 = ampl1[j];
			}
			/*cout<<"Time "<<i<<" "<<j<<" "<<time1[j]<<endl;
			//cout<<"Amplitude "<<i<<" "<<j<<" "<<ampl1[j]<<endl;
			cout<<endl;*/
		}
		//fitting 90 percent of rising edge
		for(Int_t k=0; k<1023; k++) {
			if(ampl1[k] < 0.1*minAmpl1 && ampl1[k] > 0.9*minAmpl1) { //we have negative signals, amplitude between 10 and 90 proc from minimum
				/*cout<<"rjgnfre"<<endl;
				TGraph *gr2 = new TGraph(1023, time1, ampl1);
				gr2->SetTitle("stupido");
				gr2->Fit("pol1");
				gr2->Draw("Al*");*/
				
			}
		}
		//getting integral

		TGraph *gr3 = new TGraph(1023, time1, ampl1);
		//for(Int_t k=120; k<180; k++) {
		gr3->Integral(120,180);
		cout<<"INtegral "<<gr3->Integral(120,180)<<endl;
		//}
		minAmplitude1 = minAmpl1;
		cout<<"Min amplitude "<<minAmpl1<<" for entry "<<i<<endl;
		

		tw->Fill();
	}
	fw->cd();
	tw->Write();
	fw->Close();
}