]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONTriggerDisplay.cxx
Added analysis of fakes (Francesco)
[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>
f3d288ab 35#include <TGraph.h>
aef183f7 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
49e110ec 42/// trigger chamber.
43///
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
aef183f7 48///
49/// \author D. Stocco
50
51/// \cond CLASSIMP
52ClassImp(AliMUONTriggerDisplay)
53/// \endcond
54
55//____________________________________________________________________________
56AliMUONTriggerDisplay::AliMUONTriggerDisplay() :
57TObject()
58{
59 /// ctor
60}
61
62//__________________________________________________________________
63AliMUONTriggerDisplay::~AliMUONTriggerDisplay()
64{
65 /// dtor
66}
67
68
69//____________________________________________________________________________
70TH2* AliMUONTriggerDisplay::GetEmptyDisplayHisto(TString displayHistoName, EDisplayType displayType,
71 Int_t cathode, Int_t chamber,
72 TString displayHistoTitle)
73{
74 //
75 /// Return the display histogram with optimized binning
76 /// but do not fill it.
77 //
78 TH2F* displayHisto = new TH2F();
79
80 InitOrDisplayTriggerInfo(0x0, displayHisto, displayType,
81 cathode, chamber, displayHistoName, displayHistoTitle);
82
83 return displayHisto;
84}
85
86
87//____________________________________________________________________________
88TH2* AliMUONTriggerDisplay::GetBoardNumberHisto(TString displayHistoName,
89 Int_t chamber,
90 TString displayHistoTitle)
91{
92 //
93 /// Return the display histogram with optimized binning
94 /// and fill it with the board number
95 //
96
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);
101 }
102
103 TH2F* displayHisto = (TH2F*)GetEmptyDisplayHisto(displayHistoName, kDisplayBoards, 0, chamber, displayHistoTitle);
104 FillDisplayHistogram(inputHisto,displayHisto,kDisplayBoards,0,chamber,kNumbered);
105
106 delete inputHisto;
107
108 displayHisto->SetStats(kFALSE);
109 return displayHisto;
110}
111
112
113//____________________________________________________________________________
114TH2* AliMUONTriggerDisplay::GetDisplayHistogram(TH1* inputHisto, TString displayHistoName,
115 EDisplayType displayType, Int_t cathode,
116 Int_t chamber, TString displayHistoTitle,
117 EDisplayOption displayOpt)
118{
119 //
120 /// Get histogram displaying the information contained in the input histogram
121 //
122 TH2* displayHisto = GetEmptyDisplayHisto(displayHistoName, displayType,
123 cathode, chamber, displayHistoTitle);
124
125 FillDisplayHistogram(inputHisto, displayHisto, displayType, cathode, chamber, displayOpt);
126
127 return displayHisto;
128}
129
f3d288ab 130//____________________________________________________________________________
131TH2* AliMUONTriggerDisplay::GetDisplayHistogram(TGraph* inputGraph, TString displayHistoName,
132 EDisplayType displayType, Int_t cathode,
133 Int_t chamber, TString displayHistoTitle,
134 EDisplayOption displayOpt)
135{
136 //
137 /// Get histogram displaying the information contained in the input graph
138 //
139 TH2* displayHisto = GetEmptyDisplayHisto(displayHistoName, displayType,
140 cathode, chamber, displayHistoTitle);
141
142 FillDisplayHistogram(inputGraph, displayHisto, displayType, cathode, chamber, displayOpt);
143
144 return displayHisto;
145}
146
aef183f7 147//____________________________________________________________________________
148Bool_t AliMUONTriggerDisplay::FillDisplayHistogram(TH1* inputHisto, TH2* displayHisto,
149 EDisplayType displayType, Int_t cathode,
150 Int_t chamber, EDisplayOption displayOpt)
151{
152 //
153 /// Fill a previously initialized display histogram
154 /// with the information contained in inputHisto.
155 /// To get initialized display, please use GetEmptyDisplayHisto method
156 //
157 return InitOrDisplayTriggerInfo(inputHisto, displayHisto, displayType,
158 cathode, chamber, "", "",displayOpt);
159}
160
161//____________________________________________________________________________
f3d288ab 162Bool_t AliMUONTriggerDisplay::FillDisplayHistogram(TGraph* inputGraph, TH2* displayHisto,
163 EDisplayType displayType, Int_t cathode,
164 Int_t chamber, EDisplayOption displayOpt)
165{
166 //
167 /// Fill a previously initialized display histogram
168 /// with the information contained in inputGraph.
169 /// To get initialized display, please use GetEmptyDisplayHisto method
170 //
171 return InitOrDisplayTriggerInfo(inputGraph, displayHisto, displayType,
172 cathode, chamber, "", "",displayOpt);
173}
174
175//____________________________________________________________________________
176Bool_t AliMUONTriggerDisplay::InitOrDisplayTriggerInfo(TObject* inputObject, TH2* displayHisto,
aef183f7 177 EDisplayType displayType,
178 Int_t cathode, Int_t chamber,
179 TString displayHistoName, TString displayHistoTitle,
180 EDisplayOption displayOpt)
181{
182 //
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.
186 //
187
188 // Load mapping
189 if ( ! AliMpSegmentation::Instance(kFALSE) ) {
190 /// Load mapping
191 if ( ! AliMpCDB::LoadDDLStore() ) {
192 AliError("Could not access mapping from OCDB !");
193 AliError("Histograms are not initialized !");
194 return kFALSE;
195 }
196 }
197
198 Int_t iCh = (chamber > AliMpConstants::NofTrackingChambers()) ? chamber - 11 : chamber;
199 Int_t iCath = cathode;
200
201 TArrayD xAxisStrip;
202 TArrayD yAxisStrip;
203 TArrayD xAxisBoard;
204 TArrayD yAxisBoard;
205
206 Float_t yOffsetLine, xOffsetLine = 0.;
207
208 const Float_t kResetValue=1234567.;
209
f3d288ab 210 if(!inputObject){
aef183f7 211 xAxisBoard.Set(55);
212 xAxisBoard.Reset(kResetValue);
213 yAxisBoard.Set(50);
214 yAxisBoard.Reset(kResetValue);
215
216 xAxisStrip.Set(420);
217 xAxisStrip.Reset(kResetValue);
218 yAxisStrip.Set(710);
219 yAxisStrip.Reset(kResetValue);
220 }
221 else if(!displayHisto){
222 AliWarning("Display histogram not initialized. Please initialize it first!");
223 return kFALSE;
224 }
f3d288ab 225 else {
226 TH1* inputHisto = dynamic_cast<TH1*>(inputObject);
227 if ( inputHisto ) {
228 if ( inputHisto->GetEntries() == 0 ) {
229 return kTRUE;
230 }
231 }
232 else {
233 TGraph* inputGraph = dynamic_cast<TGraph*>(inputObject);
32ceb7fa 234 if ( inputGraph ) {
235 if ( inputGraph->GetN() == 0 ){
236 return kTRUE;
237 }
238 }
239 else {
240 AliWarning("The object should inherit from TH1 or TGraph!");
241 return kFALSE;
f3d288ab 242 }
243 }
719914e0 244 }
aef183f7 245
246 Float_t xWidth, yWidth, yWidthSlat=0., xWidthCol=0.;
247 Float_t x1,x2,y1,y2;
248 Float_t x1b=0., x2b=0., y1b=0., y2b=0.;
249 Float_t xcPad, ycPad;
250 Int_t line=0, slat;
251 Float_t sign = 1.;
252
253 const Float_t kShiftB = 0.5;
254 const Float_t kShiftS = 0.1;
255
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;
259
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);
264
265 if (!detElemId) continue;
266
267 AliMpLocalBoard* localBoard = AliMpDDLStore::Instance()->GetLocalBoard(iBoard, kFALSE);
268
269 // skip copy cards
270 if( !localBoard->IsNotified())
271 continue;
272
273 // get segmentation
274 const AliMpVSegmentation* seg[2] = {
275 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(0)),
276 AliMpSegmentation::Instance()->GetMpSegmentation(detElemId, AliMp::GetCathodType(1))};
277
278 if(iLoc==0){
168e9c4d 279 AliMpPad pad1 = seg[1]->PadByLocation(iBoard,0,kFALSE);
6e97fbb8 280 yWidthSlat = pad1.GetDimensionY();
168e9c4d 281 AliMpPad pad0 = seg[0]->PadByLocation(iBoard,0,kFALSE);
6e97fbb8 282 xOffsetLine = TMath::Abs(pad0.GetPositionX()) + pad0.GetDimensionX();
283 xWidthCol = 2.* pad0.GetDimensionX();
aef183f7 284 }
285
286 // Get ideal global position of DetElemId center
287 slat = detElemId%100;
288 line = (4 + slat)%18;
289 sign = 1.;
290 if(line>8) {
291 line = 17 - line;
292 sign = -1.;
293 }
294 yOffsetLine = (Float_t)(line - 4) * 2. * yWidthSlat;
616d91d8 295
296 Int_t nLocations = 1;
aef183f7 297
298 for(Int_t cath=0; cath<AliMpConstants::NofCathodes(); cath++){
299 // Loop on cathodes:
300 // necessary because strip info is read for each cathode
301 // board info is read only from cathode 0
302
303 // loop over strips
616d91d8 304 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy) {
aef183f7 305 // get pad from electronics
32f0a7ea 306
307 Int_t offset = 0;
dc5d3949 308 if (cath && localBoard->GetSwitch(AliMpLocalBoard::kZeroAllYLSB)) offset = -8;
32f0a7ea 309
616d91d8 310 AliMpPad pad = seg[cath]->PadByLocation(iBoard,ibitxy+offset,kFALSE);
aef183f7 311
312 if (!pad.IsValid()) continue;
313
6e97fbb8 314 xWidth = pad.GetDimensionX();
315 yWidth = pad.GetDimensionY();
316 xcPad = sign * (pad.GetPositionX() + xOffsetLine);
aef183f7 317 if(line==4) xcPad += 0.75 * sign * xWidthCol;
6e97fbb8 318 ycPad = pad.GetPositionY() + yOffsetLine;
616d91d8 319 nLocations = pad.GetNofLocations();
320 Int_t iStrip = pad.GetLocalBoardChannel(0);
aef183f7 321
322 if(cath==iCath){
323 x1 = xcPad - xWidth + kShiftX;
324 y1 = ycPad - yWidth + kShiftY;
325 x2 = xcPad + xWidth - kShiftX;
326 y2 = ycPad + yWidth - kShiftY;
327
f3d288ab 328 if(!inputObject){
aef183f7 329 AddSortedPoint(x1, xAxisStrip, kResetValue);
330 AddSortedPoint(x2, xAxisStrip, kResetValue);
331
332 AddSortedPoint(y1, yAxisStrip, kResetValue);
333 AddSortedPoint(y2, yAxisStrip, kResetValue);
334 }
335 else if(displayType==kDisplayStrips)
f3d288ab 336 FillBins(inputObject, displayHisto, iBoard, iStrip, x1, x2, y1, y2, kShiftX, kShiftY, displayOpt);
aef183f7 337 }
338
339 if(cath==0){
616d91d8 340 if(iStrip==0) {
aef183f7 341 x1b = xcPad - xWidth + kShiftEl;
342 y1b = ycPad - yWidth + kShiftEl;
343 }
344 x2b = xcPad + xWidth - kShiftEl;
345 y2b = ycPad + yWidth - kShiftEl;
346 }
616d91d8 347
aef183f7 348 } // loop on strips
349
350 // if iCath==0 strip info and board info are both filled -> break!
351 // if iCath==1 board info is filled at cath==0. Strip info to be filled at cath==1
352 if(iCath==0) break;
353 } // loop on cathodes
354
f3d288ab 355 if(!inputObject){
aef183f7 356 // Per board
357 AddSortedPoint(x1b, xAxisBoard, kResetValue);
358 AddSortedPoint(x2b, xAxisBoard, kResetValue);
359
360 AddSortedPoint(y1b, yAxisBoard, kResetValue);
361 AddSortedPoint(y2b, yAxisBoard, kResetValue);
362 }
363 else if(displayType==kDisplayBoards)
616d91d8 364 FillBins(inputObject, displayHisto, iBoard, -nLocations, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
aef183f7 365 else if(displayType==kDisplaySlats)
f3d288ab 366 FillBins(inputObject, displayHisto, slat, -1, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
aef183f7 367 } // loop on local boards
368
f3d288ab 369 if ( inputObject ) return kTRUE;
aef183f7 370
371 displayHisto->Reset();
372
373 // Book histos
374 const Float_t kMinDiff = 0.1;
375
376 TArrayD* currArray[4] = {&xAxisStrip, &yAxisStrip,
377 &xAxisBoard, &yAxisBoard};
378 for(Int_t iaxis=0; iaxis<4; iaxis++){
379 Int_t ipoint=0;
380 while(TMath::Abs((*currArray[iaxis])[ipoint]-kResetValue)>kMinDiff) {
381 ipoint++;
382 }
383 if(ipoint>currArray[iaxis]->GetSize()-2)
384 AliWarning(Form("Array size (%i) lower than the number of points!", currArray[iaxis]->GetSize()));
385 currArray[iaxis]->Set(ipoint);
386 }
387
388 switch(displayType){
389 case kDisplayStrips:
390 displayHisto->SetBins(xAxisStrip.GetSize()-1, xAxisStrip.GetArray(),
391 yAxisStrip.GetSize()-1, yAxisStrip.GetArray());
392 break;
393 case kDisplayBoards:
394 case kDisplaySlats:
395 displayHisto->SetBins(xAxisBoard.GetSize()-1, xAxisBoard.GetArray(),
396 yAxisBoard.GetSize()-1, yAxisBoard.GetArray());
397 break;
398 }
399
400 displayHisto->SetName(displayHistoName.Data());
401 displayHisto->SetTitle(displayHistoTitle.Data());
402 displayHisto->SetXTitle("X (cm)");
403 displayHisto->SetYTitle("Y (cm)");
404 //displayHisto->SetStats(kFALSE);
405
406 return kTRUE;
407}
408
409
410//____________________________________________________________________________
411Bool_t AliMUONTriggerDisplay::AddSortedPoint(Float_t currVal, TArrayD& position, const Float_t kResetValue)
412{
413 //
414 /// Add sorted point in array according to an increasing order.
415 /// Used to build display histograms axis.
416 //
417 Int_t nEntries = position.GetSize()-1;
418 Float_t tmp1, tmp2;
419 const Float_t kMinDiff = 0.1;
420 for(Int_t i=0; i<nEntries; i++){
421 if(TMath::Abs(position[i]-currVal)<kMinDiff) return kFALSE;
422 if(TMath::Abs(position[i]-kResetValue)<kMinDiff) {
423 position[i] = currVal;
424 return kTRUE;
425 }
426 if(currVal>position[i]) continue;
427 tmp1 = position[i];
428 position[i] = currVal;
429 for(Int_t j=i+1; j<nEntries; j++){
430 tmp2 = position[j];
431 position[j] = tmp1;
432 tmp1 = tmp2;
433 if(tmp1==kResetValue) break;
434 }
435 return kTRUE;
436 }
437 return kFALSE;
438}
439
440
441//____________________________________________________________________________
f3d288ab 442void AliMUONTriggerDisplay::FillBins(TObject* inputObject, TH2* displayHisto,
aef183f7 443 Int_t iElement1, Int_t iElement2,
444 Float_t x1, Float_t x2, Float_t y1, Float_t y2,
445 const Float_t kShiftX, const Float_t kShiftY,
446 EDisplayOption displayOpt)
447{
448 //
449 /// Given the bin in inputHisto, search the corresponding bins
450 /// in display histo and fill it.
451 //
aef183f7 452 Int_t binY=0;
453 Float_t binContent=0;
32ceb7fa 454 TH1* inputHisto = dynamic_cast<TH1*>(inputObject);
455 if ( inputHisto ) {
f3d288ab 456 Int_t binX = inputHisto->GetXaxis()->FindBin(iElement1);
32ceb7fa 457 if ( inputObject->IsA()->InheritsFrom("TH2") ) {
f3d288ab 458 binY = inputHisto->GetYaxis()->FindBin(iElement2);
459 binContent = inputHisto->GetBinContent(binX, binY);
460 }
461 else binContent = inputHisto->GetBinContent(binX);
462 }
463 else {
464 TGraph* inputGraph = dynamic_cast<TGraph*>(inputObject);
32ceb7fa 465 if ( inputGraph ) {
466 Double_t xpt, ypt;
467 for ( Int_t ipt=0; ipt<inputGraph->GetN(); ipt++){
468 inputGraph->GetPoint(ipt, xpt, ypt);
469 if ( TMath::Abs(xpt - iElement1) < 0.1 ) {
470 binContent = ypt;
471 break;
472 }
f3d288ab 473 }
474 }
32ceb7fa 475 else return;
476 }
aef183f7 477
478 if(binContent==0) {
479 if(displayOpt==kShowZeroes) binContent = 1e-5;
480 else return;
481 }
482
483 Int_t binX1 = displayHisto->GetXaxis()->FindBin(x1 + 0.01*kShiftX);
484 Int_t binX2 = displayHisto->GetXaxis()->FindBin(x2 - 0.01*kShiftX);
485 Int_t binY1 = displayHisto->GetYaxis()->FindBin(y1 + 0.01*kShiftY);
486 Int_t binY2 = displayHisto->GetYaxis()->FindBin(y2 - 0.01*kShiftY);
487
488 if(displayOpt==kNumbered) {
489 Int_t meanBin = (binX1+binX2)/2;
490 binX1 = meanBin;
491 binX2 = meanBin;
492
493 meanBin = (binY1+binY2)/2;
494 binY1 = meanBin;
495 binY2 = meanBin;
496 }
497
719914e0 498 Float_t elementArea = 1.;
499 if(displayOpt == kNormalizeToArea) {
500 elementArea = (x2 - x1 + 2*kShiftX) *
501 (y2 - y1 + 2*kShiftY); // In InitOrDisplayTriggerInfo:
502 // x2 = x_c + xHalfWidth - kShiftX
503 // x1 = x_c - xHalfWidth + kShiftX
504 // so x2 - x1 + 2*kShiftX returns the element width.
616d91d8 505
506 // If iElement2 is less than 0, then its meaning is the
507 // number of boards covered by one strip
508 // the area has therefore to be multiplied accordingly
509 // This fixes the problem when filling the trigger rate per boards in non-bending plane
510 // which is overestimated since the segmentation is always given by the bending-plane
511 if ( iElement2 < 0 ) elementArea *= -(Double_t)iElement2;
719914e0 512
513 }
514
aef183f7 515 for(Int_t ibinx=binX1; ibinx<=binX2; ibinx++){
516 for(Int_t ibiny=binY1; ibiny<=binY2; ibiny++){
719914e0 517 displayHisto->SetBinContent(ibinx,ibiny,binContent/elementArea);
aef183f7 518 }
519 }
520}
521