linux 比较两个文件的差异

linux 比较两个文件的差异

一般来说在开发的时候,维护两个文件版本显然要比在文件中做一个if-else更加复杂;当你升级其中一个文件的时候,另一个文件并不能很好地同步。

meld

博客设置 --安装meld.

// deepin
sudo apt install meld

比较两个C++ 的文件

// pmt
/*******************************************************************************
 *
 * AUTHOR:ZHAO RONG
 * DATE:20180521
 * VERSION: V1.0
 * DESCRIPTION: this program will
 * based on the original file generateroot.cc
 *
 *
 *
 *
********************************************************************************/
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include "TTree.h"
#include "TFile.h"
#include "TLine.h"
#include "TH1F.h"
#include "TF1.h"
#include "Math/WrappedTF1.h"    //to wrapp the nfunction
#include "TH2D.h"
#include "TCanvas.h"
#include "TLegend.h"
#include "TStyle.h"
#include "TLatex.h"
#include "TMath.h"
#include "TFrame.h"
#include "TGraph.h"
#include "TBox.h"
#include "TPaveStats.h"
#include "TPaveLabel.h"
#include "TImage.h" //to display logo
#include "NIMmodel.h"
using namespace std;
int main(int argc,char  ** argv){

//**********************************************************varibles declaration***********************************************************//
string sys_id_s="1";   			//the ID of testing system
string mass_num_s="111";		//the mass number of each batch
string umass_num_s="0";		//the mass number of each batch
string channel_num_s="111";		//the channel number or the drawer number in the container
TString pmt_id="EA2194";		//the serial number(SN) of each PMTint
string lt_tag_s="1";			//light intensity tag,1 for 0.1pe,2 for setpoint 3000,3 for laser
TString input_file="/tmp/sys1_mass1_ch111_EA0339_1.txt";	//the input data file's absolute directory
string pmt_type_s="0";			//the  0 for hamamatsu-PMT(R12860) and 1 for MCP-PMT
string vendor_HV_s="1870";		//the working high voltage provided by vendor
string fit_HV_s="1907";			//the working high voltage fitted by container
string base_type_s="0";			//the mcp base type tag,0 for small current,1 for large current
TString test_date="2018-01-24";		//the date of testing
TString	var_rese="0";			//reserved variable
TString outfile_dir="./results";	//the output directory
string cont_dcr_s="35.0";		//the container dcr
string vendor_ap_s="1.0";		//the vendor_afterpulse
string vendor_dcr_s="35.0";		//the vendor_dark count rate
string vendor_qe_s="27.0";		//the vendor_quantum efficiency
string vendor_tts_s="15.";		//the vendor_transit time spread
string vendor_pvr_s="5.0";		//the vendor_peak-valley ratio
string vendor_res_s="30";		//the vendor_resolution
string vendor_rt_s="7.";		//the vendor_rise time
string vendor_ft_s="8.";		//the vendor_fall time
string test_times_s="1";		//test times till now
string pmtnum_s="0";		//pmt num,SN without EA or PA
/********************************* reading parameters *****************************************/
if (argc ==1){} 			//do nothing
else	  				//read parameters as filenames
    {
   for(int i=1;i<argc;i++)
     {   if(strcmp(argv[i],"-s")== 0){i++;sys_id_s=argv[i];}  		//the testing system id
         if(strcmp(argv[i],"-m")== 0){i++;mass_num_s=argv[i];}  		//the mass number
         if(strcmp(argv[i],"-c")== 0){i++;channel_num_s=argv[i];}  	//the channel number
         if(strcmp(argv[i],"-n")== 0){i++;pmt_id=argv[i];}  		//the PMT SN
         if(strcmp(argv[i],"-l")== 0){i++;lt_tag_s=argv[i];}  		//the light intensity
         if(strcmp(argv[i],"-i")== 0){i++;input_file=argv[i];}  	//the input file
         if(strcmp(argv[i],"-t")== 0){i++;pmt_type_s=argv[i];}  		//the pmt type
         if(strcmp(argv[i],"-v")== 0){i++;vendor_HV_s=argv[i];}  		//the vendor HV
         if(strcmp(argv[i],"-f")== 0){i++;fit_HV_s=argv[i];}  		//the fit HV
         if(strcmp(argv[i],"-b")== 0){i++;base_type_s=argv[i];}		//the base type
         if(strcmp(argv[i],"-d")== 0){i++;test_date=argv[i];}  		//the test date
         if(strcmp(argv[i],"-o")== 0){i++;outfile_dir=argv[i];}		//the output directory
         if(strcmp(argv[i],"-cd")== 0){i++;cont_dcr_s=argv[i];}		//the container dcr
         if(strcmp(argv[i],"-vq")== 0){i++;vendor_qe_s=argv[i];}		//the vendor_qe
         if(strcmp(argv[i],"-va")== 0){i++;vendor_ap_s=argv[i];}		//the vendor_ap
         if(strcmp(argv[i],"-vd")== 0){i++;vendor_dcr_s=argv[i];}		//the vendor_dcr
         if(strcmp(argv[i],"-vt")== 0){i++;vendor_tts_s=argv[i];}		//the vendor_tts
         if(strcmp(argv[i],"-vr")== 0){i++;vendor_rt_s=argv[i];}		//the vendor_rise time
         if(strcmp(argv[i],"-vf")== 0){i++;vendor_ft_s=argv[i];}		//the vendor_fall time
         if(strcmp(argv[i],"-vp")== 0){i++;vendor_pvr_s=argv[i];}		//the vendor_pv
         if(strcmp(argv[i],"-ve")== 0){i++;vendor_res_s=argv[i];}		//the vendor_resolution
         if(strcmp(argv[i],"-pm")== 0){i++;pmtnum_s=argv[i];}		//the pmtnum
         if(strcmp(argv[i],"-um")== 0){i++;umass_num_s=argv[i];}		//the umass_num
         if(strcmp(argv[i],"-tt")== 0){i++;if((argv[i]))test_times_s=argv[i];else test_times_s="0";}		//the test times 
        else if(strcmp(argv[i],"-r")== 0){i++;var_rese=argv[i];}	// reserved variable
      }
   }
/**************************************** type convertion *************************************/
int sys_id=atoi(sys_id_s.c_str());
int channel_num=atoi(channel_num_s.c_str());
int mass_num=atoi(mass_num_s.c_str());
int umass_num=atoi(umass_num_s.c_str());
int lt_tag=atoi(lt_tag_s.c_str());
int pmt_type=atoi(pmt_type_s.c_str());
int pmtnum=atoi(pmtnum_s.c_str());
int vendor_HV=atoi(vendor_HV_s.c_str());
int fit_HV=atoi(fit_HV_s.c_str());
int base_type=atoi(base_type_s.c_str());
int test_times=atoi(test_times_s.c_str());
float vendor_qe=atof(vendor_qe_s.c_str());
float vendor_qeout=atof(vendor_qe_s.c_str());
if(vendor_qeout>100)vendor_qeout=vendor_qeout/1000.;
float cont_dcr=atof(cont_dcr_s.c_str())/1000.;
float vendor_ap=atof(vendor_ap_s.c_str());
float vendor_dcr=atof(vendor_dcr_s.c_str());
if(pmt_type==0)vendor_dcr=vendor_dcr/1000.;
float vendor_tts=atof(vendor_tts_s.c_str());
float vendor_rt=atof(vendor_rt_s.c_str());
float vendor_ft=atof(vendor_ft_s.c_str());
float vendor_pvr=atof(vendor_pvr_s.c_str());
float vendor_res=atof(vendor_res_s.c_str());
/********************************** variables declaration *************************************/
TString outroot_name="results/root/sys"+sys_id_s+"_mass"+umass_num_s+"_channel"+channel_num_s+"_sn"+pmt_id+"_lt"+lt_tag_s+".root";		//name of output .root file  ::::  sys.mass.channel.sn.lt.root
TString outroot_all_name="results/root/all_info.root";		//name of output .root file  ::::  sys.mass.channel.sn.lt.root
TString outtxt_name="results/txt/sys"+sys_id_s+"_mass"+umass_num_s+"_channel"+channel_num_s+"_sn"+pmt_id+"_lt"+lt_tag_s+".txt";		//name of output .txt file   ::::  sys.mass.channel.sn.lt.txt
TString outtxt_sighit_name="results/trigtxt/sys"+sys_id_s+"_mass"+umass_num_s+"_channel"+channel_num_s+"_sn"+pmt_id+"_lt"+lt_tag_s+"sighit.txt";		//name of output .txt file   ::::  sys.mass.channel.sn.lt.txt
TString outtxt_all_name="results/txt/all_info.txt";		//name of output .txt file   ::::  all.txt
TString outpng_name="results/png/sys"+sys_id_s+"_mass"+umass_num_s+"_channel"+channel_num_s+"_sn"+pmt_id+"_lt"+lt_tag_s+".png";		//name of output .png file   ::::  sys.mass.channel.sn.lt.png
TString outpdf_name="results/pdf/sys"+sys_id_s+"_mass"+umass_num_s+"_channel"+channel_num_s+"_sn"+pmt_id+"_lt"+lt_tag_s+".pdf";		//pdf file contain 100 sample waveforms   ::::	sys.mass.channel.sn.lt.pdf
TString outpdf_name_start="results/pdf/sys"+sys_id_s+"_mass"+umass_num_s+"_channel"+channel_num_s+"_sn"+pmt_id+"_lt"+lt_tag_s+".pdf[";		//pdf file contain 100 sample waveforms   ::::	sys.mass.channel.sn.lt.pdf
TString outpdf_name_end="results/pdf/sys"+sys_id_s+"_mass"+umass_num_s+"_channel"+channel_num_s+"_sn"+pmt_id+"_lt"+lt_tag_s+".pdf]";		//pdf file contain 100 sample waveforms   ::::	sys.mass.channel.sn.lt.pdf
TString com_str="sys"+sys_id_s+"_mass"+umass_num_s+"_channel"+channel_num_s+"_SN"+pmt_id+"_lt"+lt_tag_s;
/****************************************** declaration**********************************************/
int npoint=521;		//each waveform have 521 points,1ns/point
int peak_threshold=3;	//the 3mV threshold to search signal
int inte_window=50;	//the 60ns integration window width
int nevent=0;		//the event counter
int tcount=0;		//time count in a waveform
int rise_time_start=0;	//the start position of rise-time
int rise_time_end=npoint;	//the end position of rise-time
int rise_time=0;	//rise time of one signal
int fall_time_start=0;	//the start position of fall-time
int fall_time_end=npoint;	//the end position of fall-time
int fall_time=0;	//fall time of one signal
int signal_count=0;	//signal counter
int sig_inwindow_count=0; //signals in the integral window
int rise_position=0;	//the rise position of the signal through the threshold
int fall_position=0;	//the fall position of the signal through the threshold
int sig_min_position=0;	//the minimum position of signal wave
int inte_start=0;	//the start position of integration window
int inte_end=npoint;		//the end position of integration window
int fwhm=0;		//the full width of maximum
int fwhm_start=0;	//the start position of fwhm
int fwhm_end=npoint;		//the end postion of fwhm
int sig_skip=26;		//the width to skip the found signal
int rise_edge_thrd=4;		//the points to find as a raising edge
int peak_pos=0;			//the peak position in the average waveform
int wave2d_ymin=-40;		//the min of y axis of 2d histogram
int wave2d_ymax=40;		//the max of y axis of 2d histogram
int local_count=0;		//local count to calculate baseline
int peak_count=0;		//peak numbers in one waveform
int npoint_hist=npoint-31;	//histgram points = 510 ns
int sig_tag=0;    //the flag of signal
int pe1min_conv=0;
int predcr_count=0;
int corg_count=0;
int hit_time=0;
int ped_count=0;
int noped_count=0;
int pdf_count=0;
int deltaN0=0;
int pass_count=0;
int dltag=0;
//int p1p_r=0;			//0.1 peak amplitude raising position
//int p5p_r=0;			//0.5 peak amplitude raising position
//int p9p_r=0;			//0.9 peak amplitude raising position
//int p1p_f=0;			//0.1 peak amplitude falling position
//int p5p_f=0;			//0.5 peak amplitude falling position
//int p9p_f=0;			//0.9 peak amplitude falling position

double amplitude[npoint];	//the waveform array
double average_wave[npoint];	//the average wave
double sig_profile[500]={0};	//the signal profile
double peak_val=0;		//the peak value in the average waveform
double QDC_sig=0;		//signal charge integral
double QDC_dn=0;		//dark noise integral
double baseline=0;		//the baseline of each
double baselinenew=0;
double baseline_sigma=0;
double QDC_sig1=0;
double QDC_dn1;
double average_baseline=0;	//the average baseline
double sig_min_value=0;		//the min value of signal
double signal_amp=0;
double gain=0;			//the gain
double gain_err=0;			//the gain
double pvratio=0;		//the peak-valley ratio
double snr=0;			//the signal noise ratio
double soft_dcr=0;		//the dcr by Algorithm
double signal_charge=0;		//charge integral of each signal found in or out of window
double pe0sigma=0;
double pe0mean=0;
double pe0mean_err=0;
double pe1sigma=0;
double pe0max=0;
double pe1max=0;
double pe1max_error=0;
double pe1resolution=0;
double ave_charge=0;
double rise_position_mean=0;
double fall_position_mean=0;
double rise_time_mean=0;
double fall_time_mean=0;
double fwhm_mean=0;
double pv_amp=0;
double amp_mean=0;
double nsnt=0;
double pde=0;
double pde_err=0;
double corf=0;
double wave_amp=0;
double wave_charge=0;
double mu=0;
double valley_pos=0;
double mufactor_sys1[36]={2.032,2.916,2.852,2.451,2.613,3.418,2.817,3.358,3.12,2.556,2.866,3.195,2.954,2.333,3.722,1.729,2.566,4.141,1.957,2.32,2.98,2.034,2.983,3.594,2.477,2.375,3.59,3.214,2.9398,2.87,0,2.219,2.758,2.378,2.059,2.622};
double mufactor_sys1_new[36]={2.224,3.138,3.127,2.599,2.862,3.461,2.749,3.274,3.416,2.532,3.099,3.447,3.11,2.307,3.718,1.877,2.616,4.249,2.281,2.661,3.437,2.354,3.271,4.047,2.821,2.644,3.961,3.632,3.259,3.173,0,2.54,3.105,2.6,2.443,3.035};
double mufactor1_sys1[36]={.4151,.4458,.3871,.4137,.3774,.4271,.354,.4112,.4024,.3986,.4279,.4105,.4125,.3751,.3603,.4653,.3992,.3566,.414,.4168,.5272,.4214,.378,.3807,.391,.3487,.4386,.4347,.4169,.4565,0,.4936,.5647,.4429,.4152,.4295};
double mufactor1_sys1_new[36]={.4151,.4458,.3871,.4137,.3774,.4271,.354,.4112,.4024,.3986,.4279,.4105,.4125,.3751,.3603,.4653,.3992,.3566,.414,.4168,.5272,.4214,.378,.3807,.391,.3487,.4386,.4347,.4169,.4565,0,.4936,.5647,.4429,.4152,.4295};
double self_factor_sys1[36]={49.12,34.55,35.94,41.44,38.79,30,37.85,30.21,31.63,40.66,34.42,31.07,33.99,43.15,26.96,57.66,39.21,24,49.4,42.07,32.05,48.32,31.96,26.47,38.99,41.4,26.76,30.48,32.27,33.06,0,42.55,34.48,40.65,45.35,35.7};
//double nsntfactor_sys1[36]={3.206,3.254,3.045,3.26,2.948,3.274,2.71,3.198,3.187,2.937,3.267,3.157,3.174,2.882,2.735,3.397,3.119,2.774,3.142,3.231,3.928,3.264,2.996,3.007,3.089,2.734,3.465,3.331,3.246,3.583,0,3.822,4.312,3.383,3.258,3.379};
//double mufactor1_sys1_new[]={};
double mufactor_sys2[36]={4.614,7.479,4.244,3.866,4.646,3.808,5.437,7.374,4.861,5.279,6.761,4.395,4.058,2.668,5.211,2.842,4.510,3.753,5.458,5.336,3.456,6.476,4.083,2.896,6.501,4.370,1.660,4.222,5.133,6.038,4.739,4.255,4.452,4.672,4.110,3.287};
double mufactor1_sys2[36]={4.614,7.479,4.244,3.866,4.646,3.808,5.437,7.374,4.861,5.279,6.761,4.395,4.058,2.668,5.211,2.842,4.510,3.753,5.458,5.336,3.456,6.476,4.083,2.896,6.501,4.370,1.660,4.222,5.133,6.038,4.739,4.255,4.452,4.672,4.110,3.287};
//double mufactor1_sys2[36]={2.032,2.916,2.852,2.451,2.613,3.418,2.817,3.358,3.12,2.556,2.866,3.195,2.954,2.333,3.722,1.729,2.566,4.141,1.957,2.32,2.98,2.034,2.983,3.594,2.477,2.375,3.59,3.214,2.9398,2.87,0,2.219,2.758,2.378,2.059,2.622};
double mufactor[36]={0};
if(sys_id==1&&lt_tag==2&&mass_num<145){for(int i=0;i<36;i++)mufactor[i]=mufactor_sys1[i];}
if(sys_id==1&&lt_tag==2&&mass_num>=145){for(int i=0;i<36;i++)mufactor[i]=mufactor_sys1_new[i];}
//if(sys_id==1&&lt_tag==2&&mass_num<145){for(int i=0;i<36;i++)mufactor[i]=100./self_factor_sys1[i];}
//if(sys_id==1&&lt_tag==2&&mass_num>=145){for(int i=0;i<36;i++)mufactor[i]=100./self_factor_sys1[i];}
if(sys_id==1&&lt_tag==1&&mass_num<145){for(int i=0;i<36;i++)mufactor[i]=mufactor1_sys1[i];}
if(sys_id==1&&lt_tag==1&&mass_num>=145){for(int i=0;i<36;i++)mufactor[i]=mufactor1_sys1_new[i];}
/sys2
if(sys_id==2&&lt_tag==2){for(int i=0;i<36;i++)mufactor[i]=mufactor_sys2[i];}
if(sys_id==2&&lt_tag==1){for(int i=0;i<36;i++)mufactor[i]=mufactor1_sys2[i];}
//factors for different light intensity
double factors1[10]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};
double factors2[10]={2.,1.,1.4,2.3,1.,1.,1.,1.,1.,1.};
//0--ampwave,1--qdc,2--amp_spec,3--charge2d
double factors3[10]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};
double factors[10]={1.,1.,1.,1.,1.,1.,1.,1.,1.,1.};
if(lt_tag==2){for(int i=0;i<10;i++)factors[i]=factors2[i];}
/************************************************** name of histograms *********************************************************/
TH2D *Hist_wave2d = new TH2D("Hist_wave2d",com_str+"waveform2d",npoint,0,npoint,800,wave2d_ymin*factors[0],wave2d_ymax);	//2D histogram
TH2D *Hist_amp2d = new TH2D("Hist_amp2d",com_str+"amp2d",npoint,0,npoint,800,-2,20*factors[3]);	//2D histogram
TH2D *Hist_cnn = new TH2D("Hist_cnn",com_str+"cnn2d",2,0,2,2,0,2);	//2D histogram
TH2D *Hist_charge2d = new TH2D("Hist_charge2d",com_str+"charge2d",npoint,0,npoint,800,-10,12*factors[3]);	//2D histogram
TH2D *Hist_amp_qdc = new TH2D("amp_qdc_cor",com_str+"amplitude_qdc",100,-3.,40,500,0,8);	//amplitude QDC correlation
TH1D *Hist_tem_rise_pos=new TH1D("Hist_tem_rise_pos",com_str+"tmp_rise_pos",npoint_hist,0,npoint_hist);		//temperary histogram to get the integral window
TH1D *Hist_ave_waveform=new TH1D("Hist_ave_waveform",com_str+"average_waveform",npoint_hist-11,0,npoint_hist);		//the average waveform
TH1D *Hist_rise_position=new TH1D("Hist_rise_position",com_str+"rise_position",(int)(npoint_hist/2.),0,npoint_hist);		//rise_position through the threshold
TH1D *Hist_fall_position=new TH1D("Hist_fall_position",com_str+"fall_position",npoint_hist,0,npoint_hist);		//fall_position through the threshold
TH1D *Hist_fall_time_start=new TH1D("Hist_fall_time_start",com_str+"fall_time_start",npoint_hist,0,npoint_hist);	//fall_time start position
TH1D *Hist_fall_time_end=new TH1D("Hist_fall_time_end",com_str+"fall_time_end",npoint_hist,0,npoint_hist);		//fall_time end position
TH1D *Hist_rise_time_start=new TH1D("Hist_rise_time_start",com_str+"rise_time_start",npoint_hist,0,npoint_hist);	//rise_time start position
TH1D *Hist_rise_time_end=new TH1D("Hist_rise_time_end",com_str+"rise_time_end",npoint_hist,0,npoint_hist);		//rise_time end position
TH1D *Hist_fwhm_start=new TH1D("Hist_fwhm_start",com_str+"fwhm_start",npoint_hist,0,npoint_hist);			//fwhm start position
TH1D *Hist_fwhm_end=new TH1D("Hist_fwhm_end",com_str+"fwhm_end",npoint_hist,0,npoint_hist);				//fwhm end position
TH1D *Hist_sig_min_position=new TH1D("Hist_sig_min_position",com_str+"sig_min_position",npoint_hist,0,npoint_hist);	//signal peak position
TH1D *Hist_sig_min_value=new TH1D("Hist_sig_min_value",com_str+"sig_min_value",100,wave2d_ymin*factors[0],1.*wave2d_ymax);	//signal min value
TH1D *Hist_sig_amplitude=new TH1D("Hist_sig_amplitude",com_str+"sig_amplitude",100,-3.,40.*factors[0]);				//signal amplitude
TH1D *Hist_fwhm=new TH1D("Hist_fwhm",com_str+"fwhm",40,0,40);								//fwhm histogram
TH1D *Hist_rise_time=new TH1D("Hist_rise_time",com_str+"rise_time",40,0,40);						//rise time histogram
TH1D *Hist_fall_time=new TH1D("Hist_fall_time",com_str+"fall_time",40,0,40);						//fall time histogram
TH1D *Hist_QDC_sig=new TH1D("QDC_sig",com_str+"signal-QDC",500,-2,8);
TH1D *Hist_QDC_dn=new TH1D("QDC_dn",com_str+"noise-QDC",200,-20,20);
TH1D *Hist_QDC_sig1=new TH1D("QDC_sig1",com_str+"sig-QDC-avebaseline",200,-2.,23*factors[1]);
TH1D *Hist_QDC_sig1_conv=new TH1D("QDC_sig1_conv",com_str+"sig-QDC-convoluted",200,-2.,23*factors[1]);
TH1D *Hist_QDC_dn1=new TH1D("QDC_dn1",com_str+"noise-QDC-avebaseline",200,-20,20);
TH1D *Hist_sQDC=new TH1D("sQDC",com_str+"QDC_signal",npoint_hist,-2,23);
TH1D *Hist_nQDC=new TH1D("nQDC",com_str+"QDC_nosignal",npoint_hist,-2,23);
TH1D *Hist_peakspec=new TH1D("hist_peakspec",com_str+"amp_spec",100,-20,80);
TH1D *Hist_sig_profile=new TH1D("Hist_sig_profile",com_str+"signal_profile1d",1.5*inte_window,0,1.5*inte_window);       //signal profile histgram
TH2D *Hist_sig_profile2d = new TH2D("Hist_sig_profile2d",com_str+"sig_profile2d",1.5*inte_window,0,1.5*inte_window,900,wave2d_ymin*factors[0],wave2d_ymax);
TH1D *Hist_check1d=new TH1D("check1d",com_str+"check_waveform",npoint_hist,0,npoint_hist);
/**************************************************** other ROOT bojects ********************************************************/
TFile *outroot_file=new TFile(outroot_name,"recreate");									//the output root file that contain all the information
TTree *pmt_tree=new TTree("pmt_tree",com_str+"signals");										//the tree contain the key parameters
TTree *auxiliary_info=new TTree("auxiliary_info",com_str+"auxiliary info");
TTree *performance_info=new TTree("performance_info",com_str+"performance_parameters");
pmt_tree->Branch("signal_charge",&signal_charge,"signal_charge/D");
pmt_tree->Branch("baseline",&baseline,"baseline/D");
pmt_tree->Branch("rise_position",&rise_position,"rise_position/I");
pmt_tree->Branch("fall_position",&fall_position,"fall_position/I");
pmt_tree->Branch("sig_min_pos",&sig_min_position,"sig_min_position/I");
pmt_tree->Branch("signal_amp",&signal_amp,"signal_amp/D");
pmt_tree->Branch("rise_time",&rise_time,"rise_time/I");
pmt_tree->Branch("fall_time",&fall_time,"fall_time/I");
pmt_tree->Branch("fwhm",&fwhm,"fwhm/I");
auxiliary_info->Branch("sys_id",&sys_id,"sys_id/I");
auxiliary_info->Branch("pmt_id",&pmt_id,"pmt_id/C");
auxiliary_info->Branch("umass_num",&umass_num,"umass_num/I");
auxiliary_info->Branch("channel_num",&channel_num,"channel_num/I");
auxiliary_info->Branch("lt_tag",&lt_tag,"lt_tag/I");
auxiliary_info->Branch("pmt_type",&pmt_type,"pmt_type/I");
auxiliary_info->Branch("base_type",&base_type,"base_type/I");
auxiliary_info->Branch("vendor_HV",&vendor_HV,"vendor_HV/I");
auxiliary_info->Branch("fit_HV",&fit_HV,"fit_HV/I");
auxiliary_info->Branch("inte_start",&inte_start,"inte_start/I");
auxiliary_info->Branch("inte_end",&inte_end,"inte_end/I");
auxiliary_info->Branch("average_baseline",&average_baseline,"average_baseline/D");
auxiliary_info->Branch("test_times",&test_times,"test_times/I");
//performance_info->Branch("Hist_wave2d",&Hist_wave2d,128000,0);
performance_info->Branch("vendor_qe",&vendor_qe,"vendor_qe/f");
performance_info->Branch("vendor_ap",&vendor_ap,"vendor_ap/f");
performance_info->Branch("vendor_dcr",&vendor_dcr,"vendor_dcr/f");
performance_info->Branch("vendor_tts",&vendor_tts,"vendor_tts/f");
performance_info->Branch("vendor_rt",&vendor_rt,"vendor_rt/f");
performance_info->Branch("vendor_ft",&vendor_ft,"vendor_ft/f");
performance_info->Branch("vendor_res",&vendor_res,"vendor_res/f");
performance_info->Branch("vendor_pvr",&vendor_pvr,"vendor_pvr/f");
performance_info->Branch("cont_dcr",&cont_dcr,"cont_dcr/f");
performance_info->Branch("soft_dcr",&soft_dcr,"soft_dcr/D");
performance_info->Branch("nevent",&nevent,"nevent/I");
performance_info->Branch("hit_time",&hit_time,"hit_time/I");
performance_info->Branch("gain",&gain,"gain/D");
performance_info->Branch("gain_err",&gain_err,"gain_err/D");
performance_info->Branch("ave_charge",&ave_charge,"ave_charge/D");
performance_info->Branch("pe1min_conv",&pe1min_conv,"pe1min_conv/I");
performance_info->Branch("rise_position_mean",&rise_position_mean,"rise_position_mean/D");
performance_info->Branch("fall_position_mean",&fall_position_mean,"fall_position_mean/D");
performance_info->Branch("rise_time_mean",&rise_time_mean,"rise_time_mean/D");
performance_info->Branch("fall_time_mean",&fall_time_mean,"fall_time_mean/D");
performance_info->Branch("fwhm_mean",&fwhm_mean,"fwhm_mean/D");
performance_info->Branch("amp_mean",&amp_mean,"amp_mean/D");
performance_info->Branch("signal_count",&signal_count,"signal_count/I");
performance_info->Branch("sig_inwindow_count",&sig_inwindow_count,"sig_inwindow_count/I");
performance_info->Branch("ped_count",&ped_count,"ped_count/I");
performance_info->Branch("noped_count",&noped_count,"noped_count/I");
performance_info->Branch("pvratio",&pvratio,"pvratio/D");
performance_info->Branch("pv_amp",&pv_amp,"pv_amp/D");
performance_info->Branch("snr",&snr,"snr/D");
performance_info->Branch("corf",&corf,"corf/D");
performance_info->Branch("nsnt",&nsnt,"nsnt/D");
performance_info->Branch("mu",&mu,"mu/D");
performance_info->Branch("pde",&pde,"pde/D");
performance_info->Branch("pde_err",&pde_err,"pde_err/D");

TCanvas *pmt_can_tmp=new TCanvas("pmt_can_tmp",com_str+"fig_canvas",4200,2500);							//the canvas to draw important histograms and ouput as figures
TCanvas *checkcan=new TCanvas("checkcan",com_str+"check_waveform",1200,900);
TGraph *corg=new TGraph(1000);
/*************************************************** read the input file for the first time **************************************************/
ifstream infile(input_file);												//input file stream
string sig_line;													//read a line into a string
for(int i=0;i<npoint;i++){average_wave[i]=0;}										//initialize the average_wave array
while(getline(infile,sig_line)){											//the loop to read the full file
istringstream sigis(sig_line);												//read the string to string stream
sigis>>amplitude[tcount];												//each line of the input file as a waveform point
Hist_wave2d->Fill(tcount,amplitude[tcount]);										//fill the 2d histogram
average_wave[tcount]+=amplitude[tcount];										//average waveform sum
if(tcount<200)baseline+=amplitude[tcount];										//the average of first 100 points as the baseline to get integral window, not accurate
tcount++;														//read until end of a waveform
	if(tcount==npoint){												//get the full waveform
	baseline=baseline/200.;												//the baseline of this waveform
	for(int n=1;n<npoint-rise_edge_thrd;n++){									//check from the start of wave
                 for(int m=0;m<=rise_edge_thrd;m++){									//5 points to find the rise edge
                 if(amplitude[m+n]>=baseline-peak_threshold || amplitude[n-1]<baseline-peak_threshold)break;		//not exist
                 if(m==rise_edge_thrd){Hist_tem_rise_pos->Fill(n);							//fill the rise position
                         n+=sig_skip;}											//and skip to the next
                 }													//end of finding rise edge
		}													//the end of check
	tcount=0;													// reset tcount for next waveform
	nevent++;
	baseline=0;													//reset baseline
	}														//end of process of one waveform
}															//end of the loop to read the file
inte_start=(int)Hist_tem_rise_pos->GetMaximumBin()-inte_window*.5;								//inte_start from rise edge histogram
inte_end=(int)Hist_tem_rise_pos->GetMaximumBin()+inte_window*1.2;								//inte_end from rise edge histogra
if(inte_end>=npoint)inte_end=npoint;
if(inte_start<=0)inte_start=0;
// to calculate the average baseline for each pmt
tcount=0;														//initialize
peak_val=average_wave[0];
for(int i=0;i<npoint;i++){												//averege waveform loop
Hist_ave_waveform->SetBinContent(i,average_wave[i]*1./nevent);								//the histogram
if((i>=inte_start-50&&i<inte_start)||(i>=inte_end&&i<inte_end+50)){average_baseline+=average_wave[i];tcount++;}		//the average baseline
if(i>inte_start&&average_wave[i]<peak_val&&i<inte_end){peak_val=average_wave[i];peak_pos=i;}				//the peak position and peak value in the average wave
}															//end of the loop
average_baseline=average_baseline/(1.*tcount*nevent);
pmt_can_tmp->cd();
gPad->SetFillStyle(4000);
Hist_wave2d->Draw("colz");
Hist_wave2d->SetStats(false);
Hist_wave2d->SetFillStyle(4050);
gPad->SetLogz();
pmt_can_tmp->SaveAs(outpng_name);
delete pmt_can_tmp;
TCanvas *pmt_can=new TCanvas("pmt_can",com_str+"fig_canvas",4200,2500);							//the canvas to draw important histograms and ouput as figures
//fill the baseline histogram
TH1D *Hist_baseline=new TH1D("Hist_baseline",com_str+"baseline",400,average_baseline-4,average_baseline+4); 		//the histogram of baseline distribution
TH1D *Hist_baselinenew=new TH1D("baselinenew",com_str+"baselinenew",600,average_baseline-3,average_baseline+3);
auxiliary_info->Fill();													//fill the auxiliary info
/************************************ file pointer retract ******************************************************************/
infile.clear();									//clear the file flag
infile.seekg(0,ios::beg);							//back to the begin position
tcount=0;
nevent=0;
checkcan->cd();
checkcan->Print(outpdf_name_start);
/**************/
ofstream outtxt_sighit(outtxt_sighit_name,ios::app);
//ofstream out_train_data("deeplearning/train_data.txt",ios::app);
ofstream out_train_data("deeplearning/data/train_data.txt"+com_str);
/********************************************** the waveform formal loop******************************************************************/
while(getline(infile,sig_line)){											//start of the waveform loop
istringstream sigis(sig_line);												//read a point into line
sigis>>amplitude[tcount];
wave_charge+=average_baseline-amplitude[tcount];												//fill it to the waveform
wave_amp=average_baseline-amplitude[tcount];
Hist_amp2d->Fill(tcount,wave_amp);
Hist_charge2d->Fill(tcount,wave_charge/50.);
if((tcount>=inte_start-50&&tcount<inte_start)||(tcount>=inte_end&&tcount<inte_end+50)){baseline+=amplitude[tcount];local_count++;}	//using local-count points to get baseline of each waveform
if(tcount<npoint_hist)Hist_baselinenew->Fill(amplitude[tcount]);
tcount++;		//really really tricky!!!!!!!!!!!!!!!!!!!!!!!!!							//then to the next point(line)
//if((tcount>=inte_start-50&&tcount<inte_start)||(tcount>=inte_end&&tcount<inte_end+50)){baseline+=amplitude[tcount];local_count++;}	//using local-count points to get baseline of each waveform
	if(tcount==npoint)baseline=baseline/(local_count*1.);
	if(tcount==npoint){												//finish reading of one waveform
//	if(fabs(baseline-average_baseline)>0.8)baseline=average_baseline;
//	if(tcount==npoint&&baseline-average_baseline<.8&&baseline-average_baseline>-.8){												//finish reading of one waveform
	baselinenew=Hist_baselinenew->GetMean();
//	baselinenew=average_baseline+(Hist_baselinenew->GetMaximumBin()-300)*.01;
	baseline=baselinenew;
//	if(nevent<1000)cout<<"baseline new: "<<baselinenew<<"ddaaaaaa"<<Hist_baselinenew->GetMaximumBin()<<endl;
	//if(nevent<10){checkcan->cd();Hist_baselinenew->Draw();checkcan->SaveAs(outpdf_name);}
	Hist_baselinenew->Reset("ICESM");
	wave_charge=0;
	wave_amp=0;
//	baseline=baseline/(local_count*1.);										//the baseline of this waveform
//	if(baseline-average_baseline>.8)break;
//	for(int icc=npoint;icc>0;icc--){wave_charge+=baseline-amplitude[npoint-icc];Hist_charge2d->Fill(npoint-icc,wave_charge/50.);}
//	local_count=0;
	sig_min_position=0;												//the minimum position of one signal
//	sig_min_value=0;												//the minimum of one signal
	sig_min_value=baseline;
	peak_count=0;
	rise_position=0;
	for(int i=3;i<npoint_hist-10;i++){										//the loop to search raising edges
		for(int j=0;j<=rise_edge_thrd;j++){									//the loop to find 5 points under the threshold
			if(amplitude[i+j]>=(baseline-peak_threshold) || amplitude[i-1]<baseline-peak_threshold)break;
			if(j==rise_edge_thrd){										//found the raising edge
				peak_count++;										//the number of peaks in one waveform
				signal_charge=0;
				rise_position=i;									//the position of passing thethreshhold
				sig_min_position=i;									//to find the signal peak
				for(int k=0;k<25;k++){ 									//25ns inthe rise edge
					if(i+k>=npoint)break;								//not excess the waveform end
					if(amplitude[i+k]<sig_min_value){sig_min_position=i+k;sig_min_value=amplitude[i+k];}	//get the peak
					}										//end of the loop to find signal peak
				for(int l=0;l<40;l++){									//to get the fall position in 40 ns scope
					if(sig_min_position+l>=npoint)break;						//the end of the waveform
					if(amplitude[sig_min_position+l]<(baseline-peak_threshold)&&amplitude[sig_min_position+l+1]>=(baseline-peak_threshold)){fall_position=sig_min_position+l;break;}}  													//hope the break be useful!!
				for(int k=sig_min_position;k<sig_min_position+30;k++){					//find the 0.1,0.5,0.9 peak falling position
					if(k>=npoint)break;
					if(amplitude[k]<=((baseline-sig_min_value)*.1+sig_min_value)&&amplitude[k+1]>=((baseline-sig_min_value)*.1+sig_min_value))fall_time_start=k;//0.9peak_f_pos
					if(amplitude[k]<=((baseline-sig_min_value)*.5+sig_min_value)&&amplitude[k+1]>=((baseline-sig_min_value)*.5+sig_min_value))fwhm_end=k-1;//0.5peak_f_pos
					if(amplitude[k]<=((baseline-sig_min_value)*.9+sig_min_value)&&amplitude[k+1]>=((baseline-sig_min_value)*.9+sig_min_value)){fall_time_end=k+1;break;}//0.1peak_f_pos
//					if(k==sig_min_position+29){fall_time_end=sig_min_position*2-fall_time_start;fwhm_end=sig_min_position*2-fwhm_start;}
					}										//end of the falling peak search loop
				for(int k=sig_min_position;k>sig_min_position-20;k--){					//find the 0.1,0.5,0.9 peak falling position
					if(k<=0)break;
					if(amplitude[k]<=((baseline-sig_min_value)*.1+sig_min_value)&&amplitude[k-1]>=((baseline-sig_min_value)*.1+sig_min_value))rise_time_end=k;//0.9peak_f_pos
					if(amplitude[k]<=((baseline-sig_min_value)*.5+sig_min_value)&&amplitude[k-1]>=((baseline-sig_min_value)*.5+sig_min_value))fwhm_start=k+1;//0.5peak_f_pos
					if(amplitude[k]<=((baseline-sig_min_value)*.9+sig_min_value)&&amplitude[k-1]>=((baseline-sig_min_value)*.9+sig_min_value)){rise_time_start=k-1;break;}//0.1peak_f_pos
//					if(k==sig_min_position-19){rise_time_start=sig_min_position*2-fall_time_end;fwhm_start=sig_min_position*2-fwhm_end;}
					}										//end of the falling peak search loop
				rise_time=rise_time_end-rise_time_start;						//rise time
				fall_time=fall_time_end-fall_time_start;						//fall time
				fwhm=fwhm_end-fwhm_start;								//fwhm
				for(int ic=i;ic<fall_position+5;ic++)signal_charge+=baseline-amplitude[ic];
				signal_charge=signal_charge/(50.);
				if(average_baseline-sig_min_value>100)signal_amp=0;
				else signal_amp=average_baseline-sig_min_value;
/********************************************** filling the histograms *************************************************************************************/
				if(0<=rise_time&&rise_time<=35&&0<=fall_time&&fall_time<=35&&0<=fwhm&&fwhm<=35){	//ignore the abnormal signal while filling histogram
					Hist_rise_position->Fill(rise_position);					//fill the rise time
					Hist_fall_position->Fill(fall_position);					//fill the fall time
					Hist_fwhm->Fill(fwhm);								//fill the fwhm histogram
					Hist_rise_time->Fill(rise_time);						//fill the rise time histogram
					Hist_fall_time->Fill(fall_time);						//fill the fall time histogram
					Hist_rise_time_start->Fill(rise_time_start);
					Hist_rise_time_end->Fill(rise_time_end);
					Hist_fall_time_start->Fill(fall_time_start);
					Hist_fall_time_end->Fill(fall_time_end);
					Hist_fwhm_start->Fill(fwhm_start);
					Hist_fwhm_end->Fill(fwhm_end);
					Hist_sig_min_position->Fill(sig_min_position);
					Hist_sig_min_value->Fill(sig_min_value);
					Hist_sig_amplitude->Fill(baseline-sig_min_value);
          signal_count++;										//the signal counts
		pmt_tree->Fill();

          if(rise_position>=inte_start&&fall_position<=inte_end){
            for(int ii=sig_min_position-inte_window/2.;ii<=sig_min_position+inte_window;ii++){ //get the waveform profile
              if(ii<0||ii>499){sig_profile[ii-sig_min_position+inte_window/2]+=baseline;     //correct Range
                Hist_sig_profile2d->Fill(ii-sig_min_position+inte_window/2,baseline);}       //fill the 2d histogram
                else {sig_profile[ii-sig_min_position+inte_window/2]+=amplitude[ii];
                Hist_sig_profile2d->Fill(ii-sig_min_position+inte_window/2,amplitude[ii]);}
  //				if(nevent<5000&&baseline-amplitude[sig_min_position-15]>20)Hist_sig_profile2d->Fill(ii-sig_min_position+30,amplitude[ii]);
            }
				Hist_peakspec->Fill(baseline-sig_min_value);
            sig_inwindow_count++;             //count the signals in the integral window
		outtxt_sighit<<nevent<<" "<<rise_position<<endl;
            sig_tag=1;                // the tag
            }
		if(rise_position<inte_start-20)predcr_count++;
          }										//end of filling histograms
				i=i+sig_skip;										//skip to find in the next range
//			if(nevent<1000)cout<<signal_count<<" total have sig:"<<sig_inwindow_count<<endl;
//			if(nevent<3000)cout<<"rt"<<rise_time_start<<" "<<rise_time_end<<" "<<sig_min_position<<" "<<rise_time<<"wwwwwww"<<fall_time_start<<" "<<fall_time_end<<"ft"<<fall_time<<"fwhm"<<fwhm_start<<" "<<fwhm_end<<" "<<fwhm<<"whyyyyyyyyy"<<endl;
				}											//end of processing the found edge
			}												//end of the loop to find 5 points
		}													//end of the loop to search raising edges

for(int i=0;i<inte_end;i++)
  {
  if(i>=inte_start){
    QDC_sig+=baseline-amplitude[i];
    QDC_sig1+=baseline-amplitude[i];}
	if(sig_tag==0&&baseline-amplitude[i]>10){QDC_sig1=0;}
	//if(sig_tag==0&&baseline-amplitude[i]>4){amplitude[i]=baseline;}
  else {
    QDC_dn+=baseline-amplitude[i];
    QDC_dn1+=average_baseline-amplitude[i];}
  }
//	if(nevent==38656)cout<<baseline<<"thatisssss?????????????????"<<"here"<<amplitude[inte_start-1]<<endl;
//if(baseline-average_baseline>0.8)cout<<"QDC is"<<QDC_sig1<<endl;
//the checkf waveform
//	if(nevent==38656)cout<<baseline<<"the endloop[?????????????????"<<"amplitudewnd:"<<amplitude[inte_start-1]<<endl;
//	if(QDC_sig1<-60){
//	if(sig_tag==1&&rise_position < inte_start+140&&rise_position>inte_start+70){
//	if(pdf_count < 300&&QDC_sig1>70&&QDC_sig1<90&&(baseline-sig_min_value)<14){
if(pdf_count<50){
//	if(sig_tag==0 &&QDC_sig1>20&&QDC_sig1<50&& pdf_count < 100){
//		cout<<"nevent"<<nevent<<"bsl:"<<baseline<<"dfsgdfs"<<amplitude[inte_start-2]<<" "<<amplitude[inte_start-1]<<" "<<amplitude[inte_start]<<" "<<amplitude[inte_end]<<" "<<amplitude[inte_end+1]<<"localcount"<<local_count<<endl;
//		out_train_data<<1<<","<<baseline<<",";
//		for(int i=0;i<npoint_hist;i++){
		for(int i=inte_start;i<inte_start+81;i++){
//			if(fabs(baseline-amplitude[i])>=40) out_train_data<<1<<",";
//			else out_train_data<<fabs(baseline-amplitude[i])/40.<<",";
//			Hist_check1d->SetBinContent(i,amplitude[i]);}
			Hist_check1d->SetBinContent(i,baseline-amplitude[i]);}
		Hist_check1d->Draw();
		TLine *bl=new TLine(0,baseline,500,baseline);
		bl->Draw();
		TLine *abl=new TLine(0,average_baseline,500,average_baseline);
		abl->Draw();
		abl->SetLineColor(kRed);
		TLine *bls=new TLine(inte_start,-40,inte_start,baseline);
		bls->Draw();
		TLine *ble=new TLine(inte_end,-40,inte_end,baseline);
		ble->Draw();
		TLine *ampline=new TLine(inte_start,baseline-sig_min_value,inte_end,baseline-sig_min_value);
		ampline->Draw();
		TLatex *mltex = new TLatex(.1,-30.062,Form("pdfnum%3d QDC%5.3g",pdf_count,QDC_sig1/50.));
		mltex->Draw();
		pdf_count++;	
		Hist_check1d->GetXaxis()->SetTitle("t[ns]");
		Hist_check1d->GetYaxis()->SetTitle("U[mV]");
		Hist_check1d->GetYaxis()->SetRangeUser(-40,20);
		checkcan->SaveAs(outpdf_name);
//		out_train_data<<endl;
		}
//for deep learning
		pass_count=0;
		for(int i=inte_start;i<inte_start+81;i++){
			if(fabs(baseline-amplitude[i])>=40) out_train_data<<1<<" ";
			else out_train_data<<fabs(baseline-amplitude[i])/40.<<" ";
			if(fabs(baseline-amplitude[i])>3)pass_count++;
		}
		if(QDC_sig1/50.<0.4)dltag=0;
		else if(QDC_sig1/50.<2.4)dltag=1;
			else if(QDC_sig1/50.<4)dltag=2;
			   else dltag=3;
//		if(1.5<QDC_sig1/50.<1.7||3.1<QDC_sig1/50.<3.3||QDC_sig1/50.>4.8)dltag=dltag*10;
//		out_train_data<<baseline-sig_min_value<<" "<<QDC_sig1/50.<<" "<<pass_count<<" "<<dltag<<endl;
		out_train_data<<dltag<<endl;
	if(sig_tag>0){Hist_sQDC->Fill(QDC_sig1/50.);Hist_amp_qdc->Fill(baseline-sig_min_value,QDC_sig1/50.);}
	if(corg_count<1000&&sig_tag>0){corg->SetPoint(corg_count,baseline-sig_min_value,QDC_sig1/50.);corg_count++;}
//  if(sig_tag==0){Hist_nQDC->Fill(QDC_sig1/50.);}
	if(sig_tag==0){Hist_nQDC->Fill(QDC_sig1/50.);Hist_peakspec->Fill(baseline-amplitude[Hist_sig_min_position->GetMaximumBin()]);}
	if(QDC_sig1/50.>0.4)ave_charge+=QDC_sig1/50.;  //0.25pe
  	Hist_QDC_sig->Fill(QDC_sig/50.);   //divided by 50 Ohm to get pC charge
  	Hist_QDC_dn->Fill(QDC_dn/50.);
//  	if(baseline-average_baseline<0.8)Hist_QDC_sig1->Fill(QDC_sig1/50.);
  	Hist_QDC_sig1->Fill(QDC_sig1/50.);
  	Hist_QDC_dn1->Fill(QDC_dn1/50.);
	Hist_baseline->Fill(baseline);										//fill the baseline histogram
	tcount=0;													//reset tcount
	nevent++;
	baseline=0;
	QDC_sig=0;				//initialization
	QDC_dn=0;				//initialization
	QDC_sig1=0;				//initialization
	QDC_dn1=0;				//initialization
	sig_tag=0;				//initialization
	local_count=0;
	}														//end of the loop of one waveform's points
//	if(tcount==npoint){baseline=0;tcount=0;local_count=0;}


}															//end of the waveform loop
	soft_dcr=(predcr_count)*0.001/((inte_start-20-3)*nevent)*1e9;
//	soft_dcr=(signal_count-sig_inwindow_count)*1./((npoint_hist-5-1.5*inte_window)*nevent)*1e9;
//	cout<<soft_dcr<<"is sdcr"<<endl;
         for(int i1=0;i1<200;i1++){											//to get the mean value of 3points
                 if(i1<1||i1>=199)Hist_QDC_sig1_conv->SetBinContent(i1,0);			
                 else {
                         int aver_content=0;
                         for(int i2=-1;i2<2;i2++){aver_content+=Hist_QDC_sig1->GetBinContent(i1+i2);}
                         aver_content=(int)aver_content/3.;
                         Hist_QDC_sig1_conv->SetBinContent(i1,aver_content);}
                 }													//end of the loop to get convoluted QDC spectrum

  for(int i1=0;i1<1.5*inte_window;i1++){Hist_sig_profile->SetBinContent(i1,(sig_profile[i1]*1./sig_inwindow_count));}        //fill the 1d histogram of waveform profile
//cout<<Hist_sig_profile->GetBinContent(0)<<"    "<<sig_inwindow_count<<endl;
//**************************setting the titles***********************************************/
	Hist_sig_profile->GetXaxis()->SetTitle("time[ns]");
	Hist_sig_profile->GetYaxis()->SetTitle("U[mV]");
	Hist_sig_profile2d->GetXaxis()->SetTitle("time[ns]");
	Hist_sig_profile2d->GetYaxis()->SetTitle("U[mV]");
	Hist_ave_waveform->GetXaxis()->SetTitle("time[ns]");
	Hist_ave_waveform->GetYaxis()->SetTitle("U[mV]");
	Hist_wave2d->GetXaxis()->SetTitle("time[ns]");
	Hist_wave2d->GetYaxis()->SetTitle("U[mV]");
/************CNN****************************/
	out_train_data.close(); //close the output traindata
	gSystem->Exec("source ~/.bashrc");
	gSystem->Exec("cd /home/pmthome/zhaor/zhaorong/cont_v1/cnn");
//	gSystem->Exec("pushd /home/pmthome/zhaor/zhaorong/cont_v1/cnn");
	TString pycomd="python3 /home/pmthome/zhaor/zhaorong/cont_v1/cnn/PMT_CNN.py /home/pmthome/zhaor/zhaorong/cont_v1/deeplearning/data/train_data.txt"+com_str+" "+Form("%d",nevent)+" /home/pmthome/zhaor/zhaorong/cont_v1/cnn/results/"+com_str+"cnn.txt";
//	cout<<"arlierevt"<<nevent<<pycomd<<endl;
	gSystem->Exec(pycomd);
	gSystem->Exec("cd /home/pmthome/zhaor/zhaorong/cont_v1/");
//	gSystem->Exec("popd");

/***************************************the pmt output canvas*********************************************/
pmt_can->cd();
//to display the logo 
TPad *logopad = new TPad("logopad","This is mypad1",0.74,0.0,0.94,0.022);
logopad->Draw();
logopad->SetFillStyle(4000);
logopad->cd();
TImage *img = TImage::Open("logo.jpg");
if (!img) {
      printf("Could not create an image... exit\n");
   }
  img->SetConstRatio(0);
  img->SetImageQuality(TAttImage::kImgBest);
  img->Draw("xxx");
  img->SetEditable(kTRUE);
pmt_can->cd();
pmt_can->Divide(4,3);
//pmt_can->SetFillStyle(4000);
//------------------------------------------------------------------------------------------------------------fig 6
pmt_can->cd(6);
Hist_QDC_sig1_conv->Draw();
Hist_QDC_sig1_conv->GetYaxis()->SetNdivisions(5, kFALSE);
Hist_QDC_sig1_conv->SetFillStyle(3618);
Hist_QDC_sig1_conv->SetFillColorAlpha(8,0.5);
Hist_QDC_sig1_conv->SetLineColor(kTeal+3);
Hist_QDC_sig1_conv->SetLineWidth(2);
gPad->SetGrid();
gPad->Update();
double maxrange_y=gPad->GetUymax();
//int maxrange=infocan->GetFrame()->GetY2();
Hist_QDC_sig1_conv->GetXaxis()->SetTitle("convoluted QDC[pC]");
Hist_QDC_sig1_conv->GetYaxis()->SetTitle("count");
//int maxrange=infocan->GetFrame()->GetY2();
Hist_QDC_sig1_conv->GetXaxis()->SetRange(23.2,48); //senitive
int pe1max_conv=Hist_QDC_sig1_conv->GetMaximumBin();
//cout<<"pe1m conv is"<<pe1max_conv<<endl;
Hist_QDC_sig1_conv->GetXaxis()->SetRange(16,pe1max_conv);
pe1min_conv=Hist_QDC_sig1_conv->GetMinimumBin();
deltaN0=Hist_QDC_sig1->Integral(19,pe1min_conv);
//cout<<"pe1min_c"<<pe1min_conv<<endl;
//cout<<"delta n 0 is"<<deltaN0<<endl;
gPad->SetLogy();
Hist_QDC_sig1_conv->GetXaxis()->SetRange(0,200);
int pv_v=Hist_QDC_sig1_conv->GetBinContent(pe1min_conv);
if(pv_v==0)pv_v++;
int pv_p=Hist_QDC_sig1_conv->GetBinContent(pe1max_conv);
// horizental line1
TLine *pe1_vline=new TLine(-2,pv_v,23,pv_v);
pe1_vline->SetLineStyle(8);
pe1_vline->SetLineColor(2);
pe1_vline->SetLineWidth(2);
pe1_vline->Draw();

// horizental line2
TLine *pe1_pline=new TLine(-2,pv_p,23,pv_p);
pe1_pline->SetLineStyle(8);
pe1_pline->SetLineColor(2);
pe1_pline->SetLineWidth(2);
pe1_pline->Draw();
//vertical line1
TLine *pe1_minline=new TLine(pe1min_conv/8.-2,0,pe1min_conv/8.-2,maxrange_y);
pe1_minline->SetLineStyle(8);
pe1_minline->SetLineColor(2);
pe1_minline->SetLineWidth(2);
pe1_minline->Draw();
//vertical line2
TLine *pe1_maxline=new TLine(pe1max_conv/8.-2,0,pe1max_conv/8.-2,maxrange_y);
pe1_maxline->SetLineStyle(8);
pe1_maxline->SetLineColor(2);
pe1_maxline->SetLineWidth(2);
pe1_maxline->Draw();
TLine *p25peline=new TLine(0.25,0,0.25,maxrange_y);
p25peline->SetLineStyle(8);
p25peline->SetLineColor(4);
p25peline->SetLineWidth(2);
p25peline->Draw();
TLatex *pvtex=new TLatex();
pvratio=pv_p*1./pv_v;
if(pmt_type==1&&base_type==0)pvratio=1.43*pvratio;//correction for MCP PMT ,the base type.
pvtex->DrawLatex(1.2,pv_p*1.3,Form("Peak-Valley ratio = %5.3g ",pv_p*1./pv_v));
gPad->Update();
TPaveStats* pvps= (TPaveStats*)(Hist_QDC_sig1_conv->FindObject("stats"));
pvps->SetX1NDC(.7);  //change the position of the stats box for the first plot
pvps->SetX2NDC(.9);
pvps->SetY1NDC(.7);
pvps->SetY2NDC(.9);
//------------------------------------------------------------------------------------------------------------fig1
pmt_can->cd(1);
TPad *pad1 = (TPad*)pmt_can->cd(1);
pad1->SetFillStyle(4000);
Hist_wave2d->Draw("colz");
Hist_wave2d->SetStats(false);
Hist_wave2d->SetFillStyle(4050);
//gStyle->SetOptStat(kFALSE);
//gStyle->SetOptStat(0);
gPad->SetLogz();
TBox *inte_box = new TBox(inte_start,-40*factors[0],inte_end,40);
//inte_box->Draw();
inte_box->SetFillColor(2);
inte_box->SetFillStyle(3013);
TPad *myp1=new TPad("myp1","myp1",.1+.8*inte_start/npoint,.1,.1+.8*inte_end/npoint,.9);
myp1->Draw();
myp1->SetFillColorAlpha(2,.1);
TLine *aver_baseline=new TLine(0,average_baseline,npoint_hist,average_baseline);
TLine *inte_start_line=new TLine(inte_start,-40*factors[0],inte_start,40);
TLine *inte_end_line=new TLine(inte_end,-40*factors[0],inte_end,40);
TLine *peak_line=new TLine(Hist_sig_min_position->GetMaximumBin(),-40*factors[0],Hist_sig_min_position->GetMaximumBin(),40);
aver_baseline->Draw();
inte_start_line->Draw();
inte_end_line->Draw();
peak_line->Draw();
peak_line->SetLineStyle(8);
peak_line->SetLineColor(2);
peak_line->SetLineWidth(2);
inte_start_line->SetLineStyle(8);
inte_start_line->SetLineColor(2);
inte_start_line->SetLineWidth(-802);
inte_end_line->SetLineStyle(8);
inte_end_line->SetLineColor(2);
inte_end_line->SetLineWidth(2);
TLatex *dcrtex=new TLatex();
dcrtex->DrawLatex(10,25,Form("DCR_soft = %5.3g kHz ",soft_dcr));
dcrtex->DrawLatex(10,33,Form("DCR_container = %5.3g kHz ",cont_dcr));
dcrtex->DrawLatex(10,17,Form("DCR_vendor = %5.3g kHz ",vendor_dcr));

//------------------------------------------------------------------------------------------------------------fig5
pmt_can->cd(2);
TPad *pad2 = (TPad*)pmt_can->cd(2);
gPad->SetGrid();
pad2->SetFillStyle(0);
Hist_QDC_sig1->Draw();
Hist_QDC_sig1->GetYaxis()->SetNdivisions(5, kFALSE);
Hist_QDC_sig1->SetFillStyle(3618);
Hist_QDC_sig1->SetFillColorAlpha(8,0.5);
Hist_QDC_sig1->SetStats(false);
Hist_QDC_sig1->SetLineColor(kTeal+3);
Hist_QDC_sig1->SetLineWidth(2);
Hist_QDC_sig1->GetXaxis()->SetTitle("QDC[pC]");
Hist_QDC_sig1->GetYaxis()->SetTitle("count");
//cout<<pe1min_conv*.96/8.-2<<"    "<<(2*pe1max_conv-pe1min_conv*.99)/8.-2<<endl;
Hist_QDC_sig1->Fit("gaus","R0WW","same",(pe1min_conv)*1.095/8.-2,(2*pe1max_conv-pe1min_conv*1.11)/8.-2);
TF1 *fit =(TF1 *) Hist_QDC_sig1->GetFunction("gaus");
fit->SetLineColor(kRed-4);
fit->SetLineStyle(8);
pe1max=fit->GetParameter("Mean");
pe1max_error=fit->GetParError(1);
//cout<<"hhhhhhhhhhhhhhhhhhhhhhh"<<pe1max_error<<endl;
pe1sigma=fit->GetParameter("Sigma");
TF1 *mygaus=new TF1("mygaus","[0]*exp(-(x-[1])**2/2./[2]**2)",2-(pe1min_conv)*.96/8.,(pe1min_conv)*.92/8.-2);
mygaus->SetParNames("amp1","mean1","sigma1");
mygaus->SetParameters(5000,0,.14);
mygaus->SetParLimits(0,500,15000);
mygaus->SetParLimits(1,-.3,.3);
mygaus->SetParLimits(2,.01,1);
Hist_QDC_sig1->Fit(mygaus,"R0WW","same",2-(pe1min_conv)*.96/8.,(pe1min_conv)*.92/8.-2);
pe0sigma=mygaus->GetParameter("sigma1");
pe0mean=mygaus->GetParameter("mean1");
pe0mean_err = mygaus->GetParError(1);
//cout<<pe0mean<<"sssssssssssssssssssssssssssssssssssssss"<<pe0mean_err<<endl;
//mygaus->Draw("sames");
//mygaus->SetLineColor(3);

Hist_QDC_sig1->GetXaxis()->SetRange(200);
//the new pv ratio
//pvtex->DrawLatex(2.2,pv_p*1.3,Form("Peak-Valley ratio = %5.3g ",(fit->Eval(pe1max))*1./(fit->Eval((pe1min_conv)/50.-2))));
TLine *pe1_line=new TLine(pe1max,0,pe1max,maxrange_y);
pe1_line->SetLineStyle(8);
pe1_line->SetLineColor(2);
pe1_line->SetLineWidth(2);
pmt_can->Update();
gPad->Update();
maxrange_y=gPad->GetUymax();
//double maxrange=gPad->GetFrame()->GetY2();
pe0max=Hist_QDC_sig1->GetMaximumBin();
TLine *ped_line=new TLine(pe0max*1./8-2,0,pe0max*1./8-2,maxrange_y);
ped_line->SetLineStyle(8);
ped_line->SetLineColor(2);
ped_line->SetLineWidth(2);
//gain
//gain=(pe1max-pe0mean)/1.6*1;
gain=(pe1max-pe0max*1./8+2+1./16)/1.6*1;
//cout<<"gainnnnn is "<<gain<<endl;
TLatex *gaintex=new TLatex();
gaintex->DrawLatex(2,Hist_QDC_sig1->GetMaximum(),Form("Gain = %5.3g ",gain));
//resolution
pe1resolution=pe1sigma/(pe1max-pe0max*1./8+2);
if(pmt_type==1&&base_type==0)pe1resolution=0.3398*pe1resolution+0.198;//correction for MCP PMT ,the base type.
snr=pe0sigma/(pe1max-pe0max*1./8+2);
TLatex *resolutiontex=new TLatex();
resolutiontex->DrawLatex(2,Hist_QDC_sig1->GetMaximum()*.5,Form("Resolution = %5.3g ",pe1resolution));
resolutiontex->DrawLatex(2,Hist_QDC_sig1->GetMaximum()*.2,Form("SNR = %5.3g ",snr));

//cout<<Hist_QDC_sig1->GetMaximumBin()*1./50<<"is the binmax"<<endl;
//cout<<pe1max<<"is the pe1max"<<endl;
ped_line->Draw();
pe1_line->Draw();
gPad->SetLogy();
 TF1 *nimmodelfunc = new TF1("nimmodelfunc",NIMmodel, -1.01,23,10);
 Double_t TotalEvtNum =  Hist_QDC_sig1->GetEntries();
// cout<<"norm"<<TotalEvtNum<<endl;
  nimmodelfunc->SetParNames("N", "Q_{0}", "#sigma_{0}", "Q_{1}", "#sigma_{1}", "w", "#alpha", "#mu","mcpf","mcpg");
  nimmodelfunc->SetParameters((int)TotalEvtNum*0.125, -0.036, 0.1, 1.6, 0.45, 0.05, 0.296,1,.023,0.01);
  nimmodelfunc->SetParLimits(0, (int)TotalEvtNum*0.12, (int)TotalEvtNum*.13);
  nimmodelfunc->SetParLimits(1, -.15, .15);
  nimmodelfunc->SetParLimits(2, .051, .4);//sigma0
  nimmodelfunc->SetParLimits(3, 0.8, 2.4);
  nimmodelfunc->SetParLimits(4, .3, .56);
  nimmodelfunc->SetParLimits(5, 0.01, 1);//w
  nimmodelfunc->SetParLimits(6, 1e-1, 3.52); //alpha          
  nimmodelfunc->SetParLimits(7, 0.04, 2);           //mu
  nimmodelfunc->SetParLimits(8, 5e-3, 0.2);           //mcpf
  nimmodelfunc->SetParLimits(9, 1e-4, 2e-1);           //mcpg

 Hist_QDC_sig1->Fit(nimmodelfunc,"REML+");
Double_t myn=nimmodelfunc->GetParameter(0);
Double_t myq0=nimmodelfunc->GetParameter(1);
Double_t mysigma0=nimmodelfunc->GetParameter(2);
Double_t myq1=nimmodelfunc->GetParameter(3);
Double_t mysigma1=nimmodelfunc->GetParameter(4);
Double_t myw=nimmodelfunc->GetParameter(5);
Double_t myalpha=nimmodelfunc->GetParameter(6);
Double_t mymu=nimmodelfunc->GetParameter(7);
Double_t myfmu=nimmodelfunc->GetParameter(8);
Double_t mygmu=nimmodelfunc->GetParameter(9);
double quality= nimmodelfunc->GetChisquare()/ nimmodelfunc->GetNDF();
pvtex->DrawLatex(1.2,pv_p*.003,Form("fitmu = %5.3g,%5.3g,%5.3g ",mymu,quality,mymu+2*mymu*myfmu+3*mymu*mygmu));
TF1 *g1pe=new TF1("1pe",f1pe,0,24,7);
g1pe->SetParameters(myn*mymu*exp(-mymu)/(1+mymu+mymu*mymu/2.+mymu*mymu*mymu/6.),myq0,mysigma0,myq1,mysigma1,myfmu,mygmu);
g1pe->Draw("SAME");
g1pe->SetLineColor(4);
//g1pe->SetLineStyle(8);
TF1 *g2pe=new TF1("2pe",f2pe,0,24,7);
g2pe->SetParameters(myn*mymu*mymu*0.5*exp(-mymu)/(1+mymu*mymu/2.+mymu*mymu*mymu/6.),myq0,mysigma0,myq1,mysigma1,myfmu,mygmu);
g2pe->Draw("SAME");
g2pe->SetLineColor(5);
//g2pe->SetLineStyle(8);
TF1 *g3pe=new TF1("3pe",f3pe,0,24,7);
g3pe->SetParameters(myn*mymu*mymu*mymu/6.*exp(-mymu)/(1+mymu*mymu/2.+mymu*mymu*mymu/6.),myq0,mysigma0,myq1,mysigma1,myfmu,mygmu);
g3pe->Draw("SAME");
g3pe->SetLineColor(6);
//g3pe->SetLineStyle(8);
TF1 *g4pe=new TF1("4pe",f4pe,0,24,7);
g4pe->SetParameters(myn*mymu*mymu*mymu*mymu/24.*exp(-mymu)/(1+mymu*mymu/2.+mymu*mymu*mymu/6.),myq0,mysigma0,myq1,mysigma1,myfmu,mygmu);
g4pe->Draw("SAME");
g4pe->SetLineColor(7);
//g4pe->SetLineStyle(8);
TF1 *g5pe=new TF1("5pe",f5pe,0,24,7);
g5pe->SetParameters(myn*mymu*mymu*mymu*mymu*mymu/120.*exp(-mymu)/(1+mymu*mymu/2.+mymu*mymu*mymu*mymu/24.),myq0,mysigma0,myq1,mysigma1,myfmu,mygmu);
g5pe->Draw("SAME");
g5pe->SetLineColor(8);
//g5pe->SetLineStyle(8);
TF1 *expb=new TF1("expbkg",expbkg,0,24,3);
expb->SetParameters(myalpha,myq0);
expb->Draw("SAME");
expb->SetLineColor(1);
//g4pe->SetLineStyle(8);

//------------------------------------------------------------------------------------------------------------fig5
pmt_can->cd(5);
gPad->SetGrid();
Hist_ave_waveform->Draw();
Hist_ave_waveform->SetLineColor(kTeal+3);
Hist_ave_waveform->SetLineWidth(2);
Hist_ave_waveform->SetStats(false);
TLine *myinte_start_line=new TLine(inte_start,Hist_ave_waveform->GetMinimum(),inte_start,Hist_ave_waveform->GetMaximum());
TLine *myinte_end_line=new TLine(inte_end,Hist_ave_waveform->GetMinimum(),inte_end,Hist_ave_waveform->GetMaximum());
TLine *mypeak_line=new TLine(Hist_sig_min_position->GetMaximumBin(),Hist_ave_waveform->GetMinimum(),Hist_sig_min_position->GetMaximumBin(),Hist_ave_waveform->GetMaximum());
mypeak_line->Draw();
mypeak_line->SetLineStyle(8);
mypeak_line->SetLineColor(2);
mypeak_line->SetLineWidth(2);
myinte_start_line->Draw();
myinte_start_line->SetLineStyle(8);
myinte_start_line->SetLineColor(2);
myinte_start_line->SetLineWidth(2);
myinte_end_line->Draw();
myinte_end_line->SetLineStyle(8);
myinte_end_line->SetLineColor(2);
myinte_end_line->SetLineWidth(2);
aver_baseline->Draw();
aver_baseline->SetLineStyle(8);
aver_baseline->SetLineColor(2);
aver_baseline->SetLineWidth(2);
TLatex *avetex=new TLatex();
avetex->DrawLatex(100,Hist_ave_waveform->GetMaximum(),Form("Average baseline = %5.3g mV",average_baseline));
baseline_sigma=Hist_baseline->GetStdDev();
avetex->DrawLatex(100,Hist_ave_waveform->GetMinimum(),Form("#sigma_{baseline} = %5.3g mV",baseline_sigma));
//------------------------------------------------------------------------------------------------------------fig7
  TString cnnres="/home/pmthome/zhaor/zhaorong/cont_v1/cnn/results/"+com_str+"cnn.txt";
ifstream incnn(cnnres,ios::app);												//input file stream
string cnn_line;													//read a line into a string
double cnntag[5]={0};
int ii=0;
while(getline(incnn,cnn_line)){											//the loop to read the full file
istringstream cnnis(cnn_line);												//read the string to string stream
cnnis>>cnntag[ii];												//each line of the input file as a waveform point
ii++;
}
/********************Fill the hist cnn***************************/
for(int i=0;i<4;i++){
for(int j=0;j<cnntag[i];j++){Hist_cnn->Fill(i%2+0.5,(int)(i/2.)+0.5);}
}
pmt_can->cd(7);
Hist_amp2d->Draw("colz");
Hist_amp2d->GetXaxis()->SetTitle("time[ns]");
Hist_amp2d->GetYaxis()->SetTitle("U[mV]");
gPad->SetLogz();
Hist_amp2d->SetStats(false);
TBox *int_box = new TBox(inte_start,-2,inte_end,20*factors[3]);
//int_box->Draw();
int_box->SetFillColor(2);
int_box->SetFillStyle(3013);
//Hist_sig_profile->Draw();
//Hist_sig_profile->SetLineColor(kTeal+3);
//Hist_sig_profile->SetLineWidth(2);
TLine *sig_cen_line=new TLine(350,-40,350,40);
sig_cen_line->SetLineColor(2);
sig_cen_line->SetLineWidth(2);
sig_cen_line->SetLineStyle(8);
//sig_cen_line->Draw();
TLine *aver_baseline_p=new TLine(0,average_baseline,1.5*inte_window,average_baseline);
//aver_baseline_p->Draw();
aver_baseline_p->SetLineStyle(8);
aver_baseline_p->SetLineColor(2);
aver_baseline_p->SetLineWidth(2);
TPad *pad3=new TPad("pad3","pad3",.1+.8*inte_start/npoint,.1,.1+.8*inte_end/npoint,.9);
pad3->Draw();
pad3->SetFillColorAlpha(2,.1);
//pad3->SetFillStyle(4020);
//Hist_sig_profile->SetStats(false);
//TLine *fwhm_start_line=new TLine(25-1-Hist_sig_min_position->GetMean()+Hist_fwhm_start->GetMean(),average_baseline,25-1-Hist_sig_min_position->GetMean()+Hist_fwhm_start->GetMean(),average_baseline-Hist_sig_amplitude->GetMean()*.7);
//TLine *fwhm_end_line=new TLine(25-Hist_sig_min_position->GetMean()+Hist_fwhm_end->GetMean(),average_baseline,25-Hist_sig_min_position->GetMean()+Hist_fwhm_end->GetMean(),average_baseline-Hist_sig_amplitude->GetMean()*.7);
//fwhm_start_line->Draw();
//fwhm_start_line->SetLineStyle(8);
//fwhm_start_line->SetLineColor(2);
//fwhm_start_line->SetLineWidth(2);
//fwhm_end_line->Draw();
//fwhm_end_line->SetLineStyle(8);
//fwhm_end_line->SetLineColor(2);
//fwhm_end_line->SetLineWidth(2);
gPad->SetLogz();
Hist_cnn->Draw("colz TEXT");
Hist_cnn->SetMarkerColor(0);
Hist_cnn->SetStats(false);
Hist_cnn->SetMarkerSize(4.8);
auto mycnntext = new TText();
mycnntext->SetTextFont(52);
mycnntext->SetTextColor(0);
//mycnntext->SetTextSize(5);
mycnntext->DrawText(0.2,0.75,"0pe photons");
mycnntext->DrawText(1.2,0.75,"1pe photons");
mycnntext->DrawText(0.2,1.75,"2pe photons");
mycnntext->DrawText(1.2,1.75,"3pe photons");
//------------------------------------------------------------------------------------------------------------fig11
pmt_can->cd(11);
Hist_sig_profile2d->Draw("COLZ");
Hist_sig_profile2d->SetStats(false);
Hist_sig_profile2d->SetContour(99);
gStyle->SetPalette(68);
sig_cen_line->Draw();
aver_baseline_p->Draw();
gPad->SetLogz();
gPad->SetBottomMargin(.08);
TLatex *amp2dtex=new TLatex();
amp2dtex->DrawLatex(5,35,Form("vendor_HV = %d V",vendor_HV));
amp2dtex->DrawLatex(5,25,Form("fit_HV = %d V",fit_HV));
TLatex *fwhmtex=new TLatex();
fwhmtex->DrawLatex(30,-30,Form("Average FWHM = %5.3g ns",Hist_fwhm->GetMean()));
//fwhmtex->DrawLatex(30,average_baseline-Hist_sig_amplitude->GetMean()*.9,Form("Average FWHM = %5.3g ns",Hist_fwhm->GetMean()));
//------------------------------------------------------------------------------------------------------------fig3
pmt_can->cd(3);
Hist_charge2d->Draw("colz");
Hist_charge2d->GetXaxis()->SetTitle("time[ns]");
Hist_charge2d->GetYaxis()->SetTitle("charge[pC]");
Hist_charge2d->SetStats(false);

//Hist_sig_amplitude->Draw();
//Hist_sig_amplitude->SetLineColor(kTeal+3);
//Hist_sig_amplitude->SetLineWidth(2);
Hist_sig_amplitude->SetFillStyle(3003);
Hist_sig_amplitude->SetFillColor(2);
//Hist_sig_amplitude->GetXaxis()->SetTitle("amplitude[mV]");
//Hist_sig_amplitude->GetYaxis()->SetTitle("count");
//gPad->Update();
//TPaveStats* peakps= (TPaveStats*)(Hist_sig_amplitude->FindObject("stats"));
//peakps->SetX1NDC(.7);  //change the position of the stats box for the first plot
//peakps->SetX2NDC(.9);
//peakps->SetY1NDC(.7);
//peakps->SetY2NDC(.9);
gPad->SetLogz();
//------------------------------------------------------------------------------------------------------------fig12
pmt_can->cd(12);
gPad->SetGrid();
gPad->SetFillStyle(0);
gPad->SetFrameFillStyle(0);
Hist_rise_time->Draw();
Hist_rise_time->GetYaxis()->SetNdivisions(5, kFALSE);
Hist_rise_time->SetFillStyle(4050);
Hist_fall_time->SetFillStyle(4050);
Hist_rise_time->GetXaxis()->SetTitle("time[ns]");
Hist_rise_time->GetYaxis()->SetTitle("count");
Hist_fall_time->Draw("sames");
//Hist_rise_time->SetFillStyle(3013);
//Hist_rise_time->SetFillColor(16);
//Hist_fall_time->SetFillStyle(3013);
//Hist_fall_time->SetFillColor(42);
Hist_rise_time->SetLineColor(kTeal+3);
Hist_fall_time->SetLineColor(1);
Hist_rise_time->SetLineWidth(2);
Hist_fall_time->SetLineWidth(2);
gPad->SetBottomMargin(.08);
pmt_can->Update();
gPad->Update();
TPaveStats* pvsf= (TPaveStats*)(Hist_fall_time->FindObject("stats"));
TPaveStats* pvsr= (TPaveStats*)(Hist_rise_time->FindObject("stats"));
pvsr->SetX1NDC(.7);  //change the position of the stats box for the first plot
pvsr->SetX2NDC(.9);
pvsr->SetY1NDC(.7);
pvsr->SetY2NDC(.9);
pvsf->SetX1NDC(.7);  //change the position of the stats box for the first plot
pvsf->SetX2NDC(.9);
pvsf->SetY1NDC(.5);
pvsf->SetY2NDC(.7);
pvsr->SetTextColor(kTeal+3);
TLine *rise_line=new TLine(Hist_rise_time->GetMean(),0,Hist_rise_time->GetMean(),1.5*Hist_rise_time->GetMaximum());
TLine *fall_line=new TLine(Hist_fall_time->GetMean(),0,Hist_fall_time->GetMean(),1.5*Hist_rise_time->GetMaximum());
rise_line->SetLineStyle(8);
rise_line->SetLineColor(2);
rise_line->SetLineWidth(3);
rise_line->Draw();
fall_line->SetLineStyle(8);
fall_line->SetLineColor(2);
fall_line->SetLineWidth(3);
fall_line->Draw();
gPad->SetLogy();
gPad->Modified();
TLatex *rtex=new TLatex();
rtex->DrawLatex(12,.9*Hist_rise_time->GetMaximum(),Form("#bar{risetime} = %5.3g ns ",Hist_rise_time->GetMean()));
TLatex *ftex=new TLatex();
ftex->DrawLatex(12,.5*Hist_rise_time->GetMaximum(),Form("#bar{falltime} = %5.3g ns ",Hist_fall_time->GetMean()));

//------------------------------------------------------------------------------------------------------------fig9
pmt_can->cd(9);
gPad->SetGrid();
gPad->SetFillStyle(0);
gPad->SetFrameFillStyle(0);
Hist_rise_position->Draw();
Hist_rise_position->GetYaxis()->SetNdivisions(5, kFALSE);
Hist_rise_position->GetYaxis()->SetTitle("count");
Hist_rise_position->GetXaxis()->SetTitle("time[ns]");
Hist_rise_position->SetLineColor(kTeal+3);
Hist_rise_position->SetLineWidth(2);
//Hist_rise_position->SetFillStyle(3013);
//Hist_rise_position->SetFillColor(2);
//fall-infomation
Hist_fall_position->Draw("sames");
Hist_fall_position->SetLineColor(1);
Hist_fall_position->SetLineWidth(2);
//Hist_fall_position->SetFillStyle(3013);
//Hist_fal#l_position->SetFillColor(4);
gPad->SetBottomMargin(.08);
gPad->Update();
TPaveStats* hitps= (TPaveStats*)(Hist_rise_position->FindObject("stats"));
hitps->SetX1NDC(.1);
hitps->SetX2NDC(.3);
hitps->SetY1NDC(.7);
hitps->SetY2NDC(.9);
hitps->SetTextColor(kTeal+3);
TPaveStats* fallps= (TPaveStats*)(Hist_fall_position->FindObject("stats"));
fallps->SetX1NDC(.1);
fallps->SetX2NDC(.3);
fallps->SetY1NDC(.5);
fallps->SetY2NDC(.7);
fallps->SetTextColor(1);
gPad->SetLogy();
Hist_rise_position->Fit("gaus","RWW","same",inte_start,inte_end*.95);
TF1 *rise_fit =(TF1 *) Hist_rise_position->GetFunction("gaus");
rise_fit->SetLineWidth(3);
double tts=rise_fit->GetParameter("Sigma");
TLatex *hittex=new TLatex();
hittex->DrawLatex(200,30,Form("hit time = %5.3g ns",Hist_sig_min_position->GetMean()));
//------------------------------------------------------------------------------------------------------------fig8
pmt_can->cd(8);
gPad->SetGrid();
Hist_nQDC->Draw();
Hist_nQDC->GetYaxis()->SetNdivisions(5, kFALSE);
Hist_sQDC->GetXaxis()->SetTitle("QDC[pC]");
Hist_sQDC->GetYaxis()->SetTitle("count");
Hist_nQDC->GetXaxis()->SetTitle("QDC[pC]");
Hist_nQDC->GetYaxis()->SetTitle("count");
Hist_sQDC->Draw("sames");
Hist_sQDC->SetLineColor(kTeal+3);
Hist_sQDC->SetLineWidth(2);
//Hist_nQDC->SetFillStyle(3003);
//Hist_nQDC->SetFillColor(4);
Hist_nQDC->SetLineColor(1);
Hist_nQDC->SetLineWidth(2);
//Hist_sQDC->SetFillStyle(3003);
//Hist_sQDC->SetFillColor(8);
gPad->Update();
TPaveStats* sQDCps= (TPaveStats*)Hist_sQDC->FindObject("stats");
sQDCps->SetX1NDC(.7);
sQDCps->SetX2NDC(.9);
sQDCps->SetY1NDC(.7);
sQDCps->SetY2NDC(.9);
sQDCps->SetTextColor(kTeal+3);
TPaveStats* nQDCps= (TPaveStats*)(Hist_nQDC->FindObject("stats"));
nQDCps->SetX1NDC(.7);
nQDCps->SetX2NDC(.9);
nQDCps->SetY1NDC(.5);
nQDCps->SetY2NDC(.7);
nQDCps->SetTextColor(1);
gPad->SetLogy();
TLatex *nstex=new TLatex();
nstex->DrawLatex(4,pv_p*1.3,Form("#frac{n_{signal}}{n_{total}} = %5.3g",Hist_sQDC->GetEntries()/(Hist_sQDC->GetEntries()+Hist_nQDC->GetEntries())));
//------------------------------------------------------------------------------------------------------------fig10
pmt_can->cd(10);
Hist_peakspec->Draw();
Hist_peakspec->GetYaxis()->SetNdivisions(5, kFALSE);
Hist_peakspec->SetFillStyle(3618);
Hist_peakspec->SetFillColorAlpha(8,0.5);
//Hist_peakspec->SetFillStyle(3003);
//Hist_peakspec->SetFillColor(2);
Hist_peakspec->SetLineColor(kTeal+3);
Hist_peakspec->SetLineWidth(2);
Hist_peakspec->GetYaxis()->SetTitle("count");
Hist_peakspec->GetXaxis()->SetTitle("U[mV]");
gPad->SetBottomMargin(.08);
gPad->SetGrid();
gPad->SetLogy();
gPad->Update();
TPaveStats* ampsps= (TPaveStats*)(Hist_peakspec->FindObject("stats"));
ampsps->SetX1NDC(.7);  //change the position of the stats box for the first plot
ampsps->SetX2NDC(.9);
ampsps->SetY1NDC(.7);
ampsps->SetY2NDC(.9);
ampsps->SetTextColor(kTeal+3);
Hist_peakspec->GetXaxis()->SetRange(23,40);
int amp_maxbin=Hist_peakspec->GetMaximumBin();
Hist_peakspec->GetXaxis()->SetRange(22,28);
int amp_minbin=Hist_peakspec->GetMinimumBin();
//cout<<"ssss"<<amp_maxbin<<" "<<amp_minbin<<endl;
TLine *amp_pline=new TLine(-20,Hist_peakspec->GetBinContent(amp_maxbin),50,Hist_peakspec->GetBinContent(amp_maxbin));
amp_pline->SetLineStyle(8);
amp_pline->SetLineColor(2);
amp_pline->SetLineWidth(3);
amp_pline->Draw();
TLine *amp_vline=new TLine(-20,Hist_peakspec->GetBinContent(amp_minbin),50,Hist_peakspec->GetBinContent(amp_minbin));
amp_vline->SetLineStyle(8);
amp_vline->SetLineColor(2);
amp_vline->SetLineWidth(3);
amp_vline->Draw();
Hist_peakspec->GetXaxis()->SetRange(0,100);
TLatex *ampstex=new TLatex();
ampstex->DrawLatex(15,.5*(Hist_peakspec->GetBinContent(amp_maxbin)+Hist_peakspec->GetBinContent(amp_minbin)),Form("P/V_{amp} = %5.3g ",Hist_peakspec->GetBinContent(amp_maxbin)*1./Hist_peakspec->GetBinContent(amp_minbin)));
TLatex *amptex=new TLatex();
amptex->DrawLatex(15,Hist_peakspec->GetBinContent(amp_minbin),Form("Average amplitude = %5.3g mV",Hist_sig_amplitude->GetMean()));
//------------------------------------------------------------------------------------------------------------fig4
pmt_can->cd(4);
Hist_amp_qdc->Draw("colz");
gPad->SetLogz();
gPad->SetGrid();
Hist_amp_qdc->SetFillStyle(3003);
Hist_amp_qdc->SetFillColor(4);
Hist_amp_qdc->SetLineColor(1);
Hist_amp_qdc->SetLineWidth(2);
Hist_amp_qdc->GetYaxis()->SetTitle("QDC[pC]");
Hist_amp_qdc->GetXaxis()->SetTitle("amplitude[mV]");
//TLatex *amp_qdctex=new TLatex();
//amp_qdctex->DrawLatex(20,.5*Hist_amp_qdc->GetMaximum(),Form("#bar{FWHM} = %5.3g ns",Hist_amp_qdc->GetMean()));
gPad->Update();
TPaveStats* amp_qdcps= (TPaveStats*)(Hist_amp_qdc->FindObject("stats"));
amp_qdcps->SetX1NDC(.6);  //change the position of the stats box for the first plot
amp_qdcps->SetX2NDC(.9);
amp_qdcps->SetY1NDC(.1);
amp_qdcps->SetY2NDC(.4);
//corg->Draw(" AP");
corg->GetXaxis()->SetRangeUser(-2,40);
corg->GetYaxis()->SetRangeUser(-2,8);
TF1 *lfit =new TF1("lfit","[0]*x",3,20);
lfit->SetParNames("slope");
lfit->SetParLimits(0,0.01,1);
corg->Fit("lfit","R+WW","same",3,20);
//TF1 *lfit =(TF1 *) corg->GetFunction("pol1");
corf=lfit->GetParameter("slope");
lfit->Draw("SAME");
TLatex *cortex=new TLatex();
cortex->DrawLatex(15,6,Form("QDC = %5.3g Amp",corf));
//***************************************************************************************************
// extra pars
//double pe0mean=mygaus->GetParameter("mean1");
ped_count=Hist_QDC_sig1->Integral(0,((.4+pe0mean)+2)*8);
noped_count=Hist_QDC_sig1->Integral(((.4+pe0mean)+2)*8,200);
mu=-TMath::Log(ped_count*1./nevent);
//pde=mu*100*.93*.956/mufactor[channel_num%100-1];
pde=mu*self_factor_sys1[channel_num%100-1];
if(pmt_type==0)pde=pde*0.897;
else pde=pde*.897;

if(sys_id==2){
pde=mu*100./mufactor[channel_num%100-1];
}
//cout<<"delta n 0 is"<<deltaN0<<" "<<ped_count<<endl;
pde_err=(deltaN0*1./ped_count)*100*.93*.956/mufactor[channel_num%100-1];
//if(lt_tag==1)pde=mu*1000*.93*.956/nsntfactor_sys1[channel_num%100-1];
ave_charge=ave_charge*1./noped_count;
hit_time=Hist_sig_min_position->GetMean();
rise_position_mean=Hist_rise_position->GetMean();
fall_position_mean=Hist_fall_position->GetMean();
rise_time_mean=Hist_rise_time->GetMean();
fall_time_mean=Hist_fall_time->GetMean();
pv_amp=Hist_peakspec->GetBinContent(amp_maxbin)*1./Hist_peakspec->GetBinContent(amp_minbin);
fwhm_mean=Hist_fwhm->GetMean();
amp_mean=Hist_sig_amplitude->GetMean();
nsnt=Hist_sQDC->GetEntries()/(Hist_sQDC->GetEntries()+Hist_nQDC->GetEntries());
valley_pos=pe1min_conv/8.-2;    //the valley position in the charge spectrum.
gain_err=sqrt(TMath::Power(pe1max_error,2)+TMath::Power(pe0mean_err,2));
//plot extra pars
pmt_can->cd(2);
resolutiontex->DrawLatex(9,200,Form("average QDC = %5.3g pC",ave_charge));
TLatex *pdetex=new TLatex();
pdetex->DrawLatex(13,1000,Form("#mu = %5.3g ",mu));
if(lt_tag==1)pdetex->DrawLatex(9,500,Form("PDE(not stable) = %5.3g%%",pde));
else pdetex->DrawLatex(10,500,Form("PDE = %5.3g #pm %5.3g %%",pde,pde_err));
//pmt_can->cd();
//pmt_can->SetBottomMargin(.5);
//   TPaveLabel *title = new TPaveLabel(.11,.95,.35,.99,"new title","brndc");
//   title->Draw();
pmt_can->cd();
TPad *mypad1 = new TPad("mypad1","This is mypad1",0.01,0.00,0.95,0.95);
mypad1->Draw();
//mypad1->SetFillColor(11);
mypad1->SetFillStyle(4000);
//pad1->SetFrameFillStyle(4000);
mypad1->cd();
gPad->SetFillStyle(0);
gPad->SetFrameFillStyle(0);
TLatex *bgtex = new TLatex(.03,.662,"JUNO 20\" PMT Qualification Test ");
bgtex->Draw();
bgtex->SetTextColorAlpha(8, 0.176);
bgtex->SetTextSize(0.1091524);
TLatex *bgtex1 = new TLatex(.263,.31,"SN: "+pmt_id);
bgtex1->Draw();
bgtex1->SetTextColorAlpha(8, 0.176);
bgtex1->SetTextSize(0.1191525);
TLatex *bottex = new TLatex(.0263,.002,"******* The PMT "+pmt_id+" was tested on "+test_date+" in the container"+sys_id_s+" drawer"+channel_num_s+". PDE is "+Form("%5.3g%%",pde)+",DCR is"+Form("%5.3g kHz",cont_dcr)+" ------------ Vendor Data:"+"DE="+Form("%5.3g",vendor_qeout)+"\% DCR="+Form("%5.3g kHz",vendor_dcr)+"  --------  Email:zhaor25@mail2.sysu.edu.cn"+" ******");
bottex->Draw();
bottex->SetTextColorAlpha(kTeal+3, 0.976);
bottex->SetTextSize(0.0131525);
//bgtex->SetTextAngle(26.15998);
pmt_can->cd();
pmt_can->Modified();
pmt_can->Update();
//display the JUNO logo
TPad *junologopad = new TPad("junologopad","This is mypad1",0.0,0.0,0.031,0.046);
junologopad->Draw();
junologopad->cd();
junologopad->SetFillStyle(4000);
TImage *junoimg = TImage::Open("junologo.jpg");
if (!junoimg) {
      printf("Could not create an image... exit\n");
   }
  junoimg->SetConstRatio(0);
  junoimg->SetImageQuality(TAttImage::kImgBest);
  junoimg->Draw("xxx");
  junoimg->SetEditable(kTRUE);
/***************************************/

double mus[15]={0};
mus[0]=mu;
mus[1]=nsnt;
mus[2]=-TMath::Log(8*sqrt(2*TMath::Pi())*myn*mysigma0/nevent);
mus[3]=Hist_QDC_sig1->GetBinContent((int)((myq1+2)*8))*mysigma1*sqrt(2.*TMath::Pi());
mus[3]=mus[3]/(myn*1.);
mus[4]=mus[3]*(1+2*myfmu+3*mygmu);
double myn0=nevent/8.-Hist_QDC_sig1->GetBinContent((int)((myq1+2)*8))*mysigma1*sqrt(2.*TMath::Pi())-
Hist_QDC_sig1->GetBinContent((int)((myq1*2+2)*8))*mysigma1*sqrt(4.*TMath::Pi())-
Hist_QDC_sig1->GetBinContent((int)((myq1*3+2)*8))*mysigma1*sqrt(6.*TMath::Pi())-
Hist_QDC_sig1->GetBinContent((int)((myq1*4+2)*8))*mysigma1*sqrt(8.*TMath::Pi());
mus[5]=-TMath::Log(8*sqrt(2*TMath::Pi())*myn0*mysigma0/nevent);
mus[6]=Hist_QDC_sig1->GetBinContent((int)((myq1+2)*8))*mysigma1*sqrt(2.*TMath::Pi());
mus[6]=mus[6]/(myn0*1.);
mus[7]=mus[6]*(1+2*myfmu+3*mygmu);
mus[8]=mymu;
mus[9]=mymu*(1+myfmu*2+mygmu*3);
mus[10]=(cnntag[1]+cnntag[2]+cnntag[3])/nevent;   //signal/total--(n1+n2+n3)/n
mus[11]=-TMath::Log(cnntag[0]/nevent);    //-log (n0/n)
mus[12]=(cnntag[1]+2*cnntag[2]+3*cnntag[3])/nevent;    //(n1+2*n2+3*n3)/n
mus[13]=cnntag[1]/cnntag[0];    //n1/n0
mus[14]=cnntag[2]/cnntag[1];    //n2/n1*2

for(int i=0;i<15;i++){
cout<<"mus"<<i<<"is"<<mus[i]<<endl;
}
/***************************************writing histograms*******************************************************/
performance_info->Fill();
Hist_wave2d->Write();
Hist_charge2d->Write();
Hist_amp2d->Write();
Hist_amp_qdc->Write();
Hist_sig_profile2d->Write();
Hist_ave_waveform->Write();
Hist_baseline->Write();
Hist_rise_position->Write();												//writing histogram
Hist_fall_position->Write();
Hist_fwhm->Write();
Hist_rise_time->Write();
Hist_fall_time->Write();
Hist_rise_time_start->Write();
Hist_rise_time_end->Write();
Hist_fall_time_start->Write();
Hist_fall_time_end->Write();
Hist_fwhm_start->Write();
Hist_fwhm_end->Write();
Hist_sig_min_position->Write();
Hist_sig_min_value->Write();
Hist_sig_amplitude->Write();
Hist_sig_profile->Write();
Hist_QDC_sig1->Write();
Hist_QDC_sig1_conv->Write();
Hist_QDC_dn1->Write();
Hist_QDC_sig->Write();
Hist_QDC_dn->Write();
Hist_sQDC->Write();
Hist_nQDC->Write();
Hist_peakspec->Write();
outroot_file->Write();														//writing root file

//double mu1=Hist_QDC_sig1->Integral(pe1min_conv,200)/(nevent-Hist_QDC_sig1->Integral(pe1min_conv,200));
//double mu2=noped_count*1./(nevent-noped_count);
//double mu3=sig_inwindow_count*1./(nevent-sig_inwindow_count);
//double mu4=-TMath::Log(Hist_QDC_sig1->Integral(0,pe1min_conv)*1./nevent);
//double mu5=-TMath::Log(ped_count*1./nevent);
//double mu6=-TMath::Log((nevent-sig_inwindow_count)*1./nevent);
//cout<<"123456:"<<mu<<" "<<mu1<<" "<<mu2<<" "<<mu3<<" "<<mu4<<" "<<mu5<<" "<<mu6<<endl;

/********************************************************writing the canvas to a file*******************************************************/
//pmt_can->SaveAs(outpdf_name);
checkcan->Print(outpdf_name_end);
pmt_can->Write();
pmt_can->SaveAs(outpng_name);
/********************************* the output test ********************************************/
//cout<<"sys_id:"<<sys_id<<" mass number:"<<mass_num<<" channel number:"<<channel_num<<" pmtid:"<<pmt_id<<" light intensity:"<<lt_tag<<"test times:"<<test_times<<" pmt type:"<<pmt_type<<" vendor HV:"<<vendor_HV<<" fit HV:"<<fit_HV<<" base type:"<<base_type<<" test date:"<<test_date<<"vendor qe:"<<vendor_qe<<" vendor ap:"<<vendor_ap<<" vendor dcr:"<<vendor_dcr<<" vendor tts:"<<vendor_tts<<" vendor rt:"<<vendor_rt<<" vendor ft:"<<vendor_ft<<" vendor resolution:"<<vendor_res<<" vendor pvr:"<<vendor_pvr<<"cont_dcr:"<<cont_dcr<<"ave_baseline:"<<average_baseline<<"nevent:"<<nevent<<"inte_start:"<<inte_start<<"inte_end:"<<inte_end<<"hittime:"<<hit_time<<"GAIN:"<<gain<<"total charge"<<ave_charge<<"pe1min_conv:"<<pe1min_conv<<"rise_pos_mean:"<<Hist_rise_position->GetMean()<<"fall_pos_mean:"<<Hist_fall_position->GetMean()<<"rt"<<Hist_rise_time->GetMean()<<"ft"<<Hist_fall_time->GetMean()<<"sig count"<<signal_count<<"sig inwindow cou nt"<<sig_inwindow_count<<"pe0count"<<ped_count<<"pe1count"<<noped_count<<"fwhm_mean"<<Hist_fwhm->GetMean()<<"pvr"<<pvratio<<"pv_amp"<<Hist_peakspec->GetBinContent(amp_maxbin)*1./Hist_peakspec->GetBinContent(amp_minbin)<<"snr"<<snr<<"qdc_amp"<<corf<<"nsnt"<<Hist_sQDC->GetEntries()/(Hist_sQDC->GetEntries()+Hist_nQDC->GetEntries())<<"mu:"<<mu<<"PDE:"<<mu*1.<<"DCRsoft:"<<soft_dcr<<"amp_mean:"<<Hist_sig_amplitude->GetMean()<<endl;
//cout<<
ofstream outtxt(outtxt_name);
ofstream outtxt_all(outtxt_all_name,ios::app);

//outtxt<<sys_id<<" "<<mass_num<<" "<<channel_num<<" "<<pmt_id<<" "<<lt_tag<<" "<<pmt_type<<" "<<base_type<<" "<<test_date<<" "<<vendor_HV<<" "<<fit_HV<<" "<<inte_start<<" "<<inte_end<<" "<<average_baseline<<" "<<test_times<<" "<<vendor_qe<<" "<<vendor_ap<<" "<<vendor_dcr<<" "<<vendor_tts<<" "<<vendor_rt<<" "<<vendor_ft<<" "<<vendor_res<<" "<<vendor_pvr<<" "<<cont_dcr<<" "<<soft_dcr<<" "<<nevent<<" "<<hit_time<<" "<<gain<<" "<<ave_charge<<" "<<rise_position_mean<<" "<<fall_position_mean<<" "<<rise_time_mean<<" "<<fall_time_mean<<" "<<fwhm_mean<<" "<<amp_mean<<" "<<signal_count<<" "<<sig_inwindow_count<<" "<<ped_count<<" "<<noped_count<<" "<<pvratio<<" "<<pv_amp<<" "<<snr<<" "<<pe1resolution<<" "<<corf<<" "<<nsnt<<" "<<mu<<" "<<pde<<" "<<baseline_sigma<<" "<<valley_pos<<" "<<pe1max_error<<" "<<pe0mean_err<<" "<<gain_err<<" "<<pde_err<<" "<<pmtnum<<" "<<umass_num<<endl;
//outtxt_all<<sys_id<<" "<<mass_num<<" "<<channel_num<<" "<<pmt_id<<" "<<lt_tag<<" "<<pmt_type<<" "<<base_type<<" "<<test_date<<" "<<vendor_HV<<" "<<fit_HV<<" "<<inte_start<<" "<<inte_end<<" "<<average_baseline<<" "<<test_times<<" "<<vendor_qe<<" "<<vendor_ap<<" "<<vendor_dcr<<" "<<vendor_tts<<" "<<vendor_rt<<" "<<vendor_ft<<" "<<vendor_res<<" "<<vendor_pvr<<" "<<cont_dcr<<" "<<soft_dcr<<" "<<nevent<<" "<<hit_time<<" "<<gain<<" "<<ave_charge<<" "<<rise_position_mean<<" "<<fall_position_mean<<" "<<rise_time_mean<<" "<<fall_time_mean<<" "<<fwhm_mean<<" "<<amp_mean<<" "<<signal_count<<" "<<sig_inwindow_count<<" "<<ped_count<<" "<<noped_count<<" "<<pvratio<<" "<<pv_amp<<" "<<snr<<" "<<pe1resolution<<" "<<corf<<" "<<nsnt<<" "<<mu<<" "<<pde<<" "<<baseline_sigma<<" "<<valley_pos<<" "<<pe1max_error<<" "<<pe0mean_err<<" "<<gain_err<<" "<<pde_err<<" "<<pmtnum<<" "<<umass_num<<endl;
outtxt<<sys_id<<" "<<mass_num<<" "<<channel_num<<" "<<pmt_id<<" "<<lt_tag<<" "<<pmt_type<<" "<<base_type<<" "<<test_date<<" "<<vendor_HV<<" "<<fit_HV<<" "<<inte_start<<" "<<inte_end<<" "<<average_baseline<<" "<<test_times<<" "<<vendor_qe<<" "<<vendor_ap<<" "<<vendor_dcr<<" "<<vendor_tts<<" "<<vendor_rt<<" "<<vendor_ft<<" "<<vendor_res<<" "<<vendor_pvr<<" "<<cont_dcr<<" "<<soft_dcr<<" "<<nevent<<" "<<hit_time<<" "<<gain<<" "<<ave_charge<<" "<<rise_position_mean<<" "<<fall_position_mean<<" "<<rise_time_mean<<" "<<fall_time_mean<<" "<<fwhm_mean<<" "<<amp_mean<<" "<<signal_count<<" "<<sig_inwindow_count<<" "<<ped_count<<" "<<noped_count<<" "<<pvratio<<" "<<pv_amp<<" "<<snr<<" "<<pe1resolution<<" "<<corf<<" "<<nsnt<<" "<<mu<<" "<<pde<<" "<<baseline_sigma<<" "<<valley_pos<<" "<<pe1max_error<<" "<<pe0mean_err<<" "<<gain_err<<" "<<pde_err<<" "<<pmtnum<<" "<<umass_num<<" "<<mus[0]<<" "<<mus[1]<<" "<<mus[2]<<" "<<mus[3]<<" "<<mus[4]<<" "<<mus[5]<<" "<<mus[6]<<" "<<mus[7]<<" "<<mus[8]<<" "<<mus[9]<<" "<<mus[10]<<" "<<mus[11]<<" "<<mus[12]<<" "<<mus[13]<<" "<<mus[14]<<endl;
outtxt_all<<sys_id<<" "<<mass_num<<" "<<channel_num<<" "<<pmt_id<<" "<<lt_tag<<" "<<pmt_type<<" "<<base_type<<" "<<test_date<<" "<<vendor_HV<<" "<<fit_HV<<" "<<inte_start<<" "<<inte_end<<" "<<average_baseline<<" "<<test_times<<" "<<vendor_qe<<" "<<vendor_ap<<" "<<vendor_dcr<<" "<<vendor_tts<<" "<<vendor_rt<<" "<<vendor_ft<<" "<<vendor_res<<" "<<vendor_pvr<<" "<<cont_dcr<<" "<<soft_dcr<<" "<<nevent<<" "<<hit_time<<" "<<gain<<" "<<ave_charge<<" "<<rise_position_mean<<" "<<fall_position_mean<<" "<<rise_time_mean<<" "<<fall_time_mean<<" "<<fwhm_mean<<" "<<amp_mean<<" "<<signal_count<<" "<<sig_inwindow_count<<" "<<ped_count<<" "<<noped_count<<" "<<pvratio<<" "<<pv_amp<<" "<<snr<<" "<<pe1resolution<<" "<<corf<<" "<<nsnt<<" "<<mu<<" "<<pde<<" "<<baseline_sigma<<" "<<valley_pos<<" "<<pe1max_error<<" "<<pe0mean_err<<" "<<gain_err<<" "<<pde_err<<" "<<pmtnum<<" "<<umass_num<<" "<<mus[0]<<" "<<mus[1]<<" "<<mus[2]<<" "<<mus[3]<<" "<<mus[4]<<" "<<mus[5]<<" "<<mus[6]<<" "<<mus[7]<<" "<<mus[8]<<" "<<mus[9]<<" "<<mus[10]<<" "<<mus[11]<<" "<<mus[12]<<" "<<mus[13]<<" "<<mus[14]<<endl;
outtxt.close();
outtxt_all.close();
//TFile *outroot_all_file=new TFile(outroot_all_name,"UPDATE");									//the output root file that contain all the information
//TTree *all_par_info=(TTree*) outroot_all_file->Get("all_par_info");										//the tree contain the key parameters
//all_par_info->SetBranchAddress("sys_id",&sys_id);
//all_par_info->SetBranchAddress("pmt_id",&pmt_id);
//all_par_info->SetBranchAddress("mass_num",&mass_num);
//all_par_info->SetBranchAddress("channel_num",&channel_num);
//all_par_info->SetBranchAddress("lt_tag",&lt_tag);
//all_par_info->SetBranchAddress("pmt_type",&pmt_type);
//all_par_info->SetBranchAddress("base_type",&base_type);
//all_par_info->SetBranchAddress("vendor_HV",&vendor_HV);
//all_par_info->SetBranchAddress("fit_HV",&fit_HV);
//all_par_info->SetBranchAddress("inte_start",&inte_start);
//all_par_info->SetBranchAddress("inte_end",&inte_end);
//all_par_info->SetBranchAddress("average_baseline",&average_baseline);
//all_par_info->SetBranchAddress("test_times",&test_times);
performance_SetBranchAddressBranch("Hist_wave2d",&Hist_wave2d,128000,0);
//all_par_info->SetBranchAddress("vendor_qe",&vendor_qe);
//all_par_info->SetBranchAddress("vendor_ap",&vendor_ap);
//all_par_info->SetBranchAddress("vendor_dcr",&vendor_dcr);
//all_par_info->SetBranchAddress("vendor_tts",&vendor_tts);
//all_par_info->SetBranchAddress("vendor_rt",&vendor_rt);
//all_par_info->SetBranchAddress("vendor_ft",&vendor_ft);
//all_par_info->SetBranchAddress("vendor_res",&vendor_res);
//all_par_info->SetBranchAddress("vendor_pvr",&vendor_pvr);
//all_par_info->SetBranchAddress("cont_dcr",&cont_dcr);
//all_par_info->SetBranchAddress("soft_dcr",&soft_dcr);
//all_par_info->SetBranchAddress("nevent",&nevent);
//all_par_info->SetBranchAddress("hit_time",&hit_time);
//all_par_info->SetBranchAddress("gain",&gain);
//all_par_info->SetBranchAddress("ave_charge",&ave_charge);
//all_par_info->SetBranchAddress("pe1min_conv",&pe1min_conv);
//all_par_info->SetBranchAddress("rise_position_mean",&rise_position_mean);
//all_par_info->SetBranchAddress("fall_position_mean",&fall_position_mean);
//all_par_info->SetBranchAddress("rise_time_mean",&rise_time_mean);
//all_par_info->SetBranchAddress("fall_time_mean",&fall_time_mean);
//all_par_info->SetBranchAddress("fwhm_mean",&fwhm_mean);
//all_par_info->SetBranchAddress("amp_mean",&amp_mean);
//all_par_info->SetBranchAddress("signal_count",&signal_count);
//all_par_info->SetBranchAddress("sig_inwindow_count",&sig_inwindow_count);
//all_par_info->SetBranchAddress("ped_count",&ped_count);
//all_par_info->SetBranchAddress("noped_count",&noped_count);
//all_par_info->SetBranchAddress("pvratio",&pvratio);
//all_par_info->SetBranchAddress("pv_amp",&pv_amp);
//all_par_info->SetBranchAddress("snr",&snr);
//all_par_info->SetBranchAddress("corf",&corf);
//all_par_info->SetBranchAddress("nsnt",&nsnt);
//all_par_info->SetBranchAddress("mu",&mu);
//all_par_info->SetBranchAddress("pde",&pde);
//all_par_info->Fill();
//outroot_all_file->Write();

return 0;

} //end of main program

参考连接:
http://www.cnblogs.com/logsharing/p/7986825.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值