]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerDisplay.cxx
ADC scale for SDD in simulation calibrated on real cosmic data (F. Prino)
[u/mrichter/AliRoot.git] / MUON / AliMUONTriggerDisplay.cxx
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
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
46 ClassImp(AliMUONTriggerDisplay)
47 /// \endcond
48            
49 //____________________________________________________________________________ 
50 AliMUONTriggerDisplay::AliMUONTriggerDisplay() : 
51 TObject()
52 {
53   /// ctor
54 }
55
56 //__________________________________________________________________
57 AliMUONTriggerDisplay::~AliMUONTriggerDisplay()
58 {
59   /// dtor
60 }
61
62
63 //____________________________________________________________________________ 
64 TH2* 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 //____________________________________________________________________________ 
82 TH2* 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 //____________________________________________________________________________ 
108 TH2* 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 //____________________________________________________________________________ 
125 Bool_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 //____________________________________________________________________________ 
139 Bool_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
248         Int_t offset = 0;
249         if (cath && localBoard->GetSwitch(6)) offset = -8;
250
251         AliMpPad pad = seg[cath]->PadByLocation(AliMpIntPair(iBoard,iStrip+offset),kFALSE);
252
253         if (!pad.IsValid()) continue;
254
255         xWidth = pad.Dimensions().X();
256         yWidth = pad.Dimensions().Y();
257         xcPad = sign * (pad.Position().X() + xOffsetLine);
258         if(line==4) xcPad += 0.75 * sign * xWidthCol;
259         ycPad = pad.Position().Y() + yOffsetLine;
260
261         if(cath==iCath){
262           x1 = xcPad - xWidth + kShiftX;
263           y1 = ycPad - yWidth + kShiftY;
264           x2 = xcPad + xWidth - kShiftX;
265           y2 = ycPad + yWidth - kShiftY;
266
267           if(!inputHisto){
268             AddSortedPoint(x1, xAxisStrip, kResetValue);
269             AddSortedPoint(x2, xAxisStrip, kResetValue);
270
271             AddSortedPoint(y1, yAxisStrip, kResetValue);
272             AddSortedPoint(y2, yAxisStrip, kResetValue);
273           }
274           else if(displayType==kDisplayStrips) 
275             FillBins(inputHisto, displayHisto, iBoard, iStrip, x1, x2, y1, y2, kShiftX, kShiftY, displayOpt);
276         }
277
278         if(cath==0){
279           if(iStrip+offset==0) {
280             x1b = xcPad - xWidth + kShiftEl;
281             y1b = ycPad - yWidth + kShiftEl;
282           }
283           x2b = xcPad + xWidth - kShiftEl;
284           y2b = ycPad + yWidth - kShiftEl;
285         }
286       } // loop on strips
287
288       // if iCath==0 strip info and board info are both filled -> break!
289       // if iCath==1 board info is filled at cath==0. Strip info to be filled at cath==1
290       if(iCath==0) break;
291     } // loop on cathodes
292
293     if(!inputHisto){
294       // Per board
295       AddSortedPoint(x1b, xAxisBoard, kResetValue);
296       AddSortedPoint(x2b, xAxisBoard, kResetValue);
297
298       AddSortedPoint(y1b, yAxisBoard, kResetValue);
299       AddSortedPoint(y2b, yAxisBoard, kResetValue);
300     }
301     else if(displayType==kDisplayBoards) 
302       FillBins(inputHisto, displayHisto, iBoard, -1, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
303     else if(displayType==kDisplaySlats) 
304       FillBins(inputHisto, displayHisto, slat, -1, x1b, x2b, y1b, y2b, kShiftEl, kShiftEl, displayOpt);
305   } // loop on local boards
306
307   if(inputHisto) return kTRUE;
308
309   displayHisto->Reset();
310
311   // Book histos
312   const Float_t kMinDiff = 0.1;
313
314   TArrayD* currArray[4] = {&xAxisStrip, &yAxisStrip, 
315                            &xAxisBoard, &yAxisBoard};
316   for(Int_t iaxis=0; iaxis<4; iaxis++){
317     Int_t ipoint=0;
318     while(TMath::Abs((*currArray[iaxis])[ipoint]-kResetValue)>kMinDiff) { 
319       ipoint++;
320     }
321     if(ipoint>currArray[iaxis]->GetSize()-2) 
322       AliWarning(Form("Array size (%i) lower than the number of points!", currArray[iaxis]->GetSize()));
323     currArray[iaxis]->Set(ipoint);
324   }
325
326   switch(displayType){
327   case kDisplayStrips:
328     displayHisto->SetBins(xAxisStrip.GetSize()-1, xAxisStrip.GetArray(),
329                           yAxisStrip.GetSize()-1, yAxisStrip.GetArray());
330     break;
331   case kDisplayBoards:
332   case kDisplaySlats:
333     displayHisto->SetBins(xAxisBoard.GetSize()-1, xAxisBoard.GetArray(),
334                           yAxisBoard.GetSize()-1, yAxisBoard.GetArray());
335     break;
336   }
337
338   displayHisto->SetName(displayHistoName.Data());
339   displayHisto->SetTitle(displayHistoTitle.Data());
340   displayHisto->SetXTitle("X (cm)");
341   displayHisto->SetYTitle("Y (cm)");
342   //displayHisto->SetStats(kFALSE);
343
344   return kTRUE;
345 }
346
347
348 //____________________________________________________________________________ 
349 Bool_t AliMUONTriggerDisplay::AddSortedPoint(Float_t currVal, TArrayD& position, const Float_t kResetValue)
350 {
351   //
352   /// Add sorted point in array according to an increasing order.
353   /// Used to build display histograms axis.
354   //
355   Int_t nEntries = position.GetSize()-1;
356   Float_t tmp1, tmp2;
357   const Float_t kMinDiff = 0.1;
358   for(Int_t i=0; i<nEntries; i++){
359     if(TMath::Abs(position[i]-currVal)<kMinDiff) return kFALSE;
360     if(TMath::Abs(position[i]-kResetValue)<kMinDiff) {
361       position[i] = currVal;
362       return kTRUE;
363     }
364     if(currVal>position[i]) continue;
365     tmp1 = position[i];
366     position[i] = currVal;
367     for(Int_t j=i+1; j<nEntries; j++){
368       tmp2 = position[j];
369       position[j] = tmp1;
370       tmp1 = tmp2;
371       if(tmp1==kResetValue) break;
372     }
373     return kTRUE;
374   }
375   return kFALSE;
376 }
377
378
379 //____________________________________________________________________________ 
380 void AliMUONTriggerDisplay::FillBins(TH1* inputHisto, TH2* displayHisto,
381                                      Int_t iElement1, Int_t iElement2,
382                                      Float_t x1, Float_t x2, Float_t y1, Float_t y2,
383                                      const Float_t kShiftX, const Float_t kShiftY,
384                                      EDisplayOption displayOpt)
385 {
386   //
387   /// Given the bin in inputHisto, search the corresponding bins
388   /// in display histo and fill it.
389   //
390   TString className = inputHisto->ClassName();
391   Int_t binY=0;
392   Float_t binContent=0;
393   Int_t binX = inputHisto->GetXaxis()->FindBin(iElement1);
394   if(className.Contains("2")) {
395     binY = inputHisto->GetYaxis()->FindBin(iElement2);
396     binContent = inputHisto->GetBinContent(binX, binY);
397   }
398   else binContent = inputHisto->GetBinContent(binX);
399
400   if(binContent==0) {
401     if(displayOpt==kShowZeroes) binContent = 1e-5;
402     else return;
403   }
404
405   Int_t binX1 = displayHisto->GetXaxis()->FindBin(x1 + 0.01*kShiftX);
406   Int_t binX2 = displayHisto->GetXaxis()->FindBin(x2 - 0.01*kShiftX);
407   Int_t binY1 = displayHisto->GetYaxis()->FindBin(y1 + 0.01*kShiftY);
408   Int_t binY2 = displayHisto->GetYaxis()->FindBin(y2 - 0.01*kShiftY);
409
410   if(displayOpt==kNumbered) {
411     Int_t meanBin = (binX1+binX2)/2;
412     binX1 = meanBin;
413     binX2 = meanBin;
414     
415     meanBin = (binY1+binY2)/2;
416     binY1 = meanBin;
417     binY2 = meanBin;
418   }
419
420   for(Int_t ibinx=binX1; ibinx<=binX2; ibinx++){
421     for(Int_t ibiny=binY1; ibiny<=binY2; ibiny++){
422       displayHisto->SetBinContent(ibinx,ibiny,binContent);
423     }
424   }
425 }
426