00001 #include "BField/Viz/BfldCanvasSlice.h"
00002
00003 #include <iostream>
00004 using namespace std;
00005
00006 #include "TMath.h"
00007 #include "TString.h"
00008 #include "TPolyLine.h"
00009 #include "TEllipse.h"
00010
00011 #include "Conventions/Munits.h"
00012 #include "Plex/PlexPlaneId.h"
00013 #include "UgliGeometry/UgliGeomHandle.h"
00014 #include "BField/BfldDbiPlaneMap.h"
00015 #include "DatabaseInterface/DbiResultPtr.h"
00016
00017 BfldCanvasSlice::BfldCanvasSlice(VldContext& vldc, int ipln,
00018 int iscoil, bool isgap, double zoff)
00019 : BfldCanvas(vldc,Form("BfldCanvasSlice%d",ipln),iscoil)
00020 , fPlane(ipln)
00021 , fIsGap(isgap)
00022 {
00023 SetVldContext(vldc);
00024 if (isgap) SetScaleMax(0.1);
00025
00026 UgliGeomHandle ugh(vldc);
00027 bool issteel = !isgap;
00028 double dz = zoff;
00029 Detector::Detector_t det = vldc.GetDetector();
00030 PlexPlaneId plnid(det,ipln,issteel);
00031 if ( ! plnid.IsValid() ) {
00032 if ( issteel ) {
00033
00034 cout << "invalid steel plane " << ipln << " " << plnid << endl;
00035 plnid = PlexPlaneId(det,0,true);
00036 } else {
00037
00038
00039 cout << "invalid scint plane " << ipln << " " << plnid << endl;
00040 plnid = PlexPlaneId(det,ipln,true);
00041 dz -= 0.5 * 5.94*Munits::cm;
00042 if ( ! plnid.IsValid() ) plnid = PlexPlaneId(det,0,true);
00043 }
00044 }
00045 vector<UgliPlnHandle> uphv = ugh.GetPlnHandleVector();
00046 for (unsigned int i = 0; i < uphv.size(); ++i ) {
00047 UgliPlnHandle uph = uphv[i];
00048 if ( uph.GetPlexPlaneId() == plnid ) {
00049 SetZ(uph.GetZ0()+dz);
00050 break;
00051 }
00052 }
00053
00054 BField bfld(vldc);
00055 bfld.SetInterpMethod(GetInterpMethod());
00056 Fill(bfld);
00057
00058 std::string name = Detector::AsString(vldc.GetDetector());
00059 name += ((isgap) ? "_gap" : "_pln");
00060 name += Form("%3.3d",ipln);
00061 name += GetZoomInterpString();
00062 name += " #scale[0.35]{#splitline";
00063 name += "{";
00064 name += GetAdmixtureString();
00065 name += "}";
00066 std::string zoffstr = "{.}";
00067 if ( zoff != 0.0 ) zoffstr = Form("{z0+%5.3f=%7.3f}",zoff,GetZ());
00068 cout << " zoffstr = " << zoffstr << " zoff " << zoff << " dz " << dz << endl;
00069 name += zoffstr;
00070 name += "}";
00071
00072 SetTitle(name);
00073
00074 }
00075
00076 BfldCanvasSlice::BfldCanvasSlice()
00077 : BfldCanvas()
00078 , fPlane(-999)
00079 , fIsGap(false)
00080 {
00081
00082 }
00083
00084 BfldCanvasSlice::~BfldCanvasSlice()
00085 { }
00086
00087 void BfldCanvasSlice::Draw()
00088 {
00089 BfldCanvas::Draw();
00090
00091
00092 double radius = 0.448;
00093 BfldDbiPlaneMap::MapShape_t shape = BfldDbiPlaneMap::kCircle;
00094
00095 const BfldDbiPlaneMap* plnmap = GetPlaneMap();
00096 if ( plnmap ) {
00097 radius = plnmap->GetDetailSize();
00098 shape = plnmap->GetDetailShape();
00099 }
00100
00101 int width = 1;
00102 int color = kWhite;
00103 int style = 2;
00104
00105 switch ( shape ) {
00106 case BfldDbiPlaneMap::kCircle:
00107 {
00108 static TEllipse circle;
00109 circle.SetLineWidth(width);
00110 circle.SetLineColor(color);
00111 circle.SetLineStyle(style);
00112 circle.SetFillStyle(0);
00113 circle.DrawEllipse(0,0,radius,radius,0.,360.,0.,"");
00114 break;
00115 }
00116 case BfldDbiPlaneMap::kSquare:
00117 {
00118 static TPolyLine square;
00119 double xs[] = { -radius, -radius, radius, radius, -radius };
00120 double ys[] = { -radius, radius, radius, -radius, -radius };
00121 square.SetLineWidth(width);
00122 square.SetLineColor(color);
00123 square.SetLineStyle(style);
00124 square.DrawPolyLine(5,xs,ys);
00125 break;
00126 }
00127 case BfldDbiPlaneMap::kDiamond:
00128 {
00129 static TPolyLine diamond;
00130 double xd[] = { -radius, 0, radius , 0, -radius };
00131 double yd[] = { 0, radius, 0, -radius, 0 };
00132 for (unsigned int i=0; i < sizeof(xd)/sizeof(double); ++i )
00133 { xd[i] *= TMath::Sqrt2(); yd[i] *= TMath::Sqrt2(); }
00134 diamond.SetLineWidth(width);
00135 diamond.SetLineColor(color);
00136 diamond.SetLineStyle(style);
00137 diamond.DrawPolyLine(5,xd,yd);
00138 break;
00139 }
00140 default:
00141 cout << "illegal detail shape " << shape << endl;
00142 }
00143 }
00144
00145 const BfldDbiPlaneMap* BfldCanvasSlice::GetPlaneMap()
00146 {
00147 DbiResultPtr<BfldDbiPlaneMap> tblrows(GetVldContext());
00148 return tblrows.GetRow(GetPlane());
00149 }
00150
00151 std::string BfldCanvasSlice::GetAdmixtureString()
00152 {
00153 std::string result;
00154
00155 const BfldDbiPlaneMap* plnmap = GetPlaneMap();
00156 if ( plnmap ) {
00157 int indxpair = BfldDbiPlaneMap::kFullSteelA;
00158 if ( GetIsGap() ) {
00159 if ( GetIsCoil() ) indxpair = BfldDbiPlaneMap::kDetailGapA;
00160 else indxpair = BfldDbiPlaneMap::kFullGapA;
00161 } else {
00162 if ( GetIsCoil() ) indxpair = BfldDbiPlaneMap::kDetailSteelA;
00163 else indxpair = BfldDbiPlaneMap::kFullSteelA;
00164 }
00165 if ( plnmap->IsNull(indxpair+1) ) {
00166
00167 result += Form("map_%d",plnmap->GetMapVariant(indxpair));
00168 } else {
00169 result += Form("%5.3f*map_%d+%5.3f*map_%d",
00170 plnmap->GetScale(indxpair),
00171 plnmap->GetMapVariant(indxpair),
00172 plnmap->GetScale(indxpair+1),
00173 plnmap->GetMapVariant(indxpair+1));
00174 }
00175 }
00176
00177 return result;
00178 }