#include <TMath.h>
#include <TList.h>
#include <iostream>
+#include <TAxis.h>
//
// A class to calculate the multiplicity in @f$(x,y)@f$ bins
// using Poisson statistics.
//
-// The input is assumed to be binned in @f$(x,y)@f$ with the number of channels
-// input to the Reset member function.
+// The input is assumed to be binned in @f$(x,y)@f$ as described by
+// the 2D histogram passwd to the Reset member function.
//
// The data is grouped in to regions as defined by the parameters
// fXLumping and fYLumping. The total number of cells and number of
//
//
+namespace {
+ const char* kBasicN = "basic";
+ const char* kEmptyN = "empty";
+ const char* kTotalN = "total";
+ const char* kBasicT = "Basic number of hits";
+ const char* kEmptyT = "Empty number of bins/region";
+ const char* kTotalT = "Total number of bins/region";
+}
+
+
+
+
//____________________________________________________________________
AliPoissonCalculator::AliPoissonCalculator()
: TNamed(),
}
//____________________________________________________________________
-AliPoissonCalculator::AliPoissonCalculator(const char*/*, UShort_t d, Char_t r*/)
+AliPoissonCalculator::AliPoissonCalculator(const char*)
: TNamed("poissonCalculator", "Calculate N_ch using Poisson stat"),
fXLumping(32),
fYLumping(4),
fCorr(0)
{
Init();
-// Reset();
+ Reset(o.fBasic);
}
//____________________________________________________________________
fYLumping = o.fYLumping;
CleanUp();
Init();
- // Reset();
+ Reset(o.fBasic);
return *this;
}
//Create diagnostics if void
if (fEmptyVsTotal) return;
- MakeOutput();
-
+ MakeOutput();
+}
+//____________________________________________________________________
+void
+AliPoissonCalculator::Define(const TAxis& xaxis, const TAxis& yaxis)
+{
+ //
+ // Initialize
+ //
+ const Double_t* xBins = xaxis.GetXbins()->GetArray();
+ const Double_t* yBins = yaxis.GetXbins()->GetArray();
+ Int_t nX = xaxis.GetNbins();
+ Int_t nY = yaxis.GetNbins();
+ Double_t lX = xaxis.GetXmin();
+ Double_t hX = xaxis.GetXmax();
+ Double_t lY = yaxis.GetXmin();
+ Double_t hY = yaxis.GetXmax();
+ if (xBins) {
+ if (yBins) fBasic = new TH2D(kBasicN, kBasicT, nX, xBins, nY, yBins);
+ else fBasic = new TH2D(kBasicN, kBasicT, nX, xBins, nY, lY, hY);
+ }
+ else {
+ if (yBins) fBasic = new TH2D(kBasicN, kBasicT, nX, lX, hX, nY, yBins);
+ else fBasic = new TH2D(kBasicN, kBasicT, nX, lX, hX, nY, lY, hY);
+ }
+ fBasic->SetXTitle(xaxis.GetTitle());
+ fBasic->SetYTitle(yaxis.GetTitle());
+
+ Reset(fBasic);
}
- //____________________________________________________________________
+//____________________________________________________________________
void AliPoissonCalculator::MakeOutput() {
Int_t n = fXLumping * fYLumping + 1;
Init(nx, ny);
}
+//____________________________________________________________________
+Int_t
+AliPoissonCalculator::CheckLumping(char which, Int_t nBins, Int_t lumping) const
+{
+ if ((nBins % lumping) == 0) return lumping;
+ Int_t l = lumping;
+ do {
+ l--;
+ } while (l > 0 && ((nBins % l) != 0));
+ Warning("CheckLumping", "%c lumping %d is not a divisor of %d, set to %d",
+ which, lumping, nBins, l);
+ return l;
+}
+
//____________________________________________________________________
void
-AliPoissonCalculator::Reset(UShort_t xChannels, UShort_t yChannels)
+AliPoissonCalculator::Reset(const TH2D* base)
{
//
// Reset histogram
//
-
if (fBasic && fTotal && fEmpty) {
fBasic->Reset();
fTotal->Reset();
fEmpty->Reset();
return;
}
- Int_t nXF = xChannels;
- Int_t nX = nXF / fXLumping;
- Double_t xMin = -0.5;
- Double_t xMax = nXF - 0.5;
- Int_t nYF = yChannels;
+
+ if (!base) return;
+
+ Int_t nXF = base->GetNbinsX();
+ Double_t xMin = base->GetXaxis()->GetXmin();
+ Double_t xMax = base->GetXaxis()->GetXmax();
+ Int_t nYF = base->GetNbinsY();
+ Double_t yMin = base->GetYaxis()->GetXmin();
+ Double_t yMax = base->GetYaxis()->GetXmax();
+
+ fXLumping = CheckLumping('X', nXF, fXLumping);
+ fYLumping = CheckLumping('Y', nYF, fYLumping);
+
Int_t nY = nYF / fYLumping;
- Double_t yMin = -0.5;
- Double_t yMax = nYF - 0.5;
+ Int_t nX = nXF / fXLumping;
- fBasic = new TH2D("basic", "basic number of hits",
- nX, xMin, xMax, nY, yMin, yMax);
- fBasic->SetTitle("Basic number of hits");
- fBasic->SetDirectory(0);
- fBasic->Sumw2();
+ if (fBasic != base) {
+ fBasic = static_cast<TH2D*>(base->Clone(kBasicN));
+ fBasic->SetTitle(kBasicT);
+ fBasic->SetDirectory(0);
+ fBasic->Sumw2();
+ }
- fTotal = new TH2D("total", "Total number of bins/region",
- nX, xMin, xMax, nY, yMin, yMax);
+ fTotal = new TH2D(kTotalN, kTotalT, nX, xMin, xMax, nY, yMin, yMax);
fTotal->SetDirectory(0);
fTotal->SetXTitle(fBasic->GetXaxis()->GetTitle());
fTotal->SetYTitle(fBasic->GetYaxis()->GetTitle());
fTotal->Sumw2();
- fEmpty = static_cast<TH2D*>(fTotal->Clone("empty"));
- fEmpty->SetTitle("Empty number of bins/region");
+ fEmpty = static_cast<TH2D*>(fTotal->Clone(kEmptyN));
+ fEmpty->SetTitle(kEmptyT);
fEmpty->SetDirectory(0);
// fEmpty->Sumw2();
}
*/
void SetAllowOverwrite(Bool_t allow) { fAllowOverwrite = allow; }
//__________________________________________________________________
+ /**
+ * Service function to make a PAR out of a script.
+ *
+ * The script should contain can contain a sub-class of AliAnalysisTask.
+ * The script will be compiled on the slaves before loading the
+ * AliAnalysisManager. Parts to (not) be compiled can be protected like
+ *
+ * @code
+ * #ifdef BUILD_PAR
+ * // This will _only_ be compiled in the servers
+ * #endif
+ * #ifndef BUILD_PAR
+ * // This will not be compiled in the servers
+ * #endif
+ * @endcode
+ *
+ * @param script Script to upload and compile in the PAR
+ * @param deps Dependency pars
+ *
+ * @return true on success.
+ */
+ static Bool_t MakeScriptPAR(const char* script, const char* deps)
+ {
+ // Get the base name
+ TString base(gSystem->BaseName(script));
+ Int_t idx = base.Last('.');
+ if (idx != kNPOS) base.Remove(idx);
+ Bool_t retval = true;
+ Info("MakeScriptPAR", "script=%s, base=%s", script, base.Data());
+
+ try {
+ // Check name of script file
+ TString scr(script);
+ TString ext;
+ if (scr.EndsWith(".C")) ext = "C";
+ else if (scr.EndsWith(".cxx")) ext = "cxx";
+ else { ext = "C"; scr.Append(".C"); }
+
+ // Check if we can access the file
+ TString path = TString::Format(".:%s", TROOT::GetMacroPath());
+ char* loc = gSystem->Which(path, scr);
+ if (!loc) throw TString::Format("Script %s not found in %s",
+ scr.Data(), path.Data());
+ TString full(loc);
+
+
+ // Set-up directories
+ if (gSystem->MakeDirectory(base) < 0) {
+ base = "";
+ throw TString::Format("Could not make directory '%s'", base.Data());
+ }
+
+ if (gSystem->MakeDirectory(Form("%s/PROOF-INF", base.Data())))
+ throw TString::Format("Could not make directory %s/PROOF-INF",
+ base.Data());
+
+ // Copy the script to the setup directory
+ TString dest = TString::Format("%s/%s.%s", base.Data(),
+ base.Data(), ext.Data());
+ Int_t ret = gSystem->CopyFile(full, dest, true);
+ switch (ret) {
+ case -1: throw TString::Format("Couldn't open %s for copy", scr.Data());
+ case -2: throw TString::Format("File %s exists", dest.Data());
+ case -3: throw TString::Format("Error while copying %s", scr.Data());
+ }
+
+ // Make our build file
+ std::ofstream build(Form("%s/PROOF-INF/BUILD.sh", base.Data()));
+ if (!build)
+ throw TString::Format("Failed to open build shell script");
+ build << "#!/bin/sh\n"
+ << "echo BUILD.sh@`hostname`: Building " << base << "\n"
+ << "root.exe -l -b -q PROOF-INF/BUILD.C 2>&1 | tee " << base << ".log\n"
+ << "echo BUILD.sh@`hostname`: done: $?\n"
+ << std::endl;
+ build.close();
+ if (gSystem->Chmod(Form("%s/PROOF-INF/BUILD.sh", base.Data()), 0755) != 0)
+ throw TString::Format("Failed to set exectuable flags on "
+ "%s/PROOF-INF/BUILD.sh", base.Data());
+
+ std::ofstream util(Form("%s/PROOF-INF/UTIL.C", base.Data()));
+ if (!util)
+ throw TString::Format("Failed to open utility script");
+ util << "void LoadROOTLibs() {\n"
+ << " gSystem->Load(\"libVMC\");\n"
+ << " gSystem->Load(\"libNet\");\n"
+ << " gSystem->Load(\"libTree\");\n"
+ << " gSystem->Load(\"libPhysics\");\n"
+ << " gSystem->Load(\"libMinuit\");\n"
+ << "}\n\n"
+ << "void AddDep(const char* env) {\n"
+ << " TString val(gSystem->Getenv(Form(\"%s_INCLUDE\",env)));\n"
+ << " if (val.IsNull())\n"
+ << " Warning(\"Add\",\"%s_INCLUDE not defined\", env);\n"
+ << " else {\n"
+ << " gSystem->AddIncludePath(Form(\"-I../%s\",val.Data()));\n"
+ << " }\n"
+ << "}\n\n"
+ << "void LoadDep(const char* name) {\n"
+ << " gSystem->AddDynamicPath(Form(\"../%s\",name));\n"
+ << " char* full = gSystem->DynamicPathName(name,true);\n"
+ << " if (!full) \n"
+ << " full = gSystem->DynamicPathName(Form(\"lib%s\",name),true);\n"
+ << " if (!full) \n"
+ << " full = gSystem->DynamicPathName(Form(\"lib%s.so\",name),true);\n"
+ << " if (!full) {\n"
+ << " Warning(\"LoadDep\",\"Module %s not found\", name);\n"
+ << " return;\n"
+ << " }\n"
+ << " gSystem->Load(full);\n"
+ << "}\n"
+ << std::endl;
+
+ std::ofstream cbuild(Form("%s/PROOF-INF/BUILD.C", base.Data()));
+ if (!cbuild)
+ throw TString::Format("Failed to open build script");
+ cbuild << "void BUILD() {\n"
+ << " gSystem->AddIncludePath(\"-DBUILD_PAR=1\");\n"
+ << " gROOT->LoadMacro(\"PROOF-INF/UTIL.C\");\n"
+ << " LoadROOTLibs();\n";
+ TObjArray* depList = TString(deps).Tokenize(",");
+ TIter next(depList);
+ TObject* dep = 0;
+ while ((dep = next())) {
+ cbuild << " AddDep(\"" << dep->GetName() << "\");\t"
+ << " LoadDep(\"" << dep->GetName() << "\");\n";
+ }
+ cbuild << " // gDebug = 5;\n"
+ << " int ret = gROOT->LoadMacro(\""
+ << base << "." << ext << "++g\");\n"
+ << " if (ret != 0) Fatal(\"BUILD\",\"Failed to build\");\n"
+ << " else Info(\"BUILD\", \"Made " << base << "\");\n"
+ << "}\n"
+ << std::endl;
+ cbuild.close();
+
+ // Make our set-up script
+ std::ofstream setup(Form("%s/PROOF-INF/SETUP.C", base.Data()));
+ if (!build)
+ throw TString::Format("Failed to open setup script");
+ setup << "void SETUP() {\n"
+ << " gROOT->LoadMacro(\"PROOF-INF/UTIL.C\");\n"
+ << " LoadROOTLibs();\n"
+ << " Info(\"SETUP\",\"Loading libraries\");\n";
+ next.Reset();
+ dep = 0;
+ while ((dep = next()))
+ setup << " LoadDep(\"" << dep->GetName() << "\");\n";
+ setup << " gDebug = 5;\n"
+ << " gSystem->Load(\"" << base << "_" << ext << ".so\");\n"
+ << " gDebug = 0;\n"
+ << " gROOT->ProcessLine(\".include " << base << "\");\n"
+ << " gSystem->Setenv(\"" << base << "_INCLUDE\",\""
+ << base << "\");\n"
+ << " Info(\"SETUP\", \"Done\");\n"
+ << "}\n"
+ << std::endl;
+ setup.close();
+
+ ret = gSystem->Exec(Form("tar -czvf %s.par %s", base.Data(),base.Data()));
+ if (ret != 0)
+ throw TString::Format("Failed to create PAR file %s.PAR", base.Data());
+ }
+ catch (TString& e) {
+ Error("MakeScriptPAR", e.Data());
+ retval = false;
+ }
+ if (!base.IsNull())
+ gSystem->Exec(Form("rm -vrf %s", base.Data()));
+ return retval;
+ }
+ //__________________________________________________________________
/**
* Print the setup
*
if (mode == kProof) usePar = true;
+ Info("Exec", "Connecting in mode=%d", mode);
if (!Connect(mode)) return;
TString cwd = gSystem->WorkingDirectory();
TString nam = EscapedName();
+ Info("Exec", "Current directory=%s, escaped name=%s",
+ cwd.Data(), nam.Data());
if (oper != kTerminate) {
if (!fAllowOverwrite && !gSystem->AccessPathName(nam.Data())) {
Error("Exec", "File/directory %s already exists", nam.Data());
}
if (gSystem->AccessPathName(nam.Data())) {
if (gSystem->MakeDirectory(nam.Data())) {
- Error("Exec", "Failed to make directory %s", nam.Data());
+ Error("Exec", "Failed to make directory '%s'", nam.Data());
return;
}
}
AliCentralitySelectionTask* ctask =
dynamic_cast<AliCentralitySelectionTask*>(mgr->GetTask("CentralitySelection"));
if (!ctask) return;
- ctask->SetPass(fESDPass);
+ // ctask->SetPass(fESDPass);
if (mc) ctask->SetMCInput();
}
//__________________________________________________________________
// --- Set-up connections to Proof cluster and alien -------------
if (mode == kProof) {
+ Info("Connect", "Opening connection to proof server");
// --- Find user name ------------------------------------------
TString userName(gSystem->Getenv("alien_API_USER"));
if (userName.IsNull()) {
}
// --- Add ALICE_ROOT directory to search path for packages ----
+ Info("Connect", "Set location of packages");
gEnv->SetValue("Proof.GlobalPackageDirs",
Form("%s:%s",
gEnv->GetValue("Proof.GlobalPackageDirs", "."),
fProofServer.Data(), userName.Data());
return false;
}
+ Info("Connect", "Now connected to Proof");
+ // gProof->SetParameter("PROOF_LookupOpt", "all");
if (lite) return true;
}
// --- Open a connection to the grid -----------------------------
+#if 0
TGrid::Connect("alien://");
if (!gGrid || !gGrid->IsConnected()) {
// This is only fatal in grid mode
// Make output directory
gGrid->Mkdir("proof_output");
gGrid->Cd("proof_output");
-
+#endif
return true;
}
//__________________________________________________________________
}
+#if 0
+ // We need to activate the workers here in case
+ // we have dynamic slaves - otherwise they won't get
+ // the packages
+ if (mode == kProof) {
+ Info("LoadCommonLibraries", "Starting slaves");
+ if (!gProof->StartSlaves()) {
+ Error("LoadCommonLibraries", "Failed to start slaves");
+ return false;
+ }
+ Info("LoadCommonLibraries", "Slaves started");
+ }
+#endif
+
Bool_t ret = true;
Bool_t basic = mode == kGrid ? false : par;
}
break;
case kProof:
- ret = gProof->UploadPackage(what);
+ Info("LoadLibrary", "Uploading %s", what);
+ ret = gProof->UploadPackage(what, TProof::kRemoveOld);
if (ret < 0) {
ret = gProof->UploadPackage(gSystem->ExpandPathName(Form("../%s.par",
what)));
}
}
}
+ Info("LoadLibrary", "Enabling package %s", what);
ret = gProof->EnablePackage(what);
break;
}