vector < vector <string> > READ_SETTINGS_FILE (const string settingfilename) { vector < vector <string> > SET; ifstream inputfile (settingfilename.c_str()); while (!inputfile.eof()) { string key, value; vector <string> buf; getline(inputfile, key, '\t'); getline(inputfile, value); const size_t len = value.size(); if (len > 0 && value.at(len-1)=='\r') { // on Linux/Mac, reading files from Windows value.erase(len-1); } if (!is_WHITE_CHARACTER (key) && !is_WHITE_CHARACTER (value)) { buf.push_back (to_uppercase (key)); buf.push_back (to_uppercase (value)); SET.push_back(buf); } } return SET; }
void FileSeqPubCore::loadTrajectory() { //open file std::string traj_path = path_to_poses_ + trajectory_file_name_; ifstream inputfile(traj_path.c_str()); if (!inputfile.is_open()) { ROS_ERROR("Could not open a trajectory file at: %s. Quitting...", traj_path.c_str()); ros::shutdown(); } char const row_delim = '\n'; char const field_delim = ' '; for (string row; getline(inputfile, row, row_delim);) { temp_trajectory_.push_back(Rows_t::value_type()); istringstream ss(row); for (string field; getline(ss, field, field_delim);) { temp_trajectory_.back().push_back(field); } } //! reading problem if (temp_trajectory_.size() == 0) { ROS_WARN("There was a problem with reading %s file. Quitting...", traj_path.c_str()); ros::shutdown(); } else ROS_INFO("trajectory file size = %u.", (unsigned int)temp_trajectory_.size()); }
int main(int argc, char *argv[]) { std::cout << "You have " << argc - 1<< " search terms" << std::endl; if(argc < 2){ std::cout << "Not enough arguments." << std::endl; return 1; } std::vector<std::string> args; for(int i = 1; i < argc; i++){ args.push_back(argv[i]); } std::string line; int value; std::string temp; int key; std::string urlvalue; clock_t t1,t2, t3, t4; std::ifstream inputfile("index.txt"); map_t index; t1 = clock(); while(getline(inputfile, line)){ std::string::size_type pos = line.find(" "); if(pos != std::string::npos){ temp = line.substr(pos+1); std::stringstream ss(temp); while( ss >> value) index[line.substr(0, pos)].push_back(value); } }
void Append_file_to_file(char *inputPath, char *outputPath) { qint64 BUFFER_SIZE = 10*1024*1024; qint64 buffer_len = 0; QFile inputfile(inputPath); if (!inputfile.open(QIODevice::ReadOnly)) return; QFile outputfile(outputPath); if (!outputfile.open(QIODevice::WriteOnly | QIODevice::Append)) return; QDataStream inputstream(&inputfile); QDataStream outputstream(&outputfile); char* buffer = new char[BUFFER_SIZE]; while(!inputstream.atEnd()) { buffer_len = inputstream.readRawData( buffer, BUFFER_SIZE ); outputstream.writeRawData( buffer, buffer_len ); } inputfile.close(); outputfile.close(); delete[] buffer; return; }
/* * Assemble name.s into name.o */ bool Assembler::assemble(const char *name) { int i; struct Instruction s; if (!inputfile(asmf, name, ".s")) return false; if (!outputfile(of, name, ".o")) return false; symbols.clear(); while (parse()); asmf.clear(); asmf.seekg(0); for (;;) { i = generate(&s); if (i == 1) { #if BYTECODE == 1 of.write((const char *)&s, sizeof(s)); #else of << *(uint16_t*)&s << std::endl; #endif } else if (i == -1) break; else if (i == -2) { of.close(); return false; } } of.close(); asmf.close(); symbols.clear(); return true; }
void RenderSkinApplication::initialise(const String& commandLineParameters) { app = new RenderSkin(); StringArray parms; parms.addTokens(commandLineParameters, " "); if(parms.contains("-produce")) { File inputfile(parms[parms.size()-1]); if(inputfile.existsAsFile()) { EditableSkin skin(app); skin.loadFromFile(inputfile); DBG("producing:" + skin.getName()); skin.produce(); DBG("done producing:" + skin.getName()); this->quit(); } } else { this->window = new RenderSkinMainWindow(app); } }
bool bin_loader::load ( std::string const& filename, std::shared_ptr<beziervolumeobject> const& bptr ) { try { boost::filesystem::path inputfile ( filename ); if ( !boost::filesystem::exists ( inputfile ) ) { throw std::runtime_error ( filename + " doesn't exists." ); } std::string extension = boost::filesystem::extension ( inputfile ); if ( extension != ".bin" ) { throw std::runtime_error ( "File not in binary format." ); } std::fstream ifstr ( inputfile.string().c_str(), std::ios::in | std::ios_base::binary ); bptr->read(ifstr); bptr->parent()->name(filename); ifstr.close(); std::cerr << "Loading " << filename << " succeed." << std::endl; return true; } catch ( std::exception& e ) { std::cerr << "Loading " << filename << " failed. " << e.what() << std::endl; return false; } }
bool ShapeBezierSurface::ReadInputDataFile( QString fileName, QVector< Point3D >* inputData, int* nUCurves, int* nVCurves ) const { QVector< Point3D > surfaceData; QFile inputfile( fileName ); if( !inputfile.open( QIODevice::ReadOnly ) ) return false; QTextStream in( &inputfile); int vCurves = 0; while( !in.atEnd() ) { QString dataLine = in.readLine(); QStringList curveData = dataLine.split(QRegExp("[\\s+{},]"), QString::SkipEmptyParts); if( curveData.size() % 3 != 0 ) return false; int nPoints = curveData.size() / 3; if( vCurves > 0 && vCurves != nPoints ) return false; else if( vCurves == 0 ) vCurves = nPoints; for( int j = 0; j < nPoints; j++) surfaceData<<Point3D( curveData[ 3 * j].toDouble(),curveData[ 3* j +1 ].toDouble(),curveData[ 3* j + 2 ].toDouble() ); } inputfile.close(); *nUCurves = surfaceData.size() / vCurves; *nVCurves = vCurves; *inputData = surfaceData; return true; }
void GraveyardReader::makeGraveyards() { ifstream inputfile(filename.c_str()); string currentLine; while(getline(inputfile, currentLine)) { int height = 0; int width = 0; /// Make Graveyard stringstream widthHeight; widthHeight << currentLine; widthHeight >> width >> height; Graveyard thisGraveyard(width, height); /// Make Gravestones stringstream numOfGraves; numOfGraves << getline(inputfile, currentLine); int totalGraves = 0; numOfGraves >> totalGraves; for(int i = 0; i < totalGraves; i++) { stringstream graveCoordSS; graveCoordSS << getline(inputfile, currentLine); int graveX, graveY; graveCoordSS >> graveX >> graveY; ///Change that position to the gravestone } ///Make haunted holes stringstream numOfHoles; numOfHoles << getline(inputfile, currentLine); int totalHoles; numOfHoles >> totalHoles; for(int i = 0; i < totalHoles; i++) { stringstream holeData; holeData << getline(inputfile, currentLine); int holeX, holeY, warpX, warpY, timeWarp; holeData >> holeX >> holeY >> warpX >> warpY >> timeWarp; HauntedHole* thisHole = new HauntedHole(holeX, holeY, warpX, warpY, timeWarp); ///Change that position to the hole } } }
CoinFlipLogic::CoinFlipLogic() : mCoinFlipResultCallback(0) { // open and read the file to a string std::ifstream inputfile("results", std::ifstream::in); ResultReader reader(inputfile); RESULTS = reader.results(); it = RESULTS.begin(); begin = RESULTS.begin(); end = RESULTS.end(); }
void ReadFileToBuffer(_In_ std::wstring path, _Inout_ std::vector<uint8_t>& buffer) { std::ifstream inputfile(path,std::ios::in|std::ios_base::binary|std::ios::ate); if (inputfile.is_open()) { buffer.resize((uint32_t)inputfile.tellg()); inputfile.seekg(0, std::ios::beg); inputfile.read(reinterpret_cast<char*>(buffer.data()), buffer.size()); inputfile.close(); } }
//-------------------------------------------- // Parse Args //-------------------------------------------- bool CStatsUtil::ParseInputPath( const string & path ) { Poco::File inputfile(path); //check if path exists if( inputfile.exists() && ( inputfile.isFile() || inputfile.isDirectory() ) ) { m_inputPath = path; return true; } return false; }
int main(int argc, char** argv) { std::ifstream inputfile (SOURCE_DIR "/input.txt"); std::ofstream outputfile (SOURCE_DIR "/output.txt"); if (openFiles(inputfile,outputfile)) { task1p3(inputfile,outputfile); inputfile.close(); outputfile.close(); } else { std::cout << "fail" << std::endl; } return 0; }
int main(int argc, char* argv[]) { GRINS::Runner grins(argc,argv); grins.init(); const GetPot & inputfile = grins.get_input_file(); //FIXME: We need to move this to within the Simulation object somehow... std::string restart_file = inputfile( "restart-options/restart_file", "none" ); if( restart_file == "none" ) { GRINS::Simulation & sim = grins.get_simulation(); // Asssign initial temperature value std::string system_name = inputfile( "screen-options/system_name", "GRINS" ); std::shared_ptr<libMesh::EquationSystems> es = sim.get_equation_system(); const libMesh::System& system = es->get_system(system_name); libMesh::Parameters ¶ms = es->parameters; libMesh::Real T_init = inputfile("Materials/Gas/ReferenceTemperature/value", 0.0); libMesh::Real p0_init = inputfile("Materials/Gas/ThermodynamicPressure/value", 0.0); libMesh::Real& dummy_T = params.set<libMesh::Real>("T_init"); dummy_T = T_init; libMesh::Real& dummy_p0 = params.set<libMesh::Real>("p0_init"); dummy_p0 = p0_init; system.project_solution( initial_values, NULL, params ); } grins.run(); return 0; }
int main(int argc, char* argv[]) { StockTrades myOrder; std::ifstream inputfile(argv[argc - 1]); string line, word, id, side, price, size, level; while(std::getline(inputfile, line)){ std::istringstream iss(line); iss >> word; if(word == "c"){ iss >> id; iss >> side; iss >> price; iss >> size; if(side[0] == 'b') myOrder.StockCreateBuy(stoi(id), stod(price), stoi(size)); else myOrder.StockCreateSell(stoi(id), stod(price), stoi(size)); } else if(word == "u") {
int main(int argc, const char * argv [] ) { std::ifstream inputfile ( argv[1] ); std::ofstream outputfile ( argv[2] ); typedef std::istream_iterator< std::string > istritr; typedef std::ostream_iterator< std::string > ostritr; std::set< std::string > words( (istritr(inputfile)), istritr() ); std::copy( words.begin(), words.end(), (ostritr( outputfile, "\n" ))); return !inputfile.eof() || !outputfile; }
QString process(const QString inputfilename) { QFile inputfile(inputfilename); if (!inputfile.open(QIODevice::ReadOnly)) { throw Exception(u("Unable to open input file \"%1\" for reading!").arg(inputfilename)); } QString result; QTextStream stream(&inputfile); int linecounter = 0; while (!stream.atEnd()) { ++linecounter; const QString positionInFile = u("%1:%2").arg(inputfilename).arg(linecounter); auto line = stream.readLine(); const int index = line.indexOf(u("@@snippet(")); if ( index != -1) { const int openingBracket = line.indexOf(u("("), index); Q_ASSERT(openingBracket != 0); // we just searched for it above int position = openingBracket; int brackets = 1; while (brackets != 0) { position += 1; if (position == line.count()) { throw Exception(u("%1: Syntax error, opening and closing brackets do not match!") .arg(positionInFile)); } auto const character = line.at(position); if (character == QChar::fromLatin1('(')) { brackets += 1; } else if (character == QChar::fromLatin1(')')) { brackets -= 1; } } const QString command = line.mid(index, openingBracket - index); const QString arguments = line.mid(openingBracket + 1, position - openingBracket - 1); if (command == u("@@snippet")) { result += process_snippet(arguments, positionInFile); } else { throw Exception(u("%1: Unknown parser instruction \"%1\" at line %2!").arg(positionInFile).arg(command)); } } else { result.append(line + u("\n")); } } return result; }
// return the number of lines in a text file int get_file_lines(std::string& filename) { int number_of_lines = 0; std::string line; std::ifstream inputfile(filename.c_str()); if (inputfile.good()) { while (std::getline(inputfile, line)) ++number_of_lines; inputfile.close(); return number_of_lines; } else { std::string errmsg("File "); errmsg.append(filename); errmsg.append(" does not exist.\n"); throw std::runtime_error(errmsg); } }
int extract_histos(TString infilename, TString prefix="psi3770plot_") { //TStopwatch timer; //timer.Start(); //gROOT->LoadMacro("$VMCWORKDIR/gconfig/rootlogon.C");rootlogon(); TFile inputfile(infilename, "READ"); TCanvas* outputcanvas = new TCanvas(); extractHisto("hniceevents", inputfile, outputcanvas, prefix); extractHisto("hdpvertexxfit", inputfile, outputcanvas, prefix); extractHisto("hdpvertexyfit", inputfile, outputcanvas, prefix); extractHisto("hdpvertexzfit", inputfile, outputcanvas, prefix); extractHisto("hdmvertexxfit", inputfile, outputcanvas, prefix); extractHisto("hdmvertexyfit", inputfile, outputcanvas, prefix); extractHisto("hdmvertexzfit", inputfile, outputcanvas, prefix); extractHisto("hdpvertexxreco", inputfile, outputcanvas, prefix); extractHisto("hdpvertexyreco", inputfile, outputcanvas, prefix); extractHisto("hdpvertexzreco", inputfile, outputcanvas, prefix); extractHisto("hdmvertexxreco", inputfile, outputcanvas, prefix); extractHisto("hdmvertexyreco", inputfile, outputcanvas, prefix); extractHisto("hdmvertexzreco", inputfile, outputcanvas, prefix); extractHisto("hdpvertexxmc", inputfile, outputcanvas, prefix); extractHisto("hdpvertexymc", inputfile, outputcanvas, prefix); extractHisto("hdpvertexzmc", inputfile, outputcanvas, prefix); extractHisto("hdmvertexxmc", inputfile, outputcanvas, prefix); extractHisto("hdmvertexymc", inputfile, outputcanvas, prefix); extractHisto("hdmvertexzmc", inputfile, outputcanvas, prefix); extractHisto("hfinalpsimass", inputfile, outputcanvas, prefix); //extractHisto("", inputfile, outputcanvas, prefix); return 0; //timer.Stop(); //Double_t rtime = timer.RealTime(); //Double_t ctime = timer.CpuTime(); //printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime); } // end macro
int main( int argc, char* argv[]) { if( argc!=2 && argc!=3 && argc!=4 ) { std::cout << "USAGE: ./do2ndLevel_TMVA [dataset] [inputfile=""] [flags=""]" << std::endl; exit(31); } std::string dataset(argv[1]); Ntp1Analyzer_TMVA* na; std::string flags = ""; if( argc<4 ) { na = new Ntp1Analyzer_TMVA(dataset, "BESTZ"); } else { std::string flags_str(argv[3]); flags = flags_str; na = new Ntp1Analyzer_TMVA(dataset, "BESTZ", flags); } //na->SetPresel(400); //na->SetPresel(500); //na->AddRequiredTrigger( "HLT_Ele15_LW_L1R" ); //na->AddRequiredTrigger( "HLT_Mu9" ); //na->AddRequiredTrigger( "HLT_Mu15" ); if( argc==2 ) { na->LoadInput(); } else { std::string inputfile(argv[2]); na->LoadInputFromFile(inputfile.c_str()); } na->Loop(); delete na; return 0; }
int main(int argc, char** argv) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " input\n"; return 1; } std::string inputfile(argv[1]); virtclass = inputfile.substr(0, inputfile.find('.')); try { std::vector<std::string> output(build_file(argv[1])); std::copy(output.begin(), output.end(), std::ostream_iterator<std::string>(std::cout, "\n")); } catch (std::exception& e) { std::cerr << e.what() << '\n'; return 1; } }
int InputLayer::initialize(const char * name, PV::HyPerCol * hc) { //TODO make only root process do this //Is there a way to implement a test for mpi? int status = ANNLayer::initialize(name, hc); //2 files are test and train, assuming name of the layer is either test or train //std::string filename = "input/" + std::string(name) + ".txt"; std::ifstream inputfile (inFilename); if (inputfile.is_open()) { getline (inputfile,inputString); inputfile.close(); } else{ std::cout << "Unable to open file " << inFilename << "\n"; exit(EXIT_FAILURE); } assert(parent->getStartTime() == 0); assert(parent->getDeltaTime() == 1); numExamples = inputString.length(); return status; }
// An LEP file is an ascii whose first line contains the string <LEP>. // The read does not support comments, and assumes that the each // subsequent line of the file contains a valid MEL command that can // be executed via the "executeCommand" method of the MGlobal class. // MStatus LepTranslator::reader ( const MFileObject& file, const MString& options, MPxFileTranslator::FileAccessMode mode) { const MString fname = file.fullName(); MStatus rval(MS::kSuccess); const int maxLineSize = 1024; char buf[maxLineSize]; ifstream inputfile(fname.asChar(), ios::in); if (!inputfile) { // open failed cerr << fname << ": could not be opened for reading\n"; return MS::kFailure; } if (!inputfile.getline (buf, maxLineSize)) { cerr << "file " << fname << " contained no lines ... aborting\n"; return MS::kFailure; } if (0 != strncmp(buf, magic.asChar(), magic.length())) { cerr << "first line of file " << fname; cerr << " did not contain " << magic.asChar() << " ... aborting\n"; return MS::kFailure; } while (inputfile.getline (buf, maxLineSize)) { MString cmdString; cmdString.set(buf); if (!MGlobal::executeCommand(cmdString)) rval = MS::kFailure; } inputfile.close(); return rval; }
// // printInputTableAsTabDelimited: // void DataTable::printInputTableAsTabDelimited(std::string filename) const{ std::ofstream inputfile(filename.c_str()); if(inputfile.is_open()){ // Print the labels first: unsigned i,j; for(i=0;i<_columns-1;i++){ inputfile << (*_columnVector[i])->getName() << "\t"; } inputfile << (*_columnVector[i])->getName() << std::endl; // Print the data by rows for(j=0;j<_rows;j++){ for(i=0;i<_columns-1;i++){ inputfile << (*_columnVector[i])->get(j) << "\t"; } inputfile << (*_columnVector[i])->get(j) << std::endl; } inputfile.close(); } }
void ReadPakEntryList(_In_ std::wstring path, _Inout_ std::vector<pak_entry_t>& entries) { std::ifstream inputfile(path,std::ios::in|std::ios_base::binary); if (inputfile.is_open()) { entries.clear(); pak_fileheader_t pakHeader; uint32_t numEntries = 0; inputfile.read(reinterpret_cast<char*>(&pakHeader), sizeof(pakHeader)); numEntries = pakHeader.dirLength/sizeof(pak_entry_t); inputfile.seekg(pakHeader.dirOffset); for (size_t i = 0; i < numEntries; i++) { pak_entry_t entry; inputfile.read(reinterpret_cast<char*>(&entry), sizeof(entry)); entries.push_back(entry); } } else { printf("Cannot read PAK entry list from %ws\n", path.c_str()); } }
void LoadSoundFileData(_In_z_ const char* path, _Out_ SoundFileData* fileData) { WAVData wavData; std::ifstream inputfile(path, std::ios::in | std::ios_base::binary | std::ios::ate); if (inputfile.is_open()) { fileData->DataSize = (uint32_t)inputfile.tellg(); fileData->Data = new uint8_t[fileData->DataSize];//reinterpret_cast<uint8_t*>(_aligned_malloc(fileData->DataSize, 16)); inputfile.seekg(0, std::ios::beg); inputfile.read(reinterpret_cast<char*>(fileData->Data), fileData->DataSize); inputfile.close(); } if (FAILED(LoadWAVAudioInMemoryEx(fileData->Data, fileData->DataSize, wavData))) { throw std::exception("Unsupported sound file format"); } fileData->Format = wavData.wfx; fileData->StartAudioData = wavData.startAudio; fileData->StartAudioDataSize = wavData.audioBytes; }
bool is_SETTINGS_FILE_CORRECT (const string settingfilename) { ifstream inputfile (settingfilename.c_str()); if (! inputfile.is_open()) return false; const vector <vector <string> > SET = READ_SETTINGS_FILE (settingfilename); if (SET.size() == 0) return false; for (size_t i = 0; i < SET.size(); i++) { if (!is_SETTINGS_RECORD_CORRECT (SET.at(i))){ writeln (" - Incorrect key/value pair for '" + SET.at(i).at(0)+ "' user input key."); return false; } else { writeln (" - Correct key/value pair for '" + SET.at(i).at(0)+ "' user input key."); } } return true; }
int main (int argc, char *argv[]) { KAboutData aboutData( "html2mediawiki", 0, ki18n("html2mediawiki"), "0.1", ki18n("Converts html syntax to mediawiki syntax"), KAboutData::License_GPL, ki18n("(c) 2008-2009 by Thorsten Staerk"), ki18n("This is html2mediawiki"), "http://www.staerk.de/thorsten", "*****@*****.**"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineOptions options; options.add("+[file]", ki18n("Document to open")); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); QByteArray inputfilecontent; KApplication app; if (args->count()) { QFile inputfile(args->url(0).fileName()); inputfile.open(QIODevice::ReadOnly); QString inputfilecontentqstring=QString::fromUtf8(inputfile.read(inputfile.bytesAvailable())); QDomDocument mydom=QDomDocument(); mydom.setContent(tidy(inputfilecontentqstring)); QDomNode bodynode(mydom.elementsByTagName("body").at(0)); output(bodynode); } else { std::cout << "html2mediawiki converts an html file to mediawiki syntax" << std::endl; std::cout << "html2mediawiki usage: html2mediawiki <htmlfile>" << std::endl; std::cout << "htmlfile must be utf-8 encoded." << std::endl; } }
int main(int argc, char * argv[]) { // usage // > HBBAnalysisMacro [filelist] // example filelist is Analysis/HbbMSSMAnalysis/test/Run2011A_PR4 // Enable Sumw2 for all histograms so we can access the correct errors // from the histograms as well. TH1::SetDefaultSumw2(); TH2::SetDefaultSumw2(); // requires as a parameter the name of the filelist std::ifstream inputfile(argv[1]); std::string filelist(argv[1]); TString FileName(filelist); bool isData = false; if (FileName.Contains("Run2011")) isData = true; TString ChainName("hbbanalysis/HBBTo4B"); TString SVMassFileName("/afs/naf.desy.de/user/r/rasp/public/Hbb4b/TTJets_svMass.root"); TString SVMassOnlineFileName("/afs/naf.desy.de/user/r/rasp/public/Hbb4b/TTJets_BTagHLTmatched_svMass.root"); svMass * sv = new svMass(SVMassFileName); svMass * svOnline = new svMass(SVMassOnlineFileName); TString OutputFileName = TString(filelist) + TString(".root"); float weight = 1; int numberOfFiles = 0; inputfile >> numberOfFiles; if (!isData) { int nGenEvents = 0; float internalXsec = 0; float externalXsecLO = 0; float externalXsecNLO = 0; float filterEfficiency = 0; for (int iFile=0; iFile<numberOfFiles; ++iFile) { TString filename; inputfile >> filename; std::cout << "File " << filename ; TFile * file = new TFile(filename); if (file->IsZombie()) { std::cout << " does not exist... quitting... " << std::endl; } std::cout << std::endl; TH1F * events = (TH1F*)file->Get("InputEvents/EventCount"); nGenEvents += events->GetEntries(); TTree * genInfo = (TTree*)file->Get("hbbanalysis/GenInfo"); float internalX; float externalXLO; float externalXNLO; float filterEff; genInfo->SetBranchAddress("internalXsec",&internalX); genInfo->SetBranchAddress("externalXsecLO",&externalXLO); genInfo->SetBranchAddress("externalXsecNLO",&externalXNLO); genInfo->SetBranchAddress("filterEfficiency",&filterEff); genInfo->GetEntry(0); internalXsec += internalX; externalXsecLO += externalXLO; externalXsecNLO += externalXNLO; filterEfficiency += filterEff; } internalXsec /= float(numberOfFiles); externalXsecLO /= float(numberOfFiles); externalXsecNLO /= float(numberOfFiles); filterEfficiency /= float(numberOfFiles); std::cout << std::endl; std::cout << " Total number of generated events = " << nGenEvents << std::endl; std::cout << " InternalXsec = " << internalXsec << std::endl; std::cout << " ExternalXsecLO = " << externalXsecLO << std::endl; std::cout << " ExternalXsecNLO = " << externalXsecNLO << std::endl; std::cout << " Filter efficiency = " << filterEfficiency << std::endl; std::cout << std::endl; weight = internalXsec*fabs(filterEfficiency)/float(nGenEvents); // float weight = externalXsecLO*filterEfficiency/float(nGenEvents); // float weight = externalXsecNLO*filterEfficiency/float(nGenEvents); // weight = 1; }
void make_SIDIS_scripts( const char *inputfilename ){ double PI = TMath::Pi(); double Mp = 0.938272; int itgt; int nevents=100000; int fieldclamp=0; int ckov_flag = 1; double Ibeam, Ltgt, Ptgt; double xrast, yrast; double Ebeam, thbb, Dbb, thsbs, Dsbs, Dhcal, Drich; double SBS_magfield; double pmin_SBS, pmin_BB; ifstream inputfile(inputfilename); //inputfile >> nevents; inputfile >> itgt; //0 = LH2, 1 = LD2, 2 = H2 gas, 3 = 3He gas: inputfile >> fieldclamp; inputfile >> ckov_flag; inputfile >> Ibeam >> Ltgt >> Ptgt; inputfile >> xrast >> yrast; inputfile >> Ebeam >> thbb >> Dbb >> thsbs >> Dsbs; inputfile >> SBS_magfield; inputfile >> pmin_SBS >> pmin_BB; Dhcal = Dsbs + 4.0; Drich = Dsbs + 2.5; //The files we want to create are: pi+/-, K+/-, pi0, with upbending and downbending configurations for the charged species. // This means 9 files. //Now, let's compute angle generation limits: we know that at D = 1.5 meters, xptar acceptance is ~ +/- 0.4, yptar acceptance // ~+/-0.2 (conservatively). double dxptar_BB = 0.35 * 1.5/Dbb; double dyptar_BB = 0.15 * 1.5/Dbb; double BBthetamin = thbb - atan(dyptar_BB)*180.0/PI; double pxhat_spec = dxptar_BB/sqrt(1.0+pow(dxptar_BB,2) + pow(dyptar_BB,2) ); double pyhat_spec = -dyptar_BB/sqrt(1.0+pow(dxptar_BB,2) + pow(dyptar_BB,2) ); double pzhat_spec = 1.0/sqrt(1.0+pow(dxptar_BB,2) + pow(dyptar_BB,2) ); double pxhat_lab = pxhat_spec; double pyhat_lab = pyhat_spec*cos(thbb*PI/180.0) - pzhat_spec * sin(thbb*PI/180.0); double pzhat_lab = pyhat_spec*sin(thbb*PI/180.0) + pzhat_spec * cos(thbb*PI/180.0); // cout << "pzhat_spec, pzhat_lab = " << pzhat_spec << ", " << pzhat_lab << endl; double BBthetamax = 180.0/PI * acos(pzhat_lab); // cout << "BigBite thetamax = " << BBthetamax << endl; //Phi max/min computed from smallest in-plane angle, largest out-of-plane pyhat_spec = dyptar_BB/sqrt(1.0+pow(dxptar_BB,2)+pow(dyptar_BB,2)); pxhat_spec = -dxptar_BB/sqrt(1.0+pow(dxptar_BB,2)+pow(dyptar_BB,2)); pyhat_lab = pyhat_spec*cos(thbb*PI/180.0) - pzhat_spec * sin(thbb*PI/180.0); double BBphimin = 180.0/PI * atan2( -pxhat_spec, pyhat_lab ); double BBphimax = 360.0 + 180.0/PI * atan2( pxhat_spec, pyhat_lab ); double dxptar_SBS = 0.3 * 2.45/Dsbs; double dyptar_SBS = 0.1 * 2.45/Dsbs; double SBSthetamin = thsbs - atan(dyptar_SBS)*180.0/PI; pxhat_spec = dxptar_SBS/sqrt(1.0+pow(dxptar_SBS,2)+pow(dyptar_SBS,2)); pyhat_spec = dyptar_SBS/sqrt(1.0+pow(dxptar_SBS,2)+pow(dyptar_SBS,2)); pzhat_spec = 1.0/sqrt(1.0+pow(dxptar_SBS,2)+pow(dyptar_SBS,2)); pxhat_lab = pxhat_spec; pyhat_lab = pyhat_spec*cos(thsbs*PI/180.0) + pzhat_spec*sin(thsbs*PI/180.0); pzhat_lab = -pyhat_spec*sin(thsbs*PI/180.0) + pzhat_spec*cos(thsbs*PI/180.0); double SBSthetamax = 180.0/PI * acos( pzhat_lab ); pyhat_spec = -dyptar_SBS/sqrt(1.0+pow(dxptar_SBS,2)+pow(dyptar_SBS,2)); pxhat_spec = dxptar_SBS/sqrt(1.0+pow(dxptar_SBS,2)+pow(dyptar_SBS,2)); pyhat_lab = pyhat_spec*cos(thsbs*PI/180.0) + pzhat_spec*sin(thsbs*PI/180.0); double SBSphimin = 180.0/PI*atan2( -pxhat_spec, pyhat_lab ); double SBSphimax = 180.0/PI*atan2( pxhat_spec, pyhat_lab ); TString outfilename = "sidis_"; TString hadrons[5] = {"km_", "pim_", "pi0_", "pip_", "kp_"}; TString hadroncmd[5] = {"K-", "pi-", "pi0", "pi+", "K+" }; TString targets[4] = {"LH2", "LD2", "H2", "3He" }; for(int ihadron=-2; ihadron<=2; ihadron++){ for(int sbspol=-1; sbspol<=1; sbspol += 2 ){ outfilename = "sidis_"; outfilename += hadrons[ihadron+2]; if( sbspol*ihadron > 0 ){ outfilename += "upbend_"; } else if( sbspol*ihadron < 0 ){ outfilename += "downbend_"; } char cthD[80]; sprintf(cthD,"_ebeam%gGeV_thbb%gdeg_thsbs%gdeg_Dbb%gm_Dsbs%gm",Ebeam, thbb, thsbs, Dbb, Dsbs ); outfilename += targets[itgt]; outfilename += cthD; outfilename += ".mac"; ofstream outputfile(outfilename.Data()); ifstream template_macro("sidis_template.mac"); TString currentline; while( currentline.ReadLine(template_macro) ){ TObjArray *tokens = currentline.Tokenize(" "); TString cmd_prefix = ( (TObjString*) (*tokens)[0] )->GetString(); // cout << "read line, ntokens = " << tokens->GetEntries() << ": "; // for(int i=0; i<tokens->GetEntries(); i++){ // TString token = ( (TObjString*) (*tokens)[i] )->GetString(); // cout << token.Data() << ", "; // } // cout << endl; int ntokens = tokens->GetEntries(); TString value=" ", unit=" "; TString cmd_temp; if( cmd_prefix == "/g4sbs/beamcur" ){ //value = " "; //value += Ibeam; value.Form(" %5.3g",Ibeam); unit = " muA"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/target" ) { value = " "; value += targets[itgt]; //value.Form( " %s",targets[itgt] ); unit = ""; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/targpres" ){ //value = " "; //value += Ptgt; value.Form(" %5.3g",Ptgt); unit = " atmosphere"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/targlen" ){ //value = " "; //value += Ltgt; value.Form( " %5.3g", Ltgt); unit = " cm"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/rasterx" ){ // value = " "; //value += xrast; value.Form(" %5.3g", xrast); unit = " mm"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/rastery" ){ //value = " "; //value += yrast; value.Form(" %5.3g", yrast); unit = " mm"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/hadron" ){ value = " "; value += hadroncmd[ihadron+2]; //value.Form(" %s",hadroncmd[ihadron+2]); unit = ""; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/beamE" ){ //value = " "; //value += Ebeam; value.Form(" %5.3g",Ebeam); unit = " GeV"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/bbang" ){ //value = " "; //value += thbb; value.Form(" %5.3g", thbb); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/bbdist" ){ //value = " "; //value += Dbb; value.Form(" %5.3g", Dbb); unit = " m"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/hcalang"){ //value = " "; //value += thsbs; value.Form(" %5.3g", thsbs); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/hcaldist"){ //value = " "; //value += Dhcal; value.Form(" %5.3g",Dhcal); unit = " m"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/48D48dist" ){ //value = " "; //value += Dsbs; value.Form(" %5.3g", Dsbs); unit = " m"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/sbsmagfield" ){ //value = " "; //value += SBS_magfield*sbspol; value.Form(" %5.3g", SBS_magfield*sbspol); unit = " tesla"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/sbsclampopt" ){ //value = " "; //value += fieldclamp; value.Form(" %d",fieldclamp); unit = ""; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/richdist" ){ //value = " "; //value += Drich; value.Form(" %5.3g", Drich); unit = " m"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/thmin" ){ //value = " "; //value += BBthetamin; value.Form(" %5.3g", BBthetamin); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/phmin" ){ //value = " "; //value += BBphimin; value.Form(" %5.3g",BBphimin); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/thmax" ){ //value = " "; //value += BBthetamax; value.Form(" %5.3g",BBthetamax); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/phmax" ){ //value = " "; //value += BBphimax; value.Form(" %5.3g", BBphimax); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/hthmin" ){ //value = " "; //value += SBSthetamin; value.Form(" %5.3g", SBSthetamin); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/hthmax" ){ // value = " "; // value += SBSthetamax; value.Form(" %5.3g", SBSthetamax); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/hphmin" ){ // value = " "; // value += SBSphimin; value.Form(" %5.3g", SBSphimin); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/hphmax" ){ // value = " "; // value += SBSphimax; value.Form(" %5.3g", SBSphimax); unit = " deg"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/eemin" ){ // value = " "; // value += pmin_BB; value.Form(" %5.3g", pmin_BB); unit = " GeV"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/eemax" ){ double Eemax = Ebeam/(1.0 + Ebeam/Mp*(1.0-cos(BBthetamin*PI/180.0))); // value = " "; // value += Eemax; value.Form(" %5.3g", Eemax); unit = " GeV"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/ehmin" ){ double Ehmin = pmin_SBS; // value = " "; // value += Ehmin; value.Form( " %5.3g", Ehmin); unit = " GeV"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else if( cmd_prefix == "/g4sbs/ehmax" ){ double Ehmax = Ebeam - pmin_BB; // value = " "; // value += Ehmax; value.Form(" %5.3g", Ehmax); unit = " GeV"; cmd_temp = cmd_prefix + value + unit; outputfile << cmd_temp.Data() << endl; } else { outputfile << currentline.Data() << endl; } } if( ckov_flag == 0 ){ outputfile << "/process/inactivate Cerenkov" << endl; } TString rootfilename = outfilename; rootfilename.ReplaceAll(".mac",".root"); // outputfile << "/g4sbs/filename " << rootfilename.Data() << endl; // outputfile << "/g4sbs/run " << nevents << endl; } } }