File indexing completed on 2025-12-16 09:24:06
0001 #include "G4Setup_sPHENIX.C"
0002
0003 #include <G4_TrkrVariables.C>
0004 #include <G4_ActsGeom.C>
0005 #include <Trkr_Clustering.C>
0006
0007 #include <intt/InttCombinedRawDataDecoder.h>
0008
0009 #include <ffarawmodules/InttCheck.h>
0010
0011 #include <fun4all/Fun4AllDstOutputManager.h>
0012 #include <fun4all/Fun4AllInputManager.h>
0013 #include <fun4all/Fun4AllOutputManager.h>
0014 #include <fun4all/Fun4AllServer.h>
0015 #include <fun4all/Fun4AllUtils.h>
0016
0017 #include <fun4allraw/Fun4AllStreamingInputManager.h>
0018 #include <fun4allraw/InputManagerType.h>
0019 #include <fun4allraw/SingleInttPoolInput.h>
0020
0021 #include <phool/recoConsts.h>
0022
0023 #include <format>
0024
0025 R__LOAD_LIBRARY(libfun4all.so)
0026 R__LOAD_LIBRARY(libfun4allraw.so)
0027 R__LOAD_LIBRARY(libffarawmodules.so)
0028 R__LOAD_LIBRARY(libintt.so)
0029
0030 bool isGood(const std::string &infile);
0031 int getrunnumber(const std::string &listfile);
0032
0033 void Fun4All_Intt_Combiner(int nEvents = 0,
0034 const int = 20869,
0035 const std::string &cdbglobaltag = "newcdbtag",
0036 const bool runTrkrHits = true,
0037 const bool applyHotChannel = true,
0038 const bool applyBCOCut = true,
0039 const bool applyADCConversion = true,
0040 const bool runTkrkClus = true,
0041 const bool usesurveygeom = true,
0042 const bool stripRawHit = true)
0043 {
0044
0045 std::vector<std::string> infile = {"intt0.list", "intt1.list", "intt2.list", "intt3.list", "intt4.list", "intt5.list", "intt6.list", "intt7.list"};
0046
0047 int runnumber = getrunnumber(infile[0]);
0048
0049 std::string outfilename = std::format("intt-{:08}.root",runnumber);
0050 std::string outdirinitial = "ProdDST";
0051 if (applyHotChannel)
0052 {
0053 outdirinitial += "-HotDead";
0054 }
0055 if (applyBCOCut)
0056 {
0057 outdirinitial += "-BCO";
0058 }
0059 if (applyADCConversion)
0060 {
0061 outdirinitial += "-ADC";
0062 }
0063 if (usesurveygeom)
0064 {
0065 outdirinitial += "-Survey";
0066 }
0067 std::string cmd = "mkdir -p " + outdirinitial;
0068 system(cmd.c_str());
0069
0070 Fun4AllServer *se = Fun4AllServer::instance();
0071 se->Verbosity(1);
0072 recoConsts *rc = recoConsts::instance();
0073
0074 Enable::CDB = true;
0075 rc->set_StringFlag("CDB_GLOBALTAG", cdbglobaltag);
0076 rc->set_uint64Flag("TIMESTAMP", runnumber);
0077
0078 Fun4AllStreamingInputManager *in = new Fun4AllStreamingInputManager("Comb");
0079
0080 int i = 0;
0081 for (const auto& iter : infile)
0082 {
0083 if (isGood(iter))
0084 {
0085 SingleInttPoolInput *sngl = new SingleInttPoolInput("INTT_" + std::to_string(i));
0086
0087 sngl->AddListFile(iter);
0088 int nBcoVal = runTrkrHits ? 0 : 2;
0089 sngl->SetNegativeBco(nBcoVal);
0090 sngl->SetBcoRange(2);
0091 in->registerStreamingInput(sngl, InputManagerType::INTT);
0092 i++;
0093 }
0094 }
0095
0096 se->registerInputManager(in);
0097
0098
0099
0100
0101
0102 if (runTrkrHits)
0103 {
0104 InttCombinedRawDataDecoder *myDecoder = new InttCombinedRawDataDecoder("myUnpacker");
0105 myDecoder->runInttStandalone(true);
0106 myDecoder->writeInttEventHeader(true);
0107 if (applyHotChannel) myDecoder->LoadHotChannelMapRemote("INTT_HotMap");
0108 std::string DACmap = (applyADCConversion) ? "INTT_DACMAP" : "";
0109 std::string BCOmap = (applyBCOCut) ? "INTT_BCOMAP" : "";
0110 myDecoder->SetCalibDAC(DACmap);
0111 myDecoder->SetCalibBCO(BCOmap);
0112 se->registerSubsystem(myDecoder);
0113 }
0114
0115 if (runTkrkClus)
0116 {
0117 Enable::MVTX = true;
0118 Enable::INTT = true;
0119 Enable::TPC = true;
0120 Enable::MICROMEGAS = true;
0121
0122 Enable::INTT_USEG4SURVEYGEOM = usesurveygeom;
0123 ACTSGEOM::inttsurvey = usesurveygeom;
0124 G4Init();
0125 G4Setup();
0126 ClusteringInit();
0127 Intt_Clustering();
0128 }
0129 std::string fulloutfile = outdirinitial + "/" + outfilename;
0130 Fun4AllOutputManager *out = new Fun4AllDstOutputManager("out", fulloutfile);
0131 if (stripRawHit)
0132 {
0133 out->StripNode("INTTRAWHIT");
0134 }
0135 se->registerOutputManager(out);
0136
0137 se->run(nEvents);
0138
0139 se->End();
0140 delete se;
0141 gSystem->Exit(0);
0142 }
0143
0144 bool isGood(const std::string &infile)
0145 {
0146 std::ifstream intest;
0147 intest.open(infile);
0148 bool goodfile = false;
0149 if (intest.is_open())
0150 {
0151 if (intest.peek() != std::ifstream::traits_type::eof())
0152 {
0153 goodfile = true;
0154 }
0155 intest.close();
0156 }
0157 return goodfile;
0158 }
0159
0160 int getrunnumber(const std::string &listfile)
0161 {
0162 if (!isGood(listfile))
0163 {
0164 std::cout << "listfile " << listfile << " is bad" << std::endl;
0165 gSystem->Exit(1);
0166 }
0167 std::ifstream ifs(listfile);
0168 std::string filepath;
0169 std::getline(ifs, filepath);
0170
0171 std::pair<int, int> runseg = Fun4AllUtils::GetRunSegment(filepath);
0172 int runnumber = runseg.first;
0173
0174 return runnumber;
0175 }