]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerEfficiencyCells.cxx
New PID Classes
[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
20 #include "AliLog.h"
21 #include "AliMpConstants.h"
22
23 #include "TH1.h"
24 #include "TList.h"
25 #include "TFile.h"
26
27 #include <fstream>
28 #include <cassert>
29
30
31 //-----------------------------------------------------------------------------
32 /// \class AliMUONTriggerEfficiencyCells
33 /// A class to store and give access to the numerator and denominator 
34 /// histograms for the trigger chamber efficiency calculation.
35 ///
36 /// \author Diego Stocco; Subatech, Nantes
37 //-----------------------------------------------------------------------------
38
39 /// \cond CLASSIMP
40 ClassImp(AliMUONTriggerEfficiencyCells)
41 /// \endcond
42
43 //__________________________________________________________________________
44 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
45 :
46 TObject(),
47 fCountHistoList(0x0),
48 fNoCountHistoList(0x0),
49 fFiredStrips(0x0)
50 {
51 ///  Default constructor.
52   CheckConstants();
53   ResetHistos();
54 }
55
56 //__________________________________________________________________________
57 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const Char_t* filename,
58                                                              const Char_t* listname)
59 :
60 TObject(),
61 fCountHistoList(0x0),
62 fNoCountHistoList(0x0),
63 fFiredStrips(0x0)
64 {
65 ///  Constructor using an ASCII file.
66   CheckConstants();
67   ResetHistos();
68   ReadFile(filename, listname);
69 }
70
71 //__________________________________________________________________________
72 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(TList *countHistoList)
73 :
74 TObject(),
75 fCountHistoList(countHistoList),
76 fNoCountHistoList(0x0),
77 fFiredStrips(0x0)
78 {
79 ///  Constructor using a list of histograms with counts.
80   CheckConstants();
81   ResetHistos();
82 }
83
84 //_____________________________________________________________________________
85 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const AliMUONTriggerEfficiencyCells& other)
86 :
87 TObject(other),
88 fCountHistoList(other.fCountHistoList),
89 fNoCountHistoList(other.fNoCountHistoList),
90 fFiredStrips(other.fFiredStrips)
91 {
92 /// Copy constructor
93
94   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
95     fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
96     fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
97   }
98 }
99
100 //_____________________________________________________________________________
101 AliMUONTriggerEfficiencyCells& AliMUONTriggerEfficiencyCells::operator=(const AliMUONTriggerEfficiencyCells& other)
102 {
103   /// Asignment operator
104   // check assignement to self
105   if (this == &other)
106     return *this;
107
108   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
109     fBoardEfficiency[chCath] = other.fBoardEfficiency[chCath];
110     fSlatEfficiency[chCath] = other.fSlatEfficiency[chCath];
111   }
112
113   fCountHistoList = other.fCountHistoList;
114   fNoCountHistoList = other.fNoCountHistoList;
115   fFiredStrips = other.fFiredStrips;
116     
117   return *this;
118 }
119
120 //__________________________________________________________________________
121 AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
122 {
123 ///  Destructor.
124   //delete [] fBoardEfficiency;
125   //delete [] fSlatEfficiency;
126   ResetHistos(kTRUE);
127   delete fCountHistoList;
128   delete fNoCountHistoList;
129   delete fFiredStrips;
130 }
131
132
133 //_____________________________________________________________________________
134 void AliMUONTriggerEfficiencyCells::CheckConstants() const
135 {
136 /// Check consistence of redefined constants 
137
138   assert(fgkNcathodes == AliMpConstants::NofCathodes());    
139   assert(fgkNchambers == AliMpConstants::NofTriggerChambers());    
140   assert(fgkNplanes == AliMpConstants::NofTriggerChambers() * fgkNcathodes);    
141 }
142
143
144 //__________________________________________________________________________
145 void
146 AliMUONTriggerEfficiencyCells::ResetHistos(Bool_t deleteObjects)
147 {
148 ///  Sets our internal array contents to zero.
149
150   for(Int_t chCath=0; chCath<fgkNplanes; chCath++){
151     if ( deleteObjects ) {
152       delete fBoardEfficiency[chCath];
153       delete fSlatEfficiency[chCath];
154     }
155     fBoardEfficiency[chCath] = 0x0;
156     fSlatEfficiency[chCath] = 0x0;
157   }
158 }
159
160
161 //__________________________________________________________________________
162 void AliMUONTriggerEfficiencyCells::ReadFile(const Char_t* filename, const Char_t* listname)
163 {
164 ///  Structure of file (.root) containing local board efficency
165     TFile *file = TFile::Open(filename);
166     if(!file || !file->IsOpen()) {
167       AliError(Form("Can't read file %s",filename));
168       return;
169     }
170
171     if ( ! fCountHistoList ) {
172       fCountHistoList = new TList();
173       fCountHistoList->SetOwner();
174     }
175
176     TH1F *histo = 0x0;
177     const Char_t* histoName;
178
179     TList* listInFile = 0x0;
180     TString listNameString(listname);
181     if ( ! listNameString.IsNull() )
182       listInFile = (TList*)file->FindObjectAny(listname);
183
184     for ( Int_t ide=0; ide<=kHchamberCount; ide++){
185       for(Int_t ich=0; ich<fgkNchambers; ich++){
186
187         // Efficiency per chamber is provided by 1 histogram only
188         if ( ide == kHchamberCount ) ich = fgkNchambers;
189
190         for(Int_t hType=0; hType<kNcounts; hType++){
191           histoName = GetHistoName(ide, hType, ich);
192           histo = ( listInFile ) ? (TH1F*)listInFile->FindObject(histoName) : (TH1F*)file->Get(histoName);
193           if ( ! histo ) {
194             AliWarning(Form("Cannot find %s in file. Skip histogram", histoName));
195             continue;
196           }
197           histo->SetDirectory(0);
198           fCountHistoList->Add(histo);
199
200           AliDebug(5,Form("Adding histogram %s\n",histoName));
201
202           // Do not fill efficiency per chamber histos
203           if ( ide == kHchamberCount )
204             continue;
205
206           // Fill old historgrams for consistency
207           if ( hType < kBothPlanesEff ){
208             TString newName = histoName;
209             newName.ReplaceAll("Counts","Eff");
210             TH1F* auxHisto = (TH1F*)histo->Clone(newName.Data());
211             auxHisto->SetDirectory(0);
212             if ( ide == kHboardCount )
213               fBoardEfficiency[fgkNchambers*hType+ich] = auxHisto;
214             else if ( ide == kHslatCount )
215               fSlatEfficiency[fgkNchambers*hType+ich] = auxHisto;
216
217             AliDebug(5,Form("Creating histogram %s\n",auxHisto->GetName()));
218           }
219           else if ( hType == kAllTracks ){
220             for ( Int_t icath=0; icath<2; icath++){
221               if ( ide == kHboardCount )
222                 fBoardEfficiency[fgkNchambers*icath+ich]->Divide(histo);
223               else if ( ide == kHslatCount )
224                 fSlatEfficiency[fgkNchambers*icath+ich]->Divide(histo);
225             }
226           }
227         } // loop on count types
228       } // loop on chambers
229     } // loop on detection element type
230
231     file->Close();
232 }
233
234
235 //__________________________________________________________________________
236 const Char_t*
237 AliMUONTriggerEfficiencyCells::GetHistoName(Int_t histoType, Int_t countType, 
238                                             Int_t chamber)
239 {
240   //
241   /// Return the name of the histogram for efficiency calculation
242   //
243   TString histoTypeName[kNcounts] = {"bendPlane", "nonBendPlane", "bothPlanes", "allTracks"};
244
245   switch ( histoType ) {
246   case kHchamberCount:
247     return Form("%sCountChamber", histoTypeName[countType].Data());
248   case kHslatCount:
249     return Form("%sCountSlatCh%i", histoTypeName[countType].Data(), 11+chamber);
250   case kHboardCount:
251     return Form("%sCountBoardCh%i", histoTypeName[countType].Data(), 11+chamber);
252   }
253
254   return 0x0;
255 }
256
257 //__________________________________________________________________________
258 TH1F* AliMUONTriggerEfficiencyCells::GetOldEffHisto(Int_t histoType,
259                                                     Int_t ich, Int_t icath) const
260 {
261   //
262   /// Compatibility with old class
263   /// Gets the efficiency from the array
264   /// (which are empty in the new implementation)
265
266   switch ( histoType ) {
267   case kHboardCount:
268     return fBoardEfficiency[fgkNchambers*icath+ich];
269   case kHslatCount:
270     return fSlatEfficiency[fgkNchambers*icath+ich];
271   }
272   return 0x0;
273 }