예제 #1
0
파일: play.cpp 프로젝트: Bnap88/ChessAI
//play the game
void Play::play(char test, int maxTurns, string tCase) {
	int curTurn = 0;
	bool ykmovesavailable = true;
	bool yTurn; //false = x, true = y
	bool compMove;
	char compPlayer;
	CurrentBoard board;
	LegalMoves checkmoves;
	ofstream myfile("gameResult.txt");

	if (test == 'y') {
		//set the initial board
		setInitialBoard(myfile, board, test, tCase);

		//player x goes first
		yTurn = false;

		//take turns between players until checkmate, stalemate, or out of moves
		while (ykmovesavailable && curTurn < maxTurns) {
			cout << "Turn " << curTurn + 1 << '\n';
			myfile << "Turn " << curTurn + 1 << '\n';

			//get the next move
			autoMove(myfile, board, yTurn);
			
			if (curTurn < maxTurns)
			{
				//switch to other player
				if (yTurn) {
					yTurn = false;
					curTurn++;
				}
				else {
					yTurn = true;
				}
			}

			//check if y has moves available
			ykmovesavailable = checkYKingMoves(board);
		} //end while

		//call the function to check and print out the result
		checkResult(curTurn, maxTurns, board, myfile);
	}
	else {
		//set the initial board
		setInitialBoard(myfile, board, test, tCase);

		//if champion mode, find out if this computer is player x or y
		if (test == 'n') {
			cout << "Am I player X or Y: ";
			cin >> compPlayer;
			cout << '\n';
		}

		//initial move setup
		if (test == 'n' && compPlayer == 'y') {
			compMove = false;
			yTurn = true;
		}
		else {
			compMove = true;
			yTurn = false;
		}

		//take turns between players until checkmate, stalemate, or out of moves
		while (ykmovesavailable && curTurn <= maxTurns) {
			cout << "Turn " << curTurn << '\n';
			myfile << "Turn " << curTurn << '\n';

			if (compMove) { //make an auto move
				autoMove(myfile, board, yTurn);
				if (test == 'y') { //test mode
					if (yTurn) {
						yTurn = false;
						curTurn++;
					}
					else {
						yTurn = true;
					}
				}
				else {
					compMove = false;
				}
			}
			else if (!compMove && compPlayer == 'y') { //champion mode, computer is y, ask for x
				championOpponentX(myfile, board);
				compMove = true;
			}
			else { //champion mode, computer is x, ask for y
				championOpponentY(myfile, board);
				curTurn++;
				compMove = true;
			}

			//check if y has moves available
			ykmovesavailable = checkYKingMoves(board);
		} //end while

		//call the function to check and print out the result
		checkResult(curTurn, maxTurns, board, myfile);
	}
예제 #2
0
파일: dataCon.cpp 프로젝트: raz90/SDI2
 void DataCon<anyType>::load(std::string filename)
{
	  
	std::vector <std::string> vectline;
	std::string line;
	std::ifstream myfile (filename.c_str());
	
			if(myfile.is_open())
			{ 
			
				while (!myfile.eof())
				{
				myfile>>line;
				
				
				vectline.push_back(line);
				
				
				}
				myfile.close();
			}

	for (int start=0;start<vectline.size()-1;start++)
	{
	std::string sentence;
	sentence=vectline[start];

	std::string gpmcheck=sentence;	
	std::size_t found=gpmcheck.find_first_of(',');
	std::string check;
	if (found!=std::string::npos)
	for (unsigned int i=0; i<found;++i)
					{
						
						check=check+gpmcheck[i];
						
					}
		
		
					
		if (check=="$1")
		{
			saveSSB(sentence);		
			
		}
		else if (check=="$2")
		{
					
			saveSSK(sentence);
		}	
		else if (check=="$3")
		{
			saveTanker(sentence);
		}
		else if (check=="$4")
		{
			saveLanding(sentence);
		}
		else if (check=="$5")
		{
			saveAirCarrier(sentence);
		}
		else if (check=="$6")
		{
			saveDestroyer(sentence);
		}
	}

		std::cout<<"loaded"<<std::endl;
	
}
예제 #3
0
int main(int argc, char ** argv){
	Util ut;
	if(!ut.parse(argc, argv)){
		return 0;
	}
	if (ut.arg_print_usage){
		ut.printUsage();
		return 0;
	}

	string _input;
	if (ut.arg_input_filepath == "N/A"){
		cout << "Please enter your page references, end with [ENTER]." << endl;
		getline(cin, _input);
	} else {
		cout << "Reading page references from file {"<< ut.arg_input_filepath << "}."<< endl;
		ifstream myfile (ut.arg_input_filepath.c_str());
		if (myfile.is_open()){
			while(myfile.good()){
				getline(myfile, _input);
				break;
			}
			myfile.close();
		}
	}

	int page_refs[_input.length()];
	int _count = 0;
    istringstream iss(_input);
    do
    {
        string sub;
        iss >> sub;
        page_refs[_count] = atoi(sub.c_str());;
        ++_count;
    } while (iss);
    --_count; // discard the last one;

    // start using Policies
    Policy<int> * thePolicy;
    switch(ut.arg_replace_policy){
    	case Util::FIFO:
    		thePolicy = new PolicyFIFO<int>(ut.arg_available_frame);
    		break;
    	case Util::LFU:
    		thePolicy = new PolicyLFU<int>(ut.arg_available_frame);
    		break;
    	case Util::LRU_CLOCK:
    		thePolicy = new PolicyLRUClock<int>(ut.arg_available_frame);
    		break;
    	case Util::LRU_REF8:
    		thePolicy = new PolicyLRUREF8<int>(ut.arg_available_frame);
    		break;
    	case Util::LRU_STACK:
    		thePolicy = new PolicyLRUStack<int>(ut.arg_available_frame);
    		break;
    	default:
    		thePolicy = new PolicyFIFO<int>(ut.arg_available_frame);
    		break;
    }

    // optimal algorithm
    PolicyOptimal<int> * cmpPolicy = new PolicyOptimal<int>(page_refs, ut.arg_available_frame, _count);
    struct timeval tv1;
    struct timeval tv2;
    gettimeofday(&tv1, NULL);
    uint start_t = (uint)tv1.tv_usec;
    int optimal_pf = cmpPolicy->getOptimalResult();
    gettimeofday(&tv2, NULL);
    uint end_t = (uint)tv2.tv_usec;
    uint opt_time_usage = end_t - start_t;

    // usr's choice
    gettimeofday(&tv1, NULL);
    start_t = (uint)tv1.tv_usec;
    for (int j = 0; j<_count; ++j){
    	thePolicy->addPage(page_refs[j]);
    }
    gettimeofday(&tv2, NULL);
    end_t = (uint)tv2.tv_usec;
    int normal_pf = thePolicy->getNumPageFault();
    uint norm_time_usage = end_t - start_t;

    cout << "# of page replacements with User's Choice: " << normal_pf << endl;
    cout << "# of page replacements with Optimal: " << optimal_pf << endl;
    cout << "% page replacement penalty using: " << (((double)optimal_pf-(double)normal_pf)/(double)normal_pf) << "%"<< endl;
    cout << endl;
    cout << "Total time to run User's Choice: " << norm_time_usage << "msec" << endl;
    cout << "Total time to run Optimal algorithm: " << opt_time_usage << "msec" << endl;
    cout << "The chosen algorithm is " << (((double)opt_time_usage-(double)norm_time_usage)/(double)norm_time_usage) << " % faster than the Optimal algorithm." << endl;
}
void OptionLoader::LoadOption(int method){
    std::ifstream myfile(file.c_str());
    
    std::string line;
    std::string cell;
    
    while(myfile){
        
        OptionParameterSet option;
        
        std::getline(myfile, line);
        std::stringstream lineStream(line);
        
        std::getline(lineStream, cell, ',');
        option.T = atof(cell.c_str())/365.0;
        
        std::getline(lineStream, cell, ',');
        option.type = cell[0];
        
        std::getline(lineStream, cell, ',');
        option.S0 = atof(cell.c_str());
        
        std::getline(lineStream, cell, ',');
        option.K = atof(cell.c_str());
        
        std::getline(lineStream, cell, ',');
        option.bid = atof(cell.c_str());
        
        std::getline(lineStream, cell, ',');
        option.ask = atof(cell.c_str());
        
        option.mid = (option.bid + option.ask)/2.0;
        
        std::getline(lineStream, cell, ',');
        option.r = atof(cell.c_str())/100.0;
        
        std::getline(lineStream, cell, ',');
        option.q = atof(cell.c_str())/100.0;
        
        if (method == 0)
            option.weight = 1.0;
        else
            option.weight = 1.0/fabs(option.ask - option.bid);
        
        //Choose Out of Money
        if ( option.type == 'C') {
            if ( option.S0 < option.K)
                Options.push_back(option);
        }
        else {
            if ( option.S0 > option.K)
                Options.push_back(option);
        }
    }
    
    if (method == 1) {
        double sum = 0.0;
        for (std::vector<OptionParameterSet>::iterator iter = Options.begin(); iter != Options.end(); ++iter)
            sum += iter->weight;
        
        for (std::vector<OptionParameterSet>::iterator iter = Options.begin(); iter != Options.end(); ++iter)
            iter->weight /= sum;
    }
    
    myfile.close();
}
예제 #5
0
int main(int argc, char* argv[]){
	if (argc < 2){
		std::cerr << "Usage: " << argv[0] << " topic-X.txt, where X = 0, 1, 2, 3, 4"<<std::endl;
		return 1;
	}
	std::map<int, int> data;
	std::map<std::string, int> vocab_map;
	std::map<int, int>::iterator it;
	std::string line;
	double min_sup = 0.01;
	int transcation = 0;
	int j = 0;
	std::string name;
	if ((argv[1][6] - '0') == 0) name = "data/topic-0.txt";
	else if ((argv[1][6] - '0') == 1) name = "data/topic-1.txt";
	else if ((argv[1][6] - '0') == 2) name = "data/topic-2.txt";
	else if ((argv[1][6] - '0') == 3) name = "data/topic-3.txt";
	else if ((argv[1][6] - '0') == 4) name = "data/topic-4.txt";;
	std::ifstream myfile(name);
	if (myfile.is_open()){
		while (getline(myfile,line)){
			transcation++;
			for (size_t i =0; i<line.length();i++){
				if (isspace(line[i])){
				int value = stoi(line.substr(j,i-j));
				if (data.count(value) > 0)
					data.at(value)++;
				else data.insert(std::pair<int, int>(value,1));
				j = i+1;
				}
			}
			j = 0;
		}
	}
	myfile.close();

	int absolute_sup = min_sup * transcation;
	it = data.begin();
	while (it !=data.end())
	{
		if (it->second < absolute_sup){
			it = data.erase(it);
	}
		else{
			++it;
		}
	}

	std::ifstream myfile2("data/vocab.txt");
	if (myfile2.is_open()){
		while (getline(myfile2,line)){
			int value = 0;
			std::string vocab = "";
			for (size_t i =0; i<line.length();i++){
				if (line[i] == 9){
				value = stoi(line.substr(0,i));
				vocab = line.substr(i+1,line.length()-i);
				}
			}
			if (data.count(value) > 0)
				vocab_map.insert(std::pair<std::string, int>(vocab, data[value]));
		}
	}
	myfile2.close();

	std::ofstream write;
	std::string file;
	if ((argv[1][6] - '0') == 0) file = "pattern-0.txt";
	else if ((argv[1][6] - '0') == 1) file = "pattern-1.txt";
	else if ((argv[1][6] - '0') == 2) file = "pattern-2.txt";
	else if ((argv[1][6] - '0') == 3) file = "pattern-3.txt";
	else if ((argv[1][6] - '0') == 4) file = "pattern-4.txt";
	write.open(file);
	std::vector<std::pair<std::string, int>> v(vocab_map.begin(), vocab_map.end());
	std::sort(v.begin(), v.end(), cmp_value);
	for (size_t i =0; i != v.size();i++)
	write<<v[i].second<<"\t"<< v[i].first<<"\n";

	write.close();
	return 0;
}
예제 #6
0
void Ekf2Replay::task_main()
{
	// formats
	const int _k_max_data_size = 1024;	// 16x16 bytes
	uint8_t data[_k_max_data_size] = {};
	const char param_file[] = "./rootfs/replay_params.txt";

	// Open log file from which we read data
	// TODO Check if file exists
	int fd = ::open(_file_name, O_RDONLY);

	// create path to write a replay file
	char *replay_log_name;
	replay_log_name = strtok(_file_name, ".");
	char tmp[] = "_replayed.px4log";
	char *path_to_replay_log = (char *) malloc(1 + strlen(tmp) + strlen(replay_log_name));
	strcpy(path_to_replay_log, ".");
	strcat(path_to_replay_log, replay_log_name);
	strcat(path_to_replay_log, tmp);

	// create path which tells user location of replay file
	char tmp2[] = "./build_posix_sitl_replay/src/firmware/posix";
	char *replay_file_location = (char *) malloc(1 + strlen(tmp) + strlen(tmp2) + strlen(replay_log_name));
	strcat(replay_file_location, tmp2);
	strcat(replay_file_location, replay_log_name);
	strcat(replay_file_location, tmp);

	// open logfile to write
	_write_fd = ::open(path_to_replay_log, O_WRONLY | O_CREAT, S_IRWXU);

	std::ifstream tmp_file;
	tmp_file.open(param_file);

	std::string line;
	bool set_default_params_in_file = false;

	if (tmp_file.is_open() && ! tmp_file.eof()) {
		getline(tmp_file, line);

		if (line.empty()) {
			// the parameter file is empty so write the default values to it
			set_default_params_in_file = true;
		}
	}

	tmp_file.close();

	std::ofstream myfile(param_file, std::ios::app);

	// subscribe to estimator topics
	_att_sub = orb_subscribe(ORB_ID(vehicle_attitude));
	_estimator_status_sub = orb_subscribe(ORB_ID(estimator_status));
	_innov_sub = orb_subscribe(ORB_ID(ekf2_innovations));
	_lpos_sub = orb_subscribe(ORB_ID(vehicle_local_position));
	_control_state_sub = orb_subscribe(ORB_ID(control_state));

	// we use attitude updates from the estimator for synchronisation
	_fds[0].fd = _att_sub;
	_fds[0].events = POLLIN;

	bool read_first_header = false;
	bool set_user_params = false;

	PX4_INFO("Replay in progress... \n");
	PX4_INFO("Log data will be written to %s\n", replay_file_location);

	while (!_task_should_exit) {
		_message_counter++;
		uint8_t header[3] = {};

		if (::read(fd, header, 3) != 3) {
			if (!read_first_header) {
				PX4_WARN("error reading log file, is the path printed above correct?");

			} else {
				PX4_INFO("Done!");
			}

			_task_should_exit = true;
			continue;
		}

		read_first_header = true;

		if ((header[0] != HEAD_BYTE1 || header[1] != HEAD_BYTE2)) {
			// we assume that the log file is finished here
			PX4_WARN("Done!");
			_task_should_exit = true;
			continue;
		}

		// write header but only for messages which are not generated by the estimator
		if (needToSaveMessage(header[2])) {
			writeMessage(_write_fd, &header[0], 3);
		}

		if (header[2] == LOG_FORMAT_MSG) {
			// format message
			struct log_format_s f;

			if (::read(fd, &f.type, sizeof(f)) != sizeof(f)) {
				PRINT_READ_ERROR;
				_task_should_exit = true;
				continue;
			}

			writeMessage(_write_fd, &f.type, sizeof(log_format_s));

			memcpy(&_formats[f.type], &f, sizeof(f));

		} else if (header[2] == LOG_PARM_MSG) {
			// parameter message
			if (::read(fd, &data[0], sizeof(log_PARM_s)) != sizeof(log_PARM_s)) {
				PRINT_READ_ERROR;
				_task_should_exit = true;
				continue;
			}

			writeMessage(_write_fd, &data[0], sizeof(log_PARM_s));

			// apply the parameters
			char param_name[16];

			for (unsigned i = 0; i < 16; i++) {
				param_name[i] = data[i];

				if (data[i] == '\0') {
					break;
				}
			}

			float param_data = 0;
			memcpy(&param_data, &data[16], sizeof(float));
			param_t handle = param_find(param_name);
			param_type_t param_format = param_type(handle);

			if (param_format == PARAM_TYPE_INT32) {
				int32_t value = 0;
				value = (int32_t)param_data;
				param_set(handle, (const void *)&value);

			} else if (param_format == PARAM_TYPE_FLOAT) {
				param_set(handle, (const void *)&param_data);
			}

			// if the user param file was empty then we fill it with the ekf2 parameter values from
			// the log file
			if (set_default_params_in_file) {
				if (strncmp(param_name, "EKF2", 4) == 0) {
					std::ostringstream os;
					double value = (double)param_data;
					os << std::string(param_name) << " ";
					os << value << "\n";
					myfile << os.str();
				}
			}

		} else if (header[2] == LOG_VER_MSG) {
			// version message
			if (::read(fd, &data[0], sizeof(log_VER_s)) != sizeof(log_VER_s)) {
				PRINT_READ_ERROR;
				_task_should_exit = true;
				continue;
			}

			writeMessage(_write_fd, &data[0], sizeof(log_VER_s));

		} else if (header[2] == LOG_TIME_MSG) {
			// time message
			if (::read(fd, &data[0], sizeof(log_TIME_s)) != sizeof(log_TIME_s)) {
				// assume that this is because we have reached the end of the file
				PX4_INFO("Done!");
				_task_should_exit = true;
				continue;
			}

			writeMessage(_write_fd, &data[0], sizeof(log_TIME_s));

		} else {
			// the first time we arrive here we should apply the parameters specified in the user file
			// this makes sure they are applied after the parameter values of the log file
			if (!set_user_params) {
				myfile.close();
				setUserParams(param_file);
				set_user_params = true;
			}

			// data message
			if (::read(fd, &data[0], _formats[header[2]].length - 3) != _formats[header[2]].length - 3) {
				PX4_INFO("Done!");
				_task_should_exit = true;
				continue;
			}

			// all messages which we are not getting from the estimator are written
			// back into the replay log file
			if (needToSaveMessage(header[2])) {
				writeMessage(_write_fd, &data[0], _formats[header[2]].length - 3);
			}

			if (header[2] == LOG_RPL1_MSG && _part1_counter_ref > 0) {
				// we have found another imu replay message while we still have one waiting to be published.
				// so publish that now
				publishAndWaitForEstimator();
			}

			// set estimator input data
			setEstimatorInput(&data[0], header[2]);

			// we have read the imu replay message (part 1) and have waited 3 more cycles for other replay message parts
			// e.g. flow, gps or range. we know that in case they were written to the log file they should come right after
			// the first replay message, therefore, we can kick the estimator now
			if (_part1_counter_ref > 0 && _part1_counter_ref < _message_counter - 3) {
				publishAndWaitForEstimator();
			}
		}
	}

	::close(_write_fd);
	::close(fd);
	delete ekf2_replay::instance;
	ekf2_replay::instance = nullptr;

	// Report sensor innovation RMS values to assist with time delay tuning
	if (_numInnovSamples > 0) {
		PX4_INFO("GPS vel innov RMS = %6.3f", (double)sqrtf(_velInnovSumSq / _numInnovSamples));
		PX4_INFO("GPS pos innov RMS = %6.3f", (double)sqrtf(_posInnovSumSq / _numInnovSamples));
		PX4_INFO("Hgt innov RMS = %6.3f", (double)sqrtf(_hgtInnovSumSq / _numInnovSamples));
		PX4_INFO("Mag innov RMS = %6.4f", (double)sqrtf(_magInnovSumSq / _numInnovSamples));
		PX4_INFO("TAS innov RMS = %6.3f", (double)sqrtf(_tasInnovSumSq / _numInnovSamples));
	}

}
예제 #7
0
int main(int argc,char * argv[]){
  // array size is 20
  int AR_SIZE=20;
  // create a line array
  string line[AR_SIZE];

  int aptNum=0; // 1<=n<=100 // number of apartments

  int roomWidth=0; // 8 <=n<=100 // width of the room

  int roomLength=0; // 8 <= n <= 100 // length of the room

  int roomHeight=0; // 8 <=n <= 30 // height of the room

  // 100 <= n <= 1000 area in square feet that can be covered by each can of paint
  int roomArea=0;

  int roomDoors=0; // 0 <= m <= 10 // windows and doors

  int doorWidth=0; // No window or door will be larger than the largest wall.
  int doorHeight=0;

  int runningTotal=0; // Our total for temp calcs

  // create file name variable
  string file;

  // default return value of main is 0
  int returnValue=0;

  // default index position is 0
  int index=0;

  // check for more than 1 argument
  if(argc>1){
    // set the filename to the first argument of the program
    file=argv[1];

    // create a file handler and open the filename value given in argv[1]
    ifstream myfile(file.c_str());

    // check for valid file
    if(myfile.is_open()){

      // read in the input file
      while(myfile.good()){

        // read line from file
        myfile>>aptNum>>roomWidth>>roomLength>>roomHeight>>roomArea>>roomDoors;
        // check for zeros

        if(aptNum&&roomWidth&&roomLength&&roomHeight&&roomArea&&roomDoors){

          cout<<" There is "<<aptNum<<" apartments to be painted!"<<endl;

          cout<<"There is "<<roomDoors<<" to be done."<<endl;
          // do work

//          cout<<"roomWidth = "<<roomWidth<<endl;
//          cout<<"roomHeight = "<<roomHeight<<endl;
//          cout<<"roomLength = "<<roomLength<<endl;

          // get four wall dimension
          runningTotal=2*((roomWidth*roomHeight)+(roomLength*roomHeight));
          cout<<"wall sqft = "<<runningTotal<<endl;
          // add the ceilings!!! :)
          runningTotal=runningTotal+(roomWidth*roomLength);

          cout<<"running total sqft before windows/doors "<<runningTotal<<endl;

          // start with one!!
          for (int j=1; j<=roomDoors; j++){
            myfile>>doorWidth>>doorHeight;

            cout<<(doorWidth*doorHeight)<<endl;
            runningTotal=runningTotal-(doorWidth*doorHeight);
          }

          cout<<"running total sqft after windows/doors "<<runningTotal<<endl;

          // get the apt total
          runningTotal=(aptNum*runningTotal);
          cout<<fixed<<setprecision(2)<<endl;

          cout<<" left over paint/sqft "<<(runningTotal%roomArea)<<endl;

          // if there is leftover squarefootage, we need another can of paint!
          if((runningTotal%roomArea)!=0){
            cout<<"# cans of paint "<<(float) (runningTotal/roomArea)+1<<endl;

          }else{
            cout<<"# cans of paint "<<(float) (runningTotal/roomArea)<<endl;

          }

        }else{

          cout<<"DONE! no more work to be had!"<<endl;

        }

        index++;
      }
예제 #8
0
void define_data(IloEnv env) {
  string line("           ");
  ifstream myfile ("/home/DavidRC/data.txt");
  int i=0;
  int j=0;
  int x=0;
  int y=0;

  if (myfile.is_open())
  {
    i=0;
	  j=0;
    
	  getline(myfile,line);
	  n=atoi(line.c_str());
	  IloNumArray l(env,n);
	  NumMatrix w(env,n);
    
    for(i=0; i<n; i++)
    {
      w[i]=IloNumArray(env,n);
    }
	  
	  getline (myfile,line);
    
	  istringstream iss1(line);  
	  	while (iss1 && j<n) 
		{ 
			string subs; 
			iss1 >> subs; 
			string temp=subs;
			if(temp.compare("")==0)
			{
				continue;
			}
			else
			{

            l[j]=atoi(subs.c_str());
			}
			j++;
	    }
     exit(1);

     i=0;
	 j=0;
	 while ( getline (myfile,line) && i<n)
     {
	    istringstream iss2(line);
          j=0;

		while (iss2 && j<n) 
		{ 
			string subs; 
			iss2 >> subs; 
			string temp=subs;

			if(temp.compare("")==0)
			{
				continue;
                        j++;
			}
			else
			{

            w[i][j]=atoi(subs.c_str());
            			j++;
			}
	    }
		i++;
    }

	  m=atoi( line.c_str() );

    IloNumArray c(env,m);
	  NumMatrix d(env,m);
    
    for(i=0; i<m; i++)
    {
      d[i]=IloNumArray(env,m);
    } 
		  
  i=0;
  j=0;    
	getline (myfile,line);
	istringstream iss3(line);
	while (iss3 && j<m) 
	{ 
		string subs; 
		iss3 >> subs; 
		string temp=subs;
		if(temp.compare("")==0)
		{
			continue;
		}
		else
		{
           c[j]=atoi(subs.c_str());
		}
		j++;
	}
		
	i=0;
	j=0;
	while ( getline (myfile,line) && i<m)
    {
	    istringstream iss4(line);
          j=0;
		while (iss4 && j<m) 
		{ 
			string subs; 
			iss4 >> subs; 
			string temp=subs;
			if(temp.compare("")==0)
			{
				continue;
			}
			else
			{
            d[i][j]=atoi(subs.c_str());
			}
			j++;
	    }
		i++;
    }
    myfile.close();
  }
예제 #9
0
int main() {
	std::setlocale(LC_ALL, "de_DE.UTF-8"); // important for utf-8 multibyte chars
	const std::string path = "/home/typology/1/";
	const std::string path2 = "/home/typology/1sorted/";
	 struct dirent *entry;
	  DIR *dp;

	  dp = opendir(path.c_str());
	  if (dp == NULL) {
	    std::cout << "Path \"" << path << "\" does not exist or could not be read." << std::endl;
	    return 1;
	  }

	  std::string source;
	  std::string target;
	  float score;
	  std::vector<std::string> vSource;
	  std::vector<std::string> vTarget;
	  std::vector<float> vScore;
	  std::tuple<int,char> foo;
	  std::vector<std::tuple<std::string,std::string,float>>* vt = new std::vector<std::tuple<std::string,std::string,float>>();
	  std::vector<std::string> filenames;

	  while ((entry = readdir(dp))){
		if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
			continue;
		}
		filenames.push_back(entry->d_name);
	  }
	  closedir(dp);
	  std::sort(filenames.begin(), filenames.end());
	  wchar_t lastChar;
	  wchar_t currentChar;
	  std::string lastfName;

	  mbrtowc(&lastChar, &filenames[0][0], MB_CUR_MAX, NULL); // Convert multibyte sequence (utf-8) to wide character
	  lastfName = filenames[0];
	  for(auto iter = filenames.begin(); iter != filenames.end(); ++iter) {
		  mbrtowc(&currentChar, &((*iter)[0]), 4, NULL);
		  		if(currentChar != lastChar) {
		  			std::sort(vt->begin(),vt->end(),&compareTwoRows);
		  			std::ofstream myfile ((path2 + lastfName).c_str() );
		  			if (myfile.is_open())
		  			{
		  				for (auto i : *vt){
		  					myfile << std::get<0>(i) << '\t' << std::get<1>(i) << '\t' << std::get<2>(i) << '\n';
		  				}
		  			  myfile.close();
		  			}
		  			vt->clear();
		  			lastChar = currentChar;
		  			lastfName = *iter;
		  		}
	    std::ifstream file((path + *iter).c_str());
	    std::cout << "reading file : " << path + *iter << std::endl;
	    for(std::string line; getline(file, line);) {
			std::istringstream ss(line);
			ss >> source >> target;
			ss.ignore(2);
			ss >> score;
			vt->push_back(std::make_tuple (source, target, score));
	    }

  		if(iter == filenames.end() - 1) {
  			std::sort(vt->begin(),vt->end(),&compareTwoRows);
  			std::ofstream myfile ((path2 + lastfName).c_str() );
  			if (myfile.is_open())
  			{
  				for (auto i : *vt){
  					myfile << std::get<0>(i) << '\t' << std::get<1>(i) << '\t' << std::get<2>(i) << '\n';
  				}
  			  myfile.close();
  			}
  		}
	  }
	  delete vt;
	  return 0;
}
예제 #10
0
Table* read_from_userprofile() {
	ifstream myfile ("userprofile.csv");
  if (myfile.is_open())
  {

	Table::ColumnList columns;

	String userID;
	getline( myfile, userID, ',' );
    columns.push_back(make_pair(userID, Table::varchar));

	String latitude;
	getline( myfile, latitude, ',' );
	columns.push_back(make_pair(latitude, Table::floating));

	String longitude;
	getline( myfile, longitude, ',' );
	columns.push_back(make_pair(longitude, Table::integer));

	String smoker;
	getline( myfile, smoker, ',');
    columns.push_back(make_pair(smoker, Table::varchar));

	String drink_level;
	getline( myfile, drink_level, ',');
    columns.push_back(make_pair(drink_level, Table::varchar));

	String dress_preference;
	getline( myfile, dress_preference, ',' );
    columns.push_back(make_pair(dress_preference, Table::varchar));

	String ambience;
	getline( myfile, ambience, ',' );
    columns.push_back(make_pair(ambience, Table::varchar));

	String transport;
	getline( myfile, transport, ',' );
    columns.push_back(make_pair(transport, Table::varchar));

	String marital_status;
	getline( myfile, marital_status, ',' );
    columns.push_back(make_pair(marital_status, Table::varchar));

	String hijos;
	getline( myfile, hijos, ',');
    columns.push_back(make_pair(hijos, Table::varchar));

	String birth_year;
	getline( myfile, birth_year, ',' );
    columns.push_back(make_pair(birth_year, Table::integer));

		String interest;
	getline( myfile, interest, ',' );
    columns.push_back(make_pair(interest, Table::varchar));

		String personality;
	getline( myfile, personality, ',' );
    columns.push_back(make_pair(personality, Table::varchar));

		String religion;
	getline( myfile, religion, ',' );
    columns.push_back(make_pair(religion, Table::varchar));

		String activity;
	getline( myfile, activity, ',' );
    columns.push_back(make_pair(activity, Table::varchar));

		String color;
	getline( myfile, color, ',' );
    columns.push_back(make_pair(color, Table::varchar));

		String weight;
	getline( myfile, weight, ',' );
    columns.push_back(make_pair(weight, Table::integer));

		String budget;
	getline( myfile, budget, ',' );
    columns.push_back(make_pair(budget, Table::varchar));

		String height;
	getline( myfile, height, '\n' );
	columns.push_back(make_pair(height, Table::floating));


	Table* geo = new Table(columns); // Create geo using the defined columns
	


    while ( myfile.good() )
    {

	  vector<pair<string, string> > entries; // Entries for the record to be placed in the table
	  
	  string userID;
	  getline( myfile, userID, ',' );
	  pair <string,string> pair0  ("userID",userID);   // value init
	  entries.push_back(pair0);

	  string latitude;
	  getline( myfile, latitude, ',' );
	  pair <string,string> pair1  ("latitude",latitude);   // value init
	  entries.push_back(pair1);

	  string longitude;
	  getline( myfile, longitude, ',' );
	  pair <string,string> pair2  ("longitude",longitude);   // value init
	  entries.push_back(pair2);

	  string smoker;
	  getline( myfile, smoker, ',' );
	  pair <string,string> pair3  ("smoker",smoker);   // value init
	  entries.push_back(pair3);

	  string drink_level;
	  getline( myfile, drink_level, ',' );
	  pair <string,string> pair4  ("drink_level",drink_level);   // value init
	  entries.push_back(pair4);

	  string dress_preference;
	  getline( myfile, dress_preference, ',' );
	  pair <string,string> pair5  ("dress_preference",dress_preference);   // value init
	  entries.push_back(pair5);

	  string ambience;
	  getline( myfile, ambience, ',' );
	  pair <string,string> pair6  ("ambience",ambience);   // value init
	  entries.push_back(pair6);

	  string transport;
	  getline( myfile, transport, ',' );
	  pair <string,string> pair7  ("transport",transport);   // value init
	  entries.push_back(pair7);

	  string marital_status;
	  getline( myfile, marital_status, ',' );
	  pair <string,string> pair8  ("marital_status",marital_status);   // value init
	  entries.push_back(pair8);

	  string hijos;
	  getline( myfile, hijos, ',' );
	  pair <string,string> pair9  ("hijos",hijos);   // value init
	  entries.push_back(pair9);

	  string birth_year;
	  getline( myfile, birth_year, ',' );
	  pair <string,string> pair10  ("birth_year",birth_year);   // value init
	  entries.push_back(pair10);

	  string interest;
	  getline( myfile, interest, ',' );
	  pair <string,string> pair11  ("interest",interest);   // value init
	  entries.push_back(pair11);

	  string personality;
	  getline( myfile, personality, ',' );
	  pair <string,string> pair12  ("personality",personality);   // value init
	  entries.push_back(pair12);

	  string religion;
	  getline( myfile, religion, ',' );
	  pair <string,string> pair13  ("religion",religion);   // value init
	  entries.push_back(pair13);

	  string activity;
	  getline( myfile, activity, ',' );
	  pair <string,string> pair14  ("activity",activity);   // value init
	  entries.push_back(pair14);

	  string color;
	  getline( myfile, color, ',' );
	  pair <string,string> pair15 ("color",color);   // value init
	  entries.push_back(pair15);

	  string weight;
	  getline( myfile, weight, ',' );
	  pair <string,string> pair16  ("weight",weight);   // value init
	  entries.push_back(pair16);

	  string budget;
	  getline( myfile, budget, ',' );
	  pair <string,string> pair17  ("budget",budget);   // value init
	  entries.push_back(pair17);

	  string height;
	  getline( myfile, height, '\n' );
	  pair <string,string> pair18  ("height",height);   // value init
	  entries.push_back(pair18);



	  Record add(entries); // Create record to add to table

	  geo->insert(add); // Insert add record into geo
	  
	}
    myfile.close();
	return geo;
  }
}
예제 #11
0
Table* read_from_geoplaces2() {


  
  ifstream myfile ("geoplaces2.csv");
  if (myfile.is_open())
  {

	Table::ColumnList columns;

	String placeID;
	getline( myfile, placeID, ',' );
    columns.push_back(make_pair(placeID, Table::integer));

	String latitude;
	getline( myfile, latitude, ',' );
	columns.push_back(make_pair(latitude, Table::floating));

	String longitude;
	getline( myfile, longitude, ',' );
	columns.push_back(make_pair(longitude, Table::floating));

	String the_geom_meter;
	getline( myfile, the_geom_meter, ',' );
	columns.push_back(make_pair(the_geom_meter, Table::varchar));

	String name;
	getline( myfile, name, ',' );
    columns.push_back(make_pair(name, Table::varchar));

	String address;
	getline( myfile, address, ',' );
    columns.push_back(make_pair(address, Table::varchar));

	String city;
	getline( myfile, city, ',' );
    columns.push_back(make_pair(city, Table::varchar));

	String state;
	getline( myfile, state, ',' );
    columns.push_back(make_pair(state, Table::varchar));

	String country;
	getline( myfile, country, ',' );
    columns.push_back(make_pair(country, Table::varchar));

	String fax;
	getline( myfile, fax, ',' );
    columns.push_back(make_pair(fax, Table::varchar));

	String zip;
	getline( myfile, zip, ',' );
    columns.push_back(make_pair(zip, Table::varchar));

	String alcohol;
	getline( myfile, alcohol, ',' );
    columns.push_back(make_pair(alcohol, Table::varchar));

	String smoking_area;
	getline( myfile, smoking_area, ',' );
    columns.push_back(make_pair(smoking_area, Table::varchar));

	String dress_code;
	getline( myfile, dress_code, ',' );
    columns.push_back(make_pair(dress_code, Table::varchar));

	String accessibility;
	getline( myfile, accessibility, ',' );
    columns.push_back(make_pair(accessibility, Table::varchar));

	String price;
	getline( myfile, price, ',' );
    columns.push_back(make_pair(price, Table::varchar));

	String url;
	getline( myfile, url, ',' );
    columns.push_back(make_pair(url, Table::varchar));

	String Rambience;
	getline( myfile, Rambience, ',' );
    columns.push_back(make_pair(Rambience, Table::varchar));

	String franchise;
	getline( myfile, franchise, ',' );
    columns.push_back(make_pair(franchise, Table::varchar));

	String area;
	getline( myfile, area, ',' );
    columns.push_back(make_pair(area, Table::varchar));

	String other_services;
	getline( myfile, other_services, '\n' );
    columns.push_back(make_pair(other_services, Table::varchar));

	

	Table* geo = new Table(columns); // Create geo using the defined columns
	


    while ( myfile.good() )
    {
	  vector<pair<string, string> > entries; // Entries for the record to be placed in the table
	  
	  string placeID;
	  getline( myfile, placeID, ',' );
	  pair <string,string> pair0  ("placeID",placeID);   // value init
	  entries.push_back(pair0);

	  string latitude;
	  getline( myfile, latitude, ',' );
	  pair <string,string> pair1  ("latitude",latitude);   // value init
	  entries.push_back(pair1);

	  string longitude;
	  getline( myfile, longitude, ',' );
	  pair <string,string> pair2  ("longitude",longitude);   // value init
	  entries.push_back(pair2);

	  string the_geom_meter;
	  getline( myfile, the_geom_meter, ',' );
	  pair <string,string> pair3  ("the_geom_meter",the_geom_meter);   // value init
	  entries.push_back(pair3);

	  string name;
	  getline( myfile, name, ',' );
	  pair <string,string> pair4  ("name",name);   // value init
	  entries.push_back(pair4);

	  string address;
	  getline( myfile, address, ',' );
	  pair <string,string> pair5  ("address",address);   // value init
	  entries.push_back(pair5);

	  string city;
	  getline( myfile, city, ',' );
	  pair <string,string> pair6  ("city",city);   // value init
	  entries.push_back(pair6);

	  string state;
	  getline( myfile, state, ',' );
	  pair <string,string> pair7  ("state",state);   // value init
	  entries.push_back(pair7);

	  string country;
	  getline( myfile, country, ',' );
	  pair <string,string> pair8  ("country",country);   // value init
	  entries.push_back(pair8);

	  string fax;
	  getline( myfile, fax, ',' );
	  pair <string,string> pair9  ("fax",fax);   // value init
	  entries.push_back(pair9);

	  string zip;
	  getline( myfile, zip, ',' );
	  pair <string,string> pair10  ("zip",zip);   // value init
	  entries.push_back(pair10);

	  string alcohol;
	  getline( myfile, alcohol, ',' );
	  pair <string,string> pair11  ("alcohol",alcohol);   // value init
	  entries.push_back(pair11);

	  string smoking_area;
	  getline( myfile, smoking_area, ',' );
	  pair <string,string> pair12  ("smoking_area",smoking_area);   // value init
	  entries.push_back(pair12);

	  string dress_code;
	  getline( myfile, dress_code, ',' );
	  pair <string,string> pair13  ("dress_code",dress_code);   // value init
	  entries.push_back(pair13);

	  string accessibility;
	  getline( myfile, accessibility, ',' );
	  pair <string,string> pair14  ("accessibility",accessibility);   // value init
	  entries.push_back(pair14);

	  string price;
	  getline( myfile, price, ',' );
	  pair <string,string> pair15 ("price",price);   // value init
	  entries.push_back(pair15);

	  string url;
	  getline( myfile, url, ',' );
	  pair <string,string> pair16  ("url",url);   // value init
	  entries.push_back(pair16);

	  string Rambience;
	  getline( myfile, Rambience, ',' );
	  pair <string,string> pair17  ("Rambience",Rambience);   // value init
	  entries.push_back(pair17);

	  string franchise;
	  getline( myfile, franchise, ',' );
	  pair <string,string> pair18  ("franchise",franchise);   // value init
	  entries.push_back(pair18);

	  string area;
	  getline( myfile, area, ',' );
	  pair <string,string> pair19  ("area",area);   // value init
	  entries.push_back(pair19);

	  string other_services;
	  getline( myfile, other_services, '\n' );
	  pair <string,string> pair20  ("other_services",other_services);   // value init
	  entries.push_back(pair20);

	  Record add(entries); // Create record to add to table

	  geo->insert(add);  // Insert add record into geo
	  
	}
    
	myfile.close();
	return geo;

  }

}
예제 #12
0
Table* read_from_rating_final() {

  ifstream myfile ("rating_final.csv");
  if (myfile.is_open())
  {

	Table::ColumnList columns;

	String placeID;
	getline( myfile, placeID, ',' );
    columns.push_back(make_pair(placeID, Table::varchar));

	String latitude;
	getline( myfile, latitude, ',' );
	columns.push_back(make_pair(latitude, Table::integer));

	String longitude;
	getline( myfile, longitude, ',' );
	columns.push_back(make_pair(longitude, Table::integer));

	String the_geom_meter;
	getline( myfile, the_geom_meter, ',' );
	columns.push_back(make_pair(the_geom_meter, Table::integer));

	String name;
	getline( myfile, name, '\n' );
    columns.push_back(make_pair(name, Table::integer));


	Table* geo = new Table(columns); // Create geo using the defined columns
	


    while ( myfile.good() )
    {
	  vector<pair<string, string> > entries; // Entries for the record to be placed in the table
	  
	  string placeID;
	  getline( myfile, placeID, ',' );
	  pair <string,string> pair0  ("userID",placeID);   // value init
	  entries.push_back(pair0);

	  string latitude;
	  getline( myfile, latitude, ',' );
	  pair <string,string> pair1  ("placeID",latitude);   // value init
	  entries.push_back(pair1);

	  string longitude;
	  getline( myfile, longitude, ',' );
	  pair <string,string> pair2  ("rating",longitude);   // value init
	  entries.push_back(pair2);

	  string the_geom_meter;
	  getline( myfile, the_geom_meter, ',' );
	  pair <string,string> pair3  ("food_rating",the_geom_meter);   // value init
	  entries.push_back(pair3);

	  string name;
	  getline( myfile, name, '\n' );
	  pair <string,string> pair4  ("service_rating",name);   // value init
	  entries.push_back(pair4);


	  Record add(entries); // Create record to add to table

	  geo->insert(add); // Insert add record into geo
	  
	}
    myfile.close();
	return geo;
  }
}
예제 #13
0
void Extractor::readGeoData(const string& filepath)
{
#ifdef DEBUG
    ofstream debug_log("debug_log_readGeoData.txt");
    debug_log.precision(dbl::digits10);
#endif
    // Open text file
    ifstream myfile(filepath.c_str());
    if (!myfile.is_open())
    {
        cerr << "Could not open " << filepath << endl;
        return;
    }
    // cout << "Parsing " << filepath << " for time stamps and GPS locations." << endl;
    string line;
    // Parse line by line
    while ( getline(myfile, line) )
    {
        // Skip empty lines
        if ( line.compare("") == 0)
            continue;
        // Tokenize line
        vector<string> tokens = split(line, ' ');
        // If line starts with 'T'
        if (tokens[0].compare("T") == 0)
        {
            // 1. Add time stamp
            string timestamp = "";
            timestamp += tokens[1] + " " + tokens[2] + " UTC+4";
            // Set up the input datetime format.
            string format = "%Y-%m-%d %H:%M:%S%f %ZP";
            if (split(tokens[2], '.').size() < 2)
                format = "%Y-%m-%d %H:%M:%S %ZP";
            local_time_input_facet *input_facet = new local_time_input_facet(format.c_str());
            // Read time
            stringstream ss;
            ss.imbue(std::locale(ss.getloc(), input_facet));
            local_date_time ldt(not_a_date_time);
            ss.str(timestamp);
            ss >> ldt;
            if (ldt.is_not_a_date_time())
            {
                cout << "Warning: " << ss << " could not be read correctly." << endl;
                cout << "\tFormat is " << format << endl;
                cout << "\tDate: " << tokens[2] << endl;
            }
            // Insert boost local_time into list
            timestamps.push_back(ldt);

            // 2. Add GPS coordinates
            vector<double> coord;
            coord.push_back(atof(tokens[3].c_str()));
            coord.push_back(atof(tokens[4].c_str()));
            GPScoord.push_back(coord);
#ifdef DEBUG
            debug_log << "Time: " << ldt.local_time() << ", GPS: " << fixed << coord[0] << ", " << coord[1] << endl;
#endif
        }
#ifdef DEBUG
        else
        {
예제 #14
0
파일: vhtree.C 프로젝트: ankitm123/cmssw
void vhtree::Loop()
{
//   In a ROOT session, you can do:
//      Root > .L vhtree.C
//      Root > vhtree t
//      Root > t.GetEntry(12); // Fill t data members with entry number 12
//      Root > t.Show();       // Show values of entry 12
//      Root > t.Show(16);     // Read and show values of entry 16
//      Root > t.Loop();       // Loop on all entries
//

//     This is the loop skeleton where:
//    jentry is the global entry number in the chain
//    ientry is the entry number in the current Tree
//  Note that the argument to GetEntry must be:
//    jentry for TChain::GetEntry
//    ientry for TTree::GetEntry and TBranch::GetEntry
//
//       To read only selected branches, Insert statements like:
// METHOD1:
//    fChain->SetBranchStatus("*",0);  // disable all branches
//    fChain->SetBranchStatus("branchname",1);  // activate branchname
// METHOD2: replace line
//    fChain->GetEntry(jentry);       //read all branches
//by  b_branchname->GetEntry(ientry); //read only this branch
   if (fChain == 0) return;
   double delRMin=0.03;
   double delR=0.;
   double GenMuonPt=0.;                                                                                                            
   double delphi=0.;
   double deleta=0.;
   double RecoMuonPt=0.;
   double RecoMuonEta=0.;
   double inv_mass=0.;
   double ImpParam=0.;
   double MuonDZ=0.;
   double MuonChi2=0.;
   double SumMuonChi2=0.;
   double e1=0.;
   double e2=0.;
   double p1x=0.;
   double p2x=0.;
   double p1y=0.;
   double p2y=0.;
   double p1z=0.;
   double p2z=0.;
   double phi_1=0.;
   double phi_2=0;
   double theta_1=0;
   double theta_2=0;
   double metx=0.;
   double mety=0.;
   double p_1=0.;
   double p_2=0.;
   double x_1=0;
   double x_2=0;
   double pvis_1=0;
   double pvis_2=0;
   double inv_mass_vis=0;
   Double_t total_events=0;
   Double_t events=0;

   ofstream myfile("acceptance.file",ios::app);
   ofstream myfile2("acceptance2.file",ios::app);
   
   TH1F *h1PtReco = new TH1F("h1PtReco","Reco Muon Pt",100,0,300);
   TH1F *h1PtGen = new TH1F("h1PtGen","Gen Muon Pt",100,0,300);
   
   TH1F *h1PtLeading = new TH1F("h1PtLeading","Leading Muon Pt",100,0,100);
   TH1F *h1PtSubLeading = new TH1F("h1PtSubLeading","SubLeading Muon Pt",100,0,100);
   
   TH1F *h1PtLeadingi = new TH1F("h1PtLeadingi","Integrated Leading Muon Pt",100,0,100);
   TH1F *h1PtSubLeadingi = new TH1F("h1PtSubLeadingi","Integrated SubLeading Muon Pt",100,0,100);
   


   TH1F *h1EtaReco = new TH1F("h1EtaReco","Reco Muon Eta",100,-5,+5);
   //TH1F *h1EtaGen = new TH1F("h1EtaGen","Gen Muon Eta",100,-5,+5);
   
   TH1F *hPhiReco = new TH1F("hPhiReco","Difference in Phi between the two muons in multiples of #pi",100,-2,2);

   
   
   TH1F *hMCMatchEC = new TH1F("hMCMatchEC","Muon Pt resolution in End cap region",200,-0.5,0.5);
   TH1F *hMCMatchBa = new TH1F("hMCMatchBa","Muon Pt resolution in barrel region",200,-0.5,0.5);
   
   TH1F *hLeadMuon1 = new TH1F("hLeadMuon1","Leading Muon and Subleading Muon in EndCap",100,0,100);
   TH1F *hLeadMuon2 = new TH1F("hLeadMuon2","Leading Muon in Endcap, subleading muon in barrel",100,0,100);
   TH1F *hLeadMuon3 = new TH1F("hLeadMuon3","Leading Muon in Barrel, subleading muon in endcap",100,0,100);
   
   TH1F *hSubLeadMuon1 = new TH1F("hSubLeadMuon1","Leading Muon and Subleading Muon in EndCap",100,0,100);
   TH1F *hSubLeadMuon2 = new TH1F("hSubLeadMuon2","Leading Muon in Endcap, subleading muon in barrel",100,0,100);
   TH1F *hSubLeadMuon3 = new TH1F("hSubLeadMuon3","Leading Muon in Barrel, subleading muon in endcap",100,0,100);
   
   TH2F *h1 = new TH2F("h1","Correlation plot between Subleading and leading muon Pt(Overall)",30,0,30,30,0,30);
   TH2F *h11 = new TH2F("h11","Correlation plot between Subleading and leading muon Pt(EC(Lead), EC(sublead))",30,0,30,30,0,30);
   TH2F *h12 = new TH2F("h12","Correlation plot between Subleading and leading muon Pt(EC(Lead),Barrel(Sublead))",30,0,30,30,0,30);
   TH2F *h13 = new TH2F("h13","Correlation plot between Subleading and leading muon Pt(EC(sublead),Barrel(Lead))",30,0,30,30,0,30);
   //TH3F *h2 = new TH3F("h2","acceptance plot",300,0,300,100,0,150,100,0,1);
   TH2F *hAcceptAll = new TH2F("hAcceptAll","Overall acceptance plot",200,0,50,200,0,50);
   TH2F *hAccept1 = new TH2F("hAccept1","Leading Muon and Subleading Muon in EndCap",200,0,50,200,0,50);
   TH2F *hAccept2 = new TH2F("hAccept2","Leading Muon in Endcap, subleading muon in barrel",200,0,50,200,0,50);
   TH2F *hAccept3 = new TH2F("hAccept3","Leading Muon in Barrel, subleading muon in endcap",200,0,50,200,0,50);
   
   //TProfile2D *h2 = new TProfile2D("h2","acceptance plot",100,0,300,100,0,300,0,1);  
   //TGraph2D *t2 = new TGraph2D();
   TH1F *hInvTau = new TH1F("hInvTau","Invariant Mass plot for Taus",100,0,300);
   TH1F *hInvMuon = new TH1F("hInvMuon","Invariant Mass plot for Muons(visible)",100,0,300);

   
   
   TH1F *hImPEC = new TH1F("hImPEC","Impact parameter plot End cap",100,-0.3,0.3);
   TH1F *hImPBa = new TH1F("hImPBa","Impact parameter plot barrel",100,-0.3,0.3);
   
   TH1F *hDZEC = new TH1F("hDZEC","Muon DZ plot End cap",100,-10,10);
   TH1F *hDZBa = new TH1F("hDZBa","Muon DZ plot barrel",100,-10,10);

   TH1F *hChiEC = new TH1F("hChiEC","Muon Chi plot End cap",100,0,16);
   TH1F *hChiBa = new TH1F("hChiBa","Muon Chi plot barrel",100,0,16);

   TH1F *hImPECEr = new TH1F("hImPECEr","Error in Impact parameter plot End cap",100,0,16);
   TH1F *hImPBaEr = new TH1F("hImPBaEr","Error in Impact parameter plot barrel",100,0,16);

   //Muon eta plots for pT threshold !

   TH1F *hEtaPt10 = new TH1F("hEtaPt10","Reco Muon Eta 10",100,-3,3);
   TH1F *hEtaPt15 = new TH1F("hEtaPt15","Reco Muon Eta 15",100,-3,3);
   TH1F *hEtaPt20 = new TH1F("hEtaPt20","Reco Muon Eta 20",100,-3,3);
   TH1F *hEtaPt25 = new TH1F("hEtaPt25","Reco Muon Eta 25",100,-3,3);
   TH1F *hEtaPt30 = new TH1F("hEtaPt30","Reco Muon Eta 30",100,-3,3);
   TH1F *hEtaPt35 = new TH1F("hEtaPt35","Reco Muon Eta 35",100,-3,3);

   //2-D histograms

   TH2F *hEtaResEC = new TH2F("hEtaResEC","Eta vs MuonPt resolution in Endcap",100,-3,3,100,-5,5);
   TH2F *hEtaResBa = new TH2F("hEtaResBa","Eta vs MuonPt resolution in barrel",100,-3,3,100,-5,5);
   TH2F *hEtaResAll = new TH2F("hEtaResAll","Eta vs MuonPt resolution Overall",100,-3,3,100,-5,5);
   
   TH2F *hEtaPtEC = new TH2F("hEtaPtEC","Eta vs MuonPt in Endcap",100,-3,3,100,0,200);
   TH2F *hEtaPtBa = new TH2F("hEtaPtBa","Eta vs MuonPt in barrel",100,-3,3,100,0,200);
   TH2F *hEtaPtAll = new TH2F("hEtaPtAll","Eta vs MuonPt Overall",100,-3,3,100,0,200);
   


   //std::vector<double> leadmuonpt;
   //std::vector<double> subleadmuonpt;
   Double_t pt_cut=50.;
   Double_t bin_width=0.25;
   const int bin_size_sl=pt_cut/bin_width;
   const int bin_size_l=pt_cut/bin_width;
   
   Double_t leadmuonpt[bin_size_l]={0}; //100 is the number of bins
   Double_t subleadmuonpt[bin_size_sl]={0};
   
   Double_t leadmuonpt1[bin_size_l]={0}; //100 is the number of bins
   Double_t subleadmuonpt1[bin_size_sl]={0};
   
   Double_t leadmuonpt2[bin_size_l]={0}; //100 is the number of bins
   Double_t subleadmuonpt2[bin_size_sl]={0};
   
   Double_t leadmuonpt3[bin_size_l]={0}; //100 is the number of bins
   Double_t subleadmuonpt3[bin_size_sl]={0};

   //TFile *f1 = new TFile("histos_signal.root","RECREATE");

   
   Long64_t nentries = fChain->GetEntriesFast();
   cout<<"Number of events "<<nentries<<endl;
   int dimuon=0;
   Long64_t nbytes = 0, nb = 0;
   //for (Long64_t jentry=0;jentry<nentries;jentry++) {
   for (Long64_t jentry=0;jentry<nentries;jentry++) {
     Long64_t ientry = LoadTree(jentry);
     if (ientry < 0) break;
     nb = fChain->GetEntry(jentry);   nbytes += nb;
     
     if (nMuon!=2) continue;
     if (abs(Muon_phi[0]-Muon_phi[1] >= 2.0))continue;
     ++dimuon;
     

     if (Muon_pt[0]>Muon_pt[1]){
       h1PtLeading->Fill(Muon_pt[0]);
       h1PtSubLeading->Fill(Muon_pt[1]);
     }
     
     else if (Muon_pt[0]<Muon_pt[1]){
       h1->Fill(Muon_pt[1],Muon_pt[0]);
       cout<<Muon_pt[1]<<" "<<Muon_pt[0]<<endl;
     }
     
     

     //Different cases
     if (Muon_pt[0]>Muon_pt[1]){
	 if (((fabs(Muon_eta[0]) > 1.6) && (fabs(Muon_eta[0]) < 2.2)) && ((fabs(Muon_eta[1]) > 1.6) && (fabs(Muon_eta[1]) < 2.2))){
	   hLeadMuon1->Fill(Muon_pt[0]);
	   hSubLeadMuon1->Fill(Muon_pt[1]);
	   h1->Fill(Muon_pt[0],Muon_pt[1]);
	   h11->Fill(Muon_pt[0],Muon_pt[1]);
	   if (Muon_pt[0]<pt_cut){
	     for (int i=0;i<bin_size_l;i++){
	       if (Muon_pt[0]>=i*bin_width && Muon_pt[0]<(i+1)*bin_width){
		 leadmuonpt[i]+=1;
		 leadmuonpt1[i]+=1;
	       }
	     }
	   }
       
	   if (Muon_pt[1]<pt_cut){
	     for (int i=0;i<bin_size_sl;i++){
	       if (Muon_pt[1]>i*bin_width && Muon_pt[1]<=(i+1)*bin_width){
		 subleadmuonpt[i]+=1;
		 subleadmuonpt1[i]+=1;
	       }
	     }
	   }
	 }
	 if (((fabs(Muon_eta[0]) > 1.6) && (fabs(Muon_eta[0]) < 2.2)) && (fabs(Muon_eta[1]) < 1.6)){
	   h1->Fill(Muon_pt[0],Muon_pt[1]);
	   h12->Fill(Muon_pt[0],Muon_pt[1]);
	   hLeadMuon2->Fill(Muon_pt[0]);
	   hSubLeadMuon2->Fill(Muon_pt[1]);
	   if (Muon_pt[0]<pt_cut){
	     for (int i=0;i<bin_size_l;i++){
	       if (Muon_pt[0]>=i*bin_width && Muon_pt[0]<(i+1)*bin_width){
		 leadmuonpt[i]+=1;
		 leadmuonpt2[i]+=1;
	       }
	     }
	   }
       
	   if (Muon_pt[1]<pt_cut){
	     for (int i=0;i<bin_size_sl;i++){
	       if (Muon_pt[1]>i*bin_width && Muon_pt[1]<=(i+1)*bin_width){
		 subleadmuonpt[i]+=1;
		 subleadmuonpt2[i]+=1;
	       }
	     }
	   }
	 }
	 if ((fabs(Muon_eta[0]) < 1.6) && ((fabs(Muon_eta[1]) > 1.6) && (fabs(Muon_eta[1]) < 2.2))){
	   h1->Fill(Muon_pt[0],Muon_pt[1]);
	   h13->Fill(Muon_pt[0],Muon_pt[1]);
	   hLeadMuon3->Fill(Muon_pt[0]);
           hSubLeadMuon3->Fill(Muon_pt[1]);
	   if (Muon_pt[0]<pt_cut){
	     for (int i=0;i<bin_size_l;i++){
	       if (Muon_pt[0]>=i*bin_width && Muon_pt[0]<(i+1)*bin_width){
		 leadmuonpt[i]+=1;
		 leadmuonpt3[i]+=1;
	       }
	     }
	   }
       
	   if (Muon_pt[1]<pt_cut){
	     for (int i=0;i<bin_size_sl;i++){
	       if (Muon_pt[1]>i*bin_width && Muon_pt[1]<=(i+1)*bin_width){
		 subleadmuonpt[i]+=1;
		 subleadmuonpt3[i]+=1;
	       }
	     }
	   }
	 }
     } 
       else{
	 if (((fabs(Muon_eta[1]) > 1.6) && (fabs(Muon_eta[1]) < 2.2)) && ((fabs(Muon_eta[0]) > 1.6) && (fabs(Muon_eta[0]) < 2.2))){
	   hLeadMuon1->Fill(Muon_pt[1]);
	   hSubLeadMuon1->Fill(Muon_pt[0]);
	 }
	 if (((fabs(Muon_eta[1]) > 1.6) && (fabs(Muon_eta[1]) < 2.2)) && (fabs(Muon_eta[0]) < 1.6)){
	   hLeadMuon2->Fill(Muon_pt[1]);
	   hSubLeadMuon2->Fill(Muon_pt[0]);
	 }
	 if ((fabs(Muon_eta[1]) < 1.6) && ((fabs(Muon_eta[0]) > 1.6) && (fabs(Muon_eta[0]) < 2.2))){
	   hLeadMuon3->Fill(Muon_pt[1]);
           hSubLeadMuon3->Fill(Muon_pt[0]);
	 }
      
       }
     for (int i=0;i<nMuon; i++){
       RecoMuonPt=Muon_pt[i];
       RecoMuonEta=Muon_eta[i];
       GenMuonPt=Muon_ptgen[i];
       ImpParam=Muon_trkD0[i];
       MuonDZ=Muon_trkDz[i];
       MuonChi2=Muon_globalChi2[i];
     
       if ((fabs(RecoMuonEta) > 1.5) && (fabs(RecoMuonEta) < 2.2)){
	 hMCMatchEC->Fill((GenMuonPt-RecoMuonPt)/GenMuonPt);
	 hImPEC->Fill(ImpParam);
	 hDZEC->Fill(MuonDZ);
	 hChiEC->Fill(MuonChi2);
	 hEtaPtEC->Fill(RecoMuonEta,RecoMuonPt);
	 //hEtaResEC->Fill(RecoMuonPt-GenMuonPt,RecoMuonEta);
       }
       if ((fabs(Muon_eta[i]) < 1.6)){
	 hMCMatchBa->Fill((GenMuonPt-RecoMuonPt)/GenMuonPt);
	 hImPBa->Fill(ImpParam);
	 hDZBa->Fill(MuonDZ);
	 hChiBa->Fill(MuonChi2);
	 hEtaPtBa->Fill(RecoMuonEta,RecoMuonPt);
       }
       h1PtGen->Fill(GenMuonPt);
       h1PtReco->Fill(RecoMuonPt);
       h1EtaReco->Fill(RecoMuonEta);
       hEtaPtAll->Fill(RecoMuonEta,RecoMuonPt);
       if (RecoMuonPt>10.)hEtaPt10->Fill(RecoMuonEta);  
       if (RecoMuonPt>15.)hEtaPt15->Fill(RecoMuonEta);  
       if (RecoMuonPt>20.)hEtaPt20->Fill(RecoMuonEta);
       if (RecoMuonPt>25.)hEtaPt25->Fill(RecoMuonEta);         
       if (RecoMuonPt>30.)hEtaPt30->Fill(RecoMuonEta);
       if (RecoMuonPt>35.)hEtaPt35->Fill(RecoMuonEta);  
       //if ()
     }
    
   }
   cout<<"Number of dimuon events "<<dimuon<<" BR of di tau to dimuon "<<((float)dimuon/(float)nentries)*100<<endl;
   
   //Overall
   /*
   total_events=0;
   events=0;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       if(leadmuonpt[i]!=0 && subleadmuonpt[j]!=0)total_events+=leadmuonpt[i]*subleadmuonpt[j];
     }
   }
   cout<<total_events<<endl;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       events=0;
       for (int k=i;k<bin_size_l;k++){
	 for (int l=j;l<k;l++){
	   if(leadmuonpt[k]!=0 && subleadmuonpt[l]!=0)events+=leadmuonpt[k]*subleadmuonpt[l];
	 }
       }
       hAcceptAll->Fill(i*bin_width,j*bin_width,(Double_t)events/(Double_t)total_events);
     }
   }
   

   //Case-1
   
   total_events=0;
   events=0;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       if(leadmuonpt1[i]!=0 && subleadmuonpt1[j]!=0)total_events+=leadmuonpt1[i]*subleadmuonpt1[j];
     }
   }
   cout<<total_events<<endl;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       events=0;
       for (int k=i;k<bin_size_l;k++){
	 for (int l=j;l<k;l++){
	   if(leadmuonpt1[k]!=0 && subleadmuonpt1[l]!=0)events+=leadmuonpt1[k]*subleadmuonpt1[l];
	 }
       }
       hAccept1->Fill(i*bin_width,j*bin_width,(Double_t)events/(Double_t)total_events);
     }
   }
   
   //Case-2
   total_events=0;
   events=0;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       if(leadmuonpt2[i]!=0 && subleadmuonpt2[j]!=0)total_events+=leadmuonpt2[i]*subleadmuonpt2[j];
     }
   }
   cout<<total_events<<endl;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       events=0;
       for (int k=i;k<bin_size_l;k++){
	 for (int l=j;l<k;l++){
	   if(leadmuonpt2[k]!=0 && subleadmuonpt2[l]!=0)events+=leadmuonpt2[k]*subleadmuonpt2[l];
	 }
       }
       hAccept2->Fill(i*bin_width,j*bin_width,(Double_t)events/(Double_t)total_events);
     }
   }

   //Case-3

   total_events=0;
   events=0;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       if(leadmuonpt3[i]!=0 && subleadmuonpt3[j]!=0)total_events+=leadmuonpt3[i]*subleadmuonpt3[j];
     }
   }
   cout<<total_events<<endl;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       events=0;
       for (int k=i;k<bin_size_l;k++){
	 for (int l=j;l<k;l++){
	   if(leadmuonpt3[k]!=0 && subleadmuonpt3[l]!=0)events+=leadmuonpt3[k]*subleadmuonpt3[l];
	 }
       }
       //myfile2<<i<<" "<<j<<" "<<" "<<events<<" "<<total_events<<" "<<(Double_t)events/(Double_t)total_events<<endl;
       //myfile2<<i*bin_width<<" "<<j*bin_width<<" "<<(Double_t)events/(Double_t)total_events<<endl;
       hAccept3->Fill(i*bin_width,j*bin_width,(Double_t)events/(Double_t)total_events);
       //hAccept1->Fill(i*bin_width,j*bin_width);
     }
   }
   hAcceptAll->Write();
   
   //Time to beautify most of the plots
   hLeadMuon1->SetLineColor(1);
   hSubLeadMuon1->SetLineColor(4);
   hLeadMuon1->SetXTitle("Reco. Muon p_{T} in GeV/c");
   hSubLeadMuon1->SetXTitle("Reco. Muon p_{T} in GeV/c");
   hLeadMuon1->SetYTitle("Number of Events/GeV");
   hSubLeadMuon1->SetYTitle("Number of Events/GeV");
   hSubLeadMuon1->Draw();
   gPad->Update();
   hLeadMuon1->Draw();          //draw hist_2 first as it has a larger range
   gPad->Update();


   TPaveStats *tps1 = (TPaveStats*) hLeadMuon1->FindObject("stats");
   tps1->SetName("Hist1 Stats");
   double X1 = tps1->GetX1NDC();
   double Y1 = tps1->GetY1NDC();
   double X2 = tps1->GetX2NDC();
   double Y2 = tps1->GetY2NDC();
  
   TPaveStats *tps2 = (TPaveStats*) hSubLeadMuon1->FindObject("stats");
   tps2->SetTextColor(kRed);
   tps2->SetLineColor(kRed);
   tps2->SetX1NDC(X1);
   tps2->SetX2NDC(X2);
   tps2->SetY1NDC(Y1-(Y2-Y1));
   tps2->SetY2NDC(Y1);
   
  
  
   hSubLeadMuon1->Draw();
   hLeadMuon1->Draw("same");          //draw hist_2 first as it has a larger range
   tps2->Draw("same");
   tps1->Draw("same");
   
   leg_hist = new TLegend(0.4712644,0.5886076,0.7600575,0.778481,NULL,"brNDC");
   leg_hist->SetHeader("p_{T} histograms for case 1");
   leg_hist->SetFillColor(0);
   leg_hist->AddEntry(hLeadMuon1,"leading muon p_{T}","l");
   leg_hist->AddEntry(hSubLeadMuon1,"subleading muon p_{T}","l");
   leg_hist->SetTextSize(0.03);
   leg_hist->Draw();
  
   c1->SaveAs("case1.pdf");
   c1->Clear();
   

   hLeadMuon2->SetLineColor(1);
   hSubLeadMuon2->SetLineColor(4);
   hLeadMuon2->SetXTitle("Reco Muon p_{T} in GeV/c");
   hSubLeadMuon2->SetXTitle("Reco Muon p_{T} in GeV/c");
   hLeadMuon2->SetYTitle("Number of Events/GeV");
   hSubLeadMuon2->SetYTitle("Number of Events/GeV");
   hSubLeadMuon2->Draw();
   gPad->Update();
   hLeadMuon2->Draw();
   gPad->Update();
   //draw hist_2 first as it has a larger range
   TPaveStats *tps1 = (TPaveStats*) hLeadMuon2->FindObject("stats");
   tps1->SetName("Hist1 Stats");
   double X1 = tps1->GetX1NDC();
   double Y1 = tps1->GetY1NDC();
   double X2 = tps1->GetX2NDC();
   double Y2 = tps1->GetY2NDC();
   
   TPaveStats *tps2 = (TPaveStats*) hSubLeadMuon2->FindObject("stats");
   tps2->SetTextColor(kRed);
   tps2->SetLineColor(kRed);
   tps2->SetX1NDC(X1);
   tps2->SetX2NDC(X2);
   tps2->SetY1NDC(Y1-(Y2-Y1));
   tps2->SetY2NDC(Y1);
   
  
  
   hSubLeadMuon2->Draw();
   hLeadMuon2->Draw("same");          //draw hist_2 first as it has a larger range
   tps2->Draw("same");
   tps1->Draw("same");
   
   leg_hist = new TLegend(0.4712644,0.5886076,0.7600575,0.778481,NULL,"brNDC");
   leg_hist->SetHeader("p_{T} histograms for case 2");
   leg_hist->SetFillColor(0);
   leg_hist->AddEntry(hLeadMuon2,"leading muon p_{T}","l");
   leg_hist->AddEntry(hSubLeadMuon2,"subleading muon p_{T}","l");
   leg_hist->SetTextSize(0.03);
   leg_hist->Draw();
   
   c1->SaveAs("case2.pdf");
  
   
   hLeadMuon3->SetLineColor(1);
   hSubLeadMuon3->SetLineColor(4);
   hLeadMuon3->SetXTitle("Reco Muon p_{T} in GeV/c");
   hSubLeadMuon3->SetXTitle("Reco Muon p_{T} in GeV/c");
   hLeadMuon3->SetYTitle("Number of Events/GeV");
   hSubLeadMuon3->SetYTitle("Number of Events/GeV");
   hSubLeadMuon3->Draw();
   gPad->Update();
   hLeadMuon3->Draw();          //draw hist_2 first as it has a larger range
   gPad->Update();
   
   TPaveStats *tps1 = (TPaveStats*) hLeadMuon3->FindObject("stats");
   tps1->SetName("Hist1 Stats");
   double X1 = tps1->GetX1NDC();
   double Y1 = tps1->GetY1NDC();
   double X2 = tps1->GetX2NDC();
   double Y2 = tps1->GetY2NDC();
   
   TPaveStats *tps2 = (TPaveStats*) hSubLeadMuon3->FindObject("stats");
   tps2->SetTextColor(kRed);
   tps2->SetLineColor(kRed);
   tps2->SetX1NDC(X1);
   tps2->SetX2NDC(X2);
   tps2->SetY1NDC(Y1-(Y2-Y1));
   tps2->SetY2NDC(Y1);
   
   
   
   hSubLeadMuon3->Draw();
   hLeadMuon3->Draw("same");          //draw hist_2 first as it has a larger range
   tps2->Draw("same");
   tps1->Draw("same");
   
   
   leg_hist = new TLegend(0.4712644,0.5886076,0.7600575,0.778481,NULL,"brNDC");
   leg_hist->SetHeader("p_{T} histograms for case 3");
   leg_hist->SetFillColor(0);
   leg_hist->AddEntry(hLeadMuon3,"leading muon p_{T}","l");
   leg_hist->AddEntry(hSubLeadMuon3,"subleading muon p_{T}","l");
   leg_hist->SetTextSize(0.03);
   leg_hist->Draw();
   
   c1->SaveAs("case3.pdf");
   c1->Clear();
   
   //pT resolution plots

   hMCMatchEC->SetLineColor(1);
   
   hMCMatchEC->SetXTitle("p_{T}^{gen}-p_{T}^{reco}/p_{T}^{gen}");
   hMCMatchEC->Draw();          //draw hist_2 first as it has a larger range
   hMCMatchEC->Draw("esame");          //draw hist_2 first as it has a larger range
   c1->SaveAs("plot_res_1.pdf");
   c1->Clear();

   hMCMatchBa->SetLineColor(1);
   
   hMCMatchBa->SetXTitle("p_{T}^{gen}-p_{T}^{reco}/p_{T}^{gen}");
   hMCMatchBa->Draw();          //draw hist_2 first as it has a larger range
   hMCMatchBa->Draw("esame");          //draw hist_2 first as it has a larger range
   c1->SaveAs("plot_res_2.pdf");
   c1->Clear();

   //Acceptance plots
   
   //Overall Acceptance
   
   hAcceptAll->SetXTitle("Reco. leading muon p_{T} in GeV/c");
   hAcceptAll->SetYTitle("Reco. subleading muon p_{T} in GeV/c");
  //hAcceptAll->SetZTitle("Kinematic acceptance");
   hAcceptAll->SetStats(0);
   hAcceptAll->Draw("cont3 colz");
   //HLT_PATH Mu17_Mu8
   
   Int_t a=hAcceptAll->GetXaxis()->FindBin(17);
   Int_t b = hAcceptAll->GetYaxis()->FindBin(8);
   Double_t c = hAcceptAll->GetBinContent(a,b);
   //Double_t a = hAcceptAll->GetBinContent(hAcceptAll->GetXaxis()->FindBin(17),hAcceptAll->GetYaxis()->FindBin(8)));
   //HLT_PATH Mu13_Mu8
   //Double_t f=hAcceptAll->GetBinContent(
   Int_t d = hAcceptAll->GetXaxis()->FindBin(13);
   Int_t e = hAcceptAll->GetYaxis()->FindBin(8);
   Double_t f = hAcceptAll->GetBinContent(d,e);
  //Offline Cuts
  
   Int_t g=hAcceptAll->GetXaxis()->FindBin(20);
   Int_t h=hAcceptAll->GetYaxis()->FindBin(10);
   Double_t z=hAcceptAll->GetBinContent(g,h);
  //Double_t i=GetBinContenthAcceptAll->GetXaxis()->FindBin(20),hAcceptAll->GetYaxis()->FindBin(10));

   cout<<c<<" "<<f<<" "<<z<<endl;
  
  //Double_t m=hAcceptAll->GetBinContent(k,l);
  //draw hist_2 first as it has a larger range
  
   TLatex latex;
  //latex.DrawLatex(17,8,TString::Format("#bullet %f ",a));
  //latex.DrawLatex(17,8,TString::Format("#bullet %2f %",c*100));
   latex.DrawLatex(17,8,"#bullet 64%");
   latex.DrawLatex(13,8,"#diamond 72%");
   latex.DrawLatex(20,10,"#color[2]{#bullet} 43%");
  //latex.DrawLatex(17,8,TString::Format("%f",c));
  //latex.DrawLatex(17,8,TString::Format("%f",c));
  //latex.DrawLatex(13,8,TString::Format("#diamond %f ",f));
  
  //latex.DrawLatex(20,10,TString::Format("#circ %f ",i));
  
   latex.DrawLatex(3,22,"#bullet");
   latex.DrawLatex(2.83,25,"#diamond");
  
  
  
   latex.DrawLatex(4,28,"#scale[0.8]{HLT Paths(Run-1)}");
   latex.DrawLatex(4,22,"#scale[0.8]{Mu17_Mu8 (Luminosity 19.1 fb^{-1})}");
   latex.DrawLatex(4,25,"#scale[0.8]{Mu13_Mu8 (Luminosity 3.7 fb^{-1})}");
  
   latex.DrawLatex(4,19,"#scale[0.8]{Offline selection}");
   latex.DrawLatex(3,16,"#color[2]{#bullet}");
   latex.DrawLatex(4,16,"#scale[0.8]{Mu20_Mu10}");
   c1->SaveAs("acceptance_2d_all_cont3.pdf");
  
   //Case-1
   */
}
예제 #15
0
void FlightControlCenter::start(string file, double speed)
{

	string line;
	ifstream myfile(file);
	Clock::speedOfSimClock = speed;

	if (myfile)
	{
		getline(myfile, line);
		cityParser->InitCityData((char*)line.c_str()); //initiate city parser with file on 1st line 

		getline(myfile, line);
		fltParser->InitFlightData((char*)line.c_str()); //initiate flight parser with file on 2nd line 
	};

	cityParser->getCitySymbolsArray(&FlightControlCenter::symbols); //get city symbols array from City Parser
	cityParser->getDistTable(&FlightControlCenter::distances);	//get city Distance Table array from City Parser
	FlightControlCenter::numofCities = cityParser->getCityCount(); // get number of cities for calculating distances

	fltParser->getStartTime(&Clock::curr_hour, &Clock::curr_min); //get start time
	buildManifest(); //get info on all flights
	buildAirplanesList(); // builds airplane list
	buildCitiesList(); //builds cities list 
	buildFlightsList(); // builds flight list

	

	//print sim start time
	cout << "*** Starting simulation at "<< setfill('0') << setw(2) << Clock::curr_hour << ":" << setfill('0') << setw(2)
			<< Clock::curr_min << " ***" << endl << endl;

	
	//timer loop
	_ftime(&Clock::tStruct);	// Get start time
	Clock::startOfSimClock = Clock::tStruct.time + (((double)(Clock::tStruct.millitm)) / 1000.0); // Convert to double
	Clock::thisTime = Clock::tStruct.time + (((double)(Clock::tStruct.millitm)) / 1000.0); // Convert to double
	Clock::outputTime = Clock::thisTime + (5.0/Clock::speedOfSimClock); // Set next (5 second/ simulator speed) interval time

	while (!done)     // Start an eternal loop
	{
		_ftime(&Clock::tStruct);    // Get the current time
		Clock::thisTime = Clock::tStruct.time + (((double)(Clock::tStruct.millitm)) / 1000.0); // Convert to double

		// Check for 5 second interval to print status to screen
		if (Clock::thisTime >= Clock::outputTime)
		{

			 
			Clock::curr_min += 5 * Clock::speedOfSimClock;

			//keeps up with hours and minutes for display
			if (Clock::curr_min > 59)
			{
				++Clock::curr_hour;
				Clock::curr_min %= 60;
				Clock::startOfSimClock = Clock::thisTime;
			}
			else if (Clock::curr_hour > 12)
				Clock::curr_hour = 1;

			// Call functions to perform actions at 5 second intervals
			double t = Clock::curr_hour + ((double)Clock::curr_min / 60);
			Notify(t, Clock::curr_hour, Clock::curr_min);
			report();

			Clock::outputTime = Clock::thisTime + (5.0/Clock::speedOfSimClock); // Set next (5 second/ simulator speed) interval time

		}
		// Do other stuff here
		if ((Clock::curr_hour == SIM_END_HOUR) && (Clock::curr_min == SIM_END_MINUTE))
				done = true;

	}

}
void ObservationTable::saveToLaTeX(const string fileName, const string prefix, const int step)
{
    string fullFileName = fileName + prefix + "_ObservationTable_Step" + to_string(step) + ".tex";
    ofstream myfile(fullFileName); bool hasKK = false;
    if (!myfile.is_open()) {
        string message = "File '" + fullFileName + "' could not be opened";
        throw exception(message.c_str());
    }

    // Header
    myfile
    //    << "\\begin{table}[!htb]" << endl
        << "\\begin{tabularx}{\\textwidth}{|X|";
    for (Context f : this->F) {
        myfile << "c|";
    }
    myfile << "}" << endl
        << "    \\hline" << endl
        << "    K\\textbackslash F";
    for (Context f : this->F) {
        myfile << " & (" << this->getLaTeXString(f.first) << ", "
            << this->getLaTeXString(f.second) << ")";
    }
    myfile << " \\\\ \\hline" << endl;

    // Main
    for (string u : this->K) { // Output K
        myfile << "    " << this->getLaTeXString(u);
        for (Context f : this->F) {
            myfile << " & " << this->getLaTeXString(this->_table[u][f]);
        }
        myfile << "\\\\";
    }
    myfile << " \\hline" << endl;
    for (string u : this->_KK) { // Output KK / K
        if (this->K.find(u) != this->K.end()) { // Found in K
            continue;
        }
        hasKK = true;
        myfile << "    " << this->getLaTeXString(u);
        for (Context f : this->F) {
            myfile << " & " << this->getLaTeXString(this->_table[u][f]);
        }
        myfile << "\\\\";
    }
    if (hasKK) {
        myfile << " \\hline" << endl;
    }

    // Footer
    myfile << endl
        << "\\end{tabularx}" << endl
        << "\\caption{Step " << step << "}" << endl
        << "\\label{table:ObservationTable" << prefix << "_step" << step << "}" << endl
    //    << endl
    //    << "\\caption{" << prefix << " Step " << step << "}" << endl
    //    << "\\label{table:" << prefix << "_step" << this->getLaTeXString(step) << "}" << endl
    //    << "\\end{table}" << endl
    ;

    myfile.close();

}