SOLARIS_Analysis/Cleopatra/Cleopatra.C

112 lines
3.8 KiB
C++
Raw Permalink Normal View History

2023-04-03 16:03:48 -04:00
/***********************************************************************
*
* This is Cleopatra, a sucessor of Ptolemy
* only for (d,p), (d,p), (d,d), or (p,p)
*
* 1) it read a simple infile.in from reaction_setting file
* 2) use Ptolemy to calculate the the creation
* 3) extract the cross sec distribution into txt and root file
*
* -----------------------------------------------------
* This program will call the root library and compile in g++
* compilation:
* g++ cleopatra.C -o cleopatra `root-config --cflags --glibs`
*
*------------------------------------------------------
* The reaction_setting file is simple like:
*
* 206Hg(d,p)207Hg(1s1/2 0.000) 10MeV/u AK
*
* the first is similar to usual reaction setting, the word AK is a
* short name for Optical Potential, user can put as many line as
* they like, Cleopatra can create the suitable infile.in for Ptolomy
*
* ------------------------------------------------------
* created by Ryan (Tsz Leung) Tang, Nov-18, 2018
* email: goluckyryan@gmail.com
* ********************************************************************/
#include <fstream>
#include <cmath>
#include <vector>
#include <iostream>
#include <stdexcept>
#include <stdio.h>
#include <string>
2024-07-04 18:37:46 -04:00
#include <cstdlib>
#include <sstream>
2023-04-03 16:03:48 -04:00
#include <TROOT.h>
#include <TFile.h>
#include <TString.h>
#include "InFileCreator.h"
#include "ExtractXSec.h"
#include <TApplication.h>
#include "PlotTGraphTObjArray.h"
int main (int argc, char *argv[]) { //TODO add angle range
printf("=================================================================\n");
printf("===== Cleopatra, Ptolemy for (d,p),(p,d), (p,p) and (d,d) =====\n");
printf("=================================================================\n");
if(argc < 2 || argc > 5) {
printf("Usage: ./Cleopatra input_file (angMin = 0 deg, angMax = 180 deg, angStep = 1 deg)\n");
printf("Usage: ./Cleopatra input_file angMin angMax (angStep = 1 deg)\n");
printf("Usage: ./Cleopatra input_file angMin angMax angStep\n");
exit(0);
}else{
printf("From file : %s \n", argv[1]);
}
//================= read infile. extract the reactions, write pptolemy infile for each reaction
2024-07-04 18:37:46 -04:00
std::string readFile = argv[1];
2023-04-03 16:03:48 -04:00
double angMin = 0.;
double angMax = 180.;
double angStep = 1.;
if( argc >= 4 ){
angMin = atof(argv[2]);
angMax = atof(argv[3]);
}
if( argc == 5 ){
angStep = atof(argv[4]);
}
2024-07-04 18:37:46 -04:00
std::string ptolemyInFileName = argv[1];
2023-04-03 16:03:48 -04:00
ptolemyInFileName += ".in";
printf("=================== Create InFile\n");
InFileCreator( readFile, ptolemyInFileName, angMin, angMax, angStep);
//================= run ptolemy
std::string ptolemyOutFileName = argv[1];
ptolemyOutFileName += ".out";
2024-07-04 18:37:46 -04:00
std::ostringstream commandStream;
#if defined(__linux__)
commandStream << "../Cleopatra/ptolemy <" << ptolemyInFileName << "> " << ptolemyOutFileName;
#elif defined(__APPLE__) && defined(__MACH__)
commandStream << "../Cleopatra/ptolemy_mac <" << ptolemyInFileName << "> " << ptolemyOutFileName;
#endif
2024-07-04 18:37:46 -04:00
std::string command = commandStream.str();
2023-04-03 16:03:48 -04:00
printf("=================== Run Ptolemy\n");
2024-07-04 18:37:46 -04:00
printf("%s \n", command.c_str());
int result = std::system(command.c_str());
if (result == -1) {
std::cerr << "Error executing system command." << std::endl;
return 1;
}
2023-04-03 16:03:48 -04:00
//================= extract the Xsec and save as txt and root
printf("=================== Extract Cross-section\n");
ExtractXSec(ptolemyOutFileName);
//================= Call root to plot the d.s.c.
printf("=================== Plot Result using ROOT.\n");
2024-07-04 18:37:46 -04:00
std::string rootFileName = argv[1];
2023-04-03 16:03:48 -04:00
rootFileName += ".root";
TApplication app ("app", &argc, argv);
PlotTGraphTObjArray(rootFileName);
app.Run(); //nothing run after
return 0;
}