1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONTriggerEfficiencyCells.h"
19 #include "AliMpConstants.h"
20 #include "AliMUONConstants.h"
22 // Classes for display
23 #include "AliMUONTriggerDisplay.h"
24 #include "AliCDBManager.h"
25 #include "AliMpDDLStore.h"
30 #include "Riostream.h"
32 #include "TObjArray.h"
33 #include "TGraphAsymmErrors.h"
39 #include "AliMUONTriggerChamberEfficiency.h"
41 //-----------------------------------------------------------------------------
42 /// \class AliMUONTriggerChamberEfficiency
43 /// A class to store and give access to the trigger chamber efficiency.
45 /// Efficiency is stored per cathode on local boards
47 /// The main method of this class is IsTriggered().
49 /// \author Diego Stocco; INFN Torino
50 //-----------------------------------------------------------------------------
53 ClassImp(AliMUONTriggerChamberEfficiency)
56 //__________________________________________________________________________
57 AliMUONTriggerChamberEfficiency::AliMUONTriggerChamberEfficiency(AliMUONTriggerEfficiencyCells* effCells)
61 fEfficiencyMap(effCells),
62 fEfficiencyObjects(0x0),
65 /// Default constructor.
69 //__________________________________________________________________________
70 AliMUONTriggerChamberEfficiency::AliMUONTriggerChamberEfficiency(const Char_t* filename, const Char_t* listname)
75 fEfficiencyObjects(0x0),
78 /// Constructor using an ASCII file.
79 fEfficiencyMap = new AliMUONTriggerEfficiencyCells(filename, listname);
84 //_____________________________________________________________________________
85 AliMUONTriggerChamberEfficiency::AliMUONTriggerChamberEfficiency(const AliMUONTriggerChamberEfficiency& other)
88 fIsOwner(other.fIsOwner),
89 fEfficiencyMap(other.fEfficiencyMap),
90 fEfficiencyObjects(other.fEfficiencyObjects),
91 fDisplayList(other.fDisplayList)
96 //_____________________________________________________________________________
97 AliMUONTriggerChamberEfficiency& AliMUONTriggerChamberEfficiency::operator=(const AliMUONTriggerChamberEfficiency& other)
99 /// Asignment operator
100 // check assignement to self
104 fIsOwner = other.fIsOwner;
105 fEfficiencyMap = other.fEfficiencyMap;
106 fEfficiencyObjects = other.fEfficiencyObjects;
107 fDisplayList = other.fDisplayList;
112 //__________________________________________________________________________
113 AliMUONTriggerChamberEfficiency::~AliMUONTriggerChamberEfficiency()
117 delete fEfficiencyMap;
118 delete fEfficiencyObjects;
123 //__________________________________________________________________________
124 Float_t AliMUONTriggerChamberEfficiency::GetCellEfficiency(Int_t detElemId, Int_t localBoard, Int_t hType) const
126 /// Get the efficiencies of the 2 cathodes at a given local board
128 Int_t chamber = FindChamberIndex(detElemId);
129 Int_t index = GetIndex(kHboardEff, hType, chamber);
130 TGraphAsymmErrors* effGraph = ((TGraphAsymmErrors*)fEfficiencyObjects->At(index));
132 // Some graphs are not available in the old implementation
133 if ( ! effGraph ) return -1.;
136 effGraph->GetPoint(localBoard-1, xpt, ypt);
141 //__________________________________________________________________________
143 AliMUONTriggerChamberEfficiency::IsTriggered(Int_t detElemId, Int_t localBoard, Bool_t &trigBend, Bool_t &trigNonBend) const
145 /// Whether or not a given local board has a chance to trig, on each cathode.
147 // P(B) : probability to fire bending plane
148 Float_t effBend = GetCellEfficiency(detElemId, localBoard, AliMUONTriggerEfficiencyCells::kBendingEff);
150 // P(BN) : probability to fire bending and non-bending plane
151 Float_t effBoth = GetCellEfficiency(detElemId, localBoard, AliMUONTriggerEfficiencyCells::kBothPlanesEff);
153 trigBend = ( gRandom->Rndm() > effBend ) ? kFALSE : kTRUE;
155 // P(N) : probability to fire non-bending plane
156 Float_t effNonBend = GetCellEfficiency(detElemId, localBoard, AliMUONTriggerEfficiencyCells::kNonBendingEff);
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) )
164 trigNonBend = ( gRandom->Rndm() > effNonBend ) ? kFALSE : kTRUE;
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));
172 //__________________________________________________________________________
173 Int_t AliMUONTriggerChamberEfficiency::FindChamberIndex(Int_t detElemId) const
175 /// From detElemId to chamber number
177 // Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
178 Int_t iChamber = detElemId/100 - 1;
179 return iChamber-AliMpConstants::NofTrackingChambers();
183 //__________________________________________________________________________
185 AliMUONTriggerChamberEfficiency::FillFromList(Bool_t useMeanValues)
187 /// Fills internal histos from list.
189 if ( fEfficiencyObjects )
190 delete fEfficiencyObjects;
192 const Int_t kNeffHistos =
193 2 * ( AliMUONTriggerEfficiencyCells::kNcounts - 1 ) * AliMUONConstants::NTriggerCh();
195 fEfficiencyObjects = new TObjArray(kNeffHistos);
196 fEfficiencyObjects->SetOwner();
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};
205 Bool_t rebuildEfficiency = kTRUE;
207 for ( Int_t ide=0; ide<2; ide++){
208 Int_t currDe = deType[ide];
210 if ( useMeanValues && currDe == AliMUONTriggerEfficiencyCells::kHboardCount )
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());
218 AliWarning(Form("Histogram %s not found. Efficiency won't be re-build", histoName.Data()));
219 rebuildEfficiency = kFALSE;
223 AliWarning("Histogram list not present: efficiency won't be re-build");
224 rebuildEfficiency = kFALSE;
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);
231 histoNum = ( rebuildEfficiency ) ?
232 (TH1F*)fEfficiencyMap->GetHistoList()->FindObject(histoName.Data()) :
233 fEfficiencyMap->GetOldEffHisto(currDe, ich, hType);
236 AliWarning(Form("Histogram %s not found. Skip to next", histoName.Data()));
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));
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);
256 auxHistoNum->SetBinContent(iBinBoard, histoNum->GetBinContent(iBin));
257 auxHistoDen->SetBinContent(iBinBoard, histoDen->GetBinContent(iBin));
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));
267 } // if (useMeanValues)
268 } // loop on count type
270 } // loop on detection element histogram
274 //_____________________________________________________________________________
275 void AliMUONTriggerChamberEfficiency::DisplayEfficiency(Bool_t perSlat, Bool_t show2Dhisto)
278 /// Display calculated efficiency.
281 if ( !AliCDBManager::Instance()->GetDefaultStorage() ){
282 AliWarning("Please set default CDB storage (needed for mapping).");
285 if ( AliCDBManager::Instance()->GetRun() < 0 ){
286 AliWarning("Please set CDB run number (needed for mapping).");
290 TString baseCanName = "MTRtrigChEffCan";
293 // Remove previously created canvases
295 TIter next(gROOT->GetListOfCanvases());
296 while ((can = (TCanvas *)next())) {
297 histoName = can->GetName();
298 if ( histoName.Contains(baseCanName.Data()))
303 fDisplayList = new TList();
304 fDisplayList->SetOwner();
306 TH2F* displayHisto = 0x0;
308 AliMUONTriggerDisplay triggerDisplay;
310 Int_t deType = ( perSlat ) ? kHslatEff : kHboardEff;
311 AliMUONTriggerDisplay::EDisplayType displayType = ( perSlat ) ?
312 AliMUONTriggerDisplay::kDisplaySlats : AliMUONTriggerDisplay::kDisplayBoards;
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");
334 (TH2F*)triggerDisplay.GetDisplayHistogram(graph, histoName,
336 hType,currCh,histoName,
337 AliMUONTriggerDisplay::kShowZeroes);
338 displayHisto->SetDirectory(0);
342 displayHisto->GetZaxis()->SetRangeUser(0.,1.);
343 displayHisto->GetYaxis()->SetTitleOffset(1.4);
344 displayHisto->SetStats(kFALSE);
345 displayHisto->DrawCopy("COLZ");
348 if ( deType == kHboardEff ){
349 histoName = Form("labels%iChamber%i", hType, currCh);
351 (TH2F*)triggerDisplay.GetBoardNumberHisto(histoName,currCh);
352 displayHisto->SetDirectory(0);
353 displayHisto->DrawCopy("textsame");
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");
365 } // loop on count type
370 //__________________________________________________________________________
371 Bool_t AliMUONTriggerChamberEfficiency::LowStatisticsSettings(Bool_t useMeanValues)
374 /// In case of low statistics, fill the local board efficiency with
375 /// the average value of the RPC
379 AliInfo("Boards filled with the average efficiency of the RPC");
381 FillFromList(useMeanValues);
387 //__________________________________________________________________________
389 AliMUONTriggerChamberEfficiency::GetIndex(Int_t histoType, Int_t countType,
393 /// Return the index of the object in the array
396 const Int_t kNtypes = AliMUONTriggerEfficiencyCells::kNcounts - 1;
397 const Int_t kNchambers = AliMUONConstants::NTriggerCh();
399 histoType * kNtypes * kNchambers +
402 //countType * kNchambers +
406 //_____________________________________________________________________________
407 TGraphAsymmErrors* AliMUONTriggerChamberEfficiency::GetEfficiencyGraph(TH1* histoNum, TH1* histoDen)
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
415 TGraphAsymmErrors* auxGraph = 0x0;
416 if ( histoDen ) auxGraph = new TGraphAsymmErrors(histoNum,histoDen);
417 else auxGraph = new TGraphAsymmErrors(histoNum);
419 Int_t npoints = histoNum->GetNbinsX();
420 TGraphAsymmErrors* effGraph = new TGraphAsymmErrors(npoints);
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) ) {
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);