]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerEfficiencyCells.cxx
Modifications to reflect latest changes in MUONTRGda
[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 #include "AliMUONTriggerEfficiencyCells.h"
17 #include "AliMpConstants.h"
18
19 // Classes for display
20 #include "AliMUONGeometryTransformer.h"
21 #include "AliMpCDB.h"
22 #include "AliMpDDLStore.h"
23 #include "AliMpDDL.h"
24 #include "AliMpTriggerCrate.h"
25 #include "AliMpLocalBoard.h"
26 #include "AliMpPad.h"
27 #include "AliMpVSegmentation.h"
28 #include "AliMpSegmentation.h"
29
30 #include "AliLog.h"
31
32 #include "TRandom.h"
33 #include "Riostream.h"
34 #include "TSystem.h"
35 #include "TFile.h"
36 #include "TH1F.h"
37 #include "TMath.h"
38
39 #include "TH2F.h"
40 #include "TH3F.h"
41 #include "TF1.h"
42 #include "TStyle.h"
43 #include "TPaveLabel.h"
44 #include "TCanvas.h"
45
46 #include <fstream>
47 #include <cassert>
48
49 //-----------------------------------------------------------------------------
50 /// \class AliMUONTriggerEfficiencyCells
51 /// A class to store and give access to the trigger chamber efficiency.
52 ///
53 /// Efficiency is stored per cathode on local boards, or, alternatively,
54 /// on "cells" of a given size.
55 ///
56 /// The main method of this class is IsTriggered().
57 ///
58 /// $ALICE_ROOT/MUON/data/TriggerChamberefficiencyCells.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 /// Otherwise, he efficiency cells goes from right to left and 
65 /// from bottom to top of the chamber, namely, the efficiencies tabulated in the 
66 /// file refers to the following reference frame:
67 ///
68 /// <pre>
69 /// x
70 /// <----------------------------------|
71 ///                                    |
72 ///    ---------------------------     |
73 ///   | 0.97 | 0.97 | 0.97 | 0.97 |    |
74 ///    ---------------------------     |
75 ///   | 0.97 | 0.97 | 0.97 | 0.97 |    |
76 ///    ---------------------------     |
77 ///   | 0.97 | 0.97 | 0.97 | 0.97 |    |
78 ///    ---------------------------     |
79 ///                                    |
80 ///                                   \/ y
81 /// </pre>
82 ///
83 ///  In both cases, the file can be edited in order to change efficiency
84 ///  in a chosen local board/region of the chamber.
85 ///
86 ///
87 /// But please note that this object is also available from the CDB 
88 /// (generated using the MUONCDB.C macro)
89 ///
90 /// \author Diego Stocco; INFN Torino
91 //-----------------------------------------------------------------------------
92
93 /// \cond CLASSIMP
94 ClassImp(AliMUONTriggerEfficiencyCells)
95 /// \endcond
96
97 //__________________________________________________________________________
98 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
99 :
100 TObject(),
101 fCountHistoList(0x0),
102 fNoCountHistoList(0x0),
103 fFiredStrips(0x0),
104 fDisplayHistoList(0x0),
105 fBoardLabelList(0x0),
106 fFiredFitHistoList(0x0),
107 fFiredDisplayHistoList(0x0)
108 {
109 ///  Default constructor.
110   CheckConstants();
111   Reset();
112   InitHistos();
113 }
114
115 //__________________________________________________________________________
116 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const Char_t* filename)
117 :
118 TObject(),
119 fCountHistoList(0x0),
120 fNoCountHistoList(0x0),
121 fFiredStrips(0x0),
122 fDisplayHistoList(0x0),
123 fBoardLabelList(0x0),
124 fFiredFitHistoList(0x0),
125 fFiredDisplayHistoList(0x0)
126 {
127 ///  Constructor using an ASCII file.
128   CheckConstants();
129   Reset();
130   ReadFile(filename);
131 }
132
133 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(TList *countHistoList,
134                                                              TList *noCountHistoList)
135 :
136 TObject(),
137 fCountHistoList(countHistoList),
138 fNoCountHistoList(noCountHistoList),
139 fFiredStrips(0x0),
140 fDisplayHistoList(0x0),
141 fBoardLabelList(0x0),
142 fFiredFitHistoList(0x0),
143 fFiredDisplayHistoList(0x0)
144 {
145 ///  Constructor using an ASCII file.
146   CheckConstants();
147   Reset();
148   InitHistos();
149   FillHistosFromList();
150 }
151
152 //_____________________________________________________________________________
153 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const AliMUONTriggerEfficiencyCells& other)
154 :
155 TObject(other),
156 fCountHistoList(other.fCountHistoList),
157 fNoCountHistoList(other.fNoCountHistoList),
158 fFiredStrips(other.fFiredStrips),
159 fDisplayHistoList(other.fDisplayHistoList),
160 fBoardLabelList(other.fBoardLabelList),
161 fFiredFitHistoList(other.fFiredFitHistoList),
162 fFiredDisplayHistoList(other.fFiredDisplayHistoList)
163 {
164 /// Copy constructor
165
166   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
167     for(Int_t slat=0; slat<fgkNslats; slat++){
168       fCellContent[chCath][slat] = other.fCellContent[chCath][slat];
169     }
170     fCellSize[chCath] = other.fCellSize[chCath];
171     fCellNumber[chCath] = other.fCellNumber[chCath];
172     fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
173     fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
174   }
175 }
176
177 //_____________________________________________________________________________
178 AliMUONTriggerEfficiencyCells& AliMUONTriggerEfficiencyCells::operator=(const AliMUONTriggerEfficiencyCells& other)
179 {
180   /// Asignment operator
181   // check assignement to self
182   if (this == &other)
183     return *this;
184
185   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
186     for(Int_t slat=0; slat<fgkNslats; slat++){
187       fCellContent[chCath][slat] = other.fCellContent[chCath][slat];
188     }
189     fCellSize[chCath] = other.fCellSize[chCath];
190     fCellNumber[chCath] = other.fCellNumber[chCath];
191     fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
192     fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
193   }
194
195   fCountHistoList = other.fCountHistoList;
196   fNoCountHistoList = other.fNoCountHistoList;
197   fFiredStrips = other.fFiredStrips;
198
199   fDisplayHistoList = other.fDisplayHistoList;
200   fBoardLabelList = other.fBoardLabelList;
201   fFiredFitHistoList = other.fFiredFitHistoList;
202   fFiredDisplayHistoList = other.fFiredDisplayHistoList;
203     
204   return *this;
205 }
206
207 //__________________________________________________________________________
208 AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
209 {
210 ///  Destructor.
211 }
212
213
214 //__________________________________________________________________________
215 void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Float_t x, Float_t y, Float_t &eff1, Float_t &eff2) const
216 {
217 ///  Get the efficiencies of the 2 cathodes at a given location (x,y)
218
219   Int_t chamber = FindChamberIndex(detElemId);
220   Int_t slat = FindSlatIndex(detElemId);
221   TArrayI cell = CellByCoord(detElemId,x,y);
222   eff1 = 0.0;
223   eff2 = 0.0;
224   if(cell.At(0)>=0 && cell.At(1)>=0)
225   {
226     eff1 = fCellContent[chamber][slat][cell.At(0)][cell.At(1)];
227     eff2 = fCellContent[fgkNchambers+chamber][slat][cell.At(0)][cell.At(1)];
228   }
229 }
230
231
232 //__________________________________________________________________________
233 void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t localBoard, Float_t &eff1, Float_t &eff2) const
234 {
235 ///  Get the efficiencies of the 2 cathodes at a given local board
236
237   Int_t chamber = FindChamberIndex(detElemId);
238   Int_t bin = fBoardEfficiency[chamber]->FindBin(localBoard);
239   eff1 = fBoardEfficiency[chamber]->GetBinContent(bin);
240   eff2 = fBoardEfficiency[fgkNchambers+chamber]->GetBinContent(bin);
241 }
242
243
244 //__________________________________________________________________________
245 void 
246 AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Float_t x, Float_t y, Bool_t &trig1, Bool_t &trig2) const
247 {
248 ///  Whether or not a given location (x,y) has a chance to trig, on each cathode.
249
250   Float_t eff1 = 0.0;
251   Float_t eff2 = 0.0;
252   GetCellEfficiency(detElemId, x, y, eff1, eff2);
253   trig1 = kTRUE; 
254   trig2 = kTRUE;
255   if(gRandom->Rndm()>eff1)trig1 = kFALSE;
256   if(gRandom->Rndm()>eff2)trig2 = kFALSE;
257 }
258
259
260 //__________________________________________________________________________
261 void 
262 AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t localBoard, Bool_t &trig1, Bool_t &trig2) const
263 {
264 ///  Whether or not a given local board has a chance to trig, on each cathode.
265
266   Float_t eff1 = 0.0;
267   Float_t eff2 = 0.0;
268   GetCellEfficiency(detElemId, localBoard, eff1, eff2);
269   trig1 = kTRUE; 
270   trig2 = kTRUE;
271   if(gRandom->Rndm()>eff1)trig1 = kFALSE;
272   if(gRandom->Rndm()>eff2)trig2 = kFALSE;
273 }
274
275 //__________________________________________________________________________
276 TArrayI AliMUONTriggerEfficiencyCells::CellByCoord(Int_t detElemId, Float_t x, Float_t y) const
277 {
278 ///  Get the efficiencies at a given location.
279
280   Int_t chamber = FindChamberIndex(detElemId);
281   Int_t slat = FindSlatIndex(detElemId);
282   Int_t cell[fgkNcathodes]={-1,-1};
283   Float_t maxX = fCellSize[chamber][slat]*((Float_t)fCellNumber[chamber][slat]);
284   Float_t maxY = fCellSize[fgkNchambers+chamber][slat]*((Float_t)fCellNumber[fgkNchambers+chamber][slat]);
285   if(x>=0 & x<maxX & y>=0 & y<maxY)
286   {
287     cell[0] = (Int_t)(x/fCellSize[chamber][slat]);
288     cell[1] = (Int_t)(y/fCellSize[fgkNchambers+chamber][slat]);
289   }
290   return TArrayI(fgkNcathodes,cell);
291 }
292
293 //__________________________________________________________________________
294 void AliMUONTriggerEfficiencyCells::ReadFile(const Char_t* filename)
295 {
296 ///  Reads a file containing the efficiency map.
297
298   TString fileName = gSystem->ExpandPathName(filename);
299   if(fileName.EndsWith(".root")){
300       ReadHistoBoards(fileName.Data());
301       return;
302   }
303
304   InitHistos();
305   ifstream file(fileName.Data());
306   Char_t dat[50];
307   if (file.good()){
308       file >> dat;
309       if(!strcmp(dat,"localBoards"))ReadFileBoards(file);
310       else ReadFileXY(file);
311       file.close();
312   } else {
313       AliWarning(Form("Can't read file %s",fileName.Data()));
314   }
315 }
316
317
318 //__________________________________________________________________________
319 void AliMUONTriggerEfficiencyCells::ReadFileXY(ifstream &file)
320 {
321 ///  Structure of file (.dat) containing geometrical efficency
322     Int_t datInt=0, detEl=0, chamber=0, rpc=0, chCath=0;
323     Float_t datFloat=0.0;
324     Char_t dat[50];
325
326     while (file >> dat) {
327         file >> detEl;
328         chamber = FindChamberIndex(detEl);
329         rpc = FindSlatIndex(detEl);
330         file >> dat;
331         for(Int_t i=0; i<fgkNcathodes; i++){
332             chCath = fgkNchambers*i + chamber;
333             file >> datInt;
334             fCellNumber[chCath][rpc] = datInt;
335             file >> dat;
336         }
337         for(Int_t i=0; i<fgkNcathodes; i++){
338             chCath = fgkNchambers*i + chamber;
339             file >> datFloat;
340             fCellSize[chCath][rpc] = datFloat;
341             if(i==0)file >> dat;
342         }
343         for(Int_t cath=0; cath<fgkNcathodes; cath++){
344             chCath = fgkNchambers*cath + chamber;
345             file >> dat;
346             file >> datInt;
347             for(Int_t iy=0; iy<fCellNumber[fgkNchambers+chamber][rpc]; iy++){
348                 for(Int_t ix=0; ix<fCellNumber[chamber][rpc]; ix++){
349                     file >> datFloat;
350                     fCellContent[chCath][rpc][ix][iy] = datFloat;
351                 }
352             }
353         }
354     }
355 }
356
357 //__________________________________________________________________________
358 void AliMUONTriggerEfficiencyCells::ReadFileBoards(ifstream &file)
359 {
360 ///  Structure of file (.dat) containing local board efficency
361   Int_t datInt=0, detEl=0, chamber=0, chCath=0, bin=0;
362     Float_t datFloat=0.0;
363     Char_t dat[50];
364
365     while (file >> dat) {
366             file >> detEl;
367             chamber = FindChamberIndex(detEl);
368             //rpc = FindSlatIndex(detEl);
369             for(Int_t cath=0; cath<fgkNcathodes; cath++){
370                 chCath = fgkNchambers*cath + chamber;
371                 file >> dat;
372                 file >> datInt;
373                 for(Int_t board=1; board<=AliMpConstants::NofLocalBoards(); board++){
374                     file >> datFloat;
375                     bin = fBoardEfficiency[chCath]->FindBin(board);
376                     fBoardEfficiency[chCath]->SetBinContent(bin, datFloat);
377                 }
378             }
379     }
380 }
381
382
383 //__________________________________________________________________________
384 void AliMUONTriggerEfficiencyCells::ReadHistoBoards(const Char_t *filename)
385 {
386 ///  Structure of file (.root) containing local board efficency
387     TFile *file = new TFile(filename, "read");
388     if(!file) {
389         AliWarning(Form("Can't read file %s",filename));
390         return;
391     }
392     Char_t histoName[30];
393     Char_t *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
394
395     for(Int_t ch=0; ch<fgkNchambers; ch++){
396         for(Int_t cath=0; cath<fgkNcathodes; cath++){
397             sprintf(histoName, "%sBoardEffChamber%i", cathCode[cath], 11+ch);
398             if(!(TH1F *)file->Get(histoName)) {
399                 AliWarning(Form("Can't find histo %s in file %s",histoName, filename));
400                 continue;
401             }
402             Int_t chCath = fgkNchambers*cath + ch;
403             fBoardEfficiency[chCath] = (TH1F *)file->Get(histoName);
404         }
405     }
406 }
407
408
409 //_____________________________________________________________________________
410 void AliMUONTriggerEfficiencyCells::CheckConstants() const
411 {
412 /// Check consistence of redefined constants 
413
414   assert(fgkNcathodes == AliMpConstants::NofCathodes());    
415   assert(fgkNchambers == AliMpConstants::NofTriggerChambers());    
416   assert(fgkNplanes == AliMpConstants::NofTriggerChambers() * fgkNcathodes);    
417 }
418
419
420 //__________________________________________________________________________
421 Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId) const
422 {
423 ///  From detElemId to chamber number
424
425   // Int_t iChamber = AliMpDEManager::GetChamberId(detElemId);
426   Int_t iChamber = detElemId/100 - 1;
427   Int_t chamber = iChamber-AliMpConstants::NofTrackingChambers();
428   return chamber;
429 }
430
431
432 //__________________________________________________________________________
433 Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId) const
434 {
435 ///  From detElemId to slat index.
436   Int_t slat = detElemId%100;
437   return slat;
438 }
439
440
441 //__________________________________________________________________________
442 TVector2 AliMUONTriggerEfficiencyCells::ChangeReferenceFrame(Float_t x, Float_t y, Float_t x0, Float_t y0)
443 {
444 /// (x0,y0) position of the local reference frame (center of the chamber)
445
446     Float_t x1 = x0-x;//reflection of axis
447     Float_t y1 = y+y0;
448     return TVector2(x1,y1);
449 }
450
451 //__________________________________________________________________________
452 void
453 AliMUONTriggerEfficiencyCells::Reset()
454 {
455 ///  Sets our internal array contents to zero.
456
457     for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
458         fCellSize[chCath].Set(fgkNslats);
459         fCellNumber[chCath].Set(fgkNslats);
460         for(Int_t slat=0; slat<fgkNslats; slat++){
461             fCellContent[chCath][slat].ResizeTo(fgkNcells,fgkNcells);
462         }
463     }
464
465     for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
466         fCellSize[chCath].Reset();
467         fCellNumber[chCath].Reset();
468         for(Int_t slat=0; slat<fgkNslats; slat++){
469             fCellContent[chCath][slat].Zero();
470         }
471     }
472
473     for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
474       fBoardEfficiency[chCath] = 0x0;
475       fSlatEfficiency[chCath] = 0x0;
476     }
477 }
478
479
480 //__________________________________________________________________________
481 void
482 AliMUONTriggerEfficiencyCells::InitHistos()
483 {
484 ///  Sets our internal array contents to zero.
485
486   const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
487   Int_t chCath=0;
488   Char_t histoName[40];
489
490   Char_t *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
491
492   for(Int_t ch=0; ch<fgkNchambers; ch++){
493     for(Int_t cath=0; cath<fgkNcathodes; cath++){
494       chCath = fgkNchambers*cath + ch;
495       sprintf(histoName, "%sBoardEffChamber%i", cathCode[cath], 11+ch);
496       fBoardEfficiency[chCath] = new TH1F(histoName, histoName, kNumOfBoards, 1-0.5, kNumOfBoards+1.-0.5);
497       sprintf(histoName, "%sSlatEffChamber%i", cathCode[cath], 11+ch);
498       fSlatEfficiency[chCath] = new TH1F(histoName, histoName, fgkNslats, 0-0.5, fgkNslats-0.5);
499     }
500   }
501 }
502
503
504 //__________________________________________________________________________
505 void
506 AliMUONTriggerEfficiencyCells::FillHistosFromList()
507 {
508 ///  Fills internal histos from list.
509
510   Int_t nHistoBins=0;
511   TH1F *histoNum = 0x0, *histoDen=0x0, *currHisto = 0x0;
512   TString slatName = "Slat", boardName = "Board", histoName;
513   Int_t iHistoBoard = -1, iHistoSlat = -1;
514   Float_t efficiency, efficiencyError;
515
516   Int_t nentries = fCountHistoList->GetEntries();
517
518   for(Int_t iEntry=0; iEntry<nentries; iEntry++){
519     histoNum = (TH1F*)fCountHistoList->At(iEntry);
520     histoDen = (TH1F*)fNoCountHistoList->At(iEntry);
521
522     if(!histoNum) {
523       AliWarning("Histogram not found in fCountHistoList. Skip to next");
524       continue;
525     }
526     if(!histoDen) {
527       AliWarning("Histogram not found in fNoCountHistoList. Skip to next");
528       continue;
529     }
530
531     histoName = histoNum->GetName();
532     nHistoBins = histoNum->GetNbinsX();
533
534     if(histoName.Contains(boardName)){
535       iHistoBoard++;
536       currHisto = fBoardEfficiency[iHistoBoard];
537     }
538     else if(histoName.Contains(slatName)){
539       iHistoSlat++;
540       currHisto = fSlatEfficiency[iHistoSlat];
541     }
542     else continue;
543
544     for(Int_t iBin=1; iBin<=nHistoBins; iBin++){
545       CalculateEfficiency((Int_t)histoNum->GetBinContent(iBin), (Int_t)histoNum->GetBinContent(iBin) + (Int_t)histoDen->GetBinContent(iBin), efficiency, efficiencyError, kFALSE);
546
547       currHisto->SetBinContent(iBin, efficiency);
548       currHisto->SetBinError(iBin, efficiencyError);
549     }
550   }
551 }
552
553
554
555 //_____________________________________________________________________________
556 void AliMUONTriggerEfficiencyCells::CalculateEfficiency(Int_t trigger44, Int_t trigger34,
557                                                         Float_t &efficiency, Float_t &error,
558                                                         Bool_t failuresAsInput)
559 {
560     //
561     /// Returns the efficiency.
562     //
563
564     efficiency=-9.;
565     error=0.;
566     if(trigger34>0){
567         efficiency=(Double_t)trigger44/((Double_t)trigger34);
568         if(failuresAsInput)efficiency=1.-(Double_t)trigger44/((Double_t)trigger34);
569     }
570     Double_t q = TMath::Abs(1-efficiency);
571     if(efficiency<0)error=0.0;
572     else error = TMath::Sqrt(efficiency*q/((Double_t)trigger34));
573 }
574
575
576 //_____________________________________________________________________________
577 void AliMUONTriggerEfficiencyCells::CheckFiredStrips(const Char_t* geoFilename)
578 {
579   //
580   /// Check for fired strips participating to efficiency
581   /// calculation (when available).
582   /// Strips inside a local board should be quite homogeneously hit
583   /// If not, this could be a problem of electronics (i.e. ADULT board off).
584   //
585
586   if(!fFiredStrips) {
587     AliWarning("List of fired pads not present. Check not performable.");
588     return;
589   }
590
591   GetListsForCheck(geoFilename);
592
593   Char_t histoName[40], histoTitle[90];
594
595   // Check fired pads (when available)
596   if(fFiredFitHistoList){
597     TH1F *histo1D = 0x0;
598     TF1 *fitFunc = 0x0;
599     TCanvas *histoFiredCan[20];
600     Int_t nEntries = fFiredFitHistoList->GetEntries();
601     for(Int_t iEntry=0; iEntry<nEntries; iEntry++){
602       histo1D = (TH1F*)fFiredFitHistoList->At(iEntry);
603       printf("Problems found in %s\n", histo1D->GetTitle());
604     }
605     Int_t nPrintCan = nEntries;
606     if(nPrintCan>20) {
607       AliWarning("Too many boards with problems: only 20 will be shown");
608       nPrintCan = 20;
609     }
610     for(Int_t iCan=0; iCan<nPrintCan; iCan++){
611       histo1D = (TH1F*)fFiredFitHistoList->At(iCan);
612       histoFiredCan[iCan] = new TCanvas(histoName, histoTitle, 100+10*iCan, 10*iCan, 700, 700);
613       histoFiredCan[iCan]->SetRightMargin(0.14);
614       histoFiredCan[iCan]->SetLeftMargin(0.12);
615       histo1D->Draw("E");
616       fitFunc = histo1D->GetFunction("pol0");
617       fitFunc->SetLineColor(2);
618       fitFunc->Draw("same");
619     }
620     if(nEntries==0){
621       printf("\nAll local boards seem ok!!\n\n");
622     }
623   }
624 }
625
626
627 //_____________________________________________________________________________
628 void AliMUONTriggerEfficiencyCells::DisplayEfficiency(Bool_t perSlat, const Char_t* geoFilename)
629 {
630   //
631   /// Display calculated efficiency.
632   //
633
634   Bool_t isInitSlat = kFALSE, isInitBoard = kFALSE;
635   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
636     if(fBoardEfficiency[chCath]->GetEntries()>0) isInitBoard = kTRUE;
637     if(fSlatEfficiency[chCath]->GetEntries()>0) isInitSlat = kTRUE;
638   }
639
640   if(!isInitBoard){
641     printf("Trigger efficiency not initialized per board.\nDisplay not yet implemented.\n");
642     return;
643   }
644   if(!isInitSlat && perSlat){
645     printf("Trigger efficiency not initialized for slat.\nPlease try option kFALSE.\n");
646     return;
647   }
648   
649   GetListsForCheck(geoFilename);
650
651   const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
652
653   TH2F *histo = 0x0;
654   Char_t histoName[40], histoTitle[90];
655   TPaveLabel *boardLabel = 0x0;
656
657   // Plot fired strips (when available)
658   if(fFiredDisplayHistoList){
659     TCanvas *displayFiredCan[fgkNplanes];
660     for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
661       histo = (TH2F*)fFiredDisplayHistoList->At(chCath);
662       sprintf(histoName, "%sCan", histo->GetName());
663       sprintf(histoTitle, "%s", histo->GetTitle());
664       displayFiredCan[chCath] = new TCanvas(histoName, histoTitle, 100+10*chCath, 10*chCath, 700, 700);
665       displayFiredCan[chCath]->SetRightMargin(0.14);
666       displayFiredCan[chCath]->SetLeftMargin(0.12);
667       histo->GetYaxis()->SetTitleOffset(1.4);
668       histo->SetStats(kFALSE);
669       histo->Draw("COLZ");
670       for (Int_t board = 0; board < kNumOfBoards; board++) {
671         Int_t currLabel = chCath * kNumOfBoards + board;
672         boardLabel = (TPaveLabel*)fBoardLabelList->At(currLabel);
673         boardLabel->Draw("same");
674       }
675     }
676   }
677
678   // Plot efficiency
679   if(fDisplayHistoList){
680     TCanvas *can[fgkNplanes];
681     for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
682       Int_t currChCath = chCath;
683       if(perSlat==kTRUE) currChCath += fgkNplanes;
684       histo = (TH2F*)fDisplayHistoList->At(currChCath);
685       sprintf(histoName, "%sCan", histo->GetName());
686       sprintf(histoTitle, "%s", histo->GetTitle());
687       can[chCath] = new TCanvas(histoName, histoTitle, 100+10*chCath, 10*chCath, 700, 700);
688       can[chCath]->SetRightMargin(0.14);
689       can[chCath]->SetLeftMargin(0.12);
690       histo->GetZaxis()->SetRangeUser(0.,1.);
691       histo->GetYaxis()->SetTitleOffset(1.4);
692       histo->SetStats(kFALSE);
693       histo->Draw("COLZ");
694       for (Int_t board = 0; board < kNumOfBoards; board++) {
695         Int_t currLabel = chCath * kNumOfBoards + board;
696         if(perSlat==kTRUE) currLabel += kNumOfBoards * fgkNplanes;
697         boardLabel = (TPaveLabel*)fBoardLabelList->At(currLabel);
698         boardLabel->Draw("same");
699       }
700     }
701   }
702 }
703
704
705 //__________________________________________________________________________
706 Bool_t AliMUONTriggerEfficiencyCells::GetListsForCheck(const Char_t* geoFilename)
707 {
708   //
709   /// Getting histograms for efficiency, 
710   /// map of fired strips entering efficiency calculations,
711   /// fits for checking switched-off elements in chambers.
712   //
713
714   const Int_t kNumOfBoards = AliMpConstants::NofLocalBoards();
715   const Float_t kChi2RedMax = 1.5;
716   const Float_t kDummyFired = 1e-5;
717
718   if(fDisplayHistoList || fBoardLabelList || fFiredFitHistoList || fFiredDisplayHistoList) return kTRUE;
719
720   if(!fDisplayHistoList) fDisplayHistoList = new TList();
721   if(!fBoardLabelList) fBoardLabelList = new TList(); 
722   if(!fFiredFitHistoList && fFiredStrips) fFiredFitHistoList = new TList();
723   if(!fFiredDisplayHistoList && fFiredStrips) fFiredDisplayHistoList = new TList();
724
725   AliMUONGeometryTransformer *transform = new AliMUONGeometryTransformer();
726   transform->LoadGeometryData(geoFilename);
727
728   if(!AliMpCDB::LoadDDLStore()) // Load DDL store from OCDB
729     AliFatal("Could not access mapping OCDB");
730
731   AliMpDDLStore *ddlStore = AliMpDDLStore::Instance();
732   Int_t line, slat;
733   Float_t xLocal1=0., yLocal1=0., xLocal2=0., yLocal2=0.;
734   Float_t xg1, yg1, zg1, xg2, yg2, zg2;
735   Float_t xWidth=0., yWidth=0.;
736   Float_t x1Label=0., x2Label=0., y1Label=0., y2Label=0.;
737   Float_t x1LabelSlat=0., x2LabelSlat=0., y1LabelSlat=0., y2LabelSlat=0.;
738   Int_t x1=0, y1=0, x2=0, y2=0, localId;
739
740   gStyle->SetPalette(1);
741
742   Char_t *cathCode[fgkNcathodes] = {"bendPlane", "nonBendPlane"};
743
744   Float_t boardsX = 280.00;  // cm
745   Float_t boardsY = 335.00;  // cm
746
747   // Check fired pads (when available)  
748   Int_t maxY[fgkNcathodes] = {64,1};
749   TH3F *padFired[fgkNplanes];
750   TH1F *histoFired[fgkNplanes][234];
751   TH2F *histoFiredDisplay[fgkNplanes];
752   TF1 *fitFunc = 0x0;
753   Bool_t isStripOffInBoard[fgkNplanes][234];
754
755   TH2F *histo[fgkNplanes];
756   TH2F *histoSlat[fgkNplanes];
757   TPaveLabel *boardLabel[fgkNplanes][234];
758   TPaveLabel *boardLabelSlat[fgkNplanes][234];
759   assert(kNumOfBoards==234);
760
761   Char_t histoName[40], histoTitle[90], labelTxt[5], labelSlatTxt[5];
762
763   Float_t efficiency, efficiencyError, efficiencySlat, efficiencySlatError;
764
765   // Book histos
766   for(Int_t cath=0; cath<fgkNcathodes; cath++){
767     padFired[cath] = 0x0;
768     if(fFiredStrips) padFired[cath] = (TH3F*)fFiredStrips->At(cath);
769     for(Int_t ch=0; ch<fgkNchambers; ch++){
770       Int_t chCath = fgkNchambers*cath + ch;
771       sprintf(histoName, "%sChamber%i", cathCode[cath], 11+ch);
772       sprintf(histoTitle, "Chamber %i: efficiency %s", 11+ch, cathCode[cath]);
773       histo[chCath] = new TH2F(histoName, histoTitle, (Int_t)boardsX, -boardsX, boardsX, (Int_t)boardsY, -boardsY, boardsY);
774       histo[chCath]->SetXTitle("X (cm)");
775       histo[chCath]->SetYTitle("Y (cm)");
776       fDisplayHistoList->Add(histo[chCath]);
777
778       if(!fFiredStrips) continue;
779       sprintf(histoName, "firedPads%sChamber%i", cathCode[cath], 11+ch);
780       sprintf(histoTitle, "Chamber %i: Fired pads %s", 11+ch, cathCode[cath]);
781       histoFiredDisplay[chCath] = new TH2F(histoName, histoTitle, (Int_t)boardsX, -boardsX, boardsX, (Int_t)boardsY, -boardsY, boardsY);
782       histoFiredDisplay[chCath]->SetXTitle("X (cm)");
783       histoFiredDisplay[chCath]->SetYTitle("Y (cm)");
784       fFiredDisplayHistoList->Add(histoFiredDisplay[chCath]);
785       
786       for(Int_t ib=0; ib<kNumOfBoards; ib++){
787         sprintf(histoName, "%sChamber%iBoard%i", cathCode[cath], 11+ch, ib+1);
788         sprintf(histoTitle, "Chamber %i: fired pads %s board = %i", 11+ch, cathCode[cath], ib+1);
789         histoFired[chCath][ib] = new TH1F(histoName, histoTitle, 16, -0.5, 15.5);
790         histoFired[chCath][ib]->SetXTitle("board");
791         isStripOffInBoard[chCath][ib] = kFALSE;
792       } // loop on board
793     } // loop on chamber
794   } // loop on cathode
795
796   for(Int_t cath=0; cath<fgkNcathodes; cath++){
797     for(Int_t ch=0; ch<fgkNchambers; ch++){
798       Int_t chCath = fgkNchambers*cath + ch;
799       sprintf(histoName, "%sChamber%iSlatEff", cathCode[cath], 11+ch);
800       sprintf(histoTitle, "Chamber %i: efficiency %s per slat", 11+ch, cathCode[cath]);
801       histoSlat[chCath] = new TH2F(histoName, histoTitle, (Int_t)boardsX, -boardsX, boardsX, (Int_t)boardsY, -boardsY, boardsY);
802       histoSlat[chCath]->SetXTitle("X (cm)");
803       histoSlat[chCath]->SetYTitle("Y (cm)");
804       fDisplayHistoList->Add(histoSlat[chCath]);
805     }
806   }
807
808   // loop over the trigger DDL (Right: 20, Left: 21)
809   for (Int_t iDDL = 20; iDDL <= 21; ++iDDL) {
810     AliMpDDL* ddl = ddlStore->GetDDL(iDDL);
811     Int_t nCrate = ddl->GetNofTriggerCrates();
812     // loop over the number of crates in DDL
813     for (Int_t index = 0; index < nCrate; ++index) {
814       // get crate object
815       AliMpTriggerCrate* crate = ddlStore->GetTriggerCrate(iDDL, index);
816       Int_t nLocal = crate->GetNofLocalBoards();
817       for (Int_t iLocal = 0; iLocal < nLocal; ++iLocal) {
818         // get local board Id from crate object
819         localId = crate->GetLocalBoardId(iLocal);
820         // get local board object
821         AliMpLocalBoard* localBoard = ddlStore->GetLocalBoard(localId);
822
823         if (!localBoard->IsNotified()) continue;
824
825         // get detection element connected to this board
826         for (Int_t ch = 0; ch < fgkNchambers; ++ch) {
827           Int_t iCh = ch + AliMpConstants::NofTrackingChambers();
828           Int_t detElemId = ddlStore->GetDEfromLocalBoard(localId, iCh);
829
830           if (!detElemId) continue;
831
832           // get segmentation
833           for (Int_t cath = 0; cath < fgkNcathodes; ++cath) {
834             const AliMpVSegmentation* seg = AliMpSegmentation::Instance()
835               ->GetMpSegmentation(detElemId,
836                                   AliMp::GetCathodType(cath));
837
838             Int_t chCath = fgkNchambers*cath + ch;
839             slat = detElemId%100;
840             Int_t nStrips=0;
841
842             // loop over strips
843             for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
844               // get pad from electronics
845               AliMpPad pad = seg->PadByLocation(AliMpIntPair(localId,
846                                                                ibitxy),kFALSE);
847                 
848               if (!pad.IsValid()) continue;
849               if(cath==0){ // Geometry info from bending plane only
850                 if(ibitxy==0) {
851                   xLocal1 = pad.Position().X();
852                   yLocal1 = pad.Position().Y();
853                   xWidth = pad.Dimensions().X();
854                   yWidth = pad.Dimensions().Y();
855                 }
856                 xLocal2 = pad.Position().X();
857                 yLocal2 = pad.Position().Y();
858               }
859               
860               // Check fired pads (when available)
861               if(padFired[cath]) {
862                 Int_t padX = pad.GetIndices().GetFirst();
863                 Int_t padY = pad.GetIndices().GetSecond();
864                 Int_t currPair = padX*maxY[cath] + padY;
865                 nStrips++;
866                 //printf("cath %i board = %i  (%2i, %2i) -> %i\n",
867                 //cath, localId, padX, padY, currPair);
868                 Int_t chBin = padFired[cath]->GetXaxis()->FindBin(ch);
869                 Int_t slatBin = padFired[cath]->GetYaxis()->FindBin(slat);
870                 Int_t pairBin = padFired[cath]->GetZaxis()->FindBin(currPair);
871                 Float_t nFired = padFired[cath]->GetBinContent(chBin, slatBin, pairBin);;
872
873                 Float_t dimX = pad.Dimensions().X();
874                 Float_t dimY = pad.Dimensions().Y();
875
876                 Float_t stripX1 = pad.Position().X();
877                 Float_t stripY1 = pad.Position().Y();
878                 Float_t stripX2 = pad.Position().X();
879                 Float_t stripY2 = pad.Position().Y();
880
881                 transform->Local2Global(detElemId, stripX1, stripY1, 0, xg1, yg1, zg1);
882                 transform->Local2Global(detElemId, stripX2, stripY2, 0, xg2, yg2, zg2);
883
884                 Float_t x1Float = TMath::Min(xg1,xg2) - dimX;
885                 Float_t y1Float = TMath::Min(yg1,yg2) - dimY;
886                 Float_t x2Float = TMath::Max(xg1,xg2) + dimX;
887                 Float_t y2Float = TMath::Max(yg1,yg2) + dimY;  
888
889                 Int_t x1Int = histoFiredDisplay[chCath]->GetXaxis()->FindBin(x1Float)+1;
890                 Int_t y1Int = histoFiredDisplay[chCath]->GetYaxis()->FindBin(y1Float)+1;
891                 Int_t x2Int = histoFiredDisplay[chCath]->GetXaxis()->FindBin(x2Float)-1;
892                 Int_t y2Int = histoFiredDisplay[chCath]->GetYaxis()->FindBin(y2Float)-1;
893
894                 for(Int_t binX=x1Int; binX<=x2Int; binX++){
895                   for(Int_t binY=y1Int; binY<=y2Int; binY++){
896                     histoFiredDisplay[chCath]->SetBinContent(binX, binY, nFired);
897                   }
898                 }
899
900                 if(nFired==0.) nFired = kDummyFired;
901                 histoFired[chCath][localId-1]->Fill(ibitxy, nFired);
902               }
903             } // loop on strips
904
905             if(cath==0){ // Geometry info from bending plane only
906               transform->Local2Global(detElemId, xLocal1, yLocal1, 0, xg1, yg1, zg1);
907               transform->Local2Global(detElemId, xLocal2, yLocal2, 0, xg2, yg2, zg2);
908
909               // Per board
910               x1Label = TMath::Min(xg1,xg2) - xWidth;
911               y1Label = TMath::Min(yg1,yg2) - yWidth;
912               x2Label = TMath::Max(xg1,xg2) + xWidth;
913               y2Label = TMath::Max(yg1,yg2) + yWidth;
914
915               x1 = histo[ch]->GetXaxis()->FindBin(x1Label)+1;
916               y1 = histo[ch]->GetYaxis()->FindBin(y1Label)+1;
917               x2 = histo[ch]->GetXaxis()->FindBin(x2Label)-1;
918               y2 = histo[ch]->GetYaxis()->FindBin(y2Label)-1;
919
920               sprintf(labelTxt,"%3d", localId);
921
922               // Per slat
923               line = localBoard->GetPosition().GetFirst();
924               x1LabelSlat = 140.;
925               x2LabelSlat = x1LabelSlat + 40.;
926               y1LabelSlat = -285. + ((Float_t)(line - 1)) * 68;
927               y2LabelSlat = y1LabelSlat + 34.;
928               if(localId>kNumOfBoards/2){
929                 x1LabelSlat = -x2LabelSlat;
930                 x2LabelSlat = x1LabelSlat + 40.;
931               }
932               sprintf(labelSlatTxt,"%2d", slat);
933             }
934
935             boardLabel[chCath][localId-1] = new TPaveLabel(x1Label, y1Label, x2Label, y2Label, labelTxt);
936             boardLabel[chCath][localId-1]->SetFillStyle(0);
937             boardLabel[chCath][localId-1]->SetBorderSize(0);
938
939             boardLabelSlat[chCath][localId-1] = new TPaveLabel(x1LabelSlat, y1LabelSlat, x2LabelSlat, y2LabelSlat, labelSlatTxt);
940             boardLabelSlat[chCath][localId-1]->SetFillStyle(0);
941             boardLabelSlat[chCath][localId-1]->SetBorderSize(0);
942
943             Int_t histoBin = localId;
944             efficiency = fBoardEfficiency[chCath]->GetBinContent(histoBin);
945             efficiencyError = fBoardEfficiency[chCath]->GetBinError(histoBin);
946
947             histoBin = slat+1;
948             efficiencySlat = fSlatEfficiency[chCath]->GetBinContent(histoBin);
949             efficiencySlatError = fSlatEfficiency[chCath]->GetBinError(histoBin);
950
951             for(Int_t binX=x1; binX<=x2; binX++){
952               for(Int_t binY=y1; binY<=y2; binY++){
953                 histo[chCath]->SetBinContent(binX, binY, efficiency);
954                 histo[chCath]->SetBinError(binX, binY, efficiencyError);
955                 histoSlat[chCath]->SetBinContent(binX, binY, efficiencySlat);
956                 histoSlat[chCath]->SetBinError(binX, binY, efficiencySlatError);
957               }
958             }
959
960             // Check fired pads (when available)
961             if(padFired[cath]) {
962               histoFired[chCath][localId-1]->Fit("pol0","Q0R","",0., (Float_t)nStrips-1.);
963               fitFunc = histoFired[chCath][localId-1]->GetFunction("pol0");
964               Float_t chi2 = fitFunc->GetChisquare();
965               Float_t ndf = (Float_t)fitFunc->GetNDF();
966               Float_t reducedChi2 = chi2/ndf;
967               if(reducedChi2>kChi2RedMax) {
968                 isStripOffInBoard[chCath][localId-1] = kTRUE;
969                 //printf("Chamber = %i Cath = %i Board %i: chi2/NDF = %f\tparam = %f\n", ch, cath, localId, reducedChi2, fitFunc->GetParameter(0));
970                 fFiredFitHistoList->Add(histoFired[chCath][localId-1]);
971               }
972             }
973           } // loop on cathodes
974         } // loop on chambers
975       } // loop on boards
976     } // loop on crates
977   } // loop on DDL
978
979   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
980     for(Int_t ib=0; ib<kNumOfBoards; ib++){
981       fBoardLabelList->Add(boardLabel[chCath][ib]);
982     }
983   }
984   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
985     for(Int_t ib=0; ib<kNumOfBoards; ib++){
986       fBoardLabelList->Add(boardLabelSlat[chCath][ib]);
987     }
988   }
989
990   return kTRUE;
991 }
992
993
994 //__________________________________________________________________________
995 Bool_t AliMUONTriggerEfficiencyCells::SumRunEfficiency(const AliMUONTriggerEfficiencyCells &other)
996 {
997 ///  Sums results from different runs and gives the efficiency
998   if(!fCountHistoList || !fNoCountHistoList) {
999     AliWarning("Histograms for efficiency calculations not implemented in object");
1000     return kFALSE;
1001   }
1002   if(!other.fCountHistoList || !other.fNoCountHistoList) {
1003     AliWarning("Histograms for efficiency calculations not implemented in object passed as argument");
1004     return kFALSE;
1005   }
1006
1007   Int_t nentries = fCountHistoList->GetEntries();
1008   TH1F *currNum = 0x0, *currDen = 0x0, *otherNum = 0x0, *otherDen = 0x0;
1009
1010   for(Int_t iEntry=0; iEntry<nentries; iEntry++){
1011     currNum = (TH1F*)fCountHistoList->At(iEntry);
1012     currDen = (TH1F*)fNoCountHistoList->At(iEntry);
1013     otherNum = (TH1F*)other.fCountHistoList->At(iEntry);
1014     otherDen = (TH1F*)other.fNoCountHistoList->At(iEntry);
1015     currNum->Add(otherNum);
1016     currDen->Add(otherDen);
1017   }
1018
1019   FillHistosFromList();
1020
1021   if(!fFiredStrips) {
1022     AliWarning("Histograms for fired region check not implemented in object");
1023     return kFALSE;
1024   }
1025   if(!other.fFiredStrips) {
1026     AliWarning("Histograms for fired region check not implemented in object passed as argument");
1027     return kFALSE;
1028   }
1029   
1030   TH3F *currFired = 0x0, *otherFired = 0x0;
1031   nentries = fFiredStrips->GetEntries();
1032   for(Int_t iEntry=0; iEntry<nentries; iEntry++){
1033     currFired  = (TH3F*)fFiredStrips->At(iEntry);
1034     otherFired = (TH3F*)fFiredStrips->At(iEntry);
1035     currFired->Add(otherFired);
1036   }
1037     
1038   return kTRUE;
1039 }