AliPhysics  63e47e1 (63e47e1)
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", Int_t nSteps = 5,
16  TString rootVersion = "", TString aliphysicsVersion = "vAN-20180105-1",
17  TString dataDir = "/alice/sim/2016/LHC16e2_plus",
18  TString dataPattern = "p20/*/AliESDs.root",
19  TString runFormat = "%d",
20  TString outDir = "Sim/LHC15o/EmbedV2b/Resolution/20GeV",
21  Int_t maxFilesPerJob = 500, Int_t maxMergeFiles = 10, Int_t maxMergeStages = 2,
22  Bool_t selectPhysics = kTRUE, Bool_t selectTrigger = kTRUE, Bool_t matchTrig = kTRUE,
23  Bool_t applyAccCut = kTRUE, Bool_t applyPDCACut = kTRUE, Double_t minMomentum = 20., Double_t minPt = 0.,
24  Bool_t isMC = kFALSE, Bool_t correctForSystematics = kTRUE, Int_t extrapMode = 1,
25  Bool_t shiftHalfCh = kFALSE, Bool_t shiftDE = kFALSE, Int_t nevents = 1234567890)
26 {
54 
55  if (smode == "saf3" && gSystem->GetFromPipe("hostname") != "nansafmaster3.in2p3.fr") {
56 
57  // run on SAF3
58  if (!RunAnalysisOnSAF3(aliphysicsVersion, inputFileName)) return;
59 
60  // draw the results locally
61  TFile* outFile = TFile::Open("results.root","READ");
62  if (!outFile || !outFile->IsOpen()) return;
63  outFile->FindObjectAny("convergenceRes")->Draw();
64  outFile->FindObjectAny("convergenceShift")->Draw();
65  outFile->Close();
66 
67  } else {
68 
69  gROOT->ProcessLine(".include $ALICE_ROOT/include");
70  gROOT->ProcessLine(".include $ALICE_PHYSICS/include");
71 
72  // compile analysis macro locally
73  //if (!AliAnalysisAlien::SetupPar("PWGPPMUONdep.par")) return kFALSE;
74  if (smode == "saf3") gROOT->LoadMacro("MuonResolution.C++g");
75  else gROOT->LoadMacro("$ALICE_PHYSICS/PWGPP/MUON/dep/MuonResolution.C++g");
76  MuonResolution(smode, inputFileName, nSteps, rootVersion, aliphysicsVersion, dataDir, dataPattern, runFormat, outDir, maxFilesPerJob, maxMergeFiles, maxMergeStages, selectPhysics, selectTrigger, matchTrig, applyAccCut, applyPDCACut, minMomentum, minPt, isMC, correctForSystematics, extrapMode, shiftHalfCh, shiftDE, nevents);
77 
78  }
79 
80 }
81 
82 //______________________________________________________________________________
83 Bool_t RunAnalysisOnSAF3(TString aliphysicsVersion, TString dataset)
84 {
86 
87  // --- mount nansafmaster3 ---
88  TString saf3dir = gSystem->ExpandPathName("$HOME/saf3");
89  if (gSystem->AccessPathName(saf3dir.Data())) gSystem->Exec(Form("mkdir %s", saf3dir.Data()));
90  if (gSystem->AccessPathName(Form("%s/.vaf", saf3dir.Data()))) {
91  Int_t ret = gSystem->Exec(Form("sshfs -o ssh_command=\"gsissh -p1975\" nansafmaster3.in2p3.fr: %s", saf3dir.Data()));
92  if (ret != 0) {
93  cout<<"mounting of saf3 folder failed"<<endl;
94  return kFALSE;
95  }
96  }
97 
98  // --- create the executable to run on SAF3 ---
99  CreateSAF3Executable(dataset);
100 
101  // --- copy files needed for this analysis ---
102  if (!CopyFileOnSAF3(dataset)) {
103  cout << "cp problem" << endl;
104  return kFALSE;
105  }
106 
107  // --- change the AliPhysics version on SAF3 ---
108  gSystem->Exec(Form("sed -i '' 's/VafAliPhysicsVersion.*/VafAliPhysicsVersion=\"%s\"/g' $HOME/saf3/.vaf/vaf.conf", aliphysicsVersion.Data()));
109 
110  // --- enter SAF3 and run analysis ---
111  TString analysisLocation = gSystem->pwd();
112  analysisLocation.ReplaceAll(Form("%s/", gSystem->Getenv("HOME")), "");
113  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()));
114 
115  // --- copy analysis results (assuming analysis run smootly) ---
116  gSystem->Exec(Form("cp -p %s/%s/*.root .", saf3dir.Data(), analysisLocation.Data()));
117 
118  return kTRUE;
119 
120 }
121 
122 //______________________________________________________________________________
124 {
126 
127  TString saf3dir = gSystem->ExpandPathName("$HOME/saf3");
128  if (gSystem->AccessPathName(Form("%s/.vaf", saf3dir.Data()))) {
129  cout<<"saf3 folder is not mounted"<<endl;
130  cout<<"please retry as it can take some time to mount it"<<endl;
131  return kFALSE;
132  }
133 
134  TString remoteLocation = gSystem->pwd();
135  remoteLocation.ReplaceAll(gSystem->Getenv("HOME"),saf3dir.Data());
136  if (gSystem->AccessPathName(remoteLocation.Data())) gSystem->Exec(Form("mkdir -p %s", remoteLocation.Data()));
137 
138  gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PWGPP/MUON/dep/RunMuonResolution.C %s/RunMuonResolution.C", remoteLocation.Data()));
139  gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PWGPP/MUON/dep/MuonResolution.C %s/MuonResolution.C", remoteLocation.Data()));
140  gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PWGPP/MUON/dep/AddTaskMuonResolution.C %s/AddTaskMuonResolution.C", remoteLocation.Data()));
141  //gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PARfiles/PWGPPMUONdep.par %s/PWGPPMUONdep.par", remoteLocation.Data()));
142  gSystem->Exec(Form("cp runAnalysis.sh %s/runAnalysis.sh", remoteLocation.Data()));
143 
144  if (dataset.EndsWith(".txt")) {
145  gSystem->Exec(Form("cat %s | awk {'print $1\";Mode=cache\"}' > datasetSaf3.txt", dataset.Data()));
146  gSystem->Exec(Form("cp datasetSaf3.txt %s/datasetSaf3.txt", remoteLocation.Data()));
147  } else if (dataset.EndsWith(".root"))
148  gSystem->Exec(Form("cp %s %s/%s", dataset.Data(), remoteLocation.Data(), gSystem->BaseName(dataset.Data())));
149 
150  return kTRUE;
151 
152 }
153 
154 //______________________________________________________________________________
156 {
158  ofstream outFile("runAnalysis.sh");
159  outFile << "#!/bin/bash" << endl;
160  outFile << "vafctl start" << endl;
161  Int_t nWorkers = 80;
162  outFile << "nWorkers=" << nWorkers << endl;
163  outFile << "let \"nWorkers -= `pod-info -n`\"" << endl;
164  outFile << "echo \"requesting $nWorkers additional workers\"" << endl;
165  outFile << "vafreq $nWorkers" << endl;
166  outFile << "vafwait " << nWorkers << endl;
167  TString macro = gSystem->GetFromPipe("tail -n 1 $HOME/.root_hist | sed 's/(.*)//g;s/^\.x\ //g;s:^.*/::g'");
168  TString arg = gSystem->GetFromPipe("tail -n 1 $HOME/.root_hist | sed 's/.*(/(/g'");
169  if (dataset.EndsWith(".txt")) arg.ReplaceAll(dataset.Data(), "datasetSaf3.txt");
170  else if (dataset.EndsWith(".root")) arg.ReplaceAll(dataset.Data(), gSystem->BaseName(dataset.Data()));
171  outFile << "root -b -q '" << macro.Data() << arg.Data() << "'" << endl;
172  outFile << "vafctl stop" << endl;
173  outFile.close();
174  gSystem->Exec("chmod u+x runAnalysis.sh");
175 }
176 
double Double_t
Definition: External.C:58
void RunMuonResolution(TString smode="local", TString inputFileName="AliESDs.root", Int_t nSteps=5, TString rootVersion="", TString aliphysicsVersion="vAN-20180105-1", TString dataDir="/alice/sim/2016/LHC16e2_plus", TString dataPattern="p20/*/AliESDs.root", TString runFormat="%d", TString outDir="Sim/LHC15o/EmbedV2b/Resolution/20GeV", Int_t maxFilesPerJob=500, Int_t maxMergeFiles=10, Int_t maxMergeStages=2, Bool_t selectPhysics=kTRUE, Bool_t selectTrigger=kTRUE, Bool_t matchTrig=kTRUE, Bool_t applyAccCut=kTRUE, Bool_t applyPDCACut=kTRUE, Double_t minMomentum=20., 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)
TSystem * gSystem
void MuonResolution(TString smode, TString inputFileName, Int_t nSteps, TString rootVersion, TString aliphysicsVersion, TString dataDir, TString dataPattern, TString runFormat, TString outDir, Int_t maxFilesPerJob, Int_t maxMergeFiles, Int_t maxMergeStages, 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)
void CreateSAF3Executable(TString dataset)
int Int_t
Definition: External.C:63
Bool_t RunAnalysisOnSAF3(TString aliphysicsVersion, TString dataset)
Bool_t isMC
Int_t nevents[nsamples]
Bool_t CopyFileOnSAF3(TString dataset)
bool Bool_t
Definition: External.C:53