11 TPad *padRZ, *padXY, *padStat;
13 float LegendX, LegendY;
14 float lineScale = 1.5;
16 enum ProjectionType { kXY, kRZ, kRZSigned, kXZ, kYZ };
18 float xx(
float x,
float y,
float z, ProjectionType proj = kRZ ){
20 if ( proj == kRZ || proj == kRZSigned){
22 }
else if ( proj == kXY ){
24 }
else if ( proj == kXZ ){
26 }
else if ( proj == kYZ ){
33 float yy(
float x,
float y,
float z, ProjectionType proj = kRZ ){
36 float r = sqrt( pow(x, 2) + pow(y, 2) );
38 }
else if ( proj == kXY ){
40 }
else if ( proj == kRZSigned ){
41 float r = sqrt( pow(x, 2) + pow(y, 2) );
42 if ( y == 0 )
return r;
45 }
else if ( proj == kXZ ){
47 }
else if ( proj == kYZ ){
54 void viz_points(
const char* name,
const char* cmd,
int color,
int eventIndex, ProjectionType projType,
bool Legend =
false ){
56 fwd->Draw( cmd,
"",
"goff", 1, eventIndex );
57 int N = fwd->GetSelectedRows();
58 printf(
"%s : has %d results \n", cmd, N );
59 printf(
"Projection Mode : %d \n", projType );
61 auto cmdX = fwd->GetV1();
62 auto cmdY = fwd->GetV2();
63 auto cmdZ = fwd->GetV3();
64 auto cmdE = fwd->GetV4();
65 if ( cmdE !=
nullptr ){
71 TText *t =
new TText(.5,.5,
"Hello World !");
73 t->SetTextColor(kBlack);
80 float zSizes[] = {2.5, 2.5, 2.0, 1.5, 1.5, 1.5, 1.5, 1.5, 2.5, 2.0, 1.5};
81 for (
int i = 0; i < 50; i++ )
82 zColors[i] = TColor::GetColorPalette(i*zColorStep % 255 );
87 for (
int i = 0; i < N; i++ ){
89 vizX = xx( cmdX[i], cmdY[i], cmdZ[i], projType );
90 vizY = yy( cmdX[i], cmdY[i], cmdZ[i], projType );
91 printf(
"\tpoint at (%f, %f, %f) -> (%f, %f)\n", cmdX[i], cmdY[i], cmdZ[i], vizX, vizY );
94 if ( fabs( cmdZ[i] - 151.75) < 2.5 ) zIndex = 1;
95 if ( fabs( cmdZ[i] - 165.25) < 2.5 ) zIndex = 2;
96 if ( fabs( cmdZ[i] - 178.75) < 2.5 ) zIndex = 3;
100 if ( fabs( cmdZ[i] - 281) < 2.5 ) zIndex = 4;
101 if ( fabs( cmdZ[i] - 304) < 2.5 ) zIndex = 5;
102 if ( fabs( cmdZ[i] - 325) < 2.5 ) zIndex = 6;
103 if ( fabs( cmdZ[i] - 348) < 2.5 ) zIndex = 7;
105 if ( fabs( cmdZ[i] - 375) < 2.5 ) zIndex = 8;
110 TMarker *mk =
new TMarker( vizX, vizY, 20 );
112 mk->SetMarkerSize( 2.5 );
113 if (zIndex >= 1 && zIndex < 50){
114 slc = zColors[zIndex];
116 mk->SetMarkerSize( zSizes[zIndex] );
124 if ( zIndex != 8 && (cmdE !=
nullptr && projType == kRZSigned) ){
127 mk->SetMarkerSize(0);
128 alpha = (cmdE[i] / 10.0);
129 if (alpha>=1) alpha = 1;
130 TBox *box =
new TBox( vizX-0.05*cmdE[i], vizY-0.5, vizX, vizY+0.5 );
131 box->SetFillColor(210);
132 if ( name ==
"WCal Clusters" || name ==
"HCal CLusters" ){
133 box->SetFillColor(880);
134 mk->SetMarkerSize(1);
138 if ( name ==
"FTT Clusters" && projType == kXY ){
139 mk->SetMarkerSize(0);
141 XCluster.SetLineWidth(1);
142 XCluster.SetLineColor(9);
144 YCluster.SetLineWidth(1);
145 YCluster.SetLineColor(46);
153 }
else if(vizX >= 0){
160 }
else if (vizY >= 0){
165 XCluster.DrawLine(vizX, y0, vizX, y1);
166 YCluster.DrawLine(x0, vizY, x1, vizY);
170 if ( cmdE !=
nullptr && (zIndex == 8 || projType != kRZSigned) ){
171 mk->SetMarkerStyle(21);
172 mk->SetMarkerSize( 0.005 * cmdE[i]);
175 printf(
"\tzIndex = %d -> color = %d \n", zIndex, slc );
177 mk->SetMarkerColorAlpha( slc, alpha );
179 mk->SetMarkerColorAlpha( slc, alpha );
205 for (
int i = 1; i < 4; i++ ){
206 TMarker *mk1 =
new TMarker( LegendX, LegendY, 20 );
207 mk1->SetMarkerSize( 2.5 );
208 mk1->SetMarkerColorAlpha( zColors[i], 0.5 );
210 t->DrawText( LegendX + 2, LegendY - 0.5, TString::Format(
"%s: %d", name, i ) );
214 }
else if (name ==
"FTT"){
215 for (
int i = 1; i < 5; i++ ){
216 TMarker *mk1 =
new TMarker( LegendX, LegendY, 20 );
217 mk1->SetMarkerSize( 2.5 );
218 mk1->SetMarkerColorAlpha( zColors[i+3], 0.5 );
220 t->DrawText( LegendX + 2, LegendY - 0.5, TString::Format(
"%s: %d", name, i ) );
224 }
else if (name ==
"FCS"){
225 for (
int i = 1; i < 3; i++ ){
226 TMarker *mk1 =
new TMarker( LegendX, LegendY, 20 );
227 mk1->SetMarkerSize( 2.5 );
228 mk1->SetMarkerColorAlpha( zColors[i], 0.5 );
230 t->DrawText( LegendX + 2, LegendY - 0.5, TString::Format(
"%s: %d", name, i ) );
237 TMarker *mk1 =
new TMarker( LegendX, LegendY, 20 );
238 mk1->SetMarkerSize( 2.5 );
239 mk1->SetMarkerColor( color );
241 t->DrawText( LegendX + 2, LegendY - 0.5, TString::Format(
"%s:", name ) );
248 void viz_seed(
const char* name,
const char* cmd,
int eventIndex, ProjectionType projType = kRZSigned){
250 fwd->Draw(
"reco.id",
"",
"goff", 1, eventIndex );
251 int nTrks = fwd->GetSelectedRows();
254 line.SetLineWidth(2);
255 line.SetLineColor(1);
257 for (
int i = 0; i < nTrks; i++){
259 fwd->Draw( TString::Format(
"reco[%d].projs.mXYZ.fX:reco[%d].projs.mXYZ.fY:reco[%d].projs.mXYZ.fZ", i, i, i),
"",
"goff", 1, eventIndex );
260 auto nHits = fwd->GetSelectedRows();
261 auto projX = fwd->GetV1();
262 auto projY = fwd->GetV2();
263 auto projZ = fwd->GetV3();
275 fwd->Draw( cmd, TString::Format(
"seeds.trackId == %d", i),
"goff", 1, eventIndex );
277 int numSeeds = fwd->GetSelectedRows();
278 auto newX = fwd->GetV1();
279 auto newY = fwd->GetV2();
280 auto newZ = fwd->GetV3();
282 for (
int j = 0; j < numSeeds - 1; j++){
284 float x0 = xx( newX[j], newY[j], newZ[j], projType );
285 float y0 = yy( newX[j], newY[j], newZ[j], projType );
286 float x1 = xx( newX[j+1], newY[j+1], newZ[j+1], projType );
287 float y1 = yy( newX[j+1], newY[j+1], newZ[j+1], projType );
293 line.DrawLine(x0, y0, x1, y1);
300 void viz_proj(
int eventIndex, ProjectionType projType = kRZSigned,
bool markers =
false ){
303 fwd->Draw(
"reco.id",
"",
"goff", 1, eventIndex);
304 int nTrks = fwd->GetSelectedRows();
308 trkproj.SetLineWidth(1.5);
309 trkproj.SetLineColor(24);
312 for (
int i = 0; i < nTrks; i++ ){
315 fwd->Draw( TString::Format(
"reco[%d].projs.mXYZ.fX:reco[%d].projs.mXYZ.fY:reco[%d].projs.mXYZ.fZ", i, i, i),
"",
"goff", 1, eventIndex );
316 auto nHits = fwd->GetSelectedRows();
317 auto projX = fwd->GetV1();
318 auto projY = fwd->GetV2();
319 auto projZ = fwd->GetV3();
323 for (
int j = 0; j < nHits - 1; j++ ){
326 float x0 = xx( projX[j], projY[j], projZ[j], projType );
327 float y0 = yy( projX[j], projY[j], projZ[j], projType );
328 float x1 = xx( projX[j+1], projY[j+1], projZ[j+1], projType );
329 float y1 = yy( projX[j+1], projY[j+1], projZ[j+1], projType );
335 trkproj.DrawLine(x0, y0, x1, y1);
340 for (
int j = 0; j < nHits; j++ ){
342 float x = xx( projX[j], projY[j], projZ[j], projType );
343 float y = yy( projX[j], projY[j], projZ[j], projType );
345 TMarker *mk =
new TMarker( x, y, 20);
346 mk->SetMarkerStyle(23);
347 mk->SetMarkerColor(2);
348 mk->SetMarkerSize(1.5);
356 TText *t =
new TText(.5,.5,
"Hello World !");
357 t->SetTextColor(kBlack);
361 if ( projType == kRZSigned ){
363 }
else if (projType == kXY ){
366 TMarker *mk1 =
new TMarker( LegendX, LegendY, 23 );
367 mk1->SetMarkerSize( 2.5 );
368 mk1->SetMarkerColor( 2 );
370 t->DrawText( LegendX + 2, LegendY - 0.5, TString::Format(
"Projected Hits ") );
380 float statTextY = 0.97;
381 void n() { statTextY -= 0.05; }
382 void viz_stats(
int eventIndex ){
385 text.SetTextFont(43);
386 text.SetTextSize(36);
398 fwd->Draw(
"reco.id",
"",
"goff", 1, eventIndex );
399 int numTracks = fwd->GetSelectedRows();
400 fwd->Draw(
"fst.pos.fX:fst.pos.fY:fst.pos.fZ",
"",
"goff", 1, eventIndex );
401 int numFst = fwd->GetSelectedRows();
402 fwd->Draw(
"ftt.pos.fX:ftt.pos.fY:ftt.pos.fZ",
"",
"goff", 1, eventIndex );
403 int numFtt = fwd->GetSelectedRows();
406 fwd->Draw(
"wcalHits.starXYZ.fX:wcalHits.starXYZ.fY:wcalHits.starXYZ.fZ",
"",
"goff", 1, eventIndex );
407 int numWcalHits = fwd->GetSelectedRows();
408 fwd->Draw(
"hcalHits.starXYZ.fX:hcalHits.starXYZ.fY:hcalHits.starXYZ.fZ",
"",
"goff", 1, eventIndex );
409 int numHcalHits = fwd->GetSelectedRows();
410 fwd->Draw(
"wcalClusters.pos.fX:wcalClusters.pos.fY:wcalClusters.pos.fZ",
"",
"goff", 1, eventIndex );
411 int numWcal = fwd->GetSelectedRows();
412 fwd->Draw(
"hcalClusters.pos.fX:hcalClusters.pos.fY:hcalClusters.pos.fZ",
"",
"goff", 1, eventIndex );
413 int numHcal = fwd->GetSelectedRows();
415 text.DrawTextNDC( 0.05, statTextY, TString::Format(
"Event : %d", eventIndex) ); n();
416 text.DrawTextNDC( 0.05, statTextY, TString::Format(
"Tracks : %d", numTracks) ); n();
417 text.DrawTextNDC( 0.05, statTextY, TString::Format(
"FST Hits : %d", numFst) ); n();
418 text.DrawTextNDC( 0.05, statTextY, TString::Format(
"FTT Hits : %d", numFtt) ); n();
422 text.DrawTextNDC( 0.05, statTextY, TString::Format(
"WCal Clusters : %d", numWcal) ); n();
423 text.DrawTextNDC( 0.05, statTextY, TString::Format(
"HCal Clusters : %d", numHcal) ); n();
434 int viz_event(
int eventIndex, ProjectionType projType = kRZSigned ){
436 if ( projType == kRZSigned || projType == kXZ || projType == kYZ ){
437 hFrame =
new TH2F(
"hFrame",
";z;R", 520, -30, 900, 260, -130, 130 );
438 hFrame->SetTitle(
"Event Visualization (RZ Signed)" );
441 }
else if ( projType == kRZ ){
442 hFrame =
new TH2F(
"hFrame",
";z;R", 500, 0, 900, 60, 0, 60 );
443 hFrame->SetTitle(
"Event Visualization (RZ Signed)" );
446 }
else if ( projType == kXY ){
447 hFrame =
new TH2F(
"hFrame",
";x;y", 5, -50, 50, 5, -50, 50 );
448 hFrame->SetTitle(
"Event Visualization (XY)" );
453 printf(
"Visualizing Event %d \n", eventIndex );
455 fwd->Draw(
"reco.id",
"",
"", 1, eventIndex );
456 int nTrk = fwd->GetSelectedRows();
457 printf(
"Event has %d Tracks \n", nTrk );
460 hFrame->Draw(
"colz");
463 if (projType == kRZSigned){
465 TLine *fst1 =
new TLine(151.75, -28.3, 151.75, 28.3);
466 fst1->SetLineWidth(2);
467 fst1->SetLineColor(12);
469 TLine *fst2 =
new TLine(165.25, -28.3, 165.25, 28.3);
470 fst2->SetLineWidth(2);
471 fst2->SetLineColor(12);
473 TLine *fst3 =
new TLine(178.75, -28.3, 178.75, 28.3);
474 fst3->SetLineWidth(2);
475 fst3->SetLineColor(12);
478 TLine *ftt1 =
new TLine(281, -60, 281, 60);
479 ftt1->SetLineWidth(2);
480 ftt1->SetLineColor(12);
482 TLine *ftt2 =
new TLine(304, -60, 304, 60);
483 ftt2->SetLineWidth(2);
484 ftt2->SetLineColor(12);
486 TLine *ftt3 =
new TLine(325, -60, 325, 60);
487 ftt3->SetLineWidth(2);
488 ftt3->SetLineColor(12);
490 TLine *ftt4 =
new TLine(348, -60, 348, 60);
491 ftt4->SetLineWidth(2);
492 ftt4->SetLineColor(12);
495 TLine *epd =
new TLine(375, -130, 375, 130);
496 epd->SetLineWidth(2);
497 epd->SetLineColor(12);
501 TBox *wcal =
new TBox( 720, -120, 735, 120 );
502 wcal->SetFillColorAlpha(4, 0.2);
504 TBox *hcal =
new TBox( 800, -120, 815, 120 );
505 hcal->SetFillColorAlpha(2, 0.2);
513 viz_points(
"FST",
"fst.pos.fX:fst.pos.fY:fst.pos.fZ", kGray, eventIndex, projType,
true );
514 viz_points(
"FTT",
"ftt.pos.fX:ftt.pos.fY:ftt.pos.fZ", kRed, eventIndex, projType );
515 viz_points(
"FTT Clusters",
"fttClusters.pos.fX:fttClusters.pos.fY:fttClusters.pos.fZ", kRed, eventIndex, projType );
516 viz_points(
"WCal Hits",
"wcalHits.starXYZ.fX:wcalHits.starXYZ.fY:wcalHits.starXYZ.fZ+705:100*wcalHits.energy", kBlue, eventIndex, projType );
517 viz_points(
"HCal Hits",
"hcalHits.starXYZ.fX:hcalHits.starXYZ.fY:hcalHits.starXYZ.fZ+785:100*wcalClusters.mEnergy", kTeal, eventIndex, projType );
518 viz_points(
"WCal Clusters",
"wcalClusters.pos.fX:wcalClusters.pos.fY:wcalClusters.pos.fZ+705:100*wcalClusters.mEnergy", kViolet, eventIndex, projType );
519 viz_points(
"HCal Clusters",
"hcalClusters.pos.fX:hcalClusters.pos.fY:hcalClusters.pos.fZ+785:100*wcalClusters.mEnergy", kGreen, eventIndex, projType );
521 viz_seed(
"Seeds",
"seeds.pos.fX:seeds.pos.fY:seeds.pos.fZ", eventIndex, projType );
529 void viz( TString fn =
"fwdtree5.root",
int view = kXY) {
531 ProjectionType pjt = (ProjectionType)view;
532 fData =
new TFile( fn );
533 fwd = (TTree*)fData->Get(
"fwd" );
535 gStyle->SetOptStat(0);
537 float canWidth = 19 * 100;
538 float canHeight = 16 * 100;
539 gCan =
new TCanvas(
"g",
"", canWidth, canHeight );
540 gCan->SetMargin( 0, 0, 0, 0);
544 padRZ =
new TPad(
"padRZ",
"", 0.0, 0.5, 0.95, 0.99 );
545 padRZ->SetMargin( .05,.01,.05,.01 );
550 padXY =
new TPad(
"padXY",
"", 0.0, 0.0, 0.5, 0.5 );
551 padXY->SetMargin( .1,.02,.05,.01 );
556 padStat =
new TPad(
"padStat",
"", 0.5, 0.0, 1.0, 0.5 );
557 padStat->SetMargin( .1,.02,.05,.01 );
558 padStat->Draw(
"same");
563 int nEvents = fwd->GetEntries();
565 for (
int iEvent = 0; iEvent < nEvents; iEvent ++ ){
567 printf(
"Event: %d\n", iEvent );
573 int nTrk = viz_event( iEvent, kRZSigned );
577 viz_event( iEvent, kXY );
587 gCan->Print( TString::Format(
"out_event%d.pdf", iEvent ) );