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