]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerEfficiencyCells.cxx
Simplifications, now that pedestal subprocessor is taking care of deciding whether...
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerEfficiencyCells.cxx
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
21 // Classes for display
22 #include "AliMUONTriggerDisplay.h"
23 #include "AliCDBManager.h"
24 #include "AliMpCDB.h"
25 #include "AliMpDDLStore.h"
26 #include "AliMpLocalBoard.h"
27 #include "AliMpPad.h"
28 #include "AliMpVSegmentation.h"
29 #include "AliMpSegmentation.h"
30
31 #include "AliLog.h"
32
33 #include "TRandom.h"
34 #include "Riostream.h"
35 #include "TSystem.h"
36 #include "TFile.h"
37 #include "TH1F.h"
38 #include "TMath.h"
39
40 #include "TH2F.h"
41 #include "TH3F.h"
42 #include "TF1.h"
43 #include "TStyle.h"
44 #include "TPaveLabel.h"
45 #include "TCanvas.h"
46
47 #include <fstream>
48 #include <cassert>
49
50 //-----------------------------------------------------------------------------
51 /// \class AliMUONTriggerEfficiencyCells
52 /// A class to store and give access to the trigger chamber efficiency.
53 ///
54 /// Efficiency is stored per cathode on local boards
55 ///
56 /// The main method of this class is IsTriggered().
57 ///
58 /// $ALICE_ROOT/MUON/data/efficiencyCells.dat contains efficiency 
59 /// for each chamber (i.e. DetElement). 
60 ///
61 /// In the case of local boards, efficiency is stored from left to right
62 /// per increasing board number (from 1 to 234)
63 ///
64 /// The file can be edited in order to change efficiency
65 /// in a chosen local board/region of the chamber.
66 ///
67 ///
68 /// But please note that this object is also available from the CDB 
69 ///
70 /// \author Diego Stocco; INFN Torino
71 //-----------------------------------------------------------------------------
72
73 /// \cond CLASSIMP
74 ClassImp(AliMUONTriggerEfficiencyCells)
75 /// \endcond
76
77 //__________________________________________________________________________
78 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
79 :
80 TObject(),
81 fCountHistoList(0x0),
82 fNoCountHistoList(0x0),
83 fFiredStrips(0x0),
84 fDisplayHistoList(0x0),
85 fBoardLabelList(0x0),
86 fFiredFitHistoList(0x0),
87 fFiredDisplayHistoList(0x0)
88 {
89 ///  Default constructor.
90   CheckConstants();
91   Reset();
92   InitHistos();
93 }
94
95 //__________________________________________________________________________
96 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const Char_t* filename, const Char_t* listname)
97 :
98 TObject(),
99 fCountHistoList(0x0),
100 fNoCountHistoList(0x0),
101 fFiredStrips(0x0),
102 fDisplayHistoList(0x0),
103 fBoardLabelList(0x0),
104 fFiredFitHistoList(0x0),
105 fFiredDisplayHistoList(0x0)
106 {
107 ///  Constructor using an ASCII file.
108   CheckConstants();
109   Reset();
110   InitHistos();
111   ReadFile(filename, listname);
112 }
113
114
115 //__________________________________________________________________________
116 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(TList *countHistoList,
117                                                              TList *noCountHistoList)
118 :
119 TObject(),
120 fCountHistoList(countHistoList),
121 fNoCountHistoList(noCountHistoList),
122 fFiredStrips(0x0),
123 fDisplayHistoList(0x0),
124 fBoardLabelList(0x0),
125 fFiredFitHistoList(0x0),
126 fFiredDisplayHistoList(0x0)
127 {
128 ///  Constructor using a list of histograms with counts.
129   CheckConstants();
130   Reset();
131   InitHistos();
132   FillHistosFromList();
133 }
134
135 //_____________________________________________________________________________
136 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const AliMUONTriggerEfficiencyCells& other)
137 :
138 TObject(other),
139 fCountHistoList(other.fCountHistoList),
140 fNoCountHistoList(other.fNoCountHistoList),
141 fFiredStrips(other.fFiredStrips),
142 fDisplayHistoList(other.fDisplayHistoList),
143 fBoardLabelList(other.fBoardLabelList),
144 fFiredFitHistoList(other.fFiredFitHistoList),
145 fFiredDisplayHistoList(other.fFiredDisplayHistoList)
146 {
147 /// Copy constructor
148
149   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
150     fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
151     fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
152   }
153 }
154
155 //_____________________________________________________________________________
156 AliMUONTriggerEfficiencyCells& AliMUONTriggerEfficiencyCells::operator=(const AliMUONTriggerEfficiencyCells& other)
157 {
158   /// Asignment operator
159   // check assignement to self
160   if (this == &other)
161     return *this;
162
163   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
164     fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
165     fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
166   }
167
168   fCountHistoList = other.fCountHistoList;
169   fNoCountHistoList = other.fNoCountHistoList;
170   fFiredStrips = other.fFiredStrips;
171
172   fDisplayHistoList = other.fDisplayHistoList;
173   fBoardLabelList = other.fBoardLabelList;
174   fFiredFitHistoList = other.fFiredFitHistoList;
175   fFiredDisplayHistoList = other.fFiredDisplayHistoList;
176     
177   return *this;
178 }
179
180 //__________________________________________________________________________
181 AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
182 {
183 ///  Destructor.
184   Reset();
185 }
186
187
188 //__________________________________________________________________________
189 void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t localBoard, Float_t &eff1, Float_t &eff2) const
190 {
191 ///  Get the efficiencies of the 2 cathodes at a given local board
192
193   Int_t chamber = FindChamberIndex(detElemId);
194   Int_t bin = fBoardEfficiency[chamber]->FindBin(localBoard);
195   eff1 = fBoardEfficiency[chamber]->GetBinContent(bin);
196   eff2 = fBoardEfficiency[fgkNchambers+chamber]->GetBinContent(bin);
197 }
198
199
200 //__________________________________________________________________________
201 void 
202 AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t localBoard, Bool_t &trig1, Bool_t &trig2) const
203 {
204 ///  Whether or not a given local board has a chance to trig, on each cathode.
205
206   Float_t eff1 = 0.0;
207   Float_t eff2 = 0.0;
208   GetCellEfficiency(detElemId, localBoard, eff1, eff2);
209   trig1 = kTRUE; 
210   trig2 = kTRUE;
211   if(gRandom->Rndm()>eff1)trig1 = kFALSE;
212   if(gRandom->Rndm()>eff2)trig2 = kFALSE;
213 }
214
215
216 //__________________________________________________________________________
217 void AliMUONTriggerEfficiencyCells::ReadFile(const Char_t* filename, const Char_t* listname)
218 {
219 ///  Reads a file containing the efficiency map.
220
221   TString fileName = gSystem->ExpandPathName(filename);
222   if(fileName.EndsWith(".root")){
223       ReadHistoBoards(fileName.Data(), listname);
224       return;
225   }
226
227   ifstream file(fileName.Data());
228   Char_t dat[50];
229   if (file.good()){
230       file >> dat;
231       if(!strcmp(dat,"localBoards"))ReadFileBoards(file);
232       else AliWarning("File .dat in wrong format");
233       file.close();
234   } else {
235     AliError(Form("Can't read file %s",fileName.Data()));
236   }
237 }
238
239
240 //__________________________________________________________________________
241 void AliMUONTriggerEfficiencyCells::ReadFileBoards(ifstream &file)
242 {
243 ///  Structure of file (.dat) containing local board efficency
244   Int_t datInt=0, detEl=0, chamber=0, chCath=0, bin=0;
245     Float_t datFloat=0.0;
246     Char_t dat[50];
247
248     while (file >> dat) {
249             file >> detEl;
250             chamber = FindChamberIndex(detEl);
251             for(Int_t cath=0; cath<fgkNcathodes; cath++){
252                 chCath = GetPlane(chamber, cath);
253                 file >> dat;
254                 file >> datInt;
255                 for(Int_t board=1; board<=AliMpConstants::NofLocalBoards(); board++){
256                     file >> datFloat;
257                     bin = fBoardEfficiency[chCath]->FindBin(board);
258                     fBoardEfficiency[chCath]->SetBinContent(bin, datFloat);
259                 }
260             }
261     }
262 }
263
264
265 //__________________________________________________________________________
266 void AliMUONTriggerEfficiencyCells::ReadHistoBoards(const Char_t *filename, const Char_t* listname)
267 {
268 ///  Structure of file (.root) containing local board efficency
269     TFile *file = new TFile(filename, "read");
270     if(!file || !file->IsOpen()) {
271       AliError(Form("Can't read file %s",filename));
272       return;
273     }
274
275     TString histoName;
276     TString cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
277     enum {kAllChEff, kChNonEff, kNumOfHistoTypes};
278     TString histoTypeName[2] = {"CountInCh", "NonCountInCh"};
279
280     if ( ! fCountHistoList ) {
281       fCountHistoList = new TList();
282       fCountHistoList->SetOwner();
283     }
284     else fCountHistoList->Delete();
285     if( ! fNoCountHistoList) {
286       fNoCountHistoList = new TList();
287       fNoCountHistoList->SetOwner();
288     }
289     else fNoCountHistoList->Delete();
290
291     TList *currList[2] = {fCountHistoList, fNoCountHistoList};
292
293     TH1F *histo = 0x0;
294
295     TList* listInFile = 0x0;
296     TString listNameString(listname);
297     if ( ! listNameString.IsNull() )
298       listInFile = (TList*)file->Get(listname);
299     
300     for(Int_t cath=0; cath<fgkNcathodes; cath++){
301       for(Int_t hType=0; hType<kNumOfHistoTypes; hType++){
302         histoName = Form("%sChamber%s", cathCode[cath].Data(), histoTypeName[hType].Data());
303         histo = ( listInFile ) ? (TH1F*)listInFile->FindObject(histoName.Data()) : (TH1F*)file->Get(histoName.Data());
304         histo->SetDirectory(0);
305         currList[hType]->Add(histo);
306       }
307     }
308
309     for(Int_t cath=0; cath<fgkNcathodes; cath++){
310       for(Int_t ch=0; ch<fgkNchambers; ch++){
311         for(Int_t hType=0; hType<kNumOfHistoTypes; hType++){
312           histoName = Form("%sSlat%s%i", cathCode[cath].Data(), histoTypeName[hType].Data(), 11+ch);
313           histo = ( listInFile ) ? (TH1F*)listInFile->FindObject(histoName.Data()) : (TH1F*)file->Get(histoName.Data());
314           histo->SetDirectory(0);
315           currList[hType]->Add(histo);
316         }
317       }
318     }
319
320     for(Int_t cath=0; cath<fgkNcathodes; cath++){
321       for(Int_t ch=0; ch<fgkNchambers; ch++){
322         for(Int_t hType=0; hType<kNumOfHistoTypes; hType++){
323           histoName = Form("%sBoard%s%i", cathCode[cath].Data(), histoTypeName[hType].Data(), 11+ch);
324           histo = ( listInFile ) ? (TH1F*)listInFile->FindObject(histoName.Data()) : (TH1F*)file->Get(histoName.Data());
325           histo->SetDirectory(0);
326           currList[hType]->Add(histo);
327         }
328       }
329     }
330
331     file->Close();
332
333     FillHistosFromList();
334 }
335
336
337 //_____________________________________________________________________________
338 void AliMUONTriggerEfficiencyCells::CheckConstants() const
339 {
340 /// Check consistence of redefined constants 
341
342   assert(fgkNcathodes == AliMpConstants::NofCathodes());    
343   assert(fgkNchambers == AliMpConstants::NofTriggerChambers());    
344   assert(fgkNplanes == AliMpConstants::NofTriggerChambers() * fgkNcathodes);    
345 }
346
347
348 //__________________________________________________________________________
349 Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId) const
350 {
351 ///  From detElemId to chamber number
352
353   // Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
354   Int_t iChamber = detElemId/100 - 1;
355   Int_t chamber = iChamber-AliMpConstants::NofTrackingChambers();
356   return chamber;
357 }
358
359
360 //__________________________________________________________________________
361 void
362 AliMUONTriggerEfficiencyCells::Reset(Bool_t resetAll)
363 {
364 ///  Sets our internal array contents to zero.
365
366   if ( resetAll ){
367     for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
368       if ( fBoardEfficiency[chCath] ) {
369         fBoardEfficiency[chCath] = 0x0;
370       }
371       if ( fSlatEfficiency[chCath] ) {
372         fSlatEfficiency[chCath] = 0x0;
373       }
374     }
375
376     if ( fCountHistoList )
377       delete fCountHistoList;
378     if ( fNoCountHistoList )
379       delete fNoCountHistoList;
380   }
381
382   if ( fFiredStrips )
383     delete fFiredStrips;
384   if ( fDisplayHistoList )
385     delete fDisplayHistoList;
386   if ( fBoardLabelList )
387     delete fBoardLabelList;
388   if ( fFiredFitHistoList )
389     delete fFiredFitHistoList;
390   if ( fFiredDisplayHistoList )
391     delete fFiredDisplayHistoList;
392 }
393
394
395 //__________________________________________________________________________
396 void
397 AliMUONTriggerEfficiencyCells::InitHistos()
398 {
399 ///  Sets our internal array contents to zero.
400
401   const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
402   const Int_t kNslats = 18;
403   Int_t chCath=0;
404   TString histoName;
405
406   TString cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
407
408   for(Int_t ch=0; ch<fgkNchambers; ch++){
409     for(Int_t cath=0; cath<fgkNcathodes; cath++){
410       chCath = GetPlane(ch, cath);
411       histoName = Form("%sBoardEffChamber%i", cathCode[cath].Data(), 11+ch);
412       fBoardEfficiency[chCath] = new TH1F(histoName.Data(), histoName.Data(), kNumOfBoards, 1-0.5, kNumOfBoards+1.-0.5);
413       histoName = Form("%sSlatEffChamber%i", cathCode[cath].Data(), 11+ch);
414       fSlatEfficiency[chCath] = new TH1F(histoName.Data(), histoName.Data(), kNslats, 0-0.5, kNslats-0.5);
415     }
416   }
417 }
418
419
420 //__________________________________________________________________________
421 void
422 AliMUONTriggerEfficiencyCells::FillHistosFromList(Bool_t useMeanValues)
423 {
424 ///  Fills internal histos from list.
425
426   Int_t nHistoBins=0;
427   TH1F *histoNum = 0x0, *histoDen=0x0, *currHisto = 0x0;
428   TString slatName = "SLAT", boardName = "BOARD", histoName;
429   Float_t efficiency, efficiencyError;
430   TString chName;
431
432   Int_t nentries = fCountHistoList->GetEntries();
433
434   if ( useMeanValues )
435     AliInfo("Boards filled with the average efficiency of the RPC");
436
437   for(Int_t iEntry=0; iEntry<nentries; iEntry++){
438     histoNum = (TH1F*)fCountHistoList->At(iEntry);
439     histoDen = (TH1F*)fNoCountHistoList->At(iEntry);
440
441     if(!histoNum) {
442       AliWarning("Histogram not found in fCountHistoList. Skip to next");
443       continue;
444     }
445     if(!histoDen) {
446       AliWarning("Histogram not found in fNoCountHistoList. Skip to next");
447       continue;
448     }
449
450     histoName = histoNum->GetName();
451     histoName.ToUpper();
452     nHistoBins = histoNum->GetNbinsX();
453
454
455     Int_t currCh = 0;
456     for(Int_t ich = 11; ich<=14; ich++){
457       chName = Form("%i", ich);
458       if ( histoName.Contains(chName.Data())){
459         currCh = ich-11;
460         break;
461       }
462     }
463     Int_t currCath = ( histoName.Contains("NONBEND") ) ? 1 : 0;
464
465     Int_t chCath = GetPlane(currCh, currCath);
466
467     if(histoName.Contains(boardName)){
468       if ( useMeanValues ) continue;
469       currHisto = fBoardEfficiency[chCath];
470     }
471     else if(histoName.Contains(slatName)){
472       currHisto = fSlatEfficiency[chCath];
473     }
474     else
475       continue;
476
477     for(Int_t iBin=1; iBin<=nHistoBins; iBin++){
478       CalculateEfficiency((Int_t)histoNum->GetBinContent(iBin), (Int_t)histoNum->GetBinContent(iBin) + (Int_t)histoDen->GetBinContent(iBin), efficiency, efficiencyError, kFALSE);
479
480       currHisto->SetBinContent(iBin, efficiency);
481       currHisto->SetBinError(iBin, efficiencyError);
482     }
483
484     if ( useMeanValues ){
485       currHisto = fBoardEfficiency[chCath];
486       Int_t nBinsBoards = currHisto->GetNbinsX();
487       Int_t currChamber = currCh + AliMpConstants::NofTrackingChambers();
488       for ( Int_t iBinBoard = 1; iBinBoard<= nBinsBoards; iBinBoard++){
489         Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(iBinBoard, currChamber);
490         Int_t iBin = histoNum->FindBin(detElemId%100);
491
492         CalculateEfficiency((Int_t)histoNum->GetBinContent(iBin), (Int_t)histoNum->GetBinContent(iBin) + (Int_t)histoDen->GetBinContent(iBin), efficiency, efficiencyError, kFALSE);
493
494         currHisto->SetBinContent(iBinBoard, efficiency);
495         currHisto->SetBinError(iBinBoard, efficiencyError);
496       }
497     }
498   }
499 }
500
501
502 //_____________________________________________________________________________
503 void AliMUONTriggerEfficiencyCells::CalculateEfficiency(Int_t trigger44, Int_t trigger34,
504                                                         Float_t &efficiency, Float_t &error,
505                                                         Bool_t failuresAsInput)
506 {
507     //
508     /// Returns the efficiency.
509     //
510
511     efficiency=-9.;
512     error=0.;
513     if(trigger34>0){
514         efficiency=(Double_t)trigger44/((Double_t)trigger34);
515         if(failuresAsInput)efficiency=1.-(Double_t)trigger44/((Double_t)trigger34);
516     }
517     Double_t q = TMath::Abs(1-efficiency);
518     if(efficiency<0)error=0.0;
519     else error = TMath::Sqrt(efficiency*q/((Double_t)trigger34));
520 }
521
522
523 //_____________________________________________________________________________
524 void AliMUONTriggerEfficiencyCells::CheckFiredStrips()
525 {
526   //
527   /// Check for fired strips participating to efficiency
528   /// calculation (when available).
529   /// Strips inside a local board should be quite homogeneously hit
530   /// If not, this could be a problem of electronics (i.e. ADULT board off).
531   //
532
533   if(!fFiredStrips) {
534     AliWarning("List of fired pads not present. Check not performable.");
535     return;
536   }
537
538   GetListsForCheck();
539
540   TString histoName;
541
542   // Check fired pads (when available)
543   if(fFiredFitHistoList){
544     TH1F *histo1D = 0x0;
545     TF1 *fitFunc = 0x0;
546     TCanvas *histoFiredCan[20];
547     Int_t nEntries = fFiredFitHistoList->GetEntries();
548     for(Int_t iEntry=0; iEntry<nEntries; iEntry++){
549       histo1D = (TH1F*)fFiredFitHistoList->At(iEntry);
550       printf("Problems found in %s\n", histo1D->GetTitle());
551     }
552     Int_t nPrintCan = nEntries;
553     if(nPrintCan>20) {
554       AliWarning("Too many boards with problems: only 20 will be shown");
555       nPrintCan = 20;
556     }
557     for(Int_t iCan=0; iCan<nPrintCan; iCan++){
558       histo1D = (TH1F*)fFiredFitHistoList->At(iCan);
559       histoName = histo1D->GetName();
560       histoName.Append("Can");
561       histoFiredCan[iCan] = new TCanvas(histoName.Data(), histoName.Data(), 100+10*iCan, 10*iCan, 700, 700);
562       histoFiredCan[iCan]->SetRightMargin(0.14);
563       histoFiredCan[iCan]->SetLeftMargin(0.12);
564       histo1D->Draw("E");
565       fitFunc = histo1D->GetFunction("pol0");
566       fitFunc->SetLineColor(2);
567       fitFunc->Draw("same");
568     }
569     if(nEntries==0){
570       printf("\nAll local boards seem ok!!\n\n");
571     }
572   }
573 }
574
575
576 //_____________________________________________________________________________
577 void AliMUONTriggerEfficiencyCells::DisplayEfficiency(Bool_t perSlat)
578 {
579   //
580   /// Display calculated efficiency.
581   //
582
583   Bool_t isInitSlat = kFALSE, isInitBoard = kFALSE;
584   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
585     if(fBoardEfficiency[chCath]->GetEntries()>0) isInitBoard = kTRUE;
586     if(fSlatEfficiency[chCath]->GetEntries()>0) isInitSlat = kTRUE;
587   }
588
589   if(!isInitBoard){
590     AliWarning("Trigger efficiency not initialized per board.\nDisplay not yet implemented.");
591     return;
592   }
593   if(!isInitSlat && perSlat){
594     AliWarning("Trigger efficiency not initialized for slat.\nPlease try option kFALSE.");
595     return;
596   }
597   if ( !AliCDBManager::Instance()->GetDefaultStorage() ){
598     AliWarning("Please set default CDB storage (needed for mapping).");
599     return;
600   }
601   if ( AliCDBManager::Instance()->GetRun() < 0 ){
602     AliWarning("Please set CDB run number (needed for mapping).");
603     return;
604   }
605   
606   GetListsForCheck();
607
608   //const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
609
610   TH2F *histo = 0x0;
611   TString histoName, histoTitle;
612
613   // Plot fired strips (when available)
614   if(fFiredDisplayHistoList){
615     TCanvas *displayFiredCan[fgkNplanes];
616     for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
617       histo = (TH2F*)fFiredDisplayHistoList->At(chCath);
618       histoName = Form("%sCan", histo->GetName());
619       histoTitle = Form("%s", histo->GetTitle());
620       displayFiredCan[chCath] = new TCanvas(histoName.Data(), histoTitle.Data(), 100+10*chCath, 10*chCath, 700, 700);
621       displayFiredCan[chCath]->SetRightMargin(0.14);
622       displayFiredCan[chCath]->SetLeftMargin(0.12);
623       histo->GetYaxis()->SetTitleOffset(1.4);
624       histo->SetStats(kFALSE);
625       histo->Draw("COLZ");
626     }
627   }
628
629   // Plot efficiency
630   if(fDisplayHistoList){
631     TCanvas *can[fgkNplanes];
632     for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
633       Int_t currChCath = chCath;
634       if(perSlat==kTRUE) currChCath += fgkNplanes;
635       histo = (TH2F*)fDisplayHistoList->At(currChCath);
636       histoName = Form("%sCan", histo->GetName());
637       histoTitle = Form("%s", histo->GetTitle());
638       can[chCath] = new TCanvas(histoName.Data(), histoTitle.Data(), 100+10*chCath, 10*chCath, 700, 700);
639       can[chCath]->SetRightMargin(0.14);
640       can[chCath]->SetLeftMargin(0.12);
641       histo->GetZaxis()->SetRangeUser(0.,1.);
642       histo->GetYaxis()->SetTitleOffset(1.4);
643       histo->SetStats(kFALSE);
644       histo->Draw("COLZ");
645       if(perSlat==kTRUE) continue;
646       histo = (TH2F*)fBoardLabelList->At(currChCath);
647       histo->Draw("textsame");
648     }
649   }
650 }
651
652
653 //__________________________________________________________________________
654 Bool_t AliMUONTriggerEfficiencyCells::GetListsForCheck()
655 {
656   //
657   /// Getting histograms for efficiency, 
658   /// map of fired strips entering efficiency calculations,
659   /// fits for checking switched-off elements in chambers.
660   //
661   const Float_t kChi2RedMax = 1.5;
662   const Float_t kDummyFired = 1e-5;
663
664   Reset(kFALSE);
665
666   fDisplayHistoList = new TList();
667   fDisplayHistoList->SetOwner();
668   fBoardLabelList = new TList();
669   fBoardLabelList->SetOwner();
670   if ( fFiredStrips ){
671     fFiredFitHistoList = new TList();
672     fFiredFitHistoList->SetOwner();
673     fFiredDisplayHistoList = new TList();
674     fFiredDisplayHistoList->SetOwner();
675   }
676
677   TH3F* padFired = 0x0;
678   TH2F* displayHisto = 0x0;
679   TH1F* histoFired[fgkNplanes][234];
680   TF1* fitFunc = 0x0;
681   Bool_t isStripOffInBoard[fgkNplanes][234];
682   Int_t bin=0;
683   TString histoName, histoTitle;
684   TString cathName[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
685
686   AliMUONTriggerDisplay triggerDisplay;
687   // Book histos
688   for(Int_t iCath=0; iCath<fgkNcathodes; iCath++){
689     if(fFiredStrips) padFired = (TH3F*)fFiredStrips->At(iCath);
690     for(Int_t iCh=0; iCh<fgkNchambers; iCh++){
691       Int_t chCath = GetPlane(iCh, iCath);
692       Int_t currCh = 11 + iCh;
693       histoName = Form("%sChamber%i", cathName[iCath].Data(), currCh);
694       histoTitle = Form("Chamber %i: efficiency %s", currCh, cathName[iCath].Data());
695       displayHisto = 
696         (TH2F*)triggerDisplay.GetDisplayHistogram(fBoardEfficiency[chCath], histoName,
697                                                   AliMUONTriggerDisplay::kDisplayBoards,
698                                                   iCath,currCh,histoTitle,
699                                                   AliMUONTriggerDisplay::kShowZeroes);
700       fDisplayHistoList->Add(displayHisto);
701
702       histoName = Form("labels%sChamber%i", cathName[iCath].Data(), currCh);
703       displayHisto = 
704         (TH2F*)triggerDisplay.GetBoardNumberHisto(histoName,currCh);
705       fBoardLabelList->Add(displayHisto);
706
707       if(!fFiredStrips) continue;
708       histoName = Form("firedPads%sChamber%i", cathName[iCath].Data(), currCh);
709       histoTitle = Form("Chamber %i: Fired pads %s", currCh, cathName[iCath].Data());
710       bin = padFired->GetXaxis()->FindBin(currCh);
711       padFired->GetXaxis()->SetRange(bin,bin);
712       displayHisto = 
713         (TH2F*)triggerDisplay.GetDisplayHistogram(padFired->Project3D("zy"),histoName,
714                                                   AliMUONTriggerDisplay::kDisplayStrips,
715                                                   iCath,currCh,histoTitle);
716       fFiredDisplayHistoList->Add(displayHisto);
717       
718       for(Int_t ib=0; ib<AliMpConstants::NofLocalBoards(); ib++){
719         histoName = Form("%sChamber%iBoard%i", cathName[iCath].Data(), currCh, ib+1);
720         histoTitle = Form("Chamber %i: fired pads %s board = %i", currCh, cathName[iCath].Data(), ib+1);
721         histoFired[chCath][ib] = new TH1F(histoName.Data(), histoTitle.Data(), 16, -0.5, 15.5);
722         histoFired[chCath][ib]->SetXTitle("board");
723         isStripOffInBoard[chCath][ib] = kFALSE;
724       } // loop on board
725     } // loop on chamber
726   } // loop on cathode
727
728   for(Int_t iCath=0; iCath<fgkNcathodes; iCath++){
729     for(Int_t iCh=0; iCh<fgkNchambers; iCh++){
730       Int_t chCath = GetPlane(iCh, iCath);
731       Int_t currCh = 11+iCh;
732       histoName = Form("%sChamber%iSlatEff", cathName[iCath].Data(), currCh);
733       histoTitle = Form("Chamber %i: efficiency %s per slat", currCh, cathName[iCath].Data());
734       displayHisto = 
735         (TH2F*)triggerDisplay.GetDisplayHistogram(fSlatEfficiency[chCath], histoName,
736                                                   AliMUONTriggerDisplay::kDisplaySlats,
737                                                   iCath,currCh,histoTitle);
738       fDisplayHistoList->Add(displayHisto);
739     }
740   }
741
742   if(!fFiredStrips) return kTRUE;
743
744   AliMpCDB::LoadDDLStore();
745
746   // Check fired pads (when available)
747   for(Int_t iLoc = 0; iLoc < AliMpConstants::NofLocalBoards(); iLoc++) {  
748     Int_t iBoard = iLoc+1;
749     for(Int_t iCh=0; iCh<AliMpConstants::NofChambers(); iCh++){
750       Int_t iChamber = iCh + AliMpConstants::NofTrackingChambers();
751
752       Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(iBoard, iChamber);
753
754       if (!detElemId) continue;
755
756       AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(iBoard, kFALSE);
757
758       // skip copy cards
759       if( !localBoard->IsNotified()) 
760         continue;
761       
762       for(Int_t iCath=0; iCath<AliMpConstants::NofCathodes(); iCath++){
763         Int_t chCath = GetPlane(iCh, iCath);
764         // loop over strips
765         const AliMpVSegmentation* seg = 
766           AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(iCath));
767         Int_t nStrips=0;
768         for (Int_t iStrip = 0; iStrip < 16; ++iStrip) {
769           AliMpPad pad = seg->PadByLocation(iBoard,iStrip,kFALSE);
770           if (!pad.IsValid()) continue;
771           nStrips++;
772           padFired = (TH3F*)fFiredStrips->At(iCath);
773           Float_t nFired = padFired->GetBinContent(11+iCh, iBoard, iStrip);
774           if(nFired==0.) nFired = kDummyFired;
775           histoFired[chCath][iLoc]->Fill(iStrip, nFired);
776         }
777
778         histoFired[chCath][iLoc]->Fit("pol0","Q0R","",0., (Float_t)nStrips-1.);
779         fitFunc = histoFired[chCath][iLoc]->GetFunction("pol0");
780         Float_t chi2 = fitFunc->GetChisquare();
781         Float_t ndf = (Float_t)fitFunc->GetNDF();
782         Float_t reducedChi2 = chi2/ndf;
783         if(reducedChi2>kChi2RedMax) {
784           isStripOffInBoard[chCath][iLoc] = kTRUE;
785           fFiredFitHistoList->Add(histoFired[chCath][iLoc]);
786         }
787       } // loop on cathodes
788     } // loop on chambers
789   } // loop on local boards 
790
791   return kTRUE;
792 }
793
794 //__________________________________________________________________________
795 Bool_t AliMUONTriggerEfficiencyCells::SumRunEfficiency(const AliMUONTriggerEfficiencyCells &other)
796 {
797 ///  Sums results from different runs and gives the efficiency
798   if(!fCountHistoList || !fNoCountHistoList) {
799     AliWarning("Histograms for efficiency calculations not implemented in object");
800     return kFALSE;
801   }
802   if(!other.fCountHistoList || !other.fNoCountHistoList) {
803     AliWarning("Histograms for efficiency calculations not implemented in object passed as argument");
804     return kFALSE;
805   }
806
807   Int_t nentries = fCountHistoList->GetEntries();
808   TH1F *currNum = 0x0, *currDen = 0x0, *otherNum = 0x0, *otherDen = 0x0;
809
810   for(Int_t iEntry=0; iEntry<nentries; iEntry++){
811     currNum = (TH1F*)fCountHistoList->At(iEntry);
812     currDen = (TH1F*)fNoCountHistoList->At(iEntry);
813     otherNum = (TH1F*)other.fCountHistoList->At(iEntry);
814     otherDen = (TH1F*)other.fNoCountHistoList->At(iEntry);
815     currNum->Add(otherNum);
816     currDen->Add(otherDen);
817   }
818
819   FillHistosFromList();
820
821   if(!fFiredStrips) {
822     AliWarning("Histograms for fired region check not implemented in object");
823     return kFALSE;
824   }
825   if(!other.fFiredStrips) {
826     AliWarning("Histograms for fired region check not implemented in object passed as argument");
827     return kFALSE;
828   }
829   
830   TH3F *currFired = 0x0, *otherFired = 0x0;
831   nentries = fFiredStrips->GetEntries();
832   for(Int_t iEntry=0; iEntry<nentries; iEntry++){
833     currFired  = (TH3F*)fFiredStrips->At(iEntry);
834     otherFired = (TH3F*)fFiredStrips->At(iEntry);
835     currFired->Add(otherFired);
836   }
837     
838   return kTRUE;
839 }
840
841
842 //__________________________________________________________________________
843 Bool_t AliMUONTriggerEfficiencyCells::LowStatisticsSettings(Bool_t useMeanValues)
844 {
845   //
846   /// In case of low statistics, fill the local board efficiency with
847   /// the average value of the RPC
848   //
849
850   if ( ! fCountHistoList ){
851     AliWarning("Cannot find histograms for RPC efficiency calculation. Nothing done!");
852     return kFALSE;
853   }
854   if ( !AliCDBManager::Instance()->GetDefaultStorage() ){
855     AliWarning("Please set default CDB storage (needed for mapping).");
856     return kFALSE;
857   }
858   if ( AliCDBManager::Instance()->GetRun() < 0 ){
859     AliWarning("Please set CDB run number (needed for mapping).");
860     return kFALSE;
861   }
862
863   AliMpCDB::LoadDDLStore();
864   
865   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
866     fBoardEfficiency[chCath]->Reset();
867     fSlatEfficiency[chCath]->Reset();
868   }
869
870   FillHistosFromList(useMeanValues);
871
872   return kTRUE;
873 }