1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "Riostream.h"
23 #include "AliMUONTriggerEfficiencyCells.h"
24 #include "AliMpConstants.h"
27 /// \class AliMUONTriggerEfficiencyCells
28 /// A class to store and give access to the trigger chamber efficiency.
30 /// Efficiency is stored per cathode on local boards, or, alternatively,
31 /// on "cells" of a given size.
33 /// The main method of this class is IsTriggered().
35 /// $ALICE_ROOT/MUON/data/TriggerChamberefficiencyCells.dat contains efficiency
36 /// for each chamber (i.e. DetElement).
38 /// In the case of local boards, efficiency is stored from left to right
39 /// per increasing board number (from 1 to 234)
41 /// Otherwise, he efficiency cells goes from right to left and
42 /// from bottom to top of the chamber, namely, the efficiencies tabulated in the
43 /// file refers to the following reference frame:
47 /// <----------------------------------|
49 /// --------------------------- |
50 /// | 0.97 | 0.97 | 0.97 | 0.97 | |
51 /// --------------------------- |
52 /// | 0.97 | 0.97 | 0.97 | 0.97 | |
53 /// --------------------------- |
54 /// | 0.97 | 0.97 | 0.97 | 0.97 | |
55 /// --------------------------- |
60 /// In both cases, the file can be edited in order to change efficiency
61 /// in a chosen local board/region of the chamber.
64 /// But please note that this object is also available from the CDB
65 /// (generated using the MUONCDB.C macro)
67 /// \author Diego Stocco; INFN Torino
70 ClassImp(AliMUONTriggerEfficiencyCells)
73 //__________________________________________________________________________
74 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells()
78 /// Default constructor.
82 //__________________________________________________________________________
83 AliMUONTriggerEfficiencyCells::AliMUONTriggerEfficiencyCells(const char* filename)
87 /// Constructor using an ASCII file.
93 //__________________________________________________________________________
94 AliMUONTriggerEfficiencyCells::~AliMUONTriggerEfficiencyCells()
96 /// Destructor. Does nothing ;-)
100 //__________________________________________________________________________
101 void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Float_t x, Float_t y, Float_t &eff1, Float_t &eff2)
103 /// Get the efficiencies of the 2 cathodes at a given location (x,y)
105 Int_t chamber = FindChamberIndex(detElemId);
106 Int_t slat = FindSlatIndex(detElemId);
107 TArrayI cell = CellByCoord(detElemId,x,y);
110 if(cell.At(0)>=0 && cell.At(1)>=0)
112 eff1 = fCellContent[chamber][slat][0][cell.At(0)][cell.At(1)];
113 eff2 = fCellContent[chamber][slat][1][cell.At(0)][cell.At(1)];
118 //__________________________________________________________________________
119 void AliMUONTriggerEfficiencyCells::GetCellEfficiency(Int_t detElemId, Int_t localBoard, Float_t &eff1, Float_t &eff2)
121 /// Get the efficiencies of the 2 cathodes at a given local board
123 Int_t chamber = FindChamberIndex(detElemId);
124 eff1 = fBoardContent[chamber][0][localBoard-1];
125 eff2 = fBoardContent[chamber][1][localBoard-1];
129 //__________________________________________________________________________
131 AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Float_t x, Float_t y, Bool_t &trig1, Bool_t &trig2)
133 /// Whether or not a given location (x,y) has a chance to trig, on each cathode.
137 GetCellEfficiency(detElemId, x, y, eff1, eff2);
140 if(gRandom->Rndm()>eff1)trig1 = kFALSE;
141 if(gRandom->Rndm()>eff2)trig2 = kFALSE;
145 //__________________________________________________________________________
147 AliMUONTriggerEfficiencyCells::IsTriggered(Int_t detElemId, Int_t localBoard, Bool_t &trig1, Bool_t &trig2)
149 /// Whether or not a given local board has a chance to trig, on each cathode.
153 GetCellEfficiency(detElemId, localBoard, eff1, eff2);
156 if(gRandom->Rndm()>eff1)trig1 = kFALSE;
157 if(gRandom->Rndm()>eff2)trig2 = kFALSE;
160 //__________________________________________________________________________
161 TArrayI AliMUONTriggerEfficiencyCells::CellByCoord(Int_t detElemId, Float_t x, Float_t y)
163 /// Get the efficiencies at a given location.
165 Int_t chamber = FindChamberIndex(detElemId);
166 Int_t slat = FindSlatIndex(detElemId);
167 Int_t cell[2]={-1,-1};
168 Float_t maxX = fCellSize[chamber][slat][0]*((Float_t)fCellNumber[chamber][slat][0]);
169 Float_t maxY = fCellSize[chamber][slat][1]*((Float_t)fCellNumber[chamber][slat][1]);
170 if(x>=0 & x<maxX & y>=0 & y<maxY)
172 cell[0] = (Int_t)(x/fCellSize[chamber][slat][0]);
173 cell[1] = (Int_t)(y/fCellSize[chamber][slat][1]);
175 return TArrayI(2,cell);
178 //__________________________________________________________________________
179 void AliMUONTriggerEfficiencyCells::ReadFile(const char* filename)
181 /// Reads a file containing the efficiency map.
183 TString fileName = gSystem->ExpandPathName(filename);
184 if(fileName.EndsWith(".root")){
185 ReadHistoBoards(fileName.Data());
189 ifstream file(fileName.Data());
193 if(!strcmp(dat,"localBoards"))ReadFileBoards(file);
194 else ReadFileXY(file);
197 AliWarning(Form("Can't read file %s",fileName.Data()));
202 //__________________________________________________________________________
203 void AliMUONTriggerEfficiencyCells::ReadFileXY(ifstream &file)
205 /// Structure of file containing geometrical efficency
206 Int_t datInt=0, detEl=0, chamber=0, rpc=0;
207 Float_t datFloat=0.0;
210 while (file >> dat) {
212 chamber = FindChamberIndex(detEl);
213 rpc = FindSlatIndex(detEl);
215 for(Int_t i=0; i<2; i++){
217 fCellNumber[chamber][rpc][i] = datInt;
220 for(Int_t i=0; i<2; i++){
222 fCellSize[chamber][rpc][i] = datFloat;
225 for(Int_t cath=0; cath<2; cath++){
228 for(Int_t iy=0; iy<fCellNumber[chamber][rpc][1]; iy++){
229 for(Int_t ix=0; ix<fCellNumber[chamber][rpc][0]; ix++){
231 fCellContent[chamber][rpc][cath][ix][iy] = datFloat;
238 //__________________________________________________________________________
239 void AliMUONTriggerEfficiencyCells::ReadFileBoards(ifstream &file)
241 /// Structure of file containing local board efficency
242 Int_t datInt=0, detEl=0, chamber=0;
243 Float_t datFloat=0.0;
246 while (file >> dat) {
248 chamber = FindChamberIndex(detEl);
249 //rpc = FindSlatIndex(detEl);
250 for(Int_t cath=0; cath<2; cath++){
253 for(Int_t board=0; board<fgkNofBoards; board++){
255 fBoardContent[chamber][cath][board] = datFloat;
262 //__________________________________________________________________________
263 void AliMUONTriggerEfficiencyCells::ReadHistoBoards(const char *filename)
265 TFile *file = new TFile(filename, "read");
267 AliWarning(Form("Can't read file %s",filename));
271 char *cathCode[2] = {"bendPlane", "nonBendPlane"};
273 for(Int_t ch=0; ch<4; ch++){
274 for(Int_t cath=0; cath<2; cath++){
275 sprintf(histoName, "%sBoardEffChamber%i", cathCode[cath], 11+ch);
276 histo = (TH1F *)file->Get(histoName);
277 if(!(TH1F *)file->Get(histoName)) {
278 AliWarning(Form("Can't find histo %s in file %s",histoName, filename));
281 for(Int_t board=0; board<fgkNofBoards; board++){
282 Int_t bin = histo->FindBin(board+1);
283 fBoardContent[ch][cath][board] = histo->GetBinContent(bin);
290 //__________________________________________________________________________
291 Int_t AliMUONTriggerEfficiencyCells::FindChamberIndex(Int_t detElemId)
293 /// From detElemId to chamber number
295 Int_t offset = 100*(AliMpConstants::NofTrackingChambers()+1);
296 Int_t chamber = (detElemId-offset)/100;
301 //__________________________________________________________________________
302 Int_t AliMUONTriggerEfficiencyCells::FindSlatIndex(Int_t detElemId)
304 /// From detElemId to slat index.
306 Int_t offset = 100*(AliMpConstants::NofTrackingChambers()+1);
307 Int_t chamber = FindChamberIndex(detElemId);
308 Int_t slat = detElemId-offset-(chamber*100);
313 //__________________________________________________________________________
314 TVector2 AliMUONTriggerEfficiencyCells::ChangeReferenceFrame(Float_t x, Float_t y, Float_t x0, Float_t y0)
316 /// (x0,y0) position of the local reference frame (center of the chamber)
318 Float_t x1 = x0-x;//reflection of axis
320 return TVector2(x1,y1);
323 //__________________________________________________________________________
325 AliMUONTriggerEfficiencyCells::Reset()
327 /// Sets our internal array contents to zero.
329 for(Int_t chamber=0; chamber<4; chamber++)
331 for(Int_t slat=0; slat<18; slat++)
333 for(Int_t cath=0; cath<2; cath++)
335 fCellSize[chamber][slat][cath]=0.0;
336 fCellNumber[chamber][slat][cath]=0;
337 for(Int_t ix=0; ix<fgkNofCells; ix++)
339 for(Int_t iy=0; iy<fgkNofCells; iy++)
341 fCellContent[chamber][slat][cath][ix][iy]=0.0;
346 for(Int_t cath=0; cath<2; cath++)
348 for(Int_t board=0; board<fgkNofBoards; board++)
350 fBoardContent[chamber][cath][board]=0.0;