AliPhysics  e59a9ba (e59a9ba)
 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-20160524-1", Int_t nSteps = 5,
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 (smode == "saf3") gROOT->LoadMacro("MuonResolution.C++g");
58  else gROOT->LoadMacro("$ALICE_PHYSICS/PWGPP/MUON/dep/MuonResolution.C++g");
59  MuonResolution(smode, inputFileName, rootVersion, aliphysicsVersion, nSteps, selectPhysics, selectTrigger, matchTrig, applyAccCut, applyPDCACut, minMomentum, minPt, isMC, correctForSystematics, extrapMode, shiftHalfCh, shiftDE, nevents);
60 
61  }
62 
63 }
64 
65 //______________________________________________________________________________
66 Bool_t RunAnalysisOnSAF3(TString aliphysicsVersion, TString dataset)
67 {
69 
70  // --- mount nansafmaster3 ---
71  TString saf3dir = gSystem->ExpandPathName("$HOME/saf3");
72  if (gSystem->AccessPathName(saf3dir.Data())) gSystem->Exec(Form("mkdir %s", saf3dir.Data()));
73  if (gSystem->AccessPathName(Form("%s/.vaf", saf3dir.Data()))) {
74  Int_t ret = gSystem->Exec(Form("sshfs -o ssh_command=\"gsissh -p1975\" nansafmaster3.in2p3.fr: %s", saf3dir.Data()));
75  if (ret != 0) {
76  cout<<"mounting of saf3 folder failed"<<endl;
77  return kFALSE;
78  }
79  }
80 
81  // --- create the executable to run on SAF3 ---
82  CreateSAF3Executable(dataset);
83 
84  // --- copy files needed for this analysis ---
85  if (!CopyFileOnSAF3(dataset)) {
86  cout << "cp problem" << endl;
87  return kFALSE;
88  }
89 
90  // --- change the AliPhysics version on SAF3 ---
91  gSystem->Exec(Form("sed -i '' 's/VafAliPhysicsVersion.*/VafAliPhysicsVersion=\"%s\"/g' $HOME/saf3/.vaf/vaf.conf", aliphysicsVersion.Data()));
92 
93  // --- enter SAF3 and run analysis ---
94  TString analysisLocation = gSystem->pwd();
95  analysisLocation.ReplaceAll(Form("%s/", gSystem->Getenv("HOME")), "");
96  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()));
97 
98  // --- copy analysis results (assuming analysis run smootly) ---
99  gSystem->Exec(Form("cp -p %s/%s/*.root .", saf3dir.Data(), analysisLocation.Data()));
100 
101  return kTRUE;
102 
103 }
104 
105 //______________________________________________________________________________
106 Bool_t CopyFileOnSAF3(TString dataset)
107 {
109 
110  TString saf3dir = gSystem->ExpandPathName("$HOME/saf3");
111  if (gSystem->AccessPathName(Form("%s/.vaf", saf3dir.Data()))) {
112  cout<<"saf3 folder is not mounted"<<endl;
113  cout<<"please retry as it can take some time to mount it"<<endl;
114  return kFALSE;
115  }
116 
117  TString remoteLocation = gSystem->pwd();
118  remoteLocation.ReplaceAll(gSystem->Getenv("HOME"),saf3dir.Data());
119  if (gSystem->AccessPathName(remoteLocation.Data())) gSystem->Exec(Form("mkdir -p %s", remoteLocation.Data()));
120 
121  gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PWGPP/MUON/dep/RunMuonResolution.C %s/RunMuonResolution.C", remoteLocation.Data()));
122  gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PWGPP/MUON/dep/MuonResolution.C %s/MuonResolution.C", remoteLocation.Data()));
123  gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PWGPP/MUON/dep/AddTaskMuonResolution.C %s/AddTaskMuonResolution.C", remoteLocation.Data()));
124  //gSystem->Exec(Form("cp -p $ALICE_PHYSICS/PARfiles/PWGPPMUONdep.par %s/PWGPPMUONdep.par", remoteLocation.Data()));
125  gSystem->Exec(Form("cp runAnalysis.sh %s/runAnalysis.sh", remoteLocation.Data()));
126 
127  if (dataset.EndsWith(".txt")) {
128  gSystem->Exec(Form("cat %s | awk {'print $1\";Mode=cache\"}' > datasetSaf3.txt", dataset.Data()));
129  gSystem->Exec(Form("cp datasetSaf3.txt %s/datasetSaf3.txt", remoteLocation.Data()));
130  } else if (dataset.EndsWith(".root"))
131  gSystem->Exec(Form("cp %s %s/%s", dataset.Data(), remoteLocation.Data(), gSystem->BaseName(dataset.Data())));
132 
133  return kTRUE;
134 
135 }
136 
137 //______________________________________________________________________________
138 void CreateSAF3Executable(TString dataset)
139 {
141  ofstream outFile("runAnalysis.sh");
142  outFile << "#!/bin/bash" << endl;
143  outFile << "vafctl start" << endl;
144  Int_t nWorkers = 88;
145  outFile << "nWorkers=" << nWorkers << endl;
146  outFile << "let \"nWorkers -= `pod-info -n`\"" << endl;
147  outFile << "echo \"requesting $nWorkers additional workers\"" << endl;
148  outFile << "vafreq $nWorkers" << endl;
149  outFile << "vafwait " << nWorkers << endl;
150  TString macro = gSystem->GetFromPipe("tail -n 1 $HOME/.root_hist | sed 's/(.*)//g;s/^\.x\ //g;s:^.*/::g'");
151  TString arg = gSystem->GetFromPipe("tail -n 1 $HOME/.root_hist | sed 's/.*(/(/g'");
152  if (dataset.EndsWith(".txt")) arg.ReplaceAll(dataset.Data(), "datasetSaf3.txt");
153  else if (dataset.EndsWith(".root")) arg.ReplaceAll(dataset.Data(), gSystem->BaseName(dataset.Data()));
154  outFile << "root -b -q '" << macro.Data() << arg.Data() << "'" << endl;
155  outFile << "vafctl stop" << endl;
156  outFile.close();
157  gSystem->Exec("chmod u+x runAnalysis.sh");
158 }
159 
TSystem * gSystem
void CreateSAF3Executable(TString dataset)
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]
void RunMuonResolution(TString smode="local", TString inputFileName="AliESDs.root", TString rootVersion="", TString aliphysicsVersion="vAN-20160524-1", Int_t nSteps=5, 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)
Bool_t CopyFileOnSAF3(TString dataset)