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