183 lines
4.4 KiB
C

// File: plotRge.C
// Author: Zaher Salman, originally by Andreas Suter
// Date: 03/06/2009
// Purpose: ROOT macro to read and plot Range data from trimsp calculation
// Assume following file Format:
//
// $Id$
//
// DEPTH PARTICLES
// 15. 260
// 45. 595
// 75. 820
// 105. 1179
//
// plotRge(names), e.g.
// plotRge("InSne_E2500, InSne_E4000");
// will read files
void plotRge(TString &names)
{
if (names.CompareTo("help", TString::kIgnoreCase) == 0) {
cout << endl << "usage: plotRge(<names>) or plotRge(\"help\")";
cout << endl << " <names> is a list of rge-files";
cout << endl << endl;
return;
}
TObjArray *tokens;
TObjString *ostr;
TString str;
char cstr[128];
Int_t i, j;
Int_t nStep = 0;
Int_t nStepmax = 0;
Double_t *depth;
Double_t *nStop;
Double_t *depthmax;
Double_t *nStopmax;
Double_t norm;
Double_t intNorm;
Double_t normStop[1000];
Double_t normStopmax[1000];
TString pathname;
int sep;
TString path;
TString name,legtit;
Int_t col;
Int_t color[1000];
for (i=0; i<1000; i++)
color[i] = -1;
color[0] = TColor::kRed;
color[1] = TColor::kGreen;
color[2] = TColor::kBlue;
color[3] = TColor::kMagenta;
color[4] = TColor::kOrange;
color[5] = TColor::kViolet;
color[6] = TColor::kAzure+7;
color[7] = TColor::kOrange+4;
color[8] = TColor::kBlue-7;
TGraph *rge[1000];
TMultiGraph *mg = new TMultiGraph();
TLegend *legend = new TLegend(0.7, 0.7, 0.95, 0.95);
legend->SetFillColor(TColor::GetColor(255,255,255)); // white
tokens = names.Tokenize(" \t,;");
Double_t min = 0, max = 0, xmax = 0, xmin = 0;
Int_t imax;
// Loop over file names
for (i=0; i<tokens->GetEntries(); i++) {
ostr = dynamic_cast<TObjString*>(tokens->At(i));
str = ostr->GetString();
cout << endl << i << ": read " << str.Data();
TGraph *fileGraph = new TGraph(str);
if ( fileGraph->IsZombie() ){
cout << endl;
cout << "File " << str << " does not exist!!!" << endl << endl;
return;
}
depth = fileGraph->GetX();
nStop = fileGraph->GetY();
nStep = fileGraph->GetN(); // Number of points in range
// calculate step size in nm (convert from AA)
norm = (depth[1] - depth[0])/10;
// intNorm is the total stopping particles
intNorm = 0.0;
for (j=0; j<nStep; j++) {
intNorm += nStop[j];
}
for (j=0; j<nStep; j++) {
// Calculate normalized stopping profile
if (norm > 0.) {
// devide original profile by (step size * total particles) in %
normStop[j] = 100*nStop[j]/(norm*intNorm);
} else {
normStop[j] = -1.;
}
// rescale depth to nm
depth[j] = depth[j]/10.;
}
rge[i] = new TGraph(nStep, depth, normStop);
if (color[i] >= 0) {
rge[i]->SetMarkerColor(color[i]);
rge[i]->SetLineColor(color[i]);
} else {
TRandom *rand = new TRandom(i);
col = TColor::GetColor((Int_t)rand->Integer(255),(Int_t)rand->Integer(255),(Int_t)rand->Integer(255));
rge[i]->SetMarkerColor(col);
rge[i]->SetLineColor(col);
delete rand;
}
rge[i]->SetMarkerStyle(20);
mg->Add(rge[i]);
ostr = dynamic_cast<TObjString*>(tokens->At(i));
str = ostr->GetString() + ", ";
sprintf(cstr, "%.1lf", ostr->GetString().Atof() /1000.0);
str += cstr;
// remove path
sep = str.Last('/');
path = str(0,sep);
name = str(sep+1,str.Length()-sep-1);
// remove comma etc.
sep = name.Last(',');
name = name(0,sep);
// remove extension etc.
sep = name.Last('.');
name = name(0,sep);
// remove ????_ etc.
sep = name.Last('_');
path = name(sep+1);
name = name(sep+2,name.Length()-sep-1);
legtit = "";
legtit += path;
legtit += "=";
legtit += name;
legtit += " (eV)";
cout << endl << legtit << endl ;
rge[i]->SetTitle(str.Data());
rge[i]->SetFillColor(TColor::kWhite);
legend->AddEntry(rge[i], legtit);
delete fileGraph;
}
cout << endl;
mg->Draw("APC");
mg->GetXaxis()->SetTitle("Depth [nm]");
mg->GetYaxis()->SetTitle("Normalized Stopping Profile [%/nm]");
legend->Draw();
delete tokens;
// I am not sure what this does, but it waits until canvas is closed
c1->WaitPrimitive(" ");
cout << endl << "Canvas Closed" << endl ;
// Then quit root cleanly
gApplication->Terminate();
}