**************************************************************************/
// $Id$
+
+//-----------------------------------------------------------------------------
/// \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.
/// 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 "AliMUONObjectPair.h"
-#include "AliMUONV2DStore.h"
+#include "AliMUONPadStatusMaker.h"
+#include "AliMUONRejectList.h"
#include "AliMUONVCalibParam.h"
-#include "AliMUONVDataIterator.h"
-#include "AliMpIntPair.h"
+#include "AliMUONVStore.h"
+#include "AliMpConstants.h"
#include <Riostream.h>
-#include <TStopwatch.h>
+#include <TList.h>
+#include "TRandom.h"
+#include <cassert>
/// \cond CLASSIMP
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<AliMUONVCalibParam*>(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<<i);
+ AliWarning("Will run with non trivial survival probabilities for channels, manus, etc... Better check this is a simulation and not real data !");
+ fRejectList = new AliMUON2DMap(true);
}
}
- return statusMap;
+ else
+ {
+ fRejectList = fRejectProbabilities;
+ fRejectProbabilities = 0x0;
+ AliInfo("No RejectList found, so no RejectList will be used.");
+ }
}
//_____________________________________________________________________________
-Int_t
-AliMUONPadStatusMapMaker::GetPadStatus(Int_t detElemId,
- Int_t manuId, Int_t manuChannel) const
-
+AliMUONPadStatusMapMaker::~AliMUONPadStatusMapMaker()
{
- /// Get the pad status
- AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fStatus->Get(detElemId,manuId));
- return param->ValueAsInt(manuChannel);
+ /// dtor
+ delete fStatusMap;
+ delete fRejectProbabilities;
+ delete fRejectList;
}
//_____________________________________________________________________________
-AliMUONV2DStore*
-AliMUONPadStatusMapMaker::MakeEmptyPadStatusMap()
+AliMUONVCalibParam*
+AliMUONPadStatusMapMaker::ComputeStatusMap(Int_t detElemId, Int_t manuId) const
{
- /// Make an empty (but complete) statusMap
+ /// Compute the status map for a given manu, and add it to our internal
+ /// fStatusMap internal storage
- AliMUONCalibParamNI param(1,64,0);
+ AliCodeTimerAuto("(Int_t,Int_t)",0)
+
+ 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);
- return AliMUON2DMap::Generate(param);
+ AliMUONVCalibParam* statusParam = fkStatusMaker.PadStatus(detElemId,manuId);
+
+ Int_t n = neighbours->Dimension();
+
+ for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
+ {
+ Int_t statusMap(0);
+
+ Int_t x = neighbours->ValueAsIntFast(manuChannel,0);
+ if ( x < 0 )
+ {
+ // channel is not a valid one (i.e. (manuId,manuChannel) is not an existing pad)
+ statusMap = -1;//fgkSelfDead;
+ continue;
+ }
+
+ 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 & fMask) != 0 ) )
+ {
+ statusMap |= (1<<i);
+ }
+ }
+ param->SetValueAsIntFast(manuChannel,0,statusMap);
+ }
+ return param;
}
//_____________________________________________________________________________
-AliMUONV2DStore*
-AliMUONPadStatusMapMaker::MakePadStatusMap(const AliMUONV2DStore& 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
+ /// 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.
- fStatus = &status;
- fMask = mask;
+ if ( !fRejectProbabilities ) return;
- TStopwatch timer;
- timer.Start(kTRUE);
+ AliCodeTimerAuto("",0);
- AliMUONV2DStore* neighbourStore = fCalibrationData.Neighbours();
+ fRejectList->Clear();
- AliMUONV2DStore* statusMap = status.CloneEmpty();
+ TIter next(fRejectProbabilities->CreateIterator());
+ AliMUONVCalibParam* paramProba;
+ AliMUONVCalibParam* paramReject;
- AliMUONVDataIterator* it = status.Iterator();
- AliMUONObjectPair* pair;
-
- while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
+ while ( ( paramProba = static_cast<AliMUONVCalibParam*>(next()) ) )
{
- AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
-
- Int_t detElemId = ip->GetFirst();
- Int_t manuId = ip->GetSecond();
-
- AliMUONVCalibParam* statusEntry = static_cast<AliMUONVCalibParam*>(pair->Second());
+ paramReject = new AliMUONCalibParamNF(1,paramProba->Size(),paramProba->ID0(),paramProba->ID1(),0.0);
- AliMUONVCalibParam* statusMapEntry = static_cast<AliMUONVCalibParam*>
- (statusMap->Get(detElemId,manuId));
-
- if (!statusMapEntry)
- {
- statusMapEntry = new AliMUONCalibParamNI(1,64,0);
- statusMap->Set(detElemId,manuId,statusMapEntry,false);
- }
-
- AliMUONVCalibParam* neighbours = static_cast<AliMUONVCalibParam*>
- (neighbourStore->Get(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.
-
- Int_t statusMapValue(0);
-
- Int_t x = neighbours->ValueAsInt(manuChannel,0);
+ Float_t proba = paramProba->ValueAsFloat(i);
+ Float_t x(proba);
- if ( x > 0 )
- { // channel is a valid one (i.e. (manuId,manuChannel) is an existing pad)
- // assert(x>=0);
- 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 (it->IsOwner()) delete pair;
+ if (n) fRejectList->Add(paramReject);
}
-
- delete it;
+}
- timer.Stop();
+//_____________________________________________________________________________
+Int_t
+AliMUONPadStatusMapMaker::StatusMap(Int_t detElemId, Int_t manuId,
+ Int_t manuChannel) const
+
+{
+ /// Get the pad status map
+
+ AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(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);
- StdoutToAliInfo(
- cout << "MakePadStatusMap total timer : ";
- timer.Print();
- cout << endl;
- );
+ AliMUONVCalibParam* r = static_cast<AliMUONVCalibParam*>(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;
+
}
-