]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTriggerChamberEfficiency.cxx
TOF QA Task (F. Bellini)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerChamberEfficiency.cxx
CommitLineData
f3d288ab 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17
18#include "AliMUONTriggerEfficiencyCells.h"
19#include "AliMpConstants.h"
20#include "AliMUONConstants.h"
21
22// Classes for display
23#include "AliMUONTriggerDisplay.h"
24#include "AliCDBManager.h"
25#include "AliMpDDLStore.h"
26
27#include "AliLog.h"
28
29#include "TRandom.h"
30#include "Riostream.h"
31#include "TH1F.h"
32#include "TObjArray.h"
33#include "TGraphAsymmErrors.h"
34
35#include "TH2F.h"
36#include "TCanvas.h"
37#include "TROOT.h"
38
39#include "AliMUONTriggerChamberEfficiency.h"
40
41//-----------------------------------------------------------------------------
42/// \class AliMUONTriggerChamberEfficiency
43/// A class to store and give access to the trigger chamber efficiency.
44///
45/// Efficiency is stored per cathode on local boards
46///
47/// The main method of this class is IsTriggered().
48///
49/// \author Diego Stocco; INFN Torino
50//-----------------------------------------------------------------------------
51
52/// \cond CLASSIMP
53ClassImp(AliMUONTriggerChamberEfficiency)
54/// \endcond
55
56//__________________________________________________________________________
57AliMUONTriggerChamberEfficiency::AliMUONTriggerChamberEfficiency(AliMUONTriggerEfficiencyCells* effCells)
58:
59TObject(),
60fIsOwner(kFALSE),
61fEfficiencyMap(effCells),
62fEfficiencyObjects(0x0),
63fDisplayList(0x0)
64{
65/// Default constructor.
66 FillFromList();
67}
68
69//__________________________________________________________________________
70AliMUONTriggerChamberEfficiency::AliMUONTriggerChamberEfficiency(const Char_t* filename, const Char_t* listname)
71:
72TObject(),
73fIsOwner(kTRUE),
74fEfficiencyMap(0x0),
75fEfficiencyObjects(0x0),
76fDisplayList(0x0)
77{
78/// Constructor using an ASCII file.
79 fEfficiencyMap = new AliMUONTriggerEfficiencyCells(filename, listname);
80 FillFromList();
81}
82
83
84//_____________________________________________________________________________
85AliMUONTriggerChamberEfficiency::AliMUONTriggerChamberEfficiency(const AliMUONTriggerChamberEfficiency& other)
86:
87TObject(other),
88fIsOwner(other.fIsOwner),
89fEfficiencyMap(other.fEfficiencyMap),
90fEfficiencyObjects(other.fEfficiencyObjects),
91fDisplayList(other.fDisplayList)
92{
93/// Copy constructor
94}
95
96//_____________________________________________________________________________
97AliMUONTriggerChamberEfficiency& AliMUONTriggerChamberEfficiency::operator=(const AliMUONTriggerChamberEfficiency& other)
98{
99 /// Asignment operator
100 // check assignement to self
101 if (this == &other)
102 return *this;
103
104 fIsOwner = other.fIsOwner;
105 fEfficiencyMap = other.fEfficiencyMap;
106 fEfficiencyObjects = other.fEfficiencyObjects;
107 fDisplayList = other.fDisplayList;
108
109 return *this;
110}
111
112//__________________________________________________________________________
113AliMUONTriggerChamberEfficiency::~AliMUONTriggerChamberEfficiency()
114{
115/// Destructor.
116 if ( fIsOwner )
117 delete fEfficiencyMap;
118 delete fEfficiencyObjects;
119 delete fDisplayList;
120}
121
122
123//__________________________________________________________________________
124Float_t AliMUONTriggerChamberEfficiency::GetCellEfficiency(Int_t detElemId, Int_t localBoard, Int_t hType) const
125{
126/// Get the efficiencies of the 2 cathodes at a given local board
127
128 Int_t chamber = FindChamberIndex(detElemId);
129 Int_t index = GetIndex(kHboardEff, hType, chamber);
130 TGraphAsymmErrors* effGraph = ((TGraphAsymmErrors*)fEfficiencyObjects->At(index));
131
132 // Some graphs are not available in the old implementation
133 if ( ! effGraph ) return -1.;
134
135 Double_t xpt, ypt;
136 effGraph->GetPoint(localBoard-1, xpt, ypt);
137 return ypt;
138}
139
140
141//__________________________________________________________________________
142void
143AliMUONTriggerChamberEfficiency::IsTriggered(Int_t detElemId, Int_t localBoard, Bool_t &trigBend, Bool_t &trigNonBend) const
144{
145/// Whether or not a given local board has a chance to trig, on each cathode.
146
147 // P(B) : probability to fire bending plane
148 Float_t effBend = GetCellEfficiency(detElemId, localBoard, AliMUONTriggerEfficiencyCells::kBendingEff);
149
150 // P(BN) : probability to fire bending and non-bending plane
151 Float_t effBoth = GetCellEfficiency(detElemId, localBoard, AliMUONTriggerEfficiencyCells::kBothPlanesEff);
152
153 trigBend = ( gRandom->Rndm() > effBend ) ? kFALSE : kTRUE;
154
155 // P(N) : probability to fire non-bending plane
156 Float_t effNonBend = GetCellEfficiency(detElemId, localBoard, AliMUONTriggerEfficiencyCells::kNonBendingEff);
157
158 if ( effBoth > 0 ) {
159 effNonBend = ( trigBend ) ?
160 effBoth / effBend : // P(N|B) = P(BN) / P(B)
161 ( effNonBend - effBoth ) / ( 1. - effBend ); // P(N|!B) = ( P(N) - P(BN) ) / ( 1 - P(B) )
162 }
163
164 trigNonBend = ( gRandom->Rndm() > effNonBend ) ? kFALSE : kTRUE;
165
166 AliDebug(2,Form("Ch %i board %i resp (%i, %i) prob (%.2f, %.2f) effNB %.2f effBoth %.2f\n", detElemId/100, localBoard, trigBend, trigNonBend, effBend, effNonBend, GetCellEfficiency(detElemId, localBoard, AliMUONTriggerEfficiencyCells::kNonBendingEff), effBoth));
167
168
169}
170
171
172//__________________________________________________________________________
173Int_t AliMUONTriggerChamberEfficiency::FindChamberIndex(Int_t detElemId) const
174{
175/// From detElemId to chamber number
176
177 // Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
178 Int_t iChamber = detElemId/100 - 1;
179 return iChamber-AliMpConstants::NofTrackingChambers();
180}
181
182
183//__________________________________________________________________________
184void
185AliMUONTriggerChamberEfficiency::FillFromList(Bool_t useMeanValues)
186{
187/// Fills internal histos from list.
188
189 if ( fEfficiencyObjects )
190 delete fEfficiencyObjects;
191
192 const Int_t kNeffHistos =
193 2 * ( AliMUONTriggerEfficiencyCells::kNcounts - 1 ) * AliMUONConstants::NTriggerCh();
194
195 fEfficiencyObjects = new TObjArray(kNeffHistos);
196 fEfficiencyObjects->SetOwner();
197
198 TH1F *histoNum = 0x0, *histoDen=0x0;
199 TString histoName = "";
200 Int_t deType[2] = {AliMUONTriggerEfficiencyCells::kHboardCount,
201 AliMUONTriggerEfficiencyCells::kHslatCount};
202 Int_t deTypeEff[2] = {kHboardEff, kHslatEff};
203 Int_t index = -1;
204
205 Bool_t rebuildEfficiency = kTRUE;
206
207 for ( Int_t ide=0; ide<2; ide++){
208 Int_t currDe = deType[ide];
209
210 if ( useMeanValues && currDe == AliMUONTriggerEfficiencyCells::kHboardCount )
211 continue;
212
213 for(Int_t ich=0; ich<AliMUONConstants::NTriggerCh(); ich++){
214 histoName = fEfficiencyMap->GetHistoName(currDe, AliMUONTriggerEfficiencyCells::kAllTracks, ich);
215 if ( fEfficiencyMap->GetHistoList() ) {
216 histoDen = (TH1F*)fEfficiencyMap->GetHistoList()->FindObject(histoName.Data());
217 if ( !histoDen ) {
218 AliWarning(Form("Histogram %s not found. Efficiency won't be re-build", histoName.Data()));
219 rebuildEfficiency = kFALSE;
220 }
221 }
222 else {
223 AliWarning("Histogram list not present: efficiency won't be re-build");
224 rebuildEfficiency = kFALSE;
225 }
226
227 Int_t nTypes = ( rebuildEfficiency ) ? AliMUONTriggerEfficiencyCells::kNcounts-1 : 2;
228 for(Int_t hType=0; hType<nTypes; hType++){
229 histoName = fEfficiencyMap->GetHistoName(currDe, hType, ich);
230
231 histoNum = ( rebuildEfficiency ) ?
232 (TH1F*)fEfficiencyMap->GetHistoList()->FindObject(histoName.Data()) :
233 fEfficiencyMap->GetOldEffHisto(currDe, ich, hType);
234
235 if ( !histoNum ) {
236 AliWarning(Form("Histogram %s not found. Skip to next", histoName.Data()));
237 continue;
238 }
239
240 index = GetIndex(deTypeEff[ide], hType, ich);
241 TGraphAsymmErrors* effGraph = GetEfficiencyGraph(histoNum,histoDen);
242 histoName.ReplaceAll("Count","Eff");
243 effGraph->SetName(histoName.Data());
244 fEfficiencyObjects->AddAt(effGraph, index);
245 AliDebug(5,Form("Adding object %s (%s/%s) at index %i",effGraph->GetName(),histoNum->GetName(),histoDen->GetName(),index));
246
247 if ( useMeanValues ){
248 Int_t currChamber = ich + AliMpConstants::NofTrackingChambers();
249 histoName = fEfficiencyMap->GetHistoName(AliMUONTriggerEfficiencyCells::kHboardCount, hType, ich);
250 TH1F* auxHistoNum = (TH1F*)fEfficiencyMap->GetHistoList()->FindObject(histoName.Data())->Clone("tempHistoNum");
251 TH1F* auxHistoDen = (TH1F*)fEfficiencyMap->GetHistoList()->FindObject(histoName.Data())->Clone("tempHistoDen");
252 for ( Int_t iBinBoard = 1; iBinBoard<=AliMpConstants::NofLocalBoards(); iBinBoard++){
253 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(iBinBoard, currChamber);
254 Int_t iBin = histoNum->FindBin(detElemId%100);
255
256 auxHistoNum->SetBinContent(iBinBoard, histoNum->GetBinContent(iBin));
257 auxHistoDen->SetBinContent(iBinBoard, histoDen->GetBinContent(iBin));
258 }
259 index = GetIndex(kHboardEff, hType, ich);
260 effGraph = GetEfficiencyGraph(auxHistoNum,auxHistoDen);
261 histoName.ReplaceAll("Count","Eff");
262 effGraph->SetName(histoName.Data());
263 fEfficiencyObjects->AddAt(effGraph, index);
264 AliDebug(5,Form("Adding object %s (%s/%s) at index %i",effGraph->GetName(),histoNum->GetName(),histoDen->GetName(),index));
265 delete auxHistoNum;
266 delete auxHistoDen;
267 } // if (useMeanValues)
268 } // loop on count type
269 } // loop on chamber
270 } // loop on detection element histogram
271}
272
273
274//_____________________________________________________________________________
275void AliMUONTriggerChamberEfficiency::DisplayEfficiency(Bool_t perSlat, Bool_t show2Dhisto)
276{
277 //
278 /// Display calculated efficiency.
279 //
280
281 if ( !AliCDBManager::Instance()->GetDefaultStorage() ){
282 AliWarning("Please set default CDB storage (needed for mapping).");
283 return;
284 }
285 if ( AliCDBManager::Instance()->GetRun() < 0 ){
286 AliWarning("Please set CDB run number (needed for mapping).");
287 return;
288 }
289
290 TString baseCanName = "MTRtrigChEffCan";
291 TString histoName;
292
293 // Remove previously created canvases
294 TCanvas* can = 0x0;
295 TIter next(gROOT->GetListOfCanvases());
296 while ((can = (TCanvas *)next())) {
297 histoName = can->GetName();
298 if ( histoName.Contains(baseCanName.Data()))
299 delete can;
300 }
301
302 delete fDisplayList;
303 fDisplayList = new TList();
304 fDisplayList->SetOwner();
305
306 TH2F* displayHisto = 0x0;
307
308 AliMUONTriggerDisplay triggerDisplay;
309
310 Int_t deType = ( perSlat ) ? kHslatEff : kHboardEff;
311 AliMUONTriggerDisplay::EDisplayType displayType = ( perSlat ) ?
312 AliMUONTriggerDisplay::kDisplaySlats : AliMUONTriggerDisplay::kDisplayBoards;
313 Int_t index = -1;
314
315 TGraph* graph = 0x0;
316
317 // Book histos
318 for(Int_t ich=0; ich<AliMUONConstants::NTriggerCh(); ich++){
319 Int_t currCh = 11 + ich;
320 for(Int_t hType=0; hType<AliMUONTriggerEfficiencyCells::kNcounts - 1; hType++){
321 index = GetIndex(deType, hType, ich);
322 graph = (TGraph*)fEfficiencyObjects->At(index);
323 if ( ! graph ) continue;
324 histoName = graph->GetName();
325 histoName += baseCanName;
326 Int_t shift = 10*(index%((AliMUONTriggerEfficiencyCells::kNcounts - 1)*
327 AliMUONConstants::NTriggerCh()));
328 can = new TCanvas(histoName.Data(), histoName.Data(), 100+shift, shift, 700, 700);
329 can->SetRightMargin(0.14);
330 can->SetLeftMargin(0.12);
331 histoName.ReplaceAll(baseCanName.Data(), "Display");
332 if ( show2Dhisto ) {
333 displayHisto =
334 (TH2F*)triggerDisplay.GetDisplayHistogram(graph, histoName,
335 displayType,
336 hType,currCh,histoName,
337 AliMUONTriggerDisplay::kShowZeroes);
338 displayHisto->SetDirectory(0);
339 }
340
341 if ( show2Dhisto ){
342 displayHisto->GetZaxis()->SetRangeUser(0.,1.);
343 displayHisto->GetYaxis()->SetTitleOffset(1.4);
344 displayHisto->SetStats(kFALSE);
345 displayHisto->DrawCopy("COLZ");
346 delete displayHisto;
347
348 if ( deType == kHboardEff ){
349 histoName = Form("labels%iChamber%i", hType, currCh);
350 displayHisto =
351 (TH2F*)triggerDisplay.GetBoardNumberHisto(histoName,currCh);
352 displayHisto->SetDirectory(0);
353 displayHisto->DrawCopy("textsame");
354 delete displayHisto;
355 }
356 }
357 else {
358 TGraphAsymmErrors* drawGraph = (TGraphAsymmErrors*)graph->Clone(histoName.Data());
359 drawGraph->SetMarkerStyle(20);
360 drawGraph->SetMarkerSize(0.7);
361 drawGraph->SetMarkerColor(kRed);
362 fDisplayList->Add(drawGraph);
363 drawGraph->Draw("ap");
364 } // loop on chamber
365 } // loop on count type
366 } // loop on chamber
367}
368
369
370//__________________________________________________________________________
371Bool_t AliMUONTriggerChamberEfficiency::LowStatisticsSettings(Bool_t useMeanValues)
372{
373 //
374 /// In case of low statistics, fill the local board efficiency with
375 /// the average value of the RPC
376 //
377
378 if ( useMeanValues )
379 AliInfo("Boards filled with the average efficiency of the RPC");
380
381 FillFromList(useMeanValues);
382
383 return kTRUE;
384}
385
386
387//__________________________________________________________________________
388Int_t
389AliMUONTriggerChamberEfficiency::GetIndex(Int_t histoType, Int_t countType,
390 Int_t chamber) const
391{
392 //
393 /// Return the index of the object in the array
394 //
395
396 const Int_t kNtypes = AliMUONTriggerEfficiencyCells::kNcounts - 1;
397 const Int_t kNchambers = AliMUONConstants::NTriggerCh();
398 return
399 histoType * kNtypes * kNchambers +
400 chamber * kNtypes +
401 countType;
402 //countType * kNchambers +
403 //chamber;
404}
405
406//_____________________________________________________________________________
407TGraphAsymmErrors* AliMUONTriggerChamberEfficiency::GetEfficiencyGraph(TH1* histoNum, TH1* histoDen)
408{
409 //
410 /// Create the graph of efficiency from the numerator and denominator
411 /// histogram in such a way to have a point set also for
412 /// detection elements with efficiency = 0 or non calculated
413 //
414
415 TGraphAsymmErrors* auxGraph = 0x0;
4784d180 416 if ( histoDen ) auxGraph = new TGraphAsymmErrors(histoNum,histoDen,"cp");
f3d288ab 417 else auxGraph = new TGraphAsymmErrors(histoNum);
418
419 Int_t npoints = histoNum->GetNbinsX();
420 TGraphAsymmErrors* effGraph = new TGraphAsymmErrors(npoints);
421 Double_t oldX, oldY;
422 for ( Int_t ibin=0; ibin<npoints; ibin++ ) {
423 Int_t foundPoint = -1;
424 for (Int_t ipt=0; ipt<auxGraph->GetN(); ipt++) {
425 auxGraph->GetPoint(ipt, oldX, oldY);
426 if ( oldX > histoNum->GetBinLowEdge(ibin+1) &&
427 oldX < histoNum->GetBinLowEdge(ibin+2) ) {
428 foundPoint = ipt;
429 break;
430 }
431 }
432 Double_t currX = ( foundPoint < 0 ) ? histoNum->GetBinCenter(ibin+1) : oldX;
433 Double_t currY = ( foundPoint < 0 ) ? 0. : oldY;
434 Double_t eyl = ( foundPoint < 0 ) ? 0. : auxGraph->GetErrorYlow(foundPoint);
435 Double_t eyh = ( foundPoint < 0 ) ? 0. : auxGraph->GetErrorYhigh(foundPoint);
436 effGraph->SetPoint(ibin, currX, currY);
437 effGraph->SetPointError(ibin, 0., 0., eyl, eyh);
438 }
439
440 delete auxGraph;
441
442 return effGraph;
443}