/***************************************************************************** * * * lst2roor * * Program used to read lst files from the PTB experiment and * * store them in a TTree. * * The TTre is then read and histograms are created out of that * * Based on the c version written by LCM, updated by AN (Nov. 2007) + * * Changes by CR (March 2010): noted with ## * * Modified by FB (July 2014) * * * *****************************************************************************/ // Compile with: make // Launch with: lst2root /home/thomas/Fra_temp/PTB/Analysis/2013/Pu/3.5MeV lst lst2root/file.txt // CPP includes #include #include #include #include #include #include #include #include // C includes #include #include #include #include // ROOT includes // ROOT includes #include #include //#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define VERSION "v1.0_20140714"; #define EVENTSIZE 4L // It should mean that for every number written on the binary file, 4 words are allocated #define ADCSIZE 8192 // 8192 is it internal setting? //#define ADCSIZE 2048 // 8192 is it internal setting? //TF1 *fa2 = new TF1("fa1","0.135*(x-358)*(x-358)+340",270,500) //## Event format= 4 U16 words 1st=anode 2nd=grid 3rd=time void swapbytes(unsigned short *buf,int size) { int i; unsigned char t; union { unsigned short w; unsigned char b[2]; } v; for(i=0;iGet("t"); data data_tree_read; t->SetBranchAddress("adc1",&data_tree_read.adc1); t->SetBranchAddress("adc2",&data_tree_read.adc2); t->SetBranchAddress("adc3",&data_tree_read.adc3); t->SetBranchAddress("adc4",&data_tree_read.adc4); int nEntries=t->GetEntries(); TH1D*h1=new TH1D("h1","adc1",8192,0.,8192.); TH1D*h2=new TH1D("h2","adc2",8192,0.,8192.); TH1D*h3=new TH1D("h3","adc3",8192,0.,8192.); TH1D*h4=new TH1D("h4","adc4",8192,0.,8192.); h1->SetXTitle("Amplitude (ch)"); h1->SetYTitle("Counts"); h2->SetXTitle("Amplitude (ch)"); h2->SetYTitle("Counts"); h3->SetXTitle("Amplitude (ch)"); h3->SetYTitle("Counts"); h4->SetXTitle("Amplitude (ch)"); h4->SetYTitle("Counts"); for(int i=0;iGetEntry(i); /// histogram h1->Fill(data_tree_read.adc1); h2->Fill(data_tree_read.adc2); h3->Fill(data_tree_read.adc3); h4->Fill(data_tree_read.adc4); } c1->cd(); h1->Draw(""); c2->cd(); h2->Draw(""); c3->cd(); h3->Draw(""); c4->cd(); h4->Draw(""); h1->Write("",TObject::kOverwrite); h2->Write("",TObject::kOverwrite); h3->Write("",TObject::kOverwrite); h4->Write("",TObject::kOverwrite); } int run(const char* path, const char* lstdirectory,const char* lstfilename) { // gSystem->Load("libTree.so"); // Open a TFile (it is the equivalent of a folder) where you are going to store // the info retrieved from the lst data and some histograms TFile*f=new TFile("Foreground2.root","recreate"); //<---------------- // Associate a structure to the TTree that you are going to create data data_tree; // Some variables FILE *inp, *out, *list; char cycle[80], listname[80], outname[80], inpName[80]; unsigned short nread, event[EVENTSIZE]; int i,k; int *adc1, *adc2, *adc3, *adc4; // Open the txt file containing a list of *.lst files to analyze printf("\n Open the file containing the *lst file names to treat\n\n"); sprintf(inpName, "%s/%s", path, lstfilename); printf(" Cycles' file: %s\n", inpName); if((inp=fopen(inpName,"r"))==NULL){ printf(" ERROR: Cannot open cycles file.\n"); return 1; } // Create an outup file where you are going to write the content of the //*.lst files processed in such a way to be equivalent to the *.his files sprintf(outname,"%s", "Comp.dat"); if((out=fopen(outname,"w"))==NULL){ printf(" ERROR: Cannot open cycles file.\n"); return 1; } // Create 3 arrays where you will store the info retrieved from the *.lst files for 3 ADCs. // ADCSIZE/4 is used because you know that every ADC is configured to store data in 2048 ch. //(you know this by looking at how many rows the *.his files have) adc1 = (int*)malloc(sizeof(int)*ADCSIZE); adc2 = (int*)malloc(sizeof(int)*ADCSIZE); adc3 = (int*)malloc(sizeof(int)*ADCSIZE); adc4 = (int*)malloc(sizeof(int)*ADCSIZE); // Initialize the arrays and a counter k=-1; for(i=0; iBranch("adc1",&data_tree.adc1,"adc1/I"); t->Branch("adc2",&data_tree.adc2,"adc2/I"); t->Branch("adc3",&data_tree.adc3,"adc3/I"); t->Branch("adc4",&data_tree.adc4,"adc4/I"); while((fscanf(inp, "%s", cycle))>0){// Loop on the *.lst files to open (=lines in the file containing the *.lst filenames) k++; sprintf(listname, "%s/%s/%s", path, lstdirectory, cycle); printf("=== %s \n",listname); if((list=fopen(listname,"rb"))==NULL){ printf(" ERROR: Cannot open list file %s\n", listname); return 1; } while((nread=fread(event,sizeof(unsigned short), EVENTSIZE, list))>0){ // While over events in a listfile; read one event after the other swapbytes(event, EVENTSIZE); for(i=2; iFill(); // Process the content of the *.lst files to obtain the *.his files if((unsigned int)event[0]!=0) adc1[(unsigned int)event[0]]++; if((unsigned int)event[1]!=0) adc2[(unsigned int)event[1]]++; if((unsigned int)event[2]!=0) adc3[(unsigned int)event[2]]++; if((unsigned int)event[2]!=0) adc4[(unsigned int)event[3]]++; } // End of while for events in a *.lst file printf(" Cycle %s sorted.\n", listname); for(i=0;icd(); t->Write("",TObject::kOverwrite); process_TTree(f); f->Close(); fclose(inp); fclose(out); printf("Bye \n"); }