AliPhysics  251aa1e (251aa1e)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunMuonResolution.C
Go to the documentation of this file.
1 //--------------------------------------------------------------------------
2 // Base macro for submitting muon Resolution analysis.
3 //
4 // It needs to load magnetic field, mapping, geometry (+alignment), and reconstruction parameters from the OCDB
5 // It is done by the task and OCDB storage locations can be parameterized in MuonResolution.C (default is raw://)
6 //
7 // The task reads ESDs
8 // Intermediate results are stored in a file chamberResolution_step<#step>.root
9 // Final results are stored in the file results.root
10 //
11 // Author: Philippe Pillot - SUBATECH Nantes
12 //--------------------------------------------------------------------------
13 
14 //______________________________________________________________________________
15 void RunMuonResolution(TString smode = "local", TString inputFileName = "AliESDs.root",
16  TString rootVersion = "", TString aliphysicsVersion = "vAN-20161011-1", Int_t nSteps = 3,
17  Bool_t selectPhysics = kTRUE, Bool_t selectTrigger = kTRUE, Bool_t matchTrig = kTRUE,
18  Bool_t applyAccCut = kTRUE, Bool_t applyPDCACut = kTRUE, Double_t minMomentum = 0., Double_t minPt = 0.,
19  Bool_t isMC = kFALSE, Bool_t correctForSystematics = kTRUE, Int_t extrapMode = 1,
20  Bool_t shiftHalfCh = kFALSE, Bool_t shiftDE = kFALSE, Int_t nevents = 1234567890)
21 {
38 
39  if (smode == "saf3" && gSystem->GetFromPipe("hostname") != "nansafmaster3.in2p3.fr") {
40 
41  // run on SAF3
42  if (!RunAnalysisOnSAF3(aliphysicsVersion, inputFileName)) return;
43 
44  // draw the results locally
45  TFile* outFile = TFile::Open("results.root","READ");
46  if (!outFile || !outFile->IsOpen()) return;
47  outFile->FindObjectAny("convergenceRes")->Draw();
48  outFile->FindObjectAny("convergenceShift")->Draw();
49  outFile->Close();
50 
51  } else {
52 
53  gROOT->ProcessLine(".include $ALICE_ROOT/include");
54  gROOT->ProcessLine(".include $ALICE_PHYSICS/include");
55 
56  // compile analysis macro locally
57  //if (!AliAnalysisAlien::SetupPar("PWGPPMUONdep.par")) return kFALSE;
58  if (smode == "saf3") gROOT->LoadMacro("MuonResolution.C++g");
59  else gROOT->LoadMacro("$ALICE_PHYSICS/PWGPP/MUON/dep/MuonResolution.C++g");
60  MuonResolution(smode, inputFileName, rootVersion, aliphysicsVersion, nSteps, selectPhysics, selectTrigger, matchTrig, applyAccCut, applyPDCACut, minMomentum, minPt, isMC, correctForSystematics, extrapMode, shiftHalfCh, shiftDE, nevents);
61 
62  }
63 
64 }
65 
66 //______________________________________________________________________________
67 Bool_t RunAnalysisOnSAF3(TString aliphysicsVersion, TString dataset)
68 {
70 
71  // --- mount nansafmaster3 ---
72  TString saf3dir = gSystem->ExpandPathName("$HOME/saf3");
73  if (gSystem->AccessPathName(saf3dir.Data())) gSystem->Exec(Form("mkdir %s", saf3dir.Data()));
74  if (gSystem->AccessPathName(Form("%s/.vaf", saf3dir.Data()))) {
75  Int_t ret = gSystem->Exec(Form("sshfs -o ssh_command=\"gsissh -p1975\" nansafmaster3.in2p3.fr: %s", saf3dir.Data()));
76  if (ret != 0) {
77  cout<<"mounting of saf3 folder failed"<<endl;
78  return kFALSE;
79  }
80  }
81 
82  // --- create the executable to run on SAF3 ---
83  CreateSAF3Executable(dataset);
84 
85  // --- copy files needed for this analysis ---
86  if (!CopyFileOnSAF3(dataset)) {
87  cout << "cp problem" << endl;
88  return kFALSE;
89  }
90 
91  // --- change the AliPhysics version on SAF3 ---
92  gSystem->Exec(Form("sed -i '' 's/VafAliPhysicsVersion.*/VafAliPhysicsVersion=\"%s\"/g' $HOME/saf3/.vaf/vaf.conf", aliphysicsVersion.Data()));
93 
94  // --- enter SAF3 and run analysis ---
95  TString analysisLocation = gSystem->pwd();
96  analysisLocation.ReplaceAll(Form("%s/", gSystem->Getenv("HOME")), "");
97  gSystem->Exec(Form("gsissh -p 1975 -t -Y nansafmaster3.in2p3.fr 'cd %s; ~/saf3-enter \"\" \"./runAnalysis.sh 2>&1 | tee runAnalysis.log; exit\"'", analysisLocation.Data()));
98 
99  // --- copy analysis results (assuming analysis run smootly) ---
100  gSystem->Exec(Form("cp -p %s/%s/*.root .", saf3dir.Data(), analysisLocation.Data()));
101 
102  return kTRUE;
103 
104 }
105 
106 //______________________________________________________________________________
108 {
110 
111  TString saf3dir = gSystem->ExpandPathName("$HOME/saf3");
112  if (gSystem->AccessPathName(Form("%s/.vaf", saf3dir.Data()))) {
113  cout<<"saf3 folder is not mounted"<<endl;
114  cout<<"please retry as it can take some time to mount it"<<endl;
115  return kFALSE;
116  }
117 
118  TString remoteLocation = gSystem->pwd();
119  remoteLocation.ReplaceAll(gSystem->Getenv("HOME"),saf3dir.Data());
120  if (gSystem->AccessPathName(remoteLocation.Data())) gSystem->Exec(Form("mkdir -p %s", remoteLocation.Data()));
121 
122  gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PWGPP/MUON/dep/RunMuonResolution.C %s/RunMuonResolution.C", remoteLocation.Data()));
123  gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PWGPP/MUON/dep/MuonResolution.C %s/MuonResolution.C", remoteLocation.Data()));
124  gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PWGPP/MUON/dep/AddTaskMuonResolution.C %s/AddTaskMuonResolution.C", remoteLocation.Data()));
125  //gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PARfiles/PWGPPMUONdep.par %s/PWGPPMUONdep.par", remoteLocation.Data()));
126  gSystem->Exec(Form("cp runAnalysis.sh %s/runAnalysis.sh", remoteLocation.Data()));
127 
128  if (dataset.EndsWith(".txt")) {
129  gSystem->Exec(Form("cat %s | awk {'print $1\";Mode=cache\"}' > datasetSaf3.txt", dataset.Data()));
130  gSystem->Exec(Form("cp datasetSaf3.txt %s/datasetSaf3.txt", remoteLocation.Data()));
131  } else if (dataset.EndsWith(".root"))
132  gSystem->Exec(Form("cp %s %s/%s", dataset.Data(), remoteLocation.Data(), gSystem->BaseName(dataset.Data())));
133 
134  return kTRUE;
135 
136 }
137 
138 //______________________________________________________________________________
140 {
142  ofstream outFile("runAnalysis.sh");
143  outFile << "#!/bin/bash" << endl;
144  outFile << "vafctl start" << endl;
145  Int_t nWorkers = 88;
146  outFile << "nWorkers=" << nWorkers << endl;
147  outFile << "let \"nWorkers -= `pod-info -n`\"" << endl;
148  outFile << "echo \"requesting $nWorkers additional workers\"" << endl;
149  outFile << "vafreq $nWorkers" << endl;
150  outFile << "vafwait " << nWorkers << endl;
151  TString macro = gSystem->GetFromPipe("tail -n 1 $HOME/.root_hist | sed 's/(.*)//g;s/^\.x\ //g;s:^.*/::g'");
152  TString arg = gSystem->GetFromPipe("tail -n 1 $HOME/.root_hist | sed 's/.*(/(/g'");
153  if (dataset.EndsWith(".txt")) arg.ReplaceAll(dataset.Data(), "datasetSaf3.txt");
154  else if (dataset.EndsWith(".root")) arg.ReplaceAll(dataset.Data(), gSystem->BaseName(dataset.Data()));
155  outFile << "root -b -q '" << macro.Data() << arg.Data() << "'" << endl;
156  outFile << "vafctl stop" << endl;
157  outFile.close();
158  gSystem->Exec("chmod u+x runAnalysis.sh");
159 }
160 
double Double_t
Definition: External.C:58
TSystem * gSystem
void RunMuonResolution(TString smode="local", TString inputFileName="AliESDs.root", TString rootVersion="", TString aliphysicsVersion="vAN-20161011-1", Int_t nSteps=3, Bool_t selectPhysics=kTRUE, Bool_t selectTrigger=kTRUE, Bool_t matchTrig=kTRUE, Bool_t applyAccCut=kTRUE, Bool_t applyPDCACut=kTRUE, Double_t minMomentum=0., Double_t minPt=0., Bool_t isMC=kFALSE, Bool_t correctForSystematics=kTRUE, Int_t extrapMode=1, Bool_t shiftHalfCh=kFALSE, Bool_t shiftDE=kFALSE, Int_t nevents=1234567890)
void CreateSAF3Executable(TString dataset)
int Int_t
Definition: External.C:63
Bool_t RunAnalysisOnSAF3(TString aliphysicsVersion, TString dataset)
void MuonResolution(TString smode, TString inputFileName, TString rootVersion, TString aliphysicsVersion, Int_t nSteps, Bool_t selectPhysics, Bool_t selectTrigger, Bool_t matchTrig, Bool_t applyAccCut, Bool_t applyPDCACut, Double_t minMomentum, Double_t minPt, Bool_t isMC, Bool_t correctForSystematics, Int_t extrapMode, Bool_t shiftHalfCh, Bool_t shiftDE, Int_t nevents)
Bool_t isMC
Int_t nevents[nsamples]
Bool_t CopyFileOnSAF3(TString dataset)
bool Bool_t
Definition: External.C:53