AliPhysics  914d8ff (914d8ff)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeAcceptanceCorrection.C
Go to the documentation of this file.
1 //_____________________________________________________________________
15 {
16  AliFMDGeometry* geom = AliFMDGeometry::Instance();
17  AliFMDParameters* pars = AliFMDParameters::Instance();
18 
19  UShort_t nS = (r == 'I' || r == 'i' ? 20 : 40);
20  UShort_t nT = (r == 'I' || r == 'i' ? 512 : 256);
21 
22  // Make our two histograms
23  TH2D* hAll = new TH2D("all","All",200,-4,6,nS,0,2*TMath::Pi());
24  hAll->SetXTitle("#eta");
25  hAll->SetYTitle("#phi");
26  hAll->Sumw2();
27  hAll->SetDirectory(0);
28  TH2D* hOK = static_cast<TH2D*>(hAll->Clone());
29  hOK->SetDirectory(0);
30 
31  // Loop over all sectors and strips in this ring
32  Int_t nOK = 0;
33  Int_t nAll = 0;
34  Int_t nPhi = hAll->GetNbinsY();
35  for (UShort_t s = 0; s < nS; s++) {
36  for (UShort_t t = 0; t < nT; t++) {
37  // Get eta,phi by quering the geometry (first for (x,y,z), then
38  // correcting for the vertex position, and then calculating
39  // (eta, phi))
40  Double_t x, y, z;
41  geom->Detector2XYZ(d, r, s, t, x, y, z);
42  z -= vz;
43  Double_t q, eta, phi, theta;
44  AliFMDGeometry::XYZ2REtaPhiTheta(x, y, z, q, eta, phi, theta);
45  if (phi < 0) phi += 2*TMath::Pi();
46 
47  // Check if this is a dead channel or not
48  Bool_t isDead = pars->IsDead(d, r, s, t);
49 
50  // Special check for FMD2i
51  Int_t VA = t/128;
52  if(d==2 && r=='I' && VA>1 && (s==16 || s==17)) isDead =true;
53 
54  // Find the eta bin number and corresponding overflow bin
55  Int_t etaBin = hAll->GetXaxis()->FindBin(eta);
56  Int_t ovrBin = hAll->GetBin(etaBin, nPhi+1);
57 
58  // Increment all histogram
59  hAll->Fill(eta, phi);
60  hAll->AddBinContent(ovrBin);
61  nAll++;
62 
63  // If not dead, increment OK histogram
64  if (!isDead) {
65  hOK->Fill(eta, phi);
66  hOK->AddBinContent(ovrBin);
67  nOK++;
68  }
69  else nDead++;
70  }
71  }
72  // Divide out the efficiency.
73  // Note, that the overflow bins along eta now contains the ratio
74  // nOK/nAll Strips for a given eta bin.
75  hOK->Divide(hOK,hAll,1,1,"B");
76 
77  // Clean up
78  delete hAll;
79 
80  Info("ExtractAcceptances","Made correction for FMD%d%c at vz=%f - "
81  "%d strips out of %d OK", d, r, vz, nOK, nAll);
82 
83  // Return result
84  return hOK;
85 }
86 
87 //_____________________________________________________________________
101 void ExtractAcceptance(Int_t runNo=121526,
102  Int_t system = 1,
103  Float_t energy = 900,
104  Float_t field = 5,
105  Int_t nVtxBins=10,
106  Float_t vtxLow=-10,
107  Float_t vtxHigh=10)
108 {
109  gSystem->Load("libANALYSIS");
110  gSystem->Load("libANALYSISalice");
111  gSystem->Load("libPWGLFforward2");
112 
113  // Float_t delta = (vtxHigh - vtxLow) / (Float_t)nVtxBins;
114 
115  Bool_t kGridOnline = kTRUE;
116  if(!(TGrid::Connect("alien://",0,0,"t")))
117  kGridOnline = kFALSE;
118 
119  // --- Initialisations ------------------------------------------
120  //Set up CDB manager
121  Info("ExtractAcceptances","Setting up OCDB");
122 
123  AliCDBManager* cdb = AliCDBManager::Instance();
124  if(kGridOnline)
125  cdb->SetDefaultStorage("alien://Folder=/alice/data/2012/OCDB");
126  else
127  cdb->SetDefaultStorage("local://$(ALICE_PHYSICS)/OCDB");
128  cdb->SetRun(runNo);
129 
130  // Get the geometry
131  Info("ExtractAcceptances","Loading geometry");
132  AliGeomManager::LoadGeometry();
133 
134  // Get an initialize parameters
135  Info("ExtractAcceptances","Intialising parameters");
136  AliFMDParameters* pars = AliFMDParameters::Instance();
137  pars->Init();
138 
139  // Get an initialise geometry
140  Info("ExtractAcceptances","Initialising geomtry");
141  AliFMDGeometry* geom = AliFMDGeometry::Instance();
142  geom->Init();
143  geom->InitTransformations();
144 
145  // --- Output object -----------------------------------------------
146  // Make our correction object
148  corr->SetVertexAxis(nVtxBins, vtxLow, vtxHigh);
149 
150  // --- Loop over verticies and rings -------------------------------
151  Int_t nDead = 0;
152  Float_t dV = (vtxHigh - vtxLow) / nVtxBins;
153  for (Double_t v = vtxLow+dV/2; v < vtxHigh; v += dV) {
154  for(UShort_t d = 1; d <= 3;d++) {
155  UShort_t nR = (d == 1 ? 1 : 2);
156  for (UShort_t q = 0; q < nR; q++) {
157  Char_t r = (q == 0 ? 'I' : 'O');
158 
159  // Delegate to other function
160  TH2D* ratio = MakeOneRing(d, r, v, nDead);
161  if (!ratio) continue;
162 
163  // Set the correction
164  corr->SetCorrection(d, r, v, ratio);
165  }
166  }
167  }
168 
169  // Write to a file
170  Info("ExtractAcceptances","Writing to disk");
172  TString fname = cm.GetFileName(AliForwardCorrectionManager::kAcceptance,
173  system, energy, field, false);
174  TFile* out = TFile::Open(fname.Data(), "RECREATE");
175  corr->SetHasOverflow();
177  out->Write();
178  out->Close();
179 
180  std::ofstream f("Upload.C");
181  if (!f) {
182  Error("ExtractELoss", "Failed to open Upload.C");
183  return;
184  }
185  f << "// Generated by ExtractAcceptance.C\n"
186  << "void Upload(const TUrl& url)\n"
187  << "{\n"
188  << " if (TString(\"alien\").EqualTo(url.GetProtocol())) {\n"
189  << " if (!TGrid::Connect(\"alien://\")) {\n"
190  << " Error(\"Upload\", \"Failed to connect to AliEn\");\n"
191  << " return;\n"
192  << " }\n"
193  << " }\n\n";
194 
195  mgr.SetPrefix("");
197  sys, sNN, field, false));
199  sys, sNN, field, false));
200  f << " TString src = \"" << fef << "\";\n"
201  << " TString dest = \"" << fep << "\";\n"
202  << " TString out; out.Form(\"%s%s\",url.GetUrl(),dest.Data());\n\n"
203  << " TString dir(gSystem->DirName(out));\n"
204  << " if (gSystem->AccessPathName(dir)) {\n"
205  << " if (gSystem->mkdir(dir, true) < 0) {\n"
206  << " Warning(\"Upload\",\"Failed to make directory %s\","
207  << " dir.Data());\n"
208  << " return;\n"
209  << " }\n"
210  << " }\n"
211  << " if (!TFile::Cp(src,out)) \n"
212  << " Warning(\"Upload\",\"Failed to upload %s -> %s\",\n"
213  << " src.Data(), out.Data());\n"
214  << "}\n"
215  << "// EOF"
216  << std::endl;
217  f.close();
218 
219  Info("ExtracAcceptance",
220  "Run generated Upload.C(DEST) script to copy files in place");
221 }
222 
223 //
224 // EOF
225 //
226 
double Double_t
Definition: External.C:58
void ExtractAcceptance(Int_t runNo=121526, Int_t system=1, Float_t energy=900, Float_t field=5, Int_t nVtxBins=10, Float_t vtxLow=-10, Float_t vtxHigh=10)
energy
Definition: HFPtSpectrum.C:44
TSystem * gSystem
char Char_t
Definition: External.C:18
TH2D * MakeOneRing(UShort_t d, Char_t r, Double_t vz, Int_t &nDead)
void SetVertexAxis(const TAxis &axis)
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
Definition: External.C:228
const char * GetObjectName(Int_t what) const
void SetHasOverflow(Bool_t present=true)
unsigned short UShort_t
Definition: External.C:28
bool Bool_t
Definition: External.C:53
Bool_t SetCorrection(UShort_t d, Char_t r, Double_t v, TH2D *h)
static AliForwardCorrectionManager & Instance()