]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPadStatusMapMaker.cxx
- Removing obsolete tags
[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"
4f8ed2e4 53#include "AliMUON2DMap.h"
2c780493 54#include "AliMUONCalibParam1I.h"
55#include "AliMUONObjectPair.h"
56#include "AliMUONV2DStore.h"
57#include "AliMUONVCalibParam.h"
58#include "AliMUONVDataIterator.h"
59#include "AliMpArea.h"
60#include "AliMpConstants.h"
61#include "AliMpDEManager.h"
62#include "AliMpPad.h"
63#include "AliMpSegmentation.h"
64#include "AliMpStationType.h"
65#include "AliMpVPadIterator.h"
66#include "AliMpVSegmentation.h"
4f8ed2e4 67#include <Riostream.h>
68#include <TMath.h>
69#include <TObjArray.h>
70#include <TStopwatch.h>
2c780493 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//_____________________________________________________________________________
4f8ed2e4 168AliMUONV2DStore*
169AliMUONPadStatusMapMaker::MakeEmptyPadStatusMap()
170{
9f37150e 171 /// Make an empty (but complete) statusMap
4f8ed2e4 172
9f37150e 173 AliMUONCalibParam1I param(64,0);
4f8ed2e4 174
9f37150e 175 return AliMUON2DMap::Generate(param);
4f8ed2e4 176}
177
178//_____________________________________________________________________________
2c780493 179AliMUONV2DStore*
180AliMUONPadStatusMapMaker::MakePadStatusMap(const AliMUONV2DStore& status,
181 Int_t mask)
182{
183 /// Given the status store for all pads, compute a status map store
184 /// for all pads.
185 /// @param mask is the status mask to be tested to tell if a pad is ok or not
186
187 fStatus = &status;
188 fMask = mask;
189
190 AliMpExMap chamberTimers(kTRUE);
191 fTimerComputeStatusMap = new TStopwatch;
192 fTimerComputeStatusMap->Start(kTRUE);
193 fTimerComputeStatusMap->Stop();
194
195 TStopwatch timer;
196
197 timer.Start(kTRUE);
198
199 AliMUONV2DStore* statusMap = status.CloneEmpty();
200
201 AliMUONVDataIterator* it = status.Iterator();
202 AliMUONObjectPair* pair;
203
204 while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
205 {
206 AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
207
208 Int_t detElemId = ip->GetFirst();
209
210 Int_t manuId = ip->GetSecond();
211 Int_t chamber = AliMpDEManager::GetChamberId(detElemId);
212
213 TStopwatch* chTimer = static_cast<TStopwatch*>(chamberTimers.GetValue(chamber));
214 if (!chTimer)
215 {
216 chTimer = new TStopwatch;
217 chTimer->Start(kTRUE);
218 chTimer->Stop();
219 chamberTimers.Add(chamber,chTimer);
220 }
221
222 chTimer->Start(kFALSE);
223
224 const AliMpVSegmentation* seg =
225 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
226 fSegmentation = seg;
227
228 AliMUONVCalibParam* statusEntry = static_cast<AliMUONVCalibParam*>(pair->Second());
229
230 AliMUONVCalibParam* statusMapEntry = static_cast<AliMUONVCalibParam*>
231 (statusMap->Get(detElemId,manuId));
232
233 if (!statusMapEntry)
234 {
235 statusMapEntry = new AliMUONCalibParam1I(64,0);
236 statusMap->Set(detElemId,manuId,statusMapEntry,false);
237 }
238
239 for ( Int_t manuChannel = 0; manuChannel < statusEntry->Size(); ++manuChannel )
240 {
241 // Loop over channels and for each channel loop on its immediate neighbours
242 // to produce a statusMap word for this channel.
243
244 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
245
246 Int_t statusMapValue(0);
247
248 if ( pad.IsValid() )
249 {
250 TObjArray neighbours;
251 neighbours.SetOwner(kTRUE);
d7fc09b9 252 fSegmentation->GetNeighbours(pad,neighbours,true,true);
2c780493 253 statusMapValue = ComputeStatusMap(neighbours,detElemId);
254 }
255 else
256 {
257 statusMapValue = fgkSelfDead;
258 }
259 statusMapEntry->SetValueAsInt(manuChannel,0,statusMapValue);
260 }
261 chTimer->Stop();
262 }
263
264 delete it;
265
266 TExMapIter cit = chamberTimers.GetIterator();
267
268 Long_t key, value;
269
270 while ( cit.Next(key,value) )
271 {
272 TStopwatch* t = reinterpret_cast<TStopwatch*>(value);
273 cout << Form("Chamber %2ld CPU time/manu %5.0f ms ",key,t->CpuTime()*1e3/t->Counter());
274 t->Print();
275 }
276
277 cout << "ComputeStatusMap timer : ";
278 fTimerComputeStatusMap->Print();
279 cout<< endl;
280
281 cout << "MakePadStatusMap total timer : ";
282 timer.Print();
283 cout << endl;
284
285 return statusMap;
286}
287