00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include "UgliGeometry/UgliScintPlnNode.h"
00013
00014 #include "UgliGeometry/UgliGeometry.h"
00015 #include "UgliGeometry/TGeometryX.h"
00016
00017 #include "UgliGeometry/MinosOutline.h"
00018 #include "UgliGeometry/UgliDbiTables.h"
00019 #include "UgliGeometry/UgliScintMdlNode.h"
00020 #include "UgliGeometry/UgliStripNode.h"
00021
00022 #include "Conventions/Munits.h"
00023
00024 #include "Plex/PlexVetoShieldHack.h"
00025
00026 #include "TBRIK.h"
00027
00028 #include "MessageService/MsgService.h"
00029 CVSID("$Id: UgliScintPlnNode.cxx,v 1.32 2005/09/06 21:41:14 rhatcher Exp $");
00030
00031 #include <cassert>
00032
00033 ClassImp(UgliScintPlnNode)
00034
00035
00036 UgliScintPlnNode::UgliScintPlnNode()
00037 : UgliPlnNode()
00038 {
00039
00040 }
00041
00042
00043 UgliScintPlnNode::~UgliScintPlnNode()
00044 {
00045
00046 #ifdef DUPLICATE_WARNING
00047
00048 if (CountRef()) {
00049 MSG("Ugli",Msg::kWarning)
00050 << "~UgliScintPlnNode " << GetPlexPlaneId()
00051 << " still had " << CountRef()
00052 << " outstanding references " << endl;
00053 }
00054 #endif
00055 }
00056
00057
00058 UgliScintPlnNode::UgliScintPlnNode(const PlexPlaneId planeid,
00059 UgliGeometry* ugligeom,
00060 const UgliDbiTables& ugliTables)
00061 : UgliPlnNode(ugligeom,planeid)
00062 {
00063
00064
00065
00066 char boxname[16], plnname[16];
00067 sprintf(boxname,"%s",planeid.AsString("b"));
00068 sprintf(plnname,"%s",planeid.AsString("p"));
00069
00070
00071 const UgliDbiScintPln* plnRow =
00072 ugliTables.GetDbiScintPlnByIndex(planeid.GetPlane());
00073
00074 if (!plnRow) {
00075 MSG("Ugli",Msg::kError)
00076 << " no UgliDbiScintPln entry for " << planeid.AsString("C")
00077 << endl;
00078 return;
00079 }
00080
00081
00082 Float_t hthick = 0.5 * plnRow->GetThickness();
00083 fShape = new MinosOutline(plnname,plnname,"scint",planeid,
00084 false,hthick,1.0);
00085
00086
00087 TNode* box_node = fUgliGeometry->GetTGeometryX()->GetCurrentNode();
00088 if ( !box_node || strcmp(boxname,box_node->GetName()) ) {
00089
00090 MSG("Ugli",Msg::kWarning)
00091 << "UgliScintPlnNode " << planeid
00092 << " ctor didn't start in the right box node: "
00093 << box_node->GetName()
00094 << endl;
00095 box_node = fUgliGeometry->GetTNodeX(boxname);
00096 if (!box_node) {
00097 MSG("Ugli",Msg::kError)
00098 << "UgliScintPlnNode ctor found "
00099 << "the containing box node wasn't a TNodeX"
00100 << endl;
00101 return;
00102 }
00103 }
00104 if (GetParent() != box_node) {
00105 MSG("Ugli",Msg::kWarning)
00106 << "UgliScintPlnNode " << planeid
00107 << " ctor parent wasn't the right box node"
00108 << endl;
00109 SetParent(box_node);
00110 }
00111 MinosOutline *box_shape = dynamic_cast<MinosOutline*>(box_node->GetShape());
00112 if (!box_shape) {
00113 MSG("Ugli",Msg::kError)
00114 << "UgliScintPlnNode ctor found "
00115 << "the containing box is not a MinosOutline"
00116 << endl;
00117 return;
00118 }
00119
00120
00121 Float_t x0 = plnRow->GetX0RelSteel();
00122 Float_t y0 = plnRow->GetY0RelSteel();
00123 Float_t zshift_pln = hthick + box_shape->GetZ()[0];
00124 SetPosition(x0,y0,zshift_pln);
00125
00126
00127
00128 const Double_t deg90 = 90;
00129 Double_t zrot = plnRow->GetZRotRelSteelDeg();
00130 fMatrix = new TRotMatrix(plnname,plnname,
00131 deg90,zrot,deg90,zrot+deg90,0,0);
00132
00133 SetLineColor(38);
00134
00135
00136 BuildStrips(ugliTables);
00137
00138 }
00139
00140
00141 void UgliScintPlnNode::BuildStrips(const UgliDbiTables& ugliTables)
00142 {
00143
00144
00145 MSG("Ugli",Msg::kDebug)
00146 << " BuildStrips " << fPlaneId.AsString("c") << endl;
00147
00148 unsigned int pln_indx = UgliDbiStructHash(fPlaneId).HashAsPlane();
00149 const UgliDbiScintPlnStruct* plnStructRow =
00150 ugliTables.fScintPlnStructTbl.GetRowByIndex(pln_indx);
00151
00152 if (!plnStructRow) {
00153 unsigned int nstructrows = ugliTables.fScintPlnStructTbl.GetNumRows();
00154 MSG("Ugli",Msg::kError)
00155 << " no UgliDbiScintPlnStruct for " << fPlaneId
00156 << " hash to indx " << pln_indx
00157 << ", table has " << nstructrows << endl;
00158 for (unsigned int i=0; i<nstructrows; ++i) {
00159 const UgliDbiScintPlnStruct* aRow =
00160 ugliTables.fScintPlnStructTbl.GetRow(i);
00161 cout << " row " << i << " hash " << aRow->GetIndex(9999)
00162 << " " << Detector::AsString(aRow->GetDetector())
00163 << " view " << PlaneView::AsString(aRow->GetPlaneView())
00164 << " cover " << PlaneCoverage::AsString(aRow->GetPlaneCoverage())
00165 << endl;
00166 }
00167 abort();
00168 }
00169
00170
00171
00172 for (int imdl=0; imdl<plnStructRow->GetNModules(); imdl++) {
00173
00174 this->cd();
00175
00176 PlexScintMdlId scintmdlid(fPlaneId,imdl);
00177 unsigned int mdl_indx = UgliDbiStructHash(scintmdlid).HashAsScintMdl();
00178 const UgliDbiScintMdlStruct* mdlStructRow =
00179 ugliTables.fScintMdlStructTbl.GetRowByIndex(mdl_indx);
00180
00181 int first = mdlStructRow->GetFirstStrip();
00182 int last = mdlStructRow->GetLastStrip();
00183
00184 UgliScintMdlNode* mdlNode =
00185 new UgliScintMdlNode(scintmdlid,this,ugliTables);
00186 mdlNode->cd();
00187
00188
00189 for (int istrip = first; istrip <= last; istrip++) {
00190
00191 PlexStripEndId seid(fPlaneId,istrip);
00192 fStripTable[seid] = new UgliStripNode(seid,mdlNode,ugliTables);
00193
00194 }
00195
00196 }
00197
00198 }
00199
00200
00201 void UgliScintPlnNode::IncrementRef()
00202 {
00203 fRef++;
00204 fUgliGeometry->IncrementRef();
00205 SetVisibility(1);
00206 }
00207
00208 void UgliScintPlnNode::DecrementRef()
00209 {
00210 fRef--;
00211 fUgliGeometry->DecrementRef();
00212 if (!fRef) SetVisibility(0);
00213 }
00214
00215
00216 UgliStripNode* UgliScintPlnNode::GetStripNode(PlexStripEndId seid) const
00217 {
00218
00219
00220 TGeometryX* fRootGeom = fUgliGeometry->GetTGeometryX();
00221
00222 fRootGeom->cd();
00223
00224 PlexStripEndId geom_seid = seid;
00225
00226 if (geom_seid.GetDetector() == Detector::kFar &&
00227 geom_seid.IsVetoShield()) {
00228 VldContext vldc =
00229 PlexVetoShieldHack::ConvertRangeToContext(GetUgliGeometry()->GetVldRange());
00230 geom_seid = PlexVetoShieldHack::RenumberMuxToMdl(vldc,geom_seid);
00231 }
00232
00233 UgliScintPlnNode* the_plane = fUgliGeometry->GetScintPlnNode(geom_seid);
00234 if (the_plane != this) {
00235 string alt = " ";
00236 if (seid.IsVetoShield()) {
00237 alt = " [";
00238 alt += geom_seid.AsString("p");
00239 alt += "]";
00240 }
00241 MSG("Ugli",Msg::kFatal)
00242 << "UgliScintPlnNode::GetStripNode called on plane "
00243 << seid.AsString("p")
00244 << " other than itself "
00245 << seid.AsString("p") << alt << endl;
00246 }
00247 the_plane->cd();
00248
00249 PlexStripEndId seid_clean(geom_seid);
00250
00251 seid_clean.SetEnd(StripEnd::kUnknown);
00252 seid_clean.SetSubPart(StripEnd::kWhole);
00253 #ifdef USENODETODEPTH
00254 UgliStripNode* the_node =
00255 dynamic_cast<UgliStripNode*>(the_plane->GetNodeToDepth(seid_clean.AsString("c"),1));
00256 #else
00257
00258 UgliStripNode* the_node = 0;
00259 typedef std::map<PlexStripEndId,UgliStripNode*>::const_iterator stripTableItr_t;
00260 stripTableItr_t st_itr = fStripTable.find(seid_clean);
00261 if (st_itr != fStripTable.end()) the_node = st_itr->second;
00262 #endif
00263 if ( ! the_node ) {
00264 MSG("Ugli",Msg::kError)
00265 << "UgliScintPlnNode::GetStripNode not possible for "
00266 << seid_clean.AsString() << " " << seid << endl;
00267 std::map<PlexStripEndId,UgliStripNode*>::const_iterator mapitr =
00268 fStripTable.begin();
00269 while (mapitr != fStripTable.end()) {
00270 std::cerr << " " << mapitr->first
00271 << " StripNode* " << mapitr->second
00272 << std::endl;
00273 mapitr++;
00274 }
00275 assert(0);
00276 }
00277 return the_node;
00278 }
00279
00280
00281 Int_t UgliScintPlnNode::NumberOfStrips() const
00282 {
00283
00284
00285 return fStripTable.size();
00286
00287 #ifdef HARDCODED
00288
00289
00290 switch (fPlaneId.GetPlaneCoverage()) {
00291 case PlaneCoverage::kComplete:
00292 switch (fPlaneId.GetDetector()) {
00293 case Detector::kFar:
00294 return 192;
00295 break;
00296 case Detector::kCalib:
00297 return 24;
00298 break;
00299 default:
00300 break;
00301 }
00302 break;
00303 case PlaneCoverage::kNearFull:
00304 return 96;
00305 break;
00306 case PlaneCoverage::kNearPartial:
00307 return 68;
00308 break;
00309 default:
00310 break;
00311 }
00312
00313 MSG("Ugli",Msg::kError)
00314 << "UgliScintPlnNode::NumberOfStrips: unknown case "
00315 << fPlaneId.AsString() << endl;
00316 return 0;
00317 #endif
00318
00319 }
00320
00321
00322 vector<UgliStripNode*> UgliScintPlnNode::GetStripNodePtrVector() const
00323 {
00324
00325
00326 vector<UgliStripNode*> allStrips;
00327
00328 typedef map<PlexStripEndId,UgliStripNode*>::const_iterator nodeItr_t;
00329 nodeItr_t node_itr = fStripTable.begin();
00330 nodeItr_t node_end = fStripTable.end();
00331
00332 while (node_itr != node_end) {
00333 pair<PlexStripEndId,UgliStripNode*> map_pair = *node_itr;
00334 allStrips.push_back(map_pair.second);
00335 node_itr++;
00336 }
00337
00338 return allStrips;
00339 }
00340
00341
00342 vector<UgliScintMdlNode*> UgliScintPlnNode::GetScintMdlNodePtrVector() const
00343 {
00344
00345
00346 vector<UgliScintMdlNode*> allScintMdls;
00347
00348
00349 TObjLink *lnk = fNodes->FirstLink();
00350 while (lnk) {
00351 UgliScintMdlNode* mdlnode =
00352 dynamic_cast<UgliScintMdlNode*>(lnk->GetObject());
00353 if (mdlnode)
00354 allScintMdls.push_back(mdlnode);
00355 lnk = lnk->Next();
00356 }
00357
00358 return allScintMdls;
00359 }
00360
00361
00362 TVector3 UgliScintPlnNode::GlobalToLocal(const TVector3& global) const
00363 {
00364
00365
00366 Double_t gxyz[3], lxyz[3];
00367
00368 gxyz[0] = global.X();
00369 gxyz[1] = global.Y();
00370 gxyz[2] = global.Z();
00371
00372
00373 UgliScintPlnNode* self = const_cast<UgliScintPlnNode*>(this);
00374 self->cd();
00375 self->UpdateMatrix();
00376 self->Master2Local(gxyz,lxyz);
00377
00378 return TVector3(lxyz[0],lxyz[1],lxyz[2]);
00379 }
00380
00381
00382 TVector3 UgliScintPlnNode::LocalToGlobal(const TVector3& local) const
00383 {
00384
00385
00386 Double_t gxyz[3], lxyz[3];
00387
00388 lxyz[0] = local.X();
00389 lxyz[1] = local.Y();
00390 lxyz[2] = local.Z();
00391
00392
00393 UgliScintPlnNode* self = const_cast<UgliScintPlnNode*>(this);
00394 self->cd();
00395 self->UpdateMatrix();
00396 self->Local2Master(lxyz,gxyz);
00397
00398 return TVector3(gxyz[0],gxyz[1],gxyz[2]);
00399 }
00400
00401
00402 void UgliScintPlnNode::SetZRotRelSteelRad(Float_t radians)
00403 {
00404
00405
00406 Float_t zrotdeg = radians * Ugli::rad2deg;
00407 fMatrix->SetAngles(90,zrotdeg,90,zrotdeg+90,0,0);
00408 }
00409
00410