2 // This class calculates the exclusive charged particle density
3 // in each for the 5 FMD rings.
5 #include "AliFMDCorrector.h"
10 #include "AliForwardCorrectionManager.h"
11 // #include "AliFMDCorrDoubleHit.h"
12 #include "AliFMDCorrVertexBias.h"
13 #include "AliFMDCorrMergingEfficiency.h"
14 #include "AliFMDCorrAcceptance.h"
22 ClassImp(AliFMDCorrector)
27 //____________________________________________________________________
28 AliFMDCorrector::AliFMDCorrector()
31 fUseSecondaryMap(true),
32 fUseVertexBias(false),
34 fUseMergingEfficiency(false),
40 //____________________________________________________________________
41 AliFMDCorrector::AliFMDCorrector(const char* title)
42 : TNamed("fmdCorrector", title),
44 fUseSecondaryMap(true),
45 fUseVertexBias(false),
47 fUseMergingEfficiency(false),
54 fRingHistos.SetName(GetName());
55 fRingHistos.Add(new RingHistos(1, 'I'));
56 fRingHistos.Add(new RingHistos(2, 'I'));
57 fRingHistos.Add(new RingHistos(2, 'O'));
58 fRingHistos.Add(new RingHistos(3, 'I'));
59 fRingHistos.Add(new RingHistos(3, 'O'));
62 //____________________________________________________________________
63 AliFMDCorrector::AliFMDCorrector(const AliFMDCorrector& o)
66 fUseSecondaryMap(o.fUseSecondaryMap),
67 fUseVertexBias(o.fUseVertexBias),
68 fUseAcceptance(o.fUseAcceptance),
69 fUseMergingEfficiency(o.fUseMergingEfficiency),
75 // o Object to copy from
76 TIter next(&o.fRingHistos);
78 while ((obj = next())) fRingHistos.Add(obj);
81 //____________________________________________________________________
82 AliFMDCorrector::~AliFMDCorrector()
90 //____________________________________________________________________
92 AliFMDCorrector::operator=(const AliFMDCorrector& o)
94 // Assignment operator
97 // o Object to assign from
98 if (&o == this) return *this;
102 fRingHistos.Delete();
103 fUseSecondaryMap = o.fUseSecondaryMap;
104 fUseVertexBias = o.fUseVertexBias;
105 fUseAcceptance = o.fUseAcceptance;
106 fUseMergingEfficiency = o.fUseMergingEfficiency;
107 TIter next(&o.fRingHistos);
109 while ((obj = next())) fRingHistos.Add(obj);
114 //____________________________________________________________________
116 AliFMDCorrector::Init(const TAxis&)
119 // Initialize this object
122 // etaAxis Eta axis to use
124 if (!fUseSecondaryMap)
125 AliWarning("Secondary maps not used - BE CAREFUL");
127 AliWarning("Vertex bias not used");
129 AliWarning("Acceptance from dead-channels not used");
132 //____________________________________________________________________
133 AliFMDCorrector::RingHistos*
134 AliFMDCorrector::GetRingHistos(UShort_t d, Char_t r) const
137 // Get the ring histogram container
143 // Ring histogram container
147 case 1: idx = 0; break;
148 case 2: idx = 1 + (r == 'I' || r == 'i' ? 0 : 1); break;
149 case 3: idx = 3 + (r == 'I' || r == 'i' ? 0 : 1); break;
151 if (idx < 0 || idx >= fRingHistos.GetEntries()) return 0;
153 return static_cast<RingHistos*>(fRingHistos.At(idx));
156 //____________________________________________________________________
158 AliFMDCorrector::Correct(AliForwardUtil::Histos& hists,
162 // Do the calculations
164 // hists Cache of histograms
170 AliForwardCorrectionManager& fcm = AliForwardCorrectionManager::Instance();
172 UShort_t uvb = vtxbin;
173 for (UShort_t d=1; d<=3; d++) {
174 UShort_t nr = (d == 1 ? 1 : 2);
175 for (UShort_t q=0; q<nr; q++) {
176 Char_t r = (q == 0 ? 'I' : 'O');
177 TH2D* h = hists.Get(d,r);
178 RingHistos* rh = GetRingHistos(d,r);
180 if (fUseSecondaryMap) {
181 TH2D* bg = fcm.GetSecondaryMap()->GetCorrection(d, r, uvb);
183 AliWarning(Form("No secondary correction for FMDM%d%c "
184 "in vertex bin %d", d, r, uvb));
187 // Divide by primary/total ratio
190 if (fUseVertexBias) {
191 TH2D* ef = fcm.GetVertexBias()->GetCorrection(r, uvb);
193 AliWarning(Form("No event %s vertex bias correction in vertex bin %d",
194 (r == 'I' || r == 'i' ? "inner" : "outer"), uvb));
197 // Divide by the event selection efficiency
200 if (fUseAcceptance) {
201 TH2D* ac = fcm.GetAcceptance()->GetCorrection(d, r, uvb);
203 AliWarning(Form("No acceptance correction for FMD%d%c in "
204 "vertex bin %d", d, r, uvb));
207 // Divide by the acceptance correction
211 if (fUseMergingEfficiency) {
212 if (!fcm.GetMergingEfficiency()) {
213 AliWarning("No merging efficiencies");
216 TH1D* sf = fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb);
217 if (!fcm.GetMergingEfficiency()->GetCorrection(d,r,uvb)) {
218 AliWarning(Form("No merging efficiency for FMD%d%c at vertex bin %d",
224 for (Int_t ieta = 1; ieta <= h->GetNbinsX(); ieta++) {
225 Float_t c = sf->GetBinContent(ieta);
226 Float_t ec = sf->GetBinError(ieta);
228 if (c == 0) continue;
230 for (Int_t iphi = 1; iphi <= h->GetNbinsY(); iphi++) {
231 Double_t m = h->GetBinContent(ieta, iphi) / c;
232 Double_t em = h->GetBinError(ieta, iphi);
234 Double_t e = TMath::Sqrt(em * em + (m * ec) * (m * ec));
236 h->SetBinContent(ieta,iphi,m);
237 h->SetBinError(ieta,iphi,e);
243 TH2D* bg = fcm.GetSecondaryMap()->GetCorrection(d, r, uvb);
244 TH2D hRing("hring","hring",bg->GetNbinsX(),
245 bg->GetXaxis()->GetXmin(),
246 bg->GetXaxis()->GetXmax(),
248 bg->GetYaxis()->GetXmin(),
249 bg->GetYaxis()->GetXmax());
251 Int_t edgebin[4] = {0,0,0,0};
252 for(Int_t ii = 1; ii <=bg->GetNbinsX(); ii++) {
253 for(Int_t jj = 1; jj <=bg->GetNbinsY(); jj++) {
254 Float_t bgcor = bg->GetBinContent(ii,jj);
255 if(bgcor<0.1) continue;
256 if(edgebin[0] == 0) edgebin[0] = ii;
257 if(edgebin[0] == ii) continue;
258 if(edgebin[0] > 0 && edgebin[1] == 0) edgebin[1] = ii;
259 if(edgebin[0]>0 && edgebin[1]>0) break;
262 for(Int_t ii = bg->GetNbinsX(); ii >= 1; ii--) {
263 for(Int_t jj = 1; jj <=bg->GetNbinsY(); jj++) {
264 Float_t bgcor = bg->GetBinContent(ii,jj);
265 if(bgcor<0.1) continue;
266 if(edgebin[2] == 0) edgebin[2] = ii;
267 if(edgebin[2] == ii) continue;
268 if(edgebin[2] > 0 && edgebin[3] == 0) edgebin[3] = ii;
269 if(edgebin[2]>0 && edgebin[3]>0) break;
272 for(Int_t ii = 1; ii <=bg->GetNbinsX(); ii++) {
273 for(Int_t jj = 1; jj <=bg->GetNbinsY(); jj++) {
274 Float_t data = h->GetBinContent(ii,jj);
275 if(data <0.000001) continue;
276 if(edgebin[0] == ii || edgebin[1] == ii || edgebin[2] == ii || edgebin[3] == ii) continue;
277 hRing.SetBinContent(ii,jj,data);
278 hRing.SetBinError(ii,jj,h->GetBinError(ii,jj));
282 //std::cout<<edgebin[0]<<" "<<edgebin[1]<<" "<<edgebin[2]<<" "<<edgebin[3]<<std::endl;
285 rh->fDensity->Add(h);
292 //____________________________________________________________________
294 AliFMDCorrector::ScaleHistograms(const TList* dir, Int_t nEvents)
297 // Scale the histograms to the total number of events
299 // dir Where the output is stored
300 // nEvents Number of events
302 if (nEvents <= 0) return;
303 TList* d = static_cast<TList*>(dir->FindObject(GetName()));
306 TIter next(&fRingHistos);
308 THStack* sums = new THStack("sums", "Sums of ring results");
309 while ((o = static_cast<RingHistos*>(next()))) {
310 o->ScaleHistograms(d, nEvents);
311 TH1D* sum = o->fDensity->ProjectionX(o->GetName(), 1,
312 o->fDensity->GetNbinsY(),"e");
313 sum->Scale(1., "width");
314 sum->SetTitle(o->GetName());
315 sum->SetDirectory(0);
316 sum->SetYTitle("#sum N_{ch,primary}");
322 //____________________________________________________________________
324 AliFMDCorrector::DefineOutput(TList* dir)
327 // Output diagnostic histograms to directory
330 // dir List to write in
332 TList* d = new TList;
333 d->SetName(GetName());
335 TIter next(&fRingHistos);
337 while ((o = static_cast<RingHistos*>(next()))) {
342 //____________________________________________________________________
344 AliFMDCorrector::Print(Option_t* /* option */) const
351 char ind[gROOT->GetDirLevel()+1];
352 for (Int_t i = 0; i < gROOT->GetDirLevel(); i++) ind[i] = ' ';
353 ind[gROOT->GetDirLevel()] = '\0';
354 std::cout << ind << ClassName() << ": " << GetName() << "\n"
356 << ind << " Use secondary maps: " << fUseSecondaryMap << "\n"
357 << ind << " Use vertex bias: " << fUseVertexBias << "\n"
358 << ind << " Use acceptance: " << fUseAcceptance << "\n"
359 << ind << " Use merging efficiency: " << fUseMergingEfficiency
360 << std::noboolalpha << std::endl;
363 //====================================================================
364 AliFMDCorrector::RingHistos::RingHistos()
365 : AliForwardUtil::RingHistos(),
373 //____________________________________________________________________
374 AliFMDCorrector::RingHistos::RingHistos(UShort_t d, Char_t r)
375 : AliForwardUtil::RingHistos(d,r),
384 fDensity = new TH2D("primaryDensity",
385 "#sum N_{ch,primary}/(#Delta#eta#Delta#phi)",
386 200, -4, 6, (r == 'I' || r == 'i' ? 20 : 40),
388 fDensity->SetDirectory(0);
389 fDensity->SetMarkerColor(Color());
391 fDensity->SetXTitle("#eta");
392 fDensity->SetYTitle("#phi [radians]");
393 fDensity->SetZTitle("Primary N_{ch} density");
395 //____________________________________________________________________
396 AliFMDCorrector::RingHistos::RingHistos(const RingHistos& o)
397 : AliForwardUtil::RingHistos(o),
403 // o Object to copy from
407 //____________________________________________________________________
408 AliFMDCorrector::RingHistos&
409 AliFMDCorrector::RingHistos::operator=(const RingHistos& o)
412 // Assignment operator
414 // o Object to assign from
419 if (&o == this) return *this;
420 AliForwardUtil::RingHistos::operator=(o);
422 if (fDensity) delete fDensity;
424 fDensity = static_cast<TH2D*>(o.fDensity->Clone());
428 //____________________________________________________________________
429 AliFMDCorrector::RingHistos::~RingHistos()
434 if (fDensity) delete fDensity;
437 //____________________________________________________________________
439 AliFMDCorrector::RingHistos::Output(TList* dir)
444 // dir Where to put it
446 TList* d = DefineOutputList(dir);
450 //____________________________________________________________________
452 AliFMDCorrector::RingHistos::ScaleHistograms(TList* dir, Int_t nEvents)
455 // Scale the histograms to the total number of events
457 // dir where the output is stored
458 // nEvents Number of events
460 TList* l = GetOutputList(dir);
463 TH1* density = GetOutputHist(l,"primaryDensity");
464 if (density) density->Scale(1./nEvents);
467 //____________________________________________________________________