示例#1
0
bool CBanknodeDB::Write(const CBanknodeMan& mnodemanToSave)
{
    int64_t nStart = GetTimeMillis();

    // serialize, checksum data up to that point, then append checksum
    CDataStream ssBanknodes(SER_DISK, CLIENT_VERSION);
    ssBanknodes << strMagicMessage; // banknode cache file specific magic message
    ssBanknodes << FLATDATA(Params().MessageStart()); // network specific magic number
    ssBanknodes << mnodemanToSave;
    uint256 hash = Hash(ssBanknodes.begin(), ssBanknodes.end());
    ssBanknodes << hash;

    // open output file, and associate with CAutoFile
    FILE *file = fopen(pathMN.string().c_str(), "wb");
    CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
    if (fileout.IsNull())
        return error("%s : Failed to open file %s", __func__, pathMN.string());

    // Write and commit header, data
    try {
        fileout << ssBanknodes;
    }
    catch (std::exception &e) {
        return error("%s : Serialize or I/O error - %s", __func__, e.what());
    }
    FileCommit(fileout.Get());
    fileout.fclose();

    if(fDebug)LogPrintf("Written info to nodecache.dat  %dms\n", GetTimeMillis() - nStart);
    if(fDebug)LogPrintf("  %s\n", mnodemanToSave.ToString());

    return true;
}
示例#2
0
//
// Sign a CAlert and serialize it
//
bool SignAndSave(CAlert &alert)
{
    // Sign
    if(!alert.Sign())
    {
        printf("SignAndSave() : could not sign alert:\n%s", alert.ToString().c_str());
        return false;
    }

    std::string strFilePath = "src/test/data/alertTests.raw";
    // open output file and associate it with CAutoFile
    FILE *file = fopen(strFilePath.c_str(), "ab+");
    CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
    if (fileout.IsNull())
        return error("%s: Failed to open file %s", __func__, strFilePath);

    try {
        fileout << alert;
    }
    catch (std::exception &e) {
        return error("%s: Serialize or I/O error - %s", __func__, e.what());
    }
    fileout.fclose();
    return true;
}
示例#3
0
bool CMasternodePaymentDB::Write(const CMasternodePayments& objToSave)
{
    int64_t nStart = GetTimeMillis();

    // serialize, checksum data up to that point, then append checksum
    CDataStream ssObj(SER_DISK, CLIENT_VERSION);
    ssObj << strMagicMessage; // masternode cache file specific magic message
    ssObj << FLATDATA(Params().MessageStart()); // network specific magic number
    ssObj << objToSave;
    uint256 hash = Hash(ssObj.begin(), ssObj.end());
    ssObj << hash;

    // open output file, and associate with CAutoFile
    FILE *file = fopen(pathDB.string().c_str(), "wb");
    CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
    if (fileout.IsNull())
        return error("%s : Failed to open file %s", __func__, pathDB.string());

    // Write and commit header, data
    try {
        fileout << ssObj;
    }
    catch (std::exception &e) {
        return error("%s : Serialize or I/O error - %s", __func__, e.what());
    }
    fileout.fclose();

    LogPrintf("Written info to mnpayments.dat  %dms\n", GetTimeMillis() - nStart);

    return true;
}
示例#4
0
void insertDriftVelocity(char* unixTime = 0, Bool_t write = kFALSE)
{
  // DB-specific libs
  gSystem->Load("libStDb_Tables.so");
  gSystem->Load("StDbLib");
  gSystem->Load("StDbBroker"); 
      
  ifstream file("driftVeloc_01_23_04.txt");
  ofstream fileout("outTest.txt");

  float veloc, time, sum;
  int index, i=0;
  // define IDs
  int* rowIDs=new int[NUMBER_OF_HYBRIDS];
  // define new table to be stored
  svtDriftVelAvg_st *driftVelocity = new svtDriftVelAvg_st[NUMBER_OF_HYBRIDS];    

  while (kTRUE) {

    // read drift velocity file
    file >> index >> veloc >> time;

    if (file.eof()) break;

    fileout  << index << "  " <<  veloc << "  " <<  time << endl;
 
    if ((veloc > MEAN_VELOC*1.50) || (veloc < MEAN_VELOC*0.50)) {
      cout << "Bad drift velocity : " << veloc << endl;
      veloc = MEAN_VELOC;
    }
    else {
      sum += veloc;
      i++;
    }
    rowIDs[index]=index;
    driftVelocity[index].averageDriftVelocity = veloc;
   
  }

  /*
  for (int i=0;i<432;i++) {
    rowIDs[i]=i;
    driftVelocity[i].averageDriftVelocity = 675000;
  }
  */

  cout << "Mean drift velocity : " << sum/i << endl;

  if (write) {
    StDbManager* mgr=StDbManager::Instance();
    StDbConfigNode* svtCalibNode = mgr->initConfig(dbCalibrations,dbSvt);           StDbTable* svtCalibTable = svtCalibNode->addDbTable("svtDriftVelAvg");    
    svtCalibTable->SetTable((char*)driftVelocity,NUMBER_OF_HYBRIDS,rowIDs);
    mgr->setStoreTime(unixTime);
    cout<<" Will attempt store with timestamp="<<mgr->getDateStoreTime()<<endl;    mgr->storeDbTable(svtCalibTable);
    delete [] driftVelocity;
  }

}
   void dump()
   {
     std::ofstream fileout("matrix_dump.rh");
      (*A).Print (fileout);
      for (int i=0; i < NumMyElements; ++i)
	fileout << "RHS(" << i << "): " << (*b)[i] << std::endl;
      for (int i=0; i < NumMyElements; ++i)
	fileout << "RHS(" << i << "): " << (*x)[i] << std::endl;
      fileout.close();
   }
示例#6
0
void merge( const QString& newname, const QString& oldname,
	    const QString& resname )
{
    QFile f1(newname);
    if ( !f1.open( IO_ReadOnly) )
	return;

    QFile f2(oldname);
    if ( !f2.open( IO_ReadOnly) )
	return;

    QBuffer fout;
    fout.open(IO_WriteOnly);

    QTextStream in1( &f1 );
    QTextStream in2( &f2 );
    QTextStream out( &fout );

    QString buf1 = in1.readLine().stripWhiteSpace();
    QString buf2 = in2.readLine().stripWhiteSpace();

    Item i1 = getItem( in1, buf1 );
    Item i2 = getItem( in2, buf2 );
    while ( !i1.isNull() || !i2.isNull() ) {
	Status s = compare( i1, i2 );
	if ( s == Equal ) {
	    writemerge(out,i1,i2);
	    i1 = getItem( in1, buf1 );
	    i2 = getItem( in2, buf2 );
	} else if ( s == First ) {
	    writenew( out, i1 );
	    i1 = getItem( in1, buf1 );
	} else if ( s == FirstJunk ) {
	    //solitary comment
	    writejunk( out, i1 );
	    i1 = getItem( in1, buf1 );
	} else if ( s == Second ) {
	    writeold( out, i2 );
	    i2 = getItem( in2, buf2 );
	} else if ( s == SecondJunk ) {
	    //solitary comment
	    writejunk( out, i2 );
	    i2 = getItem( in2, buf2 );
	}
    }

    f1.close();
    f2.close();
    fout.close();
    QFile fileout(resname);
    if ( !fileout.open( IO_WriteOnly | IO_Translate ) )
	return;
    fileout.writeBlock(fout.buffer());
    fileout.close();
}
示例#7
0
bool MODEL::WriteToFile(const std::string & filepath)
{
	const std::string magic = "OGLVARRAYV01";
	std::ofstream fileout(filepath.c_str());
	if (!fileout)
		return false;
	
	fileout.write(magic.c_str(), magic.size());
	joeserialize::BinaryOutputSerializer s(fileout);
	return Serialize(s);
}
示例#8
0
int VSPTree::writeText(QString filePath,QString string){
	QFile fileout(filePath);
	if (!fileout.open(QIODevice::WriteOnly | QIODevice::Text)){
		Log("Error Cannot Open : " + fileout.fileName());
		return 1;
	}
	QTextStream out(&fileout);
	//out.setCodec("UTF-8");
	out << string;
	fileout.close();
	return 0;
}
void LocalDescriptorAndBagOfFeature::save_classifier(std::string filename, const std::vector<std::vector<double>> &category_centroids, const std::vector<std::string> &category_labels){
    std::ofstream fileout (filename);
    fileout << category_centroids.size() << std::endl;
    for(int i = 0; i < category_centroids.size(); i++){
        fileout << category_labels[i] << std::endl;
        for(const double& d : category_centroids[i]){
            fileout << d << " ";
        }
        fileout << std::endl;
    }
    fileout.close();
}
示例#10
0
bool CInfiniteMediatorTest::filesEqual(std::string fname0, std::string fname1)
{
  std::ifstream filein(fname0.c_str());
  std::ifstream fileout(fname1.c_str());

  std::istream_iterator<char> end_of_stream;
  std::istream_iterator<char> in_iter(filein);
  std::istream_iterator<char> out_iter(fileout);

  return std::equal(in_iter,end_of_stream,out_iter);

}
示例#11
0
void CMagicCube3DView::OnSave()
{
	CFileDialog fileDlg(false,NULL,NULL,4|2,"MagicCube Layout Files(*.ml)|*.ml||");
	if (fileDlg.DoModal()==IDOK){
		CString filename=fileDlg.GetPathName();
		CString ext=fileDlg.GetFileExt();
		if (ext!="ml"){
			filename.Append(".ml");
		}
		CFile fileout(filename.GetBuffer(),CFile::modeCreate|CFile::modeWrite);
		fileout.Write(((CMagicCube3DApp*)AfxGetApp())->openGL.magicCube.getColorsPtr(),sizeof(Color)*6*9);
		fileout.Close();
	}
}
示例#12
0
void client_impl::debug_write_errors_to_file( const string& path, const fc::time_point& start_time )const
{
   map<fc::time_point, fc::exception> result;
   auto itr = _exception_db.lower_bound( start_time );
   while( itr.valid() )
   {
      result[itr.key()] = itr.value();
      ++itr;
   }
   if (path != "")
   {
      std::ofstream fileout( path.c_str() );
      fileout << fc::json::to_pretty_string( result );
   }
}
void cthd_cpu_default_binding::update_zone_stat(std::string zone_name,
        int fail_cnt) {
    std::ifstream filein;
    std::streampos current = 0;
    cpu_zone_stat_t obj;
    bool found = false;

    std::stringstream filename;
    filename << TDRUNDIR << "/" << "cpu_def_zone_bind.out";

    filein.open(filename.str().c_str(), std::ios::in | std::ios::binary);
    if (filein.is_open()) {
        while (!filein.eof()) {
            current = filein.tellg();
            filein.read((char *) &obj, sizeof(obj));
            if (filein && zone_name == obj.zone_name) {
                found = true;
                break;
            }
        }
    }
    filein.close();

    std::fstream fileout(filename.str().c_str(),
                         std::ios::out | std::ios::in | std::ios::binary);

    if (!fileout.is_open()) {
        std::ofstream file;
        file.open(filename.str().c_str());
        if (file.is_open()) {
            file.close();
            fileout.open(filename.str().c_str(),
                         std::ios::in | std::ios::out | std::ios::binary);
        } else {
            thd_log_info("Can't create cpu_def_zone_bind.out\n");
        }
    }

    if (found) {
        fileout.seekp(current);
    } else
        fileout.seekp(0, std::ios::end);

    strncpy(obj.zone_name, zone_name.c_str(), 50);
    obj.failures = fail_cnt;
    fileout.write((char *) &obj, sizeof(obj));
    fileout.close();
}
示例#14
0
int main(void) {
    std::vector<std::string> c;
    std::ifstream filein("test.txt");
    std::ofstream fileout("out.txt");
    if(!filein||!fileout) throw std::runtime_error("IO error!");
    std::string s;
    while( filein>>s) {
        c.push_back(s);
    }
    filein.close(); filein.clear();
    for(std::vector<std::string>::iterator i=c.begin(); i!=c.end(); ++i) {
        fileout<<*i<<std::endl;
    }
    fileout.close(); fileout.clear();
    return 0;
}
示例#15
0
void get_control_points()
{
	fileout.close();
	int num = 0;
	int filler [94] [2];
	ifstream fin("control_points.txt");
	assert (!fin.fail());
	bool trigger = false;
	while (num != 188)
	{
		int temp = floor(num / 2);
		fin >> filler [temp] [trigger];
		//cout << filler [temp] [trigger] << endl;
		num++;
	}
	ofstream fileout("logging.txt", ios::app);
}
示例#16
0
bool RegexSourceSink::StopRecording()
{
    QString filename=QString(dir+"/"+"timestamps.txt");
//    QString filename = "/home/sam/times.txt";
    QFile fileout(filename);
    if (fileout.open(QFile::ReadWrite | QFile::Text| QFile::Truncate)){
     QTextStream out(&fileout);
     for (QVector<double>::iterator iter = timestamps.begin(); iter != timestamps.end(); iter++){
         out << *iter<<"\n";
     }
     fileout.close();
    }



    return true;
}
示例#17
0
int main(int argc, char* argv[])
{
	CxImage image;

    if (argc<3) {
        fprintf(stderr, image.GetVersion());
        fprintf(stderr, "\nConsole demo\n");
        fprintf(stderr, "usage: %s input-file output-file\n", argv[0]);
        return 1;
    }

	CString filein(argv[1]);
	CString extin(FindExtension(filein));
	extin.MakeLower();
	int typein = FindFormat(extin);
	if (typein == CXIMAGE_FORMAT_UNKNOWN) {
        fprintf(stderr, "unknown extension for %s\n", argv[1]);
        return 1;
	}

	CString fileout(argv[2]);
	CString extout(FindExtension(fileout));
	extout.MakeLower();
	int typeout = FindFormat(extout);
	if (typeout == CXIMAGE_FORMAT_UNKNOWN) {
        fprintf(stderr, "unknown extension for %s\n", argv[2]);
        return 1;
	}


	if (!image.Load(argv[1],typein)){
        fprintf(stderr, "%s\n", image.GetLastError());
        fprintf(stderr, "error loading %s\n", argv[1]);
        return 1;
	}

	if (!image.Save(argv[2],typeout)){
        fprintf(stderr, "%s\n", image.GetLastError());
        fprintf(stderr, "error saving %s\n", argv[2]);
        return 1;
	}

	printf("Done!\n");
	return 0;
}
示例#18
0
/**-------------------------------------------------------------
 * @brief 試合の結果をファイルに書き出し。
 * @param[in]   userID_     試合を行ったユーザのID
 * @param[in]   gameResult  試合結果
 *-------------------------------------------------------------*/
void writeFile_GameResult(int userID_, const GameResult* gameResult_)
{
	// 書き出しモジュール作成
	std::ofstream fileout(dataBaseResultFileName, std::ios::app);

	// 開けなかった場合は終了
	if(fileout.fail()) {
		std::cout << dataBaseResultFileName << "cannot open." << std::endl;
		assert(0);
	}

	// 出力
	fileout << "userID = " << userID_ << std::endl;
	fileout << "GameResult = " << (*gameResult_) << std::endl;

	// ファイルを閉じる
	fileout.close();
}
示例#19
0
//#define Multi 1
int main()
{
	CStopWatch sw;
	sw.startTimer();
	std::ofstream fileout("results.txt");
	std::ifstream filein("hands.txt");
	std::string str;
	auto rowCount = 0;

#if Multi
	std::array<std::future<std::string>,MaxThreads-1> futures;
	auto count = 0;
	while (count <MaxThreads-1) {
		if (filein.eof()) break;
		std::getline(filein, str);
		rowCount++;
		//futures[count++] = std::async(ProcessThread, str);
		futures[count++] = std::async([str]{
			PokerHand pokerhand(str);
			auto result = EvaluateHand(pokerhand);
			return pokerhand.GetResult(result);
		});
		if (count == MaxThreads-1) {
			for (auto & e : futures) {
				fileout << e.get() << std::endl;
			}
			count = 0;
		}
	}
#else
	while (std::getline(filein, str))
	{
		PokerHand pokerhand(str);
		auto result = EvaluateHand(pokerhand);
		pokerhand.WriteResult(fileout, result);
		rowCount++;
	}

	#endif	fileout.close();
	filein.close();
	sw.stopTimer();
	std::cout << "Time to evaluate " << rowCount << " poker hands: " << sw.getElapsedTime() << std::endl;
	return 0;
}
示例#20
0
void ReadTheory()
{
  ifstream filein("lhc.txt");
  ofstream fileout("lhcM.txt");

  int NN1; 
  double pT[100], y1[100], y2[100], y3[100], y4[100], y5[100], y6[100];

  filein >> NN1;
  for (int i=0; i<NN1; i++) {
    filein >> pT[i] >> y1[i];
    gY1->SetPoint(i, pT[i], y1[i]);
  }

  filein >> NN1;
  for (int i=0; i<NN1; i++) {
    filein >> pT[i] >> y2[i];
    gY2->SetPoint(i, pT[i], y2[i]);
  }

  filein >> NN1;
  for (int i=0; i<NN1; i++) {
    filein >> pT[i] >> y3[i];
    gY3->SetPoint(i, pT[i], y3[i]);
  }

  filein >> NN1;
  for (int i=0; i<NN1; i++) {
    filein >> pT[i] >> y4[i];
    gY4->SetPoint(i, pT[i], y4[i]);
  }

  filein >> NN1;
  for (int i=0; i<NN1; i++) {
    filein >> pT[i] >> y5[i];
    gY5->SetPoint(i, pT[i], y5[i]);
  }

  filein >> NN1;
  for (int i=0; i<NN1; i++) {
    filein >> pT[i] >> y6[i];
    gY6->SetPoint(i, pT[i], y6[i]);
  }
}
示例#21
0
//write all data to a file
void UserList::writeDatabase()
{
    string allusers;
    
    //goes through linkedlist of users
    for (int i = 0; i < UserDatabase.getlength(); i++)
    {
        User temp = UserDatabase.get(index);
        string temp2 = temp.writeUser();
        
        allusers += temp2;
        allusers += "*";    //a delimiter to let me know where each user ends
    }
    
    //store entire data into file named below
    string outfile = "UserDatabase.txt";
    ofstream fileout(outfile.c_str());
    fileout << allusers;
    fileout.close();
}
示例#22
0
bool MainWindow::CopyLog(int i,QString dst)
{
    bool ok;

    // Check if we overwrite an existing file, and we don't have the option overwrite w/o prompting set
    QFile fileout(dst);
    if(ui->checkBox_LogOverwrite->isChecked()==false && fileout.exists())
    {
        if(QMessageBox::question(this,logTitle,QString("File %1 already exist. Are you sure you want to overwrite it?").arg(QString(dst)), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::No)
            return false;
    }
    //ok = CopyRaw(SuitableVolumeDefinitions[currentvolume].volumeLink,dst.toAscii(),filesystem.logentry[i].blockstart,filesystem.logentry[i].blockend);
    ok = CopyRaw(SuitableVolumeDefinitions[currentvolume].volumeLink,dst.toAscii(),i);
    if(!ok)
    {
        QMessageBox::critical(this,logTitle,QString("Could not save log entry %1 to %2").arg(i).arg(dst));
        return false;
    }
    return true;
}
示例#23
0
// save node info (nodeID, inlink, outlink) to file
// last line (nodeNum, total_inlink, total_outlink)
void getLinkNum(Graph graph, long &total_inlink, long &total_outlink, string fout)
{
    // output file
    ofstream fileout(fout.c_str());
    if (!fileout)
    {
        cout << "Error: can't open " << fout << endl;
        exit (-1);
    }
    
    for (int i=0; i<graph.nodeSet.size(); i++)
    {
        fileout << graph.nodeSet[i].term << "\t" << graph.nodeSet[i].inlink << "\t" << graph.nodeSet[i].outlink << endl;
        total_inlink += graph.nodeSet[i].inlink;
        total_outlink += graph.nodeSet[i].outlink;
    }
    fileout << graph.nodeSet.size() << "\t" << total_inlink << "\t" << total_outlink << endl;
    
    fileout.close();
    return;
}
示例#24
0
/* 
 * calculate depedency score
 * score = syn(A->B) / syn(B->A) (where syn>threshold, score>1)
 * input syntagmatic file {FID1, FID2, SIM}
 * output dependency score to file {FID1, FID2, Score}
 */
void SyntagCmp(string fin, string fout, double threshold, char delim)
{
    vector<string> terms;
    map< string, map<string, double> >synFrom = readSim(terms, fin, 'f', threshold, delim);
    // output file
    ofstream fileout(fout.c_str());
    if (!fileout)
    {
        cout << "Error: can't open " << fout << endl;
        exit (-1);
    }
    
    // calculate dependency score
    // write to file
    double synscore;
    map< string, map<string, double> > score;
    for (int i=0; i<terms.size(); i++)
    {
        string term1 = terms[i];
        for(auto elem: synFrom[term1])
        {
            cout << "... processing term " << term1 << endl;
            string term2 = elem.first;
            if (synFrom.find(term2) == synFrom.end())
                continue;
            if (synFrom[term2].find(term1) == synFrom[term2].end())
                continue;
            synscore = elem.second / synFrom[term2][term1];
            if (synscore>1)
            {
                score[term1][term2] = synscore;
                fileout << term1 << "\t" << term2 << "\t" << synscore << endl;
            }
        }
    }    
    fileout.close();
    return;
}
int main(int argc, char const *argv[])
{
	std::stringstream output_filename;
	output_filename << argv[1];
	output_filename << ".ineV";
	std::ofstream fileout (output_filename.str().c_str(), std::ofstream::out);

	std::ifstream filein (argv[1], std::ifstream::in);
	agn::sed_table output_table = agn::read_and_convert_sed_table(filein);

    std::cout << "Found " 
    			<< output_table.value.size()
    			<< " photon indices with "
    			;
    if (output_table.header.empty()) std::cout << "no file header.";
    else  std::cout << "a file header.";
    std::cout << "\n";

	// Write to new file
    fileout << agn::format_sed_table(output_table);

	return 0;
}
示例#26
0
bool CBanDB::Write(const banmap_t& banSet)
{
    // Generate random temporary filename
    unsigned short randv = 0;
    GetRandBytes((unsigned char*)&randv, sizeof(randv));
    std::string tmpfn = strprintf("banlist.dat.%04x", randv);

    // serialize banlist, checksum data up to that point, then append csum
    CDataStream ssBanlist(SER_DISK, CLIENT_VERSION);
    ssBanlist << FLATDATA(Params().MessageStart());
    ssBanlist << banSet;
    uint256 hash = Hash(ssBanlist.begin(), ssBanlist.end());
    ssBanlist << hash;

    // open temp output file, and associate with CAutoFile
    boost::filesystem::path pathTmp = GetDataDir() / tmpfn;
    FILE *file = fopen(pathTmp.string().c_str(), "wb");
    CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
    if (fileout.IsNull())
        return error("%s: Failed to open file %s", __func__, pathTmp.string());

    // Write and commit header, data
    try {
        fileout << ssBanlist;
    }
    catch (const std::exception& e) {
        return error("%s: Serialize or I/O error - %s", __func__, e.what());
    }
    FileCommit(fileout.Get());
    fileout.fclose();

    // replace existing banlist.dat, if any, with new banlist.dat.XXXX
    if (!RenameOver(pathTmp, pathBanlist))
        return error("%s: Rename-into-place failed", __func__);

    return true;
}
示例#27
0
void Z0AccEff(int isData = 2, int yieldInt = 1, int iSpec = 3, int Weight =1)
{
  ////////  definitions of Switches   ///////////
  //  isData = 1 for Data
  //  isData = 2 for Simulation
  
    
  // iSpec = 1  pT spectra
  // iSpec = 2  Y spectra
  // iSpec = 3  Centrality Spectra
  
  //Weight = 1 for weighted histo
  //weight = 0  for non weighted histo



  ////////////////////////////////////////////////////////////
  gStyle->SetOptStat(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0000); 

  // Fit ranges
  float mass_low, mass_high, mlow, mhigh;
  int nrebin;
  bool isLog, isFit;
  double MassZ0, WidthZ0;

  // High Mass range
  MassZ0 = 91.1876; WidthZ0 = 2.4952;
  mass_low = 60; mass_high = 120;  // Fit ranges Glb Glb
  //mass_low = 40; mass_high = 140;  // Fit ranges STA
  mlow = 0.0; mhigh = 200.0; nrebin = 80; isLog =0; isFit = 0; // draw ranges
  
  int whis = 1; // 1 for full all eta, 2 for barrel  //4 for trigger matched PAT
  
  //file one is good file

  TFile *fil1, *fil2;

  if (isData == 2) fil2 = new TFile("Z0_DataMixPt50_PatDiMuonPlots_All11Dec.root");
  //if (isData == 2) fil2 = new TFile("ReReco_DM_DiMuonPlot_All16Dec.root");
  if (isData == 2)  fil1 = new TFile("Z0HydPt50_PatDiMuonPlots_AllWOSel12Dec.root");

  // Pt bin sizes
  int Nptbin=1;
  double pt_bound[100] = {0};
  
  if(iSpec == 1) { 
    Nptbin = 3;
    pt_bound[0] = 0.0; pt_bound[1] = 6.0;
    pt_bound[2] = 12.0; pt_bound[3] = 100.0;
    
    if(isData == 2) {
      Nptbin = 25;
      // pt_bound[100] = {0.0,100.0,12.0,100.0};
      pt_bound[0] = 0;
      pt_bound[1] = 2;
      pt_bound[2] = 4;
      pt_bound[3] = 6;
      pt_bound[4] = 8;
      pt_bound[5] = 10;
      pt_bound[6] = 12;
      pt_bound[7] = 14;
      pt_bound[8] = 16;
      pt_bound[9] = 18;
      pt_bound[10] = 20;
      pt_bound[11] = 22;
      pt_bound[12] = 24;
      pt_bound[13] = 26;
      pt_bound[14] = 28;
      pt_bound[15] = 30;
      pt_bound[16] = 32;
      pt_bound[17] = 34;
      pt_bound[18] = 36;
      pt_bound[19] = 38;
      pt_bound[20] = 40;
      pt_bound[21] = 42;
      pt_bound[22] = 44;
      pt_bound[23] = 46;
      pt_bound[24] = 48;
      pt_bound[25] = 50;
    }
  }
  
  // Y bin sizes
  if(iSpec == 2) {
    Nptbin = 10;
    // pt_bound[100] = {-2.4,-1.0,-0.5,0.5,1.0,2.4}; 
    // pt_bound[100] = {-2.4,-1.0,-0.5,0.5,1.0,2.4}; 
    // pt_bound[100] = {-2.4,-2.1,-1.6,-1.1,-0.6,0,0.6,1.1,1.6,2.1,2.4}; 
    pt_bound[0] = -2.4; 
    pt_bound[1] = -2.1; 
    pt_bound[2] = -1.6; 
    pt_bound[3] = -1.1; 
    pt_bound[4] = -0.6; 
    pt_bound[5] =  0.0; 
    pt_bound[6] = 0.6; 
    pt_bound[7] = 1.1; 
    pt_bound[8] = 1.6; 
    pt_bound[9] = 2.1; 
    pt_bound[10] = 2.4; 

  }
  
  if(iSpec == 3) {
    if(isData == 2) { 
      Nptbin = 9;
      pt_bound[0] = 0.0;
      pt_bound[1] = 4.0;
      pt_bound[2] = 8.0;
      pt_bound[3] = 12.0;
      pt_bound[4] = 16.0;
      pt_bound[5] = 20.0;
      pt_bound[6] = 24.0;
      pt_bound[7] = 28.0;
      pt_bound[8] = 32.0;
      pt_bound[9] = 40.0;
    }
  }
  
  double PT[100], DelPT[100], mom_err[100];
  for (Int_t ih = 0; ih < Nptbin; ih++) {
    PT[ih] = (pt_bound[ih] + pt_bound[ih+1])/2.0;
    DelPT[ih] = pt_bound[ih+1] - pt_bound[ih];
    mom_err[ih] = DelPT[ih]/2.0;
  }
  
  float gen_pt[100], gen_ptError[100];
  float gen_ptS[100], gen_ptErrorS[100];
  
  if(isData==2){

    TH2D *genMass_1, *genMassS_1;

    if (iSpec == 1 &&  Weight==1 ) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsPtW");
    if (iSpec == 2 &&  Weight==1) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsYW");
    if (iSpec == 3 &&  Weight==1) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsCenW");
    
    if (iSpec == 1 &&  Weight==1) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsPtW");
    if (iSpec == 2 &&  Weight==1) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsYW");
    if (iSpec == 3 &&  Weight==1) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsCenW");
    
    if (iSpec == 1 &&  Weight==0) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsPt");
    if (iSpec == 2 &&  Weight==0) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsY");
    if (iSpec == 3 &&  Weight==0) genMass_1 = (TH2D*)fil1->Get("diMuonsGenInvMassVsCen");


    if (iSpec == 1 &&  Weight==0) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsPt");
    if (iSpec == 2 &&  Weight==0) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsY");
    if (iSpec == 3 &&  Weight==0) genMassS_1 = (TH2D*)fil2->Get("diMuonsGenInvMassVsCen");

    TH1D *ptaxis = (TH1D*)genMass_1->ProjectionY("ptaxis");
    
    for (Int_t ih = 0; ih < Nptbin; ih++) {
      cout<<pt_bound[ih]<<"  "<<pt_bound[ih+1]<<endl;
      int pt_bin1 = ptaxis->FindBin(pt_bound[ih]+0.0000001);
      int pt_bin2 = ptaxis->FindBin(pt_bound[ih+1]+0.0000001);
      
      cout<< pt_bin1<<"  "<< pt_bin2<<endl; 
      TH1D * genMassVsPt = (TH1D*)genMass_1->ProjectionX("genMassVsPt", pt_bin1, pt_bin2-1);
      TH1D * genMassVsPtS = (TH1D*)genMassS_1->ProjectionX("genMassVsPtS", pt_bin1, pt_bin2-1);
      
      //does not work with weight
      //gen_pt[ih] = genMassVsPt->GetEntries();
      
      double genError,genErrorS;
      gen_pt[ih] = genMassVsPt->IntegralAndError(1,8000,genError);
      gen_ptError[ih]= genError;
      
      gen_ptS[ih] = genMassVsPtS->IntegralAndError(1,8000,genErrorS);
      gen_ptErrorS[ih]= genErrorS;
      
      cout<<" gen entries : "<< gen_pt[ih]<<endl;
      cout<<"genErro "<<genError<<"  "<< gen_ptError[ih]<<endl<<endl;
    }
  }
  
  // Efficiency
  float Eff_cat_1[100]; 
  float Eff_catS_1[100]; 
  
  float errEff_cat_1[100];
  float errEff_catS_1[100];
  
  float errEff_cat_S1[100], errEff_cat_S2[100];
  float errEff_catS_S1[100], errEff_catS_S2[100];
  
  char *Xname[100] = {" ", "p_{T}^{Dimuon} (GeV/c)", "rapidity", "centrality"};
  
  double yld_cat_1[100];
  double yld_catS_1[100];
  double cyld_cat_1[100];
  double cyld_catS_1[100];
  double eyld_cat_1[100];
  double eyld_catS_1[100];
  double ceyld_cat_1[100], ceyld_catS_1[100];

  char namePt_1[500];
  char namePt_1S[500];
  //char namePt_1B[500];
  char text[100];
  
  ///// Write the spectra 
  char fspectra[500];
  sprintf(fspectra,"fileSpecta%d.root", yieldInt);
  TFile *fileSpectra = new TFile(fspectra, "recreate");

  ///////////////////////////////////////////////////////////////////////
  // Category _1 
  TLegend *lcat_1;
  lcat_1 = new TLegend(.1, .82, .50, .93);
  lcat_1->SetName("lcat_1");
  lcat_1->SetBorderSize(0);
  lcat_1->SetFillStyle(0);
  lcat_1->SetFillColor(0);
  lcat_1->SetTextSize(0.032);
  //lcat_1->AddEntry(RBWPOL," CMS Preliminary", " ");
  //lcat_1->AddEntry(RBWPOL," PbPb #sqrt{s_{NN}} = 2.76 TeV ", " ");
  
  TLegend *legend_1[100];
  for(int i=0; i<100; i++) { 
    if(isFit) legend_1[i] = new TLegend(.62, .52, .91, 0.93 );
    if(!isFit) legend_1[i] = new TLegend(.62, .68, .91, 0.93 );
    legend_1[i]->SetBorderSize(0);
    legend_1[i]->SetFillStyle(0);
    legend_1[i]->SetFillColor(0);
    legend_1[i]->SetTextSize(0.032);
  }
  
  //for no cut
  //if(whis == 1 && iSpec == 1 ) TH2D *Z0Mass_1 = (TH2D*)fil1->Get("dimu");
  //if(whis == 2 && iSpec == 1) TH2D *Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsPtBRL");
  //if(whis == 4 && iSpec == 1 ) {
    //TH2D *Z0Mass_1 = (TH2D*)fil1->Get("diMuonsPATInvMassVsPt");
    //TH2D *Z0Mass_1 = (TH2D*)fil1->Get("diMuonsPATSTAInvMassVsPt");
  //}



  TH2D *Z0Mass_1, *Z0Mass_1S;

  //with weight

  if(iSpec == 1 &&  Weight==1 ) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsPtW");
  if(iSpec == 2 &&  Weight==1) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsYW");
  if(iSpec == 3 &&  Weight==1) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsCenW");


  //without weight
  if(iSpec == 1  &&  Weight==0) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsPt");
  if(iSpec == 2 &&  Weight==0) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsY");
  if(iSpec == 3 &&  Weight==0) Z0Mass_1 = (TH2D*)fil1->Get("diMuonsGlobalInvMassVsCen");
      
  //with weight fil2
  if(iSpec == 1  &&  Weight==1) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsPtW");
  if(iSpec == 2 &&  Weight==1) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsYW");
  if(iSpec == 3 &&  Weight==1) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsCenW");

  //without weight fil2
  if(iSpec == 1 &&  Weight==0  ) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsPt");
  if(iSpec == 2 &&  Weight==0  ) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsY");
  if(iSpec == 3 &&  Weight==0  ) Z0Mass_1S = (TH2D*)fil2->Get("diMuonsGlobalInvMassVsCen");
  
  TH1D *service = (TH1D*)Z0Mass_1->ProjectionY("service");
  int pt_bin_bound[100];
  TH1D *dimuonsGlobalInvMassVsPt[100],  *dimuonsGlobalInvMassVsPtS[100];
  
  TCanvas *CanvPt_1 = new TCanvas("CanvPt_1"," Z0 Yield Vs. Pt ", 40,40,1000,700);
  if (Nptbin == 2)  CanvPt_1->Divide(2,1);
  if (Nptbin == 3 || Nptbin == 4)  CanvPt_1->Divide(2,2);
  if (Nptbin == 5 || Nptbin == 6)  CanvPt_1->Divide(3,2);
  if (Nptbin == 9 || Nptbin == 10)  CanvPt_1->Divide(5,2);
  cout << endl << Xname[iSpec] << "    Yield      Mass (GeV)    Width (GeV)    GauWidth    chi2/ndf " << endl << endl; 
  //ih loop
  for (Int_t ih = 0; ih < Nptbin; ih++) 
    {
      CanvPt_1->cd(ih+1);
      gPad->SetTickx();
      gPad->SetTicky();
      
      // Project 1 D 
      pt_bin_bound[ih] = Z0Mass_1->GetYaxis()->FindBin(pt_bound[ih]+0.0000001);
      pt_bin_bound[ih+1] = Z0Mass_1->GetYaxis()->FindBin(pt_bound[ih+1]-0.0000001);
      sprintf(namePt_1,"Z0_1_pt_%d",ih);
      sprintf(namePt_1S,"Z0_1S_pt_%d",ih);
      
      //printf(namePt_1,"Z0_1_pt_%d",ih);
      //cout<<endl<<endl;
      //continue;
      
      dimuonsGlobalInvMassVsPt[ih] = (TH1D*)Z0Mass_1->ProjectionX(namePt_1, pt_bin_bound[ih], pt_bin_bound[ih+1]-1+1, "e");
      dimuonsGlobalInvMassVsPtS[ih] = (TH1D*)Z0Mass_1S->ProjectionX(namePt_1S, pt_bin_bound[ih], pt_bin_bound[ih+1]-1+1,"e");
      if(iSpec == 1 || iSpec == 2) {sprintf(text," %s [%.1f, %.1f]", Xname[iSpec], service->GetBinLowEdge(pt_bin_bound[ih]), 
					    service->GetBinLowEdge(pt_bin_bound[ih+1])+service->GetBinWidth(pt_bin_bound[ih+1]));}
      if(iSpec == 3) {sprintf(text," %s [%.1f, %.1f] %s", Xname[iSpec], 2.5*service->GetBinLowEdge(pt_bin_bound[ih]), 
			      2.5*(service->GetBinLowEdge(pt_bin_bound[ih+1])+service->GetBinWidth(pt_bin_bound[ih+1])), "%");}
      
      dimuonsGlobalInvMassVsPt[ih]->Rebin(nrebin);
      dimuonsGlobalInvMassVsPtS[ih]->Rebin(nrebin);
      
      float m_low = 60.0;
      float m_high = 120.0;
      
      TAxis *axs   = dimuonsGlobalInvMassVsPt[ih]->GetXaxis();
      int binlow = axs->FindBin(m_low);
      int binhi  = axs->FindBin(m_high);
      //      Double_t bin_size = (1.0*dimuonsGlobalInvMassVsPt[ih]->GetNbinsX())/(axs->GetXmax() - axs->GetXmin());
      //    Float_t int_sig = 0.0;
      //for(Int_t bin = binlow; bin<=binhi;bin++) {
      //int_sig+ = dimuonsGlobalInvMassVsPt[ih]->GetBinContent(bin);
      //}   
      double recerror,recerrorS;
      //double yld;
      double yld_1 = dimuonsGlobalInvMassVsPt[ih]->IntegralAndError(binlow, binhi, recerror);
      double yldS_1 = dimuonsGlobalInvMassVsPtS[ih]->IntegralAndError(binlow, binhi, recerrorS); 
      eyld_cat_1[ih] =recerror;
      eyld_catS_1[ih] =recerrorS;
      cout<< "yld " << yld_1 <<"  eyld_cat_1[ih]  "<< eyld_cat_1[ih]<<" rec error "<<recerror<<endl;
      
      yld_cat_1[ih] = yld_1;
      yld_catS_1[ih] = yldS_1;
      
      if(isLog) gPad->SetLogy(1);
      TColor *pal = new TColor();
      Int_t kblue = pal->GetColor(9,0,200);
      //      Int_t korange  = pal->GetColor(101, 42,  0);
      
      dimuonsGlobalInvMassVsPt[ih]->SetMarkerStyle(21);
      dimuonsGlobalInvMassVsPt[ih]->SetMarkerColor(kblue);
      dimuonsGlobalInvMassVsPt[ih]->SetLineColor(kblue);
      dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetTitle("Dimuon mass (GeV/c^{2})");
      dimuonsGlobalInvMassVsPt[ih]->GetYaxis()->SetTitle("Events/(2 GeV/c^{2})");
      dimuonsGlobalInvMassVsPt[ih]->GetXaxis()->SetRangeUser(mlow,mhigh);
      dimuonsGlobalInvMassVsPt[ih]->DrawCopy("EPL");
      // fil2
      dimuonsGlobalInvMassVsPtS[ih]->SetMarkerStyle(8);
      dimuonsGlobalInvMassVsPtS[ih]->SetMarkerColor(46);
      dimuonsGlobalInvMassVsPtS[ih]->SetLineColor(46);
      //****** dimuonsGlobalInvMassVsPtS[ih]->DrawCopy("EPsame");
      //RBWPOL->SetLineColor(kblue);
      //backfun_1->SetLineColor(46);
      //backfun_1->SetLineWidth(1);
      //if(isFit) backfun_1->Draw("same");
      lcat_1->Draw("same"); 
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih],"Global-Global", " ");
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," |y| < 2.4 ", "");  
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], text, "");
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih]," Opposite Charge ", "LP");
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPtS[ih]," Same Charge ", "LP");
      char label_1[512];
      //      char label_2[512], label_3[512], label_4[512];
      sprintf(label_1, "N=%1.2f #pm %1.2f ", yld_cat_1[ih], eyld_cat_1[ih]);
      //    sprintf(label_1, "N_{Z^{0}} = 27");
      legend_1[ih]->AddEntry(dimuonsGlobalInvMassVsPt[ih], label_1, "");
    }//ih loop
  cout << endl << endl;
  CanvPt_1->Print("Pt_Z0MassCat_1.png");
  
  TGraphErrors *Z0pt_cat_1 = new TGraphErrors(Nptbin, PT, yld_cat_1, mom_err, eyld_cat_1);
  Z0pt_cat_1->SetMarkerStyle(20);
  Z0pt_cat_1->SetMarkerColor(2);
  Z0pt_cat_1->GetXaxis()->SetTitle(Xname[iSpec]);
  Z0pt_cat_1->GetYaxis()->SetTitle("counts");

  new TCanvas;
  Z0pt_cat_1->SetMinimum(0.0);
  Z0pt_cat_1->SetName("Z0pt_cat_1");
  Z0pt_cat_1->Draw("AP");
  lcat_1->Draw("same"); 
  gPad->Print("Pt_Z0YieldCat_1.png");
  cout << endl << endl;
  Z0pt_cat_1->Write();
  lcat_1->Write();
  
  // Efficiency correction
  if(isData==2) 
    {
       ofstream fileout("correction.txt");
       cout << Xname[iSpec] << "   Eff_cat_1  " << endl;
       
       for (Int_t ih = 0; ih < Nptbin; ih++) {
      	//cout<<"gen_pt[ih];  "<<gen_pt[ih]<<endl;
	 Eff_cat_1[ih] = yld_cat_1[ih]/gen_pt[ih]; 
	 Eff_catS_1[ih] = yld_catS_1[ih]/gen_ptS[ih]; 
	 //eyld_cat_1[ih];
	 //gen_ptError[ih];
	 //cout<<endl<<endl<<endl;
	//cout<<"Eff_cat_1[ih] "<<Eff_cat_1[ih]<<endl;
	//cout<<"yld_cat_1[ih] "<< yld_cat_1[ih] <<endl;
	//cout<<"eyld_cat_1[ih] "<<eyld_cat_1[ih] <<endl;
	//cout<<"gen_pt[ih]    "<< gen_pt[ih] <<endl;
	//cout<<"gen_ptError[ih] "<< gen_ptError[ih]<<endl;
	 //Error for first graph
	 double errEff_cat_S1_1[100]={0},errEff_cat_S1_2[100]={0};
	 double errEff_cat_S2_1[100]={0},errEff_cat_S2_2[100]={0};
	 errEff_cat_S1_1[ih]= ( (Eff_cat_1[ih] * Eff_cat_1[ih]) /(gen_pt[ih] * gen_pt[ih]) );
	 errEff_cat_S1_2[ih]= (gen_ptError[ih] * gen_ptError[ih] ) - ( eyld_cat_1[ih] * eyld_cat_1[ih] );
	 errEff_cat_S1[ih]= (errEff_cat_S1_1[ih] * errEff_cat_S1_2[ih]);
	 //cout<<" errEff_cat_S1_1[ih] "<<	errEff_cat_S1_1[ih]<< " errEff_cat_S1_2[ih] "<<errEff_cat_S1_2[ih]<<endl;
	 errEff_cat_S2_1[ih]= ( (1 - Eff_cat_1[ih])* (1 - Eff_cat_1[ih]) ) / ( gen_pt[ih] * gen_pt[ih]);
	 errEff_cat_S2_2[ih]= (eyld_cat_1[ih] * eyld_cat_1[ih]);
	 errEff_cat_S2[ih]=errEff_cat_S2_1[ih]*errEff_cat_S2_2[ih];
	 //cout<<" errEff_cat_S2_1[ih] "<<	errEff_cat_S2_1[ih]<< " errEff_cat_S2_2[ih] "<<errEff_cat_S2_2[ih]<<endl;
	 //cout<<"errEff_cat_S1[ih]    "<<errEff_cat_S1[ih]<< " errEff_cat_S2[ih]   "<< errEff_cat_S2[ih]<<endl;	
	 errEff_cat_1[ih]=sqrt(errEff_cat_S1[ih] + errEff_cat_S2[ih]);
	 
	 //Error for second graph
	 double errEff_catS_S1_1[100]={0},errEff_catS_S1_2[100]={0};
	 double errEff_catS_S2_1[100]={0},errEff_catS_S2_2[100]={0};
	 errEff_catS_S1_1[ih]= ( (Eff_catS_1[ih] * Eff_catS_1[ih]) /(gen_ptS[ih] * gen_ptS[ih]) );
	 errEff_catS_S1_2[ih]= (gen_ptErrorS[ih] * gen_ptErrorS[ih] ) - (eyld_catS_1[ih] * eyld_catS_1[ih] );
	 errEff_catS_S1[ih]= (errEff_catS_S1_1[ih] * errEff_catS_S1_2[ih]);
	 errEff_catS_S2_1[ih]= ( (1 - Eff_catS_1[ih])* (1 - Eff_catS_1[ih]) ) / ( gen_ptS[ih] * gen_ptS[ih]);
	 errEff_catS_S2_2[ih]= (eyld_catS_1[ih] * eyld_catS_1[ih]);
	 errEff_catS_S2[ih]= errEff_catS_S2_1[ih]*errEff_catS_S2_2[ih];
	 errEff_catS_1[ih]=sqrt(errEff_catS_S1[ih] + errEff_catS_S2[ih]);
	 //Error for no weight
	 //errEff_cat_1[ih] =((Eff_cat_1[ih]*(1- Eff_cat_1[ih]))/gen_pt[ih]);
	 //Prashant error
	 //errEff_cat_1[ih] = eyld_cat_1[ih]/gen_pt[ih]; 
	 fileout << PT[ih] <<"   "<< Eff_cat_1[ih] << "   " << errEff_cat_1[ih] << endl; 
	 cout <<"    " << PT[ih] <<"    "<< Eff_cat_1[ih] << " +- " << errEff_cat_1[ih] << endl;
	 cyld_cat_1[ih] = Eff_cat_1[ih];
	 ceyld_cat_1[ih] = errEff_cat_1[ih];
	 cyld_catS_1[ih] = Eff_catS_1[ih];
	 ceyld_catS_1[ih] = errEff_catS_1[ih];
       }
    }
  
  TGraphErrors *Z0ptC_cat_1 = new TGraphErrors(Nptbin, PT, cyld_cat_1, mom_err, ceyld_cat_1);
  Z0ptC_cat_1->SetMarkerStyle(20);
  Z0ptC_cat_1->SetMarkerColor(2);
  Z0ptC_cat_1->GetXaxis()->SetTitle(Xname[iSpec]);
  Z0ptC_cat_1->GetYaxis()->SetTitle("Acc #times Eff");
  Z0ptC_cat_1->GetYaxis()->SetRangeUser(0,1.0);

  TGraphErrors *Z0ptC_catS_1 = new TGraphErrors(Nptbin, PT, cyld_catS_1, mom_err, ceyld_catS_1);
  Z0ptC_catS_1->SetMarkerStyle(8);
  Z0ptC_catS_1->SetMarkerColor(1);
  Z0ptC_catS_1->GetYaxis()->SetRangeUser(0,0.8);
  
  TLegend *legend_GP = new TLegend( 0.59,0.79,0.88,0.89);
  legend_GP->SetBorderSize(0);
  legend_GP->SetFillStyle(0);
  legend_GP->SetFillColor(0);
  legend_GP->SetTextSize(0.032);
  //legend_GP->AddEntry(Z0ptC_catS_1,"Pythia Gun in MB HI Data ", "");
  legend_GP->AddEntry(Z0ptC_catS_1,"Pythia Gun in MB Hydjet ", "");
  new TCanvas;
  Z0ptC_cat_1->SetMinimum(0.0);
  Z0ptC_cat_1->Draw("AP");
  //Z0ptC_catS_1->Draw("sameP");
  lcat_1->Draw("same"); 
  legend_GP->Draw("same");
  cout << endl << endl;
  Z0ptC_cat_1->Write();
}
示例#28
0
文件: SMTConfig.C 项目: patere/dReal
void SMTConfig::parseConfig ( char * f )
{
  FILE * filein = NULL;
  // Open configuration file
  if ( ( filein = fopen( f, "rt" ) ) == NULL )
  {
    // No configuration file is found. Print out
    // the current configuration
    // cerr << "# " << endl;
    cerr << "# WARNING: No configuration file " << f << ". Dumping default setting to " << f << endl;
    ofstream fileout( f );
    printConfig( fileout );
    fileout.close( );
  }
  else
  {
    int line = 0;

    while ( !feof( filein ) )
    {
      line ++;
      char buf[ 128 ];
      char * res = fgets( buf, 128, filein );
      (void)res;
      // Stop if finished
      if ( feof( filein ) )
        break;
      // Skip comments
      if ( buf[ 0 ] == '#' )
        continue;

      char tmpbuf[ 32 ];

      // GENERIC CONFIGURATION
           if ( sscanf( buf, "incremental %d\n"              , &incremental )                   == 1 );
      else if ( sscanf( buf, "produce_stats %d\n"            , &produce_stats )                 == 1 );
      else if ( sscanf( buf, "produce_models %d\n"           , &produce_models )                == 1 );
      else if ( sscanf( buf, "produce_proofs %d\n"           , &produce_proofs )                == 1 );
      else if ( sscanf( buf, "produce_inter %d\n"            , &produce_inter )                 == 1 );
      else if ( sscanf( buf, "regular_output_channel %s\n"   , tmpbuf )                         == 1 )
        setRegularOutputChannel( tmpbuf );
      else if ( sscanf( buf, "diagnostic_output_channel %s\n", tmpbuf )                         == 1 )
        setDiagnosticOutputChannel( tmpbuf );
      else if ( sscanf( buf, "dump_formula %d\n"             , &dump_formula )                  == 1 );
      else if ( sscanf( buf, "verbosity %d\n"                , &verbosity )                     == 1 );
      else if ( sscanf( buf, "certification_level %d\n"      , &certification_level )                     == 1 );
      else if ( sscanf( buf, "certifying_solver %s\n"        , certifying_solver )                     == 1 );
      // SAT SOLVER CONFIGURATION
      else if ( sscanf( buf, "sat_theory_propagation %d\n"   , &(sat_theory_propagation))       == 1 );
      else if ( sscanf( buf, "sat_polarity_mode %d\n"        , &(sat_polarity_mode))            == 1 );
      else if ( sscanf( buf, "sat_initial_skip_step %lf\n"   , &(sat_initial_skip_step))        == 1 );
      else if ( sscanf( buf, "sat_skip_step_factor %lf\n"    , &(sat_skip_step_factor))         == 1 );
      else if ( sscanf( buf, "sat_restart_first %d\n"        , &(sat_restart_first))            == 1 );
      else if ( sscanf( buf, "sat_restart_increment %lf\n"   , &(sat_restart_inc))              == 1 );
      else if ( sscanf( buf, "sat_use_luby_restart %d\n"     , &(sat_use_luby_restart))         == 1 );
      else if ( sscanf( buf, "sat_learn_up_to_size %d\n"     , &(sat_learn_up_to_size))         == 1 );
      else if ( sscanf( buf, "sat_temporary_learn %d\n"      , &(sat_temporary_learn))          == 1 );
      else if ( sscanf( buf, "sat_preprocess_booleans %d\n"  , &(sat_preprocess_booleans))      == 1 );
      else if ( sscanf( buf, "sat_preprocess_theory %d\n"    , &(sat_preprocess_theory))        == 1 );
      else if ( sscanf( buf, "sat_centrality %d\n"           , &(sat_centrality))               == 1 );
      else if ( sscanf( buf, "sat_trade_off %d\n"            , &(sat_trade_off))                == 1 );
      else if ( sscanf( buf, "sat_minimize_conflicts %d\n"   , &(sat_minimize_conflicts))       == 1 );
      else if ( sscanf( buf, "sat_dump_cnf %d\n"             , &(sat_dump_cnf))                 == 1 );
      else if ( sscanf( buf, "sat_dump_rnd_inter %d\n"       , &(sat_dump_rnd_inter))           == 1 );
      else if ( sscanf( buf, "sat_lazy_dtc %d\n"             , &(sat_lazy_dtc))                 == 1 );
      else if ( sscanf( buf, "sat_lazy_dtc_burst %d\n"       , &(sat_lazy_dtc_burst))           == 1 );
      // PROOF PRODUCTION CONFIGURATION
      else if ( sscanf( buf, "proof_reduce %d\n"             , &(proof_reduce))                 == 1 );
      else if ( sscanf( buf, "proof_ratio_red_solv %lf\n"    , &(proof_ratio_red_solv))         == 1 );
      else if ( sscanf( buf, "proof_red_time %lf\n"          , &(proof_red_time))               == 1 );
      else if ( sscanf( buf, "proof_red_trans %d\n"          , &(proof_red_trans))              == 1 );
      else if ( sscanf( buf, "proof_reorder_pivots %d\n"     , &(proof_reorder_pivots))         == 1 );
      else if ( sscanf( buf, "proof_remove_mixed %d\n"       , &(proof_remove_mixed))           == 1 );
      else if ( sscanf( buf, "proof_use_sym_inter %d\n"      , &(proof_use_sym_inter))          == 1 );
      else if ( sscanf( buf, "proof_certify_inter %d\n"      , &(proof_certify_inter))          == 1 );
      // EUF SOLVER CONFIGURATION
      else if ( sscanf( buf, "uf_disable %d\n"               , &(uf_disable))                   == 1 );
      else if ( sscanf( buf, "uf_theory_propagation %d\n"    , &(uf_theory_propagation))        == 1 );
      // BV SOLVER CONFIGURATION
      else if ( sscanf( buf, "bv_disable %d\n"               , &(bv_disable))                   == 1 );
      else if ( sscanf( buf, "bv_theory_propagation %d\n"    , &(bv_theory_propagation))        == 1 );
      // DL SOLVER CONFIGURATION
      else if ( sscanf( buf, "dl_disable %d\n"               , &(dl_disable))                   == 1 );
      else if ( sscanf( buf, "dl_theory_propagation %d\n"    , &(dl_theory_propagation))        == 1 );
      // LRA SOLVER CONFIGURATION
      else if ( sscanf( buf, "lra_disable %d\n"              , &(lra_disable))                  == 1 );
      else if ( sscanf( buf, "lra_theory_propagation %d\n"   , &(lra_theory_propagation))       == 1 );
      else if ( sscanf( buf, "lra_poly_deduct_size %d\n"     , &(lra_poly_deduct_size))         == 1 );
      else if ( sscanf( buf, "lra_gaussian_elim %d\n"        , &(lra_gaussian_elim))            == 1 );
      else if ( sscanf( buf, "lra_integer_solver %d\n"       , &(lra_integer_solver))           == 1 );
      else if ( sscanf( buf, "lra_check_on_assert %d\n"      , &(lra_check_on_assert))          == 1 );
      else
      {
        opensmt_error2( "unrecognized option ", buf );
      }
    }

    // Close
    fclose( filein );
  }

  if ( produce_stats )  stats_out.open( "stats.out" );
}
 void dump()
 {
   std::ofstream fileout("matrix_dump.rh");
   std::cerr << "not YET implemented " << std::endl;
   fileout.close();
 }
示例#30
0
    static int
    parse_document(
        fs::path const& filein_
      , fs::path const& fileout_
      , fs::path const& xinclude_base_
      , int indent
      , int linewidth
      , bool pretty_print)
    {
        string_stream buffer;
        id_manager ids;

        int result = 0;

        try {
            actions actor(filein_, xinclude_base_, buffer, ids);
            set_macros(actor);

            if (actor.error_count == 0) {
                actor.current_file = load(filein_); // Throws load_error

                parse_file(actor);

                if(actor.error_count) {
                    detail::outerr()
                        << "Error count: " << actor.error_count << ".\n";
                }
            }

            result = actor.error_count ? 1 : 0;
        }
        catch (load_error& e) {
            detail::outerr(filein_) << detail::utf8(e.what()) << std::endl;
            result = 1;
        }

        if (result == 0)
        {
            std::string stage2 = ids.replace_placeholders(buffer.str());

            fs::ofstream fileout(fileout_);

            if (fileout.fail()) {
                ::quickbook::detail::outerr()
                    << "Error opening output file "
                    << fileout_
                    << std::endl;

                return 1;
            }

            if (pretty_print)
            {
                try
                {
                    fileout << post_process(stage2, indent, linewidth);
                }
                catch (quickbook::post_process_failure&)
                {
                    // fallback!
                    ::quickbook::detail::outerr()
                        << "Post Processing Failed."
                        << std::endl;
                    fileout << stage2;
                    return 1;
                }
            }
            else
            {
                fileout << stage2;
            }

            if (fileout.fail()) {
                ::quickbook::detail::outerr()
                    << "Error writing to output file "
                    << fileout_
                    << std::endl;

                return 1;
            }
        }

        return result;
    }