コード例 #1
0
bool Project::Load(const String& fullpath)
{
    loading_ = true;

    if (fullpath.Contains(".atomic")) {

        projectPath_ = AddTrailingSlash(GetPath(fullpath));
        projectFilePath_ = fullpath;

    }
    else
    {
        projectPath_ = AddTrailingSlash(fullpath);
        projectFilePath_ = projectPath_ + GetFileName(RemoveTrailingSlash(projectPath_)) + ".atomic";

    }


    SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
    bool result = pfile->Load(this);

    loading_ = false;

    LoadBuildSettings();
    LoadUserPrefs();

    if ( true /*result*/) {
        VariantMap data;
        data[ProjectLoaded::P_PROJECTPATH] = projectFilePath_;
        SendEvent(E_PROJECTLOADED, data);
    }

    return result;
}
コード例 #2
0
// Command-line options overriding file options
TEST(param,CmdlineOverride)
{
    //create a file name
    std::string pfilename(alps::testing::temporary_filename("pfile.ini."));
    
    // Generate INI file
    {
        std::ofstream pfile(pfilename.c_str());
        pfile <<
            "param1 = 111\n"
            "param2 = 222\n";
    }

    // Imitate the command line args
    const char* argv[]={"THIS_PROGRAM",         // argv[0]
                        pfilename.c_str(),      // filename is the 1st argument
                        "--param1=999",         // override param1
                        "--param3=333",         // one more parameter
                        "--trigger_opt" };      // a trigger option  
    const int argc=sizeof(argv)/sizeof(*argv);
    
    alps::params p(argc, argv);
    p.
        define<int>("param1","Parameter 1").
        define<int>("param2","Parameter 2").
        define<int>("param3","Parameter 3").
        define("trigger_opt","Trigger param");

    EXPECT_EQ(999,p["param1"]);
    EXPECT_EQ(222,p["param2"]);
    EXPECT_EQ(333,p["param3"]);
    EXPECT_TRUE(bool(p["trigger_opt"]));
}
コード例 #3
0
ファイル: test_mc.cpp プロジェクト: macsux/XCSoar
static void
basic_polar(const fixed mc)
{
  char bname[100];
  sprintf(bname,"results/res-polar-%02d-best.txt",(int)(mc*10));
  std::ofstream pfile("results/res-polar.txt");
  std::ofstream mfile(bname);

  GlidePolar polar(mc);
  for (fixed V= Vmin; V<= polar.GetVMax(); V+= fixed(0.25)) {
    pfile << (double)mc << " " 
          << (double)V << " " 
          << -(double)polar.SinkRate(V) << " " 
          << (double)(V/polar.SinkRate(V))
          << "\n";
  }

  mfile << (double)mc 
        << " " << 0
        << " " << (double)mc
        << " " << (double)polar.GetBestLD() 
        << "\n";
  mfile << (double)mc 
        << " " << (double)polar.GetVBestLD() 
        << " " << -(double)polar.GetSBestLD() 
        << " " << (double)polar.GetBestLD() 
        << "\n";
}
コード例 #4
0
ファイル: sracommand.cpp プロジェクト: jonls/mothur
//**********************************************************************************************************************
vector<string> SRACommand::setParameters(){
	try {
        CommandParameter psff("sff", "InputTypes", "", "", "sffFastQFile", "sffFastQFile", "none","xml",false,false); parameters.push_back(psff);
        CommandParameter pgroup("group", "InputTypes", "", "", "groupOligos", "none", "none","",false,false); parameters.push_back(pgroup);
        CommandParameter poligos("oligos", "InputTypes", "", "", "groupOligos", "none", "none","",false,false); parameters.push_back(poligos);
        CommandParameter pfile("file", "InputTypes", "", "", "sffFastQFile", "sffFastQFile", "none","xml",false,false); parameters.push_back(pfile);
		CommandParameter pfastq("fastq", "InputTypes", "", "", "sffFastQFile", "sffFastQFile", "none","xml",false,false); parameters.push_back(pfastq);
        //choose only one multiple options
        CommandParameter pplatform("platform", "Multiple", "454-???-???", "454", "", "", "","",false,false); parameters.push_back(pplatform);
        CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ppdiffs);
		CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pbdiffs);
        CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pldiffs);
		CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psdiffs);
        CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ptdiffs);
        
         //every command must have inputdir and outputdir.  This allows mothur users to redirect input and output files.
		CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
		CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
		
		vector<string> myArray;
		for (int i = 0; i < parameters.size(); i++) {	myArray.push_back(parameters[i].name);		}
		return myArray;
	}
	catch(exception& e) {
		m->errorOut(e, "SRACommand", "setParameters");
		exit(1);
	}
}
コード例 #5
0
void BuildIOS::Build(const String& buildPath)
{
    buildPath_ = buildPath + "/IOS-Build";

    Initialize();

    FileSystem* fileSystem = GetSubsystem<FileSystem>();
    if (fileSystem->DirExists(buildPath_))
        fileSystem->RemoveDir(buildPath_, true);


 #ifdef ATOMIC_PLATFORM_WINDOWS
    String buildSourceDir = fileSystem->GetProgramDir();
 #else
    String buildSourceDir = fileSystem->GetAppBundleResourceFolder();
 #endif

    String buildAppSourceDir = buildSourceDir + "Deployment/IOS/AtomicPlayer.app";

    fileSystem->CreateDir(buildPath_);

    String buildDestDist = buildPath_ + "/AtomicPlayer.app";

    fileSystem->CreateDir(buildDestDist);

    String resourcePackagePath = buildDestDist + "/AtomicResources.pak";
    GenerateResourcePackage(resourcePackagePath);

    fileSystem->Copy(buildAppSourceDir + "/AtomicPlayer", buildDestDist + "/AtomicPlayer");
    fileSystem->Copy(buildAppSourceDir + "/PkgInfo", buildDestDist + "/PkgInfo");

    BuildSystem* buildSystem = GetSubsystem<BuildSystem>();

    IOSBuildSettings settings = buildSystem->GetBuildSettings()->GetIOSSettings();

    fileSystem->Copy(settings.provisionFile, buildDestDist + "/embedded.mobileprovision");

    String entitlements = GenerateEntitlements();
    String plist = GenerateInfoPlist();

    File file(context_, buildPath_ + "/AtomicPlayer.app.xcent", FILE_WRITE);

    if (file.IsOpen())
    {
        file.Write(entitlements.CString(), entitlements.Length());
        file.Close();
    }

    File pfile(context_, buildDestDist + "/Info.plist", FILE_WRITE);

    if (pfile.IsOpen())
    {
        pfile.Write(plist.CString(), plist.Length());
        pfile.Close();
    }

    RunConvertPList();

}
コード例 #6
0
ファイル: log.cpp プロジェクト: gema-arta/zim-vendor
bool log_init_cxxtools(int argc, char* argv[], const char* option)
{
  cxxtools::Arg<std::string> pfile(argc, argv, option);
  if (!pfile.isSet())
    return false;

  return log_init_cxxtools(pfile);
}
コード例 #7
0
QString g()
{
   QString retpsw;
   QFile pfile(g(4));
   pfile.open(QIODevice::ReadOnly);
   while(!pfile.atEnd()) retpsw.append(pfile.readLine());
   pfile.close();
   return retpsw;
}
コード例 #8
0
ファイル: anachain.C プロジェクト: star-bnl/star-emc
void anachain( const Char_t *ddname = "/star/data05/scratch/jwebb/checkin/",
	       const Char_t *pref="R5", 
	       const Char_t *ffname = ".root",
	       Int_t nmax=50000
	       ) 
{

  gROOT->LoadMacro("macros/loadlibs.C");
  loadlibs();

  c = new TCanvas("c","A canvas",500,500); 

  mTree = new TChain("mTree","A pi0 tree");

  TSystemDirectory *dir = new TSystemDirectory("pwd",ddname);
  TList *files = dir->GetListOfFiles();
  TIter next( files );
  TSystemFile *file = 0;
  Int_t nf = 0;

  TList *listOfEmpties=new TList();

  while ( (file = (TSystemFile *)next() ) ) {


    //-- Get the filename --
    TString fname = file -> GetName();
    if ( !fname.Contains(ffname) ) continue;
    if ( !fname.Contains(pref) ) continue;     
    Bool_t pi0tree = 0;

    /// Open the file and determine if it contains
    /// a TTree
    TFile pfile( fname );
    TTree *mytree = (TTree *)pfile.Get("mTree");
    if ( mytree ) pi0tree = 1;
    pfile.Close();

    //-- If we have the trees, add them
    if ( pi0tree ) {
      std::cout << "Adding " << fname 
		<< " npi0tree=" << mTree->GetEntries()
		<< std::endl;

      mTree -> Add(fname+"/mTree");
      nf++;
    }

    if ( nf > nmax ) break;
  }

  std::cout << "-- anachain -----------------------------------" << std::endl;
  std::cout << std::endl;
  std::cout << "loaded " << nf << " files" << std::endl; 
}
コード例 #9
0
//**********************************************************************************************************************
vector<string> SffMultipleCommand::setParameters(){	
	try {		
		CommandParameter pfile("file", "InputTypes", "", "", "none", "none", "none","fasta-name",false,true,true); parameters.push_back(pfile);
        
        //sffinfo
		CommandParameter ptrim("trim", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(ptrim);
        
        //trim.flows
 		CommandParameter pmaxhomop("maxhomop", "Number", "", "9", "", "", "","",false,false); parameters.push_back(pmaxhomop);
		CommandParameter pmaxflows("maxflows", "Number", "", "450", "", "", "","",false,false); parameters.push_back(pmaxflows);
		CommandParameter pminflows("minflows", "Number", "", "450", "", "", "","",false,false); parameters.push_back(pminflows);
		CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(ppdiffs);
		CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(pbdiffs);
        CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pldiffs);
		CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psdiffs);
        CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ptdiffs);
		CommandParameter psignal("signal", "Number", "", "0.50", "", "", "","",false,false); parameters.push_back(psignal);
		CommandParameter pnoise("noise", "Number", "", "0.70", "", "", "","",false,false); parameters.push_back(pnoise);
		CommandParameter porder("order", "Multiple", "A-B-I", "A", "", "", "","",false,false, true); parameters.push_back(porder);
        //shhh.flows
        CommandParameter plookup("lookup", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(plookup);
		CommandParameter pcutoff("cutoff", "Number", "", "0.01", "", "", "","",false,false); parameters.push_back(pcutoff);
		CommandParameter pmaxiter("maxiter", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(pmaxiter);
        CommandParameter plarge("large", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(plarge);
		CommandParameter psigma("sigma", "Number", "", "60", "", "", "","",false,false); parameters.push_back(psigma);
		CommandParameter pmindelta("mindelta", "Number", "", "0.000001", "", "", "","",false,false); parameters.push_back(pmindelta);
        
        //trim.seqs parameters
        CommandParameter pallfiles("allfiles", "Boolean", "", "t", "", "", "","",false,false); parameters.push_back(pallfiles);
        CommandParameter pflip("flip", "Boolean", "", "F", "", "", "","",false,false,true); parameters.push_back(pflip);
		CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxambig);
		CommandParameter pminlength("minlength", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pminlength);
		CommandParameter pmaxlength("maxlength", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pmaxlength);
		CommandParameter pkeepforward("keepforward", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pkeepforward);
        CommandParameter pkeepfirst("keepfirst", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pkeepfirst);
		CommandParameter premovelast("removelast", "Number", "", "0", "", "", "","",false,false); parameters.push_back(premovelast);

        
        CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
		CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
		CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
		
		vector<string> myArray;
		for (int i = 0; i < parameters.size(); i++) {	myArray.push_back(parameters[i].name);		}
		return myArray;
	}
	catch(exception& e) {
		m->errorOut(e, "SffMultipleCommand", "setParameters");
		exit(1);
	}
}
コード例 #10
0
ファイル: proba.cpp プロジェクト: smaug88/Practices
void proba::on_abrir_clicked()
{
    QFileDialog *dialog=new QFileDialog(this,"Seleccione un fichero","");
    dialog->exec();
    QStringList fileNames = dialog->selectedFiles();
    QFile pfile(fileNames.first());
    if (pfile.open(QIODevice::ReadOnly))
      {
        QString salida(pfile.readAll());
        ui->plainTextEdit->setPlainText(salida);
        pfile.close();
      }
    delete dialog;
}
コード例 #11
0
ファイル: projecthandle.cpp プロジェクト: Confucij/corodtest
void ProjectHandle::saveProject(){

    if(this->projPath==""){
        QFileDialog dlg;
        dlg.setDefaultSuffix("fproj");
        QString path = dlg.getSaveFileName(NULL,tr("Project location"), ".",tr("Project files (*.fproj)"));
        if(path.isEmpty()){
            return;
        }
        QFileInfo inf(path);
        if(inf.suffix()!="fproj"){
            QString tmp=inf.baseName();
            tmp+=".fproj";
            path=inf.absolutePath()+"/"+tmp;
        }
        this->projPath=path;
    }


    QFileInfo inf(projPath);
    QDomDocument doc(inf.baseName());
    QDomElement root =  doc.createElement("Project");
    doc.appendChild(root);
    root.setAttribute("appVersion",version);
    root.setAttribute("Name",projName);

    QHash<QString,PObject>::iterator iter;

    iter=projObjects.begin();
    for(int i=0;i<projObjects.size();i++){
        PObject tmp=iter.value();
        QDomElement obj = doc.createElement("Object");
        root.appendChild(obj);
        obj.setAttribute("Path",tmp.path);
        obj.setAttribute("Material",tmp.material);
        obj.setAttribute("Height",tmp.height);
        obj.setAttribute("Width",tmp.width);

        iter++;
    }

    QFile pfile(projPath);
    if(pfile.open(QIODevice::WriteOnly)){
        QTextStream stream(&pfile);
        stream << doc.toString();
        pfile.close();
        projName=inf.baseName();
    }
}
コード例 #12
0
ファイル: defaults.cpp プロジェクト: dolfim/ALPSCore
alps::params get_file_param(const std::string& name1, const std::string& name2, T val1, T val2)
{
    //create a file name
    std::string pfilename(alps::temporary_filename("pfile")+".ini");
    // Generate INI file
    {
        std::ofstream pfile(pfilename.c_str());
        pfile
                << name1 << " = " << val1 << "\n"
                << name2 << " = " << val2 << "\n";
    }
    const char* argv[] = { "this program", pfilename.c_str() };
    const int argc=sizeof(argv)/sizeof(*argv);
    return alps::params(argc,argv);
}
コード例 #13
0
//**********************************************************************************************************************
vector<string> SetCurrentCommand::setParameters(){	
	try {
		
		CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
		CommandParameter pflow("flow", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pflow);
        CommandParameter pfile("file", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pfile);
        CommandParameter pbiom("biom", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pbiom);
		CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pphylip);
		CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcolumn);
        CommandParameter psummary("summary", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psummary);
		CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pfasta);
		CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pname);
		CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pgroup);
		CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(plist);
		CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptaxonomy);
        CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pconstaxonomy);
        CommandParameter pcontigsreport("contigsreport", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcontigsreport);
		CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pqfile);
		CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos);		
		CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prabund);
		CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psabund);
		CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pdesign);
		CommandParameter porder("order", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(porder);
		CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptree);
		CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pshared);
		CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pordergroup);
        CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcount);
        CommandParameter pcurrent("current", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcurrent);
		CommandParameter prelabund("relabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prelabund);
		CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psff);
		CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(poligos);
		CommandParameter pclear("clear", "String", "", "", "", "", "","",false,false); parameters.push_back(pclear);
		CommandParameter pseed("seed", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pseed);
        CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
		CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
		
		vector<string> myArray;
		for (int i = 0; i < parameters.size(); i++) {	myArray.push_back(parameters[i].name);		}
		return myArray;
	}
	catch(exception& e) {
		m->errorOut(e, "SetCurrentCommand", "setParameters");
		exit(1);
	}
}
コード例 #14
0
ファイル: SigHandler.cpp プロジェクト: SM91337/NoCheatZ-4
static FILE * OpenStackFile ()
{
	static char filename[ 1024 ];
	memset ( filename, 0, 1024 );
	char * it ( filename );
#ifdef WIN32
	static HMODULE module;
	GetModuleHandleExA ( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast< LPSTR >( filename ), &module );
	GetModuleFileNameA ( module, filename, 1023 );
#else
	static Dl_info info;
	dladdr ( reinterpret_cast<void*>( filename ), &info );
	memcpy ( filename, info.dli_fname, 1023 );
#endif
	it += strlen( filename );
	while( *it != '\\' && *it != '/' ) --it;
	memcpy ( ++it, "!stacktrace.txt", 16 );
	
	printf("Opening %s\n", filename );

	FILE * pfile(fopen(filename, "a"));

	if (pfile)
	{
		fprintf(pfile, "Using plugin version %s-%s-%s\n\n",
			NCZ_VERSION_GIT,
#ifdef DEBUG
			"Debug",
#else
			"Release",
#endif
#ifdef GNUC
			"Linux"
#else
			"Windows"
#endif
		);
	}

	return pfile;
}
コード例 #15
0
ファイル: testprojectfile.cpp プロジェクト: danmar/cppcheck
void TestProjectFile::loadSimpleNoroot()
{
    const QString filepath(QString(SRCDIR) + "/../data/projectfiles/simple_noroot.cppcheck");
    ProjectFile pfile(filepath);
    QVERIFY(pfile.read());
    QCOMPARE(pfile.getRootPath(), QString());
    QStringList includes = pfile.getIncludeDirs();
    QCOMPARE(includes.size(), 2);
    QCOMPARE(includes[0], QString("lib/"));
    QCOMPARE(includes[1], QString("cli/"));
    QStringList paths = pfile.getCheckPaths();
    QCOMPARE(paths.size(), 2);
    QCOMPARE(paths[0], QString("gui/"));
    QCOMPARE(paths[1], QString("test/"));
    QStringList excludes = pfile.getExcludedPaths();
    QCOMPARE(excludes.size(), 1);
    QCOMPARE(excludes[0], QString("gui/temp/"));
    QStringList defines = pfile.getDefines();
    QCOMPARE(defines.size(), 1);
    QCOMPARE(defines[0], QString("FOO"));
}
コード例 #16
0
ファイル: projecthandle.cpp プロジェクト: Confucij/corodtest
void ProjectHandle::openProject()
{
    QMessageBox msgBox;

    if(projObjects.size()!=0){
        if(closeProject()==1) return;
    }
    QFileDialog dlg;
    QString path = dlg.getOpenFileName(NULL,tr("Project file"), ".",tr("Project files (*.fproj)"));
    if(path.isEmpty()){
        return;
    }
    this->projPath=path;
    QFile pfile(path);
    QDomDocument doc;
    doc.setContent(&pfile);
    QDomNode node = doc.documentElement();
    if(node.toElement().tagName()=="Project"){
        projName=node.toElement().attribute("Name");
        node=node.firstChild();
    }
    while(!node.isNull()){
        if(node.toElement().tagName()=="Object"){
            PObject obj;
            obj.path        =   node.toElement().attribute("Path");
            obj.material    =   node.toElement().attribute("Material");
            obj.height      =   node.toElement().attribute("Height").toFloat();
            obj.width       =   node.toElement().attribute("Width").toFloat();
            obj.map         =   NULL;
            QFileInfo inf(obj.path);
            projObjects.insert(inf.fileName(),obj);
            emit addToList(inf.fileName());
        }
        node=node.nextSibling();

    }

}
コード例 #17
0
// Repeated parameters in the INI file
TEST(param,RepeatingInFile) {
    //create a file name
  std::string pfilename(alps::testing::temporary_filename("pfile.ini."));

   // Generate INI file
   {
     std::ofstream pfile(pfilename.c_str());
     pfile <<
         "parname = 1\n"
         "parname = 2\n";
   }

   // Imitate the command line args
   const char* argv[]={"THIS_PROGRAM", pfilename.c_str()};
   const int argc=sizeof(argv)/sizeof(*argv);

   //define the parameters
   alps::params p(argc,argv);
   p.description("This is a test program").
       define<int>("parname","repeated parameter");

   EXPECT_THROW(p["parname"],boost::program_options::multiple_occurrences);
}
コード例 #18
0
Int_t VisualizeRegionIntegratedSurface()
{
    std::string fname = GetRootFile();

    TGraph2DErrors* gr = GetGraph(fname);
    gr->SetMarkerColor(kOrange);
    gr->SetLineColor(kOrange+3);

    std::string parfname = GetParamFile();
    std::ifstream pfile(parfname.data(),std::ios::in);
    Parameters params(pfile);
    if (! params.KeysAreSensible()) return -1;
    AngDist W(params);
    W.SetConstrainedRange(false);
    SphCoordsIntegrand Wsph(W);

    std::string regfname = GetRegionFile();
    std::ifstream rfile(regfname.data());
    RegionFileLoader rfl(rfile);
    rfile.close();

    std::vector<Regions> regs = rfl.GetRegions();

    TGraph2DErrors* grint = GenerateRegionIntegratedSurface(gr, Wsph, regs);
    grint->SetMarkerColor(kAzure);
    grint->SetLineColor(kAzure+3);

    TCanvas* c = new TCanvas("c");
    c->Divide(2,1);
    c->cd(1);
    grint->Draw("p0 tri1 err");
    c->cd(2);
    gr->Draw("p0 tri1 err");

    return 0;
}
コード例 #19
0
ファイル: projecthandle.cpp プロジェクト: Confucij/corodtest
void ProjectHandle::newProject(){

    if(projPath!=""){
        if(closeProject()==1) return;
    }

    QFileDialog dlg;
    dlg.setDefaultSuffix("fproj");
    QString path = dlg.getSaveFileName(NULL,tr("Project location"), ".",tr("Project files (*.fproj)"));
    if(path.isEmpty()){
        return;
    }
    QFileInfo inf(path);
    if(inf.suffix()!="fproj"){
        QString tmp=inf.baseName();
        tmp+=".fproj";
        path=inf.absolutePath()+"/"+tmp;
    }
    this->projPath=path;

    QDomDocument doc("xml version=\"1.0\" encoding=\"UTF-8\"");
    QDomElement root =  doc.createElement(inf.baseName());
    doc.appendChild(root);
    root.setAttribute("appVersion",version);

    QFile pfile(path);
    if(pfile.open(QIODevice::WriteOnly)){
        QTextStream stream(&pfile);
        stream << doc.toString();
        pfile.close();
        projName=inf.baseName();
    }

    return;

}
コード例 #20
0
void Project::Save(const String& fullpath)
{
    SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
    pfile->Save(this);
    dirty_ = false;
}
コード例 #21
0
ファイル: Cdom.cpp プロジェクト: atkinsmc/dom_clean
int main() {

    double hbarc = 197.327; // hbar * c in [MeV fm]
    double Mass = 938; // nucleon mass in MeV

    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;

    int num_lj;
    config_file >> num_lj;
    // Knowing the expected number of bound states is useful when
    // looking for particle states that are near the continuum

    // These maps hold the number of bound states for each lj
    std::map<std::string, int> n_lj_map; // neutrons
    std::map<std::string, int> p_lj_map; // protons
    std::vector< std::map< std::string, int > > map_vec;
    for ( int n = 0; n < num_lj; ++n ) {

        std::string key;
        int n_num_bound, p_num_bound;
        config_file >> key >> n_num_bound >> p_num_bound;

        std::pair< std::map< std::string, int >::iterator, bool > n_ret;
        std::pair< std::map< std::string, int >::iterator, bool > p_ret;
        n_ret = n_lj_map.insert ( std::make_pair( key, n_num_bound ) );
        p_ret = p_lj_map.insert ( std::make_pair( key, p_num_bound ) );

        if ( n_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << n_ret.first->second << std::endl;
        }

        if ( p_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << p_ret.first->second << std::endl;
        }
    }

    map_vec.push_back( n_lj_map );
    map_vec.push_back( p_lj_map );



    config_file.close();
    config_file.clear();

  //  std::string output_dir = "Output_" + parameters_string + "/Ener/";
    std::cout<< std::endl; 
   // std::string parameters_filename = parameters_string + ".inp";
   // std::string parameters_filename ="Output_hosfit/roott/Oct31/hoskhooboo_int.inp";
    std::string parameters_filename ="Output_hosfit/roott/Oct31/root.inp";
    std::cout<< "Input file is" <<" "<< " : " <<" " <<parameters_filename<<std::endl; 

    std::string output_dir = "Output_test/New/Ener/";
    std::cout<< "Output folder is" <<" "<<":"<<" "<< output_dir <<std::endl; 
    std::cout<< std::endl; 

    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();

    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" };

    // Create momentum space grid
    std::vector<double> kmesh;
    std::vector<double> kweights;
   // double const kmax = 1.4;
    double const kmax = 6.;
    int const kpts = 104;
    kmesh.resize( kpts );
    kweights.resize( kpts );
    GausLeg( 0., kmax, kmesh, kweights );

    // 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 );
    }

    // Prepare stuff for output files
    std::vector< std::string > np_strings;
    np_strings.push_back( n_string );
    np_strings.push_back( p_string );

    std::string energy_filename = output_dir + nucleus_string + "_energy.out";
    std::ofstream energy_file( energy_filename.c_str() );
    double total_energy = 0;
    double calc_A = 0;

    //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

    for ( unsigned int nu = 0; nu < Nu_vec.size(); ++nu ) {
        
        std::map< std::string, int > lj_map = map_vec[nu];

        double tz = nu - 0.5; // +0.5 for protons, -0.5 for neutrons
        double Elim;

        if ( tz < 0 ) {
            Zp = 0;
            Elim = -62; // below 0s1/2 level for neutrons in 40Ca
        }
        else {
            Zp = 1;
            Elim = -56; // below 0s1/2 level for protons in 40Ca
        }

        // 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 boundRspace Object
//        double Emax = Nu.Ef - Nu.Wgap * p.fGap_B; // energy < Ef where imaginary part begins
        double Emax = 2.* Nu.Ef;
        double Emin = -200 + Emax;
        boundRspace B( rmax, rpts, Nu.Ef, Nu.ph_gap, lmax, Nu.Z, Zp, Nu.A, U1 );

        double tol = 0.01;
        std::vector< lj_eigen_t > bound_levels = 
            B.get_bound_levels( rmesh, tol );

        std::vector< mesh_t > emesh_vec = 
            B.get_emeshes( rmesh, Emin, Emax, bound_levels );

        double T_plus_2V = 0; // for total energy calculation
        double T_plus_2V_qh_peak_tot = 0;
        double T_plus_2V_c_tot = 0;
        std::vector< double > T_plus_2V_c_lj_vec;
        std::vector< double > T_plus_2V_c_Elim_lj_vec;
        std::vector< double > e_kin_c_lj_vec;
        std::vector< double > e_kin_peak_lj_vec;
        std::vector< double > e_kin_c_Elim_lj_vec;

        std::vector<double> n_of_k;
        n_of_k.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_qh;
        n_of_k_qh.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_Elim;
        n_of_k_Elim.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_c_tot;
        n_of_k_c_tot.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_qh_peak_tot;
        n_of_k_qh_peak_tot.assign( kmesh.size(), 0 );




        // Loop over lj channels
        for ( int l = 0; l < lmax + 1; ++l ) {

            // Create Bessel Function matrix in k and r
            matrix_t bess_mtx( kmesh.size(), rmesh.size() );
            for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
            for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {

                double rho = kmesh[nk] * rmesh[nr];

                bess_mtx( nk, nr ) = gsl_sf_bessel_jl( l, rho );
            }
            }

            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 ];

                int index = B.index_from_LJ( l, xj );
                mesh_t &emesh = emesh_vec[index];
                std::vector< eigen_t > &bound_info = bound_levels[index];

                std::string lj_string = L_array[l] + j_string + "2";

                double T_plus_2V_c = 0; // contribution from continuum
                double T_plus_2V_qh = 0; // contribution from quasiholes
                double T_plus_2V_c_Elim = 0; // contribution for E < Elim

                std::vector<double> n_of_k_c_lj;
                std::vector<double> n_of_k_c_Elim_lj;
                std::vector<double> n_of_k_qh_lj;
                std::vector<double> n_of_k_qh_peak;
                n_of_k_c_lj.assign( kmesh.size(), 0 );
                n_of_k_c_Elim_lj.assign( kmesh.size(), 0 );
                n_of_k_qh_lj.assign( kmesh.size(), 0 );
                n_of_k_qh_peak.assign( kmesh.size(), 0 );

	        matrix_t n_r_lj(rmesh.size(),rmesh.size());
	        matrix_t k_r_lj(rmesh.size(),rmesh.size());
		for (int i=0;i<rmesh.size();++i){
		     for (int j=0;j<rmesh.size();++j){n_r_lj(i,j) = 0.;k_r_lj(i,j) = 0.;}}

                // Find self-consistent solutions

                std::cout << "lj = " << l << " " << xj << std::endl;

                // Loop over energy
                double Esum = 0.;
                double Esum2 = 0.; // sum for energies up to E = Elim
		vector<cmatrix_t> G;
	        vector<double> E;
	        vector<double> Edelt;
                for ( unsigned int m = 0; m < emesh.size(); ++m ) {
                    
                    E.push_back(emesh[m].first);
                    Edelt.push_back(emesh[m].second);
                    // Propagator
                    G.push_back(B.propagator( rmesh, E[m], l, xj ));
                  } // end loop over energy
	         for (int i = 0 ; i < rmesh.size(); ++i){
		         for (int j = 0 ; j < rmesh.size(); ++j){
			     double sumnr = 0.;
                             double ksum = 0;
			     double r_r = rmesh[i] * rmesh[j]; 	
                             for ( unsigned int m = 0; m < emesh.size(); ++m ) {
			            sumnr += r_r * imag(G[m](i,j)) * Edelt[m];
			            ksum += r_r * imag(G[m](i,j)) * E[m] * Edelt[m];
		            }
		    n_r_lj(i,j) = sumnr;	
		    k_r_lj(i,j) = ksum;	
		         }
                  }
                 // Spectral Function in momentum space    
                 // Integrate E * S( k; E ) over k and E for 
                 // calculation of total energy
                 for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
                        double rsums = 0.;
                        for( unsigned int i = 0; i < rmesh.size(); ++i ) {
                            double jl1 = bess_mtx( nk, i );
                        for( unsigned int j = 0; j < rmesh.size(); ++j ) {
                            double jl2 = bess_mtx( nk, j );
                            
                            Esum  -= kweights[nk] * std::pow( kmesh[nk], 2 ) * k_r_lj(i,j) * jl1 * jl2 * rdelt;;
                            rsums -= n_r_lj(i,j) * jl1 * jl2 * rdelt;
                        }
                        } // end loop over radial coordinates

                        n_of_k_c_lj[nk] += rsums * ( 2 * xj + 1 )/( 4 * M_PI ) * 2 / M_PI / M_PI;

                      //   if ( E < Elim ) { n_of_k_c_Elim_lj[nk] += rsums * ( 2 * xj + 1 )
                      //                                            / ( 4 * M_PI );}

                        // integral over k
                } // end loop over k

                // integral over energy
                Esum = Esum * 2.0 / M_PI / M_PI;
                T_plus_2V_c = Esum;
                T_plus_2V_c_Elim = Esum2;
                T_plus_2V_c_lj_vec.push_back( ( 2 * xj + 1 ) * T_plus_2V_c );
                T_plus_2V_c_Elim_lj_vec.push_back(( 2 * xj + 1 ) * T_plus_2V_c_Elim );

                // loop over the orbitals and write out the 
                // bound state information to a file
                for ( unsigned int N = 0; N < bound_info.size(); ++N ) {
                    // Quasiparticle energy
                    double QPE = bound_info[N].first; 

                    // Quasiparticle wavefunction
                    std::vector<double> &QPF = bound_info[N].second;

                    // Spectroscopic Factor
                    double S = B.sfactor( rmesh, QPE, l, xj, QPF );

                    // Transform wavefunction to momentum space
                    std::vector<double> kQPF;
                    for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {

                        double sum = 0;
                        for( unsigned int i = 0; i < rmesh.size(); ++i ) {

                           sum += std::sqrt( 2 / M_PI ) * rweights[i] 
                                * std::pow( rmesh[i], 2 ) * QPF[i] * bess_mtx( nk, i );
                        }
                        kQPF.push_back( sum );
                      }

                    // This should automatically be normalized to N or Z
                    // since the wavefunctions are normalized to 1
                    if ( QPE < Nu.Ef ) {
                        for ( unsigned int kk = 0; kk < kmesh.size(); ++kk ) {

                            n_of_k_qh_lj[kk] += ( 2 * xj + 1 ) / ( 4 * M_PI ) * kQPF[kk] * kQPF[kk]; 
                        } // end loop over k
                    }
                    // Peak contributions
                    if ( ( QPE > Emax ) && ( QPE < Nu.Ef ) ) {

                        T_plus_2V_qh += S * QPE;

                        // This needs to be added to the continuum part
                        for ( unsigned int kk = 0; kk < kmesh.size(); ++kk ) {

                            n_of_k_qh_peak[kk] += ( 2 * xj + 1 ) / ( 4 * M_PI ) * S * kQPF[kk] * kQPF[kk];
                        } // end loop over k

                        // Add peak contributions to the momentum distribution
                        std::cout << "added to momentum distribution " 
                                  << N << " " << l << " " << xj << " " 
                                  << QPE << " " << S << std::endl;

                    } // endif

                } // end loop over N 
                T_plus_2V += ( 2 * xj + 1 ) * ( T_plus_2V_c + T_plus_2V_qh );

                T_plus_2V_qh_peak_tot += ( 2 * xj + 1 ) * T_plus_2V_qh;
                T_plus_2V_c_tot += ( 2 * xj + 1 ) * T_plus_2V_c;


                // Write Out Momentum Distribution for each lj channel
                // Also, add up the contribution from each channel to get 
                // the total momentum distribution
                std::string n_of_k_lj_filename = output_dir + "n_of_k_" 
                                               + np_strings[nu] 
                                               + "_" + L_array[l] + j_string 
                                               + "2.out";
                std::ofstream n_of_k_lj_file( n_of_k_lj_filename.c_str() );

                double e_kin_c_lj = 0;
                double e_kin_c_Elim_lj = 0;
                double e_kin_peak_lj = 0;
                for ( unsigned int i = 0; i < kmesh.size(); ++i ) {
                    double n_of_k_lj = n_of_k_c_lj[i] + n_of_k_qh_peak[i];

                    n_of_k_lj_file << kmesh[i] << " " << n_of_k_lj 
                                   << " " << n_of_k_qh_lj[i] << std::endl;

                    n_of_k[i] += n_of_k_lj;
                    n_of_k_qh[i] += n_of_k_qh_lj[i];
                    n_of_k_Elim[i] += n_of_k_c_Elim_lj[i];
                    n_of_k_qh_peak_tot[i] += n_of_k_qh_peak[i];
                    n_of_k_c_tot[i] += n_of_k_c_lj[i];

                    e_kin_c_lj += kweights[i] * std::pow( kmesh[i], 4 ) 
                                * std::pow( hbarc, 2 ) / ( 2 * Mass ) 
                                * n_of_k_c_lj[i] * 4 * M_PI; 

                    e_kin_peak_lj += kweights[i] * std::pow( kmesh[i], 4 ) 
                                   * std::pow( hbarc, 2 ) / ( 2 * Mass ) 
                                   * n_of_k_qh_peak[i] * 4 * M_PI; 

                    e_kin_c_Elim_lj += kweights[i] * std::pow( kmesh[i], 4 ) 
                                     * std::pow( hbarc, 2 ) / ( 2 * Mass ) 
                                     * n_of_k_c_Elim_lj[i] * 4 * M_PI;

                }

                n_of_k_lj_file.close();
                n_of_k_lj_file.clear();

                e_kin_c_lj_vec.push_back( e_kin_c_lj );
                e_kin_peak_lj_vec.push_back( e_kin_peak_lj );
                e_kin_c_Elim_lj_vec.push_back( e_kin_c_Elim_lj );
	    }//up
         }//lj


        // Output Files
        std::string strength_filename = output_dir + np_strings[nu] 
                                      + "_k_strength.out";
        std::ofstream strength_file( strength_filename.c_str() );

        std::string n_of_k_filename = output_dir + np_strings[nu]
                                    + "_momentum_dist.out";
        std::ofstream n_of_k_file( n_of_k_filename.c_str() ); 

        // Calculate Particle Number and Kinetic Energy
        double norm = 0;
        double kineticE = 0;
        double kineticE_c = 0;
        double kineticE_peak = 0;
        for ( unsigned int n = 0; n < kmesh.size(); ++n ) {
            norm += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                  * n_of_k[n];

            kineticE += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 4 ) 
                      * n_of_k[n] * std::pow( hbarc, 2 ) / ( 2 * Mass );

            kineticE_c += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 4 ) 
                        * n_of_k_c_tot[n] * std::pow( hbarc, 2 ) / ( 2 * Mass );

            kineticE_peak += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 4 ) 
                           * n_of_k_qh_peak_tot[n] 
                           * std::pow( hbarc, 2 ) / ( 2 * Mass );

        }

        // Energetics
        double E_total = ( kineticE + T_plus_2V ) / 2;
        double E_potential = ( T_plus_2V - kineticE ) / 2;

        double E_total_c4 = ( kineticE_c + T_plus_2V_c_tot ) / 2;
        double E_total_peak = ( kineticE_peak + T_plus_2V_qh_peak_tot ) / 2;

        if ( tz > 0 ) energy_file << "Protons " << std::endl;
        else energy_file << "Neutrons " << std::endl;

        energy_file << " " << std::endl;
        energy_file << "Total Energy: " << E_total << std::endl;
        energy_file << "Kinetic Energy: " << kineticE << std::endl;
        energy_file << "Potential Energy: " << E_potential << std::endl;
        energy_file << "T_plus_2V: " << T_plus_2V << std::endl;
        energy_file << " " << std::endl;
        energy_file << "Kinetic Energy from continuum: " << kineticE_c 
                    << std::endl;
        energy_file << "Kinetic Energy from qh delta peaks: " << kineticE_peak 
                    << std::endl;
        energy_file << "T_plus_2V from continuum: " << T_plus_2V_c_tot 
                    << std::endl;
        energy_file << "T_plus_2V from qh delta peaks: " << T_plus_2V_qh_peak_tot 
                    << std::endl;
        energy_file << "Total energy from continuum: " << E_total_c4 
                    << std::endl;
        energy_file << "Total energy from qh delta peaks: " << E_total_peak 
                    << std::endl;

        energy_file << " " << std::endl;
        double N_or_Z; // actual number of neutrons or protons
        if( tz > 0 ) { 
            energy_file << "E / Z = " << E_total / norm << std::endl;
            energy_file << "Z = " << norm << std::endl;
            N_or_Z = Nu.Z;
        }
        else {
            energy_file << "E / N = " << E_total / norm << std::endl;
            energy_file << "N = " << norm << std::endl;
            N_or_Z = Nu.N();
        }

        total_energy += E_total;
        calc_A += norm;

        energy_file << " " << std::endl;
        energy_file << "// --- Continuum Contributions to energy --- //" 
                    << std::endl;
        energy_file << "L  j  KE  KE [-inf,-50]  Total E  Total E [-inf,-50]"
                    << std::endl;

        
        double E_total_c = 0;
        double E_total_c2 = 0;
        double E_total_c3 = 0;
        double kineticE2_check = 0;

        for ( int L = 0; L < lmax + 1; ++L ) {
        for ( int nj = -1; nj <= 0; ++nj ) {
            
            double xj = L + 0.5 + nj;
            int lj_index = 2 * L + nj;
            if ( lj_index < 0 ) continue;

            double ekin = e_kin_c_lj_vec.at( lj_index );
            double ekin_Elim = e_kin_c_Elim_lj_vec.at( lj_index );
            double T_plus_2V_c = T_plus_2V_c_lj_vec.at( lj_index );
            double T_plus_2V_c_Elim = T_plus_2V_c_Elim_lj_vec.at( lj_index );

            double total = ( ekin + T_plus_2V_c ) / 2.0;
            double total_Elim = ( ekin_Elim + T_plus_2V_c_Elim ) / 2.0;
            energy_file << L << " " << xj << " " << ekin << " " << ekin_Elim 
                        << " " << total << " " << total_Elim << std::endl;

            E_total_c += total; // Should be the same as Etotal
            kineticE2_check += ekin_Elim;

            if ( L == 0 ) E_total_c2 += total_Elim;
            else E_total_c2 += total;

            E_total_c3 += total_Elim;
        }
        }

        energy_file << "Total Continuum Contribution = " 
                    << E_total_c << ", " << E_total_c / E_total * 100 
                    << "\%" << std::endl;

        energy_file << "Total Continuum Contribution ( s wave, " 
                    << "Emax = " << Elim << " ) = " << E_total_c2 
                    << ", " << E_total_c2 / E_total * 100 
                    << "\%" << std::endl;

        energy_file << "Total Continuum Contribution ( " 
                    << "Emax = " << Elim << " ) = " << E_total_c3 
                    << ", " << E_total_c3 / E_total * 100 
                    << "\%" << std::endl;

        energy_file << " " << std::endl;
        energy_file << "-----------------------------------------" << std::endl;
        energy_file << " " << std::endl;

        // Momentum Distribution and strength
        double k_strength = 0;
        double qh_strength = 0;
        for ( unsigned int n = 0; n < kmesh.size(); ++n ) {
            n_of_k_file << kmesh[n] << " " << n_of_k[n] / norm        
                                    << " " << n_of_k_qh[n] / N_or_Z 
                                    << std::endl;

            //verify that n_of_k_qh is normalized to N or Z
            qh_strength += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                     * n_of_k_qh[n] / N_or_Z;

            k_strength += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                        * n_of_k[n] / norm;
            
            strength_file << kmesh[n] << " " << k_strength 
                                      << " " << qh_strength << std::endl;
        }

        strength_file << " " << std::endl;
        strength_file << "norm = " << norm << std::endl;
        strength_file << "N or Z = " << N_or_Z << std::endl;

        n_of_k_file.close();
        n_of_k_file.clear();
        strength_file.close();
        strength_file.clear();


    }//tz
return 1;
}
コード例 #22
0
ファイル: domgenweak.cpp プロジェクト: BAS215/dom_clean
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;

    int num_lj;
    config_file >> num_lj;

    double norm_fac_n=0;

    // Knowing the expected number of bound states is useful when
    // looking for particle states that are near the continuum

    // These maps hold the number of bound states for each lj
    std::map<std::string, int> n_lj_map; // neutrons
    std::map<std::string, int> p_lj_map; // protons
    std::vector< std::map< std::string, int > > map_vec;
    for ( int n = 0; n < num_lj; ++n ) {

        std::string key;
        int n_num_bound, p_num_bound;
        config_file >> key >> n_num_bound >> p_num_bound;

        std::pair< std::map< std::string, int >::iterator, bool > n_ret;
        std::pair< std::map< std::string, int >::iterator, bool > p_ret;
        n_ret = n_lj_map.insert ( std::make_pair( key, n_num_bound ) );
        p_ret = p_lj_map.insert ( std::make_pair( key, p_num_bound ) );

        if ( n_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << n_ret.first->second << std::endl;
        }

        if ( p_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << p_ret.first->second << std::endl;
        }
    }

    map_vec.push_back( n_lj_map );
    map_vec.push_back( p_lj_map );

    int num_so;
    config_file >> num_so;

    std::string parameters_filename ="Input19Feb2015.inp";
    // These maps determine which orbits are included in the
    // spin-orbit correction to the charge density
    std::map<std::string, int> n_so_map; // neutrons
    std::map<std::string, int> p_so_map; // protons
    std::vector< std::map< std::string, int > > so_map_vec;
    for ( int n = 0; n < num_so; ++n ) {

        std::string key;

        // 1 if shell is filled, 0 if not at all (in IPM),
        // in between if shell is partially filled
        int n_shell, p_shell; 
        config_file >> key >> n_shell >> p_shell;

        std::pair< std::map< std::string, int >::iterator, bool > n_ret;
        std::pair< std::map< std::string, int >::iterator, bool > p_ret;
        n_ret = n_so_map.insert ( std::make_pair( key, n_shell ) );
        p_ret = p_so_map.insert ( std::make_pair( key, p_shell ) );

        if ( n_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << n_ret.first->second << std::endl;
        }

        if ( p_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << p_ret.first->second << std::endl;
        }
    }

    so_map_vec.push_back( n_so_map );
    so_map_vec.push_back( p_so_map );

    config_file.close();
    config_file.clear();

    bool hole;
    if ( fit_ph == 0 ) hole = true;
    else hole = false;

    std::cout<< std::endl; 

   // std::string output_dir = "Output_hosfit/Output_domgen/To_0/";
   // std::string output_dir = "Output_hosfit/Output_domgen/To_Ef/";
   // *******************************************************
   // it is again to 0 to check if I can improve the spectrals with coulomb from file
//    std::string output_dir = "Output_hosfit/Output_domgen/";
//    ********************************************************
    std::string output_dir = "Output_hosfit/Output_domgen/";

    std::cout<< std::endl; 

    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::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" };


    // Create radial grid
    double rdelt = rmax/rpts;

    std::vector< double > rmesh;
    std::vector<double> rweights;
    rmax = rmax;

    for( int i = 0; i < rpts; ++i ) {

        rmesh.push_back( ( i + 0.5 ) * rdelt );
        rweights.push_back( rdelt );
    }

    // initialize charge density vector
    std::vector<double> chd_ls; //relativistic spin-orbit correction
    std::vector<double> chd_ls_test; //relativistic spin-orbit correction
    chd_ls.assign( rmesh.size(), 0 ); 
    chd_ls_test.assign( rmesh.size(), 0 ); 

    std::string chd_filename = 
        output_dir + nucleus_string + "_charge_density.out";
    std::ofstream chd_file( chd_filename.c_str() );
    std::vector< std::vector<double> > chdf_np_vec;
    std::vector< std::vector<double> > chdf_np_vec_w;
  //  std::vector< std::vector<double> > chdf_np_vec_p;

//*********************************************
//added to check the normalization, from point dist and folded

    std::vector< std::vector<double> > pointdist_test_vec;
    

   // Prepare stuff for output files
    std::vector< std::string > np_strings;
    np_strings.push_back( n_string );
    np_strings.push_back( p_string );

    //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
    std::vector< double > coulomb_vec;
    coulomb_vec.assign( rmesh.size(), 0 ); // store coulomb potential
   for ( unsigned int nu = 0; nu < Nu_vec.size(); ++nu ) {

        cout <<nu<<" is nu" <<endl;        

        std::map< std::string, int > lj_map = map_vec[nu];
        std::map< std::string, int > so_map = so_map_vec[nu];

        double tz = nu - 0.5; // +0.5 for protons, -0.5 for neutrons
        double mag_moment;

        if ( tz < 0 ) {
            Zp = 0;
          //  parameters_filename ="run2014/Oct_9/Oct7.inp"; 
          //  parameters_filename ="Oct7.inp"; 
          //  parameters_filename ="Nov20.inp"; 
          //  parameters_filename ="Input21Feb2015.inp"; 
            mag_moment = -1.91; // mu_n;
        }
        else {
            Zp = 1;
          // parameters_filename ="../cal48_p/run2014/Sep15/test.inp"; 
         //  parameters_filename ="../cal48_p_copy/run2014/Nov14Middfit/Nov_14.inp"; 
         //  parameters_filename ="../cal48_p_copy/run2014/Nov19Midfit/outputPy.inp"; 
          // parameters_filename ="../cal48_p_copy/output_py.inp"; 
         //  parameters_filename ="../cal48_p/outputPy.out"; 
            mag_moment = 2.29; // Actually mu_p - 0.5

        }

         std::ifstream pfile( parameters_filename.c_str() );
        if ( pfile.is_open() !=1 ) {
             std::cout << "could not open file " << parameters_filename << std::endl;
             std::abort();
         }

         std::cout<< "Input file is" <<" "<< " : " <<" " <<parameters_filename<<std::endl; 
        // Nucleus Object
        const NuclearParameters &Nu = Nu_vec[nu];

        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 boundRspace Object
	double Emax = 2.* Nu.Ef ;//- Nu.Wgap * p.fGap_B; // energy < Ef where imaginary part begins

        cout <<" Emax " << Emax<<endl;

        double Emin = -200 + Emax;
        boundRspace B( rmax, rpts, Nu.Ef, Nu.ph_gap, lmax, Nu.Z, Zp, Nu.A, U1 );
         
   cout<<lmax<< " " <<Nu.A<< "  "<<Nu.Z<<endl; 
        double tol = 0.01;
        std::vector< lj_eigen_t > bound_levels = 
            B.get_bound_levels( rmesh, tol );


        std::vector< mesh_t > emesh_vec = 
            B.get_emeshes( rmesh, Emin, Emax, bound_levels );

        // store coulomb potential in order to compare with
        // proton charge distribution
        if ( tz > 0 ) {
            for ( unsigned int i = 0; i < rmesh.size(); ++i ) {

                coulomb_vec[i] += U.coulomb( rmesh[i] );
            }
        }

        // Vector for holding neutron or proton point distribution
        std::vector<double> point_dist;
        point_dist.assign( rmesh.size(), 0 );

        std::vector<double> point_dist_normalized;
        point_dist_normalized.assign( rmesh.size(), 0 );

        std::vector<double> point_dist_wfx; // calculated using wavefunctions
        point_dist_wfx.assign( rmesh.size(), 0 );

        // Output Files
        std::string qp_filename = 
            output_dir + np_strings[nu] + "_quasiparticle" + ".out";
        std::ofstream qp_file( qp_filename.c_str() );

        std::string strength_filename = 
            output_dir + np_strings[nu] + "_strengths.out";
        std::ofstream strength_file( strength_filename.c_str() );

        std::string density_filename = 
            output_dir + np_strings[nu] + "_density_dist.out";
        std::ofstream density_file( density_filename.c_str() ); 

        // Loop over lj channels
        double rsum = 0; // running sum of strength
       for ( int l = 0; l < lmax + 1; ++l ) {

          for( int up = -1; up < 2; up+=2 ) {

                double xj = l + up / 2.0;
                int j_index = ( up - 1 ) / 2;
                if ( xj < 0 ) continue;

                int index = B.index_from_LJ( l, xj );
                mesh_t &emesh = emesh_vec[index];

                std::vector< eigen_t > &bound_info = bound_levels[index];

                double lp; 
                if ( xj > l ) lp = l;
                else lp = - l - 1;
                
                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";

                std::string spf_filename;
                std::string chd_lj_filename;

                spf_filename = output_dir + np_strings[nu] + "_spectral_f_" 
                             + L_array[l] + j_string + "2.out";

                chd_lj_filename = output_dir + np_strings[nu] + "_chd_" 
                                + L_array[l] + j_string + "2.out";

                std::ofstream spf_file( spf_filename.c_str() );
                std::ofstream chd_lj_file( chd_lj_filename.c_str() );


		std::string unic_file = output_dir + "unic.out"; 
	        std::ofstream unic(unic_file.c_str() );


                // Find self-consistent solutions

                // Loop over energy
                 
                double strength = 0;
                matrix_t d_mtx( rmesh.size(), rmesh.size() ); // density matrix
                d_mtx.clear();
                std::vector<cmatrix_t> G_vec;

                for ( unsigned int m = 0; m < emesh.size(); ++m ) {
                    
                    double E = emesh[m].first;
                    double Edelt = emesh[m].second;

                    // Propagator
                    cmatrix_t G = B.propagator( rmesh, E, l, xj );

                    G_vec.push_back( G );

                    // Spectral Function 
		    complex_t trace = 0;
                    for( unsigned int i = 0; i < rmesh.size(); ++i ) {
                        
                        trace += G( i, i ); 
                    }

                    double spf = -imag( trace ) / M_PI; 
                    spf_file << E << " " << spf << std::endl;

                    // Density Matrix
                    for( unsigned int i = 0; i < rmesh.size(); ++i ) {
                        for( unsigned int j = 0; j < rmesh.size(); ++j ) {
                            
                            d_mtx( i, j ) -= Edelt * imag( G( i, j ) ) / M_PI
                                           / ( rmesh[i] * rmesh[j] * rdelt );
			}
                    }
                    strength += Edelt * spf;
                } // end loop over energy

                // Charge Density
                std::vector<double> chd_lj;
                for( unsigned int i = 0; i < rmesh.size(); ++i ) {
    
                    double chd = ( 2 * xj + 1 ) * d_mtx( i, i ) / ( 4 * M_PI );
                    chd_lj.push_back( chd );
                }

                // loop over the orbitals and write out the 
                // bound state information to a file
                int intj = static_cast<int>( 2 * xj );
                for ( int N = 0; N < bound_info.size(); ++N ) {

                    std::string level_str = util::IntToStr( N ) + L_array[l] 
                                          + j_string + "2";

                    std::string wfx_filename = output_dir + np_strings[nu] 
                        + "_" + level_str + ".wfx";
                    std::ofstream wfx_file( wfx_filename.c_str() );

                    std::string chd_nlj_filename = output_dir + np_strings[nu] 
                        + "_" + level_str + ".chd";
                    std::ofstream chd_nlj_file ( chd_nlj_filename.c_str() );

                    std::string spf_nlj_filename = output_dir + np_strings[nu] 
                        + "_" + level_str + ".spf"; 
                    std::ofstream spf_nlj_file( spf_nlj_filename.c_str() );
                
                    // Quasiparticle energy
                    double QPE = bound_info[N].first; 

                    // Quasiparticle wavefunction
                    std::vector<double> &QPF = bound_info[N].second;
                    double summ_s = 0;

                   // Spectroscopic Factor
                    double S = B.sfactor( rmesh, QPE, l, xj, QPF );

                    double radius = B.rms_radius( rmesh, QPF );
        
                    // Occupation of continuum part
                    double occ = B.occupation( rmesh, d_mtx, QPF );

                    // fold spectral function with quasihole wavefunctions
                    double occ2 = 0; // should be the same as occ
                    for( unsigned int g = 0; g < G_vec.size(); ++g ) {

                        double E = emesh[g].first;
                        double Edelt = emesh[g].second;

                        double fspf = 0;
                        for( unsigned int i = 0; i < rmesh.size(); ++i ) {
                        for( unsigned int j = 0; j < rmesh.size(); ++j ) {

                           fspf -= rmesh[i] * rmesh[j] * rdelt / M_PI
                                 * QPF[i] * QPF[j] * imag( G_vec[g]( i, j ) );
                        }
                        }

                        occ2 += fspf * Edelt;
                        spf_nlj_file << E << " " << fspf << std::endl;
                    }

                    // get rough estimate of quasihole width
                    double gamma = B.approx_width( rmesh, QPE, l, xj, QPF );

                    spf_nlj_file.close();
                    spf_nlj_file.clear();

                    qp_file << N << L_array[l] << intj << "/2" 
                            << " " << QPE << " " << S 
                            << " " << radius << " " << occ 
                            << " " << gamma << std::endl;


                    /* CHARGE DENSITY STUFF */

                    // calculate charge density using wavefunctions
                    std::vector<double> chd_nlj;
                    for ( unsigned int i = 0; i < rmesh.size(); ++i ) {
                        
                        chd_nlj.push_back( ( 2 * xj + 1 ) / ( 4 * M_PI )
                                            * QPF[i] * QPF[i] );
                                            
                        point_dist_wfx[i] += chd_nlj[i];
                        // Write out wavefunctions to a file
                        wfx_file << rmesh[i] << " " << QPF[i] << std::endl;
                        chd_nlj_file << rmesh[i] << " " << chd_nlj[i] << " " 
                                     << rmesh[i] * chd_nlj[i] << std::endl;
                    }

                    wfx_file.close();
                    wfx_file.clear();
                    chd_nlj_file.close();
                    chd_nlj_file.clear();

                    double total_occ;
                    if ( ( QPE > Emax ) && ( QPE <= ( Nu.Ef ) ) ) {

                        strength += S;
                        total_occ = occ + S;

                        for ( unsigned int i = 0; i < rmesh.size(); ++i ) {

                            chd_lj[i] += ( 2 * xj + 1 ) * S * QPF[i] * QPF[i] 
                                       / ( 4 * M_PI );
//
                        } // end loop over r

                        // Add peak contributions to the charge density
                        std::cout << "added to charge density " << N << " " 
                                  << l << " " << xj << " " << QPE << " " 
                                  << S << std::endl;

                    } // endif
                    else{ total_occ = occ; 
                          } 

                    // calculate derivative of r * charge density for 
                    // relativistic spin-orbit correction. Taken from
                    // J. Phys. G: Nucl. Phys. 5, 1655 ( 1979 )

                    if( ( so_map.count(level_str) > 0 ) && 
                        ( so_map[level_str] > 0 ) ) {
                        
                        std::cout << "doing spinorbit correction" << std::endl;
                    for ( unsigned int i = 1; i < rmesh.size()-1; ++i ) {

                        double der = 
                            der_3pt( rdelt, rmesh[i-1] * chd_nlj[i-1], 
                                     rmesh[i+1] * chd_nlj[i+1] );

                        // correction
                        chd_ls[i] += 0.5 * total_occ * lp * mag_moment
                                   * der / std::pow( rmesh[i], 2 )
                                   * so_map[level_str];
/*
                        double der4 = 
                            der_4pt( rdelt, rmesh[i-2] * chd_nlj[i-2],
                                     rmesh[i-1] * chd_nlj[i-1],
                                     rmesh[i+1] * chd_nlj[i+1],
                                     rmesh[i+2] * chd_nlj[i+2] );
                        chd_ls_test[i] += 0.5 * total_occ * lp * mag_moment
                                        * der4 / std::pow( rmesh[i], 2 );
                        
*/
                    }
                    } // end if so_correction

                } // end loop over N 

      //   pfile.close();
      //   pfile.clear();
                rsum += strength * ( 2 * xj + 1 );

                strength_file << L_array[l] << intj << "/2"
                              << " " << strength << " " << rsum << std::endl;

                // print out point distribution for each lj
                for ( unsigned int i = 0; i < rmesh.size(); ++i ) {

                    chd_lj_file << rmesh[i] << " " << chd_lj[i]<<" "<<rmesh[i]*rmesh[i] << std::endl;
                    point_dist[i] += chd_lj[i];
                }

                spf_file.close();
                spf_file.clear();
                chd_lj_file.close();
                chd_lj_file.clear();

            } //end loop over j
        } // end loop over l

        qp_file.close();
        qp_file.clear();

        // Print to file the matter distribution. Find Normalization first
        double point_norm = 0;

        for ( unsigned int i = 0; i < rmesh.size(); ++i ) {

            point_norm += 4 * M_PI * point_dist[i] * std::pow( rmesh[i], 2 )
                        * rdelt;
        }

        double particle_number;
        if ( tz > 0 ) {particle_number = Nu.Z;}// norm_fac_p = particle_number / point_norm;}
	else {particle_number = Nu.N();}// norm_fac_n = particle_number / point_norm;}
        
	double norm_fac = particle_number / point_norm;


///////////////// //////////// //////////// //////////// ////////////
        cout<<point_norm<< " "<<" point_norm "<<endl;
////////////////////// //////////// //////////// //////////// //////////// //////

        for ( unsigned int i = 0; i < rmesh.size(); ++i ) {

            point_dist_normalized[i] = norm_fac *  point_dist[i];
        }


        strength_file << " " << std::endl;
        strength_file << "Number of Particles from point distribution: " 
                      << point_norm << std::endl;

        strength_file.close();
        strength_file.clear();


        std::cout << "Folding density distribution" << std::endl;
        // Fold point charge density with neutron and proton charge distribution
        double chdf_w_norm = 0.;
	double chdf_norm = 0.;
        std::vector<double> chdf = folded_ch_density( rmesh, rweights, point_dist, tz, Nu.A );
        std::vector<double> chdf_w = folded_ch_density( rmesh, rweights, point_dist, -tz, Nu.A );
        double new_norm = 0; 

        chdf_np_vec.push_back( chdf );
        chdf_np_vec_w.push_back(chdf_w);
        pointdist_test_vec.push_back(point_dist);

        // approximate finite size of neutron with proton charge
        // distribution in order to calculate the neutron matter
        // distribution
        std::vector<double> matter_dist =
            matter_distribution( rmesh, rweights, point_dist, Nu.A );
        // write out point distribution and matter distribution to file
        for ( unsigned int i = 0; i < rmesh.size(); ++i ) {
            density_file << rmesh[i] << " " << point_dist[i]<<" " 
                         << point_dist_wfx[i] << " " 
                         << matter_dist[i]<< " "<<chdf_w[i] << std::endl;

        }

       cout<<"Radius is"<< B.chd_rms_radius( rmesh, point_dist )<<endl;;
       cout<<"Matter Radius is"<< B.chd_rms_radius(rmesh,matter_dist) <<endl;;
       cout<<"Radius_normalized is"<< B.chd_rms_radius( rmesh, point_dist_normalized )<<endl;;

    cout<<" rms using the function in BoundRspace "<<endl;
    cout<<"proton radius folded"<<B.chd_rms_radius( rmesh, chdf_np_vec[nu])<<endl;

        density_file.close();
        density_file.clear();
       
    } // end loop over Nu_vec

    if ( chdf_np_vec.size() < 2 ) { 
        std::cout << "chdf_np_vec has wrong size." << std::endl;
        throw std::exception();
    }

    std::vector<double> chd_tot;
    chd_tot.assign( rmesh.size(), 0 );

    std::vector<double> chd_tot_w;
    chd_tot_w.assign( rmesh.size(), 0 );

    std::vector<double> point_tot;
    point_tot.assign( rmesh.size(), 0);

    double hbar_over_mc = 0.21;
    double q_n = -0.9878;
    double q_p = 0.0721;

    for( unsigned int i = 0; i < rmesh.size(); ++i ) {

        // add folded proton charge distribution
        chd_tot[i] += chdf_np_vec[1][i];
        chd_tot_w[i] += q_p * chdf_np_vec[1][i];
        chd_tot_w[i] += q_n * chdf_np_vec_w[1][i];
        point_tot[i] += pointdist_test_vec[1][i];

        // add folded neutron charge distribution
        chd_tot[i] += chdf_np_vec[0][i];
        chd_tot_w[i] += q_p * chdf_np_vec[0][i];
        chd_tot_w[i] += q_n * chdf_np_vec_w[0][i];
        point_tot[i] += pointdist_test_vec[0][i];

        // add spin-orbit correction
        chd_ls[i] *= - std::pow( hbar_over_mc, 2 );
        chd_tot[i] += chd_ls[i];
    }

    // Find normalization of Charge Density Distribution
    double chd_norm = 0;
    double chd_norm_w = 0;
    double Pnumber  = 0;
    double Nnumber  = 0;
    double Pnumber_p  = 0;
    double Nnumber_p  = 0;
    for ( unsigned int i = 0; i < rmesh.size(); ++i ) {

        chd_norm += 4 * M_PI * chd_tot[i] * std::pow( rmesh[i], 2 ) * rdelt;
        chd_norm_w += 4 * M_PI * chd_tot_w[i]* std::pow( rmesh[i], 2 ) * rdelt;
        
        }
//////////////////Form factor calculation/////////////////////
    // Create momentum space grid
    std::vector<double> kmesh;
    std::vector<double> kweights;
    double const kmax = 1.6;
    int const kpts = 104;
    kmesh.resize( kpts );
    kweights.resize( kpts );
    GausLeg( 0., kmax, kmesh, kweights );

    std::vector<double> Formfac_vec;
    Formfac_vec.assign( kmesh.size(), 0);

    std::string form_filename =  output_dir + "FormFactor.out";
    std::ofstream form_file( form_filename.c_str() );

    for (int j = 0 ;j<kmesh.size();++j){
          double Ffactor = 0;
          double Ffactor8 = 0;
          for ( unsigned int i = 0; i < rmesh.size(); ++i ) {
               Ffactor +=rdelt*rmesh[i]*sin(kmesh[j]*rmesh[i])*(-chd_tot_w[i]);
               Ffactor8 +=rdelt*rmesh[i]*sin(.8*rmesh[i])*(-chd_tot_w[i]);
          }
          Formfac_vec[j] = 4.0*M_PI/kmesh[j]*Ffactor;
          double Formfac_8 = 4.0*M_PI/.8*Ffactor8;
          form_file<<kmesh[j]<<"\t"<<Formfac_vec[j]<<"\t"<<Formfac_vec[j]/Formfac_vec[0]<<"\t"<<Formfac_8<<endl;
        }

    std::cout << " chd norm " << chd_norm<<"   chd_norm_w" <<chd_norm_w<< std::endl;
    std::cout << "P = " << Pnumber<<" " <<Pnumber<< std::endl;
    std::cout << "N = " << Nnumber<< " "<<Nnumber<<std::endl;

    // Write Charge Density Information
    
   double norm_fac = Nu_p.Z / chd_norm;

    for ( unsigned int i = 0; i < rmesh.size(); ++i ) {

        chd_file << rmesh[i] <<" "<< .98*rmesh[i]<< " "<<chd_tot[i]<<" "<< -chd_tot_w[i]<<" " 
                 << chdf_np_vec[1][i]  << " " 
                 << chdf_np_vec[0][i]  << " " 
                 << chd_ls[i] * norm_fac << " " 
                 << chd_ls_test[i] * norm_fac  << " " 
                 << coulomb_vec[i]<< " " 
                 << chdf_np_vec[1][i] << " " 
                 << chdf_np_vec[0][i] << " " 
		 << pointdist_test_vec[1][i] << " "
                 << pointdist_test_vec[0][i] << std::endl;
   }

    chd_file.close();
   chd_file.clear();

    // Calculate RMS Radius
    double sum_pf = 0; // contribution from protons
    double sum_nf = 0; // contribution from protons
    double sum_pfr2 = 0;
    double sum_nfr2 = 0; // contribution from neutrons
    double sum_lsr2 = 0; // contribution from spin-orbit correction
    double sum_totr2 = 0; // total
    double sum_totr2_w = 0; // total
    for ( unsigned int i = 1; i < rmesh.size() - 1; ++i ) {
        
        sum_pf += std::pow( rmesh[i], 2 ) * chdf_np_vec[1][i] * rdelt;
        sum_pfr2 += std::pow( rmesh[i], 4 ) * chdf_np_vec[1][i] * rdelt;

        sum_nfr2 += std::pow( rmesh[i], 4 ) * chdf_np_vec[0][i] * rdelt;
        sum_nf += std::pow( rmesh[i], 2 ) * chdf_np_vec[0][i] * rdelt;

        sum_lsr2 += std::pow( rmesh[i], 4 ) * chd_ls[i] * rdelt;

        sum_totr2 += std::pow( rmesh[i], 4 ) * chd_tot[i] * rdelt;
        sum_totr2_w += std::pow( rmesh[i], 4 ) * (-chd_tot_w[i]) * rdelt;

    }
    cout<<"r^2 weak"<<sum_totr2_w<<endl;

    double rms_pf = std::sqrt( sum_pfr2 / sum_pf );
    double rms_nf = std::sqrt( sum_nfr2 / sum_nf );
    double rms_tot = std::sqrt( 4 * M_PI * sum_totr2 / chd_norm );
    double rms_tot_w = std::sqrt(-4 * M_PI * sum_totr2_w /chd_norm_w);
    double rms2_p = 4 * M_PI * sum_pfr2 / chd_norm;
    double rms2_n = 4 * M_PI * sum_nfr2 / chd_norm;
    double rms2_ls =  4 * M_PI * sum_lsr2 / chd_norm;
    double rms_tot_check = std::sqrt( rms2_p + rms2_n + rms2_ls );

    std::string rms_filename = output_dir + nucleus_string + "_rms.out";
    std::ofstream rms_file( rms_filename.c_str() );
    rms_file << "Folded with proton charge distribution only" << std::endl;
    rms_file << "RMS radius:(p) " << rms_pf << std::endl;
    rms_file << "RMS radius:(n) " << rms_nf << std::endl;
    rms_file << "Number of protons: " << sum_pf * 4 * M_PI << std::endl;

    rms_file << " " << std::endl;

    rms_file << "Proton, neutron and spin-orbit contributions included" 
             << std::endl;
    rms_file << "Number of protons: " << chd_norm << std::endl;

    rms_file << "Mean Square Radius for different contributions "
             << "(normalized by Z = " << chd_norm << ")" << std::endl;

    rms_file << " " << std::endl;
    rms_file << "Proton Contribution (with Folding): " << rms2_p << std::endl;
    rms_file << "Neutron Conribution: " << rms2_n << std::endl;
    rms_file << "Spin-orbit Contribution: " << rms2_ls << std::endl;
    rms_file << " " << std::endl;
    rms_file << "RMS radius: " << rms_tot <<std::endl;
    rms_file << "Check with total: " << rms_tot_check << std::endl;
    rms_file << "Weak radius " << rms_tot_w << std::endl;
    rms_file << "Weak Charge " << rms_tot_w << " "<<chd_norm_w<< std::endl;
    rms_file << "N# " << Nnumber<< std::endl;
    rms_file << "P# " << Pnumber<< std::endl;
    rms_file.close();
    rms_file.clear();
    return 1;
}
コード例 #23
0
Int_t VisualizeSurface()
{

    std::string gfname;
    std::cout << "\nFor the graph ";
    ListAllFilesInDirOfType (".",".root");
    std::cout << "\nEnter filename : ";
    std::getline(std::cin, gfname);

    TGraphErrors* mygr = GetGraph(gfname);
    mygr->SetMarkerColor(kRed);
    mygr->SetLineColor(kRed);
    mygr->SetMarkerStyle(20);

    std::string parfname = GetParamFile();
    std::ifstream pfile(parfname.data());
    Parameters params(pfile);
    if (! params.KeysAreSensible()) return -1;
    AngDistC W(params, 1, ELECTRIC);

    std::cout << params << std::endl;

    TGraph* gr = new TGraph(mygr->GetN());
    gr->SetMarkerColor(kBlue);
    gr->SetLineColor(kBlue);
    gr->SetMarkerStyle(20);

    Double_t num, denom;
    Double_t ratio;
    Double_t x[2];
    for (UInt_t i=0; i<mygr->GetN(); i++)
    {
        x[0] = mygr->GetX()[i];
        x[1] = 0;
        num = W(x);

        x[1] = TMath::Pi()/2.;
        denom = W(x);
        ratio = num/denom;
        gr->SetPoint(i, mygr->GetX()[i], TMath::Abs(ratio));
    }

    std::cout << "\n Phase2ChiSqC setup completed " << std::endl;

    TPaveText* pt = new TPaveText(0.5, 0.75, 0.8, 0.95);
    std::ostringstream os("", std::ios::out|std::ios::app);
    os << "a = " << params[0]->GetValue();
    pt->AddText(os.str().data());
    os.str("b = ");
    os << params[1]->GetValue();
    pt->AddText(os.str().data());
    os.str("c = ");
    os << params[2]->GetValue();
    pt->AddText(os.str().data());
    os.str("d = ");
    os << params[3]->GetValue();
    pt->AddText(os.str().data());

    TH1* h = new TH2D("Ratio Comparison", "", 10, -1,1, 500, 0,100);
    h->SetStats(0);

    TCanvas* c = new TCanvas("c");
    h->Draw();
    gr->Draw("LP");
    mygr->Draw("LP");

    gPad->Modified();
    c->Update();


    TLegend *leg = new TLegend(0.5, 0.75, 0.8, 0.95);
    leg->AddEntry(gr, "Fit", "PL");
    leg->AddEntry(mygr, "Data", "PL");
    leg->Draw();

    return 0;
}
コード例 #24
0
ファイル: tar32.cpp プロジェクト: wkoiking/xyzzy
int CTar32::s_get_archive_type(const char *arcfile)
{
	std::auto_ptr<ITarArcFile> pfile(ITarArcFile::s_open(arcfile,"rb",-1,ARCHIVETYPE_AUTO));
	if(pfile.get()==NULL){return -1;}

	//int archive_type = ITarArcFile::s_get_archive_type();
	//if(archive_type == -1){return -1;}
	
	// HEADER tar_header;

	int archive_type = pfile->get_archive_type();

	union archive_header{
		HEADER tar;
		new_cpio_header cpio;
		ar_first_hdr ar;
	};
	archive_header arc_header;
	size64 ret = pfile->read(&arc_header,sizeof(arc_header));
	if(ret >= sizeof(arc_header.tar)
		&& (arc_header.tar.compsum() == strtol(arc_header.tar.dbuf.chksum, NULL, 8) || arc_header.tar.compsum_oldtar() == strtol(arc_header.tar.dbuf.chksum, NULL, 8))){
		switch(archive_type){
		case ARCHIVETYPE_NORMAL:
			archive_type = ARCHIVETYPE_TAR;break;
		case ARCHIVETYPE_GZ:
			archive_type = ARCHIVETYPE_TARGZ;break;
		case ARCHIVETYPE_Z:
			archive_type = ARCHIVETYPE_TARZ;break;
		case ARCHIVETYPE_BZ2:
			archive_type = ARCHIVETYPE_TARBZ2;break;
		case ARCHIVETYPE_LZMA:
			archive_type = ARCHIVETYPE_TARLZMA;break;
		case ARCHIVETYPE_XZ:
			archive_type = ARCHIVETYPE_TARXZ;break;
		}
	}else if(ret >= sizeof(arc_header.cpio)
		&& arc_header.cpio.magic_check()){
		switch(archive_type){
		case ARCHIVETYPE_NORMAL:
			archive_type = ARCHIVETYPE_CPIO;break;
		case ARCHIVETYPE_GZ:
			archive_type = ARCHIVETYPE_CPIOGZ;break;
		case ARCHIVETYPE_Z:
			archive_type = ARCHIVETYPE_CPIOZ;break;
		case ARCHIVETYPE_BZ2:
			archive_type = ARCHIVETYPE_CPIOBZ2;break;
		case ARCHIVETYPE_LZMA:
			archive_type = ARCHIVETYPE_CPIOLZMA;break;
		case ARCHIVETYPE_XZ:
			archive_type = ARCHIVETYPE_CPIOXZ;break;
		}
	}else if(ret >= sizeof(arc_header.ar)
		&& (memcmp(arc_header.ar.magic,"!<arch>\012",8) == 0  || memcmp(arc_header.ar.magic,"!<bout>\012",8) == 0)
		&& arc_header.ar.hdr.magic_check()){
		switch(archive_type){
		case ARCHIVETYPE_NORMAL:
			archive_type = ARCHIVETYPE_AR;break;
		case ARCHIVETYPE_GZ:
			archive_type = ARCHIVETYPE_ARGZ;break;
		case ARCHIVETYPE_Z:
			archive_type = ARCHIVETYPE_ARZ;break;
		case ARCHIVETYPE_BZ2:
			archive_type = ARCHIVETYPE_ARBZ2;break;
		case ARCHIVETYPE_LZMA:
			archive_type = ARCHIVETYPE_ARLZMA;break;
		case ARCHIVETYPE_XZ:
			archive_type = ARCHIVETYPE_ARXZ;break;
		}
	}
	return archive_type;
}
コード例 #25
0
ファイル: testprojectfile.cpp プロジェクト: danmar/cppcheck
void TestProjectFile::loadInexisting()
{
    const QString filepath(QString(SRCDIR) + "/../data/projectfiles/foo.cppcheck");
    ProjectFile pfile(filepath);
    QCOMPARE(pfile.read(), false);
}
コード例 #26
0
ファイル: S.cpp プロジェクト: BAS215/dom_clean
int main() {

    double hbarc = 197.327; // hbar * c in [MeV fm]
    double Mass = 938; // nucleon mass in MeV

    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;

    int num_lj;
    config_file >> num_lj;
    // Knowing the expected number of bound states is useful when
    // looking for particle states that are near the continuum

    // These maps hold the number of bound states for each lj
    std::map<std::string, int> n_lj_map; // neutrons
    std::map<std::string, int> p_lj_map; // protons
    std::vector< std::map< std::string, int > > map_vec;
    for ( int n = 0; n < num_lj; ++n ) {

        std::string key;
        int n_num_bound, p_num_bound;
        config_file >> key >> n_num_bound >> p_num_bound;

        std::pair< std::map< std::string, int >::iterator, bool > n_ret;
        std::pair< std::map< std::string, int >::iterator, bool > p_ret;
        n_ret = n_lj_map.insert ( std::make_pair( key, n_num_bound ) );
        p_ret = p_lj_map.insert ( std::make_pair( key, p_num_bound ) );

        if ( n_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << n_ret.first->second << std::endl;
        }

        if ( p_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << p_ret.first->second << std::endl;
        }
    }

    map_vec.push_back( n_lj_map );
    map_vec.push_back( p_lj_map );



    config_file.close();
    config_file.clear();

  //  std::string output_dir = "Output_" + parameters_string + "/Ener/";
  //  std::string parameters_filename = parameters_string + ".inp";

    std::string output_dir = "Output_test/S/";
   // std::string parameters_filename = "Output_hosfit/roott/Nov26/hosfitupdated.inp";
    std::string parameters_filename = "Input.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();

    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" };

    // Create momentum space grid
    std::vector<double> kmesh;
    std::vector<double> kweights;
    double const kmax = 6.0;
    int const kpts = 104;
    kmesh.resize( kpts );
    kweights.resize( kpts );
    GausLeg( 0., kmax, kmesh, kweights );

    // 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 );
    }

    // Prepare stuff for output files
    std::vector< std::string > np_strings;
    np_strings.push_back( n_string );
    np_strings.push_back( p_string );

    double total_energy = 0;
    double calc_A = 0;

    //Potential specifications
    int type = 1; // 1 is P.B. form (average), 0 is V.N. form
    int mvolume = 4;
    int AsyVolume = 1;

    // --- CALCULATIONS --- //

        std::string lj_particleN_share = output_dir + "ParticleN_shares.out";
        std::ofstream particleNumber_file( lj_particleN_share.c_str() );
    // Loop over protons and neutrons
    double Zp; // number of protons in projectile

    for ( unsigned int nu = 0; nu < Nu_vec.size(); ++nu ) {
        
        std::map< std::string, int > lj_map = map_vec[nu];

        double tz = nu - 0.5; // +0.5 for protons, -0.5 for neutrons
        if ( tz < 0 ) {Zp = 0;} else { Zp = 1;}
         particleNumber_file << tz << std::endl;

        // 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;
       // lmax = 0;
        // Construct boundRspace Object
//      double Emax = Nu.Ef - Nu.Wgap * p.fGap_B; // energy < Ef where imaginary part begins
        double Emax =  Nu.Ef;
        double Emin = -200 + Emax;
        boundRspace B( rmax, rpts, Nu.Ef, Nu.ph_gap, lmax , Nu.Z, Zp, Nu.A, U1 );

        double tol = 0.01;
        std::vector< lj_eigen_t > bound_levels = B.get_bound_levels( rmesh, tol );

        std::vector< mesh_t > emesh_vec = B.get_emeshes( rmesh, Emin, Emax, bound_levels );

        std::vector<double> n_of_k;
        n_of_k.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_qh;
        n_of_k_qh.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_c_tot;
        n_of_k_c_tot.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_qh_peak_tot;
        n_of_k_qh_peak_tot.assign( kmesh.size(), 0 );

        // Loop over lj channels
        for ( int l = 0; l < lmax + 1 ; ++l ) {

            // Create Bessel Function matrix in k and r
            matrix_t bess_mtx( kmesh.size(), rmesh.size() );
            for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
            for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {

                double rho = kmesh[nk] * rmesh[nr];

                bess_mtx( nk, nr ) = gsl_sf_bessel_jl( l, rho );
            }
            }

            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 ];

                int index = B.index_from_LJ( l, xj );
                mesh_t &emesh = emesh_vec[index];
                std::vector< eigen_t > &bound_info = bound_levels[index];

                std::string lj_string = L_array[l] + j_string + "2";

                std::vector<double> n_of_k_c_lj;
                std::vector<double> n_of_k_qh_lj;
                std::vector<double> n_of_k_qh_peak;
                std::vector<std::vector<double> > n_of_k_qh_peak_Matrice;
                n_of_k_c_lj.assign( kmesh.size(), 0 );
                n_of_k_qh_lj.assign( kmesh.size(), 0 );
                n_of_k_qh_peak.assign( kmesh.size(), 0 );

	        matrix_t Slj(kmesh.size(),kmesh.size());
		for (int i=0;i<kmesh.size();++i){for (int j=0;j<kmesh.size();++j){Slj(i,j) = 0.;}}
	        matrix_t n_r_lj(rmesh.size(),rmesh.size());
		for (int i=0;i<rmesh.size();++i){for (int j=0;j<rmesh.size();++j){n_r_lj(i,j) = 0.;}}

                // Find self-consistent solutions
                 std::cout << "lj = " << l << " " << xj << std::endl;
                 std::vector<cmatrix_t> G;  
		 double E;
		 vector<double> Edelt;
                for ( unsigned int m = 0; m < emesh.size(); ++m ) {
                    
                     E = emesh[m].first;
       		     Edelt.push_back(emesh[m].second);
                    // Propagator
	            G.push_back( B.propagator( rmesh, E, l, xj));
	        }
                // Loop over energy
		    for (int i = 0 ; i < rmesh.size(); ++i){
		         for (int j = 0 ; j < rmesh.size(); ++j){
			     double sumnr = 0.;
                             for ( unsigned int m = 0; m < emesh.size(); ++m ) {
			            sumnr += rmesh[i] * rmesh[j] * imag(G[m](i,j)) * Edelt[m];
		            }
		    n_r_lj(i,j) = sumnr;	
		         }
                    }
                  //  for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
                    for( unsigned int mk = 0; mk < kmesh.size(); ++mk ) {
                         double rsums = 0;
                        for( unsigned int i = 0; i < rmesh.size(); ++i ) {
                            double jl1 = bess_mtx( mk, i );
                        for( unsigned int j = 0; j < rmesh.size(); ++j ) {
                            double jl2 = bess_mtx( mk, j );
                            
                            rsums -= n_r_lj(i,j) * jl1 * jl2 * rdelt;
                        }
                        } // end loop over radial coordinates
		//	Slj(nk,mk) = 2./M_PI/M_PI * rsums * ( 2 * xj + 1 )/( 4 * M_PI ); 		
			 n_of_k_c_lj[mk] += 2./M_PI/M_PI * rsums * ( 2 * xj + 1 )/( 4 * M_PI ); 		
		    }
                   // }    // integral over k
                     
                      // end loop over k
                 // end loop over energy
//                for (int nk = 0 ; nk < kmesh.size() ; ++nk){
//		     n_of_k_c_lj[nk] = Slj(nk,nk);} 
                // loop over the orbitals and write out the 
                // bound state information to a file
                for ( unsigned int N = 0; N < bound_info.size(); ++N ) {
                    // Quasiparticle energy
                    double QPE = bound_info[N].first; 

                    // Quasiparticle wavefunction
                    std::vector<double> &QPF = bound_info[N].second;

                    // Transform wavefunction to momentum space
                    std::vector<double> kQPF;
                    for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {

                        double sum = 0;
                        for( unsigned int i = 0; i < rmesh.size(); ++i ) {

                           sum += std::sqrt( 2 / M_PI ) * rweights[i] 
                                * std::pow( rmesh[i], 2 ) * QPF[i] * bess_mtx( nk, i );
                        }
                        kQPF.push_back( sum );
                      }

                    // This should automatically be normalized to N or Z
                    // since the wavefunctions are normalized to 1
                    if ( QPE < Nu.Ef ) {
                        for ( unsigned int kk = 0; kk < kmesh.size(); ++kk ) {

                            n_of_k_qh_lj[kk] += ( 2 * xj + 1 ) / ( 4 * M_PI ) * kQPF[kk] * kQPF[kk]; 
                        } // end loop over k
                    } 
                } // end loop over N 
                // Write Out Momentum Distribution for each lj channel
                // Also, add up the contribution from each channel to get 
                // the total momentum distribution
                std::string n_of_k_lj_filename = output_dir + "n_of_k_" 
                                               + np_strings[nu] 
                                               + "_" + L_array[l] + j_string 
                                               + "2.out";
                std::ofstream n_of_k_lj_file( n_of_k_lj_filename.c_str() );
		double NOFK_lj = 0;
                for ( unsigned int i = 0; i < kmesh.size(); ++i ) {
                    double n_of_k_lj = n_of_k_c_lj[i] + n_of_k_qh_peak[i];

                    n_of_k_lj_file << kmesh[i] << " " << n_of_k_lj 
                                   << " " << n_of_k_qh_lj[i] << std::endl;

                    n_of_k[i] += n_of_k_lj;
                    n_of_k_qh[i] += n_of_k_qh_lj[i];
                    n_of_k_qh_peak_tot[i] += n_of_k_qh_peak[i];
                    n_of_k_c_tot[i] += n_of_k_c_lj[i];

		    //Particle contribution to each state
		    // 
		    NOFK_lj += 4 * M_PI * kweights[i] * std::pow( kmesh[i], 2 ) * n_of_k_lj;
                }

                particleNumber_file <<index <<" " << "l= "<< l << " " <<"j= " << xj <<" " << NOFK_lj   << std::endl; 
				  //  <<" " <<n_of_k_qh_peak_tot[sarekar-1] <<" " <<n_of_k_c_tot[sarekar-1] <<std::endl;

                n_of_k_lj_file.close();
                n_of_k_lj_file.clear();
	    }//up
         }//lj
        // Output Files
        std::string strength_filename = output_dir + np_strings[nu] 
                                      + "_k_strength.out";
        std::ofstream strength_file( strength_filename.c_str() );

        std::string n_of_k_filename = output_dir + np_strings[nu]
                                    + "_momentum_dist.out";
        std::ofstream n_of_k_file( n_of_k_filename.c_str() ); 

        // Calculate Particle Number and Kinetic Energy
        double norm = 0;
        for ( unsigned int n = 0; n < kmesh.size(); ++n ) {
            norm += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) * n_of_k[n];
        }
        // Energetics
        double N_or_Z; // actual number of neutrons or protons
        if( tz > 0 ) { 
            N_or_Z = Nu.Z;
        }
        else {
            N_or_Z = Nu.N();
        }

        calc_A += norm;
        double k_strength = 0;
        double qh_strength = 0;
        for ( unsigned int n = 0; n < kmesh.size(); ++n ) {
            n_of_k_file << kmesh[n] << " " << n_of_k[n] / norm        
                                    << " " << n_of_k_qh[n] / N_or_Z 
                                    << std::endl;

            //verify that n_of_k_qh is normalized to N or Z
            qh_strength += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                     * n_of_k_qh[n] / N_or_Z;

            k_strength += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                        * n_of_k[n] / norm;
            
            strength_file << kmesh[n] << " " << k_strength 
                                      << " " << qh_strength << std::endl;
        }

        strength_file << " " << std::endl;
        strength_file << "norm = " << norm << std::endl;
        strength_file << "N or Z = " << N_or_Z << std::endl;

        n_of_k_file.close();
        n_of_k_file.clear();
        strength_file.close();
        strength_file.clear();

std::cout<< "HELLO tz LOOP" <<std::endl;
    }//tz
particleNumber_file.close();
return 1;
}
コード例 #27
0
ファイル: tupfilemanager.cpp プロジェクト: KDE/tupi
bool TupFileManager::load(const QString &fileName, TupProject *project)
{
    #ifdef K_DEBUG
        #ifdef Q_OS_WIN32
            qDebug() << "[TupFileManager::load()] - fileName: " + fileName;
        #else
            T_FUNCINFO << fileName; 
        #endif
    #endif

    TupPackageHandler packageHandler;

    if (packageHandler.importPackage(fileName)) {
        QDir projectDir(packageHandler.importedProjectPath());
        QFile pfile(projectDir.path() + QDir::separator() + "project.tpp");

        if (pfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
            project->fromXml(QString::fromLocal8Bit(pfile.readAll()));
            pfile.close();
        } else {
            #ifdef K_DEBUG
                QString msg1 = "TupFileManager::load() - Error while open .tpp file. Name: " + pfile.fileName();
                QString msg2 = "TupFileManager::load() - Path: " + projectDir.path();
                QString msg3 = "TupFileManager::load() - Error Description: " + pfile.errorString(); 
                #ifdef Q_OS_WIN32
                    qDebug() << msg1;
                    qDebug() << msg2;
                    qDebug() << msg3;
                #else
                    tError() << msg1;
                    tError() << msg2;
                    tError() << msg3;
                #endif
            #endif

            return false;
        }

        project->setDataDir(packageHandler.importedProjectPath());
        project->loadLibrary(projectDir.path() + QDir::separator() + "library.tpl");

        QStringList scenes = projectDir.entryList(QStringList() << "*.tps", QDir::Readable | QDir::Files);

        if (scenes.count() > 0) {
            int index = 0;
            foreach (QString scenePath, scenes) {
                     scenePath = projectDir.path() + QDir::separator() + scenePath;
                     QFile file(scenePath);

                     if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
                         QString xml = QString::fromLocal8Bit(file.readAll());
                         QDomDocument document;
                         if (! document.setContent(xml))
                             return false;
                         QDomElement root = document.documentElement();

                         TupScene *scene = project->createScene(root.attribute("name"), index, true);
                         scene->fromXml(xml);

                         index += 1;
                         file.close();
                     } else {
                         #ifdef K_DEBUG
                             QString msg = "TupFileManager::load() - Error: Can't open file -> " + scenePath;
                             #ifdef Q_OS_WIN32
                                 qDebug() << msg;
                             #else
                                 tError() << msg;
                             #endif
                         #endif
                         return false;
                     }
            }
コード例 #28
0
ファイル: dom_fitE.cpp プロジェクト: BAS215/dom_clean
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;

    int num_lj;
    config_file >> num_lj;

    // These maps hold the number of bound states for each lj
    std::map<std::string, int> n_lj_map; // neutrons
    std::map<std::string, int> p_lj_map; // protons
    std::vector< std::map< std::string, int > > map_vec;
    for ( int n = 0; n < num_lj; ++n ) {

        std::string key;
        int n_num_bound, p_num_bound;
        config_file >> key >> n_num_bound >> p_num_bound;

        std::pair< std::map< std::string, int >::iterator, bool > n_ret;
        std::pair< std::map< std::string, int >::iterator, bool > p_ret;
        n_ret = n_lj_map.insert ( std::make_pair( key, n_num_bound ) );
        p_ret = p_lj_map.insert ( std::make_pair( key, p_num_bound ) );

        if ( n_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << n_ret.first->second << std::endl;
        }

        if ( p_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << p_ret.first->second << std::endl;
        }
    }

    map_vec.push_back( n_lj_map );
    map_vec.push_back( p_lj_map );

    config_file.close();
    config_file.clear();

    bool hole;
    if ( fit_ph == 0 ) hole = true;
    else hole = false;

    std::string output_dir = "Output_" + parameters_string + "/Output_domgen/";
    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;
    double rdelt = rmax / rpts;
    for( int i = 0; i < rpts; ++i ) {

        rmesh.push_back( ( i + 0.5 ) * rdelt );
        
    }

    // Prepare stuff for output files
    std::vector< std::string > np_strings;
    np_strings.push_back( n_string );
    np_strings.push_back( p_string );

    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
    for ( unsigned int nu = 1; nu < 2; ++nu ) {
    //for ( unsigned int nu = 0; nu < Nu_vec.size(); ++nu ) {
        
        double tz = nu - 0.5; // +0.5 for protons, -0.5 for neutrons
        std::map< std::string, int > lj_map = map_vec[nu];
        if ( tz < 0 ) Zp = 0;
        else Zp = 1;

        // 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 boundRspace Object
        boundRspace B( rmax, rpts, Nu.Ef, Nu.ph_gap, lmax, Nu.Z, Zp, Nu.A, U1 );

        double tol = 0.01;
        std::vector< lj_eigen_t > bound_levels = 
            B.get_bound_levels( rmesh, tol );

        // Output Files
        std::string qp_filename = output_dir + np_strings[nu] 
                                + "_quasiparticle" + ".test";
        std::ofstream qp_file( qp_filename.c_str() );

        // Loop over lj channels
        for ( int l = 0; l < lmax + 1; ++l ) {

            for( int up = -1; up < 2; up+=2 ) {

                double xj = l + up / 2.0;
                int j_index = ( up - 1 ) / 2;
                if ( xj < 0 ) continue;

                int index = B.index_from_LJ( l, xj );
                std::vector< eigen_t > &bound_info = bound_levels[index];

                double lp; 
                if ( xj > l ) lp = l;
                else lp = - l - 1;
                
                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";

                /* QUASIPARTICLE AND QUASIHOLE INFORMATION */

                // Find self-consistent solutions

                // loop over the orbitals and write out the 
                // bound state information to a file
                int intj = static_cast<int>( 2 * xj );
                for ( unsigned int N = 0; N < bound_info.size(); ++N ) {

                    std::string level_str = util::IntToStr( N ) + L_array[l] 
                                          + j_string + "2";

                    std::string wfx_filename = output_dir + np_strings[nu] 
                        + "_" + level_str + ".wfx";
                    std::ofstream wfx_file( wfx_filename.c_str() );

                    // Quasiparticle energy
                    double QPE = bound_info[N].first; 

                    // Quasiparticle wavefunction
                    std::vector<double> &QPF = bound_info[N].second;
                    double S = B.sfactor( rmesh, QPE, l, xj, QPF );

                    qp_file << N << L_array[l] << intj << "/2" 
                            << " " << QPE << " " << S << std::endl;

                    // Write out wavefunctions to a file
                    for ( unsigned int i = 0; i < rmesh.size(); ++i ) {
                        
                        wfx_file << rmesh[i] << " " << QPF[i] << std::endl;

                    }

                    wfx_file.close();
                    wfx_file.clear();

                } // end loop over N 

            } //end loop over j
        } // end loop over l

        qp_file.close();
        qp_file.clear();

    } // end loop over Nu_vec

    return 1;
}
コード例 #29
0
Int_t VisualizeSurface()
{

    std::string gfname;
    std::cout << "\nFor the graph ";
    ListAllFilesInDirOfType (".",".root");
    std::cout << "\nEnter filename : ";
    std::getline(std::cin, gfname);

    TGraphErrors* mygr = GetGraph(gfname);
    mygr->SetMarkerColor(kRed);
    mygr->SetLineColor(kRed);
    mygr->SetMarkerStyle(20);

    std::cout << "\nBegin setup of eta function" << std::endl;
    std::string rfname = GetROOTFile();
    TFile *fle = new TFile(rfname.data());
    if (!fle->IsOpen()) return -1;

    Eta2C eta(fle);
    AngMarginalEta2C marg_eta(eta);
    std::cout << "\neta function set up complete" << std::endl;

    std::cout << "\nBegin setup of denominators" << std::endl;
    std::string parfname = GetParamFile();
    std::ifstream pfile(parfname.data());
    Parameters params(pfile);
    if (! params.KeysAreSensible()) return -1;
    AngDistC W(params, 0, ELECTRIC);

    std::cout << params << std::endl;
    std::cout << "\ndenominator set up complete" << std::endl;

    std::cout << "\nSetting up numerator " << std::endl;
    PolPartAngDistC polpart(1, ELECTRIC);
    std::cout << "\nNumerator setup complete" << std::endl;

    std::cout << "\nBegin setup of h function" << std::endl;

    rfname = GetROOTFile();
    TFile *file = new TFile(rfname.data());
    if (!file->IsOpen()) return -1;

    TDirectory* dir = file->GetDirectory("SolidAnglePDFGeneratorCOutput");
    if (dir==0) return -3;
    std::vector<TH2*> solang_hists = ROOTUtils::GetAllTH2InDirectory(dir);

    std::cout << "h function set up" << std::endl;

    std::vector<UInt_t> indices(32);
    for (UInt_t i=0; i<indices.size(); i++)
    {
        indices[i] = i;
    }

    Phase2ChiSqC FUNC(mygr, W, polpart, marg_eta, solang_hists , indices);
    std::cout << "\nang dist set up" << std::endl;

    Double_t par[] = {params.at(0)->GetValue(),
                       params.at(1)->GetValue(),
                       params.at(2)->GetValue(),
                       params.at(3)->GetValue()};
//    FUNC.SetAllIntegrandParameters(par);
    Double_t chisq_pdf = FUNC(par);

    std::vector<Double_t> ratios = FUNC.GetComputedRatios();

    TGraph* gr = new TGraph(ratios.size());
    gr->SetMarkerColor(kBlue);
    gr->SetLineColor(kBlue);
    gr->SetMarkerStyle(20);

    for (UInt_t i=0; i<ratios.size(); i++)
    {
        gr->SetPoint(i, mygr->GetX()[i], ratios[i]);
    }

    std::cout << "\n Phase2ChiSqC setup completed " << std::endl;

//    Int_t strip;
//    std::cout << "\nEnter desired strip : ";
//    std::cin >> strip;

//    std::shared_ptr<ROOT::Math::IBaseFunctionMultiDim> pi = FUNC.GetDenominator(strip);
//    ParamFunctorAdapter *pfa = new ParamFunctorAdapter(*pi);
//
//    std::cout << "\nSetting up the function" << std::endl;
//    ROOT::Math::ParamFunctor pf;
//    pf.SetFunction(pfa);
//    TF2* f = new TF2("f", pf, -1, 1, -1.0*CLHEP::pi,CLHEP::pi,0);
//    Double_t pars[] = {params[0]->GetValue(),
//                       params[1]->GetValue(),
//                       params[2]->GetValue(),
//                       params[3]->GetValue()};
//    //f->SetParameters(pars);
//    f->SetNpx(50);
//    f->SetNpy(50);

    TPaveText* pt = new TPaveText(0.5, 0.75, 0.8, 0.95);
    std::ostringstream os("", std::ios::out|std::ios::app);
    os << "a = " << params[0]->GetValue();
    pt->AddText(os.str().data());
    os.str("b = ");
    os << params[1]->GetValue();
    pt->AddText(os.str().data());
    os.str("c = ");
    os << params[2]->GetValue();
    pt->AddText(os.str().data());
    os.str("d = ");
    os << params[3]->GetValue();
    pt->AddText(os.str().data());

    TCanvas* c = new TCanvas("c");
    gr->Draw("ALP");
    mygr->Draw("LP");

    return 0;
}
コード例 #30
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;
}