]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPadStatusMapMaker.cxx
Removed unused variables
[u/mrichter/AliRoot.git] / MUON / AliMUONPadStatusMapMaker.cxx
CommitLineData
2c780493 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/// \class AliMUONPadStatusMapMaker
18///
19/// Convert a pad status container into a pad status *map* container
20///
21/// A pad status is one 32-bits word describing whether this pad pedestal, gains
22/// hv is correct or not.
23///
24/// A pad status *map* is one 32-bits (of which 24 only are used)
25/// word describing whether this pad neighbours are ok or not
26/// (whether a pad is ok or not is determined by applying a given
27/// bitmask to the pad status word). Each bit in this word is related to one
28/// neighbour, assuming the pad itself is at bit 0
29///
30/// ----------------
31/// | 3 | 5 | 8 |
32/// ----------------
33/// | 2 | 0 | 7 |
34/// ----------------
35/// | 1 | 4 | 6 |
36/// ----------------
37///
38/// Note that for instance in NonBending plane of slats, at the boundaries
39/// between two pad densities, the pictures is a bit different, e.g.
40/// (bits in () are always zero)
41///
42/// so some care must be taken when designing a mask to be tested ;-) if you
43/// want to go farther than immediate neighbours...
44///
45/// If a pad is at a physical boundary, is will for sure have some bits at 1
46/// (i.e. a non-existing neighbour is considered = bad).
47///
48// author Laurent Aphecetche
49
50#include "AliMUONPadStatusMapMaker.h"
51
52#include "AliLog.h"
53#include "AliMUONCalibParam1I.h"
54#include "AliMUONObjectPair.h"
55#include "AliMUONV2DStore.h"
56#include "AliMUONVCalibParam.h"
57#include "AliMUONVDataIterator.h"
58#include "AliMpArea.h"
59#include "AliMpConstants.h"
60#include "AliMpDEManager.h"
61#include "AliMpPad.h"
62#include "AliMpSegmentation.h"
63#include "AliMpStationType.h"
64#include "AliMpVPadIterator.h"
65#include "AliMpVSegmentation.h"
66#include "Riostream.h"
67#include "TMath.h"
68#include "TObjArray.h"
69#include "TStopwatch.h"
70
71#include <map>
72#include <utility>
73
74ClassImp(AliMUONPadStatusMapMaker)
75
76Int_t AliMUONPadStatusMapMaker::fgkSelfDead = 1;
77
78namespace
79{
80 Bool_t IsZero(Double_t x)
81 {
82 return TMath::Abs(x) < AliMpConstants::LengthTolerance();
83 }
84}
85
86//_____________________________________________________________________________
87AliMUONPadStatusMapMaker::AliMUONPadStatusMapMaker()
88: TObject(),
89fStatus(0x0),
90fMask(0),
91fSegmentation(0x0),
92fTimerComputeStatusMap(0x0)
93{
94 /// ctor
95}
96
97//_____________________________________________________________________________
98AliMUONPadStatusMapMaker::~AliMUONPadStatusMapMaker()
99{
100 /// dtor
101 delete fTimerComputeStatusMap;
102}
103
104//_____________________________________________________________________________
105Int_t
106AliMUONPadStatusMapMaker::ComputeStatusMap(const TObjArray& neighbours,
107 Int_t detElemId) const
108{
109 /// Given a list of neighbours of one pad (which includes the pad itself)
110 /// compute the status map (aka deadmap) for that pad.
111
112 fTimerComputeStatusMap->Start(kFALSE);
113
114 Int_t statusMap(0);
115
116 //Compute the statusmap related to the status of neighbouring
117 //pads. An invalid pad means "outside of edges".
118 Int_t i(0);
119 TIter next(&neighbours);
120 AliMpPad* p;
121
122 while ( ( p = static_cast<AliMpPad*>(next()) ) )
123 {
124 Int_t status = 0;
125 if ( !p->IsValid() )
126 {
127 status = -1;
128 }
129 else
130 {
131 status = GetPadStatus(detElemId,*p);
132 }
133 if ( ( fMask==0 && status !=0 ) || ( (status & fMask) != 0 ) )
134 {
135 statusMap |= (1<<i);
136 }
137 ++i;
138 }
139
140 fTimerComputeStatusMap->Stop();
141 return statusMap;
142}
143
144//_____________________________________________________________________________
145Int_t
146AliMUONPadStatusMapMaker::GetPadStatus(Int_t detElemId,
147 const AliMpPad& pad) const
148{
149 /// Get the pad status
150 Int_t manuId = pad.GetLocation().GetFirst();
151 Int_t manuChannel = pad.GetLocation().GetSecond();
152 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->Get(detElemId,manuId));
153 return param->ValueAsInt(manuChannel);
154}
155
156//_____________________________________________________________________________
157Bool_t
158AliMUONPadStatusMapMaker::IsValid(const AliMpPad& pad,
159 const TVector2& shift) const
160{
161 /// Whether pad.Position()+shift is within the detector
162 TVector2 testPos = pad.Position() - pad.Dimensions() + shift;
163 AliMpPad p = fSegmentation->PadByPosition(testPos,kFALSE);
164 return p.IsValid();
165}
166
167//_____________________________________________________________________________
168AliMUONV2DStore*
169AliMUONPadStatusMapMaker::MakePadStatusMap(const AliMUONV2DStore& status,
170 Int_t mask)
171{
172 /// Given the status store for all pads, compute a status map store
173 /// for all pads.
174 /// @param mask is the status mask to be tested to tell if a pad is ok or not
175
176 fStatus = &status;
177 fMask = mask;
178
179 AliMpExMap chamberTimers(kTRUE);
180 fTimerComputeStatusMap = new TStopwatch;
181 fTimerComputeStatusMap->Start(kTRUE);
182 fTimerComputeStatusMap->Stop();
183
184 TStopwatch timer;
185
186 timer.Start(kTRUE);
187
188 AliMUONV2DStore* statusMap = status.CloneEmpty();
189
190 AliMUONVDataIterator* it = status.Iterator();
191 AliMUONObjectPair* pair;
192
193 while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
194 {
195 AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
196
197 Int_t detElemId = ip->GetFirst();
198
199 Int_t manuId = ip->GetSecond();
200 Int_t chamber = AliMpDEManager::GetChamberId(detElemId);
201
202 TStopwatch* chTimer = static_cast<TStopwatch*>(chamberTimers.GetValue(chamber));
203 if (!chTimer)
204 {
205 chTimer = new TStopwatch;
206 chTimer->Start(kTRUE);
207 chTimer->Stop();
208 chamberTimers.Add(chamber,chTimer);
209 }
210
211 chTimer->Start(kFALSE);
212
213 const AliMpVSegmentation* seg =
214 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
215 fSegmentation = seg;
216
217 AliMUONVCalibParam* statusEntry = static_cast<AliMUONVCalibParam*>(pair->Second());
218
219 AliMUONVCalibParam* statusMapEntry = static_cast<AliMUONVCalibParam*>
220 (statusMap->Get(detElemId,manuId));
221
222 if (!statusMapEntry)
223 {
224 statusMapEntry = new AliMUONCalibParam1I(64,0);
225 statusMap->Set(detElemId,manuId,statusMapEntry,false);
226 }
227
228 for ( Int_t manuChannel = 0; manuChannel < statusEntry->Size(); ++manuChannel )
229 {
230 // Loop over channels and for each channel loop on its immediate neighbours
231 // to produce a statusMap word for this channel.
232
233 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
234
235 Int_t statusMapValue(0);
236
237 if ( pad.IsValid() )
238 {
239 TObjArray neighbours;
240 neighbours.SetOwner(kTRUE);
d7fc09b9 241 fSegmentation->GetNeighbours(pad,neighbours,true,true);
2c780493 242 statusMapValue = ComputeStatusMap(neighbours,detElemId);
243 }
244 else
245 {
246 statusMapValue = fgkSelfDead;
247 }
248 statusMapEntry->SetValueAsInt(manuChannel,0,statusMapValue);
249 }
250 chTimer->Stop();
251 }
252
253 delete it;
254
255 TExMapIter cit = chamberTimers.GetIterator();
256
257 Long_t key, value;
258
259 while ( cit.Next(key,value) )
260 {
261 TStopwatch* t = reinterpret_cast<TStopwatch*>(value);
262 cout << Form("Chamber %2ld CPU time/manu %5.0f ms ",key,t->CpuTime()*1e3/t->Counter());
263 t->Print();
264 }
265
266 cout << "ComputeStatusMap timer : ";
267 fTimerComputeStatusMap->Print();
268 cout<< endl;
269
270 cout << "MakePadStatusMap total timer : ";
271 timer.Print();
272 cout << endl;
273
274 return statusMap;
275}
276