X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=MUON%2FAliMUONPadStatusMapMaker.cxx;h=8c6785f76f378ebf94cf82af308189b7d20be4ac;hb=9088e63b67cecae8411de3c3c25af69325389612;hp=3159b978a656d296314e180e7b470ade7684329b;hpb=3d1463c8f7148e36069c24f20cde34e096d5d6a9;p=u%2Fmrichter%2FAliRoot.git diff --git a/MUON/AliMUONPadStatusMapMaker.cxx b/MUON/AliMUONPadStatusMapMaker.cxx index 3159b978a65..8c6785f76f3 100644 --- a/MUON/AliMUONPadStatusMapMaker.cxx +++ b/MUON/AliMUONPadStatusMapMaker.cxx @@ -18,7 +18,7 @@ //----------------------------------------------------------------------------- /// \class AliMUONPadStatusMapMaker /// -/// Convert a pad status container into a pad status *map* container +/// Convert a pad statuses into pad status maps. /// /// A pad status is one 32-bits word describing whether this pad pedestal, gains /// hv is correct or not. @@ -47,23 +47,32 @@ /// If a pad is at a physical boundary, is will for sure have some bits at 1 /// (i.e. a non-existing neighbour is considered = bad). /// +/// +/// add something about the reject list/probabilities here... (LA) +/// /// \author Laurent Aphecetche //----------------------------------------------------------------------------- #include "AliMUONPadStatusMapMaker.h" +#include "AliCodeTimer.h" #include "AliLog.h" +#include "AliMpDDLStore.h" +#include "AliMpDetElement.h" +#include "AliMpManuIterator.h" #include "AliMUON2DMap.h" +#include "AliMUONCalibParamNF.h" #include "AliMUONCalibParamNI.h" #include "AliMUONCalibrationData.h" -#include "AliMUONVStore.h" +#include "AliMUONPadStatusMaker.h" +#include "AliMUONRejectList.h" #include "AliMUONVCalibParam.h" +#include "AliMUONVStore.h" #include "AliMpConstants.h" -#include "AliMpIntPair.h" -#include "AliMpManuList.h" #include #include -#include +#include "TRandom.h" +#include /// \cond CLASSIMP ClassImp(AliMUONPadStatusMapMaker) @@ -72,177 +81,263 @@ ClassImp(AliMUONPadStatusMapMaker) Int_t AliMUONPadStatusMapMaker::fgkSelfDead = 1; //_____________________________________________________________________________ -AliMUONPadStatusMapMaker::AliMUONPadStatusMapMaker(const AliMUONCalibrationData& calibData) +AliMUONPadStatusMapMaker::AliMUONPadStatusMapMaker(const AliMUONPadStatusMaker& padStatusMaker, + Int_t mask, + Bool_t deferredInitialization) : TObject(), -fStatus(0x0), -fMask(0), -fCalibrationData(calibData) +fkStatusMaker(padStatusMaker), +fMask(mask), +fStatusMap(new AliMUON2DMap(true)), +fRejectProbabilities(new AliMUON2DMap(true)), +fRejectList(0x0), +fComputeOnDemand(deferredInitialization) { /// ctor -} - -//_____________________________________________________________________________ -AliMUONPadStatusMapMaker::~AliMUONPadStatusMapMaker() -{ - /// dtor -} - -//_____________________________________________________________________________ -Int_t -AliMUONPadStatusMapMaker::ComputeStatusMap(const AliMUONVCalibParam& neighbours, - Int_t manuChannel, - Int_t detElemId) const -{ - /// Given a list of neighbours of one pad (which includes the pad itself) - /// compute the status map (aka deadmap) for that pad. + if (!deferredInitialization) + { + AliCodeTimerAuto("Computing complete status map at once",0); + AliMUONVStore* neighboursStore = padStatusMaker.NeighboursStore(); + AliMUONVCalibParam* param; + TIter next(neighboursStore->CreateIterator()); + while ( ( param = static_cast(next()) ) ) + { + Int_t detElemId = param->ID0(); + Int_t manuId = param->ID1(); + ComputeStatusMap(detElemId,manuId); + } + } - Int_t statusMap(0); - - //Compute the statusmap related to the status of neighbouring - //pads. An invalid pad means "outside of edges". - - Int_t n = neighbours.Dimension(); - for ( Int_t i = 0; i < n; ++i ) + /// Whatever the deferred flag is, we *have* to compute the reject + /// probabilities here and now, for *all* channels. + + AliMUONRejectList* rl = padStatusMaker.CalibrationData().RejectList(); + + if (rl) { - Int_t x = neighbours.ValueAsInt(manuChannel,i); - Int_t m,c; - neighbours.UnpackValue(x,m,c); - if ( c < 0 ) continue; - Int_t status = 0; - if ( !m ) + AliMpManuIterator it; + Int_t detElemId; + Int_t manuId; + + while ( it.Next(detElemId,manuId) ) { - status = -1; + AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId); + Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId); + + AliMUONVCalibParam* param = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,0); + + Int_t n(0); + + for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i ) + { + Float_t proba(0.0); + + if ( de->IsConnectedChannel(manuId,i) ) + { + proba = TMath::Max(rl->DetectionElementProbability(detElemId),rl->BusPatchProbability(busPatchId)); + + proba = TMath::Max(proba,rl->ManuProbability(detElemId,manuId)); + + proba = TMath::Max(proba,rl->ChannelProbability(detElemId,manuId,i)); + + if ( proba > 0 ) + { + ++n; + param->SetValueAsFloat(i,0,proba); + } + } + } + + if ( n > 0 ) + { + fRejectProbabilities->Add(param); + } + else + { + // no need to add empty stuff... + delete param; + } } - else + + if ( rl->IsBinary()) { - status = GetPadStatus(detElemId,m,c); + fRejectList = fRejectProbabilities; + fRejectProbabilities = 0x0; + AliDebug(1,"RejectList = RejectProbabilities"); + StdoutToAliDebug(1,fRejectList->Print("","MEAN")); } - if ( ( fMask==0 && status !=0 ) || ( (status & fMask) != 0 ) ) + else { - statusMap |= (1<(fStatus->FindObject(detElemId,manuId)); - return param->ValueAsInt(manuChannel); + /// dtor + delete fStatusMap; + delete fRejectProbabilities; + delete fRejectList; } //_____________________________________________________________________________ -AliMUONVStore* -AliMUONPadStatusMapMaker::MakeEmptyPadStatusMap() +AliMUONVCalibParam* +AliMUONPadStatusMapMaker::ComputeStatusMap(Int_t detElemId, Int_t manuId) const { - /// Make an empty (but complete) statusMap - - AliMUONVStore* store = new AliMUON2DMap(true); - - TList* list = AliMpManuList::ManuList(); - - AliMpIntPair* pair; + /// Compute the status map for a given manu, and add it to our internal + /// fStatusMap internal storage + + AliCodeTimerAuto("(Int_t,Int_t)",0) - TIter next(list); + AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(), + detElemId,manuId,-1); + + Bool_t ok = fStatusMap->Add(param); + if (!ok) + { + AliFatal(Form("Could not add manu %d of de %d",manuId,detElemId)); + } + + AliMUONVCalibParam* neighbours = fkStatusMaker.Neighbours(detElemId,manuId); + + AliMUONVCalibParam* statusParam = fkStatusMaker.PadStatus(detElemId,manuId); + + Int_t n = neighbours->Dimension(); + + for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel ) + { + Int_t statusMap(0); - while ( ( pair = static_cast(next()) ) ) + Int_t x = neighbours->ValueAsIntFast(manuChannel,0); + if ( x < 0 ) { - Int_t detElemId = pair->GetFirst(); - Int_t manuId = pair->GetSecond(); - AliMUONVCalibParam* param = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(), - detElemId,manuId, - 0); - store->Add(param); + // channel is not a valid one (i.e. (manuId,manuChannel) is not an existing pad) + statusMap = -1;//fgkSelfDead; + continue; } - - delete list; - - return store; + + for ( Int_t i = 0; i < n; ++i ) + { + // Compute the statusmap related to the status of neighbouring + // pads. An invalid pad means "outside of edges". + + Int_t y = neighbours->ValueAsIntFast(manuChannel,i); + Int_t m,c; + neighbours->UnpackValue(y,m,c); + if ( c < 0 ) continue; + Int_t status = 0; + if ( !m ) + { + status = -1; + } + else + { + status = statusParam->ValueAsIntFast(c); //fkStatusMaker.PadStatus(detElemId,m,c); + } + if ( ( fMask==0 && status !=0 ) || ( (status & fMask) != 0 ) ) + { + statusMap |= (1<SetValueAsIntFast(manuChannel,0,statusMap); + } + return param; } //_____________________________________________________________________________ -AliMUONVStore* -AliMUONPadStatusMapMaker::MakePadStatusMap(const AliMUONVStore& status, - Int_t mask) +void +AliMUONPadStatusMapMaker::RefreshRejectProbabilities() { - /// Given the status store for all pads, compute a status map store - /// for all pads. - /// \param status - /// \param mask is the status mask to be tested to tell if a pad is ok or not - - fStatus = &status; - fMask = mask; + /// From the (fixed) fRejectProbabilities, compute + /// a fRejectList that will be valid for one event + /// If fRejectProbabilities=0x0 it means we're dealing with + /// trivial probabilities (0 or 1) and those are assumed to be already + /// in fRejectList then. - TStopwatch timer; - timer.Start(kTRUE); + if ( !fRejectProbabilities ) return; - AliMUONVStore* neighbourStore = fCalibrationData.Neighbours(); + AliCodeTimerAuto("",0); - AliMUONVStore* statusMap = status.Create(); + fRejectList->Clear(); - TIter next(status.CreateIterator()); - AliMUONVCalibParam* statusEntry; + TIter next(fRejectProbabilities->CreateIterator()); + AliMUONVCalibParam* paramProba; + AliMUONVCalibParam* paramReject; - while ( ( statusEntry = static_cast(next()) ) ) + while ( ( paramProba = static_cast(next()) ) ) { - Int_t detElemId = statusEntry->ID0(); - Int_t manuId = statusEntry->ID1(); - - AliMUONVCalibParam* statusMapEntry = static_cast - (statusMap->FindObject(detElemId,manuId)); - - if (!statusMapEntry) - { - statusMapEntry = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(), - detElemId,manuId,0); - statusMap->Add(statusMapEntry); - } + paramReject = new AliMUONCalibParamNF(1,paramProba->Size(),paramProba->ID0(),paramProba->ID1(),0.0); - AliMUONVCalibParam* neighbours = static_cast - (neighbourStore->FindObject(detElemId,manuId)); + Int_t n(0); - if (!neighbours) + for ( Int_t i = 0; i < paramProba->Size(); ++i ) { - AliFatal(Form("Could not find neighbours for DE %d manuId %d", - detElemId,manuId)); - continue; - } - - for ( Int_t manuChannel = 0; manuChannel < statusEntry->Size(); ++manuChannel ) - { - // Loop over channels and for each channel loop on its immediate neighbours - // to produce a statusMap word for this channel. + Float_t proba = paramProba->ValueAsFloat(i); + Float_t x(proba); - Int_t statusMapValue(0); - - Int_t x = neighbours->ValueAsInt(manuChannel,0); - - if ( x > 0 ) - { - // channel is a valid one (i.e. (manuId,manuChannel) is an existing pad) - statusMapValue = ComputeStatusMap(*neighbours,manuChannel,detElemId); - } - else + if ( proba > 0.0 && proba < 1.0 ) { - statusMapValue = fgkSelfDead; + x = gRandom->Rndm(); + proba = ( x < proba ) ? 1.0 : 0.0; } - statusMapEntry->SetValueAsInt(manuChannel,0,statusMapValue); + if (proba>0.0) + { + ++n; + paramReject->SetValueAsFloat(i,0,proba); + } } + if (n) fRejectList->Add(paramReject); } - timer.Stop(); +} + +//_____________________________________________________________________________ +Int_t +AliMUONPadStatusMapMaker::StatusMap(Int_t detElemId, Int_t manuId, + Int_t manuChannel) const + +{ + /// Get the pad status map - StdoutToAliInfo( - cout << "MakePadStatusMap total timer : "; - timer.Print(); - cout << endl; - ); + AliMUONVCalibParam* param = static_cast(fStatusMap->FindObject(detElemId,manuId)); + if (!param) + { + if ( fComputeOnDemand ) + { + // not yet computed, so do it now + param = ComputeStatusMap(detElemId,manuId); + } + else + { + // we're locked. probably a bad manuId ? + return fgkSelfDead; + } + } + + Int_t statusMap = param->ValueAsInt(manuChannel); + + AliMUONVCalibParam* r = static_cast(fRejectList->FindObject(detElemId,manuId)); + + if (r) + { + Float_t v= r->ValueAsFloat(manuChannel); + + assert (v==0.0 || v==1.0 ); + if ( v > 0 ) + { + statusMap |= fgkSelfDead; + } + } + return statusMap; + } -