//--------------------------start of FillTTreeAcq.cpp--------------------------- //oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo // Macro to record generated signals within a Tree o // o // Toni Kögler; Helmholtz-Zentrum Dresden-Rossendorf (HZDR); t.koegler@hzdr.de o // Version 1.0 (09.07.2013) o //ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo //macro to save vector in TTree //std. c includes #include #include #include //root includes #include "TTree.h" #include "TFile.h" #include "TBranch.h" #include "TSystem.h" //global Variable definition std::vector *pGlTime; std::vector > *pGlSignalVector; TTree *pGlSignalTree; TFile *pGlFile; using namespace std; //______________________________________________________________________________ void FillTTreeAcq() { //main method //define signal characteristics unsigned int NumEvents = 10000, NumChannels = 1, NumSamples = 1000, BaseLine = 100, Width = 300; double Offset[] = {0.4,0.3,0.2,0.1}; //init global signal vectors pGlTime = new vector(); pGlSignalVector = new vector >(); pGlSignalVector->resize(4); //define and init local signal vector vector *pTime = new vector (); vector *pSignal = new vector (); vector > *pSignalVector = new vector >(); //initializise the TFile and the TTree init_TTree(NumChannels, NumSamples); //fill the time vector for (unsigned int i_sa=0; i_sapush_back(i_sa); //define loop variables unsigned int Event, i_ch; //event loop for (Event=0; Eventpush_back(*pSignal); } //record the signals RecordSignals(*pTime, *pSignalVector); gSystem->ProcessEvents(); //clear the signal vector pSignalVector->clear(); } //write the TTree to TFile, close the TFile pGlSignalTree->Write(); pGlFile->Close(); } //______________________________________________________________________________ double init_TTree(unsigned int NumChannels, unsigned int NumSamples) { //method to init the TTree char tree_name[100] = ""; char tree_description[100] = ""; char branch_name[100] = ""; //(re-)create TFile pGlFile = new TFile("Data.root", "RECREATE"); //set name and description of the TTree sprintf(tree_name, "Signals"); sprintf(tree_description, "Tree containing signals from a generator"); //create the TTree pGlSignalTree = new TTree(tree_name, tree_description); pGlSignalTree->Branch("time", &pGlTime, NumSamples, 0); for (int i_ch=0; i_chBranch(branch_name, &pGlSignalVector->at(i_ch), NumSamples,0); } return 0; } //______________________________________________________________________________ void RecordSignals(vector pTime, vector< vector > pSignalVector) { //method to copy the produced signals into global variables and filling of //the tree with them //copy local to global vectors pGlTime = &pTime; pGlSignalVector = &pSignalVector; //ouput // for (int i_ch=0; i_ch<1; i_ch++) // for (int i_sa=0; i_saat(i_ch).size(); i_sa++) // cout << "Channel: " << i_ch << "\t" // << pGlSignalVector->at(i_ch).at(i_sa) << endl; //Fill the TTree pGlSignalTree->Fill(); //clear the global vectors pGlTime->clear(); pGlSignalVector->clear(); } //______________________________________________________________________________ void GenerateSignal(vector *pSignal, int Length, int BaseLine, int Width, double Offset) { // method to create a logic signal with noise //////////////////////////////////////////////////////////////////////////////// // <------------------------Length---------------------------------> // <---BaseLine----> // Offset ________________ _____________________________________ // H | | // e | | // i | | // g | | // h | | // t ------------- // <--Width--> //////////////////////////////////////////////////////////////////////////////// // double Height = gRandom->Uniform(0,-0.8); double Height = gRandom->Gaus(-0.4, 0.1); double noise; //clear vector pSignal->clear(); for (int sample=0; sampleGaus(Offset, fabs(0.01*Height)); pSignal->push_back(noise); } //signal else if (sampleGaus(Offset+Height, fabs(0.01*Height)); pSignal->push_back(noise); } //rest else { noise = gRandom->Gaus(Offset, fabs(0.01*Height)); pSignal->push_back(noise); } } return; } //----------------------------end of FillTTreeAcq.cpp---------------------------