From 0684422d0f471c679f0c69bc25d1be66bc2dabd6 Mon Sep 17 00:00:00 2001 From: fox Date: Sun, 24 Nov 2024 21:12:20 +0800 Subject: [PATCH] Feat: cutEnable, command args parse --- CMakeLists.txt | 11 ++--------- include/BluetAnalyzer.hh | 1 + main.cc | 40 ++++++++++++++++++++++++++++++++++------ src/BluetAnalyzer.cc | 23 ++++++++++++++--------- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc67291..a0a0224 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,8 +29,6 @@ include(${Geant4_USE_FILE}) include_directories(${PROJECT_SOURCE_DIR}/include) # Include bluet file set(bluet_base "/home/liuyihui/bluet/") -# include(${bluet_base}/sources/config/include/BluetConfig.hh) -# include(${bluet_base}/sources/modules/include/BluetDataModel.hh) include_directories(${bluet_base}/sources/config/include) include_directories(${bluet_base}/sources/modules/include) include_directories(${bluet_base}/sources/runner/include) @@ -39,13 +37,8 @@ include_directories($ENV{GARFIELD_INSTALL}/include/Garfield) # Locate sources and headers for this project file(GLOB analyzer ${PROJECT_SOURCE_DIR}/include/* ${PROJECT_SOURCE_DIR}/src/*) -# file(GLOB config ${bluet_base}/sources/config/include/* ${bluet_base}/sources/config/src/*) -# file(GLOB modules ${bluet_base}/sources/modules/include/* ${bluet_base}/sources/modules/src/*) -# file(GLOB runner ${bluet_base}/sources/runner/include/* ${bluet_base}/sources/runner/src/*) -# file(GLOB utils ${bluet_base}/utils/include/* ${bluet_base}/utils/src/*) -list(FILTER analyzer EXCLUDE REGEX "BluetDrawLinkDef") +# list(FILTER analyzer EXCLUDE REGEX "BluetDrawLinkDef") -# ROOT_GENERATE_DICTIONARY(D_${PROJECT_NAME} /home/fox/bluet/sources/modules/include/DrawEvent.hh LINKDEF /home/fox/bluet/sources/modules/include/BluetDrawLinkDef.hh) add_library(SO_${PROJECT_NAME} SHARED ${analyzer} # Bluet @@ -56,7 +49,7 @@ add_library(SO_${PROJECT_NAME} SHARED ${bluet_base}/utils/src/xmlparse.cc ${bluet_base}/utils/include/stringhandle.hh ${bluet_base}/utils/src/stringhandle.cc - # D_${PROJECT_NAME}.cxx + ${bluet_base}/utils/include/clipp.h ) target_link_libraries(SO_${PROJECT_NAME} PUBLIC diff --git a/include/BluetAnalyzer.hh b/include/BluetAnalyzer.hh index 20bb3f9..49b6bbe 100644 --- a/include/BluetAnalyzer.hh +++ b/include/BluetAnalyzer.hh @@ -63,6 +63,7 @@ private: double flighL; double sampleT; + bool cutEnable; double EcutMin; double EcutMax; double tofCutMin; diff --git a/main.cc b/main.cc index 126d624..fa71ccc 100644 --- a/main.cc +++ b/main.cc @@ -1,19 +1,47 @@ #include "BluetAnalyzer.hh" +#include "clipp.h" +#include "stringhandle.hh" #include "iostream" using namespace std; +const string datapath = "/home/liuyihui/BluetAnalyzer/data"; + int main(int argc, char **argv) { - if (argc < 3) { - cout << "Usage: " << argv[0] << " " << endl; + string cfgfile; + string datafile; + vector ranges; + vector runfiles; + Long_t rl, rr; + + auto cfg = clipp::value("config file", cfgfile); + auto data = + (clipp::option("-f", "--file") & clipp::value("data file", datafile), + clipp::option("-r", "--range") & + clipp::values("number1 number2", ranges)); + + if (!clipp::parse(argc, const_cast(argv), cfg & data)) { + cerr << clipp::make_man_page(cfg & data, argv[0]) << endl; return 1; } - string cfgfile = argv[1]; - string datafile = argv[2]; - vector runfiles; - runfiles.push_back(datafile); + if (ranges.size() == 0) { + runfiles.push_back(datafile); + } else { + std::vector ifiles; + bluet::GetAllFiles(datapath, ifiles); + + rl = stoll(ranges[0]); + rr = stoll(ranges[1]); + for (size_t j = 0; j < ifiles.size(); j++) { + if (bluet::SplitString(ifiles[j], '.')[4] != string("root")) + continue; + long long number = stoll(bluet::SplitString(ifiles[j], '.')[2]); + if (number >= rl && number <= rr) + runfiles.push_back(datapath + "/" + ifiles[j]); + } + } BluetAnalyzer *bluet = new BluetAnalyzer(); bluet->readCutParameters(cfgfile); diff --git a/src/BluetAnalyzer.cc b/src/BluetAnalyzer.cc index c1693d6..5fc72df 100644 --- a/src/BluetAnalyzer.cc +++ b/src/BluetAnalyzer.cc @@ -144,6 +144,7 @@ void BluetAnalyzer::readCutParameters(string cfgfile) { dv0 = bluet::XMLToQuantity(gas.child("DriftVelocity")) * 1e4; pugi::xml_node cut = root.child("CutParameters"); + cutEnable = bluet::XMLToQuantity(cut.child("CutEnable")); EcutMin = bluet::XMLToQuantity(cut.child("ECutMin")); EcutMax = bluet::XMLToQuantity(cut.child("ECutMax")); tofCutMin = bluet::XMLToQuantity(cut.child("TOFCutMin")); @@ -173,7 +174,7 @@ void BluetAnalyzer::readCutParameters(string cfgfile) { Nbin = 100; tmin = 2.e2; // [ns] gamma - tmax = 5.e6; // [ns] 1 eV + tmax = 1.e7; // [ns] 0.3 eV ts=1.2e6 Nrbin = 300; rmax = 80.; Sbin = new double[Nrbin]; @@ -409,6 +410,8 @@ void BluetAnalyzer::defineHistograms() { } bool BluetAnalyzer::isGoodEvent(BluetEvent *event) { + if (!cutEnable) + return true; if (event->TOF0 < tofCutMin || event->TOF0 > tofCutMax) return false; if (event->TimeStamp < stampCutMin || event->TimeStamp > stampCutMax) @@ -428,6 +431,8 @@ bool BluetAnalyzer::isGoodEvent(BluetEvent *event) { } bool BluetAnalyzer::isGoodTrack(BluetTrack *track) { + if (!cutEnable) + return true; if (track->TrSumEdep < EcutMin || track->TrSumEdep > EcutMax) return false; if (track->TrRawLength < lengthCutMin || track->TrRawLength > lengthCutMax) @@ -491,8 +496,8 @@ void BluetAnalyzer::FillHistograms() { double sumE = fEvent->Tracks[itrk].TrSumEdep; double length = fEvent->Tracks[itrk].TrRawLength; - double tmax = fEvent->Tracks[itrk].Tmax; - double tmin = fEvent->Tracks[itrk].Tmin; + double traTmax = fEvent->Tracks[itrk].Tmax; + double traTmin = fEvent->Tracks[itrk].Tmin; double cost = fEvent->Tracks[itrk].TrCosTheta; double *xypos = fEvent->Tracks[itrk].ZmaxHit_xy; double radius = @@ -504,17 +509,17 @@ void BluetAnalyzer::FillHistograms() { if (radius >= rTarget && rSubstrate <= rSubstrate + 5) nRing++; - double v0 = driftL / (tmax - tcath) / sampleT; - double v1 = driftL / (tmax - tmin) / sampleT; + double v0 = driftL / (traTmax - tcath) / sampleT; + double v1 = driftL / (traTmax - traTmin) / sampleT; hv0->Fill(v0 * 1000.); // [mm/ns]->[mm/us] hv1->Fill(v1 * 1000.); // [mm/ns]->[mm/us] - htpad->Fill((tmax - tmin) * sampleT); - htcath->Fill((tmax - tcath) * sampleT); + htpad->Fill((traTmax - traTmin) * sampleT); + htcath->Fill((traTmax - tcath) * sampleT); hcos->Fill(fabs(cost)); hphi->Fill(fEvent->Tracks[itrk].TrPhi); - hdeltacos1->Fill(fabs(cost), (tmax - tcath) * sampleT); - hdeltacos2->Fill(fabs(cost), (tmax - tmin) * sampleT); + hdeltacos1->Fill(fabs(cost), (traTmax - tcath) * sampleT); + hdeltacos2->Fill(fabs(cost), (traTmax - traTmin) * sampleT); hLengthE->Fill(length, sumE); hprofile->Fill(xypos[0], xypos[1]); hbeamr->Fill(radius);