00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #include "RerootExodus/UgliGeometryReroot.h"
00014
00015 #include "UgliGeometry/TGeometryX.h"
00016 #include "UgliGeometry/UgliStripNode.h"
00017 #include "Conventions/Munits.h"
00018
00019 #include "MINF_Classes/MINFast.h"
00020 #include "REROOT_Classes/REROOT_Event.h"
00021 #include "REROOT_Classes/REROOT_Geom.h"
00022 #include "REROOT_Classes/REROOT_GAFKey.h"
00023
00024 #include "TMath.h"
00025 #include "TCanvas.h"
00026 #include "TRotMatrix.h"
00027 #include "TBRIK.h"
00028 #include "TSPHE.h"
00029
00030 #include "MessageService/MsgService.h"
00031 CVSID("$Id: UgliGeometryReroot.cxx,v 1.36 2006/12/03 01:52:59 gmieg Exp $");
00032
00033 #include <iomanip>
00034
00035 #include "UgliGeometry/MinosOutline.h"
00036
00037 #include "DatabaseInterface/Dbi.h"
00038 #include "DatabaseInterface/DbiCascader.h"
00039 #include "DatabaseInterface/DbiTableProxy.h"
00040 #include "DatabaseInterface/DbiTableProxyRegistry.h"
00041 #include "DatabaseInterface/DbiOutRowStream.h"
00042 #include "DatabaseInterface/DbiWriter.h"
00043 #include "DatabaseInterface/DbiCache.h"
00044 #include "DatabaseInterface/DbiResultPtr.h"
00045
00046 #include "UgliGeometry/UgliDbiGeometry.h"
00047 #include "UgliGeometry/UgliDbiScintPlnStruct.h"
00048 #include "UgliGeometry/UgliDbiScintMdlStruct.h"
00049 #include "UgliGeometry/UgliDbiStripStruct.h"
00050 #include "UgliGeometry/UgliDbiSteelPln.h"
00051 #include "UgliGeometry/UgliDbiScintPln.h"
00052 #include "UgliGeometry/UgliDbiScintMdl.h"
00053 #include "UgliGeometry/UgliDbiStrip.h"
00054 #include <set>
00055
00056 #include "RerootExodus/RerootExodus.h"
00057
00058 #include <set>
00059 #include <vector>
00060
00061 ClassImp(UgliGeometryReroot)
00062
00063
00064 UgliGeometryReroot::UgliGeometryReroot()
00065 : UgliGeometry()
00066 {
00067
00068
00069 MSG("Ugli",Msg::kVerbose) << "UgliGeometryReroot default ctor" << endl;
00070
00071 if (UgliGeometry::kNotThere == GetMINFStatus()) {
00072 MSG("Ugli",Msg::kWarning)
00073 << "UgliGeometryReroot default ctor with no GetMINFStatus" << endl;
00074
00075 return;
00076 }
00077
00078 VldContext vldc = RerootExodus::BuildVldContext();
00079
00080 #ifndef NO_UGLI_DATABASE
00081 MakeTempTables(vldc);
00082 #endif
00083 BuildAll(vldc);
00084 }
00085
00086
00087 UgliGeometryReroot::UgliGeometryReroot(const VldContext& vldc)
00088 : UgliGeometry()
00089 {
00090
00091
00092 MSG("Ugli",Msg::kVerbose) << "UgliGeometryReroot vldc ctor " << endl;
00093
00094 if (UgliGeometry::kNotThere == GetMINFStatus()) {
00095 MSG("Ugli",Msg::kWarning)
00096 << "UgliGeometryReroot vldc ctor with no GetMINFStatus" << endl;
00097
00098 return;
00099 }
00100
00101 #ifndef NO_UGLI_DATABASE
00102 MakeTempTables(vldc);
00103 #endif
00104 BuildAll(vldc);
00105 }
00106
00107
00108 UgliGeometryReroot::~UgliGeometryReroot()
00109 {
00110
00111
00112 MSG("Ugli",Msg::kVerbose) << "UgliGeometryReroot dtor " << endl;
00113
00114 }
00115
00116
00117 UgliGeometry::EMINFStatus UgliGeometryReroot::GetMINFStatus() const
00118 { if (gMINFast) return UgliGeometry::kOkay;
00119 else return UgliGeometry::kNotThere;
00120 }
00121
00122
00123 void UgliGeometryReroot::BuildVldRange(const VldContext &vldc)
00124 {
00125
00126
00127 #ifdef NO_UGLI_DATABASE
00128 fVldRange = RerootExodus::BuildVldRange();
00129 #else
00130 UgliGeometry::BuildVldRange(vldc);
00131 #endif
00132
00133 }
00134
00135
00136 void UgliGeometryReroot::BuildShapes(const VldContext& vldc)
00137 {
00138
00139
00140 MSG("Ugli",Msg::kInfo) << "UgliGeometryReroot::BuildShapes " << endl;
00141
00142 if (!gMINFast) {
00143 MSG("Ugli",Msg::kFatal)
00144 << "UgliGeometryReroot::BuildShapes lacked gMINFast"
00145 << endl;
00146 return;
00147 }
00148
00149 UgliGeometry::BuildShapes(vldc);
00150
00151 #ifdef NO_UGLI_DATABASE
00152 MSG("Ugli",Msg::kInfo)
00153 << "UgliGeometryReroot BuildShapes NO_UGLI_DATABASE " << endl << endl;
00154
00155 TString name;
00156 MinosOutline *outline = 0;
00157
00159
00160 REROOT_Geom *rgeo = gMINFast->GetREROOTGeom();
00161 const TClonesArray *geommiscs = rgeo->geommiscs();
00162 const TClonesArray *supermodules = rgeo->supermodules();
00163 REROOT_GeomMisc *geommisc = (REROOT_GeomMisc*) geommiscs->At(0);
00164 REROOT_SuperModule *supermodule = 0;
00165
00166 TShape *ashapeptr = 0;
00167 TNodeX *anodeptr = 0;
00168 TNodeX *worldnode = 0;
00169 TNodeX *hallnode = 0;
00170
00171 Float_t local[3];
00172 Float_t global[3];
00173
00174
00175
00176 Float_t xsize = geommisc->VHall()[0] * Munits::cm;
00177 Float_t ysize = geommisc->VHall()[1] * Munits::cm;
00178 Float_t zsize = geommisc->VHall()[2] * Munits::cm;
00179
00180
00181 xsize = TMath::Max(TMath::Abs(geommisc->HallXmin()*Munits::cm),
00182 TMath::Abs(geommisc->HallXmax()*Munits::cm)) +
00183 100.*Munits::cm;
00184 ysize = TMath::Max(TMath::Abs(geommisc->HallYmin()*Munits::cm),
00185 TMath::Abs(geommisc->HallYmax()*Munits::cm)) +
00186 100.*Munits::cm;
00187 zsize = 0.5*(geommisc->HallZmax() - geommisc->HallZmin())*Munits::cm;
00188
00189
00190 Float_t xysize = TMath::Max(xsize,ysize) * TMath::Sqrt(2.0);
00191 xsize = xysize;
00192 ysize = xysize;
00193
00194 ashapeptr = new TBRIK("worldvol","The world space","void",
00195 xysize,xysize,zsize+100.*Munits::cm);
00196
00197 worldnode = new TNodeX("worldnode","The world space",
00198 "worldvol",0.,0.,0.);
00199 worldnode->SetVisibility(1);
00200 worldnode->SetLineColor(kYellow);
00201 worldnode->cd();
00202
00203
00204 ashapeptr = new TSPHE("originvol","origin","void",10.*Munits::cm);
00205 anodeptr = new TNodeX("originnode","origin","originvol",0.,0.,0.);
00206 anodeptr->SetLineColor(kMagenta);
00207
00208 ashapeptr = new TBRIK("hall","The hall","void",
00209 geommisc->VHall()[0]*Munits::cm,
00210 geommisc->VHall()[1]*Munits::cm,
00211 zsize);
00212
00213 Float_t x0hall = 0.5 * ( geommisc->HallXmin()*Munits::cm +
00214 geommisc->HallXmax()*Munits::cm);
00215 Float_t y0hall = 0.5 * ( geommisc->HallYmin()*Munits::cm +
00216 geommisc->HallYmax()*Munits::cm);
00217 Float_t z0hall = 0.5 * ( geommisc->HallZmin()*Munits::cm +
00218 geommisc->HallZmax()*Munits::cm);
00219
00220 const Float_t huge = 1.0e30;
00221
00222 if (x0hall>huge) x0hall = 0.0;
00223 if (y0hall>huge) y0hall = 0.0;
00224
00225
00226 supermodule = (REROOT_SuperModule*) supermodules->At(0);
00227 z0hall = geommisc->VHall()[2]*Munits::cm - supermodule->UpSpace()*Munits::cm;
00228
00229 z0hall = 0;
00230
00231 hallnode = new TNodeX("hall","The hall",
00232 "hall",x0hall,y0hall,z0hall);
00233 hallnode->SetVisibility(1);
00234 hallnode->SetLineColor(kRed);
00235
00236 MSG("Ugli",Msg::kInfo)
00237 << " UgliGeometryReroot::BuildShapes hall is sized ["
00238 << geommisc->VHall()[0]*Munits::cm << ","
00239 << geommisc->VHall()[1]*Munits::cm << ","
00240 << geommisc->VHall()[2]*Munits::cm << "] "
00241 << Munits::base_length_name << "s " << endl
00242 << " centered at ["
00243 << x0hall << ","
00244 << y0hall << ","
00245 << z0hall << "]" << endl;
00246
00247 MSG("Ugli",Msg::kInfo) << endl
00248 << " X hall limits "
00249 << geommisc->HallXmin()*Munits::cm << " "
00250 << geommisc->HallXmax()*Munits::cm << endl
00251 << " Y hall limits "
00252 << geommisc->HallYmin()*Munits::cm << " "
00253 << geommisc->HallYmax()*Munits::cm << endl
00254 << " Z hall limits "
00255 << geommisc->HallZmin()*Munits::cm << " "
00256 << geommisc->HallZmax()*Munits::cm << endl;
00257
00258
00259
00260 Detector::Detector_t nearfar =
00261 (Detector::Detector_t) fVldRange.GetDetectorMask();
00262
00263
00264 Int_t nsupmdl = geommisc->NSupmdl();
00265
00266 Char_t xx[40];
00267 TString supmdl_name, outline_name;
00268
00269 for (Int_t isupmdl = 0; isupmdl < nsupmdl; isupmdl++) {
00270
00271 supermodule = (REROOT_SuperModule*) supermodules->At(isupmdl);
00272
00273 hallnode->cd();
00274 hallnode->UpdateMatrix();
00275
00276 Float_t zmin_supmdl = supermodule->Zmin()*Munits::cm +
00277 supermodule->UpSpace()*Munits::cm;
00278 Float_t zmax_supmdl = supermodule->Zmax()*Munits::cm -
00279 supermodule->DnSpace()*Munits::cm;
00280 Float_t dz_supmdl = 0.5*(zmax_supmdl-zmin_supmdl);
00281 Float_t z0_supmdl = 0.5*(zmax_supmdl+zmin_supmdl) - z0hall;
00282 Float_t x0_supmdl = supermodule->SupX0()*Munits::cm;
00283 Float_t y0_supmdl = supermodule->SupY0()*Munits::cm;
00284
00285
00286
00287
00288
00289
00290
00291
00292 global[0] = x0_supmdl;
00293 global[1] = y0_supmdl;
00294 global[2] = z0_supmdl;
00295
00296 hallnode->Master2Local(global,local);
00297
00298 x0_supmdl = local[0];
00299 y0_supmdl = local[1];
00300 z0_supmdl = local[2];
00301
00302
00303
00304
00305
00306
00307 Float_t x0shift;
00308 PlaneView::PlaneView_t noview = PlaneView::kUnknown;
00309 PlaneCoverage::PlaneCoverage_t cover = PlaneCoverage::kComplete;
00310 if (nearfar == Detector::kNear)
00311 cover = PlaneCoverage::kNearFull;
00312
00313 sprintf(xx,"%d",isupmdl);
00314 supmdl_name = "SM"; supmdl_name += xx;
00315
00316
00317 if (nearfar == Detector::kNear && isupmdl == 0) {
00318 PlexPlaneId partActv(nearfar,-1,false,noview,
00319 PlaneCoverage::kNearPartial);
00320 outline_name = supmdl_name + "PartialActive";
00321 outline = new MinosOutline(outline_name,outline_name,"void",
00322 partActv,false,dz_supmdl,1.);
00323 x0shift = outline->GetGlobalXOffset() * Munits::cm;
00324 anodeptr = new TNodeX(outline_name,outline_name,outline_name,
00325 x0_supmdl+x0shift,y0_supmdl,z0_supmdl);
00326 anodeptr->SetLineColor(kGreen);
00327 anodeptr->SetVisibility(1);
00328 }
00329
00330
00331
00332
00333 if (nearfar == Detector::kCalib && isupmdl >= 5) {
00334
00335 outline_name = supmdl_name;
00336 Float_t dx = 0.5*(supermodule->Xmax()*Munits::cm -
00337 supermodule->Xmin()*Munits::cm);
00338 Float_t dy = 0.5*(supermodule->Ymax()*Munits::cm -
00339 supermodule->Ymin()*Munits::cm);
00340 Float_t dz = 0.5*(supermodule->Zmax()*Munits::cm -
00341 supermodule->Zmin()*Munits::cm);
00342 Float_t x0 = 0.5*(supermodule->Xmax()*Munits::cm +
00343 supermodule->Xmin()*Munits::cm);
00344 Float_t y0 = 0.5*(supermodule->Ymax()*Munits::cm +
00345 supermodule->Ymin()*Munits::cm);
00346 Float_t z0 = 0.5*(supermodule->Zmax()*Munits::cm +
00347 supermodule->Zmin()*Munits::cm);
00348 TBRIK *caldet_special = 0;
00349 caldet_special = new TBRIK(supmdl_name,supmdl_name,"void",dx,dy,dz);
00350 anodeptr = new TNodeX(supmdl_name,supmdl_name,supmdl_name,x0,y0,z0);
00351 anodeptr->SetLineColor(kGreen);
00352 anodeptr->SetVisibility(1);
00353
00354
00355 continue;
00356 }
00357
00358
00359 outline_name = supmdl_name + "FullActive";
00360 PlexPlaneId fullActv(nearfar,-1,false,noview,cover);
00361 outline = new MinosOutline(outline_name,outline_name,"void",
00362 fullActv,false,dz_supmdl,1.);
00363 x0shift = outline->GetGlobalXOffset() * Munits::cm;
00364 anodeptr = new TNodeX(outline_name,outline_name,outline_name,
00365 x0_supmdl+x0shift,y0_supmdl,z0_supmdl);
00366 anodeptr->SetLineColor(kGreen);
00367 anodeptr->SetVisibility(1);
00368
00369 outline_name = supmdl_name + "SteelEars";
00370 PlexPlaneId steelid = fullActv;
00371 steelid.SetIsSteel(true);
00372 outline = new MinosOutline(outline_name,outline_name,"void",
00373 steelid,true,dz_supmdl,1.);
00374 x0shift = outline->GetGlobalXOffset() * Munits::cm;
00375 anodeptr = new TNodeX(outline_name,outline_name,outline_name,
00376 x0_supmdl+x0shift,y0_supmdl,z0_supmdl);
00377 anodeptr->SetLineColor(kBlue);
00378 anodeptr->SetVisibility(1);
00379
00380 }
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 #endif
00398
00399 }
00400
00401
00402
00403 void UgliGeometryReroot::BuildNodes(const VldContext& vldc)
00404 {
00405
00406
00407 MSG("Ugli",Msg::kInfo) << "UgliGeometryReroot::BuildNodes " << endl;
00408
00409 if (!gMINFast) {
00410 MSG("Ugli",Msg::kFatal)
00411 << "UgliGeometryReroot::BuildNodes lacked gMINFast"
00412 << endl;
00413 return;
00414 }
00415
00416 #ifndef NO_UGLI_DATABASE
00417 UgliGeometry::BuildNodes(vldc);
00418 #else
00419 MSG("Ugli",Msg::kInfo)
00420 << "UgliGeometryReroot BuildNodes NO_UGLI_DATABASE " << endl << endl;
00421
00422
00423 fRootGeom->cd();
00424 TNodeX* hallnode = dynamic_cast<TNodeX*>(fRootGeom->GetNode("hall"));
00425 hallnode->cd();
00426
00427 Int_t nscint = RerootExodus::NumberOfPlanes(kTRUE);
00428 Int_t nsteel = RerootExodus::NumberOfPlanes(kFALSE);
00429 Int_t npairs = TMath::Max(nscint,nsteel);
00430
00431 if (!fPlaneNodes) fPlaneNodes = new TObjArray(nscint+nsteel);
00432
00433 TNodeX* node = 0;
00434
00435 for (Int_t rpln = 0; rpln < npairs; rpln++) {
00436
00437 TString pname = RerootExodus::PasvPlaneName(rpln);
00438 if ( pname[0] == 'B' || pname[0] == 'S' ) {
00439 PlexPlaneId steelid = RerootExodus::RerootPln2PlnId(rpln,kFALSE);
00440 node = new UgliSteelPlnNode(this,steelid);
00441 fPlaneNodes->AddLast(node);
00442 fPlaneTable[steelid] = node;
00443 }
00444
00445 TString aname = RerootExodus::ActvPlaneName(rpln);
00446 if ( aname[0] == 'F' || aname[0] == 'M' ) {
00447 PlexPlaneId scintid = RerootExodus::RerootPln2PlnId(rpln,kTRUE);
00448 node = new UgliScintPlnNode(this,scintid);
00449 fPlaneNodes->AddLast(node);
00450 fPlaneTable[scintid] = node;
00451 }
00452
00453 }
00454 #endif
00455
00456 }
00457
00458
00459
00460 void UgliGeometryReroot::MakeTempTables(const VldContext& vldc)
00461 {
00462
00463
00464 MSG("Ugli",Msg::kInfo)
00465 << "UgliGeometryReroot::MakeTempTables --"
00466 << endl
00467 << " this step can be bypassed for standard geometries by adding the line: "
00468 << endl
00469 << " UgliLoanPool::SetAlwaysUseDbi(true);"
00470 << endl
00471 << " in the job .C script before the any code triggers building the geometry."
00472 << endl;
00473
00474
00475 fVldRange = RerootExodus::BuildVldRange();
00476
00477 MakeTempDbiGeometry(vldc);
00478 MakeTempDbiScintStruct(vldc);
00479 MakeTempDbiPosInfo(vldc);
00480
00481 }
00482
00483
00484 void UgliGeometryReroot::MakeTempDbiGeometry(const VldContext& )
00485 {
00486
00487
00488 const char* tblName = "UGLIDBIGEOMETRY";
00489 const char* tblDescr = UgliDbiGeometry::GetTableDescr();
00490
00491
00492 DbiCascader& cascader =
00493 DbiTableProxyRegistry::Instance().GetCascader();
00494
00495
00496 Int_t dbNoTemp = cascader.CreateTemporaryTable(tblName,tblDescr);
00497 if ( dbNoTemp < 0 ) {
00498 MSG("Ugli",Msg::kWarning)
00499 << "No database will accept temporary tables." << endl;
00500 return;
00501 }
00502
00503
00504 Int_t aggNo = -1;
00505 Dbi::Task task = 0;
00506 VldTimeStamp now;
00507 DbiWriter<UgliDbiGeometry> writer(fVldRange,aggNo,task,now,dbNoTemp);
00508
00509
00510 writer.TableProxy().GetCache()->SetStale();
00511
00512
00513 Detector::Detector_t detector =
00514 (Detector::Detector_t) fVldRange.GetDetectorMask();
00515 bool isXYUV = false;
00516 if (Detector::kCalDet == detector) isXYUV = true;
00517
00518 REROOT_GeomMisc *geommisc = RerootExodus::GetGeomMisc();
00519
00520 Float_t hall_min[3];
00521 Float_t hall_max[3];
00522
00523 hall_min[0] = geommisc->HallXmin() * Munits::cm;
00524 hall_min[1] = geommisc->HallYmin() * Munits::cm;
00525 hall_min[2] = geommisc->HallZmin() * Munits::cm;
00526 hall_max[0] = geommisc->HallXmax() * Munits::cm;
00527 hall_max[1] = geommisc->HallYmax() * Munits::cm;
00528 hall_max[2] = geommisc->HallZmax() * Munits::cm;
00529
00530
00531 UgliDbiGeometry row(detector,isXYUV,hall_min,hall_max);
00532
00533
00534 writer << row;
00535
00536
00537
00538 bool success = writer.Close();
00539
00540 if (!success)
00541 MSG("Ugli",Msg::kWarning)
00542 << "Failed to write to temporary table." << endl;
00543
00544 }
00545
00546
00547 void UgliGeometryReroot::MakeTempDbiScintStruct(const VldContext& )
00548 {
00549
00550
00551
00552 const char* plnTblName = "UGLIDBISCINTPLNSTRUCT";
00553 const char* plnTblDescr = UgliDbiScintPlnStruct::GetTableDescr();
00554
00555 const char* mdlTblName = "UGLIDBISCINTMDLSTRUCT";
00556 const char* mdlTblDescr = UgliDbiScintMdlStruct::GetTableDescr();
00557
00558 const char* stripTblName = "UGLIDBISTRIPSTRUCT";
00559 const char* stripTblDescr = UgliDbiStripStruct::GetTableDescr();
00560
00561 #undef ORDERED_ENTRY
00562
00563 #ifdef ORDERED_ENTRY
00564 vector<UgliDbiScintPlnStruct> plnRowVec;
00565 vector<UgliDbiScintPlnStruct>::iterator plnRowIter;
00566 vector<UgliDbiScintMdlStruct> mdlRowVec;
00567 vector<UgliDbiScintMdlStruct>::iterator mdlRowIter;
00568 vector<UgliDbiStripStruct> stripRowVec;
00569 vector<UgliDbiStripStruct>::iterator stripRowIter;
00570 #endif
00571
00572
00573 DbiCascader& cascader =
00574 DbiTableProxyRegistry::Instance().GetCascader();
00575
00576
00577 Int_t plnDb = cascader.CreateTemporaryTable(plnTblName,plnTblDescr);
00578 Int_t mdlDb = cascader.CreateTemporaryTable(mdlTblName,mdlTblDescr);
00579 Int_t stripDb = cascader.CreateTemporaryTable(stripTblName,stripTblDescr);
00580 if ( plnDb < 0 || mdlDb < 0 || stripDb < 0) {
00581 MSG("Ugli",Msg::kWarning)
00582 << "No database will accept temporary tables." << endl;
00583 return;
00584 }
00585
00586
00587 Int_t aggNo = -1;
00588 Dbi::Task task = 0;
00589 VldTimeStamp now;
00590
00591 DbiWriter<UgliDbiScintPlnStruct> plnWriter(fVldRange,aggNo,task,now,plnDb);
00592 DbiWriter<UgliDbiScintMdlStruct> mdlWriter(fVldRange,aggNo,task,now,mdlDb);
00593 DbiWriter<UgliDbiStripStruct> stripWriter(fVldRange,aggNo,task,now,stripDb);
00594
00595
00596 plnWriter.TableProxy().GetCache()->SetStale();
00597 mdlWriter.TableProxy().GetCache()->SetStale();
00598 stripWriter.TableProxy().GetCache()->SetStale();
00599
00600
00601
00602 typedef set<UInt_t> indxset;
00603 typedef set<UInt_t>::iterator indxsetIter;
00604 typedef set<UInt_t>::const_iterator indxsetConstIter;
00605 typedef pair<indxsetIter,bool> indxsetPair;
00606 indxset plnEntered, mdlEnterd, stripEnterd;
00607
00608
00609 int npairs = RerootExodus::GetGeomMisc()->NPlanes() + 1;
00610 for (int ipln = 0; ipln<npairs; ipln++) {
00611 int rr_scint = RerootExodus::SteelToRerootPlane(ipln,true);
00612 PlexPlaneId scintplnid = RerootExodus::RerootPln2PlnId(rr_scint,true);
00613 REROOT_PlaneSpec *spec = RerootExodus::GetPlaneSpec(scintplnid);
00614
00615 if (!spec) continue;
00616
00617
00618 UInt_t plnIndx = UgliDbiStructHash(scintplnid).HashAsPlane();
00619 indxsetPair ispair = plnEntered.insert(plnIndx);
00620
00621
00622
00623 MSG("Ugli",Msg::kDebug)
00624 << " ScintPlnStruct " << scintplnid.AsString("c")
00625 << " hash " << plnIndx
00626 << " ispair.second " << (int)ispair.second << endl;
00627 if (!ispair.second) continue;
00628
00629 TString aname = RerootExodus::ActvPlaneName(rr_scint);
00630 int mxstrips = RerootExodus::NStripsNonZero(rr_scint);
00631
00632
00633 int last_extru = -1;
00634 int current_mdl = 0, first_strip = 0, last_strip = 0;
00635 for (int istrip=0; istrip<mxstrips; istrip++) {
00636 PlexStripEndId seid(scintplnid,istrip);
00637 REROOT_CellPos *cellpos = RerootExodus::GetCellPos(seid);
00638 if (!cellpos) continue;
00639 if (cellpos->IExtr() != last_extru) {
00640
00641 if (last_extru == -1) {
00642
00643 current_mdl = 0;
00644 first_strip = 0;
00645 }
00646 else {
00647
00648 string mdlName = StandardMdlName(scintplnid,current_mdl,aname);
00649 PlexScintMdlId scintmdlid(scintplnid,current_mdl);
00650 UgliDbiScintMdlStruct mdlRow(scintmdlid,mdlName,
00651 first_strip,last_strip);
00652 MSG("Ugli",Msg::kDebug)
00653 << "UgliDbiScintMdlStruct entry " << scintplnid.AsString("c")
00654 << " module " << current_mdl << " [" << first_strip
00655 << "," << last_strip << "] (hash = "
00656 << mdlRow.GetIndex(0) << ") " << endl;
00657 #ifdef ORDERED_ENTRY
00658 UInt_t indx = mdlRow.GetIndex(-1);
00659 if (mdlRowVec.size()<=indx) mdlRowVec.resize(indx+1);
00660
00661 mdlRowIter = mdlRowVec.begin() + indx;
00662 mdlRowVec[indx] = mdlRow;
00663 #else
00664 mdlWriter << mdlRow;
00665 #endif
00666
00667 current_mdl++;
00668 first_strip = last_strip+1;
00669 }
00670 last_extru = cellpos->IExtr();
00671 last_strip = first_strip;
00672 }
00673
00674
00675 Float_t totlen, wls_east, wls_west, len_east, len_west, len_bypass;
00676 totlen = TMath::Abs(cellpos->XYZReadout()[0] -
00677 cellpos->XYZFarend()[0] ) * Munits::cm;
00678 ABtoEastWest(cellpos->FiberTailA() * Munits::cm,
00679 cellpos->FiberTailB() * Munits::cm,
00680 scintplnid,aname,wls_east,wls_west);
00681
00682
00683 len_east = len_west = totlen;
00684 len_bypass = 0 * Munits::cm;
00685
00686
00687 UgliDbiStripStruct
00688 stripRow(seid,current_mdl,totlen,wls_east,wls_west,
00689 len_east,len_west,len_bypass);
00690 #ifdef ORDERED_ENTRY
00691 UInt_t indx = stripRow.GetIndex(-1);
00692 if (stripRowVec.size()<=indx) stripRowVec.resize(indx+1);
00693
00694 stripRowIter = stripRowVec.begin() + indx;
00695 stripRowVec[indx] = stripRow;
00696 #else
00697 stripWriter << stripRow;
00698 #endif
00699
00700 last_strip = istrip;
00701 }
00702 if (last_extru != -1) {
00703
00704 string mdlName = StandardMdlName(scintplnid,current_mdl,aname);
00705 UgliDbiScintMdlStruct mdlRow(PlexScintMdlId(scintplnid,current_mdl),
00706 mdlName,first_strip,last_strip);
00707 MSG("Ugli",Msg::kDebug)
00708 << "UgliDbiScintMdlStruct entry " << scintplnid.AsString("c")
00709 << " module " << current_mdl << " [" << first_strip
00710 << "," << last_strip << "] (hash = "
00711 << mdlRow.GetIndex(0) << ") " << endl;
00712 #ifdef ORDERED_ENTRY
00713 UInt_t indx = mdlRow.GetIndex(-1);
00714 if (mdlRowVec.size()<=indx) mdlRowVec.resize(indx+1);
00715
00716 mdlRowIter = mdlRowVec.begin() + indx;
00717 mdlRowVec[indx] = mdlRow;
00718 #else
00719 mdlWriter << mdlRow;
00720 #endif
00721 }
00722
00723
00724 Short_t nmodules = current_mdl+1;
00725 UgliDbiScintPlnStruct plnRow(scintplnid,nmodules);
00726 MSG("Ugli",Msg::kDebug)
00727 << "UgliDbiScintPlnStruct entry " << scintplnid.AsString("c")
00728 << " has " << nmodules << " modules (hash = "
00729 << plnRow.GetIndex(0) << ") " << endl;
00730 #ifdef ORDERED_ENTRY
00731 UInt_t indx = plnRow.GetIndex(-1);
00732 if (plnRowVec.size()<=indx) plnRowVec.resize(indx+1);
00733
00734 plnRowIter = plnRowVec.begin() + indx;
00735 plnRowVec[indx] = plnRow;
00736 #else
00737 plnWriter << plnRow;
00738 #endif
00739
00740 }
00741
00742 #ifdef ORDERED_ENTRY
00743
00744
00745 MSG("Ugli",Msg::kInfo)
00746 << "plnRowVec had " << plnRowVec.size() << " entries " << endl;
00747 for (UInt_t i = 0; i< plnRowVec.size(); i++)
00748 plnWriter << plnRowVec[i];
00749
00750 MSG("Ugli",Msg::kInfo)
00751 << "mdlRowVec had " << mdlRowVec.size() << " entries " << endl;
00752 for (UInt_t i = 0; i< mdlRowVec.size(); i++)
00753 mdlWriter << mdlRowVec[i];
00754
00755 MSG("Ugli",Msg::kInfo)
00756 << "stripRowVec had " << stripRowVec.size() << " entries " << endl;
00757 for (UInt_t i = 0; i< stripRowVec.size(); i++)
00758 stripWriter << stripRowVec[i];
00759
00760 MSG("Ugli",Msg::kInfo) << "Struct data entry complete" << endl;
00761 #endif
00762
00763
00764 bool plnSuccess = plnWriter.Close();
00765 MSG("Ugli",Msg::kInfo)
00766 << "plnStructWriter " << ((plnSuccess)?"ok":"failed") << endl;
00767 bool mdlSuccess = mdlWriter.Close();
00768 MSG("Ugli",Msg::kInfo)
00769 << "mdlStructWriter " << ((mdlSuccess)?"ok":"failed") << endl;
00770 bool stripSuccess = stripWriter.Close();
00771 MSG("Ugli",Msg::kInfo)
00772 << "stripStructWriter " << ((stripSuccess)?"ok":"failed") << endl;
00773
00774 if (!plnSuccess || !mdlSuccess || ! stripSuccess)
00775 MSG("Ugli",Msg::kWarning)
00776 << "Failed to write to temporary table." << endl;
00777 }
00778
00779
00780 void UgliGeometryReroot::MakeTempDbiPosInfo(const VldContext& vldc)
00781 {
00782
00783
00784
00785 MSG("Ugli",Msg::kInfo) << "UgliGeometryReroot: Start MakeTempDbiPosInfo" << endl;
00786
00787 const char* steelTblName = "UGLIDBISTEELPLN";
00788 const char* steelTblDescr = UgliDbiSteelPln::GetTableDescr();
00789
00790 const char* plnTblName = "UGLIDBISCINTPLN";
00791 const char* plnTblDescr = UgliDbiScintPln::GetTableDescr();
00792
00793 const char* mdlTblName = "UGLIDBISCINTMDL";
00794 const char* mdlTblDescr = UgliDbiScintMdl::GetTableDescr();
00795
00796 const char* stripTblName = "UGLIDBISTRIP";
00797 const char* stripTblDescr = UgliDbiStrip::GetTableDescr();
00798
00799
00800 DbiCascader& cascader =
00801 DbiTableProxyRegistry::Instance().GetCascader();
00802
00803
00804 Int_t steelDb = cascader.CreateTemporaryTable(steelTblName,steelTblDescr);
00805 Int_t plnDb = cascader.CreateTemporaryTable(plnTblName,plnTblDescr);
00806 Int_t mdlDb = cascader.CreateTemporaryTable(mdlTblName,mdlTblDescr);
00807 Int_t stripDb = cascader.CreateTemporaryTable(stripTblName,stripTblDescr);
00808 if ( steelDb < 0 || plnDb < 0 || mdlDb < 0 || stripDb < 0) {
00809 MSG("Ugli",Msg::kWarning)
00810 << "No database will accept temporary tables." << endl;
00811 return;
00812 }
00813
00814 typedef struct angles { Char_t view;
00815 Float_t thetax, phix, thetay, phiy, thetaz, phiz; } angles_t;
00816
00817 angles_t gminos_angles[] =
00818 { {'X', 90, 0, 90, 90, 0, 0},
00819 {'Y', 90, 270, 90, 0, 0, 0},
00820 {'U', 90, -45, 90, 45, 0, 0},
00821 {'V', 90, 45, 90, 135, 0, 0},
00822 {'A', 90, 0, 0, 0, 90, 270},
00823 {'B', 180, 0, 90, 0, 90, 270},
00824 {'W', 90, 45, 90, 135, 0, 0},
00825 {'?', 90, 0, 90, 90, 0, 0}
00826 };
00827 int nangles = sizeof(gminos_angles) / sizeof(angles_t);
00828
00829 for (int i=0; i<nangles; i++) {
00830
00831 gminos_angles[i].thetax *= Munits::degree;
00832 gminos_angles[i].thetay *= Munits::degree;
00833 gminos_angles[i].thetaz *= Munits::degree;
00834 gminos_angles[i].phix *= Munits::degree;
00835 gminos_angles[i].phiy *= Munits::degree;
00836 gminos_angles[i].phiz *= Munits::degree;
00837 }
00838
00839
00840
00841 int npairs = RerootExodus::GetGeomMisc()->NPlanes() + 1;
00842
00843
00844 REROOT_PlanePos *fake_scintpos = 0;
00845 REROOT_PlanePos *fake_steelpos = 0;
00846
00847
00848 VldTimeStamp now;
00849 Dbi::Task task = 0;
00850
00851 int iplnLastWritten = -1;
00852 for (int ipln = 0; ipln<npairs; ipln++) {
00853
00854 MSG("Ugli",Msg::kInfo)
00855 << "UgliGeometryReroot: fill temp position table for plane "
00856 << ipln << "\r" << flush;
00857
00858
00859 Int_t aggNo = ipln;
00860
00861
00862
00863
00864 DbiWriter<UgliDbiSteelPln> steelWriter(fVldRange,aggNo,task,now,steelDb);
00865
00866
00867
00868
00869
00870
00871
00872 DbiWriter<UgliDbiScintPln> plnWriter(fVldRange,aggNo,task,now,plnDb);
00873 DbiWriter<UgliDbiScintMdl> mdlWriter(fVldRange,aggNo,task,now,mdlDb);
00874 DbiWriter<UgliDbiStrip> stripWriter(fVldRange,aggNo,task,now,stripDb);
00875
00876
00877 steelWriter.TableProxy().GetCache()->SetStale();
00878 plnWriter.TableProxy().GetCache()->SetStale();
00879 mdlWriter.TableProxy().GetCache()->SetStale();
00880 stripWriter.TableProxy().GetCache()->SetStale();
00881
00882
00883 int rr_scint = RerootExodus::SteelToRerootPlane(ipln,true);
00884 int rr_steel = RerootExodus::SteelToRerootPlane(ipln,false);
00885 PlexPlaneId scintplnid = RerootExodus::RerootPln2PlnId(rr_scint,true);
00886 PlexPlaneId steelplnid = RerootExodus::RerootPln2PlnId(rr_steel,false);
00887 REROOT_PlanePos *scintpos = RerootExodus::GetPlanePos(scintplnid);
00888 REROOT_PlaneSpec *scintspec = RerootExodus::GetPlaneSpec(scintplnid);
00889 REROOT_PlanePos *steelpos = RerootExodus::GetPlanePos(steelplnid);
00890 REROOT_PlaneSpec *steelspec = RerootExodus::GetPlaneSpec(steelplnid);
00891
00892
00893
00894
00895
00896 bool ok_steel = (steelplnid.GetPlane() == ipln);
00897 bool ok_scint = (scintplnid.GetPlane() == ipln);
00898 if (!ok_steel && !ok_scint) {
00899 MSG("Ugli",Msg::kError)
00900 << endl << "Neither ok_steel nor ok_scint."
00901 << endl;
00902 continue;
00903 }
00904 if (!ok_steel && ok_scint) {
00905 steelplnid = scintplnid;
00906 steelplnid.SetIsSteel(true);
00907 steelpos = RerootExodus::GetPlanePos(steelplnid);
00908 steelspec = RerootExodus::GetPlaneSpec(steelplnid);
00909 }
00910
00911
00912
00913
00914
00915
00916 bool iscaldet = scintplnid.GetDetector() == Detector::kCalDet;
00917 bool noinfo = ( !scintspec || !scintpos );
00918 bool caldet0 = iscaldet && noinfo && scintplnid.GetPlane() == 0;
00919 bool caldet60 = iscaldet && scintplnid.GetPlane() == 60;
00920
00921 char key = RerootExodus::ActvPlaneName(rr_scint)[0];
00922 bool trailing_scint = ( ipln == npairs-1 && ok_scint && !ok_steel
00923 && ( key == 'F' || key == 'M' ) );
00924
00925 if (caldet0) {
00926
00927
00928 PlexPlaneId caldet2id = scintplnid;
00929 caldet2id.SetPlane(2);
00930 scintpos = RerootExodus::GetPlanePos(caldet2id);
00931
00932
00933 PLANEPOS_DEF *pp = CreateAndBackFillPlanePosDef(scintpos);
00934
00935 pp->ID -= 2;
00936 pp->InMdl -= 2;
00937 Float_t dz = pp->PairZmax - pp->PairZmin;
00938 pp->PairZmin -= 2*dz - zoffset_REROOT();
00939 pp->PairZmax -= 2*dz - zoffset_REROOT();
00940 pp->ZFrntPasv -= 2*dz - zoffset_REROOT();
00941 pp->ZFrntActv -= 2*dz - zoffset_REROOT();
00942
00943 if (fake_scintpos) delete fake_scintpos;
00944 fake_scintpos = new REROOT_PlanePos(pp);
00945
00946 delete pp;
00947
00948 scintpos = fake_scintpos;
00949
00950 steelspec = RerootExodus::GetPlaneSpec(caldet2id);
00951
00952 }
00953 else if (caldet60) {
00954
00955
00956 PlexPlaneId caldet58id = steelplnid;
00957 caldet58id.SetPlane(58);
00958 steelpos = RerootExodus::GetPlanePos(caldet58id);
00959
00960
00961 PLANEPOS_DEF *pp = CreateAndBackFillPlanePosDef(steelpos);
00962
00963 pp->ID += 2;
00964 pp->InMdl += 2;
00965 Float_t dz = pp->PairZmax - pp->PairZmin;
00966 pp->PairZmin += 2*dz - zoffset_REROOT();
00967 pp->PairZmax += 2*dz - zoffset_REROOT();
00968 pp->ZFrntPasv += 2*dz - zoffset_REROOT();
00969 pp->ZFrntActv += 2*dz - zoffset_REROOT();
00970
00971 if (fake_steelpos) delete fake_steelpos;
00972 fake_steelpos = new REROOT_PlanePos(pp);
00973
00974 delete pp;
00975
00976 steelpos = fake_steelpos;
00977
00978 steelspec = RerootExodus::GetPlaneSpec(caldet58id);
00979
00980 }
00981 else if ( trailing_scint ) {
00982 MSG("Ugli",Msg::kInfo) << endl;
00983 MSG("Ugli",Msg::kWarning)
00984 << " Geometry with trailing scint plane " << endl;
00985
00986
00987
00988
00989
00990 PlexPlaneId fakesteelid = steelplnid;
00991 fakesteelid.SetPlane(steelplnid.GetPlane()-2);
00992 steelpos = RerootExodus::GetPlanePos(fakesteelid);
00993
00994
00995 PLANEPOS_DEF *pp = CreateAndBackFillPlanePosDef(steelpos);
00996
00997 pp->ID += 2;
00998 pp->InMdl += 2;
00999 Float_t dz = pp->PairZmax - pp->PairZmin;
01000 pp->PairZmin += 2*dz - zoffset_REROOT();
01001 pp->PairZmax += 2*dz - zoffset_REROOT();
01002 pp->ZFrntPasv += 2*dz - zoffset_REROOT();
01003 pp->ZFrntActv += 2*dz - zoffset_REROOT();
01004
01005 if (fake_steelpos) delete fake_steelpos;
01006 fake_steelpos = new REROOT_PlanePos(pp);
01007
01008 delete pp;
01009
01010 steelpos = fake_steelpos;
01011
01012 steelspec = RerootExodus::GetPlaneSpec(fakesteelid);
01013 }
01014
01015
01016 if (!steelpos) {
01017 MSG("Ugli",Msg::kInfo)
01018 << endl << "!steelpos for ipln " << ipln << "." << endl;
01019 continue;
01020 }
01021
01022
01023 char steelnam[16], scintnam[16];
01024 sprintf(steelnam,"%s",steelplnid.AsString("c"));
01025 sprintf(scintnam,"%s",scintplnid.AsString("c"));
01026
01027 MSG("Ugli",Msg::kVerbose)
01028 << "UgliGeometryReroot: build table info for "
01029 << steelnam << " " << (int)ok_steel
01030 << " " << steelpos << " " << steelspec << " "
01031 << scintnam << " " << (int)ok_scint
01032 << " " << scintpos << " " << scintspec << " "
01033 << RerootExodus::ActvPlaneName(rr_scint)
01034 << endl;
01035
01036 PlaneCoverage::PlaneCoverage_t cover = scintplnid.GetPlaneCoverage();
01037
01038 Float_t cell_width = 0;
01039 Float_t scint_thick = 0;
01040 Float_t gap_scint = 0;
01041
01042 Float_t steel_thick = 0;
01043 Float_t gap_steel = 0;
01044 Int_t melt = -1;
01045 Float_t x0steel = 0;
01046 Float_t y0steel = 0;
01047
01048 if (scintspec && cover != PlaneCoverage::kNoActive) {
01049 cell_width = scintspec->CellWidth() * Munits::cm;
01050 scint_thick = scintspec->Thickness() * Munits::cm;
01051 gap_scint = scintspec->AirGap()[1] * Munits::cm;
01052 }
01053
01054 if (steelspec) {
01055 steel_thick = steelspec->Thickness() * Munits::cm;
01056 gap_steel = steelspec->AirGap()[0] * Munits::cm;
01057 melt = steelspec->BMap() + 1000000;
01058 }
01059
01060
01061
01062 angles_t steel_angles = gminos_angles[0];
01063
01064 PlaneView::PlaneView_t view = scintplnid.GetPlaneView();
01065 if (vldc.GetDetector() == Detector::kCalDet ) {
01066
01067 if (view == PlaneView::kU) view = PlaneView::kY;
01068 if (view == PlaneView::kV) view = PlaneView::kX;
01069 }
01070
01071
01072 if (PlaneView::kA == view || PlaneView::kB == view) {
01073
01074
01075 steel_angles = gminos_angles[(int)view];
01076
01077
01078
01079 PlexPlaneId steelid_AB =
01080 RerootExodus::RerootPln2PlnId(rr_scint,false);
01081 steelpos = RerootExodus::GetPlanePos(steelid_AB);
01082 steelspec = RerootExodus::GetPlaneSpec(steelid_AB);
01083
01084 steel_thick = steelspec->Thickness() * Munits::cm;
01085 gap_steel = steelspec->AirGap()[0] * Munits::cm;
01086 melt = steelspec->BMap() + 1000000;
01087
01088
01089 PLANEPOS_DEF *pp = CreateAndBackFillPlanePosDef(steelpos);
01090
01091
01092 Float_t dz = 0.5*scintspec->Thickness();
01093 REROOT_Geom *rgeo = gMINFast->GetREROOTGeom();
01094
01095 #ifdef XYZZY_DEBUG
01096 cout << " pp->ZFrntPasv " << pp->ZFrntPasv << " cm "
01097 << ", dz " << dz << " cm "
01098 << ", shift " << rgeo->GetGlobalZ0Shift() << " cm "
01099 << ", steel " << steelspec->Thickness() << " cm "
01100 << endl;
01101
01102 #endif
01103
01104
01105
01106
01107
01108
01109 pp->ZFrntPasv += dz - rgeo->GetGlobalZ0Shift();
01110 pp->XYPasv[0] -= dz;
01111 pp->XYPasv[1] -= 2.0*dz;
01112
01113
01114 pp->ZFrntPasv += 0.0*steelspec->Thickness();
01115 pp->XYPasv[0] -= 1.0*steelspec->Thickness();
01116 pp->XYPasv[1] -= 1.0*steelspec->Thickness();
01117
01118
01119
01120 if (fake_steelpos) delete fake_steelpos;
01121 fake_steelpos = new REROOT_PlanePos(pp);
01122 delete pp;
01123 steelpos = fake_steelpos;
01124
01125 }
01126
01127
01128 Float_t gap = gap_scint + gap_steel;
01129 Float_t total_z = scint_thick + gap + steel_thick;
01130
01131 if (steelpos) {
01132 x0steel = steelpos->XYPasv()[0] * Munits::cm;
01133 y0steel = steelpos->XYPasv()[1] * Munits::cm;
01134 }
01135
01136 Float_t z_back = steelpos->ZFrntPasv()*Munits::cm + steel_thick;
01137
01138
01139
01140
01141 UgliDbiSteelPln steelRow(steelplnid,melt,steel_thick,total_z,
01142 x0steel,y0steel,z_back,
01143 steel_angles.thetax,steel_angles.phix,
01144 steel_angles.thetay,steel_angles.phiy,
01145 steel_angles.thetaz,steel_angles.phiz);
01146 steelWriter << steelRow;
01147
01148
01149
01150 bool steelSuccess = steelWriter.Close();
01151 if (!steelSuccess)
01152 MSG("Ugli",Msg::kWarning)
01153 << "Failed to write to temporary table." << endl;
01154
01155 bool doscint = true;
01156
01157 if (cover == PlaneCoverage::kNoActive) doscint = false;
01158 if (cover == PlaneCoverage::kUnknown ) doscint = false;
01159 if ( noinfo && !caldet0 ) doscint = false;
01160
01161
01162 TString aname = RerootExodus::ActvPlaneName(rr_scint);
01163 if ( aname[0] != 'F' && aname[0] != 'M' && !caldet0 ) doscint = false;
01164
01165 if (doscint) {
01166 Float_t x0scint_rel = scintpos->XYActv()[0]*Munits::cm - x0steel;
01167 Float_t y0scint_rel = scintpos->XYActv()[1]*Munits::cm - y0steel;
01168
01169
01170 angles_t scint_angles = gminos_angles[(int)view];
01171
01172 Float_t zrot = scint_angles.phix - steel_angles.phix;
01173
01174
01175 UgliDbiScintPln plnRow(scintplnid,scint_thick,gap,
01176 x0scint_rel,y0scint_rel, zrot);
01177 plnWriter << plnRow;
01178
01179
01180
01181
01182 VldContext vldc = RerootExodus::BuildVldContext();
01183 DbiResultPtr<UgliDbiScintPlnStruct> plnStructTable(vldc);
01184 DbiResultPtr<UgliDbiScintMdlStruct> mdlStructTable(vldc);
01185
01186 unsigned int pln_indx = UgliDbiStructHash(scintplnid).HashAsPlane();
01187 const UgliDbiScintPlnStruct* plnStruct =
01188 plnStructTable.GetRowByIndex(pln_indx);
01189
01190
01191 for (short mdl = 0; mdl<plnStruct->GetNModules(); mdl++) {
01192
01193 PlexScintMdlId scintmdlid(scintplnid,mdl);
01194 unsigned int mdl_indx =
01195 UgliDbiStructHash(scintmdlid).HashAsScintMdl();
01196 const UgliDbiScintMdlStruct* mdlStruct =
01197 mdlStructTable.GetRowByIndex(mdl_indx);
01198
01199 int first = mdlStruct->GetFirstStrip();
01200 int last = mdlStruct->GetLastStrip();
01201
01202 Float_t sum_clrA =0, sum_clrB = 0, sum_tpos = 0;
01203 Float_t tposFirst=9999., tposLast=-9999.;
01204 Int_t nstrips=0, nstripA=0, nstripB=0;
01205
01206
01207 for (short istrip = first; istrip <= last; istrip++) {
01208 PlexStripEndId seid(scintplnid,istrip);
01209 REROOT_CellPos *cellpos = RerootExodus::GetCellPos(seid);
01210
01211 const Float_t maxclr = 10.0 * Munits::m;
01212 Float_t clrA = cellpos->ClearFiberA() * Munits::cm;
01213 if (clrA < maxclr) { sum_clrA += clrA; nstripA++; }
01214 Float_t clrB = cellpos->ClearFiberB() * Munits::cm;
01215 if (clrB < maxclr) { sum_clrB += clrB; nstripB++; }
01216
01217
01218
01219 Float_t tpos = RerootExodus::SEIdToTPos(seid) * Munits::cm;
01220 sum_tpos += tpos;
01221 nstrips++;
01222 if (istrip == first) tposFirst = tpos;
01223 if (istrip == last) tposLast = tpos;
01224
01225
01226 }
01227
01228
01229
01230
01231
01232
01233
01234 if (nstripA<=0||sum_clrA<=0.0) {nstripA=1; sum_clrA=99.99*Munits::m;}
01235 if (nstripB<=0||sum_clrB<=0.0) {nstripB=1; sum_clrB=99.99*Munits::m;}
01236 Float_t clear_east, clear_west;
01237 ABtoEastWest(sum_clrA/nstripA,sum_clrB/nstripB,
01238 scintplnid,aname,clear_east,clear_west);
01239
01240 int ipln = scintplnid.GetPlane();
01241 if (ipln == 1 || ipln == 2 || ipln == 3 || ipln == 6 )
01242 MSG("Exodus",Msg::kInfo)
01243 << "Module " << scintmdlid
01244 << " clear E=" << clear_east << "(" << nstripA << ") "
01245 << " W=" << clear_west << "(" << nstripB << ") "
01246 << endl;
01247
01248
01249 Float_t mdl_width = TMath::Abs(tposFirst - tposLast) + cell_width;
01250 Float_t tpos_center = sum_tpos/nstrips;
01251
01252 Float_t lpos_mdl = 0 * Munits::cm;
01253 Float_t zrot_mdl = 0;
01254
01255
01256 UgliDbiScintMdl mdlRow(PlexScintMdlId(scintplnid,mdl),
01257 mdl_width,tpos_center,
01258 lpos_mdl,zrot_mdl,clear_east,clear_west);
01259 mdlWriter << mdlRow;
01260
01261
01262
01263
01264 for (int istrip = first; istrip <= last; istrip++) {
01265 PlexStripEndId seid(scintplnid,istrip);
01266
01267
01268
01269 Float_t tpos =
01270 RerootExodus::SEIdToTPos(seid) * Munits::cm - tpos_center;
01271
01272
01273 Float_t lpos =
01274 RerootExodus::SEIdToLPos(seid) * Munits::cm;
01275
01276 if (vldc.GetDetector() == Detector::kNear && seid.GetPlane()<6)
01277 MSG("Ugli",Msg::kDebug)
01278 << seid.AsString("c") << " lpos " << lpos << endl;
01279 Float_t zrot = 0;
01280
01281 UgliDbiStrip stripRow(seid,tpos,lpos,zrot);
01282 stripWriter << stripRow;
01283
01284
01285 }
01286
01287
01288 }
01289
01290 }
01291
01292
01293
01294 bool plnSuccess = plnWriter.Close();
01295 bool mdlSuccess = mdlWriter.Close();
01296 bool stripSuccess = stripWriter.Close();
01297
01298 if (! plnSuccess || ! mdlSuccess || ! stripSuccess)
01299 MSG("Ugli",Msg::kWarning)
01300 << "Failed to write to temporary table." << endl;
01301 else
01302 iplnLastWritten = ipln;
01303
01304 }
01305
01306 if (vldc.GetDetector() == Detector::kFar) {
01307
01308
01309
01310 for (int ipln = iplnLastWritten+1; ipln<2*249; ++ipln) {
01311 MSG("Ugli",Msg::kInfo)
01312 << "UgliGeometryReroot: fill temp position table for plane "
01313 << ipln << "\r" << flush;
01314
01315 Int_t aggNo = ipln;
01316
01317 DbiWriter<UgliDbiSteelPln> steelWriter(fVldRange,aggNo,task,now,steelDb);
01318 DbiWriter<UgliDbiScintPln> plnWriter(fVldRange,aggNo,task,now,plnDb);
01319 DbiWriter<UgliDbiScintMdl> mdlWriter(fVldRange,aggNo,task,now,mdlDb);
01320 DbiWriter<UgliDbiStrip> stripWriter(fVldRange,aggNo,task,now,stripDb);
01321
01322
01323 steelWriter.TableProxy().GetCache()->SetStale();
01324 plnWriter.TableProxy().GetCache()->SetStale();
01325 mdlWriter.TableProxy().GetCache()->SetStale();
01326 stripWriter.TableProxy().GetCache()->SetStale();
01327
01328
01329
01330
01331 if (!steelWriter.Close() || !plnWriter.Close() ||
01332 !mdlWriter.Close() || !stripWriter.Close() ) {
01333 MSG("Ugli",Msg::kWarning)
01334 << "Failed to write to temporary table." << endl;
01335 }
01336 }
01337 }
01338
01339 if (fake_scintpos) delete fake_scintpos; fake_scintpos = 0;
01340 if (fake_steelpos) delete fake_steelpos; fake_steelpos = 0;
01341
01342 MSG("Ugli",Msg::kInfo) << endl << "temp position table filled" << endl;
01343
01344 }
01345
01346
01347 string UgliGeometryReroot::StandardMdlName(PlexPlaneId plnid, int module,
01348 TString& aname)
01349 {
01350
01351
01352
01353 Detector::Detector_t detector = plnid.GetDetector();
01354 PlaneView::PlaneView_t view = plnid.GetPlaneView();
01355 PlaneCoverage::PlaneCoverage_t cover = plnid.GetPlaneCoverage();
01356
01357 char mchar = '?';
01358 char vchar = PlaneView::AsString(view)[0];
01359
01360 static char scratch[32];
01361
01362 switch (detector) {
01363 case (Detector::kNear): {
01364 char key = aname[0];
01365 if (cover == PlaneCoverage::kNearPartial) {
01366
01367 if (module >= 4) break;
01368 const char* mdl_list;
01369
01370
01371
01372
01373 if (key == 'F') {
01374 if ('U' == vchar) mdl_list = "qihg";
01375 else if ('V' == vchar) mdl_list = "ghiq";
01376 else break;
01377 }
01378 else {
01379
01380 if ('U' == vchar) mdl_list = "IHG";
01381 else if ('V' == vchar) mdl_list = "GHI";
01382 else break;
01383 }
01384 mchar = mdl_list[module];
01385 }
01386 else if (cover == PlaneCoverage::kNearFull) {
01387 const char* mdl_list;
01388 if (key == 'F') {
01389 if ('U' == vchar) mdl_list = "NMLKJ";
01390 else if ('V' == vchar) mdl_list = "JKLMN";
01391 else break;
01392 }
01393 else {
01394
01395 if ('U' == vchar) mdl_list = "NMLKJ";
01396 else if ('V' == vchar) mdl_list = "JKLMN";
01397 else break;
01398 }
01399 mchar = mdl_list[module];
01400 }
01401 break;
01402 }
01403 case (Detector::kFar): {
01404 if (cover != PlaneCoverage::kComplete) break;
01405 if (module >= 8) break;
01406 const char* mdl_list;
01407 if ('U' == vchar) mdl_list = "abefFEBA";
01408 else if ('V' == vchar) mdl_list = "abcdDCBA";
01409 else break;
01410 mchar = mdl_list[module];
01411 break;
01412 }
01413 case (Detector::kCalDet): {
01414 if (cover != PlaneCoverage::kComplete) break;
01415 mchar = 'X';
01416 break;
01417 }
01418 default:
01419 mchar = '?';
01420 break;
01421 }
01422
01423 if ('?' == mchar) {
01424 char cchar = PlaneCoverage::AsString(cover)[0];
01425 sprintf(scratch,"%c:%c%c%2.2d",Detector::AsString(detector)[0],
01426 cchar,vchar,module);
01427 }
01428 else sprintf(scratch,"%c%c",mchar,vchar);
01429
01430 return scratch;
01431 }
01432
01433
01434 void UgliGeometryReroot::ABtoEastWest(Float_t a, Float_t b,
01435 PlexPlaneId plnid, TString& aname,
01436 Float_t& east, Float_t& west)
01437 {
01438
01439
01440
01441
01442 Float_t tmpA = a;
01443 Float_t tmpB = b;
01444
01445 if ( plnid.GetPlaneView() != PlaneView::kV ||
01446 plnid.GetDetector() == Detector::kCalDet ) {
01447
01448 east = tmpA;
01449 west = tmpB;
01450 }
01451 else {
01452 if ( aname[0] == 'F' ) {
01453
01454
01455 east = tmpB;
01456 west = tmpA;
01457 }
01458 else {
01459
01460 east = tmpA;
01461 west = tmpB;
01462 }
01463 }
01464
01465 }
01466
01467
01468
01469 PLANEPOS_DEF* UgliGeometryReroot::CreateAndBackFillPlanePosDef(REROOT_PlanePos *reroot_PlanePos)
01470 {
01471
01472
01473
01474 PLANEPOS_DEF *ppdef = new PLANEPOS_DEF;
01475 ppdef->ID = reroot_PlanePos->ID() + 1;
01476 ppdef->ISuper = reroot_PlanePos->ISuper() + 1;
01477 ppdef->IModule = reroot_PlanePos->IModule() + 1;
01478 ppdef->InMdl = reroot_PlanePos->InMdl() + 1;
01479 ppdef->PairZmin = reroot_PlanePos->PairZmin();
01480 ppdef->PairZmax = reroot_PlanePos->PairZmax();
01481 strncpy(ppdef->PasvName,reroot_PlanePos->PasvName(),4);
01482 ppdef->XYPasv[0] = reroot_PlanePos->XYPasv()[0];
01483 ppdef->XYPasv[1] = reroot_PlanePos->XYPasv()[1];
01484 ppdef->ZFrntPasv = reroot_PlanePos->ZFrntPasv();
01485 strncpy(ppdef->ActvName,reroot_PlanePos->ActvName(),4);
01486 ppdef->XYActv[0] = reroot_PlanePos->XYActv()[0];
01487 ppdef->XYActv[1] = reroot_PlanePos->XYActv()[1];
01488 ppdef->ZFrntActv = reroot_PlanePos->ZFrntActv();
01489 strncpy(ppdef->Rotm,reroot_PlanePos->Rotm(),4);
01490 ppdef->ActvSpec = reroot_PlanePos->ActvSpec() + 1;
01491 ppdef->PasvSpec = reroot_PlanePos->PasvSpec() + 1;
01492 ppdef->RotmID = reroot_PlanePos->RotmID() + 1;
01493
01494 return ppdef;
01495 }
01496
01497