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 // --- MUON header files ---
19 #include "AliMUONTriggerDisplay.h"
21 #include "AliMpDDLStore.h"
22 #include "AliMpVSegmentation.h"
23 #include "AliMpSegmentation.h"
24 #include "AliMpConstants.h"
26 #include "AliMpLocalBoard.h"
29 // --- AliRoot header files ---
32 // --- ROOT system ---
37 //-----------------------------------------------------------------------------
38 /// \class AliMUONTriggerDisplay
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
44 /// Input histos can be given as:
45 /// - TH2 with x -> board # [1-234] and y -> strip # in board [0-15]. Option: kDisplayStrips
46 /// - TH1 with x -> board # [1-234] Option: kDisplayBoards
47 /// - TH1 with x -> slat # [0-17] Option: kDisplaySlats
52 ClassImp(AliMUONTriggerDisplay)
55 //____________________________________________________________________________
56 AliMUONTriggerDisplay::AliMUONTriggerDisplay() :
62 //__________________________________________________________________
63 AliMUONTriggerDisplay::~AliMUONTriggerDisplay()
69 //____________________________________________________________________________
70 TH2* AliMUONTriggerDisplay::GetEmptyDisplayHisto(TString displayHistoName, EDisplayType displayType,
71 Int_t cathode, Int_t chamber,
72 TString displayHistoTitle)
75 /// Return the display histogram with optimized binning
76 /// but do not fill it.
78 TH2F* displayHisto = new TH2F();
80 InitOrDisplayTriggerInfo(0x0, displayHisto, displayType,
81 cathode, chamber, displayHistoName, displayHistoTitle);
87 //____________________________________________________________________________
88 TH2* AliMUONTriggerDisplay::GetBoardNumberHisto(TString displayHistoName,
90 TString displayHistoTitle)
93 /// Return the display histogram with optimized binning
94 /// and fill it with the board number
97 const Int_t kNboards = AliMpConstants::NofLocalBoards();
98 TH1F* inputHisto = new TH1F("boardNumbers","Board Numbers",kNboards,0.5,(Float_t)kNboards + 0.5);
99 for(Int_t ibin=1; ibin<=kNboards; ibin++){
100 inputHisto->Fill(ibin,ibin);
103 TH2F* displayHisto = (TH2F*)GetEmptyDisplayHisto(displayHistoName, kDisplayBoards, 0, chamber, displayHistoTitle);
104 FillDisplayHistogram(inputHisto,displayHisto,kDisplayBoards,0,chamber,kNumbered);
108 displayHisto->SetStats(kFALSE);
113 //____________________________________________________________________________
114 TH2* AliMUONTriggerDisplay::GetDisplayHistogram(TH1* inputHisto, TString displayHistoName,
115 EDisplayType displayType, Int_t cathode,
116 Int_t chamber, TString displayHistoTitle,
117 EDisplayOption displayOpt)
120 /// Get histogram displaying the information contained in the input histogram
122 TH2* displayHisto = GetEmptyDisplayHisto(displayHistoName, displayType,
123 cathode, chamber, displayHistoTitle);
125 FillDisplayHistogram(inputHisto, displayHisto, displayType, cathode, chamber, displayOpt);
130 //____________________________________________________________________________
131 TH2* AliMUONTriggerDisplay::GetDisplayHistogram(TGraph* inputGraph, TString displayHistoName,
132 EDisplayType displayType, Int_t cathode,
133 Int_t chamber, TString displayHistoTitle,
134 EDisplayOption displayOpt)
137 /// Get histogram displaying the information contained in the input graph
139 TH2* displayHisto = GetEmptyDisplayHisto(displayHistoName, displayType,
140 cathode, chamber, displayHistoTitle);
142 FillDisplayHistogram(inputGraph, displayHisto, displayType, cathode, chamber, displayOpt);
147 //____________________________________________________________________________
148 Bool_t AliMUONTriggerDisplay::FillDisplayHistogram(TH1* inputHisto, TH2* displayHisto,
149 EDisplayType displayType, Int_t cathode,
150 Int_t chamber, EDisplayOption displayOpt)
153 /// Fill a previously initialized display histogram
154 /// with the information contained in inputHisto.
155 /// To get initialized display, please use GetEmptyDisplayHisto method
157 return InitOrDisplayTriggerInfo(inputHisto, displayHisto, displayType,
158 cathode, chamber, "", "",displayOpt);
161 //____________________________________________________________________________
162 Bool_t AliMUONTriggerDisplay::FillDisplayHistogram(TGraph* inputGraph, TH2* displayHisto,
163 EDisplayType displayType, Int_t cathode,
164 Int_t chamber, EDisplayOption displayOpt)
167 /// Fill a previously initialized display histogram
168 /// with the information contained in inputGraph.
169 /// To get initialized display, please use GetEmptyDisplayHisto method
171 return InitOrDisplayTriggerInfo(inputGraph, displayHisto, displayType,
172 cathode, chamber, "", "",displayOpt);
175 //____________________________________________________________________________
176 Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TObject* inputObject, TH2* displayHisto,
177 EDisplayType displayType,
178 Int_t cathode, Int_t chamber,
179 TString displayHistoName, TString displayHistoTitle,
180 EDisplayOption displayOpt)
183 /// Initialize trigger information display histograms using mapping
184 /// Trigger information is displayed in a user-friendly way:
185 /// from local board and strip numbers to their position on chambers.
189 if ( ! AliMpSegmentation::Instance(kFALSE) ) {
191 if ( ! AliMpCDB::LoadDDLStore() ) {
192 AliError("Could not access mapping from OCDB !");
193 AliError("Histograms are not initialized !");
198 Int_t iCh = (chamber > AliMpConstants::NofTrackingChambers()) ? chamber - 11 : chamber;
199 Int_t iCath = cathode;
206 Float_t yOffsetLine, xOffsetLine = 0.;
208 const Float_t kResetValue=1234567.;
212 xAxisBoard.Reset(kResetValue);
214 yAxisBoard.Reset(kResetValue);
217 xAxisStrip.Reset(kResetValue);
219 yAxisStrip.Reset(kResetValue);
221 else if(!displayHisto){
222 AliWarning("Display histogram not initialized. Please initialize it first!");
226 TH1* inputHisto = dynamic_cast<TH1*>(inputObject);
228 if ( inputHisto->GetEntries() == 0 ) {
233 TGraph* inputGraph = dynamic_cast<TGraph*>(inputObject);
235 if ( inputGraph->GetN() == 0 ){
240 AliWarning("The object should inherit from TH1 or TGraph!");
246 Float_t xWidth, yWidth, yWidthSlat=0., xWidthCol=0.;
248 Float_t x1b=0., x2b=0., y1b=0., y2b=0.;
249 Float_t xcPad, ycPad;
253 const Float_t kShiftB = 0.5;
254 const Float_t kShiftS = 0.1;
256 const Float_t kShiftX = (iCath==0) ? kShiftB : kShiftS;
257 const Float_t kShiftY = (iCath==0) ? kShiftS : kShiftB;
258 const Float_t kShiftEl = (displayType==kDisplaySlats) ? 0.01 : kShiftB;
260 Int_t iChamber = iCh + AliMpConstants::NofTrackingChambers();
261 for(Int_t iLoc = 0; iLoc < AliMpConstants::NofLocalBoards(); iLoc++) {
262 Int_t iBoard = iLoc+1;
263 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromLocalBoard(iBoard, iChamber);
265 if (!detElemId) continue;
267 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(iBoard, kFALSE);
270 if( !localBoard->IsNotified())
274 const AliMpVSegmentation* seg[2] = {
275 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(0)),
276 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(1))};
279 AliMpPad pad1 = seg[1]->PadByLocation(iBoard,0,kFALSE);
280 yWidthSlat = pad1.GetDimensionY();
281 AliMpPad pad0 = seg[0]->PadByLocation(iBoard,0,kFALSE);
282 xOffsetLine = TMath::Abs(pad0.GetPositionX()) + pad0.GetDimensionX();
283 xWidthCol = 2.* pad0.GetDimensionX();
286 // Get ideal global position of DetElemId center
287 slat = detElemId%100;
288 line = (4 + slat)%18;
294 yOffsetLine = (Float_t)(line - 4) * 2. * yWidthSlat;
296 Int_t nLocations = 1;
298 for(Int_t cath=0; cath<AliMpConstants::NofCathodes(); cath++){
300 // necessary because strip info is read for each cathode
301 // board info is read only from cathode 0
304 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
305 // get pad from electronics
308 if (cath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
310 AliMpPad pad = seg[cath]->PadByLocation(iBoard,ibitxy+offset,kFALSE);
312 if (!pad.IsValid()) continue;
314 // For non-bending plane fill only the first board covered by the strip
315 // i.e. avoide filling many times the same information
316 if ( cath == 1 && pad.GetLocalBoardId(0) != iBoard ) continue;
318 xWidth = pad.GetDimensionX();
319 yWidth = pad.GetDimensionY();
320 xcPad = sign * (pad.GetPositionX() + xOffsetLine);
321 if(line==4) xcPad += 0.75 * sign * xWidthCol;
322 ycPad = pad.GetPositionY() + yOffsetLine;
323 nLocations = pad.GetNofLocations();
324 Int_t iStrip = pad.GetLocalBoardChannel(0);
327 x1 = xcPad - xWidth + kShiftX;
328 y1 = ycPad - yWidth + kShiftY;
329 x2 = xcPad + xWidth - kShiftX;
330 y2 = ycPad + yWidth - kShiftY;
333 AddSortedPoint(x1, xAxisStrip, kResetValue);
334 AddSortedPoint(x2, xAxisStrip, kResetValue);
336 AddSortedPoint(y1, yAxisStrip, kResetValue);
337 AddSortedPoint(y2, yAxisStrip, kResetValue);
339 else if(displayType==kDisplayStrips)
340 FillBins(inputObject, displayHisto, iBoard, iStrip, x1, x2, y1, y2, kShiftX, kShiftY, displayOpt);
345 x1b = xcPad - xWidth + kShiftEl;
346 y1b = ycPad - yWidth + kShiftEl;
348 x2b = xcPad + xWidth - kShiftEl;
349 y2b = ycPad + yWidth - kShiftEl;
354 // if iCath==0 strip info and board info are both filled -> break!
355 // if iCath==1 board info is filled at cath==0. Strip info to be filled at cath==1
357 } // loop on cathodes
361 AddSortedPoint(x1b, xAxisBoard, kResetValue);
362 AddSortedPoint(x2b, xAxisBoard, kResetValue);
364 AddSortedPoint(y1b, yAxisBoard, kResetValue);
365 AddSortedPoint(y2b, yAxisBoard, kResetValue);
367 else if(displayType==kDisplayBoards)
368 FillBins(inputObject, displayHisto, iBoard, -nLocations, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
369 else if(displayType==kDisplaySlats)
370 FillBins(inputObject, displayHisto, slat, -1, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
371 } // loop on local boards
373 if ( inputObject ) return kTRUE;
375 displayHisto->Reset();
378 const Float_t kMinDiff = 0.1;
380 TArrayD* currArray[4] = {&xAxisStrip, &yAxisStrip,
381 &xAxisBoard, &yAxisBoard};
382 for(Int_t iaxis=0; iaxis<4; iaxis++){
384 while(TMath::Abs((*currArray[iaxis])[ipoint]-kResetValue)>kMinDiff) {
387 if(ipoint>currArray[iaxis]->GetSize()-2)
388 AliWarning(Form("Array size (%i) lower than the number of points!", currArray[iaxis]->GetSize()));
389 currArray[iaxis]->Set(ipoint);
394 displayHisto->SetBins(xAxisStrip.GetSize()-1, xAxisStrip.GetArray(),
395 yAxisStrip.GetSize()-1, yAxisStrip.GetArray());
399 displayHisto->SetBins(xAxisBoard.GetSize()-1, xAxisBoard.GetArray(),
400 yAxisBoard.GetSize()-1, yAxisBoard.GetArray());
404 displayHisto->SetName(displayHistoName.Data());
405 displayHisto->SetTitle(displayHistoTitle.Data());
406 displayHisto->SetXTitle("X (cm)");
407 displayHisto->SetYTitle("Y (cm)");
408 //displayHisto->SetStats(kFALSE);
414 //____________________________________________________________________________
415 Bool_t AliMUONTriggerDisplay::AddSortedPoint(Float_t currVal, TArrayD& position, const Float_t kResetValue)
418 /// Add sorted point in array according to an increasing order.
419 /// Used to build display histograms axis.
421 Int_t nEntries = position.GetSize()-1;
423 const Float_t kMinDiff = 0.1;
424 for(Int_t i=0; i<nEntries; i++){
425 if(TMath::Abs(position[i]-currVal)<kMinDiff) return kFALSE;
426 if(TMath::Abs(position[i]-kResetValue)<kMinDiff) {
427 position[i] = currVal;
430 if(currVal>position[i]) continue;
432 position[i] = currVal;
433 for(Int_t j=i+1; j<nEntries; j++){
437 if(tmp1==kResetValue) break;
445 //____________________________________________________________________________
446 void AliMUONTriggerDisplay::FillBins(TObject* inputObject, TH2* displayHisto,
447 Int_t iElement1, Int_t iElement2,
448 Float_t x1, Float_t x2, Float_t y1, Float_t y2,
449 const Float_t kShiftX, const Float_t kShiftY,
450 EDisplayOption displayOpt)
453 /// Given the bin in inputHisto, search the corresponding bins
454 /// in display histo and fill it.
457 Float_t binContent=0;
458 TH1* inputHisto = dynamic_cast<TH1*>(inputObject);
460 Int_t binX = inputHisto->GetXaxis()->FindBin(iElement1);
461 if ( inputObject->IsA()->InheritsFrom("TH2") ) {
462 binY = inputHisto->GetYaxis()->FindBin(iElement2);
463 binContent = inputHisto->GetBinContent(binX, binY);
465 else binContent = inputHisto->GetBinContent(binX);
468 TGraph* inputGraph = dynamic_cast<TGraph*>(inputObject);
471 for ( Int_t ipt=0; ipt<inputGraph->GetN(); ipt++){
472 inputGraph->GetPoint(ipt, xpt, ypt);
473 if ( TMath::Abs(xpt - iElement1) < 0.1 ) {
483 if(displayOpt==kShowZeroes) binContent = 1e-5;
487 Int_t binX1 = displayHisto->GetXaxis()->FindBin(x1 + 0.01*kShiftX);
488 Int_t binX2 = displayHisto->GetXaxis()->FindBin(x2 - 0.01*kShiftX);
489 Int_t binY1 = displayHisto->GetYaxis()->FindBin(y1 + 0.01*kShiftY);
490 Int_t binY2 = displayHisto->GetYaxis()->FindBin(y2 - 0.01*kShiftY);
492 if(displayOpt==kNumbered) {
493 Int_t meanBin = (binX1+binX2)/2;
497 meanBin = (binY1+binY2)/2;
502 Float_t elementArea = 1.;
503 if(displayOpt == kNormalizeToArea) {
504 elementArea = (x2 - x1 + 2*kShiftX) *
505 (y2 - y1 + 2*kShiftY); // In InitOrDisplayTriggerInfo:
506 // x2 = x_c + xHalfWidth - kShiftX
507 // x1 = x_c - xHalfWidth + kShiftX
508 // so x2 - x1 + 2*kShiftX returns the element width.
510 // If iElement2 is less than 0, then its meaning is the
511 // number of boards covered by one strip
512 // the area has therefore to be multiplied accordingly
513 // This fixes the problem when filling the trigger rate per boards in non-bending plane
514 // which is overestimated since the segmentation is always given by the bending-plane
515 if ( iElement2 < 0 ) elementArea *= -(Double_t)iElement2;
519 for(Int_t ibinx=binX1; ibinx<=binX2; ibinx++){
520 for(Int_t ibiny=binY1; ibiny<=binY2; ibiny++){
521 displayHisto->SetBinContent(ibinx,ibiny,binContent/elementArea);