diff --git a/inc/DataInterface.hh b/inc/DataInterface.hh index f59ec8e..f9f2e69 100644 --- a/inc/DataInterface.hh +++ b/inc/DataInterface.hh @@ -72,6 +72,7 @@ namespace mu2e{ void AddTrkCaloHit(KalSeed const& kalseed, REX::REveElement* &scene); template void AddKinKalTrajectory( std::unique_ptr &trajectory, REX::REveElement* &scene, unsigned int j, std::string kaltitle, double& t1, double& t2); void FillKinKalTrajectory(REX::REveManager *&eveMng, bool firstloop, REX::REveElement* &scene, std::tuple, std::vector> track_tuple, bool kalinter, bool hits, bool calohits, double& t1, double& t2); + void AddCRVKalIntersection(REX::REveManager *&eveMng, bool firstloop, REX::REveElement* &scene, std::tuple, std::vector> track_tuple, bool kalinter, bool hits, bool calohits, double& t1, double& t2, std::tuple, std::vector> crvpulse_tuple, bool extracted, bool addCrvBars); void AddCosmicTrackFit(REX::REveManager *&eveMng, bool firstLoop_, const mu2e::CosmicTrackSeedCollection *cosmiccol, REX::REveElement* &scene); #endif diff --git a/src/DataInterface.cc b/src/DataInterface.cc index 6c01d31..125f956 100644 --- a/src/DataInterface.cc +++ b/src/DataInterface.cc @@ -1698,3 +1698,231 @@ void DataInterface::AddCosmicTrackFit(REX::REveManager *&eveMng, bool firstLoop_ // Add the compound of all tracks to the scene scene->AddElement(all_tracks_compound); } + +void DataInterface::AddCRVKalIntersection(REX::REveManager *&eveMng, bool firstloop, REX::REveElement* &scene, + std::tuple, + std::vector> track_tuple, bool plotKalIntersection, + bool addTrkHits, bool addTrkCaloHits, + double& t1, double& t2, std::tuple, std::vector> crvpulse_tuple, bool extracted, bool addCrvBars) +{ + std::cout << "[DataInterface::AddCRVKalIntersection()]" << std::endl; + // Critical Logic: Scene Cleanup + if (!firstloop) { + scene->DestroyElements(); + } + // Setup and Data Extraction + //const auto& ptable = GlobalConstantsHandle(); + const auto& track_list = std::get<1>(track_tuple); + //const auto& names = std::get<0>(track_tuple); + if (track_list.empty()) return; + std::vector tcrv_times; + // Loop over KalSeed Collections + for(unsigned int j = 0; j < track_list.size(); j++){ + const mu2e::KalSeedPtrCollection* seedcol = track_list[j]; + if(seedcol == nullptr) continue; + // Loop over individual KalSeeds + for(const auto& kseedptr : *seedcol){ + if (!kseedptr) continue; + const mu2e::KalSeed& kseed = *kseedptr; + std::vector const& inters = kseed.intersections(); + for (mu2e::KalIntersection const& inter: inters){ + if(inter.surfaceId().name() == "TCRV"){ + std::cout<<"Inter time = "< crvpulse_list = std::get<1>(crvpulse_tuple); + std::vector names = std::get<0>(crvpulse_tuple); + mu2e::GeomHandle CRS; + mu2e::GeomHandle det; + if (crvpulse_list.size() == 0) return; + double minTime = 1e9; + for(unsigned int i=0; i < crvpulse_list.size(); i++){ + const CrvCoincidenceClusterCollection* crvClusters = crvpulse_list[i]; + if (crvClusters->size() == 0) continue; + for(unsigned int j=0; j< crvClusters->size(); j++){ + mu2e::CrvCoincidenceCluster const &crvclu = (*crvClusters)[j]; + double cluTime = crvclu.GetAvgHitTime(); + for (const auto&tcrv_time : tcrv_times){ + double deltaT = std::abs(tcrv_time - cluTime); + if(deltaT < minTime) + minTime = deltaT; + } + } + } + // Visualization Loop + for(unsigned int i=0; i < crvpulse_list.size(); i++){ + const CrvCoincidenceClusterCollection* crvClusters = crvpulse_list[i]; + if (crvClusters->size() == 0) continue; + std::string bars_title = "Crv Cluster Bars: " + names[i]; + auto allcrvbars_collection = new REX::REveCompound(bars_title.c_str(), bars_title.c_str(), 1); + + for(unsigned int j=0; j< crvClusters->size(); j++){ + + mu2e::CrvCoincidenceCluster const &crvclu = (*crvClusters)[j]; + // Make title + std::string crvtitle = "CrvCoincidenceCluster" + std::to_string(j) + " tag : " + names[i] + '\n' + + " averge hit time = " + std::to_string(crvclu.GetAvgHitTime())+" ns " + '\n' + + " PEs = " + std::to_string(crvclu.GetPEs()); + auto ps1 = new REX::REvePointSet(crvtitle.c_str(), crvtitle.c_str(), 0); + + CLHEP::Hep3Vector pointInMu2e = det->toDetector(crvclu.GetAvgHitPos()); + // For extracted geometry, apply Z-shift to align CRV cluster points with geometry display + double cluster_z = pointmmTocm(pointInMu2e.z()); + if(extracted) { + cluster_z += GetCrvExtractedZShift(); + } + ps1->SetNextPoint(pointmmTocm(pointInMu2e.x()), pointmmTocm(pointInMu2e.y()) , cluster_z); + + std::set drawn_bars; + + for(unsigned h =0 ; h < crvclu.GetCrvRecoPulses().size();h++) { + + art::Ptr crvpulse = crvclu.GetCrvRecoPulses()[h]; + const mu2e::CRSScintillatorBarIndex &crvBarIndex = crvpulse->GetScintillatorBarIndex(); + + if (addCrvBars && crvpulse && drawn_bars.count(crvBarIndex) == 0) { + + drawn_bars.insert(crvBarIndex); + + const mu2e::CRSScintillatorBar &crvCounter = CRS->getBar(crvBarIndex); + const mu2e::CRSScintillatorBarDetail &barDetail = crvCounter.getBarDetail(); + CLHEP::Hep3Vector crvCounterPos = crvCounter.getPosition(); + + // Calculate Time Window Based Color + double pulse_time = crvpulse->GetPulseTime(); + double pulse_height = crvpulse->GetPulseHeight(); + + // Base Geometry Setup + CLHEP::Hep3Vector bar_center_mu2e = det->toDetector(crvCounterPos); + + double X_cm = pointmmTocm(bar_center_mu2e.x()); + double Y_cm = pointmmTocm(bar_center_mu2e.y()); + double Z_cm = pointmmTocm(bar_center_mu2e.z()); + // For extracted geometry, apply Z-shift to align bars with display coordinate frame + if(extracted) { + Z_cm += GetCrvExtractedZShift(); + } + + double length = pointmmTocm(crvCounter.getHalfLength()); + double width = pointmmTocm(crvCounter.getHalfWidth()); + double height = pointmmTocm(crvCounter.getHalfThickness()); + + std::string pulsetitle = " Crv Bar Hit for tag : " + + names[i] + '\n' + + "Bar ID: " + std::to_string(crvBarIndex.asInt()) + '\n' + + "Pulse Time: " + std::to_string(pulse_time) + '\n' + + "Pulse Height: " + std::to_string(pulse_height) + " ADC" + '\n' + + "Coincidence start time: " + std::to_string(crvclu.GetStartTime()) + '\n' + + "Coincidence end time: " + std::to_string(crvclu.GetEndTime()); + char const *pulsetitle_c = pulsetitle.c_str(); + + auto b = new REX::REveBox(pulsetitle_c, pulsetitle_c); + double minTime2 = 1e9; + double cluTime2 = crvclu.GetAvgHitTime(); + for (const auto&tcrv_time : tcrv_times){ + double deltaT = std::abs(tcrv_time - cluTime2); + if(deltaT < minTime2) + minTime2 = deltaT; + } + std::cout<<"MinTime = "<SetLineWidth(drawconfig.getInt("GeomLineWidth")); + + // Geometry Setting + if(!extracted){ + // Crv D, Crv U orientation (Length along X) + if(barDetail.getWidthDirection() == 1 and barDetail.getThicknessDirection() == 2 and barDetail.getLengthDirection() == 0){ + b->SetVertex(0, X_cm - length, Y_cm - width, Z_cm - height); + b->SetVertex(1, X_cm - length, Y_cm - width, Z_cm + height); + b->SetVertex(2, X_cm - length, Y_cm + width, Z_cm + height); + b->SetVertex(3, X_cm - length, Y_cm + width, Z_cm - height); + b->SetVertex(4, X_cm + length, Y_cm - width, Z_cm - height); + b->SetVertex(5, X_cm + length, Y_cm - width, Z_cm + height); + b->SetVertex(6, X_cm + length, Y_cm + width, Z_cm + height); + b->SetVertex(7, X_cm + length, Y_cm + width, Z_cm - height); + } + // Crv TS orientation (Length along Z) + else if(barDetail.getWidthDirection() == 0 and barDetail.getThicknessDirection() == 1 and barDetail.getLengthDirection() == 2){ + b->SetVertex(0, X_cm - width, Y_cm - height, Z_cm - length); + b->SetVertex(1, X_cm - width, Y_cm + height, Z_cm - length); + b->SetVertex(2, X_cm + width, Y_cm + height, Z_cm - length); + b->SetVertex(3, X_cm + width, Y_cm - height, Z_cm - length); + b->SetVertex(4, X_cm - width, Y_cm - height, Z_cm + length); + b->SetVertex(5, X_cm - width, Y_cm + height, Z_cm + length); + b->SetVertex(6, X_cm + width, Y_cm + height, Z_cm + length); + b->SetVertex(7, X_cm + width, Y_cm - height, Z_cm + length); + } + // Crv T orientation (Length along X) + else if(barDetail.getWidthDirection() == 2 and barDetail.getThicknessDirection() == 1 and barDetail.getLengthDirection() == 0){ + b->SetVertex(0, X_cm - length, Y_cm - height, Z_cm - width); + b->SetVertex(1, X_cm - length, Y_cm + height, Z_cm - width); + b->SetVertex(2, X_cm - length, Y_cm + height, Z_cm + width); + b->SetVertex(3, X_cm - length, Y_cm - height, Z_cm + width); + b->SetVertex(4, X_cm + length, Y_cm - height, Z_cm - width); + b->SetVertex(5, X_cm + length, Y_cm + height, Z_cm - width); + b->SetVertex(6, X_cm + length, Y_cm + height, Z_cm + width); + b->SetVertex(7, X_cm + length, Y_cm - height, Z_cm + width); + } + // Crv R, Crv L orientation (Length along Y) + else if(barDetail.getWidthDirection() == 2 and barDetail.getThicknessDirection() == 0 and barDetail.getLengthDirection() == 1){ + b->SetVertex(0, X_cm - height, Y_cm - length, Z_cm - width); + b->SetVertex(1, X_cm - height, Y_cm + length, Z_cm - width); + b->SetVertex(2, X_cm + height, Y_cm + length, Z_cm - width); + b->SetVertex(3, X_cm + height, Y_cm - length, Z_cm - width); + b->SetVertex(4, X_cm - height, Y_cm - length, Z_cm + width); + b->SetVertex(5, X_cm - height, Y_cm + length, Z_cm + width); + b->SetVertex(6, X_cm + height, Y_cm + length, Z_cm + width); + b->SetVertex(7, X_cm + height, Y_cm - length, Z_cm + width); + } + allcrvbars_collection->AddElement(b); + + } else if(extracted){ + // T1 (Length along Z) + if(barDetail.getWidthDirection() == 0 and barDetail.getThicknessDirection() == 1 and barDetail.getLengthDirection() == 2){ + b->SetVertex(0, X_cm - width, Y_cm - height, Z_cm - length); + b->SetVertex(1, X_cm - width, Y_cm + height, Z_cm - length); + b->SetVertex(2, X_cm + width, Y_cm + height, Z_cm - length); + b->SetVertex(3, X_cm + width, Y_cm - height, Z_cm - length); + b->SetVertex(4, X_cm - width, Y_cm - height, Z_cm + length); + b->SetVertex(5, X_cm - width, Y_cm + height, Z_cm + length); + b->SetVertex(6, X_cm + width, Y_cm + height, Z_cm + length); + b->SetVertex(7, X_cm + width, Y_cm - height, Z_cm + length); + } + // EX, T2 (Length along X) + else { + b->SetVertex(0, X_cm - length, Y_cm - height, Z_cm - width); + b->SetVertex(1, X_cm - length, Y_cm + height, Z_cm - width); + b->SetVertex(2, X_cm + length, Y_cm + height, Z_cm - width); + b->SetVertex(3, X_cm + length, Y_cm - height, Z_cm - width); + b->SetVertex(4, X_cm - length, Y_cm - height, Z_cm + width); + b->SetVertex(5, X_cm - length, Y_cm + height, Z_cm + width); + b->SetVertex(6, X_cm + length, Y_cm + height, Z_cm + width); + b->SetVertex(7, X_cm + length, Y_cm - height, Z_cm + width); + } + scene->AddElement(b); + } + } + } // End of inner h loop (pulses) + + // Cluster Point Set Configuration + ps1->SetMarkerColor(kBlue); // Marker color based on configuration + ps1->SetMarkerStyle(DataInterface::mstyle); + ps1->SetMarkerSize(DataInterface::msize); + + if(ps1->GetSize() !=0 ) scene->AddElement(ps1); + + } // End of j loop (clusters) + + // Final Additions to Scene + if(!extracted && addCrvBars) { + scene->AddElement(allcrvbars_collection); + } + } +} diff --git a/src/MainWindow.cc b/src/MainWindow.cc index 48a779a..e6f1c09 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -775,7 +775,10 @@ void MainWindow::showEvents(REX::REveManager *eveMng, REX::REveElement* &eventSc double t2 = 1696.; std::vector track_list = std::get<1>(data.track_tuple); if(drawOpts.addTracks and track_list.size() !=0) { - pass_data->FillKinKalTrajectory(eveMng, firstLoop, eventScene, data.track_tuple, KKOpts.addKalInter, KKOpts.addTrkStrawHits, KKOpts.addTrkCaloHits, t1, t2); + pass_data->FillKinKalTrajectory(eveMng, firstLoop, eventScene, data.track_tuple, KKOpts.addKalInter, KKOpts.addTrkStrawHits, KKOpts.addTrkCaloHits, t1, t2); + } + if(drawOpts.addTracks and track_list.size() !=0 and drawOpts.addCrvClusters) { + pass_data->AddCRVKalIntersection(eveMng, firstLoop, eventScene, data.track_tuple, KKOpts.addKalInter, KKOpts.addTrkStrawHits, KKOpts.addTrkCaloHits, t1, t2, data.crvcoin_tuple, geomOpts.extracted, drawOpts.addCrvBars); } if(drawOpts.addComboHits) { std::vector combohit_list = std::get<1>(data.combohit_tuple); @@ -790,10 +793,10 @@ void MainWindow::showEvents(REX::REveManager *eveMng, REX::REveElement* &eventSc if(crvpulse_list.size() !=0) pass_data->AddCrvInfo(eveMng, firstLoop, data.crvpulse_tuple, eventScene, geomOpts.extracted, drawOpts.addCrvBars); } - if(drawOpts.addCrvClusters){ + /*if(drawOpts.addCrvClusters){ std::vector crvcoin_list = std::get<1>(data.crvcoin_tuple); if(crvcoin_list.size() !=0) pass_data->AddCrvClusters(eveMng, firstLoop, data.crvcoin_tuple, eventScene, geomOpts.extracted, drawOpts.addCrvBars); - } + }*/ if(drawOpts.addCaloDigis){ std::vector calodigi_list = std::get<1>(data.calodigi_tuple);