#define hit_analyse_cxx #include "hit_analyse.h" int main(int argc, char **argv){ opendatafiles(argc, argv); histograms(argc, argv); analyse(argc, argv); closedatafiles(); return 0; } int opendatafiles(int argc, char ** argv){ if (argc>2){ //open bpm data file filename = Form("%s%s.dat",argv[1],argv[2]); file.open(filename, ifstream::in | ifstream::binary); fileframesize = getFileSize(filename) / ( 4*sizeof(BufferData) ); if (fileframesize>0){ std::cout << "Number of frames in data file: " << fileframesize << std::endl;} else { std:cout << "BPM .dat dile not found." << endl; return -1;} //bpm data timestamps timestampfilename = Form("%s%s_timestamp.csv",argv[1],argv[2]); timestampfile.open(timestampfilename, ifstream::in); if (!timestampfile.is_open()){ printf("timestamp.csv did not open.\n"); ethercat = false; //return -1; //file could not be opened } //open ethercat file if (argc>3){ ethercatfile = argv[3]; tree2 = new TTree("t2", "t2"); std::cout << " Loading Ethercat data." << std::endl; tree2->ReadFile(ethercatfile, "RELTIME2/D:IC1/D:MW1_POSX/D:MW1_POSY/D:ANALOG_IN1/D:ENERGY_INDEX/D:INTENSITY_INDEX/D:ION-SORT/D:TIME2/D", '\t'); std::cout << "Ethercat data loaded." << std::endl; tree2->Print(); } //open amplitude offset correction file if (argc>4){ offsetfilename = Form("%s",argv[4]); offsetfile.open(offsetfilename, ifstream::in); if (!offsetfile.is_open()){ printf("no offset.txt file found\n"); // return -1; //file could not be opened } } dataptr = new BufferData(); return 1; } int closedatafiles(int argc, char ** argv){ if (file.is_open()) file.close(); if (timestampfile.is_open()) timestampfile.close(); if (offsetfile.is_open()) offsetfile.close(); rootFile->Write(); rootFile->Close(); } int analyse(int argc, char **argv) { int bkg_frames = 1000; set_background_v1(bkg_frames); for (int frame = 0; frame< fileframesize - bkg_frames; frame++ ){ if (frame%10000==0) std::cout << "Frame: " << frame << " (" <sync_frame.device_nr==boardnumber){ for (int j = 1; j<128;j++){ //subtract the background from the data board.channel_amp[j] = dataptr->sensor_data[j] - board_b_bkg[boardnumber].channel_amp[j]; // std::cout << j << " " << board.channel_amp[j] << " " << dataptr->sensor_data[j] << std::endl; //sum the signal across channels board.integratedsignalamp += board.channel_amp[j]; //find the peak channel if (board.channel_amp[j]> board.maxchannel_amp) { board.maxchannel = j; board.maxchannel_amp = board.channel_amp[j]; // cout << maxchannel_b0 << " " <IsOpen() ) printf("ROOT file opened successfully\n"); } else return -1; TTree *rootTree = new TTree("t","HIT Data Root Tree"); } void set_background_v1(int max_frames){ for (int j = 0; j<128; j++){ for (int k = 0; k<4; k++){ board_b_bkg[k].channel_amp[j] = 0.; } } for (int i = 0;isync_frame.device_nr==boardnumber){ for (int j = 1; j<128;j++){ board_b_bkg[boardnumber].channel_amp[j] += double(dataptr->sensor_data[j]) / double(max_frames); // std::cout << j << " " << board.channel_amp[j] << " " << dataptr->sensor_data[j] << std::endl; } } else std::cerr << "Error reading board data." << std::endl; } } } beamRecon beamreconstruction(bpm_frame_v1 frametoanalyse, double threshold = 50.){ ///////////////// linear regression using Integration by parts of gaussian function. beamRecon beam; double SumT, SumS, SumS2, SumST, SumT2, SumY, SumYS, SumYT, sigmaABC, muABC,p,c, b, b_den, b_num, SumYYP, SumYYM, MeanY; TMatrixD M1(3,3); TMatrixD M1inv(3,3); TVectorD ABC(3); TVectorD M2(3); vector signal_list; vector channel_list; SumY = 0.; SumS = 0.; SumT = 0.; SumS2 = 0.; SumST = 0.; SumT2 = 0.; SumYS = 0.; SumYT = 0.; b_den = 0.; b_num = 0.; b = 0.; p = 0.; c = 0.; SumYYM = 0.; SumYYP = 0.; MeanY = 0.; // const int array_length = sizeof(frametoanalyse.channel_amp)/sizeof(double); const int array_length = 128; for (int i = 0; i< array_length; i++){ if (frametoanalyse.channel_amp[i]>=threshold) { signal_list.push_back(frametoanalyse.channel_amp[i]); channel_list.push_back(i);//correct for actual detector position } } const int vector_length = channel_list.size(); if (vector_length<=3) return beam; double S[vector_length]; double T[vector_length]; for(int k=0; k y = b*exp(-p*(x-c)*(x-c)) p = -ABC(0)/2.; c = -ABC(1)/ABC(0); for(int k=0; k