Hello I’ve to run a Macro and the process is very long…so I want to divide it in more CPU. I mean
- I must open a TTree from a Root File (1e6 entries)
TFile *fin = TFile::Open("/B1.root");
- I’ve to read three branches of the TTree and save the entries into arrays
ts->SetBranchAddress("SecondaryParticleVert.x", &xVv[0]);
ts->SetBranchAddress("PositionDirection.x", &xv[0]);
ts->SetBranchAddress("SecondaryParticleAng.x", &xpv[0]);
- I’ve to generate 1e6 random entries and I’ve to calculate the emittance for each random entry
for(int jentry=0; jentry<nentries;jentry++) {
entry = gRandom->Integer(ts->GetEntries());
ts->GetEntry(entry);
x+=k*xv[0]-k*xVv[0];
x2+=(k*xv[0]-k*xVv[0])*(k*xv[0]-k*xVv[0]);
xp+=xpv[0];
xp2+=xpv[0]*xpv[0];
xxp+=(k*xv[0]-k*xVv[0])*xpv[0];
}
x*=1./nentries;
x2*=1./nentries;
xp*=1./nentries;
xp2*=1./nentries;
xxp*=1./nentries;
sigmax2=x2-x*x;
sigmaxp2=xp2-xp*xp;
sigmaxsigmaxp=xxp-x*xp;
emittance2=sigmax2*sigmaxp2-sigmaxsigmaxp;
emittance=TMath::Sqrt(emittance2);
emittance/=1000;
- I’ve to repeat the emittance calculation 100 times (i.e. I’ve to extract 100 times the 1e6 random entries)…I call the 100 times Nextractions
- I’ve to save the results into 2 txt files
results << "Extraction = " << i << "\t x = " << x << "\t x2 = " << x2 << " \t xp = " << xp << " \t xp2= " << xp2 << " \t xxp= " << xxp << endl;
results << "sigmax2 = " << sigmax2 << "\t sigmaxp2 = " << sigmaxp2 << "\t sigmaxsigmaxp = " << sigmaxsigmaxp << " \t emittance = " << emittance << endl;
resultsthf << emittance << endl;
- I’ve to file a TH1F
hscoring->Fill(emittance);
and to print it
c0->Print("emittanceer_xxp.pdf");
When I was using TTree having just some thousand of events I did it using one for cycle in this way:
int Nextraction=100;
for(i=0; i<Nextraction;i++) {
Double_t emittance=0.;
Double_t emittance2=0.;
Double_t x=0;
Double_t x2=0;
Double_t xp=0;
Double_t xp2=0;
Double_t xxp=0;
Double_t sigmax2=0;
Double_t sigmaxp2=0;
Double_t sigmaxsigmaxp=0;
int nentries = ts->GetEntries();
double xv[10];
double xVv[10];
double xpv[10];
int entry;
int k=1000000000;
ts->SetBranchAddress("SecondaryParticleVert.x", &xVv[0]);
ts->SetBranchAddress("PositionDirection.x", &xv[0]);
ts->SetBranchAddress("SecondaryParticleAng.x", &xpv[0]);
for(int jentry=0; jentry<nentries;jentry++) {
entry = gRandom->Integer(ts->GetEntries());
ts->GetEntry(entry);
x+=k*xv[0]-k*xVv[0];
x2+=(k*xv[0]-k*xVv[0])*(k*xv[0]-k*xVv[0]);
xp+=xpv[0];
xp2+=xpv[0]*xpv[0];
xxp+=(k*xv[0]-k*xVv[0])*xpv[0];
}
etc.
and I did it in just few time
Here the working old macro
emiter.cpp (5.4 KB)
Unfortunately, now I’ve 1e6 entries in the Root file and I need 1 day just to repeat the process 10 times (i.e. I need 10 days to repeat the process 100 times)…so I need to divide the proces in more CPU
then I was trying to divide the process on 10 CPU so that each CPU makes 10 extraction simultanley and (but I’ve to get the total results on the txt file and on the TH1F plot)
Then I was trying to write a sh shell
#
for i in {0..9}
do
seed=$(($1+i))
echo $seed
#
nohup root -b -q '.x emiter.cpp('$seed')'
#
done
#
and I modified my macro deleting the line
for(i=0; i<Nextraction;i++) {
and replacing the line
void emiter()
{
by
void emiter(Int_t seed=0){
TRandom *r = new TRandom();
r->SetSeed(seed);
Then I uploaded my sh file and my new emiter.cpp macro on the laboratory machine and I’m trying to run the macro using the commands
source bootstrap_script.sh 0
source bootstrap_script.sh 10
source bootstrap_script.sh 20
...
source bootstrap_script.sh 90
to get 100 simultanley extractions, but
it doesnt’ work ie. I get the error
Warning in <TInterpreter::ReadRootmapFile>: class TPyArg found in libPyROOT.so is already in libROOTTPython.so
Warning in <TInterpreter::ReadRootmapFile>: class TPyReturn found in libPyROOT.so is already in libROOTTPython.so
Warning in <TInterpreter::ReadRootmapFile>: class TPython found in libPyROOT.so is already in libROOTTPython.so
Warning in <TApplication::GetOptions>: macro .x emiter.cpp not found
Here the new macro (I don’t know if I wrote in the right place the
void emiter(Int_t seed=0){
TRandom *r = new TRandom();
r->SetSeed(seed);
emiter.cpp (5.5 KB)
Here the shell
bootstrap_script.txt (100 Bytes)
and here the error report
nohup.txt (8.9 KB)
Does anyone know how to do what I need ?
Thank you
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided