]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPadStatusMapMaker.cxx
Updated list of MUON libraries
[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 "AliMUONCalibParamNI.h"
55 #include "AliMUONCalibrationData.h"
56 #include "AliMUONObjectPair.h"
57 #include "AliMUONV2DStore.h"
58 #include "AliMUONVCalibParam.h"
59 #include "AliMUONVDataIterator.h"
60 #include "AliMpIntPair.h"
61 #include <Riostream.h>
62 #include <TStopwatch.h>
63
64 /// \cond CLASSIMP
65 ClassImp(AliMUONPadStatusMapMaker)
66 /// \endcond
67
68 Int_t AliMUONPadStatusMapMaker::fgkSelfDead = 1;
69
70 //_____________________________________________________________________________
71 AliMUONPadStatusMapMaker::AliMUONPadStatusMapMaker(const AliMUONCalibrationData& calibData) 
72 : TObject(),
73 fStatus(0x0),
74 fMask(0),
75 fCalibrationData(calibData)
76 {
77   /// ctor
78 }
79
80 //_____________________________________________________________________________
81 AliMUONPadStatusMapMaker::~AliMUONPadStatusMapMaker()
82 {
83   /// dtor
84 }
85
86 //_____________________________________________________________________________
87 Int_t
88 AliMUONPadStatusMapMaker::ComputeStatusMap(const AliMUONVCalibParam& neighbours,
89                                           Int_t manuChannel,
90                                           Int_t detElemId) const
91 {
92   /// Given a list of neighbours of one pad (which includes the pad itself)
93   /// compute the status map (aka deadmap) for that pad.
94   
95   Int_t statusMap(0);
96
97   //Compute the statusmap related to the status of neighbouring
98   //pads. An invalid pad means "outside of edges".
99
100   Int_t n = neighbours.Dimension();
101   for ( Int_t i = 0; i < n; ++i )
102   {
103     Int_t x = neighbours.ValueAsInt(manuChannel,i);
104     Int_t m,c;
105     neighbours.UnpackValue(x,m,c);
106     if ( c < 0 ) continue;
107     Int_t status = 0;
108     if ( !m )
109     {
110       status = -1;
111     }
112     else
113     {
114       status = GetPadStatus(detElemId,m,c);
115     }
116     if ( ( fMask==0 && status !=0 ) || ( (status & fMask) != 0 ) )
117     {
118       statusMap |= (1<<i);
119     }
120   }
121   return statusMap;
122 }
123
124 //_____________________________________________________________________________
125 Int_t
126 AliMUONPadStatusMapMaker::GetPadStatus(Int_t detElemId, 
127                                        Int_t manuId, Int_t manuChannel) const
128                                       
129 {
130   /// Get the pad status
131   AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->Get(detElemId,manuId));
132   return param->ValueAsInt(manuChannel);
133 }
134
135 //_____________________________________________________________________________
136 AliMUONV2DStore*
137 AliMUONPadStatusMapMaker::MakeEmptyPadStatusMap()
138 {
139   /// Make an empty (but complete) statusMap
140   
141   AliMUONCalibParamNI param(1,64,0);
142   
143   return AliMUON2DMap::Generate(param);
144 }
145
146 //_____________________________________________________________________________
147 AliMUONV2DStore*
148 AliMUONPadStatusMapMaker::MakePadStatusMap(const AliMUONV2DStore& status,
149                                            Int_t mask)
150 {
151   /// Given the status store for all pads, compute a status map store
152   /// for all pads. 
153   /// \param status
154   /// \param mask is the status mask to be tested to tell if a pad is ok or not
155   
156   fStatus = &status;
157   fMask = mask;
158   
159   TStopwatch timer;  
160   timer.Start(kTRUE);
161   
162   AliMUONV2DStore* neighbourStore = fCalibrationData.Neighbours();
163   
164   AliMUONV2DStore* statusMap = status.CloneEmpty();
165   
166   AliMUONVDataIterator* it = status.Iterator();
167   AliMUONObjectPair* pair;
168   
169   while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
170   {
171     AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
172
173     Int_t detElemId = ip->GetFirst();    
174     Int_t manuId = ip->GetSecond();
175         
176     AliMUONVCalibParam* statusEntry = static_cast<AliMUONVCalibParam*>(pair->Second());
177     
178     AliMUONVCalibParam* statusMapEntry = static_cast<AliMUONVCalibParam*>
179       (statusMap->Get(detElemId,manuId));
180
181     if (!statusMapEntry)
182     {
183       statusMapEntry = new AliMUONCalibParamNI(1,64,0);
184       statusMap->Set(detElemId,manuId,statusMapEntry,false);
185     }
186     
187     AliMUONVCalibParam* neighbours = static_cast<AliMUONVCalibParam*>
188       (neighbourStore->Get(detElemId,manuId));
189     
190     if (!neighbours)
191     {
192       AliFatal(Form("Could not find neighbours for DE %d manuId %d",
193                     detElemId,manuId));
194       continue;
195     }
196     
197     for ( Int_t manuChannel = 0; manuChannel < statusEntry->Size(); ++manuChannel ) 
198     {
199       // Loop over channels and for each channel loop on its immediate neighbours
200       // to produce a statusMap word for this channel.
201       
202       Int_t statusMapValue(0);
203
204       Int_t x = neighbours->ValueAsInt(manuChannel,0);
205       
206       if ( x > 0 )
207       { // channel is a valid one (i.e. (manuId,manuChannel) is an existing pad)
208         // assert(x>=0);
209         statusMapValue = ComputeStatusMap(*neighbours,manuChannel,detElemId);
210       }
211       else
212       {
213         statusMapValue = fgkSelfDead;
214       }
215       
216       statusMapEntry->SetValueAsInt(manuChannel,0,statusMapValue);
217     }
218     
219     if (it->IsOwner()) delete pair;
220   }
221   
222   delete it;
223
224   timer.Stop();
225   
226   StdoutToAliInfo(
227                   cout << "MakePadStatusMap total timer : ";
228                   timer.Print();
229                   cout << endl;
230                   );
231
232   return statusMap;
233 }
234