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