]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerEfficiencyCells.cxx
Renamed vector and methods by removing Geant3 from the names
[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 <fstream>
17 #include <TRandom.h>
18 #include "Riostream.h"
19
20 #include "AliMUONTriggerEfficiencyCells.h"
21 #include "AliMUONConstants.h"
22 #include "AliRun.h"
23 #include "AliMpPad.h"
24 #include "AliMUON.h"
25 #include "AliMpVSegmentation.h"
26 #include "AliMpTriggerSegmentation.h"
27 #include "AliMpTrigger.h"
28 #include "AliLog.h"
29
30 /// \class AliMUONTriggerEfficiencyCells
31 /// A class to store and give access to the trigger chamber efficiency.
32 ///
33 /// Efficiency is stored per cathode, on "cells" of a given size.
34 ///
35 /// The main method of this class is IsTriggered().
36 ///
37 /// $ALICE_ROOT/MUON/data/TriggerChamberefficiencyCells.dat contains efficiency 
38 /// for each chamber (i.e. DetElement). 
39 /// The efficiency cells goes from right to left and 
40 /// from bottom to top of the chamber, namely, the efficiencies tabulated in the 
41 /// file refers to the following reference frame:
42 ///
43 /// <pre>
44 /// x
45 /// <----------------------------------|
46 ///                                    |
47 ///    ---------------------------     |
48 ///   | 0.97 | 0.97 | 0.97 | 0.97 |    |
49 ///    ---------------------------     |
50 ///   | 0.97 | 0.97 | 0.97 | 0.97 |    |
51 ///    ---------------------------     |
52 ///   | 0.97 | 0.97 | 0.97 | 0.97 |    |
53 ///    ---------------------------     |
54 ///                                    |
55 ///                                   \/ y
56 /// </pre>
57 ///  The file can be edited in order to change efficiency in a chosen region
58 ///  of the chamber.
59 ///
60 /// But please note that this object is also available from the CDB 
61 /// (generated using the MUONCDB.C macro)
62 ///
63 /// \author Diego Stocco; INFN Torino
64
65 /// \cond CLASSIMP
66 ClassImp(AliMUONTriggerEfficiencyCells)
67 /// \endcond
68
69 //__________________________________________________________________________
70 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
71 :
72 TObject()
73 {
74 ///  Default constructor.
75   Reset();
76 }
77
78 //__________________________________________________________________________
79 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const char* filename)
80 :
81 TObject()
82 {
83 ///  Constructor using an ASCII file.
84   Reset();
85   ReadFile(filename);
86 }
87
88
89 //__________________________________________________________________________
90 AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
91 {
92 ///  Destructor. Does nothing ;-)
93 }
94     
95 //__________________________________________________________________________
96 Float_t AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t cathode, Float_t x, Float_t y)
97 {
98 ///  Get the efficiency at a given position (x,y) for a given cathode
99   
100   Int_t chamber = FindChamberIndex(detElemId);
101   Int_t slat = FindSlatIndex(detElemId);
102   TArrayI cell = CellByCoord(detElemId,x,y);
103   Float_t efficiency = 0.0;
104   if (cell.At(0)>=0 && cell.At(1)>=0)
105   {
106     efficiency = fCellContent[chamber][slat][cathode][cell.At(0)][cell.At(1)];
107   }
108   return efficiency;
109 }
110
111
112 //__________________________________________________________________________
113 void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Float_t x, Float_t y, Float_t &eff1, Float_t &eff2)
114 {
115 ///  Get the efficiencies of the 2 cathode at a given location (x,y)
116
117   Int_t chamber = FindChamberIndex(detElemId);
118   Int_t slat = FindSlatIndex(detElemId);
119   TArrayI cell = CellByCoord(detElemId,x,y);
120   eff1 = 0.0;
121   eff2 = 0.0;
122   if(cell.At(0)>=0 && cell.At(1)>=0)
123   {
124     eff1 = fCellContent[chamber][slat][0][cell.At(0)][cell.At(1)];
125     eff2 = fCellContent[chamber][slat][1][cell.At(0)][cell.At(1)];
126   }
127 }
128
129
130 //__________________________________________________________________________
131 Bool_t 
132 AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t cathode, Float_t x, Float_t y)
133 {
134 ///  Random decision of whether a given "location" (x,y) trigs or not.
135
136   Float_t efficiency = GetCellEfficiency(detElemId, cathode, x, y);
137   Bool_t trigger = kTRUE;
138   if(gRandom->Rndm()>efficiency)
139   {
140     trigger = kFALSE;
141   }
142   return trigger;
143 }
144
145
146 //__________________________________________________________________________
147 void 
148 AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Float_t x, Float_t y, Bool_t &trig1, Bool_t &trig2)
149 {
150 ///  Whether or not a given location (x,y) has a chance to trig, on each cathode.
151
152   Float_t eff1 = 0.0;
153   Float_t eff2 = 0.0;
154   GetCellEfficiency(detElemId, x, y, eff1, eff2);
155   trig1 = kTRUE; 
156   trig2 = kTRUE;
157   if(gRandom->Rndm()>eff1)trig1 = kFALSE;
158   if(gRandom->Rndm()>eff2)trig2 = kFALSE;
159 }
160
161
162 //__________________________________________________________________________
163 TArrayI AliMUONTriggerEfficiencyCells::CellByCoord(Int_t detElemId, Float_t x, Float_t y)
164 {
165 ///  Get the efficiencies at a given location.
166
167   Int_t chamber = FindChamberIndex(detElemId);
168   Int_t slat = FindSlatIndex(detElemId);
169   Int_t cell[2]={-1,-1};
170   Float_t maxX = fCellSize[chamber][slat][0]*((Float_t)fCellNumber[chamber][slat][0]);
171   Float_t maxY = fCellSize[chamber][slat][1]*((Float_t)fCellNumber[chamber][slat][1]);
172   if(x>=0 & x<maxX & y>=0 & y<maxY)
173   {
174     cell[0] = (Int_t)(x/fCellSize[chamber][slat][0]);
175     cell[1] = (Int_t)(y/fCellSize[chamber][slat][1]);
176   }
177   return TArrayI(2,cell);
178 }
179
180 //__________________________________________________________________________
181 void AliMUONTriggerEfficiencyCells::ReadFile(const char* filename)
182 {
183 ///  Reads a file containing the efficiency map.
184
185   TString fileName = gSystem->ExpandPathName(filename);
186   ifstream file(fileName.Data());
187   Int_t datInt=0, detEl=0, chamber=0, rpc=0;
188   Float_t datFloat=0.0;
189   char dat[50];
190   if (file.good()){
191     while (file >> dat) {
192             file >> detEl;
193             chamber = FindChamberIndex(detEl);
194             rpc = FindSlatIndex(detEl);
195             file >> dat;
196             for(Int_t i=0; i<2; i++){
197         file >> datInt;
198         fCellNumber[chamber][rpc][i] = datInt;
199         file >> dat;
200             }
201             for(Int_t i=0; i<2; i++){
202         file >> datFloat;
203         fCellSize[chamber][rpc][i] = datFloat;
204         if(i==0)file >> dat;
205             }
206             for(Int_t cath=0; cath<2; cath++){
207         file >> dat;
208         file >> datInt;
209         for(Int_t iy=0; iy<fCellNumber[chamber][rpc][1]; iy++){
210           for(Int_t ix=0; ix<fCellNumber[chamber][rpc][0]; ix++){
211             file >> datFloat;
212             fCellContent[chamber][rpc][cath][ix][iy] = datFloat;
213           }
214         }
215             }
216     }
217     file.close();
218   } else {
219     AliWarning(Form("Can't read file %s",fileName.Data()));
220   }
221 }
222
223
224 //__________________________________________________________________________
225 Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId)
226 {
227 ///  From detElemId to chamber number
228
229   Int_t offset = 100*(AliMUONConstants::NTrackingCh()+1);
230   Int_t chamber = (detElemId-offset)/100;
231   return chamber;
232 }
233
234
235 //__________________________________________________________________________
236 Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId)
237 {
238 ///  From detElemId to slat index.
239
240   Int_t offset = 100*(AliMUONConstants::NTrackingCh()+1);
241   Int_t chamber = FindChamberIndex(detElemId);
242   Int_t slat = detElemId-offset-(chamber*100);
243   return slat;
244 }
245
246
247 //__________________________________________________________________________
248 TVector2 AliMUONTriggerEfficiencyCells::ChangeReferenceFrame(Float_t x, Float_t y, Float_t x0, Float_t y0)
249 {
250 /// (x0,y0) position of the local reference frame (center of the chamber)
251
252     Float_t x1 = x0-x;//reflection of axis
253     Float_t y1 = y+y0;
254     return TVector2(x1,y1);
255 }
256
257 //__________________________________________________________________________
258 void
259 AliMUONTriggerEfficiencyCells::Reset()
260 {
261 ///  Sets our internal array contents to zero.
262
263   for(Int_t chamber=0; chamber<4; chamber++)
264   {
265     for(Int_t slat=0; slat<18; slat++)
266     {
267             for(Int_t cath=0; cath<2; cath++)
268       {
269         fCellSize[chamber][slat][cath]=0.0;
270         fCellNumber[chamber][slat][cath]=0;
271         for(Int_t ix=0; ix<fgkNofCells; ix++)
272         {
273           for(Int_t iy=0; iy<fgkNofCells; iy++)
274           {
275             fCellContent[chamber][slat][cath][ix][iy]=0.0;
276           }
277         }
278       }
279     }
280   }
281 }
282