]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWGLF/FORWARD/analysis2/corrs/ExtractMCCorr.C
Mega commit of many changes to PWGLFforward
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / corrs / ExtractMCCorr.C
index 0776b0ab31d960fd9c5767bd20e529e8f1b3c60d..ad271ca68d5f845588c538033aeca080e0de72ba 100644 (file)
@@ -3,15 +3,7 @@
  * 
  * @ingroup pwglf_forward_scripts_corr
  */
-#ifndef __CINT__
-#include <TFile.h>
-#include <TList.h>
-#include <TError.h>
-#include "AliFMDCorrSecondaryMap.h"
-#include "AliCentralCorrSecondaryMap.h"
-#include "AliForwardCorrectionManager.h"
-#endif 
-
+  
 //____________________________________________________________________
 /** 
  * Extract the energy loss correction object from file and rename it 
  * @ingroup pwglf_forward_scripts_corr
  */
 void
-ExtractMCCorr(const char* fname = "forward_mccorr.root",
-             UShort_t    sys   = 0, 
-             UShort_t    sNN   = 900, 
-             Short_t     field = 5)
+ExtractMCCorr(const char* fname)
 {
-#ifdef __CINT__
-  gROOT->Macro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C");
-#endif
-
-  TFile* file = TFile::Open(fname, "READ");
-  if (!file) {
-    Error("ExtractMCCorr", "Couldn't open %s", fname);
-    return;
-  }
-  if (sys <= 0 || sys > 3 || sNN <= 0) { 
-    TList* forward = static_cast<TList*>(file->Get("ForwardSums"));
-    if (!forward) { 
-      Error("ExtractMCCorr", "Couldn't get forward list from %s", fname);
-      return;
-    }
-    TList* insp = static_cast<TList*>(forward->FindObject("fmdEventInspector"));
-    if (!insp) { 
-      Error("ExtractMCCorr", "Couldn't get event inspector list from %s",fname);
-      return;
-    }
-    TObject* oSys = insp->FindObject("sys");
-    TObject* oSNN = insp->FindObject("sNN");
-    TObject* oFld = insp->FindObject("field");
-    if (oSys) sys   = oSys->GetUniqueID();
-    if (oSNN) sNN   = oSNN->GetUniqueID();
-    if (oFld) field = oFld->GetUniqueID();
-  }
-  if (sys < 0 || sys > 3) {
-    Error("ExtractMCCorr", "Couldn't get system type (%d), "
-         "collision energy (%d), "
-         "and/or field strength (%d)", sys, sNN, field);
-    return;
+  const char* fwd = "$ALICE_ROOT/../trunk/PWGLF/FORWARD/analysis2";
+  gSystem->AddIncludePath(Form("-I%s", fwd));
+  gROOT->Macro(Form("%s/scripts/LoadLibs.C", fwd));
+  gROOT->LoadMacro(Form("%s/corrs/CorrExtractor.C++g", fwd));
+  
+  CorrExtractor fmdEx(&AliForwardCorrectionManager::Instance());
+  if (fmdEx.Init(fname, "ForwardCorrSums", "fmd_corrections.root")) {
+    fmdEx.Extract(AliFMDCorrSecondaryMap::Class(),
+                 "ForwardCorrResults");
   }
 
-  ExtractFMDSecMap(file, sys, sNN, field);
-  ExtractSPDSecMap(file, sys, sNN, field);
-  ExtractSPDAcceptance(file, sys, sNN, field);
-  WriteUploadScript(sys, sNN, field);
-  Info("ExtracMCCorr", 
-       "Run generated Upload.C(DEST) script to copy files in place");
-}
+  CorrExtractor spdEx(&AliCentralCorrectionManager::Instance());
+  if (spdEx.Init(fname, "CentralCorrSums", "spd_corrections.root")) {
+    spdEx.Extract(AliCentralCorrSecondaryMap::Class(), "CentralCorrResults");
+    spdEx.Extract(AliCentralCorrAcceptance::Class(), "CentralCorrResults");
+  }
 
-//____________________________________________________________________
-void WriteUploadScript(UShort_t sys, UShort_t sNN, Short_t field)
-{
   std::ofstream f("Upload.C");
-  if (!f) { 
-    Error("WriteUploadScript", "Failed to open Upload.C");
-    return;
-  }
   f << "// Generated by ExtractMCCorr.C\n"
-    << "void Upload(const TUrl& url)\n"
+    << "TString MakeDest(const TString& dest, const TString& fname)\n"
     << "{\n"
-    << "  gEnv->SetValue(\"XSec.GSI.DelegProxy\", \"2\");\n"
-    << "  if (TString(\"alien\").EqualTo(url.GetProtocol())) {\n"
-    << "    if (!TGrid::Connect(\"alien://\")) {\n"
-    << "      Error(\"Upload\", \"Failed to connect to AliEn\");\n"
-    << "      return;\n"
-    << "    }\n"
-    << "  }\n\n";
-  
-  AliForwardCorrectionManager& fcm = 
-    AliForwardCorrectionManager::Instance();
-  fcm.SetPrefix("");
-  TString fsf(fcm.GetFileName(AliForwardCorrectionManager::kSecondaryMap, 
-                             sys, sNN, field, false));
-  TString fsp(fcm.GetFilePath(AliForwardCorrectionManager::kSecondaryMap, 
-                             sys, sNN, field, false));
-  AliCentralMultiplicityTask::Manager* mgr = new 
-    AliCentralMultiplicityTask::Manager;
-  mgr->SetSecMapPath("/CentralSecMap");
-  mgr->SetAcceptancePath("/CentralAcceptance");
-  TString csf(mgr->GetFileName(0, sys, sNN, field));
-  TString csp(mgr->GetFullFileName(0, sys, sNN, field));
-  TString caf(mgr->GetFileName(1, sys, sNN, field));
-  TString cap(mgr->GetFullFileName(1, sys, sNN, field));
-
-  f << "  const char* src[] = {\n"
-    << "    \"" << fsf << "\",\n"
-    << "    \"" << csf << "\",\n"
-    << "    \"" << caf << "\",\n"
-    << "    0 };\n"
-    << "  const char* dest[] = {\n"
-    << "    \"" << fsp << "\",\n"
-    << "    \"" << csp << "\",\n"
-    << "    \"" << cap << "\",\n"
-    << "    0 };\n\n"
-    << "  const char** psrc  = src;\n"
-    << "  const char** pdest = dest;\n"
-    << "  while (*psrc && *pdest) {\n"
-    << "    TString out; out.Form(\"%s%s\",url.GetUrl(),*pdest);\n"
-    << "    TString dir(gSystem->DirName(out));\n"
-    << "    if (gSystem->AccessPathName(dir)) {\n"
-    << "      if (gSystem->mkdir(dir, true) < 0) {\n"
-    << "        Warning(\"Upload\",\"Failed to make directory %s\","
-    << "                dir.Data());\n"
-    << "        continue;\n"
-    << "      }\n"
-    << "    }\n"
-    << "    if (!TFile::Cp(*psrc, out.Data())) \n"
-    << "      Warning(\"Upload\",\"Failed to upload %s -> %s\",\n"
-    << "              *psrc, out.Data());\n"
-    << "    psrc++;\n"
-    << "    pdest++;\n"
-    << "  };\n"
+    << "  TString tmp(dest);\n"
+    << "  if (!tmp.IsNull()) {\n"
+    << "    if (!tmp.EndsWith(\"/\")) tmp.Append(\"/\");\n"
+    << "    tmp.Append(fname);\n"
+    << "  }\n"
+    << "  return tmp;\n"
+    << "}\n\n"
+    << "void Upload(const TString& dest=\"\")\n"
+    << "{\n"
+    << "  gROOT->Macro(\"" << fwd << "/scripts/LoadLibs.C\");\n"
+    << "  \n"
+    << "  const char* fmdFile = \"fmd_corrections.root\";\n"
+    << "  const char* spdFile = \"spd_corrections.root\";\n"
+    << "  TString fdest = MakeDest(dest, fmdFile);\n"
+    << "  TString sdest = MakeDest(dest, spdFile);\n"
+    << "  \n"
+    << "  AliForwardCorrectionManager::Instance().Append(fmdFile, fdest);\n"
+    << "  AliCentralCorrectionManager::Instance().Append(spdFile, sdest);\n"
     << "}\n"
-    << "// EOF"
+    << "// EOF\n"
     << std::endl;
   f.close();
 }
 
-//____________________________________________________________________
-/** 
- * Extract and copy FMD secondary map to file 
- * 
- * @param file  Input file
- * @param sys   Collision system (1:pp, 2:PbPb)
- * @param sNN   Center of mass energy (GeV) per nucleon
- * @param field L3 magnetic field
- *
- * @ingroup pwglf_forward_scripts_corr
- */
-void     
-ExtractFMDSecMap(TFile* file, UShort_t sys, UShort_t sNN, Short_t field)
-{
-  TList* forward = static_cast<TList*>(file->Get("ForwardResults"));
-  if (!forward) { 
-    Error("ExtractMCCorr", "Couldn't get forward list from %s", fname);
-    return;
-  }
-  
-  TString n(AliFMDCorrSecondaryMap::Class()->GetName());
-  TObject* fmdCorr = forward->FindObject(n);
-  if (!fmdCorr) { 
-    Error("ExtractMCCorr", "Couldn't get forward correction object %s", 
-         n.Data());
-    return;
-  }
-
-  AliForwardCorrectionManager& mgr = AliForwardCorrectionManager::Instance();
-  mgr.WriteFile(AliForwardCorrectionManager::kSecondaryMap, 
-               sys, sNN, field, false, fmdCorr, false);
-}
-
-//____________________________________________________________________
-/** 
- * Extract and copy SPD secondary map to file 
- * 
- * @param file  Input file
- * @param sys   Collision system (1:pp, 2:PbPb)
- * @param sNN   Center of mass energy (GeV) per nucleon
- * @param field L3 magnetic field
- *
- * @ingroup pwglf_forward_scripts_corr
- */
-void     
-ExtractSPDSecMap(TFile* file, UShort_t sys, UShort_t sNN, Short_t field)
-{
-  TList* central = static_cast<TList*>(file->Get("CentralResults"));
-  // static_cast<TList*>(file->Get("PWGLFcentralDnDeta/Central"));
-  if (!central) { 
-    Error("ExtractMCCorr", "Couldn't get central list from %s", fname);
-    return;
-  }
-  
-  TString n(AliCentralCorrSecondaryMap::Class()->GetName());
-  TObject* spdCorr  = central->FindObject(n);
-  if (!spdCorr) { 
-    Error("ExtractMCCorr", "Couldn't get central correction object %s", 
-         n.Data());
-    return;
-  }
-
-
-  AliCentralMultiplicityTask::Manager* mgr = new 
-    AliCentralMultiplicityTask::Manager;
-  // mgr->Dump();
-  // mgr->Print();
-  mgr->WriteFile(0, sys, sNN, field, spdCorr, false);
-}
-//____________________________________________________________________
-/** 
- * Extract and copy SPD secondary map to file 
- * 
- * @param file  Input file
- * @param sys   Collision system (1:pp, 2:PbPb)
- * @param sNN   Center of mass energy (GeV) per nucleon
- * @param field L3 magnetic field
- *
- * @ingroup pwglf_forward_scripts_corr
- */
-void     
-ExtractSPDAcceptance(TFile* file, UShort_t sys, UShort_t sNN, Short_t field)
-{
-  TList* central = static_cast<TList*>(file->Get("CentralResults"));
-  if (!central) { 
-    Error("ExtractMCCorr", "Couldn't get central list from %s", fname);
-    return;
-  }
-  
-  TString n(AliCentralCorrAcceptance::Class()->GetName());
-  TObject* spdCorr  = central->FindObject(n);
-  if (!spdCorr) { 
-    Error("ExtractMCCorr", "Couldn't get central correction object %s", 
-         n.Data());
-    return;
-  }
-
-
-  AliCentralMultiplicityTask::Manager* mgr = new 
-    AliCentralMultiplicityTask::Manager;
-  // mgr->Dump();
-  // mgr->Print();
-  mgr->WriteFile(1, sys, sNN, field, spdCorr, false);
-}
-    
-  
-//____________________________________________________________________
-/** 
- * Extract the energy loss correction object from file and rename it 
- * according to the settings 
- * 
- * @param fname  File to extract from 
- * @param sys    Collision system (pp, PbPb)
- * @param sNN    Center of mass energy (in GeV) per nucleon
- * @param field  L3 magnetic field (-5,0,5) in kGaus
- * 
- * @ingroup pwglf_forward_scripts_corr
- */
-void
-ExtractMCCorr(const char* fname, // "forward_mccorr.root"
-             const char* sys="p-p", 
-             Float_t     sNN=900, 
-             Float_t     field=5)
-{
-  gROOT->Macro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C");
-
-  UShort_t uSys   = AliForwardUtil::ParseCollisionSystem(sys);
-  UShort_t usNN   = AliForwardUtil::ParseCenterOfMassEnergy(uSys,sNN);
-  Short_t  sField = AliForwardUtil::ParseMagneticField(field);
-
-  ExtractMCCorr(fname, uSys, usNN, sField);
-}
-
 //____________________________________________________________________
 //
 // EOF