void TestChunks::compare() { QByteArray rHighLighted; QByteArray rData = _chunks.data(0, -1, &rHighLighted); bool error = false; if (rData != _data) error = true; if (rHighLighted != _highlighted) error = true; _tCnt += 1; int chunkSize = _chunks.chunkSize(); QString tName = QString("logs/%1_%2_%3").arg(_tName).arg(_tCnt).arg(chunkSize); if (error || (_tCnt >= _saveFile)) { QFile file1(tName + "_data.txt"); file1.open(QIODevice::WriteOnly); file1.write(_data); file1.close(); QFile file2(tName + "_highlighted.txt"); file2.open(QIODevice::WriteOnly); file2.write(_highlighted); file2.close(); QFile file3(tName + "_rData.txt"); file3.open(QIODevice::WriteOnly); file3.write(rData); file3.close(); QFile file4(tName + "_rHighlighted.txt"); file4.open(QIODevice::WriteOnly); file4.write(rHighLighted); file4.close(); } if (error) { qDebug() << "NOK " << tName; *_log << "NOK " << tName << "\n"; } else { qDebug() << "OK " << tName; *_log << "OK " << tName << "\n"; } }
void XMLParserTest::initTestCase(){ xmlParser = new XMLParser(); QString path = QString("%1/%2").arg(StandardPaths::writeableLocation()); QFile file(":/testData/transportations.xml"); if(file.open(QIODevice::ReadOnly)){ if(file.copy(path.arg("transportations.xml"))) QFile::setPermissions(path.arg("transportations.xml"), QFile::WriteOwner | QFile::ReadOwner); } file.close(); QFile file2(":/testData/equipments.xml"); if(file2.open(QIODevice::ReadOnly)){ if(file2.copy(path.arg("equipments.xml"))) QFile::setPermissions(path.arg("equipments.xml"), QFile::WriteOwner | QFile::ReadOwner); } file2.close(); QFile file3(":/testData/products.xml"); if(file3.open(QIODevice::ReadOnly)){ if(file3.copy(path.arg("products.xml"))) QFile::setPermissions(path.arg("products.xml"), QFile::WriteOwner | QFile::ReadOwner); } file3.close(); QFile file4(":/testData/employees.xml"); if(file4.open(QIODevice::ReadOnly)){ if(file4.copy(path.arg("employees.xml"))) QFile::setPermissions(path.arg("employees.xml"), QFile::WriteOwner | QFile::ReadOwner); } file4.close(); QFile file5(":/testData/workplaces.xml"); if(file5.open(QIODevice::ReadOnly)){ if(file5.copy(path.arg("workplaces.xml"))) QFile::setPermissions(path.arg("workplaces.xml"), QFile::WriteOwner | QFile::ReadOwner); } file5.close(); QFile file6(":/testData/workprocesslists.xml"); if(file6.open(QIODevice::ReadOnly)){ if(file6.copy(path.arg("workprocesslists.xml"))) QFile::setPermissions(path.arg("workprocesslists.xml"), QFile::WriteOwner | QFile::ReadOwner); } file6.close(); }
void DecisionTree::FlushIntoFile(){ if(__MESSAGE__) cout << "Flushing..." << endl; FlushVpidToFile(accTrain, "PruneTainAcc.csv"); FlushVpidToFile(accVal, "PruneValAcc.csv"); FlushVpidToFile(accTest, "PruneTestAcc.csv"); filebuf fb; fb.open("PruneAllAcc.csv", ios::out); ostream file4(&fb); for(int i=0; i<accTest.size(); i++) file4 << accTest[i].first << "," << accTrain[i].second << "," << accVal[i].second << "," << accTest[i].second << endl; fb.close(); if(__MESSAGE__) cout << "Flushing data into files finished ... " << endl; }
int main ( int argc, char** argv ) { JInitCore(); JString fileName; if (!(JGetChooseSaveFile())->SaveFile("Save file as:", NULL, "junk", &fileName)) { return 0; } ofstream file0(fileName); file0 << "0123456789"; file0.close(); // force write to disk fstream file1(fileName, kJTextFile); cout << "Length of file (10): " << JGetFStreamLength(file1) << endl; fstream* file2 = JSetFStreamLength(fileName, file1, 20, kJTextFile); cout << "Old fstream open? (0) " << (file1.rdbuf())->is_open() << endl; cout << "Length of file (20): " << JGetFStreamLength(*file2) << endl; fstream* file3 = JSetFStreamLength(fileName, *file2, 5, kJTextFile); cout << "Old fstream open? (0) " << (file2->rdbuf())->is_open() << endl; cout << "Length of file (5): " << JGetFStreamLength(*file3) << endl; file3->close(); ofstream file4(fileName); file4.close(); file1.open(fileName, kJTextFile); cout << "default open of ofstream should erase file" << endl; cout << "Length of file (0): " << JGetFStreamLength(file1) << endl; file1.close(); remove(fileName); return 0; }
void ThroughPut::InputManagement(){ //QFile file("datain.txt"); QFile file0("./Pilot_send_data/pilot_1200_im.txt"); if (!file0.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << file0.errorString(); qDebug() << "Last sentence is in QPSK Inputmanagement." << endl; } //qDebug() << QObject::tr("file text:") << endl << file.readAll(); //char str[100]; char str6[100]; for( int i = 0 ; i < 1200 ; i++ ){ file0.readLine(str6,100); double crr = 0; crr = char2int(str6); //qDebug() << "pilot2[ "<< i <<"][0] is :"<<crr; pilot2[i][1] = crr; } file0.close(); QFile file5("./Pilot_send_data/pilot_1200_re.txt"); if (!file5.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << file5.errorString(); qDebug() << "Last sentence is in QPSK Inputmanagement." << endl; } //qDebug() << QObject::tr("file text:") << endl << file.readAll(); //char str[100]; for( int i = 0 ; i < 1200 ; i++ ){ file5.readLine(str6,100); double crr = 0; crr = char2int(str6); //qDebug() << "pilot2[ "<< i <<"][0] is :"<<crr; pilot2[i][0] = crr; } file5.close(); //QFile file("./pilot4_send_data/pilot4_1200_re.txt"); QFile file("./16qam_data_new/data_im.txt"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << file.errorString(); qDebug() << "Last sentence is in ThroughPut Inputmanagement." << endl; } //qDebug() << QObject::tr("file text:") << endl << file.readAll(); //char str[100]; char str[100]; for( int i = 0 ; i < 1200 ; i++ ){ file.readLine(str,100); double crr = 0; crr = char2int(str); //qDebug() << "pilot4[ "<< i <<"][0] is :"<<crr; pilot4[i][0] = crr; } //qDebug() << "last one is :"<< ThroughPut[9][0] ; file.close(); //QFile file2("./pilot4_send_data/pilot4_1200_im.txt"); QFile file2("./16qam_data_new/data_re.txt"); if (!file2.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << file2.errorString(); qDebug() << "Last sentence is in ThroughPut Inputmanagement." << endl; } //qDebug() << QObject::tr("file text:") << endl << file2.readAll(); //char str[100]; for( int i = 0 ; i < 1200 ; i++ ){ file2.readLine(str,100); double crr = 0; crr = char2int(str); //qDebug() << "pilot4[ "<< i <<"][1] is :"<<crr; pilot4[i][1] = crr; } //qDebug() <<"apsk[0][0] is :"<< *(pdata) << endl; file2.close(); // QFile file3("./16qam_data/data_re.txt"); QFile file3("./16qam_data_new/data_re.txt"); if (!file3.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << file3.errorString(); qDebug() << "Last sentence is in ThroughPut Inputmanagement." << endl; } //qDebug() << QObject::tr("file text:") << endl << file.readAll(); //char str[100]; int cnt_2_500=0; for( int i = 0 ; i < 600 ; i++ ){ file3.readLine(str,100); double crr = 0; if(i%6!=0){ crr = char2double(str); // qDebug() << "re[ "<< i <<"][0] is :"<<crr; qam16_3[cnt_2_500][0] = crr; cnt_2_500++; } } //qDebug() << "last one is :"<< ThroughPut[9][0] ; file3.close(); // QFile file4("./16qam_data/data_im.txt"); QFile file4("./16qam_data_new/data_im.txt"); if (!file4.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << file4.errorString(); qDebug() << "Last sentence is in ThroughPut Inputmanagement." << endl; } //qDebug() << QObject::tr("file text:") << endl << file.readAll(); //char str[100]; int cnt_2_500_2; for( int i = 0 ; i < 600 ; i++ ){ file4.readLine(str,100); double crr = 0; if(i%6!=0){ crr = char2double(str); //qDebug() << "im[ "<< i <<"][0] is :"<<crr; qam16_3[cnt_2_500_2][1] = crr; cnt_2_500_2++; } } //qDebug() << "last one is :"<< ThroughPut[9][0] ; file4.close(); }
int main(int argc, char * argv[]) { PARSE_ARGS; ////////////////////////////////////////////////////////////////////////////////////////////////////////Pipipeline 1//////////////////////////////////////////////////////////////////////////////////////////////////////////////// std::string nameFile; nameFile="/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/dataset.csv"; std::ifstream Sub(nameFile.c_str(),std::ios::in); int i=0; if(Sub) { std :: string line; while(getline( Sub, line )) { std :: cout <<"1"<<endl; if (i>0) { char labelfile[200]; char subjid[100]; char WarpedCorrespondenceMesh[200]; char CorrespondenceMesh[200]; char labelMapInput[200]; char measurementOutput[200]; char group[100]; char ThicknessSamplingResult[200]; /*std :: string labelfile; std :: string subjid; std :: string WarpedCorrespondenceMesh; std :: string CorrespondenceMesh; std :: string labelMapInput; std :: string measurementOutput; std :: string group; std :: string ThicknessSamplingResult;*/ std::string BatchMakeScriptFile = "slicer3ThicknessSPHARM.bms"; std::ofstream file( BatchMakeScriptFile.c_str()); readFileCSV(line, group,subjid,labelMapInput, measurementOutput,labelfile, CorrespondenceMesh, WarpedCorrespondenceMesh, ThicknessSamplingResult); //std :: cout << "s is : " << group << std :: endl; file <<"set (labelMapInput "<< labelMapInput<<")"<<std::endl; file <<"set (measurementOutput "<< measurementOutput<<")"<<std::endl; file <<"set (spharmBinaryInput "<<labelfile<<")"<<std::endl; file <<"set (case1 "<< subjid <<")"<<std::endl; file <<"set (group "<< group <<")"<<std::endl; file <<"set (subjWorkDir "<< subjWorkDir<<")"<<std::endl; file <<"set (exprId "<< exprId<<")"<<std::endl; file <<"include (/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/ThicknessSpharm.bms)"<<std::endl; file.close(); /* bm::ScriptParser m_Parser; m_Parser.LoadWrappedApplication( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser.SetBatchMakeBinaryPath( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser.Execute(BatchMakeScriptFile); */ } i++; } Sub.close(); } // fin du if (sub) else { std::cout << "ERROR: Unable to open file for reading." << std::endl; } ///////////////////////////////////////////////////////////////////////////////////////////////////////Pipeline2/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// std::string nameFile2; nameFile2=dataset; int number_of_groups = GetNumberGroups(nameFile2); number_of_groups = number_of_groups - 1; // First line isn't a group name //Initialisation char** groupIds = new char*[number_of_groups]; for(int i = 0; i < number_of_groups; ++i) groupIds[i] = NULL; char** Groups = new char*[number_of_groups]; for(int i = 0; i < number_of_groups; ++i) Groups[i] = NULL; char** subjgroups = new char*[number_of_groups]; for(int i = 0; i < number_of_groups; ++i) subjgroups[i] = NULL; int L = GetGroups(nameFile2, groupIds, subjgroups, Groups); for(int i = 0; i < L; ++i) std::cout << groupIds[i] << std::endl; for(int i = 0; i < number_of_groups; ++i) std::cout << subjgroups[i] << std::endl; for(int i = 0; i < number_of_groups; ++i) std::cout << Groups[i] << std::endl; std::string final_groups; std::string subjGroup; for(int i = 0; i < L; ++i) { if (i != L-1) final_groups = final_groups + groupIds[i] + ' '; else final_groups = final_groups + groupIds[i]; } for(int i = 0; i < number_of_groups; ++i) { if (i != number_of_groups-1) subjGroup = subjGroup + subjgroups[i] +'/'+ Groups[i] + ' '; else subjGroup = subjGroup + subjgroups[i] +'/'+ Groups[i]; } //std::cout << final_groups << std::endl; std::cout << subjGroup << std::endl; //file bms std::string BatchMakeScriptFile2 = "slicer3ThicknessSPHARM1.bms"; std::ofstream file2( BatchMakeScriptFile2.c_str()); file2 <<"set (groupIds "<< final_groups<<")"<<std::endl; file2 <<"set (subjectsWithGroups "<< subjGroup<<")"<<std::endl; file2 <<"set (subjWorkDir "<< subjWorkDir<<")"<<std::endl; file2 <<"set (exprId "<< exprId<<")"<<std::endl; file2 <<"include (/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/particlecorrespondance.bms)"<<std::endl; file2.close(); /* bm::ScriptParser m_Parser1; m_Parser1.LoadWrappedApplication( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser1.SetBatchMakeBinaryPath( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser1.Execute(BatchMakeScriptFile2); */ ////////////////////////////////////////////////////////////////////////////////////////////////////////Pipeline 3///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// std::string nameFile3; nameFile3=dataset; std::ifstream Sub1(nameFile.c_str(),std::ios::in); int i1=0; if(Sub1) { std :: string line; while(getline( Sub1, line )) { if (i1>0) { char labelfile[200]; char subjid[100]; char WarpedCorrespondenceMesh[200]; char CorrespondenceMesh[200]; char labelMapInput[200]; char measurementOutput[200]; char group[100]; char ThicknessSamplingResult[200]; std::string BatchMakeScriptFile = "slicer3writefile.bms"; std::ofstream file( BatchMakeScriptFile.c_str()); readFileCSV(line, group, subjid, labelMapInput, measurementOutput, labelfile, CorrespondenceMesh, WarpedCorrespondenceMesh, ThicknessSamplingResult); file <<"set (labelMapInput "<< labelMapInput<<")"<<std::endl; file <<"set (measurementOutput "<< measurementOutput<<")"<<std::endl; file <<"set (spharmBinaryInput "<<labelfile<<")"<<std::endl; file <<"set (case1 "<< subjid <<")"<<std::endl; file <<"set (CorrespondenceMesh "<<CorrespondenceMesh<<")"<<std::endl; file <<"set (WarpedCorrespondenceMesh "<<WarpedCorrespondenceMesh<<")"<<std::endl; file <<"set (group "<< group <<")"<<std::endl; file <<"set (subjWorkDir "<< subjWorkDir<<")"<<std::endl; file <<"set (exprId "<< exprId<<")"<<std::endl; file <<"include (/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/writefile.bms)"<<std::endl; file.close(); /* bm::ScriptParser m_Parser; m_Parser.LoadWrappedApplication( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser.SetBatchMakeBinaryPath( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser.Execute(BatchMakeScriptFile); */ } i1++; } Sub1.close(); } // fin du if (sub) else { std::cout << "ERROR: Unable to open file for reading." << std::endl; } //////////////////////////////////////////////////////////////////////////////////////////////////Pipeline4//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// std::string nameFile4; nameFile4=dataset; //file bms std::string BatchMakeScriptFile4 = "slicer3shapeworks.bms"; std::ofstream file4( BatchMakeScriptFile4.c_str()); file4 <<"set (groupIds "<< final_groups<<")"<<std::endl; file4 <<"set (subjWorkDir "<< subjWorkDir<<")"<<std::endl; file4 <<"set (exprId "<< exprId<<")"<<std::endl; file4 <<"include (/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/shapeworks.bms)"<<std::endl; file4.close(); /* bm::ScriptParser m_Parser4; m_Parser4.LoadWrappedApplication( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser4.SetBatchMakeBinaryPath( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser4.Execute(BatchMakeScriptFile4); */ ////////////////////////////////////////////////////////////////////////////////////////////////Pipeline5///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// std::string nameFile5; nameFile5=dataset; std::ifstream Sub2(nameFile.c_str(),std::ios::in); int i2=0; if(Sub2) { std :: string line; while(getline( Sub2, line )) { if (i2>0) { char labelfile[200]; char subjid[100]; char WarpedCorrespondenceMesh[200]; char CorrespondenceMesh[200]; char labelMapInput[200]; char measurementOutput[200]; char group[100]; char ThicknessSamplingResult[200]; std::string BatchMakeScriptFile5 = "slicer3meshintensity.bms"; std::ofstream file( BatchMakeScriptFile5.c_str()); readFileCSV(line, group, subjid, labelMapInput, measurementOutput, labelfile, CorrespondenceMesh, WarpedCorrespondenceMesh, ThicknessSamplingResult); file <<"set (labelMapInput "<< labelMapInput<<")"<<std::endl; file <<"set (measurementOutput "<< measurementOutput<<")"<<std::endl; file <<"set (spharmBinaryInput "<<labelfile<<")"<<std::endl; file <<"set (case1 "<< subjid <<")"<<std::endl; file <<"set (CorrespondenceMesh "<<CorrespondenceMesh<<")"<<std::endl; file <<"set (WarpedCorrespondenceMesh "<<WarpedCorrespondenceMesh<<")"<<std::endl; file <<"set (ThicknessSamplingResult "<<ThicknessSamplingResult<<")"<<std::endl; file <<"set (group "<< group <<")"<<std::endl; file <<"set (subjWorkDir "<< subjWorkDir<<")"<<std::endl; file <<"set (exprId "<< exprId<<")"<<std::endl; file <<"include (/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/meshintensity.bms)"<<std::endl; file.close(); /* bm::ScriptParser m_Parser; m_Parser.LoadWrappedApplication( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser.SetBatchMakeBinaryPath( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser.Execute(BatchMakeScriptFile5); */ } i2++; } Sub2.close(); } // fin du if (sub) else { std::cout << "ERROR: Unable to open file for reading." << std::endl; } ///////////////////////////////////////////////////////////////////////////////////////////////////////Pipeline6/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// std::string nameFile1; nameFile1=dataset; //file bms std::string BatchMakeScriptFile1 = "slicer3ThicknessSPHARM2.bms"; std::ofstream file6( BatchMakeScriptFile1.c_str()); file6 <<"set (groupIds "<< final_groups<<")"<<std::endl; file6 <<"set (subjWorkDir "<< subjWorkDir<<")"<<std::endl; file6 <<"set (exprId "<< exprId<<")"<<std::endl; file6 <<"set (subjectsWithGroups "<< subjGroup<<")"<<std::endl; file6 <<"include (/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/correspondance.bms)"<<std::endl; file6.close(); /* bm::ScriptParser m_Parser2; m_Parser2.LoadWrappedApplication( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser2.SetBatchMakeBinaryPath( "/biomed-resimg/work/mjacquem/Slicer3Thickness2/SampleBatchMake/bmm2" ); m_Parser2.Execute(BatchMakeScriptFile1); */ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Memory Space liberation for (int i = 0; i < L; ++i) delete [] groupIds[i]; delete [] groupIds; // Memory Space liberation for (int i = 0; i < number_of_groups; ++i) delete [] subjgroups[i]; delete [] subjgroups; // Memory Space liberation for (int i = 0; i < number_of_groups; ++i) delete [] Groups[i]; delete [] Groups; return 0; }
int main( ) { std::string input_dir = "Input/"; // Read Nucleus File std::string nucleus_string; std::ifstream nucleus_file( "domgen.config" ); nucleus_file >> nucleus_string; nucleus_file.close(); nucleus_file.clear(); // Read Configuration file std::string config_filename = nucleus_string + ".config"; std::ifstream config_file( config_filename.c_str() ); std::string parameters_string; int fit_ph; double rmax; int rpts; int lmax; config_file >> parameters_string >> fit_ph; config_file >> rmax >> rpts >> lmax; cout<<"parameters_string = "<<parameters_string<<endl; int num_lj; config_file >> num_lj; config_file.close(); config_file.clear(); // Read in normalization double calc_Z = 20; double calc_N = 20; //std::cout << "Enter calculated Z: " << std::endl; //std::cin >> calc_Z; //std::cout << "Enter calculated N: " << std::endl; //std::cin >> calc_N; std::string output_dir = "Output_" + parameters_string + "/Spectral_functions_kE/"; std::string parameters_filename = parameters_string + ".inp"; std::cout << "rmax = " << rmax << std::endl; std::cout << "rpts = " << rpts << std::endl; std::cout << "lmax = " << lmax << std::endl; std::string n_string = "n" + nucleus_string; std::string p_string = "p" + nucleus_string; std::string n_filename = input_dir + n_string + ".inp"; std::string p_filename = input_dir + p_string + ".inp"; // Create Nuclear Parameter Objects NuclearParameters Nu_n = read_nucleus_parameters( n_filename ); NuclearParameters Nu_p = read_nucleus_parameters( p_filename ); std::vector< NuclearParameters > Nu_vec; Nu_vec.push_back( Nu_n ); Nu_vec.push_back( Nu_p ); // Read in DOM parameters std::ifstream pfile( parameters_filename.c_str() ); if ( pfile.is_open() !=1 ) { std::cout << "could not open file " << parameters_filename << std::endl; std::abort(); } pfile.close(); pfile.clear(); // Create radial grid std::vector<double> rmesh; std::vector<double> rweights; double rdelt = rmax / rpts; for( int i = 0; i < rpts; ++i ) { rmesh.push_back( ( i + 0.5 ) * rdelt ); rweights.push_back( rdelt ); } // Create momentum space grid for k-slice std::vector<double> kmesh1; double kmax1 = 6.0; int kpts1 = 100; double deltak1 = kmax1 / kpts1; for ( int i = 0; i < kpts1; ++i ) { kmesh1.push_back( ( i + 0.5 ) * deltak1 ); } // Create momentum space grid for E-slice std::vector<double> kmesh2; // wave number in units of fm^{-1} std::vector<double> pmesh; // momentum in units of MeV / c double pmin = 170; double pmax = 650; double deltap = 40; int ppts = static_cast<int> ( ( pmax - pmin ) / deltap ) + 1; for ( int i = 0; i < ppts; ++i ) { double p = pmin + i * deltap; pmesh.push_back( p ); double k = p / hbarc; kmesh2.push_back( k ); } // Prepare stuff for output files std::vector< std::string > np_strings; np_strings.push_back( n_string ); np_strings.push_back( p_string ); // create L and J strings for output files std::string L_array[8] = { "s", "p", "d", "f", "g", "h", "i", "j" }; std::string J_array[8] = { "1", "3", "5", "7", "9", "11", "13", "15" }; //Potential specifications int type = 1; // 1 is P.B. form (average), 0 is V.N. form int mvolume = 4; int AsyVolume = 1; /* CALCULATIONS */ // Loop over protons and neutrons double Zp; // number of protons in projectile omp_set_nested(1); #pragma omp parallel num_threads(2) { #pragma omp for for ( unsigned int nu = 0; nu < Nu_vec.size(); ++nu ) { double tz = nu - 0.5; // +0.5 for protons, -0.5 for neutrons double calc_norm; if ( tz < 0 ) { Zp = 0; calc_norm = calc_N; } else { Zp = 1; calc_norm = calc_Z; } // Nucleus Object const NuclearParameters &Nu = Nu_vec[nu]; // Construct Parameters Object Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, Zp ); // Construct Potential Object pot U = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p ); pot *U1 = &U; // Construct Object for calculating bound-state properties boundRspace B( rmax, rpts, Nu.Ef, Nu.ph_gap, lmax, Nu.Z, Zp, Nu.A, U1 ); // Create Energy Grid for k-slice double Emin1 = -225; double Emax1 = -25; double deltaE1 = 25; int epts1 = static_cast<int>( ( Emax1 - Emin1 ) / deltaE1 ) + 1; std::vector<double> emesh1; for ( int i = 0; i < epts1; ++i ) { emesh1.push_back( Emin1 + i * deltaE1 ); } // Create Energy grid for E-slice double Emin2 = -300; double Emax2 = -25; double deltaE2 = 2; int epts2 = static_cast<int>( ( Emax2 - Emin2 ) / deltaE2 ) + 1; std::vector<double> emesh2; for ( int i = 0; i < epts2; ++i ) { emesh2.push_back( Emin2 + i * deltaE2 ); } matrix_t S_of_kE_mtx1( kmesh1.size(), emesh1.size() ); matrix_t S_of_kE_mtx2( kmesh2.size(), emesh2.size() ); // intialize matrices to zero for ( unsigned int i = 0; i < kmesh1.size(); ++i ) { for ( unsigned int j = 0; j < emesh1.size(); ++j ) { S_of_kE_mtx1( i, j ) = 0; } } for ( unsigned int i = 0; i < kmesh2.size(); ++i ) { for ( unsigned int j = 0; j < emesh2.size(); ++j ) { S_of_kE_mtx2( i, j ) = 0; } } std::vector< matrix_t > S_of_kE_mtx2_lj_vec; // Loop over lj channels for ( int L = 0; L < lmax + 1; ++L ) { cout<<"l = "<<L<<endl; for( int up = -1; up < 2; up+=2 ) { double xj = L + up / 2.0; int j_index = ( up - 1 ) / 2; if ( xj < 0 ) continue; std::string j_string; if ( L == 0 ) j_string = J_array[ L ]; else j_string = J_array[ L + j_index ]; std::string lj_string = L_array[L] + j_string + "2"; // Create Bessel Function matrix in k and r matrix_t bess_mtx1( kmesh1.size(), rmesh.size() ); for( unsigned int nk = 0; nk < kmesh1.size(); ++nk ) { for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) { double rho = kmesh1[nk] * rmesh[nr]; bess_mtx1( nk, nr ) = gsl_sf_bessel_jl( L, rho ); } } // Create Bessel Function matrix in k and r matrix_t bess_mtx2( kmesh2.size(), rmesh.size() ); for( unsigned int nk = 0; nk < kmesh2.size(); ++nk ) { for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) { double rho = kmesh2[nk] * rmesh[nr]; bess_mtx2( nk, nr ) = gsl_sf_bessel_jl( L, rho ); } } // Calculate S( k; E ) for k-slice for ( unsigned int m = 0; m < emesh1.size(); ++m ) { double E = emesh1[m]; /* std::ostringstream e_strm; e_strm << "m" << std::abs( E ); std::string s_of_kE_lj_filename1 = output_dir + np_strings[nu] + "_s_of_k_" + "E_at_" + e_strm.str() + "MeV_" + L_array[L] + j_string + "2.out"; std::ofstream file1( s_of_kE_lj_filename1.c_str() ); */ // Propagator cmatrix_t G = B.propagator( rmesh, E, L, xj ); // Spectral Function in momentum space, S( k; E ) for( unsigned int nk = 0; nk < kmesh1.size(); ++nk ) { double rsums = 0; for( unsigned int i = 0; i < rmesh.size(); ++i ) { double jl1 = bess_mtx1( nk, i ); for( unsigned int j = 0; j < rmesh.size(); ++j ) { double jl2 = bess_mtx1( nk, j ); rsums -= rmesh[i] * jl1 * imag( G( i, j ) ) * rmesh[j] * jl2 * rdelt * 2 / M_PI / M_PI; } } // end loop over radial coordinates // file1 << kmesh1[nk] << " " << rsums << std::endl; S_of_kE_mtx1( nk, m ) += ( 2 * xj + 1 ) * rsums; } // end loop over k // file1.close(); // file1.clear(); // r-space spectral functions } // end loop over energy // Calculate S( k; E ) for E-slice matrix_t S_of_kE_mtx_lj( kmesh2.size(), emesh2.size() ); for ( unsigned int m = 0; m < emesh2.size(); ++m ) { double E = emesh2[m]; // Propagator cmatrix_t G = B.propagator( rmesh, E, L, xj ); // Spectral Function in momentum space, S( k; E ) for( unsigned int nk = 0; nk < kmesh2.size(); ++nk ) { double rsums = 0; for( unsigned int i = 0; i < rmesh.size(); ++i ) { double jl1 = bess_mtx2( nk, i ); for( unsigned int j = 0; j < rmesh.size(); ++j ) { double jl2 = bess_mtx2( nk, j ); rsums -= rmesh[i] * jl1 * imag( G( i, j ) ) * rmesh[j] * jl2 * rdelt * 2 / M_PI / M_PI; } } // end loop over radial coordinates S_of_kE_mtx_lj( nk, m ) = ( 2 * xj + 1 ) * rsums; S_of_kE_mtx2( nk, m ) += ( 2 * xj + 1 ) * rsums; } // end loop over k } // end loop over energy S_of_kE_mtx2_lj_vec.push_back( S_of_kE_mtx_lj ); }// end loop over j } // end loop over L // write out results summed over the lj combinations for ( unsigned int j = 0; j < emesh1.size(); ++j ) { std::ostringstream e_strm; e_strm << "m" << std::abs( emesh1[j] ); std::string s_of_kE_filename1 = output_dir + np_strings[nu] + "_s_of_k_" + "E_at_" + e_strm.str() + "MeV.out"; std::ofstream file3( s_of_kE_filename1.c_str() ); for ( unsigned int i = 0; i < kmesh1.size(); ++i ) { file3 << kmesh1[i] << " " << S_of_kE_mtx1( i, j ) << std::endl; } file3.close(); file3.clear(); } // write in units of MeV^-4 sr^-1 double fac = std::pow( hbarc, 3 ) * 4 * M_PI; for ( unsigned int i = 0; i < kmesh2.size(); ++i ) { std::ostringstream k_strm; k_strm << pmesh[i]; std::string s_of_kE_filename2 = output_dir + np_strings[nu] + "_s_of_E_" + "p_at_" + k_strm.str() + "MeV_over_c.out"; std::ofstream file4( s_of_kE_filename2.c_str() ); for ( unsigned int j = 0; j < emesh2.size(); ++j ) { // write energy in terms of missing energy // and in units of GeV file4 << std::abs( emesh2[j]/1000) << " " << S_of_kE_mtx2( i, j ) / fac << " " << S_of_kE_mtx2( i, j ) / fac / calc_norm << std::endl; } file4.close(); file4.clear(); } // write in units of MeV^-4 sr^-1 for ( unsigned int nk = 0; nk < kmesh2.size(); ++nk ) { for ( int L = 0; L < lmax + 1; ++L ) { std::ostringstream k_strm; k_strm << pmesh[nk]; std::string s_of_kE_lj_filename2 = output_dir + np_strings[nu] + "_s_of_E_p_at_" + k_strm.str() + "MeV_over_c_" + L_array[L] + ".out"; std::ofstream file2( s_of_kE_lj_filename2.c_str() ); for ( unsigned int m = 0; m < emesh2.size(); ++m ) { // write energy in terms of missing energy // and in units of GeV if ( L == 0 ) { file2 << std::abs( emesh2[m]/1000 ) << " " << S_of_kE_mtx2_lj_vec[0]( nk, m ) / fac << std::endl; } else { double jg = S_of_kE_mtx2_lj_vec[2*L]( nk, m ); double jl = S_of_kE_mtx2_lj_vec[2*L- 1]( nk, m ); file2 << std::abs( emesh2[m]/1000) << " " << jg / fac << " " << jl / fac << " " << ( jg + jl ) / fac << std::endl; } } file2.close(); file2.clear(); } // end loop over L } // end loop over momentum } // end loop over tz } /* end of pragma loop */ return 1; }
void overlay_plots(const string& fFile0, const string& fFile1, const string& fFile2, const string& fFile3, const string& fFile4, const string& fPlot0, const string& fPlot1, const string& fPlot2, const string& fPlot3, const string& fPlot4, const double fXmin, const double fXmax, const string& fXAxisLabel, const string& fName, const int logY, const int rescale, const double cutValue0, const double cutValue1, const string& label) { TH1F *h[5]; TFile file0(fFile0.c_str()); h[0] = (TH1F*)file0.Get(fPlot0.c_str()); TFile file1(fFile1.c_str()); h[1] = (TH1F*)file1.Get(fPlot1.c_str()); TFile file2(fFile2.c_str()); h[2] = (TH1F*)file2.Get(fPlot2.c_str()); TFile file3(fFile3.c_str()); h[3] = (TH1F*)file3.Get(fPlot3.c_str()); TFile file4(fFile4.c_str()); h[4] = (TH1F*)file4.Get(fPlot4.c_str()); h[0]->Rebin(1); h[1]->Rebin(1); h[2]->Rebin(1); h[3]->Rebin(1); h[4]->Rebin(1); // double ymax = (h[0]->GetMaximum()>h[1]->GetMaximum()) ? h[0]->GetMaximum() : h[1]->GetMaximum(); h[0]->GetXaxis()->SetTitle(fXAxisLabel.c_str()); h[0]->GetXaxis()->SetRangeUser(fXmin,fXmax); // h[0]->GetYaxis()->SetRangeUser(0.5,1.25*ymax); h[0]->SetTitleOffset(1.2,"X"); h[0]->GetXaxis()->SetTitleSize(0.04); h[0]->GetYaxis()->SetTitleSize(0.04); if(rescale) { if (h[0]->Integral()!=0) h[0]->Scale(1/h[0]->Integral()); //---------------------------- // if (h[1]->Integral()!=0) // h[1]->Scale(1/h[1]->Integral()); // if (h[2]->Integral()!=0) // h[2]->Scale(1/h[2]->Integral()); //---------------------------- if (h[3]->Integral()!=0) h[3]->Scale(1/h[3]->Integral()); if (h[4]->Integral()!=0) h[4]->Scale(1/h[4]->Integral()); } TCanvas *c = new TCanvas("c","",800,800); c->cd(); c->Range(-0.4638998,-0.01028103,4.210331,0.09111118); c->SetRightMargin(0.2286432); h[0]->SetLineWidth(3); // h[0]->SetLineStyle(4); h[0]->SetLineColor(kRed); h[0]->SetFillColor(kRed); h[0]->SetFillStyle(3002); // h[0]->SetMarkerSize(.6); // h[0]->SetMarkerStyle(26); // h[0]->SetMarkerColor(kRed); h[0]->Draw("hist"); h[1]->SetLineWidth(3); // h[1]->SetLineStyle(3); h[1]->SetLineColor(kBlack); // h[1]->SetMarkerSize(.8); h[1]->SetMarkerStyle(20); h[1]->SetMarkerColor(kBlack); //---------------------------- //h[1]->Draw("sameshist"); //---------------------------- h[2]->SetLineWidth(3); h[2]->SetLineStyle(3); h[2]->SetLineColor(kBlack); // h[1]->SetMarkerSize(.8); h[2]->SetMarkerStyle(20); h[2]->SetMarkerColor(kBlack); //---------------------------- //h[2]->Draw("sameshist"); //---------------------------- h[3]->SetLineWidth(3); h[3]->SetLineStyle(4); h[3]->SetLineColor(kBlack); // h[1]->SetMarkerSize(.8); h[3]->SetMarkerStyle(20); h[3]->SetMarkerColor(kBlack); h[3]->Draw("sameshist"); h[4]->SetLineWidth(3); h[4]->SetLineStyle(5); h[4]->SetLineColor(kBlack); // h[1]->SetMarkerSize(.8); h[4]->SetMarkerStyle(20); h[4]->SetMarkerColor(kBlack); h[4]->Draw("sameshist"); double maximum = 0; if( h[0]->GetMaximum() > maximum ) maximum = h[0]->GetMaximum() ; //------------------------------- // if( h[1]->GetMaximum() > maximum ) // maximum = h[1]->GetMaximum(); // if( h[2]->GetMaximum() > maximum ) // maximum = h[2]->GetMaximum(); //------------------------------- if( h[3]->GetMaximum() > maximum ) maximum = h[3]->GetMaximum(); if( h[4]->GetMaximum() > maximum ) maximum = h[4]->GetMaximum(); h[0]->GetYaxis()->SetRangeUser(0,maximum+maximum*0.1); //update the current pad, needed to modify statboxes gPad->Update(); // get the statboxes and set color TPaveStats *st1 = (TPaveStats*)h[0]->GetListOfFunctions()->FindObject("stats"); st1->SetTextColor(kRed); st1->SetLineColor(kRed); st1->SetOptStat(1111111); //------------------------------ // TPaveStats *st2 = (TPaveStats*)h[1]->GetListOfFunctions()->FindObject("stats"); // st2->SetTextColor(kBlack); // st2->SetLineColor(kBlack); // st2->SetOptStat(1111111); // TPaveStats *st3 = (TPaveStats*)h[2]->GetListOfFunctions()->FindObject("stats"); // st3->SetTextColor(kBlack); // st3->SetLineColor(kBlack); // st3->SetOptStat(1111111); //------------------------------ TPaveStats *st4 = (TPaveStats*)h[3]->GetListOfFunctions()->FindObject("stats"); st4->SetTextColor(kBlack); st4->SetLineColor(kBlack); st4->SetOptStat(1111111); TPaveStats *st5 = (TPaveStats*)h[4]->GetListOfFunctions()->FindObject("stats"); st5->SetTextColor(kBlack); st5->SetLineColor(kBlack); st5->SetOptStat(1111111); // set the position of the statboxes double x1 = st1->GetX1NDC(); double y1 = st1->GetY1NDC(); double x2 = st1->GetX2NDC(); double y2 = st1->GetY2NDC(); //double xx = x2-x1; double yy = y2-y1; //-------------------------- // st2->SetX1NDC(x1); // st2->SetY1NDC(y1-yy); // st2->SetX2NDC(x2); // st2->SetY2NDC(y1); // st3->SetX1NDC(x1); // st3->SetY1NDC(y1-yy-yy); // st3->SetX2NDC(x2); // st3->SetY2NDC(y1-yy); //-------------------------- st4->SetX1NDC(x1); st4->SetY1NDC(y1-yy-yy-yy); st4->SetX2NDC(x2); st4->SetY2NDC(y1-yy-yy); st5->SetX1NDC(x1); st5->SetY1NDC(y1-yy-yy-yy-yy); st5->SetX2NDC(x2); st5->SetY2NDC(y1-yy-yy-yy); gPad->Modified(); TLegend *legend = new TLegend(.4,.91,.75,.99); legend->SetBorderSize(1); legend->SetFillColor(0); // legend->SetFillStyle(0); legend->AddEntry(h[0],"SM background","l"); //-------------------------- // legend->AddEntry(h[1],"Axigluon + W , M = 150 GeV","l"); // legend->AddEntry(h[2],"Axigluon + W , M = 500 GeV","l"); //-------------------------- legend->AddEntry(h[3],"Axigluon + W , M = 1000 GeV","l"); legend->AddEntry(h[4],"Axigluon + W , M = 1500 GeV","l"); legend->Draw(); // TLine line0(cutValue0,0,cutValue0,h[1]->GetMaximum()); // line0.SetLineColor(kRed); // line0.Draw("same"); // TLine line1(cutValue1,0,cutValue1,h[1]->GetMaximum()); // line1.SetLineColor(kRed); // line1.Draw("same"); TLatex l; l.SetTextAlign(12); l.SetTextSize(0.04); l.SetTextFont(62); l.SetNDC(); l.DrawLatex(0.6,0.8,label.c_str()); if(logY==1) c->SetLogy(); string fileName = fName; c->SaveAs(fileName.c_str()); delete legend; delete c; }