diff --git a/convertDRS4/read_binary.cpp b/convertDRS4/read_binary.cpp index 8de23e13edbf4bee9639ab9f10f677e62aa28cb5..8cf0650f4e3c99b94321f8efbcaf4a9d74780ea7 100644 --- a/convertDRS4/read_binary.cpp +++ b/convertDRS4/read_binary.cpp @@ -334,7 +334,9 @@ int main(int argc, const char * argv[]) rfile->Close(); // delete event; + printf("error1\n"); delete[] event; + printf("error2\n"); return 1; } diff --git a/convertRawToAnalyzed/analyse.cpp b/convertRawToAnalyzed/analyse.cpp new file mode 100644 index 0000000000000000000000000000000000000000..abde307df82eb13bcb421afc8bc0dfbd24016da6 --- /dev/null +++ b/convertRawToAnalyzed/analyse.cpp @@ -0,0 +1,58 @@ +void analyse() +{ + gSystem->Load("../libData.so"); + + TFile *f = new TFile("../data/rawDataDSR4/NeuRad_test_07_1.root"); + TTree *tr = (TTree*)f->Get("rtree"); + + const Int_t noBranches = 4; + const Double_t cfRatio = 0.5; + const Int_t cfTD = 5; + + TString bName; + RawEvent *revent[noBranches]; // pointer to the array (of RawEvent class) in which raw data for each channel will be put + for (Int_t j = 0; jSetBranchAddress(bName.Data(), &revent[j]); //read the tree tr with raw data and fill array revent with raw data + } + +// tr->SetMakeClass(1); + + TFile *fw = new TFile("../data/dataDSR4/analysis_07_1.root", "RECREATE"); //create .root file with somehow analyzed data + TTree *tw = new TTree("atree", "title of drs4 analysis tree"); //create analysis tree atree in it + + AEvent *wevent[noBranches]; // pointer to the array (of AEvent class) in which analyzed data for each channel will be put + for (Int_t j = 0; jSetInputEvent(&revent[j]); //takes raw event from RawEvent + wevent[j]->SetCFratio(cfRatio); + wevent[j]->SetCFtimeDelay(cfTD); + tw->Bronch(bName.Data(), "AEvent", &wevent[j]); // create branches in atree to hold analyzed data + } + +//----event loop in tr input tree + Long64_t nentries = tr->GetEntries(); + + for(Long64_t i = 0; i < nentries; i++) { + tr->GetEntry(i); + if ( !(tr->GetEntry(i)%100) ) { + printf("Found event #%d\n", tr->GetEntry(i)); + } + + for (Int_t j = 0; jReset(); + wevent[j]->ProcessEvent(); //here all the analysis is going on so far + } + + tw->Fill(); + } + +//----end of event loop + + tw->Write(); + fw->Close(); + + return; +} diff --git a/convertTektronix/exp2.root b/convertTektronix/exp2.root deleted file mode 100644 index 3940361a479d9b54b32a1cbad59c8175ae77e561..0000000000000000000000000000000000000000 Binary files a/convertTektronix/exp2.root and /dev/null differ diff --git a/convertTektronix/read1.cpp b/convertTektronix/read1.cpp index e70ab099374ff0a31adb7efdd0d86a9c2af72cd5..b6dad41e9f1f13bb452482c6bce4504884cd0a0e 100644 --- a/convertTektronix/read1.cpp +++ b/convertTektronix/read1.cpp @@ -1,15 +1,39 @@ -void read1(Int_t input=0) { -cout<Load("../libData.so"); - +#include + +#include "TString.h" +#include "TFile.h" +#include "TError.h" +#include "TTree.h" + +#include "../dataClasses/RawEvent.h" + + +int main(int argc, char* argv[]) +{ + + if (argc != 3) { + // Tell the user how to run the program + std::cerr << "Usage: " << argv[0] << " [list with input files] [outputfile]" << std::endl; + /* "Usage messages" are a conventional way of telling the user + * how to run a program if they enter the command incorrectly. + */ + return 1; + } + // Print the user's name: + TString infiles = argv[1]; + TString ofile = argv[2]; + +// std::cout << argv[1] << "says hello, " << argv[2] << "!" << std::endl; +// std::cout << infiles << "says hello, " << ofile << "!" << std::endl; +// return 0; + 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"); + TFile *f1 = new TFile(ofile.Data(),"RECREATE"); TTree *tree = new TTree("rtree","signal"); tree->Branch("A1",A1,"A1[1000]/D"); tree->Branch("A2",A2,"A2[1000]/D"); @@ -39,7 +63,7 @@ cout<Write(); f1->Close(); + + return 0; } diff --git a/data/dataDSR4/analysis_07_1.root b/data/dataDSR4/analysis_07_1.root index 1a9e7d6a47e2682a16771d4d4ddc8a2f2cc22530..ef57558475da2aaf6abd3097d218accac8e192d6 100644 Binary files a/data/dataDSR4/analysis_07_1.root and b/data/dataDSR4/analysis_07_1.root differ diff --git a/data/rawDataDSR4/NeuRad_test_07_1.root b/data/rawDataDSR4/NeuRad_test_07_1.root index 0edec10b15f7435cac6d9bcd5211b22b4f881ae7..8bca15a8cd3af82a37d0e48215d7c41a5d2c086f 100644 Binary files a/data/rawDataDSR4/NeuRad_test_07_1.root and b/data/rawDataDSR4/NeuRad_test_07_1.root differ diff --git a/dataClasses/AEvent.cpp b/dataClasses/AEvent.cpp index ca56e016fcb09de1c868b6b0a8f2ade98814d7b8..84a0b51eec5bc39846daa18ff8995c429b5903fc 100644 --- a/dataClasses/AEvent.cpp +++ b/dataClasses/AEvent.cpp @@ -55,6 +55,14 @@ void AEvent::ProcessEvent() { fTime[j] = time[j]; } +// SetGraphs(); + const Double_t zeroLevel = FindZeroLevel(); +// const Double_t zeroLevel = 0; + for(Int_t j = 0; j < fNPoints; j++) { + //fAmpPos[j] = amp[j]*(-1.) - zeroLevel; + fAmpPos[j] = fAmpPos[j] - zeroLevel; + } + Double_t maxAmp = 0.; Double_t maxAmpT = 0.; @@ -125,9 +133,8 @@ void AEvent::SetGraphs() { } void AEvent::SetCFD() { -// Double_t c = 0.5; //attenuation coefficient -// Int_t td = 5; //time of delay in points - Double_t level = 100.; //todo what is it? + + Double_t level = 100.; //is necessary to find cfd amplitude value closest to zero fGraphCFD->Set(fNPoints); @@ -139,9 +146,7 @@ void AEvent::SetCFD() { //CFD method if(i>fCFtimeDelay) { -// fAmpCFD[i] = fAmpPos[i]*cfRatio*(-1); fAmpCFD[i] = fAmpPos[i]*fCFratio*(-1); -// fAmpCFD[i] = fAmpCFD[i] + fAmpPos[i - timeDelay]; fAmpCFD[i] = fAmpCFD[i] + fAmpPos[i - fCFtimeDelay]; fGraphCFD->SetPoint(i, fTime[i], fAmpCFD[i]); } @@ -167,9 +172,31 @@ void AEvent::SetCFD() { fCFD = fTime[j]; } } - } +Double_t AEvent::FindZeroLevel(Int_t pmin, Int_t pmax) { + +// fGraphZero->Set(fNPoints); +// const Double_t *amp = fInputEvent->GetAmp(); +// const Double_t *time = fInputEvent->GetTime(); + SetGraphs(); + Double_t correction = 0; + TF1 *fit1 = new TF1("fit1","[0]"); + fit1->SetRange(pmin,pmax); + +// Warning("AEvent::FindZeroLevel", "Graph was not set"); + if (!fGraphSignal) { + Warning("AEvent::FindZeroLevel", "Graph was not set"); + return 0; + } +// fGraphSignal->Print(); + fGraphSignal->Fit(fit1,"RQN","goff"); +// fGraphSignal->Fit(fit1,"QR","goff"); + correction = fit1->GetParameter(0); +// printf("zero level %f\n", correction); + delete fit1; + return correction; + Double_t AEvent::GetfCFD() { return fCFD; } diff --git a/dataClasses/AEvent.h b/dataClasses/AEvent.h index 5898cec50f929a4772af85323069ce4b79959b4a..b3fb76ceb91e65c85b4ddf5e88cb7dbab7ddd4c3 100644 --- a/dataClasses/AEvent.h +++ b/dataClasses/AEvent.h @@ -17,6 +17,7 @@ #include "TString.h" #include "TTree.h" #include "TFile.h" +#include "TF1.h" //#include "TMath.h" @@ -43,10 +44,11 @@ private: TGraph *fGraphSignal; TGraph *fGraphCFD; + TGraph *fGraphZero; RawEvent *fInputEvent; //! - Double_t fCFratio; //! + Double_t fCFratio; //! Double_t fCFtimeDelay; //! public: @@ -59,20 +61,33 @@ public: Double_t GetOnefAmpPos(Int_t i); void SetRawDataFile(const char* inprawfile, const char* treename); void ProcessEvent(); -// void Integral() void SetInputEvent(RawEvent** event); - void SetCFratio(Double_t ratio) { fCFratio = ratio; }; - void SetCFtimeDelay(Double_t timeDelay) { fCFtimeDelay = timeDelay; }; + void SetCFratio(Double_t ratio) { fCFratio = ratio; }; + //CFD set attenuation coefficient + + void SetCFtimeDelay(Double_t timeDelay) { fCFtimeDelay = timeDelay; }; + //CFD set time delay (in points) void Reset(); //Resets arrays to zeros - TGraph* GetGraph() { - //todo + TGraph* GetGraphCFD() { + return fGraphCFD; - // return gSignal; } + //draws CFD graphs + + TGraph* GetGraphSignal() { + + return fGraphSignal; + } + //draws signal shape graphs + + Double_t FindZeroLevel(Int_t pmin = 10, Int_t pmax = 100); + //for zero level correction + //one parameter fit between pmin and pmax + //returns fit parameter i.e. number on which amplitude should be corrected private: void Init(); diff --git a/convertTektronix/IntegralCFD.c b/macros/IntegralCFD.cxx similarity index 100% rename from convertTektronix/IntegralCFD.c rename to macros/IntegralCFD.cxx diff --git a/macros/analyse.C b/macros/analyse.C index a648d693c41f2cc09869b0d0bf82f9084bdc0ea0..abde307df82eb13bcb421afc8bc0dfbd24016da6 100644 --- a/macros/analyse.C +++ b/macros/analyse.C @@ -13,7 +13,7 @@ void analyse() RawEvent *revent[noBranches]; // pointer to the array (of RawEvent class) in which raw data for each channel will be put for (Int_t j = 0; jSetBranchAddress(bName.Data(), &revent[j]); //read the tree tr with raw data and fill array revent with raw data } @@ -37,6 +37,9 @@ void analyse() for(Long64_t i = 0; i < nentries; i++) { tr->GetEntry(i); + if ( !(tr->GetEntry(i)%100) ) { + printf("Found event #%d\n", tr->GetEntry(i)); + } for (Int_t j = 0; jReset(); diff --git a/macros/testShowCFD.cxx b/macros/testShowCFD.cxx index 503cbeb1be5de3c826a10acab1d6fdb9d23005fc..b9a3c3589cc67174205772c1ac518539c92f88c0 100644 --- a/macros/testShowCFD.cxx +++ b/macros/testShowCFD.cxx @@ -17,7 +17,7 @@ void testShowCFD() for (Int_t i = 0; i < 10; i++) { gr[i] = 0; tr->GetEntry(i+kFirstEvent); - gr[i] = new TGraph(*revent->GetGraph()); + gr[i] = new TGraph(*revent->GetGraphCFD()); }//for over events diff --git a/macros/testShowGraphs.cxx b/macros/testShowGraphs.cxx index 127213dc519df3200776c71234c96ed8a8a20da3..b1a2d6cc5a999e7b143e816eb1633ac5fa7be182 100644 --- a/macros/testShowGraphs.cxx +++ b/macros/testShowGraphs.cxx @@ -9,24 +9,33 @@ void testShowGraphs() TTree *tr = (TTree*)fr.Get("atree"); AEvent *revent = new AEvent(); - tr->SetBranchAddress("Ach0.",&revent); + cout << tr->SetBranchAddress("Ach0.",&revent) << endl; TGraph *gr[10]; + cout << "warning" << endl; + + cout << tr->GetEntries() << endl; + //loop over events - for (Int_t i = 0; i < 10; i++) { + for (Long64_t i = 0; i < 10; i++) { gr[i] = 0; - tr->GetEntry(i+kFirstEvent); - gr[i] = new TGraph(*revent->GetGraph()); + cout << "warning 1" << endl; + cout << i+kFirstEvent << endl; +// tr->GetEntry(i+kFirstEvent); + tr->GetEntry(i); + cout << "warning 2" << endl; + gr[i] = new TGraph(*revent->GetGraphSignal()); }//for over events + cout << "warning 3" << endl; TCanvas *c1 = new TCanvas("c1","test",10,10,1000,600); c1->Divide(3,2); - for (Int_t i = 0; i < 6; i++) { - c1->cd(i+1); - gr[i]->Draw(); + for (Int_t k = 0; k < 6; k++) { + c1->cd(k+1); + gr[k]->Draw(); } // c1->cd(2); diff --git a/makefile b/makefile index a30f0f007bfabcfb84bcb13e861757ad1ed2dc65..bf7ba1a95ac9b57e879e45690b9f528be16c3161 100755 --- a/makefile +++ b/makefile @@ -24,11 +24,15 @@ PWD = $(shell pwd) DATA = $(PWD)/dataClasses CONVERTDRS4 = $(PWD)/convertDRS4 +CONVERTTEKTRONIX = $(PWD)/convertTektronix +CONVERTRAWTOANALYZED = $(PWD)/convertRawToAnalyzed -include $(DATA)/Data.mk all: libData.so \ - read_binary_DRS4 + read_binary_DRS4 \ + convertTektronix \ + convertRawToAnalyzed #ROOT html documentation, it will be done as a program which will be alsa compiled by this makefile, program will be as a last condition after all of the libraries @@ -67,6 +71,14 @@ read_binary_DRS4: $(CONVERTDRS4)/read_binary.cpp libData.so @echo 'Finished building target: $@' @echo ' ' +convertRawToAnalyzed: $(CONVERTRAWTOANALYZED)/analyse.cpp libData.so + @echo 'Building target: $@' + @echo 'Invoking: GCC C++ Linker' +# $(CC) -L $(ROOTLIBS) -shared -o"libData.so" $(DATAOBJS) $(DATALIBS) + $(CC) -o $(CONVERTRAWTOANALYZED)/convertRawToAnalyzed $(CONVERTRAWTOANALYZED)/analyse.cpp -lm `root-config --cflags --libs` -L $(PWD) -lData -Wl,-rpath,$(PWD) + @echo 'Finished building target: $@' + @echo ' ' + .PHONY: all clean # Each subdirectory must supply rules for building sources it contributes