]>
Commit | Line | Data |
---|---|---|
aef183f7 | 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 | // --- MUON header files --- | |
19 | #include "AliMUONTriggerDisplay.h" | |
20 | #include "AliMUONConstants.h" | |
21 | ||
22 | #include "AliMpDDLStore.h" | |
23 | #include "AliMpVSegmentation.h" | |
24 | #include "AliMpSegmentation.h" | |
25 | #include "AliMpConstants.h" | |
26 | #include "AliMpPad.h" | |
27 | #include "AliMpLocalBoard.h" | |
28 | #include "AliMpCDB.h" | |
29 | ||
30 | // --- AliRoot header files --- | |
31 | #include "AliLog.h" | |
32 | ||
33 | // --- ROOT system --- | |
34 | #include <TH1.h> | |
35 | #include <TH2.h> | |
36 | ||
37 | //----------------------------------------------------------------------------- | |
38 | /// \class AliMUONTriggerDisplay | |
39 | /// | |
40 | /// MUON base class for converting histos as a function of strip/board/slat number | |
41 | /// into display histos showing the detection element position in the | |
42 | /// trigger chamber | |
43 | /// | |
44 | /// \author D. Stocco | |
45 | ||
46 | /// \cond CLASSIMP | |
47 | ClassImp(AliMUONTriggerDisplay) | |
48 | /// \endcond | |
49 | ||
50 | //____________________________________________________________________________ | |
51 | AliMUONTriggerDisplay::AliMUONTriggerDisplay() : | |
52 | TObject() | |
53 | { | |
54 | /// ctor | |
55 | } | |
56 | ||
57 | //__________________________________________________________________ | |
58 | AliMUONTriggerDisplay::~AliMUONTriggerDisplay() | |
59 | { | |
60 | /// dtor | |
61 | } | |
62 | ||
63 | ||
64 | //____________________________________________________________________________ | |
65 | TH2* AliMUONTriggerDisplay::GetEmptyDisplayHisto(TString displayHistoName, EDisplayType displayType, | |
66 | Int_t cathode, Int_t chamber, | |
67 | TString displayHistoTitle) | |
68 | { | |
69 | // | |
70 | /// Return the display histogram with optimized binning | |
71 | /// but do not fill it. | |
72 | // | |
73 | TH2F* displayHisto = new TH2F(); | |
74 | ||
75 | InitOrDisplayTriggerInfo(0x0, displayHisto, displayType, | |
76 | cathode, chamber, displayHistoName, displayHistoTitle); | |
77 | ||
78 | return displayHisto; | |
79 | } | |
80 | ||
81 | ||
82 | //____________________________________________________________________________ | |
83 | TH2* AliMUONTriggerDisplay::GetBoardNumberHisto(TString displayHistoName, | |
84 | Int_t chamber, | |
85 | TString displayHistoTitle) | |
86 | { | |
87 | // | |
88 | /// Return the display histogram with optimized binning | |
89 | /// and fill it with the board number | |
90 | // | |
91 | ||
92 | const Int_t kNboards = AliMpConstants::NofLocalBoards(); | |
93 | TH1F* inputHisto = new TH1F("boardNumbers","Board Numbers",kNboards,0.5,(Float_t)kNboards + 0.5); | |
94 | for(Int_t ibin=1; ibin<=kNboards; ibin++){ | |
95 | inputHisto->Fill(ibin,ibin); | |
96 | } | |
97 | ||
98 | TH2F* displayHisto = (TH2F*)GetEmptyDisplayHisto(displayHistoName, kDisplayBoards, 0, chamber, displayHistoTitle); | |
99 | FillDisplayHistogram(inputHisto,displayHisto,kDisplayBoards,0,chamber,kNumbered); | |
100 | ||
101 | delete inputHisto; | |
102 | ||
103 | displayHisto->SetStats(kFALSE); | |
104 | return displayHisto; | |
105 | } | |
106 | ||
107 | ||
108 | //____________________________________________________________________________ | |
109 | TH2* AliMUONTriggerDisplay::GetDisplayHistogram(TH1* inputHisto, TString displayHistoName, | |
110 | EDisplayType displayType, Int_t cathode, | |
111 | Int_t chamber, TString displayHistoTitle, | |
112 | EDisplayOption displayOpt) | |
113 | { | |
114 | // | |
115 | /// Get histogram displaying the information contained in the input histogram | |
116 | // | |
117 | TH2* displayHisto = GetEmptyDisplayHisto(displayHistoName, displayType, | |
118 | cathode, chamber, displayHistoTitle); | |
119 | ||
120 | FillDisplayHistogram(inputHisto, displayHisto, displayType, cathode, chamber, displayOpt); | |
121 | ||
122 | return displayHisto; | |
123 | } | |
124 | ||
125 | //____________________________________________________________________________ | |
126 | Bool_t AliMUONTriggerDisplay::FillDisplayHistogram(TH1* inputHisto, TH2* displayHisto, | |
127 | EDisplayType displayType, Int_t cathode, | |
128 | Int_t chamber, EDisplayOption displayOpt) | |
129 | { | |
130 | // | |
131 | /// Fill a previously initialized display histogram | |
132 | /// with the information contained in inputHisto. | |
133 | /// To get initialized display, please use GetEmptyDisplayHisto method | |
134 | // | |
135 | return InitOrDisplayTriggerInfo(inputHisto, displayHisto, displayType, | |
136 | cathode, chamber, "", "",displayOpt); | |
137 | } | |
138 | ||
139 | //____________________________________________________________________________ | |
140 | Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TH1* inputHisto, TH2* displayHisto, | |
141 | EDisplayType displayType, | |
142 | Int_t cathode, Int_t chamber, | |
143 | TString displayHistoName, TString displayHistoTitle, | |
144 | EDisplayOption displayOpt) | |
145 | { | |
146 | // | |
147 | /// Initialize trigger information display histograms using mapping | |
148 | /// Trigger information is displayed in a user-friendly way: | |
149 | /// from local board and strip numbers to their position on chambers. | |
150 | // | |
151 | ||
152 | // Load mapping | |
153 | if ( ! AliMpSegmentation::Instance(kFALSE) ) { | |
154 | /// Load mapping | |
155 | if ( ! AliMpCDB::LoadDDLStore() ) { | |
156 | AliError("Could not access mapping from OCDB !"); | |
157 | AliError("Histograms are not initialized !"); | |
158 | return kFALSE; | |
159 | } | |
160 | } | |
161 | ||
162 | Int_t iCh = (chamber > AliMpConstants::NofTrackingChambers()) ? chamber - 11 : chamber; | |
163 | Int_t iCath = cathode; | |
164 | ||
165 | TArrayD xAxisStrip; | |
166 | TArrayD yAxisStrip; | |
167 | TArrayD xAxisBoard; | |
168 | TArrayD yAxisBoard; | |
169 | ||
170 | Float_t yOffsetLine, xOffsetLine = 0.; | |
171 | ||
172 | const Float_t kResetValue=1234567.; | |
173 | ||
174 | if(!inputHisto){ | |
175 | xAxisBoard.Set(55); | |
176 | xAxisBoard.Reset(kResetValue); | |
177 | yAxisBoard.Set(50); | |
178 | yAxisBoard.Reset(kResetValue); | |
179 | ||
180 | xAxisStrip.Set(420); | |
181 | xAxisStrip.Reset(kResetValue); | |
182 | yAxisStrip.Set(710); | |
183 | yAxisStrip.Reset(kResetValue); | |
184 | } | |
185 | else if(!displayHisto){ | |
186 | AliWarning("Display histogram not initialized. Please initialize it first!"); | |
187 | return kFALSE; | |
188 | } | |
189 | ||
190 | Float_t xWidth, yWidth, yWidthSlat=0., xWidthCol=0.; | |
191 | Float_t x1,x2,y1,y2; | |
192 | Float_t x1b=0., x2b=0., y1b=0., y2b=0.; | |
193 | Float_t xcPad, ycPad; | |
194 | Int_t line=0, slat; | |
195 | Float_t sign = 1.; | |
196 | ||
197 | const Float_t kShiftB = 0.5; | |
198 | const Float_t kShiftS = 0.1; | |
199 | ||
200 | const Float_t kShiftX = (iCath==0) ? kShiftB : kShiftS; | |
201 | const Float_t kShiftY = (iCath==0) ? kShiftS : kShiftB; | |
202 | const Float_t kShiftEl = (displayType==kDisplaySlats) ? 0.01 : kShiftB; | |
203 | ||
204 | Int_t iChamber = iCh + AliMpConstants::NofTrackingChambers(); | |
205 | for(Int_t iLoc = 0; iLoc < AliMpConstants::NofLocalBoards(); iLoc++) { | |
206 | Int_t iBoard = iLoc+1; | |
207 | Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(iBoard, iChamber); | |
208 | ||
209 | if (!detElemId) continue; | |
210 | ||
211 | AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(iBoard, kFALSE); | |
212 | ||
213 | // skip copy cards | |
214 | if( !localBoard->IsNotified()) | |
215 | continue; | |
216 | ||
217 | // get segmentation | |
218 | const AliMpVSegmentation* seg[2] = { | |
219 | AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(0)), | |
220 | AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(1))}; | |
221 | ||
222 | if(iLoc==0){ | |
223 | AliMpPad pad1 = seg[1]->PadByLocation(AliMpIntPair(iBoard,0),kFALSE); | |
224 | yWidthSlat = pad1.Dimensions().Y(); | |
225 | AliMpPad pad0 = seg[0]->PadByLocation(AliMpIntPair(iBoard,0),kFALSE); | |
226 | xOffsetLine = TMath::Abs(pad0.Position().X()) + pad0.Dimensions().X(); | |
227 | xWidthCol = 2.* pad0.Dimensions().X(); | |
228 | } | |
229 | ||
230 | // Get ideal global position of DetElemId center | |
231 | slat = detElemId%100; | |
232 | line = (4 + slat)%18; | |
233 | sign = 1.; | |
234 | if(line>8) { | |
235 | line = 17 - line; | |
236 | sign = -1.; | |
237 | } | |
238 | yOffsetLine = (Float_t)(line - 4) * 2. * yWidthSlat; | |
239 | ||
240 | for(Int_t cath=0; cath<AliMpConstants::NofCathodes(); cath++){ | |
241 | // Loop on cathodes: | |
242 | // necessary because strip info is read for each cathode | |
243 | // board info is read only from cathode 0 | |
244 | ||
245 | // loop over strips | |
246 | for (Int_t iStrip = 0; iStrip < 16; ++iStrip) { | |
247 | // get pad from electronics | |
248 | AliMpPad pad = seg[cath]->PadByLocation(AliMpIntPair(iBoard,iStrip),kFALSE); | |
249 | ||
250 | if (!pad.IsValid()) continue; | |
251 | ||
252 | xWidth = pad.Dimensions().X(); | |
253 | yWidth = pad.Dimensions().Y(); | |
254 | xcPad = sign * (pad.Position().X() + xOffsetLine); | |
255 | if(line==4) xcPad += 0.75 * sign * xWidthCol; | |
256 | ycPad = pad.Position().Y() + yOffsetLine; | |
257 | ||
258 | if(cath==iCath){ | |
259 | x1 = xcPad - xWidth + kShiftX; | |
260 | y1 = ycPad - yWidth + kShiftY; | |
261 | x2 = xcPad + xWidth - kShiftX; | |
262 | y2 = ycPad + yWidth - kShiftY; | |
263 | ||
264 | if(!inputHisto){ | |
265 | AddSortedPoint(x1, xAxisStrip, kResetValue); | |
266 | AddSortedPoint(x2, xAxisStrip, kResetValue); | |
267 | ||
268 | AddSortedPoint(y1, yAxisStrip, kResetValue); | |
269 | AddSortedPoint(y2, yAxisStrip, kResetValue); | |
270 | } | |
271 | else if(displayType==kDisplayStrips) | |
272 | FillBins(inputHisto, displayHisto, iBoard, iStrip, x1, x2, y1, y2, kShiftX, kShiftY, displayOpt); | |
273 | } | |
274 | ||
275 | if(cath==0){ | |
276 | if(iStrip==0) { | |
277 | x1b = xcPad - xWidth + kShiftEl; | |
278 | y1b = ycPad - yWidth + kShiftEl; | |
279 | } | |
280 | x2b = xcPad + xWidth - kShiftEl; | |
281 | y2b = ycPad + yWidth - kShiftEl; | |
282 | } | |
283 | } // loop on strips | |
284 | ||
285 | // if iCath==0 strip info and board info are both filled -> break! | |
286 | // if iCath==1 board info is filled at cath==0. Strip info to be filled at cath==1 | |
287 | if(iCath==0) break; | |
288 | } // loop on cathodes | |
289 | ||
290 | if(!inputHisto){ | |
291 | // Per board | |
292 | AddSortedPoint(x1b, xAxisBoard, kResetValue); | |
293 | AddSortedPoint(x2b, xAxisBoard, kResetValue); | |
294 | ||
295 | AddSortedPoint(y1b, yAxisBoard, kResetValue); | |
296 | AddSortedPoint(y2b, yAxisBoard, kResetValue); | |
297 | } | |
298 | else if(displayType==kDisplayBoards) | |
299 | FillBins(inputHisto, displayHisto, iBoard, -1, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt); | |
300 | else if(displayType==kDisplaySlats) | |
301 | FillBins(inputHisto, displayHisto, slat, -1, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt); | |
302 | } // loop on local boards | |
303 | ||
304 | if(inputHisto) return kTRUE; | |
305 | ||
306 | displayHisto->Reset(); | |
307 | ||
308 | // Book histos | |
309 | const Float_t kMinDiff = 0.1; | |
310 | ||
311 | TArrayD* currArray[4] = {&xAxisStrip, &yAxisStrip, | |
312 | &xAxisBoard, &yAxisBoard}; | |
313 | for(Int_t iaxis=0; iaxis<4; iaxis++){ | |
314 | Int_t ipoint=0; | |
315 | while(TMath::Abs((*currArray[iaxis])[ipoint]-kResetValue)>kMinDiff) { | |
316 | ipoint++; | |
317 | } | |
318 | if(ipoint>currArray[iaxis]->GetSize()-2) | |
319 | AliWarning(Form("Array size (%i) lower than the number of points!", currArray[iaxis]->GetSize())); | |
320 | currArray[iaxis]->Set(ipoint); | |
321 | } | |
322 | ||
323 | switch(displayType){ | |
324 | case kDisplayStrips: | |
325 | displayHisto->SetBins(xAxisStrip.GetSize()-1, xAxisStrip.GetArray(), | |
326 | yAxisStrip.GetSize()-1, yAxisStrip.GetArray()); | |
327 | break; | |
328 | case kDisplayBoards: | |
329 | case kDisplaySlats: | |
330 | displayHisto->SetBins(xAxisBoard.GetSize()-1, xAxisBoard.GetArray(), | |
331 | yAxisBoard.GetSize()-1, yAxisBoard.GetArray()); | |
332 | break; | |
333 | } | |
334 | ||
335 | displayHisto->SetName(displayHistoName.Data()); | |
336 | displayHisto->SetTitle(displayHistoTitle.Data()); | |
337 | displayHisto->SetXTitle("X (cm)"); | |
338 | displayHisto->SetYTitle("Y (cm)"); | |
339 | //displayHisto->SetStats(kFALSE); | |
340 | ||
341 | return kTRUE; | |
342 | } | |
343 | ||
344 | ||
345 | //____________________________________________________________________________ | |
346 | Bool_t AliMUONTriggerDisplay::AddSortedPoint(Float_t currVal, TArrayD& position, const Float_t kResetValue) | |
347 | { | |
348 | // | |
349 | /// Add sorted point in array according to an increasing order. | |
350 | /// Used to build display histograms axis. | |
351 | // | |
352 | Int_t nEntries = position.GetSize()-1; | |
353 | Float_t tmp1, tmp2; | |
354 | const Float_t kMinDiff = 0.1; | |
355 | for(Int_t i=0; i<nEntries; i++){ | |
356 | if(TMath::Abs(position[i]-currVal)<kMinDiff) return kFALSE; | |
357 | if(TMath::Abs(position[i]-kResetValue)<kMinDiff) { | |
358 | position[i] = currVal; | |
359 | return kTRUE; | |
360 | } | |
361 | if(currVal>position[i]) continue; | |
362 | tmp1 = position[i]; | |
363 | position[i] = currVal; | |
364 | for(Int_t j=i+1; j<nEntries; j++){ | |
365 | tmp2 = position[j]; | |
366 | position[j] = tmp1; | |
367 | tmp1 = tmp2; | |
368 | if(tmp1==kResetValue) break; | |
369 | } | |
370 | return kTRUE; | |
371 | } | |
372 | return kFALSE; | |
373 | } | |
374 | ||
375 | ||
376 | //____________________________________________________________________________ | |
377 | void AliMUONTriggerDisplay::FillBins(TH1* inputHisto, TH2* displayHisto, | |
378 | Int_t iElement1, Int_t iElement2, | |
379 | Float_t x1, Float_t x2, Float_t y1, Float_t y2, | |
380 | const Float_t kShiftX, const Float_t kShiftY, | |
381 | EDisplayOption displayOpt) | |
382 | { | |
383 | // | |
384 | /// Given the bin in inputHisto, search the corresponding bins | |
385 | /// in display histo and fill it. | |
386 | // | |
387 | TString className = inputHisto->ClassName(); | |
388 | Int_t binY=0; | |
389 | Float_t binContent=0; | |
390 | Int_t binX = inputHisto->GetXaxis()->FindBin(iElement1); | |
391 | if(className.Contains("2")) { | |
392 | binY = inputHisto->GetYaxis()->FindBin(iElement2); | |
393 | binContent = inputHisto->GetBinContent(binX, binY); | |
394 | } | |
395 | else binContent = inputHisto->GetBinContent(binX); | |
396 | ||
397 | if(binContent==0) { | |
398 | if(displayOpt==kShowZeroes) binContent = 1e-5; | |
399 | else return; | |
400 | } | |
401 | ||
402 | Int_t binX1 = displayHisto->GetXaxis()->FindBin(x1 + 0.01*kShiftX); | |
403 | Int_t binX2 = displayHisto->GetXaxis()->FindBin(x2 - 0.01*kShiftX); | |
404 | Int_t binY1 = displayHisto->GetYaxis()->FindBin(y1 + 0.01*kShiftY); | |
405 | Int_t binY2 = displayHisto->GetYaxis()->FindBin(y2 - 0.01*kShiftY); | |
406 | ||
407 | if(displayOpt==kNumbered) { | |
408 | Int_t meanBin = (binX1+binX2)/2; | |
409 | binX1 = meanBin; | |
410 | binX2 = meanBin; | |
411 | ||
412 | meanBin = (binY1+binY2)/2; | |
413 | binY1 = meanBin; | |
414 | binY2 = meanBin; | |
415 | } | |
416 | ||
417 | for(Int_t ibinx=binX1; ibinx<=binX2; ibinx++){ | |
418 | for(Int_t ibiny=binY1; ibiny<=binY2; ibiny++){ | |
419 | displayHisto->SetBinContent(ibinx,ibiny,binContent); | |
420 | } | |
421 | } | |
422 | } | |
423 |