Beispiel #1
0
bool mu::loadFromFile(const std::string file_name, cv::Mat &K, cv::Mat &radial, cv::Mat &R,
        cv::Mat &t) {

    std::string current_line;
    std::vector<double> numbers;
    std::ifstream f(file_name);

    if (f.is_open()) {
        // (3x3) camera matrix K
        K = cv::Mat(3, 3, CV_64F);

        for (int k = 0; k < 3; k++) {
            getline(f, current_line);
            string2double(current_line, numbers);

            K.at<double>(k, 0) = numbers[0];
            K.at<double>(k, 1) = numbers[1];
            K.at<double>(k, 2) = numbers[2];
        }

        // (3) radial distortion parameters
        radial = cv::Mat(1, 3, CV_64F);
        getline(f, current_line);
        string2double(current_line, numbers);

        radial.at<double>(0, 0) = numbers[0];
        radial.at<double>(0, 1) = numbers[1];
        radial.at<double>(0, 2) = numbers[2];

        // (3x3) rotation matrix R
        R = cv::Mat(3, 3, CV_64F);

        for (int k = 0; k < 3; k++) {
            getline(f, current_line);
            string2double(current_line, numbers);

            R.at<double>(k, 0) = numbers[0];
            R.at<double>(k, 1) = numbers[1];
            R.at<double>(k, 2) = numbers[2];
        }

        // (3) translation vector t
        t = cv::Mat(1, 3, CV_64F);
        getline(f, current_line);
        string2double(current_line, numbers);

        t.at<double>(0, 0) = numbers[0];
        t.at<double>(0, 1) = numbers[1];
        t.at<double>(0, 2) = numbers[2];

        f.close();

        return true;
    }

    return false;
}
Beispiel #2
0
double string2date(const std::string &str, Node::ErrorCode &error)
{
    std::string str1(trim(str));
    // Validate
    if (str1.find('-') != std::string::npos)
    {
        error = Node::InvalidFormat;
        return 0;
    }

    // Year
    error = Node::NoError;
    int year = string2int(str1.substr(0, 2).c_str(), error);
    if (error != Node::NoError)
        return 0;

    year += (year < (UNIX_FIRST_YEAR - (UNIX_FIRST_YEAR / 100) * 100))
          ? 2000
          : 1900;

    double res = 0;
    for (int y = UNIX_FIRST_YEAR; y < year; y++)
    {
        // If current year is leap
        bool leap = !(y % 4) && ((y % 100) || !(y % 400));
        res += leap ? 366 : 365;
    }
    // Years -> seconds
    res *= 86400;
    // Additional part
    res +=
       (string2double(str1.substr(2, str1.length() - 2), error) - 1) * 86400;

    return res;
}
Beispiel #3
0
void Applicant::loadApplicants(const std::string &fileName, std::vector<Applicant> &applicants)
{
	/*
	1. řádek label - pamatovat
	2. řádek - zadání počtů = integery
	další nabídky
	*/

	// cena vyšetření na přístoj = (počet vyšetření) *  ((spec. cena) + (nespecif. cena))
	// celková cena = součet možných přístojů + minim. z cen vyštření/přístoj pro každé vyšetření

	std::ifstream f;
	if (!f) {
		f.close();
		throw InvalidInputException("Nepodarilo se otevrit vstupni soubor");
	}

	f.open(fileName, std::ifstream::in);

	std::string line;

	getline(f, line);
	getline(f, line);

	while (getline(f, line)) {
		auto chunks = explode(line, ';');

		std::vector<double> vals;
		for (auto it = chunks.begin() + 4; it != chunks.end(); ++it) {
			if (it->size() == 0) {
				vals.push_back(-1);
			}
			else {
				vals.push_back(string2double(*it));
			}
		}
		applicants.push_back(Applicant(chunks.at(0), chunks.at(1), string2double(chunks.at(2)), string2double(chunks.at(3)), vals));
	}

	f.close();
}
Beispiel #4
0
vector<double> read_vector_file(string filename) {
//    cerr << "Loading " << filename << endl;
    ifstream myfile(filename.c_str());
    std::stringstream ss;

    vector<double> M;
    if (myfile.is_open()) {
        string line;
        while ( getline(myfile,line) ) {
            M.push_back(string2double(line));
        }
    }
    return M;
}
Beispiel #5
0
bool PacketDescriptor::setFieldAsString(void *object, int field, int i, const char *value) const
{
    cClassDescriptor *basedesc = getBaseClassDescriptor();
    if (basedesc) {
        if (field < basedesc->getFieldCount(object))
            return basedesc->setFieldAsString(object,field,i,value);
        field -= basedesc->getFieldCount(object);
    }
    Packet *pp = (Packet *)object; (void)pp;
    switch (field) {
        case 0: pp->setSrc(string2long(value)); return true;
        case 1: pp->setDst(string2long(value)); return true;
        case 2: pp->setSessionID(string2long(value)); return true;
        case 3: pp->setPacketID(string2long(value)); return true;
        case 4: pp->setPriority(string2long(value)); return true;
        case 5: pp->setHops(string2long(value)); return true;
        case 6: pp->setPayload(string2long(value)); return true;
        case 7: pp->setDs(string2long(value)); return true;
        case 8: pp->setCreationTime(string2double(value)); return true;
        default: return false;
    }
}
Beispiel #6
0
vector<vector<double> > read_2D_vector_file(string filename, char sep) {
 //   cerr << "Loading " << filename << endl;
    ifstream myfile(filename.c_str());
    std::stringstream ss;

    vector<vector<double> > M;
    if (myfile.is_open()) {
        string line;

        while ( getline(myfile,line) ) {
            vector<string> fields;
            split(line, sep, fields);

            vector<double>row(fields.size());
            for( unsigned int i=0; i < fields.size(); i++ ) {
                    row[i] = string2double(fields[i]);
            }
            M.push_back(row);
        }
    }
    return M;
}
Beispiel #7
0
double parseDouble(const std::string *line, const std::size_t start,
                   const std::size_t length, Node::ErrorCode &error,
                   const bool decimalPointAssumed)
{
    if (!line)
        return 0;

    if (line->length() < start + length)
    {
        error = Node::TooShortString;
        return 0;
    }

    std::string val = trim(line->substr(start, length));
    // Prepare string
    if (decimalPointAssumed)
    {
        if (val[0] == '-' || val[0] == '+')
            val = val.substr(0, 1) + "0." + val.substr(1, val.length() - 1);
        else
            val = "0." + val;
    }
    // -- 123-4 or 123+4 -> 123e-4 or 123e4 --
    std::size_t pos = val.rfind('-');
    if (pos != std::string::npos && pos && val[pos - 1] != 'e'
                                                       && val[pos - 1] != 'E')
    {
        val.replace(pos, 1, "e-");
    }
    pos = val.rfind('+');
    if (pos != std::string::npos && pos && val[pos - 1] != 'e'
                                                       && val[pos - 1] != 'E')
    {
        val.replace(pos, 1, "e+");
    }

    return string2double(val.c_str(), error);
}
Beispiel #8
0
int main(int argc, char* argv[]){
	std::stringstream buff;

	//=======================================
	//*************read parameter**********
	//if (argc==1) {
	//	print_usage(argv[0]);
	//	return -1;
	//}
	init_args();
	int result;
	while((result=getopt(argc,argv,"hbv:n:m:p:"))!=-1){
		switch(result){
			/* INPUTS */
			case 'm':
				strcpy(m_workMode,optarg);
				printf("work mode: %s\n",m_workMode);
				break;
			case 'v':
				verbose = atoi(optarg);
				printf("verbose level: %d\n",verbose);
				break;
			case 'b':
				backup = true;
				printf("restore backup file!\n");
				break;
			case 'n':
				nEvents = atoi(optarg);
				printf("nEvent: %d\n",nEvents);
				break;
			case 'p':
				printModule = atoi(optarg);
				printf("printModule: %d\n",printModule);
				break;
			case '?':
				printf("Wrong option! optopt=%c, optarg=%s\n", optopt, optarg);
				break;
			case 'h':
			default:
				print_usage(argv[0]);
				return 1;
		}
	}

	//for (;optind<argc;optind++){
	//	m_input_files.push_back(argv[optind]);
	//}

	//=======================================
	//************Verbose Control***********
	int Verbose_SectorInfo = 5; //大概的流程情况
	std::string prefix_SectorInfo = "### ";
	int Verbose_HistInfo = 10; //有哪些hist,什么时候输出了,参数如何
	std::string prefix_HistInfo= "  [Histograms] ";
	int Verbose_Statistics = 10; //跟统计相关的(效率,分辨,粒子鉴别的情况)
	std::string prefix_Statistics="  [Statistics] ";
	int Verbose_FileInfo = 10; //有哪些FileList,都有多少file
	std::string prefix_FileInfo="  [FileInfo] ";
	int Verbose_EffInfo = 15; //Efficiency info
	std::string prefix_EffInfo="  [EffInfo] ";
	int Verbose_EventInfo = 20; //每个event的基本流程
	std::string prefix_EventInfoStart="    =>[EventInfo] ";
	std::string prefix_EventInfo="      [EventInfo] ";
	int Verbose_ParticleInfo=25; //每个particle的基本信息
	std::string prefix_ParticleInfoStart="    ->[ParticleInfo]";
	std::string prefix_ParticleInfo="      [ParticleInfo]";

	//=======================================================================================================
	//************PRESET********************
	if (verbose >= Verbose_SectorInfo ) std::cout<<prefix_SectorInfo<<"In PRESET###"<<std::endl;

	//=> About Histogram
	std::string histList = "histList";
	int index_temp;

	//=>About Constant
	double PI = 3.141592653589793238;
	double FSC = 1/137.03599911; //fine structure constant
	double M_MUON = 0.1056584; //mass of muon in GeV
	double M_ELE = 0.510999e-3; //mass of electron in GeV
	double M_U = 0.931494061; //atomic mass unit in GeV
	double M_p = 0.9382723; // proton mass unit in GeV

	//=>About output
	std::string OutputDir = "result/";

	//=======================================================================================================
	//************SET HISTOGRAMS********************
	if (verbose >= Verbose_SectorInfo ) std::cout<<prefix_SectorInfo<<"In SET HISTOGRAMS###"<<std::endl;
 
	//=>Read histList
	std::ifstream fin_card(histList.c_str());
	if(!fin_card){
		std::cout<<"Cannot find "<<histList<<std::endl;
	}
	std::string s_card;
	std::vector<std::string> DirNames; 
	std::vector<std::string> RunNames; 
	std::vector<int> NCPU;
	std::vector<int> NJob;
	double beamPx = 0;
	double beamPy = 0;
	double beamPz = 0;
	// read histList
	while(getline(fin_card,s_card)){
		if ( ISEMPTY(s_card) ) continue;
		std::vector<std::string> segments;
		seperate_string(s_card,segments,'|');
		int iterator = 1;
		if ( segments[0] == "TH1D" ){
			if(iterator<segments.size()) nameForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) titleForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xNameForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) yNameForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) bin1ForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) left1ForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) right1ForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) minxForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) minyForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) colorForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) compareForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xlogForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) ylogForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) markerForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) normForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) drawOptForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
		}
		else if ( segments[0] == "TH2D" ){
			if(iterator<segments.size()) nameForH2D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) titleForH2D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xNameForH2D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) yNameForH2D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) bin1ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) left1ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) right1ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) bin2ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) left2ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) right2ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
		}
		else if ( segments[0] == "FILE" ){
			if(iterator<segments.size()) DirNames.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			std::string runname;
			if(iterator<segments.size()) runname = "_"+segments[iterator++]; else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if (runname=="_"){
				RunNames.push_back("");
			}
			else{
				RunNames.push_back(runname);
			}
			if(iterator<segments.size()) NCPU.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) NJob.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
		}
		else if ( segments[0] == "TGraph" ){
			if(iterator<segments.size()) nameForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) titleForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xNameForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) yNameForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			std::vector<double> avec;
			xForGraph.push_back(avec);
			std::vector<double> bvec;
			yForGraph.push_back(bvec);
			if(iterator<segments.size()) colorForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) compareForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) minxForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) maxxForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) minyForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xlogForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) ylogForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) markerForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) drawOptForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			int i = nameForGraph.size() - 1;
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"Input vecGraph["<<i<<"]: "<<nameForGraph[i]<<", "<<titleForGraph[i]<<", "<<xNameForGraph[i]<<", "<<yNameForGraph[i]<<", Color="<<colorForGraph[i]<<", xlogSyle="<<xlogForGraph[i]<<", ylogSyle="<<ylogForGraph[i]<<", nCompare="<<compareForGraph[i]<<", markerStyle="<<markerForGraph[i]<<", drawOpt=\""<<drawOptForGraph[i]<<"\""<<std::endl;
		}
		else if (segments[0] == "refTH1D"){
			if(iterator<segments.size()) refFileName.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) refHistName.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
		}
		else if (segments[0] == "oFILE"){
			if(iterator<segments.size()) oFileName.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
		}
		else if (segments[0] == "BEAM"){
			if(iterator<segments.size()) beamPx = string2double(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) beamPy = string2double(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) beamPz = string2double(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
		}
		else{
			std::cout<<"Cannot recogonize this line: "<<s_card<<std::endl;
			continue;
		}
	}

	//=> Get histograms in
	for ( int i = 0; i < nameForH2D.size(); i++ ){
		vecH2D.push_back(new TH2D(nameForH2D[i].c_str(),titleForH2D[i].c_str(),bin1ForH2D[i],left1ForH2D[i],right1ForH2D[i],bin2ForH2D[i],left2ForH2D[i],right2ForH2D[i]) );
	}
	for ( int i = 0; i < nameForH1D.size(); i++ ){
		vecH1D.push_back(new TH1D(nameForH1D[i].c_str(),titleForH1D[i].c_str(),bin1ForH1D[i],left1ForH1D[i],right1ForH1D[i]) );
	}
	for ( int i = 0; i < refFileName.size(); i++ ){
		TFile * fp_ref = new TFile(refFileName[i].c_str());
		if (fp_ref==NULL) {
			std::cout<<"ERROR: Can not find file: "<<refFileName[i]<<"!!!"<<std::endl;
			return -1;
		}
		TH1D* h1_ref = (TH1D*)fp_ref->Get(refHistName[i].c_str());
		if(h1_ref==NULL){
			std::cout<<"ERROR: Can not find histogram \""<<refHistName[i]<<"\"in file : "<<refFileName[i]<<"!!!"<<std::endl;
			return -1;
		}
		if ( (index_temp = get_TH1D(refHistName[i])) != -1 ){
			h1_ref->SetTitle(titleForH1D[index_temp].c_str());
			vecH1D[index_temp]=h1_ref;
		}
		else{
			std::cout<<"ERROR: Can not find histogram \""<<refHistName[i]<<"\"in vecH1D!!!"<<std::endl;
			return -1;
		}
	}

	//=======================================================================================================
	//************SET Statistics********************
	if (verbose >= Verbose_SectorInfo ) std::cout<<prefix_SectorInfo<<"In SET Statistics###"<<std::endl;

	//=>About Statistical
	int N0 = 0;
	int N1 = 0;
	int N2 = 0;
	int N3 = 0;
	int N4 = 0;
	int N5 = 0;
	int N6 = 0;
	int N7 = 0;

	//=======================================================================================================
	//************READ THE FILES********************
	if (verbose >= Verbose_SectorInfo ) std::cout<<prefix_SectorInfo<<"In READ THE FILES###"<<std::endl;
	std::string TreeName = "tree";
	TChain *m_TChain = new TChain(TreeName.c_str());

	int iStart = 0;
	int nBit = 2;
	for ( int iFile = 0; iFile < DirNames.size(); iFile++ ){
		int nCPU = NCPU[iFile];
		int njob = NJob[iFile];
		if ( verbose >= Verbose_FileInfo) std::cout<<prefix_FileInfo<<"FileList \""<<DirNames[iFile]<<"\" with runname = \""<<RunNames[iFile]<<"\" has "<<NJob[iFile]<<" jobs on "<<NCPU[iFile]<<" CPUs"<<std::endl;
		for (int i = iStart; i < iStart + nCPU; i ++){
			for (int j = iStart; j < iStart + njob; j ++){
				buff.str("");
				buff.clear();
				buff<<DirNames[iFile]<<"/"<<i<<"_job"<<j<<RunNames[iFile]<<".raw";
				m_TChain->Add(buff.str().c_str());
			}
		}
	}
	for ( int iFile = 0; iFile < oFileName.size(); iFile++ ){
		m_TChain->Add(oFileName[iFile].c_str());
	}

	//=======================================================================================================
	//************SET Branches********************
	int evt_num = 0;
	int run_num = 0;
	int McTruth_nTracks;
	std::vector<int> *McTruth_pid = 0;
	std::vector<int> *McTruth_tid = 0;
	std::vector<int> *McTruth_ptid = 0;
	std::vector<int> *McTruth_time = 0;
	std::vector<double> *McTruth_px = 0;
	std::vector<double> *McTruth_py = 0;
	std::vector<double> *McTruth_pz = 0;
	std::vector<double> *McTruth_e = 0;
	std::vector<double> *McTruth_x = 0;
	std::vector<double> *McTruth_y = 0;
	std::vector<double> *McTruth_z = 0;
	std::vector<int> *McTruth_charge = 0;
	std::vector<std::string> *McTruth_particleName = 0;
	std::vector<std::string> *McTruth_process = 0;
	std::vector<std::string> *McTruth_volume = 0;

	int Trigger_nHits = 0;
	std::vector<double> *Trigger_x = 0;
	std::vector<double> *Trigger_y = 0;
	std::vector<double> *Trigger_z = 0;
	std::vector<double> *Trigger_t = 0;
	std::vector<double> *Trigger_px = 0;
	std::vector<double> *Trigger_py = 0;
	std::vector<double> *Trigger_pz = 0;
	std::vector<double> *Trigger_e = 0;
	std::vector<double> *Trigger_edep = 0;
	std::vector<double> *Trigger_stepL = 0;
	std::vector<int> *Trigger_volID = 0;
	std::vector<std::string> *Trigger_volName = 0;
	std::vector<int> *Trigger_tid = 0;
	std::vector<int> *Trigger_pid = 0;
	std::vector<int> *Trigger_charge = 0;

	int CdcCell_nHits;
	std::vector<double> *CdcCell_x = 0;
	std::vector<double> *CdcCell_y = 0;
	std::vector<double> *CdcCell_z = 0;
	std::vector<double> *CdcCell_pIx = 0;
	std::vector<double> *CdcCell_pIy = 0;
	std::vector<double> *CdcCell_pIz = 0;
	std::vector<double> *CdcCell_pOx = 0;
	std::vector<double> *CdcCell_pOy = 0;
	std::vector<double> *CdcCell_pOz = 0;
	std::vector<double> *CdcCell_t = 0;
	std::vector<double> *CdcCell_px = 0;
	std::vector<double> *CdcCell_py = 0;
	std::vector<double> *CdcCell_pz = 0;
	std::vector<double> *CdcCell_e = 0;
	std::vector<double> *CdcCell_edep = 0;
	std::vector<double> *CdcCell_driftD_smeared = 0;
	std::vector<double> *CdcCell_driftD = 0;
	std::vector<double> *CdcCell_error = 0;
	std::vector<int> *CdcCell_status = 0;
	std::vector<int> *CdcCell_nTry = 0;
	std::vector<int> *CdcCell_layerID = 0;
	std::vector<int> *CdcCell_cellID = 0;
	std::vector<int> *CdcCell_tid = 0;
	std::vector<int> *CdcCell_pid = 0;

	TBranch *bMcTruth_pid = 0;
	TBranch *bMcTruth_tid = 0;
	TBranch *bMcTruth_ptid = 0;
	TBranch *bMcTruth_time = 0;             
	TBranch *bMcTruth_px = 0;              
	TBranch *bMcTruth_py = 0;              
	TBranch *bMcTruth_pz = 0;              
	TBranch *bMcTruth_e = 0;               
	TBranch *bMcTruth_x = 0;                
	TBranch *bMcTruth_y = 0;                
	TBranch *bMcTruth_z = 0;                
	TBranch *bMcTruth_charge = 0;
	TBranch *bMcTruth_particleName = 0;
	TBranch *bMcTruth_process = 0;
	TBranch *bMcTruth_volume = 0;

	TBranch *bTrigger_x = 0;
	TBranch *bTrigger_y = 0;
	TBranch *bTrigger_z = 0;
	TBranch *bTrigger_t = 0;
	TBranch *bTrigger_px = 0;
	TBranch *bTrigger_py = 0;
	TBranch *bTrigger_pz = 0;
	TBranch *bTrigger_e = 0;
	TBranch *bTrigger_edep = 0;
	TBranch *bTrigger_stepL = 0;
	TBranch *bTrigger_volID = 0;
	TBranch *bTrigger_volName = 0;
	TBranch *bTrigger_tid = 0;
	TBranch *bTrigger_pid = 0;
	TBranch *bTrigger_charge = 0;

	TBranch *bCdcCell_x = 0;
	TBranch *bCdcCell_y = 0;
	TBranch *bCdcCell_z = 0;
	TBranch *bCdcCell_pIx = 0;
	TBranch *bCdcCell_pIy = 0;
	TBranch *bCdcCell_pIz = 0;
	TBranch *bCdcCell_pOx = 0;
	TBranch *bCdcCell_pOy = 0;
	TBranch *bCdcCell_pOz = 0;
	TBranch *bCdcCell_t = 0;
	TBranch *bCdcCell_px = 0;
	TBranch *bCdcCell_py = 0;
	TBranch *bCdcCell_pz = 0;
	TBranch *bCdcCell_e = 0;
	TBranch *bCdcCell_edep = 0;
	TBranch *bCdcCell_driftD_smeared = 0;
	TBranch *bCdcCell_driftD = 0;
	TBranch *bCdcCell_error = 0;
	TBranch *bCdcCell_status = 0;
	TBranch *bCdcCell_nTry = 0;
	TBranch *bCdcCell_layerID = 0;
	TBranch *bCdcCell_cellID = 0;
	TBranch *bCdcCell_tid = 0;
	TBranch *bCdcCell_pid = 0;

	m_TChain->SetBranchAddress("evt_num", &evt_num);
	m_TChain->SetBranchAddress("run_num", &run_num);
	m_TChain->SetBranchAddress("McTruth_nTracks", &McTruth_nTracks);
	m_TChain->SetBranchAddress("McTruth_pid", &McTruth_pid, &bMcTruth_pid);
	m_TChain->SetBranchAddress("McTruth_tid", &McTruth_tid, &bMcTruth_tid);
	m_TChain->SetBranchAddress("McTruth_ptid", &McTruth_ptid, &bMcTruth_ptid);
	m_TChain->SetBranchAddress("McTruth_time", &McTruth_time, &bMcTruth_time);             
	m_TChain->SetBranchAddress("McTruth_px", &McTruth_px, &bMcTruth_px);              
	m_TChain->SetBranchAddress("McTruth_py", &McTruth_py, &bMcTruth_py);              
	m_TChain->SetBranchAddress("McTruth_pz", &McTruth_pz, &bMcTruth_pz);              
	m_TChain->SetBranchAddress("McTruth_e", &McTruth_e, &bMcTruth_e);               
	m_TChain->SetBranchAddress("McTruth_x", &McTruth_x, &bMcTruth_x);                
	m_TChain->SetBranchAddress("McTruth_y", &McTruth_y, &bMcTruth_y);                
	m_TChain->SetBranchAddress("McTruth_z", &McTruth_z, &bMcTruth_z);                
	m_TChain->SetBranchAddress("McTruth_charge", &McTruth_charge, &bMcTruth_charge);
	m_TChain->SetBranchAddress("McTruth_particleName", &McTruth_particleName, &bMcTruth_particleName);
	m_TChain->SetBranchAddress("McTruth_process", &McTruth_process, &bMcTruth_process);
	m_TChain->SetBranchAddress("McTruth_volume", &McTruth_volume, &bMcTruth_volume);

	m_TChain->SetBranchAddress("Trigger_nHits", &Trigger_nHits);
	m_TChain->SetBranchAddress("Trigger_x", &Trigger_x, &bTrigger_x);
	m_TChain->SetBranchAddress("Trigger_y", &Trigger_y, &bTrigger_y);
	m_TChain->SetBranchAddress("Trigger_z", &Trigger_z, &bTrigger_z);
	m_TChain->SetBranchAddress("Trigger_t", &Trigger_t, &bTrigger_t);
	m_TChain->SetBranchAddress("Trigger_px", &Trigger_px, &bTrigger_px);
	m_TChain->SetBranchAddress("Trigger_py", &Trigger_py, &bTrigger_py);
	m_TChain->SetBranchAddress("Trigger_pz", &Trigger_pz, &bTrigger_pz);
	m_TChain->SetBranchAddress("Trigger_e", &Trigger_e, &bTrigger_e);
	m_TChain->SetBranchAddress("Trigger_edep", &Trigger_edep, &bTrigger_edep);
	m_TChain->SetBranchAddress("Trigger_stepL", &Trigger_stepL, &bTrigger_stepL);
	m_TChain->SetBranchAddress("Trigger_volID", &Trigger_volID, &bTrigger_volID);
	m_TChain->SetBranchAddress("Trigger_volName", &Trigger_volName, &bTrigger_volName);
	m_TChain->SetBranchAddress("Trigger_tid", &Trigger_tid, &bTrigger_tid);
	m_TChain->SetBranchAddress("Trigger_pid", &Trigger_pid, &bTrigger_pid);
	m_TChain->SetBranchAddress("Trigger_charge", &Trigger_charge, &bTrigger_charge);

	m_TChain->SetBranchAddress("CdcCell_nHits", &CdcCell_nHits);
	m_TChain->SetBranchAddress("CdcCell_x", &CdcCell_x, &bCdcCell_x);
	m_TChain->SetBranchAddress("CdcCell_y", &CdcCell_y, &bCdcCell_y);
	m_TChain->SetBranchAddress("CdcCell_z", &CdcCell_z, &bCdcCell_z);
	m_TChain->SetBranchAddress("CdcCell_pIx", &CdcCell_pIx, &bCdcCell_pIx);
	m_TChain->SetBranchAddress("CdcCell_pIy", &CdcCell_pIy, &bCdcCell_pIy);
	m_TChain->SetBranchAddress("CdcCell_pIz", &CdcCell_pIz, &bCdcCell_pIz);
	m_TChain->SetBranchAddress("CdcCell_pOx", &CdcCell_pOx, &bCdcCell_pOx);
	m_TChain->SetBranchAddress("CdcCell_pOy", &CdcCell_pOy, &bCdcCell_pOy);
	m_TChain->SetBranchAddress("CdcCell_pOz", &CdcCell_pOz, &bCdcCell_pOz);
	m_TChain->SetBranchAddress("CdcCell_t", &CdcCell_t, &bCdcCell_t);
	m_TChain->SetBranchAddress("CdcCell_px", &CdcCell_px, &bCdcCell_px);
	m_TChain->SetBranchAddress("CdcCell_py", &CdcCell_py, &bCdcCell_py);
	m_TChain->SetBranchAddress("CdcCell_pz", &CdcCell_pz, &bCdcCell_pz);
	m_TChain->SetBranchAddress("CdcCell_e", &CdcCell_e, &bCdcCell_e);
	m_TChain->SetBranchAddress("CdcCell_edep", &CdcCell_edep, &bCdcCell_edep);
	m_TChain->SetBranchAddress("CdcCell_driftD_smeared", &CdcCell_driftD_smeared, &bCdcCell_driftD_smeared);
	m_TChain->SetBranchAddress("CdcCell_driftD", &CdcCell_driftD, &bCdcCell_driftD);
	m_TChain->SetBranchAddress("CdcCell_error", &CdcCell_error, &bCdcCell_error);
	m_TChain->SetBranchAddress("CdcCell_status", &CdcCell_status, &bCdcCell_status);
	m_TChain->SetBranchAddress("CdcCell_nTry", &CdcCell_nTry, &bCdcCell_nTry);
	m_TChain->SetBranchAddress("CdcCell_layerID", &CdcCell_layerID, &bCdcCell_layerID);
	m_TChain->SetBranchAddress("CdcCell_cellID", &CdcCell_cellID, &bCdcCell_cellID);
	m_TChain->SetBranchAddress("CdcCell_tid", &CdcCell_tid, &bCdcCell_tid);
	m_TChain->SetBranchAddress("CdcCell_pid", &CdcCell_pid, &bCdcCell_pid);

	TTree* d_tree = new TTree( "t", "t" );

	int d_evt_num;
	int d_run_num;
	int d_pid;
	int d_tid;
	char d_vid[124];
	char d_prid[124];
	double d_mot_x;
	double d_mot_y;
	double d_mot_z;
	double d_mot_px;
	double d_mot_py;
	double d_mot_pz;
	double d_x;
	double d_y;
	double d_z;
	double d_px;
	double d_py;
	double d_pz;
	int d_nhits;
	double d_hits_x[1000];
	double d_hits_y[1000];
	double d_hits_z[1000];
	double d_hits_t[1000];
	double d_hits_px[1000];
	double d_hits_py[1000];
	double d_hits_pz[1000];
	double d_tri_t;

	d_tree->Branch("evt_num", &d_evt_num, "evt_num/I");
	d_tree->Branch("run_num", &d_run_num, "run_num/I");
	d_tree->Branch("pid", &d_pid, "pid/I");
	d_tree->Branch("tid", &d_tid, "tid/I");
	d_tree->Branch("vid", d_vid, "vid[124]/C");
	d_tree->Branch("prid", d_prid, "prid[124]/C");
	d_tree->Branch("mot_x", &d_mot_x, "mot_x/D");
	d_tree->Branch("mot_y", &d_mot_y, "mot_y/D");
	d_tree->Branch("mot_z", &d_mot_z, "mot_z/D");
	d_tree->Branch("mot_px", &d_mot_px, "mot_px/D");
	d_tree->Branch("mot_py", &d_mot_py, "mot_py/D");
	d_tree->Branch("mot_pz", &d_mot_pz, "mot_pz/D");
	d_tree->Branch("ini_x_cm", &d_x, "ini_x_cm/D");
	d_tree->Branch("ini_y_cm", &d_y, "ini_y_cm/D");
	d_tree->Branch("ini_z_cm", &d_z, "ini_z_cm/D");
	d_tree->Branch("ini_px_GeV", &d_px, "ini_px_GeV/D");
	d_tree->Branch("ini_py_GeV", &d_py, "ini_py_GeV/D");
	d_tree->Branch("ini_pz_GeV", &d_pz, "ini_pz_GeV/D");
	d_tree->Branch("nwirehit", &d_nhits, "nwirehit/I");
	d_tree->Branch("x", d_hits_x, "x[nhits]/D");
	d_tree->Branch("y", d_hits_y, "y[nhits]/D");
	d_tree->Branch("z", d_hits_z, "z[nhits]/D");
	d_tree->Branch("t", d_hits_t, "t[nhits]/D");
	d_tree->Branch("px", d_hits_px, "px[nhits]/D");
	d_tree->Branch("py", d_hits_py, "py[nhits]/D");
	d_tree->Branch("pz", d_hits_pz, "pz[nhits]/D");
	d_tree->Branch("tri_t", &d_tri_t, "tri_t/D");

	//=======================================================================================================
	//************DO THE DIRTY WORK*******************
	if (verbose >= Verbose_SectorInfo) std::cout<<prefix_SectorInfo<<"In DO THE DIRTY WORK ###"<<std::endl;

	if (!strcmp(m_workMode,"gen")){
		Long64_t nEvent = m_TChain->GetEntries();
		for( Long64_t iEvent = 0; iEvent < nEvent; iEvent++ ){
			if (verbose >= Verbose_EventInfo || iEvent%printModule == 0) std::cout<<prefix_EventInfoStart<<"In Event "<<iEvent<<std::endl;
			N0++;
			Long64_t tentry = m_TChain->LoadTree(iEvent);
			if(bMcTruth_pid) bMcTruth_pid->GetEntry(tentry);
			if(bMcTruth_tid) bMcTruth_tid->GetEntry(tentry);
			if(bMcTruth_ptid) bMcTruth_ptid->GetEntry(tentry);
			if(bMcTruth_time) bMcTruth_time->GetEntry(tentry);             
			if(bMcTruth_px) bMcTruth_px->GetEntry(tentry);              
			if(bMcTruth_py) bMcTruth_py->GetEntry(tentry);              
			if(bMcTruth_pz) bMcTruth_pz->GetEntry(tentry);              
			if(bMcTruth_e) bMcTruth_e->GetEntry(tentry);               
			if(bMcTruth_x) bMcTruth_x->GetEntry(tentry);                
			if(bMcTruth_y) bMcTruth_y->GetEntry(tentry);                
			if(bMcTruth_z) bMcTruth_z->GetEntry(tentry);                
			if(bMcTruth_charge) bMcTruth_charge->GetEntry(tentry);
			if(bMcTruth_particleName) bMcTruth_particleName->GetEntry(tentry);
			if(bMcTruth_process) bMcTruth_process->GetEntry(tentry);
			if(bMcTruth_volume) bMcTruth_volume->GetEntry(tentry);

			if(bTrigger_x) bTrigger_x->GetEntry(tentry);
			if(bTrigger_y) bTrigger_y->GetEntry(tentry);
			if(bTrigger_z) bTrigger_z->GetEntry(tentry);
			if(bTrigger_t) bTrigger_t->GetEntry(tentry);
			if(bTrigger_px) bTrigger_px->GetEntry(tentry);
			if(bTrigger_py) bTrigger_py->GetEntry(tentry);
			if(bTrigger_pz) bTrigger_pz->GetEntry(tentry);
			if(bTrigger_e) bTrigger_e->GetEntry(tentry);
			if(bTrigger_edep) bTrigger_edep->GetEntry(tentry);
			if(bTrigger_stepL) bTrigger_stepL->GetEntry(tentry);
			if(bTrigger_volID) bTrigger_volID->GetEntry(tentry);
			if(bTrigger_volName) bTrigger_volName->GetEntry(tentry);
			if(bTrigger_tid) bTrigger_tid->GetEntry(tentry);
			if(bTrigger_pid) bTrigger_pid->GetEntry(tentry);
			if(bTrigger_charge) bTrigger_charge->GetEntry(tentry);

			if(bCdcCell_x) bCdcCell_x->GetEntry(tentry);
			if(bCdcCell_y) bCdcCell_y->GetEntry(tentry);
			if(bCdcCell_z) bCdcCell_z->GetEntry(tentry);
			if(bCdcCell_pIx) bCdcCell_pIx->GetEntry(tentry);
			if(bCdcCell_pIy) bCdcCell_pIy->GetEntry(tentry);
			if(bCdcCell_pIz) bCdcCell_pIz->GetEntry(tentry);
			if(bCdcCell_pOx) bCdcCell_pOx->GetEntry(tentry);
			if(bCdcCell_pOy) bCdcCell_pOy->GetEntry(tentry);
			if(bCdcCell_pOz) bCdcCell_pOz->GetEntry(tentry);
			if(bCdcCell_t) bCdcCell_t->GetEntry(tentry);
			if(bCdcCell_px) bCdcCell_px->GetEntry(tentry);
			if(bCdcCell_py) bCdcCell_py->GetEntry(tentry);
			if(bCdcCell_pz) bCdcCell_pz->GetEntry(tentry);
			if(bCdcCell_e) bCdcCell_e->GetEntry(tentry);
			if(bCdcCell_edep) bCdcCell_edep->GetEntry(tentry);
			if(bCdcCell_driftD_smeared) bCdcCell_driftD_smeared->GetEntry(tentry);
			if(bCdcCell_driftD) bCdcCell_driftD->GetEntry(tentry);
			if(bCdcCell_error) bCdcCell_error->GetEntry(tentry);
			if(bCdcCell_status) bCdcCell_status->GetEntry(tentry);
			if(bCdcCell_nTry) bCdcCell_nTry->GetEntry(tentry);
			if(bCdcCell_layerID) bCdcCell_layerID->GetEntry(tentry);
			if(bCdcCell_cellID) bCdcCell_cellID->GetEntry(tentry);
			if(bCdcCell_tid) bCdcCell_tid->GetEntry(tentry);
			if(bCdcCell_pid) bCdcCell_pid->GetEntry(tentry);

			m_TChain->GetEntry(iEvent);

			// find the electron
			int index = 0;
			N1++;
			double px = (*McTruth_px)[0];
			double py = (*McTruth_py)[0];
			double pz = (*McTruth_pz)[0];
			double pt = sqrt(px*px+py*py);
			double pa = sqrt(pt*pt+pz*pz);
			if (pa<90){ // pa < 90MeV/c
				continue;
			}
			N2++;

			std::string process = (*McTruth_process)[index];
			std::string volume = (*McTruth_volume)[index];
			int tid = (*McTruth_tid)[index];

			if (verbose >= Verbose_EventInfo || iEvent%printModule == 0)
				std::cout<<prefix_EventInfoStart
					     <<" pa = "<<pa
					     <<"MeV/c, process = "<<process
					     <<std::endl;

			// prepare for d_tree
			d_nhits = 0;
			double CdcCell_firstHitTime = -1;
			for ( int i_hit = 0; i_hit < CdcCell_nHits; i_hit++ ){
				int i_tid = (*CdcCell_tid)[i_hit];
				if (i_tid == tid){
					d_hits_x[d_nhits] = (*CdcCell_x)[i_hit];
					d_hits_y[d_nhits] = (*CdcCell_y)[i_hit];
					d_hits_z[d_nhits] = (*CdcCell_z)[i_hit];
					d_hits_t[d_nhits] = (*CdcCell_t)[i_hit];
					d_hits_px[d_nhits] = (*CdcCell_px)[i_hit];
					d_hits_py[d_nhits] = (*CdcCell_py)[i_hit];
					d_hits_pz[d_nhits] = (*CdcCell_pz)[i_hit];
					d_nhits++;
				}
			}
			CdcCell_firstHitTime = d_nhits>0?d_hits_t[0]:-1;
			double Trigger_firstHitTime = -1;
			for ( int i_hit = 0; i_hit < Trigger_nHits; i_hit++ ){
				int i_tid = (*Trigger_tid)[i_hit];
				if (i_tid == tid){
					Trigger_firstHitTime = (*Trigger_t)[i_hit];
					break;
				}
			}
			// Fill the tree
			d_evt_num = evt_num;
			d_run_num = run_num;
			d_pid = 11;
			d_tid = tid;
			strcpy(d_vid,volume.c_str());
			strcpy(d_prid,process.c_str());
			if ( d_vid[0] == 'C'
			  && d_vid[1] == 'd'
			  && d_vid[2] == 'c'){
			  	strcpy(d_vid,"CDCChamber");
			}
			d_tri_t = Trigger_firstHitTime;
			d_mot_x = (*McTruth_x)[0];
			d_mot_y = (*McTruth_y)[0];
			d_mot_z = (*McTruth_z)[0];
			d_mot_px = (*McTruth_px)[0];
			d_mot_py = (*McTruth_py)[0];
			d_mot_pz = (*McTruth_pz)[0];
			d_x = (*McTruth_x)[index];
			d_y = (*McTruth_y)[index];
			d_z = (*McTruth_z)[index];
			d_px = (*McTruth_px)[index]/1000.;
			d_py = (*McTruth_py)[index]/1000.;
			d_pz = (*McTruth_pz)[index]/1000.;

			if (CdcCell_nHits<=0) // not hit the Cdc
				continue;
			N3++;

			if ( CdcCell_firstHitTime == -1) // this electron not hit the Cdc
				continue;
			N4++;

			if (Trigger_nHits<=0) // not hit the trigger
				continue;
			N5++;

			if ( Trigger_firstHitTime == -1) // this electron not hit the trigger
				continue;
			N6++;

			if ( Trigger_firstHitTime <= CdcCell_firstHitTime ) // hit trigger first
				continue;
			N7++;

			if ( (index_temp = get_TH1D("pa")) != -1 ){
				vecH1D[index_temp]->Fill(pa);
			}

			d_tree->Fill();

			if (verbose >= Verbose_EventInfo || iEvent%printModule == 0) std::cout<<prefix_EventInfo<<"Finished!"<<std::endl;
		}/* end of loop in events*/
	}

	//=======================================================================================================

	//=======================================================================================================
	//************WRITE AND OUTPUT********************
	if (verbose >= Verbose_SectorInfo) std::cout<<prefix_SectorInfo<<"In WRITE AND OUTPUT ###"<<std::endl;
	std::string outputFileName = OutputDir + "output.root";
	TFile *file = new TFile(outputFileName.c_str(),"RECREATE");
	std::cout<<"N0 = "<<N0<<std::endl;
	std::cout<<"N1 = "<<N1<<std::endl;
	std::cout<<"N2 = "<<N2<<std::endl;
	std::cout<<"N3 = "<<N3<<std::endl;
	std::cout<<"N4 = "<<N4<<std::endl;
	std::cout<<"N5 = "<<N5<<std::endl;
	std::cout<<"N6 = "<<N6<<std::endl;
	std::cout<<"N7 = "<<N7<<std::endl;

	gStyle->SetPalette(1);
	gStyle->SetOptStat(0);
	gStyle->SetPadTickX(1);
	gStyle->SetPadTickY(1);
	//  gStyle->SetTitleW(0.99);
	//  gStyle->SetTitleH(0.08);
	//Output these histograms
	for ( int i = 0; i < vecH1D.size(); i++ ){
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"Output vecH1D["<<i<<"]: "<<nameForH1D[i]<<", "<<titleForH1D[i]<<", "<<xNameForH1D[i]<<", "<<yNameForH1D[i]<<", "<<bin1ForH1D[i]<<", "<<left1ForH1D[i]<<", "<<right1ForH1D[i]<<", Color="<<colorForH1D[i]<<", xlogSyle="<<xlogForH1D[i]<<", ylogSyle="<<ylogForH1D[i]<<", nCompare="<<compareForH1D[i]<<", markerStyle="<<markerForH1D[i]<<", normalize ="<<normForH1D[i]<<", drawOpt=\""<<drawOptForH1D[i]<<"\""<<std::endl;
		vecH1D[i]->SetLineColor(colorForH1D[i]);
		std::string name = vecH1D[i]->GetName();
		TCanvas* c = new TCanvas(name.c_str());
		int nCompare = compareForH1D[i];
		if ( nCompare ) if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<nCompare<<" histograms to be compared"<<std::endl;
		if (normForH1D[i]){
			if (normForH1D[i] == 1) vecH1D[i]->Scale(1./vecH1D[i]->Integral());
			else vecH1D[i]->Scale(1./normForH1D[i]);
		}
		double currentMaximum = vecH1D[i]->GetMaximum();
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"    currentMaximum y value is ("<<currentMaximum<<")"<<std::endl;
		for ( int j = 1; j <= nCompare; j++ ){
			if (normForH1D[i+j]){
				if (normForH1D[i+j] == 1) vecH1D[i+j]->Scale(1./vecH1D[i+j]->Integral());
				else vecH1D[i+j]->Scale(1./normForH1D[i+j]);
			}
			double maximum = vecH1D[i+j]->GetMaximum();
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"    Maximum y for "<<nameForH1D[i+j]<<" is ("<<maximum<<")"<<std::endl;
			if ( maximum > currentMaximum ){
				currentMaximum = maximum;
			}
		}
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"  maximum y value is ("<<currentMaximum<<")"<<std::endl;
		if ( xlogForH1D[i] ) gPad->SetLogx(1);
		else gPad->SetLogx(0);
		if ( ylogForH1D[i] ) gPad->SetLogy(1);
		else gPad->SetLogy(0);
		if ( xlogForH1D[i] ){
			vecH1D[i]->GetXaxis()->SetRangeUser(minxForH1D[i],right1ForH1D[i]);
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"  Logx! set xRange("<<minxForH1D[i]<<","<<right1ForH1D[i]<<")"<<std::endl;
		}
		else {
			vecH1D[i]->GetXaxis()->SetRangeUser(left1ForH1D[i],right1ForH1D[i]);
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"        set xRange("<<left1ForH1D[i]<<","<<right1ForH1D[i]<<")"<<std::endl;
		}
		if ( ylogForH1D[i] ) {
			vecH1D[i]->GetYaxis()->SetRangeUser(minyForH1D[i],2*currentMaximum);
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"  Logy! set yRange("<<minyForH1D[i]<<","<<2*currentMaximum<<")"<<std::endl;
		}
		else {
			vecH1D[i]->GetYaxis()->SetRangeUser(minyForH1D[i],1.05*currentMaximum);
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"        set yRange("<<minyForH1D[i]<<","<<1.05*currentMaximum<<")"<<std::endl;
		}
		vecH1D[i]->SetMarkerStyle(markerForH1D[i]);
		vecH1D[i]->SetMarkerColor(colorForH1D[i]);
		vecH1D[i]->SetLineColor(colorForH1D[i]);
		vecH1D[i]->GetXaxis()->SetTitle(xNameForH1D[i].c_str());
		vecH1D[i]->GetYaxis()->SetTitle(yNameForH1D[i].c_str());
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"    Integral of ("<<nameForH1D[i]<<"): "<<vecH1D[i]->Integral()<<std::endl;
		vecH1D[i]->Draw(drawOptForH1D[i].c_str());
		vecH1D[i]->Write();
		for ( int j = 0; j < nCompare; j++ ){
			i++;
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<" ->"<<j<<", vecH1D["<<i<<"]: "<<nameForH1D[i]<<", "<<titleForH1D[i]<<", "<<xNameForH1D[i]<<", "<<yNameForH1D[i]<<", "<<bin1ForH1D[i]<<", "<<left1ForH1D[i]<<", "<<right1ForH1D[i]<<", Color="<<colorForH1D[i]<<", xlogSyle="<<xlogForH1D[i]<<", ylogSyle="<<ylogForH1D[i]<<", nCompare="<<compareForH1D[i]<<", markerStyle="<<markerForH1D[i]<<", normalize ="<<normForH1D[i]<<", drawOpt=\""<<drawOptForH1D[i]<<"\""<<std::endl;
			vecH1D[i]->SetLineColor(colorForH1D[i]);
			vecH1D[i]->SetMarkerStyle(markerForH1D[i]);
			vecH1D[i]->SetMarkerColor(colorForH1D[i]);
			vecH1D[i]->SetLineColor(colorForH1D[i]);
			std::string drawOpt = drawOptForH1D[i]+"SAME";
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"    Integral of ("<<nameForH1D[i]<<"): "<<vecH1D[i]->Integral()<<std::endl;
			vecH1D[i]->Draw(drawOpt.c_str());
		}
		std::string fileName = OutputDir + name + ".pdf";
		c->Print(fileName.c_str());
	}
	gStyle->SetOptStat(0);
	for ( int i = 0; i < vecH2D.size(); i++ ){
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"Output vecH2D["<<i<<"]: "<<nameForH2D[i]<<", "<<titleForH2D[i]<<", "<<xNameForH2D[i]<<", "<<yNameForH2D[i]<<", "<<bin1ForH2D[i]<<", "<<left1ForH2D[i]<<", "<<right1ForH2D[i]<<", "<<bin2ForH2D[i]<<", "<<left2ForH2D[i]<<", "<<right2ForH2D[i]<<std::endl;
		std::string name = vecH2D[i]->GetName();
		TCanvas* c = new TCanvas(name.c_str());
		vecH2D[i]->GetXaxis()->SetTitle(xNameForH2D[i].c_str());
		vecH2D[i]->GetYaxis()->SetTitle(yNameForH2D[i].c_str());
		vecH2D[i]->Draw("COLZ");
		vecH2D[i]->Write();
		std::string fileName = OutputDir + name + ".pdf";
		c->Print(fileName.c_str());
	}
	for ( int i = 0; i < nameForGraph.size(); i++ ){
		int sizeOfThisGraph = xForGraph[i].size();
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"Output vecGraph["<<i<<"]: "<<nameForGraph[i]<<", "<<titleForGraph[i]<<", "<<xNameForGraph[i]<<", "<<yNameForGraph[i]<<", Color="<<colorForGraph[i]<<", xlogSyle="<<xlogForGraph[i]<<", ylogSyle="<<ylogForGraph[i]<<", nCompare="<<compareForGraph[i]<<", markerStyle="<<markerForGraph[i]<<", drawOpt=\""<<drawOptForGraph[i]<<"\", size = "<<sizeOfThisGraph<<std::endl;
		if ( sizeOfThisGraph <= 0 ) continue;
		if (verbose >= Verbose_HistInfo){
			for ( int j = 0; j < sizeOfThisGraph; j++ ){
				std::cout<<prefix_HistInfo<<"  ["<<j<<"]: ("<<xForGraph[i][j]<<","<<yForGraph[i][j]<<")"<<std::endl;
			}
		}
		std::string name = nameForGraph[i];
		TCanvas* c = new TCanvas(nameForGraph[i].c_str());
		TGraph *aTGraph = new TGraph(sizeOfThisGraph,&xForGraph[i][0],&yForGraph[i][0]);
		aTGraph->SetTitle(titleForGraph[i].c_str());
		int nCompare = compareForGraph[i];
		if ( nCompare ) if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<nCompare<<" graphs to be compared"<<std::endl;
		std::vector<double> yforgraph = yForGraph[i];
		std::vector<double> xforgraph = xForGraph[i];
		double currentMaximum = *std::max_element(yforgraph.begin(),yforgraph.end());
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"    currentMaximum y value is ("<<currentMaximum<<")"<<std::endl;
		for ( int j = 1; j <= nCompare; j++ ){
			double maximum = *std::max_element(yForGraph[i+j].begin(),yForGraph[i+j].end());
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"    Maximum y for "<<nameForGraph[i+j]<<" is ("<<maximum<<")"<<std::endl;
			if ( maximum > currentMaximum ){
				currentMaximum = maximum;
			}
		}
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"  maximum y value is ("<<currentMaximum<<")"<<std::endl;
		if ( xlogForGraph[i] ) gPad->SetLogx(1);
		else gPad->SetLogx(0);
		if ( ylogForGraph[i] ) gPad->SetLogy(1);
		else gPad->SetLogy(0);
		if ( xlogForGraph[i] ) aTGraph->GetXaxis()->SetRangeUser(minxForGraph[i],2*maxxForGraph[i]);
		else aTGraph->GetXaxis()->SetRangeUser(minxForGraph[i],1.05*maxxForGraph[i]);
		if ( ylogForGraph[i] ) aTGraph->GetYaxis()->SetRangeUser(minyForGraph[i],2*currentMaximum);
		else aTGraph->GetYaxis()->SetRangeUser(minyForGraph[i],1.05*currentMaximum);
		aTGraph->GetXaxis()->SetTitle(xNameForGraph[i].c_str());
		aTGraph->GetYaxis()->SetTitle(yNameForGraph[i].c_str());
		aTGraph->SetMarkerStyle(markerForGraph[i]);
		aTGraph->SetMarkerColor(colorForGraph[i]);
		aTGraph->SetLineColor(colorForGraph[i]);
		std::string drawOpt = "A"+drawOptForGraph[i];
		aTGraph->Draw(drawOpt.c_str());
		aTGraph->Write();
		for ( int j = 0; j < nCompare; j++ ){
			i++;
			int sizeOfThisGraph = xForGraph[i].size();
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<" ->"<<j<<", vecGraph["<<i<<"]: "<<nameForGraph[i]<<", "<<titleForGraph[i]<<", "<<xNameForGraph[i]<<", "<<yNameForGraph[i]<<", Color="<<colorForGraph[i]<<", xlogSyle="<<xlogForGraph[i]<<", ylogSyle="<<ylogForGraph[i]<<", nCompare="<<compareForGraph[i]<<", markerStyle="<<markerForGraph[i]<<", drawOpt=\""<<drawOptForGraph[i]<<"\", size = "<<sizeOfThisGraph<<std::endl;
			if ( sizeOfThisGraph <= 0 ) continue;
			if (verbose >= Verbose_HistInfo){
				for ( int k = 0; k < sizeOfThisGraph; k++ ){
					std::cout<<prefix_HistInfo<<"  ["<<k<<"]: ("<<xForGraph[i][k]<<","<<yForGraph[i][k]<<")"<<std::endl;
				}
			}
			TGraph *bTGraph = new TGraph(sizeOfThisGraph,&xForGraph[i][0],&yForGraph[i][0]);
			bTGraph->SetTitle(titleForGraph[i].c_str());
			bTGraph->GetXaxis()->SetTitle(xNameForGraph[i].c_str());
			bTGraph->GetYaxis()->SetTitle(yNameForGraph[i].c_str());
			bTGraph->SetLineColor(colorForGraph[i]);
			bTGraph->SetMarkerStyle(markerForGraph[i]);
			bTGraph->SetMarkerColor(colorForGraph[i]);
			bTGraph->SetLineColor(colorForGraph[i]);
			bTGraph->Draw(drawOptForGraph[i].c_str());
			bTGraph->Write();
		}
		std::string fileName = OutputDir + name + ".pdf";
		c->Print(fileName.c_str());
	}

	d_tree->Write();
	file->Close();
	std::string backupFileName = OutputDir + "backup.root";

	if (backup){
		TFile *file2 = new TFile(backupFileName.c_str(),"RECREATE");
		m_TChain->CloneTree(-1,"fast");
		file2->Write();
		file2->Close();
	}

	delete file;
	return 0;
}
Beispiel #9
0
int main(int argc, char* argv[]){
	std::stringstream buff;
	//=======================================
	//*************About Models**********
	double pFermi_1 = 0.24;
	double pFermi_2 = 0.8;
	double vFermi_1 = 2e-2;
	double vFermi_2 = 4.5e-4;

	//=======================================
	//*************read parameter**********
	//if (argc==1) {
	//	print_usage(argv[0]);
	//	return -1;
	//}
	init_args();
	int result;
	while((result=getopt(argc,argv,"hv:m:"))!=-1){
		switch(result){
			/* INPUTS */
			case 'm':
				strcpy(m_workMode,optarg);
				printf("work mode: %s\n",m_workMode);
				break;
			case 'v':
				verbose = atoi(optarg);
				printf("verbose level: %d\n",verbose);
				break;
			case '?':
				printf("Wrong option! optopt=%c, optarg=%s\n", optopt, optarg);
				break;
			case 'h':
			default:
				print_usage(argv[0]);
				return 1;
		}
	}

	//for (;optind<argc;optind++){
	//	m_input_files.push_back(argv[optind]);
	//}

	//=======================================
	//************Verbose Control***********
	int Verbose_SectorInfo = 5; //大概的流程情况
	std::string prefix_SectorInfo = "### ";
	int Verbose_HistInfo = 10; //有哪些hist,什么时候输出了,参数如何
	std::string prefix_HistInfo= "  [Histograms] ";
	int Verbose_Statistics = 10; //跟统计相关的(效率,分辨,粒子鉴别的情况)
	std::string prefix_Statistics="  [Statistics] ";
	int Verbose_FileInfo = 10; //有哪些FileList,都有多少file
	std::string prefix_FileInfo="  [FileInfo] ";
	int Verbose_EffInfo = 15; //Efficiency info
	std::string prefix_EffInfo="  [EffInfo] ";
	int Verbose_EventInfo = 20; //每个event的基本流程
	std::string prefix_EventInfoStart="    =>[EventInfo] ";
	std::string prefix_EventInfo="      [EventInfo] ";
	int Verbose_ParticleInfo=25; //每个particle的基本信息
	std::string prefix_ParticleInfoStart="    ->[ParticleInfo]";
	std::string prefix_ParticleInfo="      [ParticleInfo]";

	//=======================================================================================================
	//************PRESET********************
	if (verbose >= Verbose_SectorInfo ) std::cout<<prefix_SectorInfo<<"In PRESET###"<<std::endl;

	//=> About Histogram
	std::string histList = "histList";
	int index_temp;

	//=>About Constant
	double PI = 3.141592653589793238;
	double FSC = 1/137.03599911; //fine structure constant
	double M_MUON = 105.6584; //mass of muon in MeV
	double M_ELE = 0.510999; //mass of electron in MeV
	double M_U = 931.494061; //atomic mass unit in MeV

	//=>About output
	std::string OutputDir = "result/";

	//=======================================================================================================
	//************SET HISTOGRAMS********************
	if (verbose >= Verbose_SectorInfo ) std::cout<<prefix_SectorInfo<<"In SET HISTOGRAMS###"<<std::endl;
 
	//=>Read histList
	std::ifstream fin_card(histList.c_str());
	if(!fin_card){
		std::cout<<"Cannot find "<<histList<<std::endl;
	}
	std::string s_card;
	std::string histtype, histname, histtitle, dirname, runname, histdrawOpt, histxName, histyName;
	double histleft1, histright1, histleft2, histright2;
	int histbin1, histbin2, histcolor, histcompare, histlogx, histlogy, nCPU, njob, histmarker;
	std::vector<std::string> DirNames; 
	std::vector<std::string> RunNames; 
	std::vector<int> NCPU;
	std::vector<int> NJob;
	// read histList
	while(getline(fin_card,s_card)){
		if ( ISEMPTY(s_card) ) continue;
		std::vector<std::string> segments;
		seperate_string(s_card,segments,'|');
		int iterator = 1;
		if ( segments[0] == "TH1D" ){
			if(iterator<segments.size()) nameForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) titleForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xNameForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) yNameForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) bin1ForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) left1ForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) right1ForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) minxForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) minyForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) colorForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) compareForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xlogForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) ylogForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) markerForH1D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) drawOptForH1D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
		}
		else if ( segments[0] == "TH2D" ){
			if(iterator<segments.size()) nameForH2D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) titleForH2D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xNameForH2D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) yNameForH2D.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) bin1ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) left1ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) right1ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) bin2ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) left2ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) right2ForH2D.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
		}
		else if ( segments[0] == "FILE" ){
			if(iterator<segments.size()) DirNames.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			std::string runname;
			if(iterator<segments.size()) runname = "_"+segments[iterator++]; else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if (runname=="_"){
				RunNames.push_back("");
			}
			else{
				RunNames.push_back(runname);
			}
			if(iterator<segments.size()) NCPU.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) NJob.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
		}
		else if ( segments[0] == "TGraph" ){
			if(iterator<segments.size()) nameForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) titleForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xNameForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) yNameForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			std::vector<double> avec;
			xForGraph.push_back(avec);
			std::vector<double> bvec;
			yForGraph.push_back(bvec);
			if(iterator<segments.size()) colorForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) compareForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) minxForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) maxxForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) minyForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) xlogForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) ylogForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) markerForGraph.push_back(string2double(segments[iterator++])); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			if(iterator<segments.size()) drawOptForGraph.push_back(segments[iterator++]); else {std::cout<<"Not enough segments in"<<s_card<<"!!!"<<std::endl; return -1;}
			int i = nameForGraph.size() - 1;
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"Input vecGraph["<<i<<"]: "<<nameForGraph[i]<<", "<<titleForGraph[i]<<", "<<xNameForGraph[i]<<", "<<yNameForGraph[i]<<", Color="<<colorForGraph[i]<<", xlogSyle="<<xlogForGraph[i]<<", ylogSyle="<<ylogForGraph[i]<<", nCompare="<<compareForGraph[i]<<", markerStyle="<<markerForGraph[i]<<", drawOpt=\""<<drawOptForGraph[i]<<"\""<<std::endl;
		}
		else{
			std::cout<<"Cannot recogonize this line: "<<s_card<<std::endl;
			continue;
		}
	}

	//=> Get histograms in
	for ( int i = 0; i < nameForH2D.size(); i++ ){
		vecH2D.push_back(new TH2D(nameForH2D[i],titleForH2D[i],bin1ForH2D[i],left1ForH2D[i],right1ForH2D[i],bin2ForH2D[i],left2ForH2D[i],right2ForH2D[i]) );
	}
	for ( int i = 0; i < nameForH1D.size(); i++ ){
		vecH1D.push_back(new TH1D(nameForH1D[i],titleForH1D[i],bin1ForH1D[i],left1ForH1D[i],right1ForH1D[i]) );
	}

	//=======================================================================================================
	//************SET Statistics********************
	if (verbose >= Verbose_SectorInfo ) std::cout<<prefix_SectorInfo<<"In SET Statistics###"<<std::endl;

	//=>About Statistical
	int N0 = 0;
	int N1 = 0;
	int N2 = 0;
	int N3 = 0;

	//=======================================================================================================
	//************DO THE DIRTY WORK*******************
	if (verbose >= Verbose_SectorInfo) std::cout<<prefix_SectorInfo<<"In DO THE DIRTY WORK ###"<<std::endl;

	//loop in events
	int nbin = 120;
	if ( (index_temp = get_TH1D("h")) != -1 ){
		nbin = bin1ForH1D[index_temp];
	}
	for( int ibin = 1; ibin <= nbin; ibin++ ){
		if (verbose >= Verbose_EventInfo ) std::cout<<prefix_EventInfoStart<<"In Event "<<ibin<<std::endl;
		N0++;
		// Generate a nucleon
		double pFermi_left = 0;
		double pFermi_right = pFermi_2;
		if ( (index_temp = get_TH1D("h")) != -1 ){
			pFermi_left = left1ForH1D[index_temp];
			pFermi_right = right1ForH1D[index_temp];
		}
		double pFermi = pFermi_left + (pFermi_right-pFermi_left)*(ibin-1)/((double)nbin);
		double weight = 0;
		if ( pFermi < pFermi_1 ) weight = 1;
		else {
			weight = vFermi_1 * pow(vFermi_2/vFermi_1,(pFermi-pFermi_1)/(pFermi_2-pFermi_1));
		}
		if ( (index_temp = get_TH1D("h")) != -1 ){
			vecH1D[index_temp]->SetBinContent(ibin,weight);
		}
		if ( (index_temp = get_TH1D("h_log")) != -1 ){
			vecH1D[index_temp]->SetBinContent(ibin,weight);
		}

		if (verbose >= Verbose_EventInfo ) std::cout<<prefix_EventInfo<<"Finished!"<<std::endl;
	}/* end of loop in events*/

	//=======================================================================================================

	//=======================================================================================================
	//************WRITE AND OUTPUT********************
	if (verbose >= Verbose_SectorInfo) std::cout<<prefix_SectorInfo<<"In WRITE AND OUTPUT ###"<<std::endl;
	std::string outputFileName = OutputDir + "output.root";
	TFile *file = new TFile(outputFileName.c_str(),"RECREATE");
	std::cout<<"N0 = "<<N0<<std::endl;
	std::cout<<"N1 = "<<N1<<std::endl;
	std::cout<<"N2 = "<<N2<<std::endl;
	std::cout<<"N3 = "<<N3<<std::endl;

	gStyle->SetPalette(1);
	gStyle->SetOptStat(0);
	gStyle->SetPadTickX(1);
	gStyle->SetPadTickY(1);
	//  gStyle->SetTitleW(0.99);
	//  gStyle->SetTitleH(0.08);
	//Output these histograms
	for ( int i = 0; i < vecH1D.size(); i++ ){
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"Output vecH1D["<<i<<"]: "<<nameForH1D[i]<<", "<<titleForH1D[i]<<", "<<xNameForH1D[i]<<", "<<yNameForH1D[i]<<", "<<bin1ForH1D[i]<<", "<<left1ForH1D[i]<<", "<<right1ForH1D[i]<<", Color="<<colorForH1D[i]<<", xlogSyle="<<xlogForH1D[i]<<", ylogSyle="<<ylogForH1D[i]<<", nCompare="<<compareForH1D[i]<<", markerStyle="<<markerForH1D[i]<<", drawOpt=\""<<drawOptForH1D[i]<<"\""<<std::endl;
		vecH1D[i]->SetLineColor(colorForH1D[i]);
		TString name = vecH1D[i]->GetName();
		TCanvas* c = new TCanvas(name);
		int nCompare = compareForH1D[i];
		if ( nCompare ) if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<nCompare<<" histograms to be compared"<<std::endl;
		double currentMaximum = vecH1D[i]->GetMaximum();
		for ( int j = 1; j <= nCompare; j++ ){
			double maximum = vecH1D[i+j]->GetMaximum();
			if ( maximum > currentMaximum ){
				currentMaximum = maximum;
			}
		}
		if ( nCompare ) if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"  maximum y value is ("<<currentMaximum<<")"<<std::endl;
		if ( xlogForH1D[i] ) gPad->SetLogx(1);
		else gPad->SetLogx(0);
		if ( ylogForH1D[i] ) gPad->SetLogy(1);
		else gPad->SetLogy(0);
		if ( xlogForH1D[i] ) vecH1D[i]->GetXaxis()->SetRangeUser(minxForH1D[i],right1ForH1D[i]);
		else vecH1D[i]->GetXaxis()->SetRangeUser(left1ForH1D[i],right1ForH1D[i]);
		if ( ylogForH1D[i] ) vecH1D[i]->GetYaxis()->SetRangeUser(minyForH1D[i],2*currentMaximum);
		else vecH1D[i]->GetYaxis()->SetRangeUser(left1ForH1D[i],1.05*currentMaximum);
		vecH1D[i]->SetMarkerStyle(markerForH1D[i]);
		vecH1D[i]->SetMarkerColor(colorForH1D[i]);
		vecH1D[i]->SetLineColor(colorForH1D[i]);
		vecH1D[i]->GetXaxis()->SetTitle(xNameForH1D[i]);
		vecH1D[i]->GetYaxis()->SetTitle(yNameForH1D[i]);
		vecH1D[i]->Draw(drawOptForH1D[i]);
		vecH1D[i]->Write();
		for ( int j = 0; j < nCompare; j++ ){
			i++;
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<" ->"<<j<<", vecH1D["<<i<<"]: "<<nameForH1D[i]<<", "<<titleForH1D[i]<<", "<<xNameForH1D[i]<<", "<<yNameForH1D[i]<<", "<<bin1ForH1D[i]<<", "<<left1ForH1D[i]<<", "<<right1ForH1D[i]<<", Color="<<colorForH1D[i]<<", xlogSyle="<<xlogForH1D[i]<<", ylogSyle="<<ylogForH1D[i]<<", nCompare="<<compareForH1D[i]<<", markerStyle="<<markerForH1D[i]<<", drawOpt=\""<<drawOptForH1D[i]<<"\""<<std::endl;
			vecH1D[i]->SetLineColor(colorForH1D[i]);
			vecH1D[i]->SetMarkerStyle(markerForH1D[i]);
			vecH1D[i]->SetMarkerColor(colorForH1D[i]);
			vecH1D[i]->SetLineColor(colorForH1D[i]);
			TString drawOpt = drawOptForH1D[i]+"SAME";
			vecH1D[i]->Draw(drawOpt);
		}
		TString fileName = OutputDir + name + ".pdf";
		c->Print(fileName);
	}
	gStyle->SetOptStat(0);
	for ( int i = 0; i < vecH2D.size(); i++ ){
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"Output vecH2D["<<i<<"]: "<<nameForH2D[i]<<", "<<titleForH2D[i]<<", "<<xNameForH2D[i]<<", "<<yNameForH2D[i]<<", "<<bin1ForH2D[i]<<", "<<left1ForH2D[i]<<", "<<right1ForH2D[i]<<", "<<bin2ForH2D[i]<<", "<<left2ForH2D[i]<<", "<<right2ForH2D[i]<<std::endl;
		TString name = vecH2D[i]->GetName();
		TCanvas* c = new TCanvas(name);
		vecH2D[i]->GetXaxis()->SetTitle(xNameForH2D[i]);
		vecH2D[i]->GetYaxis()->SetTitle(yNameForH2D[i]);
		vecH2D[i]->Draw("COLZ");
		vecH2D[i]->Write();
		TString fileName = OutputDir + name + ".pdf";
		c->Print(fileName);
	}
	for ( int i = 0; i < nameForGraph.size(); i++ ){
		int sizeOfThisGraph = xForGraph[i].size();
		if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"Output vecGraph["<<i<<"]: "<<nameForGraph[i]<<", "<<titleForGraph[i]<<", "<<xNameForGraph[i]<<", "<<yNameForGraph[i]<<", Color="<<colorForGraph[i]<<", xlogSyle="<<xlogForGraph[i]<<", ylogSyle="<<ylogForGraph[i]<<", nCompare="<<compareForGraph[i]<<", markerStyle="<<markerForGraph[i]<<", drawOpt=\""<<drawOptForGraph[i]<<"\", size = "<<sizeOfThisGraph<<std::endl;
		if ( sizeOfThisGraph <= 0 ) continue;
		if (verbose >= Verbose_HistInfo){
			for ( int j = 0; j < sizeOfThisGraph; j++ ){
				std::cout<<prefix_HistInfo<<"  ["<<j<<"]: ("<<xForGraph[i][j]<<","<<yForGraph[i][j]<<")"<<std::endl;
			}
		}
		TString name = nameForGraph[i];
		TCanvas* c = new TCanvas(nameForGraph[i]);
		TGraph *aTGraph = new TGraph(sizeOfThisGraph,&xForGraph[i][0],&yForGraph[i][0]);
		aTGraph->SetTitle(titleForGraph[i]);
		int nCompare = compareForGraph[i];
		if ( nCompare ) if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<nCompare<<" graphs to be compared"<<std::endl;
		std::vector<double> yforgraph = yForGraph[i];
		std::vector<double> xforgraph = xForGraph[i];
		double currentMaximum = *std::max_element(yforgraph.begin(),yforgraph.end());
		for ( int j = 1; j <= nCompare; j++ ){
			double maximum = *std::max_element(yForGraph[i+j].begin(),yForGraph[i+j].end());
			if ( maximum > currentMaximum ){
				currentMaximum = maximum;
			}
		}
		if ( nCompare ) if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<"  maximum y value is ("<<currentMaximum<<")"<<std::endl;
		if ( xlogForGraph[i] ) gPad->SetLogx(1);
		else gPad->SetLogx(0);
		if ( ylogForGraph[i] ) gPad->SetLogy(1);
		else gPad->SetLogy(0);
		if ( xlogForGraph[i] ) aTGraph->GetXaxis()->SetRangeUser(minxForGraph[i],2*maxxForGraph[i]);
		else aTGraph->GetXaxis()->SetRangeUser(minxForGraph[i],1.05*maxxForGraph[i]);
		if ( ylogForGraph[i] ) aTGraph->GetYaxis()->SetRangeUser(minyForGraph[i],2*currentMaximum);
		else aTGraph->GetYaxis()->SetRangeUser(minyForGraph[i],1.05*currentMaximum);
		aTGraph->GetXaxis()->SetTitle(xNameForGraph[i]);
		aTGraph->GetYaxis()->SetTitle(yNameForGraph[i]);
		aTGraph->SetMarkerStyle(markerForGraph[i]);
		aTGraph->SetMarkerColor(colorForGraph[i]);
		aTGraph->SetLineColor(colorForGraph[i]);
		TString drawOpt = "A"+drawOptForGraph[i];
		aTGraph->Draw(drawOpt);
		aTGraph->Write();
		for ( int j = 0; j < nCompare; j++ ){
			i++;
			int sizeOfThisGraph = xForGraph[i].size();
			if (verbose >= Verbose_HistInfo) std::cout<<prefix_HistInfo<<" ->"<<j<<", vecGraph["<<i<<"]: "<<nameForGraph[i]<<", "<<titleForGraph[i]<<", "<<xNameForGraph[i]<<", "<<yNameForGraph[i]<<", Color="<<colorForGraph[i]<<", xlogSyle="<<xlogForGraph[i]<<", ylogSyle="<<ylogForGraph[i]<<", nCompare="<<compareForGraph[i]<<", markerStyle="<<markerForGraph[i]<<", drawOpt=\""<<drawOptForGraph[i]<<"\", size = "<<sizeOfThisGraph<<std::endl;
			if ( sizeOfThisGraph <= 0 ) continue;
			if (verbose >= Verbose_HistInfo){
				for ( int k = 0; k < sizeOfThisGraph; k++ ){
					std::cout<<prefix_HistInfo<<"  ["<<k<<"]: ("<<xForGraph[i][k]<<","<<yForGraph[i][k]<<")"<<std::endl;
				}
			}
			TGraph *bTGraph = new TGraph(sizeOfThisGraph,&xForGraph[i][0],&yForGraph[i][0]);
			bTGraph->SetTitle(titleForGraph[i]);
			bTGraph->GetXaxis()->SetTitle(xNameForGraph[i]);
			bTGraph->GetYaxis()->SetTitle(yNameForGraph[i]);
			bTGraph->SetLineColor(colorForGraph[i]);
			bTGraph->SetMarkerStyle(markerForGraph[i]);
			bTGraph->SetMarkerColor(colorForGraph[i]);
			bTGraph->SetLineColor(colorForGraph[i]);
			bTGraph->Draw(drawOptForGraph[i]);
			bTGraph->Write();
		}
		TString fileName = OutputDir + name + ".pdf";
		c->Print(fileName);
	}

	//TTree *m_TTree = m_TChain->CloneTree();
	//m_TTree->Write();
	//file->Write();
	file->Close();

	delete file;
	return 0;
}
Beispiel #10
0
std::string double2string(const double val, const std::size_t fieldLength,
                          const std::size_t precission, const bool scientific,
                          const bool decimalPointAssumed,
                          const bool leftAlign)
{
    char str[fieldLength];
    double val1 = val;
    if (decimalPointAssumed)
    {
        double val3;
        val1 = modf(val, &val3);
    }
    sprintf(str, ("%" + int2string(fieldLength) + "." +
                  int2string(precission + (scientific ? 1 : 0)) +
                  (scientific ? "e" : "f")).c_str(),
            val1);
    std::string res(str);

    // Remove decimal point
    std::size_t pos = res.find(".");
    int n = 0;
    if (decimalPointAssumed && pos != std::string::npos && scientific)
    {
        n = -pos;
        res.replace(pos, 1, "");
    }
    else if (decimalPointAssumed && !scientific)
    {
        pos = res.find("0.");
        if (pos != std::string::npos)
            res.replace(pos, 2, "");
    }

    // Remove point from scientific format
    if (scientific)
    {
        std::size_t e_pos = res.find("e");
        std::string base = res.substr(0, e_pos);
        std::string a = res.substr(e_pos + 1, res.length() - e_pos - 1);
        std::size_t pos1 = base.find(".");
        if (pos1 != std::string::npos)
        {
            n = base.length() - pos1 - 1;
            base.replace(pos1, 1, "");
        }
        Node::ErrorCode error;
        int new_a = string2int(a, error) - n;
        if (string2double(base, error) == 0)
            new_a = 0;
        res = base + (new_a > 0 ? "+" : "-") + int2string(abs(new_a));
    }
    res = trim(res);

    // Correct "0." or "-0."
    if (res.substr(0, 2) == "0.")
        res = res.substr(1, res.length() - 1);
    else if (res.substr(0, 3) == "-0.")
        res = "-" + res.substr(2, res.length() - 2);

    return string2string(res, fieldLength, leftAlign, false);
}
    boost::shared_ptr<GraspSpecification > GraspSpecification::readFromUrdf(const std::string &filename) {
        TiXmlDocument doc( filename );
        doc.LoadFile();
        std::unique_ptr<GraspSpecification > u_gs(new GraspSpecification);

	    if (doc.Error())
	    {
		    std::cout << "ERROR: GraspSpecification::readFromXml: " << doc.ErrorDesc() << std::endl;
		    doc.ClearError();
		    return boost::shared_ptr<GraspSpecification >(NULL);
	    }

    	TiXmlElement *elementR = doc.FirstChildElement("robot");
	    if (!elementR)
	    {
		    std::cout << "ERROR: GraspSpecification::readFromXml: " << "Could not find the 'robot' element in the xml file" << std::endl;
		    return boost::shared_ptr<GraspSpecification >(NULL);
	    }

        int grasp_specs_count = 0;
	    for (TiXmlElement* elementGS = elementR->FirstChildElement("grasp_specification"); elementGS; elementGS = elementGS->NextSiblingElement("grasp_specification")) {
            grasp_specs_count++;
        }
        if (grasp_specs_count != 1) {
		    std::cout << "ERROR: GraspSpecification::readFromXml: wrong number of grasp_specification elements: " << grasp_specs_count << std::endl;
    		return boost::shared_ptr<GraspSpecification >(NULL);
        }

        TiXmlElement* elementGS = elementR->FirstChildElement("grasp_specification");

	    for (TiXmlElement* elementI = elementGS->FirstChildElement("init_state"); elementI; elementI = elementI->NextSiblingElement("init_state")) {
        	const char *str = elementI->Attribute("joint");
            if (!str) {
		        std::cout << "ERROR: GraspSpecification::readFromXml: init_state joint" << std::endl;
        		return boost::shared_ptr<GraspSpecification >(NULL);
            }
            std::string joint_name( str );

        	str = elementI->Attribute("position");
            if (!str) {
		        std::cout << "ERROR: GraspSpecification::readFromXml: init_state position" << std::endl;
        		return boost::shared_ptr<GraspSpecification >(NULL);
            }
            u_gs->q_init_map_[joint_name] = string2double( str );
	    }

	    for (TiXmlElement* elementG = elementGS->FirstChildElement("goal_state"); elementG; elementG = elementG->NextSiblingElement("goal_state")) {
        	const char *str = elementG->Attribute("joint");
            if (!str) {
		        std::cout << "ERROR: GraspSpecification::readFromXml: init_state joint" << std::endl;
        		return boost::shared_ptr<GraspSpecification >(NULL);
            }
            std::string joint_name( str );

        	str = elementG->Attribute("position");
            if (!str) {
		        std::cout << "ERROR: GraspSpecification::readFromXml: init_state position" << std::endl;
        		return boost::shared_ptr<GraspSpecification >(NULL);
            }
            u_gs->q_goal_map_[joint_name] = string2double( str );
	    }

        return boost::shared_ptr<GraspSpecification >(new GraspSpecification(*u_gs.get()));
    }