Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-18 09:15:15

0001 // Fun4All_RunStreakFromDST.C
0002 
0003 #ifdef __CLING__
0004 #pragma cling add_include_path("/sphenix/u/$USER/install/include")
0005 #endif
0006 
0007 #include <fun4all/Fun4AllServer.h>
0008 #include <fun4all/Fun4AllDstInputManager.h>
0009 #include <fun4all/SubsysReco.h>
0010 #include <phool/recoConsts.h>
0011 
0012 R__LOAD_LIBRARY(libfun4all.so)
0013 R__LOAD_LIBRARY(libg4eval.so)
0014 R__LOAD_LIBRARY(libcalo_reco.so)
0015 R__LOAD_LIBRARY(libjetbase.so)
0016 R__LOAD_LIBRARY(libStreakEventsIdentifier.so)
0017 
0018 #include <algorithm>
0019 #include <cctype>
0020 #include <sstream>
0021 #include <string>
0022 #include <vector>
0023 
0024 #include <TError.h>
0025 
0026 #include "streakeventsidentifier/StreakEventsIdentifier.h"
0027 
0028 // -------- helpers --------
0029 static std::string tolower_copy(std::string s){
0030   std::transform(s.begin(), s.end(), s.begin(),
0031                  [](unsigned char c){ return std::tolower(c); });
0032   return s;
0033 }
0034 static bool has_suffix_ci(const std::string& s, const char* suf){
0035   auto ls = tolower_copy(s);
0036   std::string ss = tolower_copy(suf);
0037   return ls.size() >= ss.size() && ls.compare(ls.size()-ss.size(), ss.size(), ss) == 0;
0038 }
0039 static void AddFilesSmart(Fun4AllDstInputManager* mgr, const char* spec)
0040 {
0041   if (!spec || !spec[0]) return;
0042   std::string s(spec);
0043 
0044   if (!s.empty() && s[0]=='@') { mgr->AddListFile(s.substr(1)); return; }
0045 
0046   // *.list / *.lst / *.txt => treat as list file
0047   if (has_suffix_ci(s, ".list") || has_suffix_ci(s, ".lst") || has_suffix_ci(s, ".txt"))
0048   { mgr->AddListFile(s); return; }
0049 
0050   // allow comma-separated list of .root files
0051   if (s.find(',') != std::string::npos) {
0052     std::stringstream ss(s);
0053     std::string item;
0054     while (std::getline(ss, item, ',')) {
0055       if (!item.empty()) mgr->AddFile(item);
0056     }
0057     return;
0058   }
0059 
0060   mgr->AddFile(s);
0061 }
0062 // -------------------------
0063 
0064 void Fun4All_RunStreakFromDST(const char* dst_jetcalo,
0065                               const char* dst_jet,
0066                               int   nevents      = 2,
0067                               const char* outprefix = "streak_fromDST",
0068                               float etMin_GeV   = 5.0,
0069                               float wetaMin     = 0.5,
0070                               float absTimeCutNs= 10.0,
0071                               float rmsMinNs    = 5.0,
0072                               float timeWeightEthresh= 0.10,
0073                               const char* pngDir= "",
0074                               bool  excludeStreaks = false,
0075                               float mbdTimeMin = -10.0,
0076                               float mbdTimeMax = 10.0,
0077                               const char* triggerBits = "24,25,26,27,36,37,38",
0078                               bool requireValidTiming = true)  //  trigger bits
0079 
0080 {
0081   Fun4AllServer* se = Fun4AllServer::instance();
0082 
0083 
0084   gErrorAbortLevel = kError; 
0085   
0086   // inputs
0087   auto in1 = new Fun4AllDstInputManager("DST1");
0088   AddFilesSmart(in1, dst_jetcalo);
0089   se->registerInputManager(in1);
0090 
0091   if (dst_jet && dst_jet[0] != '\0') {
0092     auto in2 = new Fun4AllDstInputManager("DST2");
0093     AddFilesSmart(in2, dst_jet);
0094     se->registerInputManager(in2);
0095   }
0096 
0097   // Create module
0098   auto* mod = new StreakEventsIdentifier("StreakID", outprefix);
0099   mod->SetEnergyThreshold(etMin_GeV);
0100   mod->SetWetaCut(wetaMin);
0101   mod->SetTimingCuts(absTimeCutNs, rmsMinNs);
0102   mod->SetTimeWeightEthresh(timeWeightEthresh);
0103 
0104   //require valid timing information
0105   //mod->SetRequireValidTiming(true);
0106     mod->SetRequireValidTiming(requireValidTiming);
0107 
0108   // Set the exclude streaks flag
0109   mod->SetExcludeStreaks(excludeStreaks);
0110   mod->SetMbdTimingCuts(mbdTimeMin, mbdTimeMax);
0111 
0112   //trigger selection
0113   if (triggerBits && triggerBits[0] != '\0') {
0114     std::vector<int> trigger_bit_list;
0115     std::string s(triggerBits);
0116     std::stringstream ss(s);
0117     std::string item;
0118     
0119     std::cout << "\n=== Configuring Trigger Selection ===" << std::endl;
0120     std::cout << "Parsing trigger bits: " << triggerBits << std::endl;
0121     
0122     while (std::getline(ss, item, ',')) {
0123       if (!item.empty()) {
0124         // Trim whitespace
0125         item.erase(0, item.find_first_not_of(" \t"));
0126         item.erase(item.find_last_not_of(" \t") + 1);
0127         
0128         try {
0129           int bit = std::stoi(item);
0130           trigger_bit_list.push_back(bit);
0131           std::cout << "  Added trigger bit: " << bit << std::endl;
0132         } catch (...) {
0133           std::cout << "  [WARNING] Could not parse trigger bit: " << item << std::endl;
0134         }
0135       }
0136     }
0137     
0138     if (!trigger_bit_list.empty()) {
0139       mod->set_using_trigger_bits(trigger_bit_list);
0140       std::cout << "Total trigger bits configured: " << trigger_bit_list.size() << std::endl;
0141       std::cout << "Logic: OR (event passes if ANY bit fires)" << std::endl;
0142     } else {
0143       std::cout << "[WARNING] No valid trigger bits parsed!" << std::endl;
0144     }
0145     std::cout << "======================================\n" << std::endl;
0146   } else {
0147     std::cout << "\n[INFO] No trigger bits specified - accepting all events\n" << std::endl;
0148   }
0149   // ===== END TRIGGER SELECTION =====
0150 
0151   if (pngDir && pngDir[0] != '\0') mod->SetPngDir(pngDir);
0152 
0153   mod->SetJetContainer("AntiKt_unsubtracted_r04");
0154   mod->Verbosity(0);
0155   
0156   se->registerSubsystem(mod);
0157   se->run(nevents);
0158   se->End();
0159 }