Fixes for #86059: Install data when ALICE_ROOT does not point to source (Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerLut.cxx
CommitLineData
a9e2aefa 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 **************************************************************************/
cbc57deb 15
88cb7938 16/* $Id$ */
c1651df4 17
3d1463c8 18//-----------------------------------------------------------------------------
19/// \class AliMUONTriggerLut
20///
6ae22475 21/// Local Trigger Look Up Table
22/// reading interface LUT data is stored into TH3S histograms and readout
23/// from the Local Trigger algorithm
890cc210 24///
25/// Histograms structure is :
26/// X 234 bins, 1 to 235 = local board number
27/// Y 31 bins, 0 to 31 = x strip
28/// Z 31 bins, 0 to 31 = x deviation
29/// content = Short_t = y strip mask
30///
31/// overflow bin is used !
32///
3d1463c8 33/// \author Philippe Crochet
34//-----------------------------------------------------------------------------
d1525c79 35
a9e2aefa 36#include "AliMUONTriggerLut.h"
9afd2481 37
8c343c7c 38#include "AliLog.h"
a9e2aefa 39
890cc210 40#include <TFile.h>
41#include <TH3.h>
42#include <TMap.h>
43#include <TObjString.h>
9afd2481 44
5398f946 45/// \cond CLASSIMP
a9e2aefa 46ClassImp(AliMUONTriggerLut)
5398f946 47/// \endcond
a9e2aefa 48
49//----------------------------------------------------------------------
30178c30 50AliMUONTriggerLut::AliMUONTriggerLut()
1657f946 51 : TNamed(),
52 fLptPlus(0),
53 fLptMinu(0),
54 fLptUnde(0),
55 fHptPlus(0),
56 fHptMinu(0),
57 fHptUnde(0),
58 fAptPlus(0),
59 fAptMinu(0),
890cc210 60 fAptUnde(0),
61 fMap(0x0)
30178c30 62{
3d1463c8 63/// ctor
a9e2aefa 64}
1657f946 65
a9e2aefa 66//----------------------------------------------------------------------
9afd2481 67AliMUONTriggerLut::~AliMUONTriggerLut()
68{
5398f946 69/// Destructor
70
a9e2aefa 71 delete fLptPlus;
72 delete fLptMinu;
73 delete fLptUnde;
74 delete fHptPlus;
75 delete fHptMinu;
76 delete fHptUnde;
77 delete fAptPlus;
78 delete fAptMinu;
79 delete fAptUnde;
890cc210 80 delete fMap;
81}
82
83//----------------------------------------------------------------------
84Int_t
85AliMUONTriggerLut::Compare(TH3* h1, TH3* h2) const
86{
87/// Return 0 if both histograms are strictly equal (at the bin-by-bin level)
88
89 AliDebug(1,Form("h1 %s h2 %s",h1 ? h1->GetName() : "null", h2 ? h2->GetName() : "null"));
90
91 if (!h1 || !h2)
92 {
93 return 0;
94 }
ea6d7574 95 Int_t bin;
96 for ( Int_t ix = 0; ix <= h1->GetNbinsX()+1; ix++ )
97 for ( Int_t iy = 0; iy <= h1->GetNbinsY()+1; iy++ )
98 for ( Int_t iz = 0; iz <= h1->GetNbinsZ()+1; iz++ )
99 {
100 {
101 {
102 bin = h1->GetBin(ix,iy,iz);
103 Double_t x1 = h1->GetBinContent(bin);
104 Double_t x2 = h2->GetBinContent(bin);
105 if ( x1 != x2 ) return 0;
106 }
107 }
108 }
890cc210 109
110 AliDebug(1,"same");
111
112 return 1;
113}
114
115//----------------------------------------------------------------------
116Int_t
117AliMUONTriggerLut::Compare(const TObject* object) const
118{
119/// Return 0 if the two luts are strictly equal
120
121 const AliMUONTriggerLut* lut = static_cast<const AliMUONTriggerLut*>(object);
122
123 Int_t rvLpt(0);
124
125 rvLpt += Compare(fLptPlus,lut->fLptPlus);
126 rvLpt += Compare(fLptMinu,lut->fLptMinu);
127 rvLpt += Compare(fLptUnde,lut->fLptUnde);
128
129 Int_t rvHpt(0);
130
131 rvHpt += Compare(fHptPlus,lut->fHptPlus);
132 rvHpt += Compare(fHptMinu,lut->fHptMinu);
133 rvHpt += Compare(fHptUnde,lut->fHptUnde);
134
135 Int_t rv(0);
136
137 rv += Compare(fAptPlus,lut->fAptPlus);
138 rv += Compare(fAptMinu,lut->fAptMinu);
139 rv += Compare(fAptUnde,lut->fAptUnde);
140
141 AliDebug(1,Form("Same Lpt %d Hpt %d Apt %d",rvLpt,rvHpt,rv));
142
143 if ( rvLpt == 3 && rvHpt == 3 )
144 {
145 return 0;
146 }
147
148 return 1;
a9e2aefa 149}
150
71a2d3aa 151//----------------------------------------------------------------------
152void AliMUONTriggerLut::ReadFromFile(const char* filename)
9afd2481 153{
5398f946 154/// Return output of LuT for corresponding TH3S
155
9afd2481 156 TFile f(filename);
157
158 if ( f.IsZombie() )
159 {
160 AliFatal(Form("Could not open file %s",filename));
161 }
162
1c29e5aa 163 AliDebug(1,Form("filename=%s",filename));
164
1c29e5aa 165 fLptPlus = (TH3*)(f.Get("LptPlus"));
166 fLptMinu = (TH3*)(f.Get("LptMinu"));
167 fLptUnde = (TH3*)(f.Get("LptUnde"));
168 fHptPlus = (TH3*)(f.Get("HptPlus"));
169 fHptMinu = (TH3*)(f.Get("HptMinu"));
170 fHptUnde = (TH3*)(f.Get("HptUnde"));
171 fAptPlus = (TH3*)(f.Get("AptPlus"));
172 fAptMinu = (TH3*)(f.Get("AptMinu"));
173 fAptUnde = (TH3*)(f.Get("AptUnde"));
174
9afd2481 175 // insure we "detach" those histograms from file f
176 fLptPlus->SetDirectory(0);
177 fLptMinu->SetDirectory(0);
178 fLptUnde->SetDirectory(0);
179 fHptPlus->SetDirectory(0);
180 fHptMinu->SetDirectory(0);
181 fHptUnde->SetDirectory(0);
182 fAptPlus->SetDirectory(0);
183 fAptMinu->SetDirectory(0);
184 fAptUnde->SetDirectory(0);
890cc210 185
186 RegisterHistos();
187}
188
189//----------------------------------------------------------------------
190void
191AliMUONTriggerLut::RegisterHistos()
192{
193/// Add histos to our internal map
194
195 Add(fLptPlus);
196 Add(fLptMinu);
197 Add(fLptUnde);
198
199 Add(fHptPlus);
200 Add(fHptMinu);
201 Add(fHptUnde);
202
203 Add(fAptPlus);
204 Add(fAptMinu);
205 Add(fAptUnde);
206}
207
208//----------------------------------------------------------------------
209void
210AliMUONTriggerLut::Add(TH3* h)
211{
212 /// Update internal map
213 if (!fMap)
214 {
215 fMap = new TMap;
216 fMap->SetOwner(kTRUE);
217 }
218
219 if (h) fMap->Add(new TObjString(h->GetName()),h);
220}
221
222//----------------------------------------------------------------------
223void
224AliMUONTriggerLut::SetContent(const char* hname, Int_t icirc, UChar_t istripX,
225 UChar_t idev, Short_t value)
226{
227 /// Set the content of one bin of one histogram
228
229 if (!fMap)
230 {
231 //..........................................circuit/stripX/deviation
232 fLptPlus = new TH3S("LptPlus","LptPlus",234,0,234,31,0,31,31,0,31);
233 fLptMinu = new TH3S("LptMinu","LptMinu",234,0,234,31,0,31,31,0,31);
234 fLptUnde = new TH3S("LptUnde","LptUnde",234,0,234,31,0,31,31,0,31);
235
236 fHptPlus = new TH3S("HptPlus","HptPlus",234,0,234,31,0,31,31,0,31);
237 fHptMinu = new TH3S("HptMinu","HptMinu",234,0,234,31,0,31,31,0,31);
238 fHptUnde = new TH3S("HptUnde","HptUnde",234,0,234,31,0,31,31,0,31);
239
ea6d7574 240 fAptPlus = new TH3S("AptPlus","AptPlus",234,0,234,31,0,31,31,0,31);
241 fAptMinu = new TH3S("AptMinu","AptMinu",234,0,234,31,0,31,31,0,31);
242 fAptUnde = new TH3S("AptUnde","AptUnde",234,0,234,31,0,31,31,0,31);
243
890cc210 244 RegisterHistos();
245 }
246
247 TH3* h = static_cast<TH3*>(fMap->GetValue(hname));
248
249 Int_t bin = h->GetBin(icirc,istripX,idev);
250 h->SetBinContent(bin,value);
9afd2481 251}
252
a9e2aefa 253//----------------------------------------------------------------------
254void AliMUONTriggerLut::GetLutOutput(Int_t circuit, Int_t xstrip, Int_t idev,
890cc210 255 Int_t ystrip, Int_t lutLpt[2],
256 Int_t lutHpt[2]) const
9afd2481 257{
5398f946 258/// Return output of LuT for corresponding TH3S
d56db588 259
9afd2481 260 if ( !fLptPlus )
261 {
890cc210 262 AliError("LUT not initialized");
263// ReadFromFile("$(ALICE_ROOT)/MUON/data/MUONTriggerLut.root");
d56db588 264 }
9afd2481 265
a9e2aefa 266 Int_t bin;
267 Short_t binc;
268 Int_t mask = GetMask(ystrip); // get ystrip mask
269
270 // Low pt..............................................
9afd2481 271 bin = fLptPlus->GetBin(circuit,xstrip,idev);
272 binc = (Short_t)fLptPlus->GetBinContent(bin);
a9e2aefa 273 if ((binc & mask)!=0) lutLpt[1]=1;
274
9afd2481 275 bin = fLptMinu->GetBin(circuit,xstrip,idev);
276 binc = (Short_t)fLptMinu->GetBinContent(bin);
a9e2aefa 277 if ((binc & mask)!=0) lutLpt[0]=1;
278
9afd2481 279 bin = fLptUnde->GetBin(circuit,xstrip,idev);
280 binc = (Short_t)fLptUnde->GetBinContent(bin);
a9e2aefa 281 if ((binc & mask)!=0) lutLpt[0]=lutLpt[1]=1;
282
283 // High pt.............................................
9afd2481 284 bin = fHptPlus->GetBin(circuit,xstrip,idev);
285 binc = (Short_t)fHptPlus->GetBinContent(bin);
a9e2aefa 286 if ((binc & mask)!=0) lutHpt[1]=1;
287
9afd2481 288 bin = fHptMinu->GetBin(circuit,xstrip,idev);
289 binc = (Short_t)fHptMinu->GetBinContent(bin);
a9e2aefa 290 if ((binc & mask)!=0) lutHpt[0]=1;
291
9afd2481 292 bin = fHptUnde->GetBin(circuit,xstrip,idev);
293 binc = (Short_t)fHptUnde->GetBinContent(bin);
a9e2aefa 294 if ((binc & mask)!=0) lutHpt[0]=lutHpt[1]=1;
6ae22475 295/*
a9e2aefa 296 // All pts.............................................
9afd2481 297 bin = fAptPlus->GetBin(circuit,xstrip,idev);
298 binc = (Short_t)fAptPlus->GetBinContent(bin);
a9e2aefa 299 if ((binc & mask)!=0) lutApt[1]=1;
300
9afd2481 301 bin = fAptMinu->GetBin(circuit,xstrip,idev);
302 binc = (Short_t)fAptMinu->GetBinContent(bin);
a9e2aefa 303 if ((binc & mask)!=0) lutApt[0]=1;
304
9afd2481 305 bin = fAptUnde->GetBin(circuit,xstrip,idev);
306 binc = (Short_t)fAptUnde->GetBinContent(bin);
a9e2aefa 307 if ((binc & mask)!=0) lutApt[0]=lutApt[1]=1;
6ae22475 308*/
a9e2aefa 309}
310
311//----------------------------------------------------------------------
890cc210 312Int_t AliMUONTriggerLut::GetMask(Int_t ystrip) const
9afd2481 313{
5398f946 314/// Return the mask corresponding to ystrip
315
058fe239 316 return (Int_t)(1<<ystrip);
a9e2aefa 317}
318
b0ac3c26 319//----------------------------------------------------------------------
320void AliMUONTriggerLut::SetLutCode(const UChar_t lutCode)
321{
322/// Set the LUT code for the pair of cuts
323/// see AliMUONTriggerIO::ReadLUT for the definitions
324
325 if (!fMap) {
326 AliWarning("Nothing registered in the map ?... ");
327 return;
328 }
329 TH3* h = static_cast<TH3*>(fMap->GetValue("LptPlus"));
330 h->SetTitle(Form("LptPlus 0x%02x",lutCode));
a9e2aefa 331
b0ac3c26 332}
a9e2aefa 333
334
335
b0ac3c26 336//----------------------------------------------------------------------
337void AliMUONTriggerLut::PrintLutCode()
338{
339/// Print out the LUT code for the pair of cuts
340/// see AliMUONTriggerIO::ReadLUT for the definitions
341
342 TString lutCode = fLptPlus->GetTitle();
343 lutCode.Remove(0,8);
344 if (lutCode.Length() == 0) {
345 AliInfo("No code stored (older version).");
346 } else {
347 AliInfo(lutCode.Data());
348
349 AliInfo("---------------------------------");
350 AliInfo("1st/2nd cut code pt cut [GeV/c]");
351 AliInfo(" ");
352 AliInfo(" 0 0.5 (a.k.a. Apt)");
353 AliInfo(" 1 1.0 (a.k.a. Lpt)");
354 AliInfo(" 2 1.7 (a.k.a. Hpt)");
355 AliInfo(" 3 4.2 (a.k.a. infinity)");
356 AliInfo(" 4 free");
357 AliInfo(" .");
358 AliInfo(" .");
359 AliInfo(" .");
360 AliInfo("15 default (for backward compatibility)");
361 AliInfo("---------------------------------------");
362
363 }
364
365}