1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \class AliMUONPadStatusMapMaker
21 /// Convert a pad statuses into pad status maps.
23 /// A pad status is one 32-bits word describing whether this pad pedestal, gains
24 /// hv is correct or not.
26 /// A pad status *map* is one 32-bits (of which 24 only are used)
27 /// word describing whether this pad neighbours are ok or not
28 /// (whether a pad is ok or not is determined by applying a given
29 /// bitmask to the pad status word). Each bit in this word is related to one
30 /// neighbour, assuming the pad itself is at bit 0
40 /// Note that for instance in NonBending plane of slats, at the boundaries
41 /// between two pad densities, the pictures is a bit different, e.g.
42 /// (bits in () are always zero)
44 /// so some care must be taken when designing a mask to be tested ;-) if you
45 /// want to go farther than immediate neighbours...
47 /// If a pad is at a physical boundary, is will for sure have some bits at 1
48 /// (i.e. a non-existing neighbour is considered = bad).
51 /// add something about the reject list/probabilities here... (LA)
53 /// \author Laurent Aphecetche
54 //-----------------------------------------------------------------------------
56 #include "AliMUONPadStatusMapMaker.h"
58 #include "AliCodeTimer.h"
60 #include "AliMpDDLStore.h"
61 #include "AliMpDetElement.h"
62 #include "AliMpManuIterator.h"
63 #include "AliMUON2DMap.h"
64 #include "AliMUONCalibParamNF.h"
65 #include "AliMUONCalibParamNI.h"
66 #include "AliMUONCalibrationData.h"
67 #include "AliMUONPadStatusMaker.h"
68 #include "AliMUONRejectList.h"
69 #include "AliMUONVCalibParam.h"
70 #include "AliMUONVStore.h"
71 #include "AliMpConstants.h"
72 #include <Riostream.h>
78 ClassImp(AliMUONPadStatusMapMaker)
81 Int_t AliMUONPadStatusMapMaker::fgkSelfDead = 1;
83 //_____________________________________________________________________________
84 AliMUONPadStatusMapMaker::AliMUONPadStatusMapMaker(const AliMUONPadStatusMaker& padStatusMaker,
86 Bool_t deferredInitialization)
88 fkStatusMaker(padStatusMaker),
90 fStatusMap(new AliMUON2DMap(true)),
91 fRejectProbabilities(new AliMUON2DMap(true)),
93 fComputeOnDemand(deferredInitialization)
96 if (!deferredInitialization)
98 AliCodeTimerAuto("Computing complete status map at once",0);
99 AliMUONVStore* neighboursStore = padStatusMaker.NeighboursStore();
100 AliMUONVCalibParam* param;
101 TIter next(neighboursStore->CreateIterator());
102 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
104 Int_t detElemId = param->ID0();
105 Int_t manuId = param->ID1();
106 ComputeStatusMap(detElemId,manuId);
110 /// Whatever the deferred flag is, we *have* to compute the reject
111 /// probabilities here and now, for *all* channels.
113 AliMUONRejectList* rl = padStatusMaker.CalibrationData().RejectList();
117 AliMpManuIterator it;
121 while ( it.Next(detElemId,manuId) )
123 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
124 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
126 AliMUONVCalibParam* param = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,0);
130 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
134 if ( de->IsConnectedChannel(manuId,i) )
136 proba = TMath::Max(rl->DetectionElementProbability(detElemId),rl->BusPatchProbability(busPatchId));
138 proba = TMath::Max(proba,rl->ManuProbability(detElemId,manuId));
140 proba = TMath::Max(proba,rl->ChannelProbability(detElemId,manuId,i));
145 param->SetValueAsFloat(i,0,proba);
152 fRejectProbabilities->Add(param);
156 // no need to add empty stuff...
163 fRejectList = fRejectProbabilities;
164 fRejectProbabilities = 0x0;
165 AliDebug(1,"RejectList = RejectProbabilities");
166 StdoutToAliDebug(1,fRejectList->Print("","MEAN"));
170 AliWarning("Will run with non trivial survival probabilities for channels, manus, etc... Better check this is a simulation and not real data !");
171 fRejectList = new AliMUON2DMap(true);
176 fRejectList = fRejectProbabilities;
177 fRejectProbabilities = 0x0;
178 AliInfo("No RejectList found, so no RejectList will be used.");
182 //_____________________________________________________________________________
183 AliMUONPadStatusMapMaker::~AliMUONPadStatusMapMaker()
187 delete fRejectProbabilities;
191 //_____________________________________________________________________________
193 AliMUONPadStatusMapMaker::ComputeStatusMap(Int_t detElemId, Int_t manuId) const
195 /// Compute the status map for a given manu, and add it to our internal
196 /// fStatusMap internal storage
198 AliCodeTimerAuto("(Int_t,Int_t)",0)
200 AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),
201 detElemId,manuId,-1);
203 Bool_t ok = fStatusMap->Add(param);
206 AliFatal(Form("Could not add manu %d of de %d",manuId,detElemId));
209 AliMUONVCalibParam* neighbours = fkStatusMaker.Neighbours(detElemId,manuId);
211 AliMUONVCalibParam* statusParam = fkStatusMaker.PadStatus(detElemId,manuId);
213 Int_t n = neighbours->Dimension();
215 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
219 Int_t x = neighbours->ValueAsIntFast(manuChannel,0);
222 // channel is not a valid one (i.e. (manuId,manuChannel) is not an existing pad)
223 statusMap = -1;//fgkSelfDead;
227 for ( Int_t i = 0; i < n; ++i )
229 // Compute the statusmap related to the status of neighbouring
230 // pads. An invalid pad means "outside of edges".
232 Int_t y = neighbours->ValueAsIntFast(manuChannel,i);
234 neighbours->UnpackValue(y,m,c);
235 if ( c < 0 ) continue;
243 status = statusParam->ValueAsIntFast(c); //fkStatusMaker.PadStatus(detElemId,m,c);
245 if ( ( fMask != 0 ) && ( (status & fMask) != 0 ) )
250 param->SetValueAsIntFast(manuChannel,0,statusMap);
255 //_____________________________________________________________________________
257 AliMUONPadStatusMapMaker::RefreshRejectProbabilities()
259 /// From the (fixed) fRejectProbabilities, compute
260 /// a fRejectList that will be valid for one event
261 /// If fRejectProbabilities=0x0 it means we're dealing with
262 /// trivial probabilities (0 or 1) and those are assumed to be already
263 /// in fRejectList then.
265 if ( !fRejectProbabilities ) return;
267 AliCodeTimerAuto("",0);
269 fRejectList->Clear();
271 TIter next(fRejectProbabilities->CreateIterator());
272 AliMUONVCalibParam* paramProba;
273 AliMUONVCalibParam* paramReject;
275 while ( ( paramProba = static_cast<AliMUONVCalibParam*>(next()) ) )
277 paramReject = new AliMUONCalibParamNF(1,paramProba->Size(),paramProba->ID0(),paramProba->ID1(),0.0);
281 for ( Int_t i = 0; i < paramProba->Size(); ++i )
283 Float_t proba = paramProba->ValueAsFloat(i);
286 if ( proba > 0.0 && proba < 1.0 )
289 proba = ( x < proba ) ? 1.0 : 0.0;
295 paramReject->SetValueAsFloat(i,0,proba);
298 if (n) fRejectList->Add(paramReject);
302 //_____________________________________________________________________________
304 AliMUONPadStatusMapMaker::StatusMap(Int_t detElemId, Int_t manuId,
305 Int_t manuChannel) const
308 /// Get the pad status map
310 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatusMap->FindObject(detElemId,manuId));
313 if ( fComputeOnDemand )
315 // not yet computed, so do it now
316 param = ComputeStatusMap(detElemId,manuId);
320 // we're locked. probably a bad manuId ?
325 Int_t statusMap = param->ValueAsInt(manuChannel);
327 AliMUONVCalibParam* r = static_cast<AliMUONVCalibParam*>(fRejectList->FindObject(detElemId,manuId));
331 Float_t v= r->ValueAsFloat(manuChannel);
333 assert (v==0.0 || v==1.0 );
337 statusMap |= fgkSelfDead;