]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPadStatusMapMaker.cxx
Add comments for Doxygen
[u/mrichter/AliRoot.git] / MUON / AliMUONPadStatusMapMaker.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 /// \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 "AliMUON2DMap.h"
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"
67 #include <Riostream.h>
68 #include <TMath.h>
69 #include <TObjArray.h>
70 #include <TStopwatch.h>
71 #include <map>
72 #include <utility>
73
74 /// \cond CLASSIMP
75 ClassImp(AliMUONPadStatusMapMaker)
76 /// \endcond
77
78 Int_t AliMUONPadStatusMapMaker::fgkSelfDead = 1;
79
80 namespace
81 {
82   Bool_t IsZero(Double_t x)
83   {
84     return TMath::Abs(x) < AliMpConstants::LengthTolerance();
85   }
86 }
87
88 //_____________________________________________________________________________
89 AliMUONPadStatusMapMaker::AliMUONPadStatusMapMaker() 
90 : TObject(),
91 fStatus(0x0),
92 fMask(0),
93 fSegmentation(0x0),
94 fTimerComputeStatusMap(0x0)
95 {
96   /// ctor
97 }
98
99 //_____________________________________________________________________________
100 AliMUONPadStatusMapMaker::~AliMUONPadStatusMapMaker()
101 {
102   /// dtor
103   delete fTimerComputeStatusMap;
104 }
105
106 //_____________________________________________________________________________
107 Int_t
108 AliMUONPadStatusMapMaker::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 //_____________________________________________________________________________
147 Int_t
148 AliMUONPadStatusMapMaker::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 //_____________________________________________________________________________
159 Bool_t
160 AliMUONPadStatusMapMaker::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 //_____________________________________________________________________________
170 AliMUONV2DStore*
171 AliMUONPadStatusMapMaker::MakeEmptyPadStatusMap()
172 {
173   /// Make an empty (but complete) statusMap
174   
175   AliMUONCalibParam1I param(64,0);
176   
177   return AliMUON2DMap::Generate(param);
178 }
179
180 //_____________________________________________________________________________
181 AliMUONV2DStore*
182 AliMUONPadStatusMapMaker::MakePadStatusMap(const AliMUONV2DStore& status,
183                                            Int_t mask)
184 {
185   /// Given the status store for all pads, compute a status map store
186   /// for all pads. 
187   /// \param status
188   /// \param mask is the status mask to be tested to tell if a pad is ok or not
189   
190   fStatus = &status;
191   fMask = mask;
192   
193   AliMpExMap chamberTimers(kTRUE);
194   fTimerComputeStatusMap = new TStopwatch;
195   fTimerComputeStatusMap->Start(kTRUE);
196   fTimerComputeStatusMap->Stop();
197   
198   TStopwatch timer;
199   
200   timer.Start(kTRUE);
201   
202   AliMUONV2DStore* statusMap = status.CloneEmpty();
203   
204   AliMUONVDataIterator* it = status.Iterator();
205   AliMUONObjectPair* pair;
206   
207   while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
208   {
209     AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
210
211     Int_t detElemId = ip->GetFirst();
212     
213     Int_t manuId = ip->GetSecond();
214     Int_t chamber = AliMpDEManager::GetChamberId(detElemId);
215     
216     TStopwatch* chTimer = static_cast<TStopwatch*>(chamberTimers.GetValue(chamber));
217     if (!chTimer)
218     {
219       chTimer = new TStopwatch;
220       chTimer->Start(kTRUE);
221       chTimer->Stop();
222       chamberTimers.Add(chamber,chTimer);
223     }
224     
225     chTimer->Start(kFALSE);
226     
227     const AliMpVSegmentation* seg = 
228       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
229     fSegmentation = seg;
230     
231     AliMUONVCalibParam* statusEntry = static_cast<AliMUONVCalibParam*>(pair->Second());
232     
233     AliMUONVCalibParam* statusMapEntry = static_cast<AliMUONVCalibParam*>
234       (statusMap->Get(detElemId,manuId));
235
236     if (!statusMapEntry)
237     {
238       statusMapEntry = new AliMUONCalibParam1I(64,0);
239       statusMap->Set(detElemId,manuId,statusMapEntry,false);
240     }
241     
242     for ( Int_t manuChannel = 0; manuChannel < statusEntry->Size(); ++manuChannel ) 
243     {
244       // Loop over channels and for each channel loop on its immediate neighbours
245       // to produce a statusMap word for this channel.
246       
247       AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
248       
249       Int_t statusMapValue(0);
250       
251       if ( pad.IsValid() )
252       {
253         TObjArray neighbours;
254         neighbours.SetOwner(kTRUE);
255         fSegmentation->GetNeighbours(pad,neighbours,true,true);
256         statusMapValue = ComputeStatusMap(neighbours,detElemId);      
257       }
258       else
259       {
260         statusMapValue = fgkSelfDead;
261       }
262       statusMapEntry->SetValueAsInt(manuChannel,0,statusMapValue);
263     }
264     chTimer->Stop();
265   }
266   
267   delete it;
268   
269   TExMapIter cit = chamberTimers.GetIterator();
270   
271   Long_t key, value;
272   
273   while ( cit.Next(key,value) ) 
274   {
275     TStopwatch* t = reinterpret_cast<TStopwatch*>(value);
276     cout << Form("Chamber %2ld CPU time/manu %5.0f ms ",key,t->CpuTime()*1e3/t->Counter());
277     t->Print();
278   }
279
280   cout << "ComputeStatusMap timer : ";
281   fTimerComputeStatusMap->Print();
282   cout<< endl;
283   
284   cout << "MakePadStatusMap total timer : ";
285   timer.Print();
286   cout << endl;
287   
288   return statusMap;
289 }
290