]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/FORWARD/analysis2/corrs/ExtractELoss.C
93418f02464e9780ca682a8fb99255f65dbac97e
[u/mrichter/AliRoot.git] / PWGLF / FORWARD / analysis2 / corrs / ExtractELoss.C
1 /**
2  * Script to draw the energy loss fits 
3  * 
4  * @ingroup pwglf_forward_scripts_corr
5  */
6 #ifndef __CINT__
7 #include <TFile.h>
8 #include <TList.h>
9 #include <TError.h>
10 #include "AliFMDCorrELossFit.h"
11 #include "AliForwardCorrectionManager.h"
12 #endif 
13
14 //____________________________________________________________________
15 /** 
16  * Extract the energy loss correction object from file and rename it 
17  * according to the settings 
18  * 
19  * @param fname  File to extract from 
20  * @param sys    Collision system (pp, PbPb)
21  * @param sNN    Center of mass energy (in GeV) per nucleon
22  * @param field  L3 magnetic field (-5,0,5) in kGaus
23  * @param mc     Whether this is from MC data or not 
24  * 
25  * @ingroup pwglf_forward_scripts_corr
26  */
27 void
28 ExtractELoss(const char* fname="forward_eloss.root", Bool_t mc=false,
29              UShort_t sys=1, UShort_t sNN=900, Short_t field=5)
30 {
31 #ifdef __CINT__
32   gROOT->Macro("$ALICE_ROOT/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C");
33 #endif
34
35   TFile* file = TFile::Open(fname, "READ");
36   if (!file) {
37     Error("ExtractELoss", "Couldn't open %s", fname);
38     return;
39   }
40    
41   if (sys <= 0 || sys > 3 || sNN <= 0) { 
42     TList* base = static_cast<TList*>(file->Get("Forward"));
43     if (!base) { 
44       Error("ExtractELoss", "Couldn't get forward list from %s", fname);
45       return;
46     }
47     TList* insp = static_cast<TList*>(base->FindObject("fmdEventInspector"));
48     if (!insp) { 
49       Error("ExtractELoss", "Couldn't get event inspector list from %s",fname);
50       return;
51     }
52     TObject* oSys = insp->FindObject("sys");
53     TObject* oSNN = insp->FindObject("sNN");
54     TObject* oFld = insp->FindObject("field");
55     if (oSys) sys   = oSys->GetUniqueID();
56     if (oSNN) sNN   = oSNN->GetUniqueID();
57     if (oFld) field = oFld->GetUniqueID();
58   }
59   if (sys <= 0 || sys > 3) {
60     Error("ExtractELoss", "Couldn't get system type (%d), "
61           "collision energy (%d), "
62           "and/or field strength (%d)", sys, sNN, field);
63     return;
64   }
65  
66   TList* forward = static_cast<TList*>(file->Get("ForwardResults"));
67   // static_cast<TList*>(file->Get("PWGLFforwardDnDeta/Forward"));
68   if (!forward) { 
69     Error("ExtractELoss", "Couldn't get forward list from %s", fname);
70     return;
71   }
72   
73   TList* fitter = static_cast<TList*>(forward->FindObject("fmdEnergyFitter"));
74   if (!fitter) { 
75     Error("ExtractELoss", "Couldn't get fitter folder");
76     return;
77   }
78
79   TString cName(AliFMDCorrELossFit::Class()->GetName());
80
81   AliFMDCorrELossFit* obj = 
82     static_cast<AliFMDCorrELossFit*>(fitter->FindObject(cName));
83   if (!obj) {
84     Error("ExtractELoss", "Couldn't get %s correction object", cName.Data());
85     return;
86   }
87
88   AliForwardCorrectionManager& mgr = AliForwardCorrectionManager::Instance();
89   mgr.WriteFile(AliForwardCorrectionManager::kELossFits, 
90                 sys, sNN, field, mc, obj, false);
91
92   std::ofstream f("Upload.C");
93   if (!f) { 
94     Error("ExtractELoss", "Failed to open Upload.C");
95     return;
96   }
97   f << "// Generated by ExtractELoss.C\n"
98     << "void Upload(const TUrl& url)\n"
99     << "{\n"
100     << "  if (TString(\"alien\").EqualTo(url.GetProtocol())) {\n"
101     << "    if (!TGrid::Connect(\"alien://\")) {\n"
102     << "      Error(\"Upload\", \"Failed to connect to AliEn\");\n"
103     << "      return;\n"
104     << "    }\n"
105     << "  }\n\n";
106
107   mgr.SetPrefix("");
108   TString fef(mgr.GetFileName(AliForwardCorrectionManager::kELossFits, 
109                               sys, sNN, field, mc));
110   TString fep(mgr.GetFilePath(AliForwardCorrectionManager::kELossFits, 
111                               sys, sNN, field, mc));
112   f << "  TString src  = \"" << fef << "\";\n"
113     << "  TString dest = \"" << fep << "\";\n"
114     << "  TString out; out.Form(\"%s%s\",url.GetUrl(),dest.Data());\n\n"
115     << "  TString dir(gSystem->DirName(out));\n"
116     << "  if (gSystem->AccessPathName(dir)) {\n"
117     << "    if (gSystem->mkdir(dir, true) < 0) {\n"
118     << "      Warning(\"Upload\",\"Failed to make directory %s\","
119     << "              dir.Data());\n"
120     << "      return;\n"
121     << "    }\n"
122     << "  }\n"
123     << "  if (!TFile::Cp(src,out)) \n"
124     << "    Warning(\"Upload\",\"Failed to upload %s -> %s\",\n"
125     << "            src.Data(), out.Data());\n"
126     << "}\n"
127     << "// EOF"
128     << std::endl;
129   f.close();
130   
131   Info("ExtracELoss", 
132        "Run generated Upload.C(DEST) script to copy files in place");
133
134 }
135
136     
137   
138 //____________________________________________________________________
139 /** 
140  * Extract the energy loss correction object from file and rename it 
141  * according to the settings 
142  * 
143  * @param fname  File to extract from 
144  * @param sys    Collision system (pp, PbPb)
145  * @param sNN    Center of mass energy (in GeV) per nucleon
146  * @param field  L3 magnetic field (-5,0,5) in kGaus
147  * @param mc     Whether this is from MC data or not 
148  * 
149  * @ingroup pwglf_forward_scripts_corr
150  */
151 void
152 ExtractELoss(const char* fname="energyFits.root", 
153              const char* sys="p-p", 
154              Float_t     sNN=900, 
155              Float_t     field=5,
156              Bool_t      mc=false)
157 {
158   UShort_t uSys   = AliForwardUtil::ParseCollisionSystem(sys);
159   UShort_t usNN   = AliForwardUtil::ParseCenterOfMassEnergy(uSys,sNN);
160   Short_t  sField = AliForwardUtil::ParseMagneticField(field);
161
162   ExtractELoss(fname, mc, uSys, usNN, sField);
163 }
164
165 //____________________________________________________________________
166 //
167 // EOF
168 //