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