Hi everybody! I am new and this is my very first post. I hope i posted in the more appropriate category.
I am a physicist (like a lot in here i suppose) but i have to confess i seriously converted to ROOT since a couple of months. Of course i already had a lot of time to get introduced in ROOT and i already worked a lot with it but never by writing from blank a new script. Now it’s time to grow!
Here’s the deal: i am shooting beta particles through a diamond with graphite contacts and i am getting the numbers of collected electrons-holes. My software provide me essentially a file .dat, two columns of numbers: the bin (ADC channel) and the counts.
I want to plot the Energy Loss Distribution of the charged particles impinging in my diamond. Of course i change the voltage accross the diamond and i have several .dat files. It is one week i am dying in order to give as input not only one file name but to automatically read all the files present in the folder (i.e. run_1.dat, run_2.dat, etc.)
Here is a minimal working example of what i was able to write alone.
#include <iostream> // std ::cout
#include <fstream> // std::ifstream
#include "TFile.h"
#include <TCanvas.h>
#include "TLegend.h"
#include "TGraph.h"
using namespace std;
void Example()
{
string filename,infile,fileout,extin,extout;
string input_dir;
char DatDirectory [99];
// Reading .dat files (i want more than one!!!)
extin=".dat";
extout=".root";
cout << "Please enter the directory containing\n"
"the .dat files you wish to plot "<< endl;
cin >> DatDirectory;
cin.getline(DatDirectory, sizeof(DatDirectory));
input_dir=(DatDirectory); // Input Directory from user
cout<<"File you wish to plot? (without .dat extension): ";
// Asking filename
getline(cin, filename);
infile=input_dir+filename+extin;
fileout=filename+extout;
cout<<"Processing Data File: "<<infile<<endl; //Just a check
// Graphic Section
c1 = new TCanvas(infile.c_str(),"My Plot");
TGraph *gr=new TGraph(infile.c_str(),"%lg %lg");
gr->Draw("AL");
// Saving my Graph
TFile *f0=new TFile(fileout.c_str(),"RECREATE");
gr->Write();
f0->Close();
}
this is a working script, you can have fun with it.
Now the deal: is anybody able to tell me, for my mental health sake, how can i input from screen the two run_*.dat at once? And eventually how to save both graphs? I’ll be delighted and forever grateful!!
I would have attached some .dat file but i can’t find how to…
EDIT: .dat files seems not allowed… i attached them as .txt so to use them in the script just change extin=".dat"; into extin=".txt";
or rename the extensions to .dat again
P.S.
I know for sure that the ‘99’ inside char DatDirectory [99]; is giving me a warning (warning: expression result unused [-Wunused-value]) but this is another minor thing i couldn’t figured out till now…run_2.txt (134.2 KB)
run_1.txt (134.0 KB)