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