]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPadStatusMapMaker.cxx
Using AliITSgeomTGeo
[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"
4f8ed2e4 62#include "AliMpManuList.h"
2c780493 63#include "AliMpPad.h"
64#include "AliMpSegmentation.h"
65#include "AliMpStationType.h"
66#include "AliMpVPadIterator.h"
67#include "AliMpVSegmentation.h"
4f8ed2e4 68#include <Riostream.h>
69#include <TMath.h>
70#include <TObjArray.h>
71#include <TStopwatch.h>
72#include <TList.h>
2c780493 73#include <map>
74#include <utility>
75
76ClassImp(AliMUONPadStatusMapMaker)
77
78Int_t AliMUONPadStatusMapMaker::fgkSelfDead = 1;
79
80namespace
81{
82 Bool_t IsZero(Double_t x)
83 {
84 return TMath::Abs(x) < AliMpConstants::LengthTolerance();
85 }
86}
87
88//_____________________________________________________________________________
89AliMUONPadStatusMapMaker::AliMUONPadStatusMapMaker()
90: TObject(),
91fStatus(0x0),
92fMask(0),
93fSegmentation(0x0),
94fTimerComputeStatusMap(0x0)
95{
96 /// ctor
97}
98
99//_____________________________________________________________________________
100AliMUONPadStatusMapMaker::~AliMUONPadStatusMapMaker()
101{
102 /// dtor
103 delete fTimerComputeStatusMap;
104}
105
106//_____________________________________________________________________________
107Int_t
108AliMUONPadStatusMapMaker::ComputeStatusMap(const TObjArray& neighbours,
109 Int_t detElemId) const
110{
111 /// Given a list of neighbours of one pad (which includes the pad itself)
112 /// compute the status map (aka deadmap) for that pad.
113
114 fTimerComputeStatusMap->Start(kFALSE);
115
116 Int_t statusMap(0);
117
118 //Compute the statusmap related to the status of neighbouring
119 //pads. An invalid pad means "outside of edges".
120 Int_t i(0);
121 TIter next(&neighbours);
122 AliMpPad* p;
123
124 while ( ( p = static_cast<AliMpPad*>(next()) ) )
125 {
126 Int_t status = 0;
127 if ( !p->IsValid() )
128 {
129 status = -1;
130 }
131 else
132 {
133 status = GetPadStatus(detElemId,*p);
134 }
135 if ( ( fMask==0 && status !=0 ) || ( (status & fMask) != 0 ) )
136 {
137 statusMap |= (1<<i);
138 }
139 ++i;
140 }
141
142 fTimerComputeStatusMap->Stop();
143 return statusMap;
144}
145
146//_____________________________________________________________________________
147Int_t
148AliMUONPadStatusMapMaker::GetPadStatus(Int_t detElemId,
149 const AliMpPad& pad) const
150{
151 /// Get the pad status
152 Int_t manuId = pad.GetLocation().GetFirst();
153 Int_t manuChannel = pad.GetLocation().GetSecond();
154 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->Get(detElemId,manuId));
155 return param->ValueAsInt(manuChannel);
156}
157
158//_____________________________________________________________________________
159Bool_t
160AliMUONPadStatusMapMaker::IsValid(const AliMpPad& pad,
161 const TVector2& shift) const
162{
163 /// Whether pad.Position()+shift is within the detector
164 TVector2 testPos = pad.Position() - pad.Dimensions() + shift;
165 AliMpPad p = fSegmentation->PadByPosition(testPos,kFALSE);
166 return p.IsValid();
167}
168
169//_____________________________________________________________________________
4f8ed2e4 170AliMUONV2DStore*
171AliMUONPadStatusMapMaker::MakeEmptyPadStatusMap()
172{
173 AliMUONV2DStore* padStatusMap = new AliMUON2DMap(kTRUE);
174
175 TList* list = AliMpManuList::ManuList();
176
177 AliMpIntPair* pair;
178
179 TIter next(list);
180
181 while ( ( pair = static_cast<AliMpIntPair*>(next()) ) )
182 {
183 Int_t detElemId = pair->GetFirst();
184 Int_t manuId = pair->GetSecond();
185 padStatusMap->Set(detElemId,manuId,new AliMUONCalibParam1I(64,0),kFALSE);
186 }
187
188 delete list;
189
190 return padStatusMap;
191}
192
193//_____________________________________________________________________________
2c780493 194AliMUONV2DStore*
195AliMUONPadStatusMapMaker::MakePadStatusMap(const AliMUONV2DStore& status,
196 Int_t mask)
197{
198 /// Given the status store for all pads, compute a status map store
199 /// for all pads.
200 /// @param mask is the status mask to be tested to tell if a pad is ok or not
201
202 fStatus = &status;
203 fMask = mask;
204
205 AliMpExMap chamberTimers(kTRUE);
206 fTimerComputeStatusMap = new TStopwatch;
207 fTimerComputeStatusMap->Start(kTRUE);
208 fTimerComputeStatusMap->Stop();
209
210 TStopwatch timer;
211
212 timer.Start(kTRUE);
213
214 AliMUONV2DStore* statusMap = status.CloneEmpty();
215
216 AliMUONVDataIterator* it = status.Iterator();
217 AliMUONObjectPair* pair;
218
219 while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
220 {
221 AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
222
223 Int_t detElemId = ip->GetFirst();
224
225 Int_t manuId = ip->GetSecond();
226 Int_t chamber = AliMpDEManager::GetChamberId(detElemId);
227
228 TStopwatch* chTimer = static_cast<TStopwatch*>(chamberTimers.GetValue(chamber));
229 if (!chTimer)
230 {
231 chTimer = new TStopwatch;
232 chTimer->Start(kTRUE);
233 chTimer->Stop();
234 chamberTimers.Add(chamber,chTimer);
235 }
236
237 chTimer->Start(kFALSE);
238
239 const AliMpVSegmentation* seg =
240 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
241 fSegmentation = seg;
242
243 AliMUONVCalibParam* statusEntry = static_cast<AliMUONVCalibParam*>(pair->Second());
244
245 AliMUONVCalibParam* statusMapEntry = static_cast<AliMUONVCalibParam*>
246 (statusMap->Get(detElemId,manuId));
247
248 if (!statusMapEntry)
249 {
250 statusMapEntry = new AliMUONCalibParam1I(64,0);
251 statusMap->Set(detElemId,manuId,statusMapEntry,false);
252 }
253
254 for ( Int_t manuChannel = 0; manuChannel < statusEntry->Size(); ++manuChannel )
255 {
256 // Loop over channels and for each channel loop on its immediate neighbours
257 // to produce a statusMap word for this channel.
258
259 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
260
261 Int_t statusMapValue(0);
262
263 if ( pad.IsValid() )
264 {
265 TObjArray neighbours;
266 neighbours.SetOwner(kTRUE);
d7fc09b9 267 fSegmentation->GetNeighbours(pad,neighbours,true,true);
2c780493 268 statusMapValue = ComputeStatusMap(neighbours,detElemId);
269 }
270 else
271 {
272 statusMapValue = fgkSelfDead;
273 }
274 statusMapEntry->SetValueAsInt(manuChannel,0,statusMapValue);
275 }
276 chTimer->Stop();
277 }
278
279 delete it;
280
281 TExMapIter cit = chamberTimers.GetIterator();
282
283 Long_t key, value;
284
285 while ( cit.Next(key,value) )
286 {
287 TStopwatch* t = reinterpret_cast<TStopwatch*>(value);
288 cout << Form("Chamber %2ld CPU time/manu %5.0f ms ",key,t->CpuTime()*1e3/t->Counter());
289 t->Print();
290 }
291
292 cout << "ComputeStatusMap timer : ";
293 fTimerComputeStatusMap->Print();
294 cout<< endl;
295
296 cout << "MakePadStatusMap total timer : ";
297 timer.Print();
298 cout << endl;
299
300 return statusMap;
301}
302