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