00001
00002
00003 #include <TStyle.h>
00004 #include <TColor.h>
00005 #include <TROOT.h>
00006 #include <TH1.h>
00007 #include <TGeoManager.h>
00008
00009 #include "TridPmtPage.h"
00010 #include "TridFlatGLFrame.h"
00011 #include "TridSketches.h"
00012 #include "TridModelPmt.h"
00013 #include "TridControl.h"
00014 #include "TridModelMaker.h"
00015
00016 #include "Midad/Base/PageProxy.h"
00017 #include "Midad/Gui/GuiBox.h"
00018 #include "Midad/Gui/GuiCanvas.h"
00019 #include "Midad/Gui/GuiMainWindow.h"
00020 #include "Midad/Base/Mint.h"
00021
00022 #include "MessageService/MsgService.h"
00023 #include <DataUtil/GetCandidate.h>
00024 #include <JobControl/JobC.h>
00025
00026 #include <sigc++/sigc++.h>
00027 #include <sigc++/class_slot.h>
00028
00029 #include "Plex/PlexSEIdAltL.h"
00030 #include "Plex/PlexPixelSpotId.h"
00031
00032 #include "CandData/CandRecord.h"
00033 #include "CandDigit/CandDigitListHandle.h"
00034 #include "CandDigit/CandDigitHandle.h"
00035
00036 const double kSizePmt_x = 0.5;
00037 const double kSizePmt_y = 0.5;
00038
00039 const double kSizePixel16_x = kSizePmt_x/4.;
00040 const double kSizePixel16_y = kSizePmt_y/4.;
00041
00042 const double kSizePixel64_x = kSizePmt_x/8.;
00043 const double kSizePixel64_y = kSizePmt_y/8.;
00044
00045 const double kSizeMux_x = 1.75;
00046 const double kSizeMux_y = 0.6;
00047 const int kBoxesPerRack = 8;
00048 const double kSizeRack_x = 2.0;
00049 const double kSizeRack_y = 5.0;
00050 const int kRacksPerLevel = 16;
00051 const double kSizeLevel_y = 5.0;
00052 const double kDistEW = kSizeLevel_y * 2;
00053
00054 CVSID("$Id: TridPmtPage.cxx,v 1.31 2006/04/20 00:37:39 tagg Exp $");
00055
00056
00057
00058 static PageProxy<TridPmtPage> gsTridPmtPageProxy("TridPmt");
00059
00060 TridPmtPage::TridPmtPage()
00061 : TridPage()
00062 {
00063 fViewModesSupported = kView2D | kView3D;
00064 fViewMode = kView2D;
00065 fWindowName = "TridPmt";
00066 fAutoPOV.Set(15.0, 0, 0, 10, 90, 0 );
00067 fFullPOV.Set(15.0, 0, 0, 10, 90, 0 );
00068 }
00069
00070 TridPmtPage::~TridPmtPage()
00071 {
00072 }
00073
00074
00075 TObject* TridPmtPage::Init(Mint* mint, PageDisplay* pageDisplay, GuiBox& box)
00076 {
00077 MSG("TriD",Msg::kDebug) << "TridPmtPage: Init()\n";
00078 return TridPage::Init(mint, pageDisplay, box);
00079 }
00080
00081
00082 TridGLFrame* TridPmtPage::CreateNewGLFrame( TridPage::ViewMode_t mode )
00083 {
00084 TridPOV min(0, 0,-kDistEW, 0, 0,-180);
00085 TridPOV max(kRacksPerLevel*kSizeRack_x,0, kDistEW,1000,90, 180);
00086
00087 if(mode==kView2D) {
00088 MSG("TriD",Msg::kDebug) << "Changing to 2D" << endl;
00089 return new TridFlatGLFrame(this,*fGuiBox,fTridControl,min,max);
00090 };
00091
00092 MSG("TriD",Msg::kDebug) << "Changing to 3D" << endl;
00093 return new TridGLFrame(this,*fGuiBox,fTridControl,min,max);
00094 }
00095
00096
00097
00098
00099
00100
00101
00102 TVector3 TridPmtPage::PmtToCoords(PlexPixelSpotId& spot,
00103 float& pmtsize )
00104 {
00105 float x,y,w,h;
00106 TVector3 v;
00107 TVector3 span;
00108
00109 if(fContext.GetDetector()==Detector::kFar){
00110 GetRackCoords_FD(spot.GetRackBay(),
00111 spot.GetRackLevel(),
00112 spot.GetEastWest(),
00113 x,y,w,h);
00114 v.SetXYZ(x,0,y);
00115 span.SetXYZ(w,0,h);
00116 OffsetPmtIntoRack_FD(spot,span,v,pmtsize);
00117 }
00118
00119 else if(fContext.GetDetector()==Detector::kCalDet) {
00120
00121 GetRackCoords_FD(spot.GetRackBay(),
00122 spot.GetRackLevel(),
00123 spot.GetEastWest(),
00124 x,y,w,h);
00125 v.SetXYZ(x,0,y);
00126 span.SetXYZ(w,0,h);
00127 OffsetPmtIntoRack_FD(spot,span,v,pmtsize);
00128
00129 }
00130
00131 else if(fContext.GetDetector()==Detector::kNear) {
00132
00133 GetRackCoords_ND(spot.GetRackBay(),
00134 spot.GetRackLevel(),
00135 spot.GetEastWest(),
00136 x,y,w,h);
00137 v.SetXYZ(x,0,y);
00138 span.SetXYZ(w,0,h);
00139 OffsetPmtIntoRack_ND(spot,span,v,pmtsize);
00140
00141 }
00142
00143 return v;
00144 }
00145
00146
00147 TVector3 TridPmtPage::PixelToCoords(PlexPixelSpotId& spot,
00148 float& pixelsize )
00149 {
00150 float pmtsize = 0;
00151 TVector3 v = PmtToCoords(spot,pmtsize);
00152 OffsetPixelIntoPmt(spot,pmtsize,v,pixelsize);
00153
00154 return v;
00155 }
00156
00157
00158 void TridPmtPage::GetRackCoords_FD(int rackbay, char racklvl, char ew,
00159 float& xoff, float& yoff, float& w, float& h)
00160 {
00161 const float kSizeRack_x = 2.0;
00162 const float kSizeRack_y = 5.0;
00163 const float kSizeLevel_y = 5.0;
00164 const float kDistEW = kSizeLevel_y * 2;
00165
00166 xoff=yoff=0;
00167 w = kSizeRack_x;
00168 h = kSizeRack_y;
00169
00170
00171 xoff += kSizeRack_x * (rackbay);
00172
00173
00174 if(fContext.GetDetector()==Detector::kCalDet) {
00175 xoff += kSizeRack_x;
00176 }
00177
00178
00179 if(racklvl == 'U')
00180 yoff += kSizeLevel_y;
00181
00182
00183 if(ew=='E')
00184 yoff += 0;
00185 else
00186 yoff -= kDistEW;
00187 }
00188
00189
00190 void TridPmtPage::GetRackCoords_ND(int rackbay, char racklvl, char ew,
00191 float& xoff, float& yoff, float& w, float& h)
00192 {
00193
00194 const float kSizeRack_x = 4.0;
00195 const float kSizeRack_y = 1.8;
00196 const float kSizeLevel_y = kSizeRack_y*2.2;
00197
00198 xoff = yoff = 0;
00199 w = kSizeRack_x;
00200 h = kSizeRack_y;
00201
00202 if(ew=='E') return;
00203
00204
00205 xoff += kSizeRack_x * (rackbay/2);
00206 yoff += kSizeRack_y * ((rackbay+1)%2);
00207
00208
00209 if(racklvl == 'U')
00210 yoff -= kSizeLevel_y;
00211 }
00212
00213
00214 void TridPmtPage::OffsetPmtIntoRack_FD(PlexPixelSpotId& spot,
00215 TVector3& rackSpan,
00216 TVector3& ioPos,
00217 float& pmtSize)
00218 {
00219 float sizeMux_x = rackSpan.X()*0.9;
00220 float sizeMux_y = rackSpan.Z()/(8.2);
00221
00222 float pmtSize_x = sizeMux_x/3.5;
00223 float pmtSize_y = sizeMux_y/1.2;
00224 pmtSize = (pmtSize_x>pmtSize_y)?pmtSize_y:pmtSize_x;
00225
00226 float xoff = 0;
00227 float yoff = 0;
00228
00229
00230 yoff += PlaceInBox(sizeMux_y,pmtSize,0,1);
00231 xoff += PlaceInBox(sizeMux_x,pmtSize,spot.GetTube(),3);
00232
00233
00234 xoff += PlaceInBox(rackSpan.X(),sizeMux_x,0,1);
00235 yoff += PlaceInBox(rackSpan.Z(),sizeMux_y,(spot.GetInRack()),8);
00236
00237 ioPos += TVector3(xoff,0,yoff);
00238 }
00239
00240 void TridPmtPage::OffsetPmtIntoRack_ND(PlexPixelSpotId& spot,
00241 TVector3& rackSpan,
00242 TVector3& ioPos,
00243 float& pmtSize)
00244 {
00245 float sizeAlner_x = rackSpan.X()*0.23;
00246 float sizeAlner_y = rackSpan.Z()*0.45;
00247
00248 float pmtSize_x = sizeAlner_x;
00249 float pmtSize_y = sizeAlner_y;
00250 pmtSize = (pmtSize_x>pmtSize_y)?pmtSize_y:pmtSize_x;
00251
00252 float xoff = 0;
00253 float yoff = 0;
00254
00255
00256 xoff += PlaceInBox(sizeAlner_x,pmtSize,0,1);
00257 yoff += PlaceInBox(sizeAlner_y,pmtSize,0,1);
00258
00259
00260 xoff += PlaceInBox(rackSpan.X(),sizeAlner_x,(spot.GetInRack()%4),4);
00261 yoff += PlaceInBox(rackSpan.Z(),sizeAlner_y,(spot.GetInRack()/4),2);
00262
00263 ioPos += TVector3(xoff,0,yoff);
00264 }
00265
00266
00267 void TridPmtPage::OffsetPixelIntoPmt(PlexPixelSpotId& spot, float pmtSize,
00268 TVector3& pos, float& pixelSize)
00269 {
00270 float xoff = 0;
00271 float yoff = 0;
00272 if(spot.GetElecType()==ElecType::kVA) {
00273 pixelSize = pmtSize*0.25;
00274
00275
00276 int ix= (spot.GetPixel()-1) % 4;
00277 int iy = (spot.GetPixel()-1) / 4;
00278
00279 xoff += float(ix)*pixelSize;
00280 yoff += float(iy)*pixelSize;
00281
00282 } else {
00283 pixelSize = pmtSize*0.125;
00284
00285
00286 int ix= (spot.GetPixel()-1) % 8;
00287 int iy = (spot.GetPixel()-1) / 8;
00288
00289 xoff += float(ix)*pixelSize;
00290 yoff += float(iy)*pixelSize;
00291 }
00292
00293
00294 xoff += pixelSize*0.5;
00295 yoff += pixelSize*0.5;
00296
00297 pos += TVector3(xoff,0,yoff);
00298 }
00299
00300
00301 void TridPmtPage::CreateScenery()
00302 {
00303 TridSketch::StartScenery();
00304 TridSketch::SetDefaultColor(fTridControl->GetForegroundColor());
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 if(fContext.GetDetector()==Detector::kFar)
00317 {
00318 const float kSizeRack_x = 2.0;
00319 const int kRacksPerLevel = 16;
00320 const float kSizeLevel_y = 5.0;
00321
00322
00323 for(int iew = 0;iew<2;iew++) {
00324 char ew = iew?'W':'E';
00325 for(int ilvl = 0; ilvl <2; ilvl++) {
00326 char lvl = ilvl?'U':'L';
00327 float x,y,w,h;
00328 for(int bay = 1;bay<=16;bay++) {
00329 GetRackCoords_FD(bay,lvl,ew,x,y,w,h);
00330
00331 TridSketch* l;
00332 l = new TridSketchLine( x, 0,y, x+w, 0, y ); fGLFrame->AddSketch(l);
00333 l = new TridSketchLine( x+w,0,y, x+w, 0, y+h); fGLFrame->AddSketch(l);
00334 l = new TridSketchLine( x, 0,y+h, x+w, 0, y+h); fGLFrame->AddSketch(l);
00335 l = new TridSketchLine( x, 0,y+h, x, 0, y); fGLFrame->AddSketch(l);
00336 }
00337 }
00338 }
00339
00340 TridSketchText* txt;
00341 txt = new TridSketchText( TVector3(-1.2, 0, kSizeLevel_y), kv_x, kv_y, "East Side");
00342 txt->SetScale(0.6);
00343 fGLFrame->AddSketch(txt);
00344
00345 txt = new TridSketchText( TVector3(-1.2,0,-kSizeLevel_y), kv_x, kv_y, "West Side");
00346 txt->SetScale(0.6);
00347 fGLFrame->AddSketch(txt);
00348
00349 txt = new TridSketchText( TVector3(-0.3,0,kSizeLevel_y*0.5), kv_x, kv_y, "Lower");
00350 txt->SetScale(0.5);
00351 fGLFrame->AddSketch(txt);
00352
00353 txt = new TridSketchText( TVector3(-0.3,0,kSizeLevel_y*1.5), kv_x, kv_y, "Upper");
00354 txt->SetScale(0.5);
00355 fGLFrame->AddSketch(txt);
00356
00357 txt = new TridSketchText( TVector3(-0.3,0,-kSizeLevel_y*1.5), kv_x, kv_y, "Lower");
00358 txt->SetScale(0.5);
00359 fGLFrame->AddSketch(txt);
00360
00361 txt = new TridSketchText( TVector3(-0.3,0,-kSizeLevel_y*0.5), kv_x, kv_y, "Upper");
00362 txt->SetScale(0.5);
00363 fGLFrame->AddSketch(txt);
00364
00365
00366 for(int i=1;i<=kRacksPerLevel;i++) {
00367 txt = new TridSketchText( TVector3(kSizeRack_x*((float)i-0.5), 0, kSizeLevel_y * 2.1),
00368 -kv_z, kv_y, Form("Bay%d",i) );
00369 txt->SetScale(0.3);
00370 fGLFrame->AddSketch(txt);
00371
00372 txt = new TridSketchText( TVector3(kSizeRack_x*((float)i-0.5), 0, -kSizeLevel_y * 2.1),
00373 -kv_z, kv_y, Form("Bay%d",i) );
00374 txt->SetScale(0.3);
00375 fGLFrame->AddSketch(txt);
00376 }
00377 } else if(fContext.GetDetector()==Detector::kCalDet) {
00378
00379
00380 for(int iew = 0;iew<2;iew++) {
00381 char ew = iew?'W':'E';
00382 char lvl = 'U';
00383 float x,y,w,h;
00384 for(int bay = 1;bay<=16;bay++) {
00385 GetRackCoords_FD(bay,lvl,ew,x,y,w,h);
00386 TridSketch* l;
00387 l = new TridSketchLine( x, 0,y, x+w, 0, y ); fGLFrame->AddSketch(l);
00388 l = new TridSketchLine( x+w,0,y, x+w, 0, y+h); fGLFrame->AddSketch(l);
00389 l = new TridSketchLine( x, 0,y+h, x+w, 0, y+h); fGLFrame->AddSketch(l);
00390 l = new TridSketchLine( x, 0,y+h, x, 0, y); fGLFrame->AddSketch(l);
00391 }
00392 }
00393
00394
00395 } else if(fContext.GetDetector()==Detector::kNear) {
00396
00397
00398
00399 char ew = 'W';
00400 for(int ilvl = 0; ilvl <2; ilvl++) {
00401 char lvl = ilvl?'U':'L';
00402 float x,y,w,h;
00403 for(int bay = 1;bay<=13;bay++) {
00404 GetRackCoords_ND(bay,lvl,ew,x,y,w,h);
00405 TridSketch* l;
00406 l = new TridSketchLine( x, 0,y, x+w, 0, y ); fGLFrame->AddSketch(l);
00407 l = new TridSketchLine( x+w,0,y, x+w, 0, y+h); fGLFrame->AddSketch(l);
00408 l = new TridSketchLine( x, 0,y+h, x+w, 0, y+h); fGLFrame->AddSketch(l);
00409 l = new TridSketchLine( x, 0,y+h, x, 0, y); fGLFrame->AddSketch(l);
00410 TVector3 botcenter(x+(w/2.), 0.0, y+h-(h/10.));
00411 TridSketchText* txt =
00412 new TridSketchText(botcenter,-kv_z,kv_y,
00413 Form("Rack %c%02d",lvl,bay));
00414 txt->SetTransparency(0.3);
00415 txt->SetThickness(0.001);
00416 txt->SetScale(h/6.);
00417 fGLFrame->AddSketch(txt);
00418 }
00419 }
00420 }
00421
00422 TridSketch::StopScenery();
00423 }
00424
00425
00426 void TridPmtPage::CreateModels()
00427 {
00428 fModels.Clear();
00429 fTridControl->ClearPicked();
00430 fTridControl->ClearSelected();
00431
00432 TridModelMaker maker;
00433 maker.Prepare(&(fMint->GetJobC().Mom));
00434 maker.CreatePmtModels(&(fMint->GetJobC().Mom),fModels);
00435 }
00436
00437
00438 void TridPmtPage::CreateSketches()
00439 {
00440 double meanx = 0;
00441 double meany = 0;
00442 double meanz = 0;
00443 double meann = 1e-9;
00444
00445 TridModel* basemodel;
00446 TridModelItr itr = fModels.GetIterator();
00447 while( (basemodel = itr.Next()) ) {
00448
00449 TridModelPmt* pmtModel = dynamic_cast<TridModelPmt*>(basemodel);
00450 TridModelPixel* pixelModel = dynamic_cast<TridModelPixel*>(basemodel);
00451
00452 if(pmtModel) {
00453
00454 float pmtsize=0;
00455 TVector3 x1 = PmtToCoords(pmtModel->fPixelSpot, pmtsize);
00456 TVector3 pos = x1+TVector3(pmtsize*0.5,0,pmtsize*0.5);
00457 pos.SetY(-0.1);
00458
00459 TridSketch* sk = new TridSketchPlane(pos,
00460 kv_x, pmtsize*0.5,
00461 kv_z, pmtsize*0.5 );
00462
00463 sk->SetTime(basemodel->GetEarliestTime());
00464 sk->SetColor(1,1,1);
00465 sk->SetTransparency(1);
00466 fModels.AssociateModel(basemodel,sk->GetId());
00467
00468 fGLFrame->AddSketch(sk);
00469 }
00470
00471 if(pixelModel) {
00472
00473
00474 int pixel = pixelModel->fPixelSpot.GetPixel() +1;
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493 PlexPixelSpotId spot = pixelModel->fPixelSpot;
00494 spot.SetPixel(pixel);
00495
00496 if(pixel>0) {
00497 TVector3 pos;
00498 float pixelsize=0;
00499 pos = PixelToCoords(spot,pixelsize);
00500
00501 float sizex = 0.9 * pixelsize;
00502 float sizez = 0.9 * pixelsize;
00503
00504
00505 float sizey = 0.0001* pixelModel->GetTotalCharge(CalStripType::kNone);
00506 if(sizey<0) sizey=0;
00507 pos.SetY(sizey*0.5);
00508
00509 TridSketch* sk =
00510 new TridSketchBox( pos,
00511 kv_x, sizex*0.5,
00512 kv_y, sizey*0.5,
00513 kv_z, sizez*0.5
00514 );
00515
00516 sk->SetTime(basemodel->GetEarliestTime());
00517 meanx += pos.x();
00518 meany += pos.y();
00519 meanz += pos.z();
00520 meann += 1;
00521
00522
00523
00524
00525 fModels.AssociateModel(basemodel,sk->GetId());
00526 fGLFrame->AddSketch(sk);
00527 }
00528 }
00529 }
00530
00531 ModifySketches();
00532
00533 meanx = meanx/meann;
00534 meany = meany/meann;
00535 meanz = meanz/meann;
00536 fGLFrame->Update();
00537 }
00538
00539
00540 void TridPmtPage::ModifySketches()
00541 {
00542
00543
00544
00545 fColorHistogram->Reset();
00546 fTransHistogram->Reset();
00547
00548 TridModelItr itr = fModels.GetIterator();
00549 TridModel* model;
00550 while( (model = itr.Next()) ) {
00551
00552
00553 int sketchnum = fModels.GetSketchNumber(model);
00554 TridSketch* sketch = fGLFrame->FindSketch(sketchnum);
00555
00556
00557 if((sketch)&&(model)) {
00558
00559 if(dynamic_cast<TridModelPixel*>(model)) {
00560
00561
00562 Double_t color_x = fTridControl->GetRangedModelColor(model);
00563 Double_t trans_x = fTridControl->GetRangedModelTrans(model);
00564
00565 sketch->SetColor(fTridControl->GetColor(color_x));
00566 sketch->SetTransparency(trans_x);
00567
00568
00569 sketch->SetDrawn(true);
00570 if(color_x<0)
00571 if(!fTridControl->ShowColorUnderScale())
00572 sketch->SetDrawn(false);
00573
00574 if(color_x>1)
00575 if(!fTridControl->ShowColorOverScale())
00576 sketch->SetDrawn(false);
00577
00578 if(fTridControl->IsPicked(model)) {
00579 sketch->SetColor(1,1,1);
00580 }
00581
00582 if(fTridControl->IsSelected(model)) {
00583 sketch->SetColor(1,1,1);
00584 }
00585
00586
00587 fColorHistogram->Fill(color_x);
00588 fTransHistogram->Fill(trans_x);
00589 } else {
00590
00591
00592
00593 Double_t color_x = fTridControl->GetRangedModelColor(model);
00594
00595
00596
00597 TVector3 color = (fTridControl->GetColor(color_x));
00598 color *=0.5;
00599 sketch->SetColor(color);
00600 sketch->SetTransparency(1.0);
00601
00602
00603 sketch->SetDrawn(true);
00604 if(color_x<0)
00605 if(!fTridControl->ShowColorUnderScale())
00606 sketch->SetDrawn(false);
00607
00608 if(color_x>1)
00609 if(!fTridControl->ShowColorOverScale())
00610 sketch->SetDrawn(false);
00611
00612
00613 if(fTridControl->IsPicked(model)) {
00614 sketch->SetColor(1,0,0);
00615 }
00616 if(fTridControl->IsSelected(model)) {
00617 sketch->SetColor(0,1,0);
00618 }
00619 }
00620 } else {
00621 MSG("TriD",Msg::kError) << "Cannot find sketch or model, model number " << model
00622 << " ModelAdd: " << model
00623 << " SketchNumber: " << sketchnum
00624 << " SketchAddr: " << sketch << endl;
00625 }
00626 }
00627 }