#include "AliMUONDEPainter.h"
#include "AliMUONBusPatchPainter.h"
#include "AliMUONGeometryTransformer.h"
#include "AliMUONPCBPainter.h"
#include "AliMUONContour.h"
#include "AliMUONPainterHelper.h"
#include "AliMUONVCalibParam.h"
#include "AliMUONVTrackerData.h"
#include "AliMUONObjectPair.h"
#include "AliMpDDLStore.h"
#include "AliMpDEManager.h"
#include "AliMpDetElement.h"
#include "AliMpPCB.h"
#include "AliMpSector.h"
#include "AliMpSlat.h"
#include "AliLog.h"
#include <TMap.h>
#include <TObjString.h>
#include "AliMUONPainterGroup.h"
ClassImp(AliMUONDEPainter)
AliMUONDEPainter::AliMUONDEPainter()
: AliMUONVPainter(),
fDetElemId(-1)
{
}
AliMUONDEPainter::AliMUONDEPainter(TRootIOCtor* ioCtor)
: AliMUONVPainter(ioCtor),
fDetElemId(-1)
{
}
AliMUONDEPainter::AliMUONDEPainter(const AliMUONAttPainter& att, Int_t detElemId)
: AliMUONVPainter("DE"),
fDetElemId(detElemId)
{
AliMUONAttPainter deAtt(att);
if ( att.IsCathodeDefined() )
{
AliMp::CathodType cathodType = ( att.IsCathode0() ? AliMp::kCath0 : AliMp::kCath1 ) ;
Bool_t cath0 = ( cathodType == AliMp::kCath0 ) ;
AliMp::PlaneType planeType = AliMpDEManager::GetPlaneType(detElemId,cathodType);
Bool_t bending = ( planeType == AliMp::kBendingPlane );
deAtt.SetCathode(cath0,!cath0);
deAtt.SetPlane(bending,!bending);
}
if ( att.IsPlaneDefined() )
{
AliMp::PlaneType planeType = ( att.IsBendingPlane() ? AliMp::kBendingPlane : AliMp::kNonBendingPlane );
Bool_t bending = ( planeType == AliMp::kBendingPlane );
Bool_t cath0 = ( AliMpDEManager::GetCathod(detElemId,planeType) == AliMp::kCath0 );
deAtt.SetCathode(cath0,!cath0);
deAtt.SetPlane(bending,!bending);
}
deAtt.SetCathodeAndPlaneMutuallyExclusive(kFALSE);
SetAttributes(deAtt);
AliMUONPainterHelper* h = AliMUONPainterHelper::Instance();
SetID(detElemId,-1);
SetName(h->DEName(fDetElemId).Data());
SetPathName(h->DEPathName(fDetElemId).Data());
AliMp::PlaneType planeType = ( Attributes().IsBendingPlane() ? AliMp::kBendingPlane : AliMp::kNonBendingPlane );
Double_t x,y,z;
if ( AliMpDEManager::GetStationType(DetElemId()) == AliMp::kStation345 )
{
const AliMpSlat* slat = h->GetSlat(DetElemId(),planeType);
for ( Int_t i = 0; i < slat->GetSize(); ++i )
{
Add(new AliMUONPCBPainter(Attributes(),DetElemId(),i));
}
AliMUONPainterHelper::Instance()->Local2Global(fDetElemId,0.0,0.0,0.0,x,y,z);
}
else if ( AliMpDEManager::GetStationType(DetElemId()) != AliMp::kStationTrigger )
{
const AliMpSector* sector = h->GetSector(DetElemId(),planeType);
Double_t xl(sector->GetDimensionX());
Double_t yl(sector->GetDimensionY());
h->Local2Global(fDetElemId,xl,yl,0.0,x,y,z);
}
else
{
AliFatal("Not implemented for trigger !!!");
}
AliMUONContour* contour = h->GetContour(ContourName());
TObjArray contourArray;
AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(fDetElemId);
AliDebug(1,Form("de %p n %d",de,de->GetNofBusPatches()));
for ( Int_t i = 0; i < de->GetNofBusPatches(); ++i )
{
AliMUONBusPatchPainter* painter = new AliMUONBusPatchPainter(Attributes(),de->GetBusPatchId(i));
if ( !painter->IsValid() )
{
AliDebug(1,Form("Skipping BP %d which seem to have no manu in plane %s",
de->GetBusPatchId(i),
Attributes().IsBendingPlane() ? "bending" : "non bending"));
delete painter;
continue;
}
else
{
Add(painter);
}
if ( !contour )
{
contourArray.Add(painter->Contour());
}
}
if (!contour)
{
contour = h->MergeContours(contourArray,ContourName());
if (!contour)
{
AliError(Form("%s : could not merge those contours",Name().Data()));
StdoutToAliError(contourArray.Print(););
}
}
SetContour(contour);
}
AliMUONDEPainter::AliMUONDEPainter(const AliMUONDEPainter& rhs):
AliMUONVPainter(rhs), fDetElemId(-1)
{
rhs.Copy(*this);
}
AliMUONDEPainter&
AliMUONDEPainter::operator=(const AliMUONDEPainter& rhs)
{
if ( this != &rhs )
{
rhs.Copy(*this);
}
return *this;
}
AliMUONDEPainter::~AliMUONDEPainter()
{
}
void
AliMUONDEPainter::ComputeDataRange(const AliMUONVTrackerData& data, Int_t dataIndex,
Double_t& dataMin, Double_t& dataMax) const
{
dataMin = dataMax = data.DetectionElement(fDetElemId, dataIndex);
}
void
AliMUONDEPainter::Copy(TObject& object) const
{
AliMUONVPainter::Copy((AliMUONVPainter&)(object));
((AliMUONDEPainter&)(object)).fDetElemId = fDetElemId;
}
TString
AliMUONDEPainter::Describe(const AliMUONVTrackerData& data, Int_t dataIndex,
Double_t, Double_t)
{
if (!data.HasDetectionElement(fDetElemId)) return "";
Double_t value = data.DetectionElement(fDetElemId,dataIndex);
return AliMUONPainterHelper::Instance()->FormatValue(data.DimensionName(dataIndex).Data(),value);
}
void
AliMUONDEPainter::FillManuList(TObjArray& manuList) const
{
TIter next(Children());
AliMUONVPainter* p;
while ( ( p = static_cast<AliMUONVPainter*>(next()) ) )
{
if ( p->IsA() == AliMUONBusPatchPainter::Class() )
{
p->FillManuList(manuList);
}
}
}
Bool_t
AliMUONDEPainter::IsIncluded() const
{
return ( InteractiveReadOutConfig()->DetectionElement(fDetElemId) > 0 );
}
void
AliMUONDEPainter::PaintArea(const AliMUONVTrackerData& data, Int_t dataIndex,
Double_t min, Double_t max)
{
if (!data.HasDetectionElement(fDetElemId)) return;
Double_t value = data.DetectionElement(fDetElemId,dataIndex);
if ( value >= AliMUONVCalibParam::InvalidFloatValue() ) return;
Int_t color = AliMUONPainterHelper::Instance()->ColorFromValue(value,min,max);
PaintArea(color);
}
AliMUONAttPainter
AliMUONDEPainter::Validate(const AliMUONAttPainter& attributes) const
{
AliMUONAttPainter norm(attributes);
norm.SetCathodeAndPlaneMutuallyExclusive(kFALSE);
if ( norm.IsCathodeDefined() && !norm.IsPlaneDefined() )
{
AliMp::CathodType cathodType = ( norm.IsCathode0() ? AliMp::kCath0 : AliMp::kCath1 );
AliMp::PlaneType planeType = AliMpDEManager::GetPlaneType(fDetElemId,cathodType);
Bool_t bending = ( planeType == AliMp::kBendingPlane ) ;
norm.SetPlane(bending,!bending);
}
else if ( !norm.IsCathodeDefined() && norm.IsPlaneDefined() )
{
AliMp::PlaneType planeType = ( norm.IsBendingPlane() ? AliMp::kBendingPlane : AliMp::kNonBendingPlane );
Bool_t cath0 = ( AliMpDEManager::GetCathod(fDetElemId,planeType) == AliMp::kCath0 );
norm.SetCathode(cath0,!cath0);
}
else
{
AliMp::PlaneType planeType = ( norm.IsBendingPlane() ? AliMp::kBendingPlane : AliMp::kNonBendingPlane );
AliMp::CathodType cathode = AliMpDEManager::GetCathod(fDetElemId,planeType);
if ( (cathode == AliMp::kCath0 && norm.IsCathode1()) ||
(cathode == AliMp::kCath1 && norm.IsCathode0()) )
{
norm.SetValid(kFALSE);
}
}
return norm;
}
void
AliMUONDEPainter::SetResponder(Int_t depth)
{
AliDebug(1,Form("depth=%d",depth));
if (!fPainterGroups)
{
CreateGroups();
}
TIter next(fPainterGroups);
TObjString* str;
fResponderGroup = 0x0;
while ( ( str = static_cast<TObjString*>(next()) ) )
{
AliMUONPainterGroup* group = static_cast<AliMUONPainterGroup*>(fPainterGroups->GetValue(str));
if ( str->String() == "BUSPATCH" )
{
AliDebug(1,Form("group %s is indeed buspatch, using as responder %d",
group->Type(),depth));
group->SetResponder(kTRUE);
fResponderGroup = group;
break;
}
else
{
group->SetResponder(kFALSE);
}
}
}