From 5be1474832746f5cb77b992c5ff26b58a6ccdbba Mon Sep 17 00:00:00 2001
From: Namitha Chithirasreemadam <namithac@mu2egpvm04.fnal.gov>
Date: Thu, 23 Apr 2026 17:18:43 -0500
Subject: [PATCH 1/7] Adding the option to view hit CRV bars in time with the
 reco cosmic tracks

---
 inc/DataInterface.hh |   1 +
 src/DataInterface.cc | 228 +++++++++++++++++++++++++++++++++++++++++++
 src/MainWindow.cc    |   9 +-
 3 files changed, 235 insertions(+), 3 deletions(-)

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<class KTRAJ> void AddKinKalTrajectory( std::unique_ptr<KTRAJ> &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<std::string>, std::vector<const KalSeedPtrCollection*>> 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<std::string>, std::vector<const KalSeedPtrCollection*>> track_tuple, bool kalinter, bool hits, bool calohits, double& t1, double& t2, std::tuple<std::vector<std::string>, std::vector<const CrvCoincidenceClusterCollection*>>  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<std::string>, 
+                                         std::vector<const KalSeedPtrCollection*>> track_tuple, bool plotKalIntersection,
+                                         bool addTrkHits, bool addTrkCaloHits, 
+                                         double& t1, double& t2, std::tuple<std::vector<std::string>, std::vector<const CrvCoincidenceClusterCollection*>> 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<ParticleDataList>();
+    const auto& track_list = std::get<1>(track_tuple);
+    //const auto& names = std::get<0>(track_tuple);
+    if (track_list.empty()) return;
+    std::vector<double> 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<mu2e::KalIntersection> const& inters = kseed.intersections();
+            for (mu2e::KalIntersection const& inter: inters){
+              if(inter.surfaceId().name() == "TCRV"){
+                std::cout<<"Inter time = "<<inter.time()<<" ns"<<std::endl;
+                tcrv_times.push_back(inter.time());
+              }
+            }
+        }
+    }
+    std::vector<const CrvCoincidenceClusterCollection*> crvpulse_list = std::get<1>(crvpulse_tuple);
+    std::vector<std::string> names = std::get<0>(crvpulse_tuple);
+    mu2e::GeomHandle<mu2e::CosmicRayShield> CRS;
+    mu2e::GeomHandle<mu2e::DetectorSystem> 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<mu2e::CRSScintillatorBarIndex> drawn_bars; 
+
+            for(unsigned h =0 ; h < crvclu.GetCrvRecoPulses().size();h++) {
+                
+                art::Ptr<mu2e::CrvRecoPulse> 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 = "<<minTime<<" minTime2 = "<<minTime2<<std::endl;
+                    if(std::abs(minTime2 - minTime) < 1e-3)
+                      b->SetMainColor(kRed);
+                    else
+                      b->SetMainColor(kBlack);
+                    b->SetMainTransparency(drawconfig.getInt("Crvtrans"));
+                    b->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<const KalSeedPtrCollection*> 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<const ComboHitCollection*> 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<const CrvCoincidenceClusterCollection*> 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<const CaloDigiCollection*> calodigi_list = std::get<1>(data.calodigi_tuple);

From 0e856cfa6438354a9d3fb9169b654322cf5c41a4 Mon Sep 17 00:00:00 2001
From: NamithaChitrazee <namitha@pi.infn.it>
Date: Mon, 4 May 2026 10:22:10 -0700
Subject: [PATCH 2/7] check if openAI changes work

---
 fcl/prolog.fcl                 |  5 +++--
 inc/CollectionFiller.hh        |  3 ++-
 inc/MainWindow.hh              | 11 ++++++-----
 src/CollectionFiller.cc        |  1 +
 src/MainWindow.cc              |  6 +++---
 src/Mu2eEventDisplay_module.cc |  2 +-
 6 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/fcl/prolog.fcl b/fcl/prolog.fcl
index a517823..a8788ba 100644
--- a/fcl/prolog.fcl
+++ b/fcl/prolog.fcl
@@ -41,8 +41,9 @@ Mu2eEventDisplay : {
       addHits : false
       addBkgClusters : false
       addCrvRecoPulse : false
-      addCrvClusters : false
-      addTimeClusters : false
+       addCrvClusters : false
+       addCrvTrack : false
+       addTimeClusters : false
       addTrkHits : false //Combo hits?
       addCaloDigis : false
       addClusters : true
diff --git a/inc/CollectionFiller.hh b/inc/CollectionFiller.hh
index 1037107..61fad6f 100644
--- a/inc/CollectionFiller.hh
+++ b/inc/CollectionFiller.hh
@@ -77,6 +77,7 @@ namespace mu2e{
             fhicl::Atom<bool> addBkgClusters{Name("addBkgClusters"), Comment("set to add the bkg clusters"),false}; // Corresponds to bkg clusters
             fhicl::Atom<bool> addCrvRecoPulse{Name("addCrvRecoPulse"), Comment("set to add crv hits"),false}; // Corresponds to CrvRecoPulses
             fhicl::Atom<bool> addCrvClusters{Name("addCrvClusters"), Comment("set to add crv clusters"),false}; // Corresponds to CrvCoincidenceCluster
+            fhicl::Atom<bool> addCrvTrack{Name("addCrvTrack"), Comment("set to add crv track intersections"),false};
             fhicl::Atom<bool> addTimeClusters{Name("addTimeClusters"), Comment("set to add the Crv hits"),false};
             fhicl::Atom<bool> addTrkHits{Name("addTrkHits"), Comment("set to add the Trk hits"),false}; // Alias for ComboHits/TrkHits
             fhicl::Atom<bool> addCaloDigis{Name("addCaloDigis"), Comment("set to add calodigis"),false};
@@ -125,7 +126,7 @@ namespace mu2e{
         art::Run *_run;
         
         // --- Boolean Control Flags (Copied from FHiCL Config) ---
-        bool addHits_, addBkgClusters_, addCrvRecoPulse_, addCrvClusters_, addTimeClusters_, addTrkHits_, addCaloDigis_, 
+        bool addHits_, addBkgClusters_, addCrvRecoPulse_, addCrvClusters_, addCrvTrack_, addTimeClusters_, addTrkHits_, addCaloDigis_, 
              addClusters_, addHelixSeeds_, addKalSeeds_, addCosmicTrackSeeds_, addMCTraj_,
              addSurfSteps_, addSimParts_, FillAll_;
              
diff --git a/inc/MainWindow.hh b/inc/MainWindow.hh
index dc90807..6ac00d3 100644
--- a/inc/MainWindow.hh
+++ b/inc/MainWindow.hh
@@ -124,9 +124,10 @@ namespace mu2e {
 
       bool addBkgClusters = false;
       bool addCrvRecoPulse = false;
-      bool addCrvClusters = false;
-
-      bool addTimeClusters = false;
+       bool addCrvClusters = false;
+       bool addCrvTrack = false;
+ 
+       bool addTimeClusters = false;
       bool addTrkHits = false; // legacy
       bool addMCTrajectories = false;
       bool addSurfaceSteps = false;
@@ -136,8 +137,8 @@ namespace mu2e {
       bool addCrvBars = true;
       DrawOptions(){};
 
-      DrawOptions(bool cosmictracks, bool helices, bool tracks, bool calodigis, bool clusters, bool combohits, bool bkgclusters, bool crv, bool crvclu, bool timeclusters, bool trkhits, bool mctraj, bool surfsteps, bool simparts, bool errbar, bool crys, bool crvbars)
-      : addCosmicTracks(cosmictracks), addHelices(helices), addTracks(tracks), addCaloDigis(calodigis), addClusters(clusters), addComboHits(combohits), addBkgClusters(bkgclusters), addCrvRecoPulse(crv), addCrvClusters(crvclu), addTimeClusters(timeclusters), addTrkHits(trkhits), addMCTrajectories(mctraj), addSurfaceSteps(surfsteps), addSimParts(simparts), addTrkErrBar(errbar), addCrystalDraw(crys), addCrvBars(crvbars) {};
+       DrawOptions(bool cosmictracks, bool helices, bool tracks, bool calodigis, bool clusters, bool combohits, bool bkgclusters, bool crv, bool crvclu, bool crvtrack, bool timeclusters, bool trkhits, bool mctraj, bool surfsteps, bool simparts, bool errbar, bool crys, bool crvbars)
+       : addCosmicTracks(cosmictracks), addHelices(helices), addTracks(tracks), addCaloDigis(calodigis), addClusters(clusters), addComboHits(combohits), addBkgClusters(bkgclusters), addCrvRecoPulse(crv), addCrvClusters(crvclu), addCrvTrack(crvtrack), addTimeClusters(timeclusters), addTrkHits(trkhits), addMCTrajectories(mctraj), addSurfaceSteps(surfsteps), addSimParts(simparts), addTrkErrBar(errbar), addCrystalDraw(crys), addCrvBars(crvbars) {};
 
      };
 
diff --git a/src/CollectionFiller.cc b/src/CollectionFiller.cc
index d20b926..05304af 100644
--- a/src/CollectionFiller.cc
+++ b/src/CollectionFiller.cc
@@ -25,6 +25,7 @@ namespace mu2e{
     addBkgClusters_(conf.addBkgClusters()),
     addCrvRecoPulse_(conf.addCrvRecoPulse()),
     addCrvClusters_(conf.addCrvClusters()),
+    addCrvTrack_(conf.addCrvTrack()),
     addTimeClusters_(conf.addTimeClusters()),
     addTrkHits_(conf.addTrkHits()),
     addCaloDigis_(conf.addCaloDigis()),
diff --git a/src/MainWindow.cc b/src/MainWindow.cc
index e6f1c09..d5f2b62 100644
--- a/src/MainWindow.cc
+++ b/src/MainWindow.cc
@@ -777,9 +777,9 @@ void MainWindow::showEvents(REX::REveManager *eveMng, REX::REveElement* &eventSc
   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);
   }
-  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.addCrvTrack) {
+     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<const ComboHitCollection*> combohit_list = std::get<1>(data.combohit_tuple);
     if(combohit_list.size() !=0 ) pass_data->AddComboHits(eveMng, firstLoop, data.combohit_tuple, eventScene, strawdisplay, drawOpts.addTrkErrBar);
diff --git a/src/Mu2eEventDisplay_module.cc b/src/Mu2eEventDisplay_module.cc
index f41e231..a4301d5 100644
--- a/src/Mu2eEventDisplay_module.cc
+++ b/src/Mu2eEventDisplay_module.cc
@@ -690,7 +690,7 @@ void Mu2eEventDisplay::FillAnyCollection(const art::Event& evt, std::vector<std:
       if(diagLevel_ == 1) std::cout<<"[Mu2eEventDisplay : process_single_event] -- calls to data interface "<<std::endl;
 
       // Create a structure defining which data products should be drawn (based on module configuration).
-      DrawOptions drawOpts(filler_.addCosmicTrackSeeds_, filler_.addHelixSeeds_, filler_.addKalSeeds_, filler_.addCaloDigis_, filler_.addClusters_, filler_.addHits_, filler_.addBkgClusters_, filler_.addCrvRecoPulse_, filler_.addCrvClusters_, filler_.addTimeClusters_, filler_.addTrkHits_, filler_.addMCTraj_, filler_.addSurfSteps_, filler_.addSimParts_, addErrBar_, addCrystalHits_, addCrvBars_);
+       DrawOptions drawOpts(filler_.addCosmicTrackSeeds_, filler_.addHelixSeeds_, filler_.addKalSeeds_, filler_.addCaloDigis_, filler_.addClusters_, filler_.addHits_, filler_.addBkgClusters_, filler_.addCrvRecoPulse_, filler_.addCrvClusters_, filler_.addCrvTrack_, filler_.addTimeClusters_, filler_.addTrkHits_, filler_.addMCTraj_, filler_.addSurfSteps_, filler_.addSimParts_, addErrBar_, addCrystalHits_, addCrvBars_);
 
       // Create a structure defining visualization options specific to Kinematic/Kalman fitting results.
       KinKalOptions KKOpts(addKalInter_, addTrkStrawHits_, addTrkCaloHits_);

From 17830ecea17ef756999f1af1d70e7452586de17b Mon Sep 17 00:00:00 2001
From: Namitha Chithirasreemadam <namithac@mu2egpvm04.fnal.gov>
Date: Mon, 4 May 2026 13:00:42 -0500
Subject: [PATCH 3/7] addCrvTrack parameter added to show cosmic reco tracks +
 associated CRV clusters

---
 examples/extracted_MDC2025.fcl | 1 +
 fcl/extracted.fcl              | 1 +
 2 files changed, 2 insertions(+)

diff --git a/examples/extracted_MDC2025.fcl b/examples/extracted_MDC2025.fcl
index f0f30e4..f462c8a 100644
--- a/examples/extracted_MDC2025.fcl
+++ b/examples/extracted_MDC2025.fcl
@@ -41,6 +41,7 @@ physics.analyzers.Mu2eEventDisplay.gdmlname :"Offline/gen/gdml/mu2e_extracted.gd
 services.TFileService.fileName: "/dev/null"
 services.GeometryService.inputFile: "Offline/Mu2eG4/geom/geom_common_extracted.txt"
 physics.analyzers.Mu2eEventDisplay.filler.addCrvClusters : true
+physics.analyzers.Mu2eEventDisplay.filler.addCrvTrack : true
 physics.analyzers.Mu2eEventDisplay.filler.addCrvRecoPulse : false
 physics.analyzers.Mu2eEventDisplay.filler.addCaloDigis : false
 physics.analyzers.Mu2eEventDisplay.filler.addClusters : false
diff --git a/fcl/extracted.fcl b/fcl/extracted.fcl
index ca3838d..c20f541 100644
--- a/fcl/extracted.fcl
+++ b/fcl/extracted.fcl
@@ -15,6 +15,7 @@ Mu2eEventDisplay.filler.addClusters : true
 Mu2eEventDisplay.filler.addHits : false #  adds ComboHits
 Mu2eEventDisplay.filler.addCrvClusters : true
 Mu2eEventDisplay.filler.addCrvRecoPulse : true
+Mu2eEventDisplay.filler.addCrvTrack : true
 Mu2eEventDisplay.filler.addTimeClusters : false
 Mu2eEventDisplay.filler.addSimParts : false
 Mu2eEventDisplay.addTrkStrawHits : true

From de8f1fa2af6b208961556185987134891fa5c223 Mon Sep 17 00:00:00 2001
From: NamithaChitrazee <namitha@pi.infn.it>
Date: Mon, 4 May 2026 11:13:43 -0700
Subject: [PATCH 4/7] removed addCrvInfo

---
 inc/DataInterface.hh |   5 +-
 src/DataInterface.cc | 251 +++----------------------------------------
 src/MainWindow.cc    |   7 +-
 3 files changed, 22 insertions(+), 241 deletions(-)

diff --git a/inc/DataInterface.hh b/inc/DataInterface.hh
index f9f2e69..3b10076 100644
--- a/inc/DataInterface.hh
+++ b/inc/DataInterface.hh
@@ -63,9 +63,8 @@ namespace mu2e{
       void AddTimeClusters(REX::REveManager *&eveMng, bool firstloop, std::tuple<std::vector<std::string>, std::vector<const TimeClusterCollection*>> timecluster_tuple, std::tuple<std::vector<std::string>, std::vector<const ComboHitCollection*>> combohit_tuple, REX::REveElement* &scene);
           void AddCaloDigis(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CaloDigiCollection*>> calodigi_tuple, REX::REveElement* &scene);
           void AddCaloClusterLegend(REX::REveElement* scene, double t_ref);
-          void AddCaloClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CaloClusterCollection*>> calocluster_tuple, REX::REveElement* &scene, bool addCrystalDraw);
-          void AddCrvInfo(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CrvRecoPulseCollection*>> crvpulse_tuple, REX::REveElement* &scene, bool extracted, bool addCrvBars);
-          void AddCrvClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CrvCoincidenceClusterCollection*>>  crvpulse_tuple, REX::REveElement* &scene, bool extracted, bool addCrvBars);
+           void AddCaloClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CaloClusterCollection*>> calocluster_tuple, REX::REveElement* &scene, bool addCrystalDraw);
+           void AddCrvClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CrvCoincidenceClusterCollection*>>  crvpulse_tuple, REX::REveElement* &scene, bool extracted, bool addCrvBars);
           void AddHelixSeedCollection(REX::REveManager *&eveMng,bool firstloop,  std::tuple<std::vector<std::string>, std::vector<const HelixSeedCollection*>> helix_tuple, REX::REveElement* &scene);
           void AddKalIntersection(KalSeed const& kalseed, REX::REveElement* &scene, REX::REveCompound *products, std::string track_tag);
           template<class KTRAJc> void AddTrkStrawHit(KalSeed const& kalseed, REX::REveElement* &scene, std::unique_ptr<KTRAJc> &trajectory, REX::REveCompound *products);
diff --git a/src/DataInterface.cc b/src/DataInterface.cc
index 125f956..39d17b1 100644
--- a/src/DataInterface.cc
+++ b/src/DataInterface.cc
@@ -611,247 +611,30 @@ void DataInterface::AddComboHits(REX::REveManager *&eveMng, bool firstLoop_,
  * RecoPules are visualized as points bars are visualized as 3D boxes
  * Elements are colored based on the height of the digitization pulse.
 */
-void DataInterface::AddCrvInfo(REX::REveManager *&eveMng, bool firstLoop_, 
-                               std::tuple<std::vector<std::string>, 
-                               std::vector<const CrvRecoPulseCollection*>> crvpulse_tuple, 
-                               REX::REveElement* &scene, bool extracted, bool addCrvBars){
-
-    /*if(!firstLoop_){
-        scene->DestroyElements();;
-    }*/
-    std::cout << "[DataInterface::AddCrvInfo() ] - Coloring by Time Window" << std::endl;
-    std::vector<const CrvRecoPulseCollection*> crvpulse_list = std::get<1>(crvpulse_tuple);
-    std::vector<std::string> names = std::get<0>(crvpulse_tuple);
-    
-    // Geometry Handles
-    mu2e::GeomHandle<mu2e::CosmicRayShield> CRS;
-    mu2e::GeomHandle<mu2e::DetectorSystem> det;
-    
-    // Find the Global Pulse Time Range (min/max) and collect all pulses
-    double max_time = -1e6;
-    double min_time = 1e6;
-    bool found_pulses = false;
-    std::vector<double> all_pulse_times;
-
-    if( !crvpulse_list.empty()){
-        std::cout << "[DataInterface::AddCrvInfo() ] Found " << crvpulse_list.size() << " Crv Reco Pulse Collections." << std::endl;
-        for(const auto* crvRecoPulse : crvpulse_list){
-            if(crvRecoPulse && !crvRecoPulse->empty()){
-                found_pulses = true;
-                for(const auto& crvpulse : *crvRecoPulse){
-                    double time = crvpulse.GetPulseTime();
-                    std::cout << "Found Crv Reco Pulse with time: " << time << " ns" << std::endl;
-                    all_pulse_times.push_back(time);
-                    if(time > max_time) max_time = time;
-                    if(time < min_time) min_time = time;
-                }
-            }
-        }
-    }
-
-    if (!found_pulses) {
-        std::cout << "[ REveDataInterface::AddCrvInfo() ] No valid Crv Reco Pulses found." << std::endl;
-        return;
-    }
-    
-    // Define time window size (in ns) - adjust this parameter to group pulses differently
-    const double time_window_size = 500.0; // 100 ns windows
-    
-    // Calculate number of time windows needed
-    double time_range = max_time - min_time;
-    int num_windows = static_cast<int>(std::ceil(time_range / time_window_size)) + 1;
-    
-    // Define a set of distinct colors for time windows
-    std::vector<Color_t> time_window_colors = {
-        kRed, kGreen, kBlue, kYellow, kMagenta, kCyan, 
-        kOrange, kSpring, kTeal, kAzure, kViolet, kPink,
-        kRed+2, kGreen+2, kBlue+2, kYellow+2, kMagenta+2, kCyan+2,
-        kRed+1, kGreen+1
-    };
-    
-    // If we need more colors than we have, cycle through them
-    std::cout << "[DataInterface::AddCrvInfo() ] Time range: " << min_time << " to " << max_time 
-              << " ns (range: " << time_range << " ns), num_windows: " << num_windows << std::endl;
-    
-    // Visualization Loop
-    for(unsigned int i=0; i < crvpulse_list.size(); i++){
-        const CrvRecoPulseCollection* crvRecoPulse = crvpulse_list[i];
-        
-        if(crvRecoPulse->size() != 0){
-            
-            auto allcrvbars = new REX::REveCompound(("CrvHitBars_" + std::to_string(i)).c_str(), 
-                                                   ("Crv Hit Bars: " + names[i]).c_str(), 1);
-
-            std::cout << "[DataInterface::AddCrvInfo() ] Processing Crv Reco Pulse Collection: " << names[i] << " with " << crvRecoPulse->size() << " pulses " << std::endl;
-            for(unsigned int j=0; j< crvRecoPulse->size(); j++){
-
-                mu2e::CrvRecoPulse const &crvpulse = (*crvRecoPulse)[j];
-                
-                // Calculate Time Window Based Color
-                double pulse_time = crvpulse.GetPulseTime();
-                
-                // Determine which time window this pulse belongs to
-                int time_window_index = static_cast<int>(std::floor((pulse_time - min_time) / time_window_size));
-                if (time_window_index < 0) time_window_index = 0;
-                if (time_window_index >= num_windows) time_window_index = num_windows - 1;
-                
-                // Get color from predefined color array, cycling if necessary
-                Color_t hit_color = time_window_colors[time_window_index % time_window_colors.size()];
-                
-                std::cout << "Found Crv Reco Pulse with time: " << pulse_time << " ns, window: " << time_window_index 
-                          << ", color: " << hit_color << std::endl;
-
-                // Geometry Setup
-                const mu2e::CRSScintillatorBarIndex &crvBarIndex = crvpulse.GetScintillatorBarIndex();
-                const mu2e::CRSScintillatorBar &crvCounter = CRS->getBar(crvBarIndex);
-                const mu2e::CRSScintillatorBarDetail &barDetail = crvCounter.getBarDetail();
-                
-                CLHEP::Hep3Vector crvCounterPos = crvCounter.getPosition(); 
-                CLHEP::Hep3Vector pointInMu2e = det->toDetector(crvCounterPos); 
-
-                // DETAILED PULSE TITLE (Used for individual point labels)
-                std::string pulsetitle = " Crv Pulse #" + std::to_string(j) + " - " + names[i] + '\n'
-                                       + " SiPM Channel ID: " + std::to_string(crvpulse.GetSiPMNumber()) + '\n'
-                                       + " Crv Bar ID: " + std::to_string(crvBarIndex.asInt()) + '\n'
-                                       + " Pulse Time: " + std::to_string(crvpulse.GetPulseTime()) + " ns (Time Window: " + std::to_string(time_window_index) + ")" + '\n'
-                                       + " Pulse Height: " + std::to_string(crvpulse.GetPulseHeight()) + " ADC" + '\n'
-                                       + " Pedestal: " + std::to_string(crvpulse.GetPedestal()) + " ADC";
-                char const *pulsetitle_c = pulsetitle.c_str();
-                
-                // A. Draw Crv Bar (REveBox)
-                if(addCrvBars){
-                   
-                    double length = pointmmTocm(crvCounter.getHalfLength());
-                    double width = pointmmTocm(crvCounter.getHalfWidth());
-                    double height = pointmmTocm(crvCounter.getHalfThickness());
-                    
-                    double X_cm = pointmmTocm(pointInMu2e.x());
-                    double Y_cm = pointmmTocm(pointInMu2e.y());
-                    double Z_cm = pointmmTocm(pointInMu2e.z());
-                    // For extracted geometry, apply Z-shift to align bars with display coordinate frame
-                    if(extracted) {
-                        Z_cm += GetCrvExtractedZShift();
-                    }
-                    
-                    // Handle geometry errors that cause Seg Faults
-                    try {
-                        // Check for degenerate dimensions (re-added for robustness)
-                        const double kMinDimension = 1e-4; // 1 micrometer (in cm)
-                        if (length < kMinDimension || width < kMinDimension || height < kMinDimension) {
-                             throw std::runtime_error("Degenerate dimensions detected.");
-                        }
-
-                        // Only create and configure the REveBox if the dimensions are safe
-                        auto b = new REX::REveBox(pulsetitle_c, pulsetitle_c);
-                        b->SetMainColor(hit_color); 
-                        b->SetMainTransparency(drawconfig.getInt("Crvtrans"));
-                        b->SetLineWidth(drawconfig.getInt("GeomLineWidth"));
-                        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);
-                          }
-                        }
-                        if(extracted){
-                            if(barDetail.getWidthDirection() == 0 and barDetail.getThicknessDirection() == 1 and barDetail.getLengthDirection() == 2){ //T1 (Length along Z)
-                                b->SetVertex(0, X_cm - width, Y_cm - height, -1*length + Z_cm);
-                                b->SetVertex(1, X_cm - width, Y_cm + height, -1*length + Z_cm);
-                                b->SetVertex(2, X_cm + width, Y_cm + height, -1*length + Z_cm);
-                                b->SetVertex(3, X_cm + width, Y_cm - height, -1*length + Z_cm);
-                                b->SetVertex(4, X_cm - width, Y_cm - height, length + Z_cm);
-                                b->SetVertex(5, X_cm - width, Y_cm + height, length + Z_cm);
-                                b->SetVertex(6, X_cm + width, Y_cm + height, length + Z_cm);
-                                b->SetVertex(7, X_cm + width, Y_cm - height, length + Z_cm);
-                            } else { //EX, T2 (Length along X)
-                                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); 
-                        } else {
-                             allcrvbars->AddElement(b); 
-                        }
-                    } catch (const std::exception& e) {
-                        // Print a warning but continue the loop
-                        std::cerr << "Crv Geometry Error (Bar ID: " << crvBarIndex.asInt() 
-                                  << "). Skipping REveBox creation. Reason: " << e.what() 
-                                  << " L=" << length << ", W=" << width << ", H=" << height << std::endl;
-                    } catch (...) {
-                        // Catch any unknown exception type (e.g., if REve throws a non-standard error)
-                        std::cerr << "Crv Geometry Critical Error (Bar ID: " << crvBarIndex.asInt() 
-                                  << "). Skipping REveBox creation due to unknown geometry failure." << std::endl;
-                    }
-                }
-                
-                // B. Add individual Reco Pulse Point with its own label
-                auto ps1 = new REX::REvePointSet(pulsetitle_c, pulsetitle_c, 1);
-                // For extracted geometry, apply Z-shift to align CRV data with geometry display
-                double hit_z = pointmmTocm(pointInMu2e.z());
-                if(extracted) {
-                    hit_z += GetCrvExtractedZShift();
-                }
-                ps1->SetNextPoint(pointmmTocm(pointInMu2e.x()), pointmmTocm(pointInMu2e.y()), hit_z);
-                ps1->SetMarkerColor(hit_color); 
+void DataInterface::AddBkgClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const BkgClusterCollection*>> bkgcluster_tuple, REX::REveElement* &scene){
+    std::cout << "[DataInterface::AddBkgClusters()]" << std::endl;
+    std::vector<const BkgClusterCollection*> bkgcluster_list = std::get<1>(bkgcluster_tuple);
+    std::cout << "BkgClusterCollection size = " << bkgcluster_list.size() << std::endl;
+    for(unsigned int j = 0; j < bkgcluster_list.size(); j++){
+        const BkgClusterCollection* bccol = bkgcluster_list[j];
+        if(bccol && bccol->size() != 0){
+            for(unsigned int i=0; i < bccol->size(); i++){
+                mu2e::BkgCluster const &bkgcluster = (*bccol)[i];
+                int colour = (i+3);
+                CLHEP::Hep3Vector ClusterPos(pointmmTocm(bkgcluster.pos().x()), pointmmTocm(bkgcluster.pos().y()), pointmmTocm(bkgcluster.pos().z()));
+                std::string bctitle = "BkgCluster";
+                auto ps1 = new REX::REvePointSet(bctitle.c_str(), bctitle.c_str(), 0);
+                ps1->SetNextPoint(ClusterPos.x(), ClusterPos.y() , ClusterPos.z());
+                ps1->SetMarkerColor(colour);
                 ps1->SetMarkerStyle(DataInterface::mstyle);
                 ps1->SetMarkerSize(DataInterface::msize);
-                scene->AddElement(ps1);
-                
-            } // End of individual pulse loop
-            
-            // Add Compounds/Collections to Scene
-            if (!extracted && addCrvBars) {
-                scene->AddElement(allcrvbars);
+                if(ps1->GetSize() != 0) scene->AddElement(ps1);
             }
         }
     }
 }
 
+
 /*
  * Adds reconstructed CrvCluster data products to the REve visualization scene.
  * Clusters are visualized as points, RecoPulses used to access bar info, bars visualized as boxes in 3D
diff --git a/src/MainWindow.cc b/src/MainWindow.cc
index d5f2b62..a8d82f1 100644
--- a/src/MainWindow.cc
+++ b/src/MainWindow.cc
@@ -788,10 +788,9 @@ void MainWindow::showEvents(REX::REveManager *eveMng, REX::REveElement* &eventSc
     std::vector<const BkgClusterCollection*> bkgcluster_list = std::get<1>(data.bkgcluster_tuple);
     if(bkgcluster_list.size() !=0 ) pass_data->AddBkgClusters(eveMng, firstLoop, data.bkgcluster_tuple, eventScene);
   }
-  if(drawOpts.addCrvRecoPulse){
-    std::vector<const CrvRecoPulseCollection*> crvpulse_list = std::get<1>(data.crvpulse_tuple);
-    if(crvpulse_list.size() !=0) pass_data->AddCrvInfo(eveMng, firstLoop, data.crvpulse_tuple, eventScene, geomOpts.extracted, drawOpts.addCrvBars);
-  }
+    if(drawOpts.addCrvRecoPulse){
+      // removed AddCrvInfo call
+    }
 
   /*if(drawOpts.addCrvClusters){
     std::vector<const CrvCoincidenceClusterCollection*> crvcoin_list = std::get<1>(data.crvcoin_tuple);

From 792eef96a6431052a20590a43f617e44c8b8ec6b Mon Sep 17 00:00:00 2001
From: NamithaChitrazee <namitha@pi.infn.it>
Date: Mon, 4 May 2026 11:23:45 -0700
Subject: [PATCH 5/7] little bug fix

---
 src/DataInterface.cc | 30 ------------------------------
 1 file changed, 30 deletions(-)

diff --git a/src/DataInterface.cc b/src/DataInterface.cc
index 39d17b1..2957966 100644
--- a/src/DataInterface.cc
+++ b/src/DataInterface.cc
@@ -605,36 +605,6 @@ void DataInterface::AddComboHits(REX::REveManager *&eveMng, bool firstLoop_,
     }
 }
 
-
-/*
- * Adds reconstructed CaloRecoPulse data products to the REve visualization scene.
- * RecoPules are visualized as points bars are visualized as 3D boxes
- * Elements are colored based on the height of the digitization pulse.
-*/
-void DataInterface::AddBkgClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const BkgClusterCollection*>> bkgcluster_tuple, REX::REveElement* &scene){
-    std::cout << "[DataInterface::AddBkgClusters()]" << std::endl;
-    std::vector<const BkgClusterCollection*> bkgcluster_list = std::get<1>(bkgcluster_tuple);
-    std::cout << "BkgClusterCollection size = " << bkgcluster_list.size() << std::endl;
-    for(unsigned int j = 0; j < bkgcluster_list.size(); j++){
-        const BkgClusterCollection* bccol = bkgcluster_list[j];
-        if(bccol && bccol->size() != 0){
-            for(unsigned int i=0; i < bccol->size(); i++){
-                mu2e::BkgCluster const &bkgcluster = (*bccol)[i];
-                int colour = (i+3);
-                CLHEP::Hep3Vector ClusterPos(pointmmTocm(bkgcluster.pos().x()), pointmmTocm(bkgcluster.pos().y()), pointmmTocm(bkgcluster.pos().z()));
-                std::string bctitle = "BkgCluster";
-                auto ps1 = new REX::REvePointSet(bctitle.c_str(), bctitle.c_str(), 0);
-                ps1->SetNextPoint(ClusterPos.x(), ClusterPos.y() , ClusterPos.z());
-                ps1->SetMarkerColor(colour);
-                ps1->SetMarkerStyle(DataInterface::mstyle);
-                ps1->SetMarkerSize(DataInterface::msize);
-                if(ps1->GetSize() != 0) scene->AddElement(ps1);
-            }
-        }
-    }
-}
-
-
 /*
  * Adds reconstructed CrvCluster data products to the REve visualization scene.
  * Clusters are visualized as points, RecoPulses used to access bar info, bars visualized as boxes in 3D

From 2a7a765518ce7dd37a3e973092f3ff7f0797b9e5 Mon Sep 17 00:00:00 2001
From: NamithaChitrazee <namitha@pi.infn.it>
Date: Mon, 4 May 2026 13:37:29 -0700
Subject: [PATCH 6/7] clean up CRV geometry code

---
 inc/DataInterface.hh |   5 +-
 src/DataInterface.cc | 443 +++++++++++++------------------------------
 2 files changed, 140 insertions(+), 308 deletions(-)

diff --git a/inc/DataInterface.hh b/inc/DataInterface.hh
index 3b10076..64b079b 100644
--- a/inc/DataInterface.hh
+++ b/inc/DataInterface.hh
@@ -64,8 +64,9 @@ namespace mu2e{
           void AddCaloDigis(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CaloDigiCollection*>> calodigi_tuple, REX::REveElement* &scene);
           void AddCaloClusterLegend(REX::REveElement* scene, double t_ref);
            void AddCaloClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CaloClusterCollection*>> calocluster_tuple, REX::REveElement* &scene, bool addCrystalDraw);
-           void AddCrvClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CrvCoincidenceClusterCollection*>>  crvpulse_tuple, REX::REveElement* &scene, bool extracted, bool addCrvBars);
-          void AddHelixSeedCollection(REX::REveManager *&eveMng,bool firstloop,  std::tuple<std::vector<std::string>, std::vector<const HelixSeedCollection*>> helix_tuple, REX::REveElement* &scene);
+          void AddCrvClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const CrvCoincidenceClusterCollection*>>  crvpulse_tuple, REX::REveElement* &scene, bool extracted, bool addCrvBars);
+           void AddCrvBar(const mu2e::CRSScintillatorBarIndex& barIndex, const std::string& title, Color_t color, bool extracted, REX::REveElement* &scene, REX::REveCompound* barCompound);
+           void AddHelixSeedCollection(REX::REveManager *&eveMng,bool firstloop,  std::tuple<std::vector<std::string>, std::vector<const HelixSeedCollection*>> helix_tuple, REX::REveElement* &scene);
           void AddKalIntersection(KalSeed const& kalseed, REX::REveElement* &scene, REX::REveCompound *products, std::string track_tag);
           template<class KTRAJc> void AddTrkStrawHit(KalSeed const& kalseed, REX::REveElement* &scene, std::unique_ptr<KTRAJc> &trajectory, REX::REveCompound *products);
           void AddTrkCaloHit(KalSeed const& kalseed, REX::REveElement* &scene);
diff --git a/src/DataInterface.cc b/src/DataInterface.cc
index 2957966..150dc85 100644
--- a/src/DataInterface.cc
+++ b/src/DataInterface.cc
@@ -610,235 +610,167 @@ void DataInterface::AddComboHits(REX::REveManager *&eveMng, bool firstLoop_,
  * Clusters are visualized as points, RecoPulses used to access bar info, bars visualized as boxes in 3D
  * Elements are colored based on the pulse height of the digitization pulse.
 */
-void DataInterface::AddCrvClusters(REX::REveManager *&eveMng, bool firstLoop_, 
-                                 std::tuple<std::vector<std::string>, 
-                                 std::vector<const CrvCoincidenceClusterCollection*>> crvpulse_tuple, 
-                                 REX::REveElement* &scene, bool extracted, bool addCrvBars)
-{
-
-    std::vector<const CrvCoincidenceClusterCollection*> crvpulse_list = std::get<1>(crvpulse_tuple);
-    std::vector<std::string> names = std::get<0>(crvpulse_tuple);
+void DataInterface::AddCrvBar(const mu2e::CRSScintillatorBarIndex& barIndex, const std::string& title, Color_t color, bool extracted, REX::REveElement* &scene, REX::REveCompound* barCompound){
     mu2e::GeomHandle<mu2e::CosmicRayShield> CRS;
     mu2e::GeomHandle<mu2e::DetectorSystem> det;
-    
-    if (crvpulse_list.size() == 0) return;
+    const mu2e::CRSScintillatorBar &crvCounter = CRS->getBar(barIndex);
+    const mu2e::CRSScintillatorBarDetail &barDetail = crvCounter.getBarDetail();
+    CLHEP::Hep3Vector crvCounterPos = crvCounter.getPosition();
+    CLHEP::Hep3Vector pointInMu2e = det->toDetector(crvCounterPos);
+
+    double X_cm = pointmmTocm(pointInMu2e.x());
+    double Y_cm = pointmmTocm(pointInMu2e.y());
+    double Z_cm = pointmmTocm(pointInMu2e.z());
+    if(extracted) {
+        Z_cm += GetCrvExtractedZShift();
+    }
 
-    // Find the Global Pulse Time Range (min/max) for ALL pulses in ALL clusters
-    double max_time = -1e6;
-    double min_time = 1e6;
-    bool found_pulses = false;
-
-    for (const auto* crvClusters : crvpulse_list) {
-        if (crvClusters) {
-            for (const auto& crvclu : *crvClusters) {
-                for (const auto& crvpulsePtr : crvclu.GetCrvRecoPulses()) {
-                    if (crvpulsePtr) {
-                        found_pulses = true;
-                        double time = crvpulsePtr->GetPulseTime();
-                        if(time > max_time) max_time = time;
-                        if(time < min_time) min_time = time;
-                    }
-                }
-            }
+    double length = pointmmTocm(crvCounter.getHalfLength());
+    double width = pointmmTocm(crvCounter.getHalfWidth());
+    double height = pointmmTocm(crvCounter.getHalfThickness());
+
+    auto b = new REX::REveBox(title.c_str(), title.c_str());
+    b->SetMainColor(color);
+    b->SetMainTransparency(drawconfig.getInt("Crvtrans"));
+    b->SetLineWidth(drawconfig.getInt("GeomLineWidth"));
+
+    if(!extracted){
+        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);
+        }
+        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);
+        }
+        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);
         }
+        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);
+        }
+        if(barCompound) barCompound->AddElement(b);
     }
-
-    if (!found_pulses) {
-        std::cout << "[DataInterface::AddCrvClusters() ] No valid Crv Reco Pulses found in clusters." << std::endl;
-        return;
+    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);
+        } 
+        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);
     }
+}
 
-    // Define time window size (in ns) - adjust this parameter to group pulses differently
-    const double time_window_size = 50000.0; // 50 ms windows (400 ms total span / ~8 windows)
-    
-    // Calculate number of time windows needed
-    double time_range = max_time - min_time;
-    int num_windows = static_cast<int>(std::ceil(time_range / time_window_size)) + 1;
+void DataInterface::AddCrvClusters(REX::REveManager *&eveMng, bool firstLoop_, 
+                                   std::tuple<std::vector<std::string>, 
+                                   std::vector<const CrvCoincidenceClusterCollection*>> crvpulse_tuple, 
+                                   REX::REveElement* &scene, bool extracted, bool addCrvBars)
+{
+    std::vector<const CrvCoincidenceClusterCollection*> crvpulse_list = std::get<1>(crvpulse_tuple);
+    std::vector<std::string> names = std::get<0>(crvpulse_tuple);
+    mu2e::GeomHandle<mu2e::CosmicRayShield> CRS;
+    mu2e::GeomHandle<mu2e::DetectorSystem> det;
     
-    // Define a set of distinct colors for time windows
-    std::vector<Color_t> time_window_colors = {
-        kRed, kGreen, kBlue, kYellow, kMagenta, kCyan, 
-        kOrange, kSpring, kTeal, kAzure, kViolet, kPink,
-        kRed+2, kGreen+2, kBlue+2, kYellow+2, kMagenta+2, kCyan+2,
-        kRed+1, kGreen+1
-    };
+    if (crvpulse_list.size() == 0) return;
     
-    std::cout << "[DataInterface::AddCrvClusters() ] Time range: " << min_time << " to " << max_time 
-              << " ns (range: " << time_range << " ns), num_windows: " << num_windows << std::endl;
-
-    // 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();
-            }
+            if(extracted) cluster_z += GetCrvExtractedZShift();
             ps1->SetNextPoint(pointmmTocm(pointInMu2e.x()), pointmmTocm(pointInMu2e.y()) , cluster_z);
-            
             std::set<mu2e::CRSScintillatorBarIndex> drawn_bars; 
-
             for(unsigned h =0 ; h < crvclu.GetCrvRecoPulses().size();h++) {
-                
                 art::Ptr<mu2e::CrvRecoPulse> 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();
-                    
-                    // Determine which time window this pulse belongs to
-                    int time_window_index = static_cast<int>(std::floor((pulse_time - min_time) / time_window_size));
-                    if (time_window_index < 0) time_window_index = 0;
-                    if (time_window_index >= num_windows) time_window_index = num_windows - 1;
-                    
-                    // Get color from predefined color array, cycling if necessary
-                    Color_t hit_color = time_window_colors[time_window_index % time_window_colors.size()];
-
-
-                    // 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) + " ns (Time Window: " + std::to_string(time_window_index) + ", Color)" + '\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);
-                    b->SetMainColor(hit_color);
-                    b->SetMainTransparency(drawconfig.getInt("Crvtrans"));
-                    b->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); 
-                    }
+                    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) + " ns" + '\n'
+                                              + "Pulse Height: " + std::to_string(crvpulse->GetPulseHeight()) + " ADC" + '\n'
+                                              + "Coincidence start time: " + std::to_string(crvclu.GetStartTime()) +  '\n'
+                                              + "Coincidence end time: " + std::to_string(crvclu.GetEndTime());
+                    AddCrvBar(crvBarIndex, pulsetitle, kBlack, extracted, scene, allcrvbars_collection);
                 }
-            } // End of inner h loop (pulses)
-            
-            // Cluster Point Set Configuration
-            ps1->SetMarkerColor(drawconfig.getInt("CrvHitColor")); // Marker color based on configuration
+            }
+            ps1->SetMarkerColor(drawconfig.getInt("CrvHitColor"));
             ps1->SetMarkerStyle(DataInterface::mstyle);
             ps1->SetMarkerSize(DataInterface::msize);
-            
             if(ps1->GetSize() !=0 ) scene->AddElement(ps1); 
-            
-        } // End of j loop (clusters)
+        }
+        if(!extracted && addCrvBars) scene->AddElement(allcrvbars_collection); 
+    }
+}
 
-        // Final Additions to Scene
-        if(!extracted && addCrvBars) {
-            scene->AddElement(allcrvbars_collection); 
-        } 
+            }
+            ps1->SetMarkerColor(drawconfig.getInt("CrvHitColor"));
+            ps1->SetMarkerStyle(DataInterface::mstyle);
+            ps1->SetMarkerSize(DataInterface::msize);
+            if(ps1->GetSize() !=0 ) scene->AddElement(ps1); 
+        }
+        if(!extracted && addCrvBars) scene->AddElement(allcrvbars_collection); 
+    }
+}
+
+            }
+            ps1->SetMarkerColor(drawconfig.getInt("CrvHitColor"));
+            ps1->SetMarkerStyle(DataInterface::mstyle);
+            ps1->SetMarkerSize(DataInterface::msize);
+            if(ps1->GetSize() !=0 ) scene->AddElement(ps1); 
+        }
+        if(!extracted && addCrvBars) scene->AddElement(allcrvbars_collection); 
     }
 }
 
@@ -1537,42 +1469,9 @@ void DataInterface::AddCRVKalIntersection(REX::REveManager *&eveMng, bool firstl
                 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){
@@ -1580,87 +1479,19 @@ void DataInterface::AddCRVKalIntersection(REX::REveManager *&eveMng, bool firstl
                       if(deltaT < minTime2)
                         minTime2 = deltaT;
                     }
-                    std::cout<<"MinTime = "<<minTime<<" minTime2 = "<<minTime2<<std::endl;
+                    Color_t hit_color;
                     if(std::abs(minTime2 - minTime) < 1e-3)
-                      b->SetMainColor(kRed);
+                      hit_color = kRed;
                     else
-                      b->SetMainColor(kBlack);
-                    b->SetMainTransparency(drawconfig.getInt("Crvtrans"));
-                    b->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); 
-                    }
+                      hit_color = kBlack;
+                    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());
+                    AddCrvBar(crvBarIndex, pulsetitle, hit_color, extracted, scene, allcrvbars_collection);
                 }
             } // End of inner h loop (pulses)
             

From ac95c8035e8610657a58c00007df38861f063e6d Mon Sep 17 00:00:00 2001
From: Namitha Chithirasreemadam <namithac@mu2egpvm04.fnal.gov>
Date: Mon, 4 May 2026 15:58:30 -0500
Subject: [PATCH 7/7] bug fix

---
 src/DataInterface.cc | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/src/DataInterface.cc b/src/DataInterface.cc
index 150dc85..1e7999b 100644
--- a/src/DataInterface.cc
+++ b/src/DataInterface.cc
@@ -754,26 +754,6 @@ void DataInterface::AddCrvClusters(REX::REveManager *&eveMng, bool firstLoop_,
     }
 }
 
-            }
-            ps1->SetMarkerColor(drawconfig.getInt("CrvHitColor"));
-            ps1->SetMarkerStyle(DataInterface::mstyle);
-            ps1->SetMarkerSize(DataInterface::msize);
-            if(ps1->GetSize() !=0 ) scene->AddElement(ps1); 
-        }
-        if(!extracted && addCrvBars) scene->AddElement(allcrvbars_collection); 
-    }
-}
-
-            }
-            ps1->SetMarkerColor(drawconfig.getInt("CrvHitColor"));
-            ps1->SetMarkerStyle(DataInterface::mstyle);
-            ps1->SetMarkerSize(DataInterface::msize);
-            if(ps1->GetSize() !=0 ) scene->AddElement(ps1); 
-        }
-        if(!extracted && addCrvBars) scene->AddElement(allcrvbars_collection); 
-    }
-}
-
 /*------------Function to add TimeCluster Collection in 3D and 2D displays:-------------*/
 void DataInterface::AddTimeClusters(REX::REveManager *&eveMng, bool firstLoop_, std::tuple<std::vector<std::string>, std::vector<const TimeClusterCollection*>>  timecluster_tuple, std::tuple<std::vector<std::string>, std::vector<const ComboHitCollection*>> combohit_tuple, REX::REveElement* &scene){
 
