diff --git a/ModularDetectorAnalysis/EventCategorizer.cpp b/ModularDetectorAnalysis/EventCategorizer.cpp index fc8295c8..71baea45 100644 --- a/ModularDetectorAnalysis/EventCategorizer.cpp +++ b/ModularDetectorAnalysis/EventCategorizer.cpp @@ -567,7 +567,7 @@ void EventCategorizer::initialiseCalibrationHistograms(bool includeTrento) "Scin ID", "Time diffrence [ps]"); // Time walk histograms - double revToTLimit = 0.000000018; + double revToTLimit = 0.000000030; getStatistics().createHistogramWithAxes( new TH2D("time_walk_ab_tdiff", "AB TDiff vs. reversed ToT", 200, -fMaxTimeDiff / 2.0, fMaxTimeDiff / 2.0, 200, -revToTLimit, revToTLimit), diff --git a/opsAnalysis/NTupler.cpp b/opsAnalysis/NTupler.cpp index c6b74109..fa22fee4 100644 --- a/opsAnalysis/NTupler.cpp +++ b/opsAnalysis/NTupler.cpp @@ -1,5 +1,5 @@ /** - * @copyright Copyright 2016 The J-PET Framework Authors. All rights reserved. + * @copyright Copyright 2024 The J-PET Framework Authors. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may find a copy of the License in the LICENCE file. @@ -13,18 +13,15 @@ * @file Ntupler.cpp */ -#include #include "NTupler.h" -//#include "OPSAnalysisTools.h" -#include #include "../ModularDetectorAnalysis/HitFinderTools.h" #include +#include using namespace jpet_options_tools; -//using namespace ops_analysis_tools; using namespace std; -NTupler::NTupler(const char* name): JPetUserTask(name) {} +NTupler::NTupler(const char* name) : JPetUserTask(name) {} bool NTupler::init() { @@ -32,104 +29,69 @@ bool NTupler::init() fOutputEvents = new JPetTimeWindow("JPetEvent"); - //if (isOptionSet(fParams.getOptions(), fThresholdValuesKey)){ - //fThresholdValues = getOptionAsVectorOfInts(fParams.getOptions(), fThresholdValuesKey); - - //INFO(Form("Loaded the following threshold values: (%d, %d, %d, %d)", - // fThresholdValues[0], - // fThresholdValues[1], - // fThresholdValues[2], - // fThresholdValues[3] - // )); - - //}else{ - // WARNING("TOT values were not provided by the user!"); - // } - - if (isOptionSet(fParams.getOptions(), fEventTimeParamKey)){ - kEventTimeWindow = getOptionAsFloat(fParams.getOptions(), fEventTimeParamKey); - }else{ - ERROR("Fine time window width not provided by the user!"); - return false; - } - - if(isOptionSet(fParams.getOptions(), "inputFile_std::string")){ - fOutFileName = getOptionAsString(fParams.getOptions(), "inputFile_std::string"); + if (isOptionSet(fParams.getOptions(), "inputFile_std::string")) + { + fOutFileName = getOptionAsString(fParams.getOptions(), "inputFile_std::string"); } - if(isOptionSet(fParams.getOptions(), "outputPath_std::string")){ - fOutFilePath = getOptionAsString(fParams.getOptions(), "outputPath_std::string"); + if (isOptionSet(fParams.getOptions(), "outputPath_std::string")) + { + fOutFilePath = getOptionAsString(fParams.getOptions(), "outputPath_std::string"); } - + // initialize output file and tree - if(fOutFileName.find("unk.evt.root") != std::string::npos){ - fOutFileName.replace(fOutFileName.find("unk.evt.root"), std::string::npos, "ntu.root"); + if (fOutFileName.find("unk.evt.root") != std::string::npos) + { + fOutFileName.replace(fOutFileName.find("unk.evt.root"), std::string::npos, "ntu.root"); } - // handle special case if direct processing is used - //if(fOutFileName.find("hld.root") != std::string::npos){ - //fOutFileName.replace(fOutFileName.find("hld.root"), std::string::npos, "ntu.root"); - //} - - if (!fOutFilePath.empty()) { + if (!fOutFilePath.empty()) + { size_t filename_pos = fOutFileName.find("dabc"); fOutFileName.replace(0, filename_pos - 1, fOutFilePath); } fOutFile = new TFile(fOutFileName.c_str(), "RECREATE"); - fOutTree = new TTree("T", "o-Ps event candidates"); - + fOutTree = new TTree("T", "JPET Events"); + fOutTree->Branch("nhits", &fNumberOfHits, "nhits/b"); fOutTree->Branch("times", &fHitTimes); fOutTree->Branch("pos", &fHitPos); - fOutTree->Branch("tots_flat", &fHitTOTsFlat); - fOutTree->Branch("tots", &fHitTOTs); + fOutTree->Branch("tots", &fHitTOTs); fOutTree->Branch("scins", &fHitScinIDs); - return true; } bool NTupler::exec() -{ - if (auto timeWindow = dynamic_cast(fEvent)) { +{ + if (auto timeWindow = dynamic_cast(fEvent)) + { int n_events = timeWindow->getNumberOfEvents(); - - for (int entry = 0; entry < n_events; ++entry) { - const JPetEvent &event = - dynamic_cast(timeWindow->operator[](entry)); - - const auto &hits = event.getHits(); - fNumberOfHits = event.getHits().size(); - - for (auto &hit : hits) { - //double tot_proportional = calculateTOTproportional(hit); - //double tot = HitFinderTools::calculateTOT(hit, HitFinderTools::TOTCalculationType::kThresholdTrapeze)/1000; - double tot_flat = hit->getEnergy(); + for (int entry = 0; entry < n_events; ++entry) + { + const JPetEvent& event = dynamic_cast(timeWindow->operator[](entry)); - // reject hits with badly reconstructed TOT - if ( - tot_flat <= 0.) { - continue; - } + const auto& hits = event.getHits(); + fNumberOfHits = event.getHits().size(); - fHitPos.push_back(hit->getPos()); + for (auto& hit : hits) + { + // Writing time in nanoseconds fHitTimes.push_back(hit->getTime() / 1000.); + fHitPos.push_back(hit->getPos()); + fHitTOTs.push_back(hit->getEnergy()); fHitScinIDs.push_back(hit->getScin().getID()); - fHitTOTsFlat.push_back(tot_flat); - //fHitTOTs.push_back(tot); } - // only save the event if there was a cluster of 3+ hits in the fine time window - if (isThreeHitCluster(hits)) { - fOutTree->Fill(); - } + fOutTree->Fill(); resetRow(); } - - } else { + } + else + { return false; } return true; @@ -140,88 +102,15 @@ bool NTupler::terminate() fOutTree->Write(); fOutFile->Close(); - // delete fOutTree; - // delete fOutFile; - - INFO("Finished reduction of data to ntuples."); + INFO("Finished reduction of data to ntuples."); return true; } -/* -double Ntupler::calculateTOTproportional(const JPetHit& hit) const { - - auto getThresholdWeight = [&](int i) -> double { - if (i <= 1) { - return 1.; - } - return 1.*(fThresholdValues[i-1] - fThresholdValues[i-2]) / fThresholdValues[0]; - }; - - double tot = 0.; - - for(auto& phys_sig: {hit.getSignalA(), hit.getSignalB()}){ - - const JPetRawSignal& raw_sig = phys_sig.getRecoSignal().getRawSignal(); - - auto leading_points = raw_sig.getTimesVsThresholdNumber(JPetSigCh::Leading); - auto trailing_points = raw_sig.getTimesVsThresholdNumber(JPetSigCh::Trailing); - - for (int i = 1; i <= 4; i++) { - auto lead_search = leading_points.find(i); - auto trail_search = trailing_points.find(i); - if (lead_search != leading_points.end() - && trail_search != trailing_points.end()){ - tot += getThresholdWeight(i) * - (trail_search->second - lead_search->second) / 1000.; // in ns - } - } - } - - - return tot; -} -*/ - -bool NTupler::isThreeHitCluster( std::vector hits) +void NTupler::resetRow() { - vector newEventVec; - - int s = 0; - int n_hits = hits.size(); - //std::cout<getTime() - startHit->getTime()) < kEventTimeWindow) { - cluster_size++; - k++; - } else { - break; - } - } - s += k; - } - - if (cluster_size >= 3) { - return true; - } - return false; -} - -void NTupler::resetRow() { - fNumberOfHits = 0; - fHitScinIDs.clear(); - fHitPos.clear(); fHitTimes.clear(); - fHitTOTsFlat.clear(); + fHitPos.clear(); fHitTOTs.clear(); - + fHitScinIDs.clear(); } diff --git a/opsAnalysis/NTupler.h b/opsAnalysis/NTupler.h index c38f1077..591ede33 100644 --- a/opsAnalysis/NTupler.h +++ b/opsAnalysis/NTupler.h @@ -1,5 +1,5 @@ /** - * @copyright Copyright 2019 The J-PET Framework Authors. All rights reserved. + * @copyright Copyright 2024 The J-PET Framework Authors. All rights reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may find a copy of the License in the LICENCE file. @@ -13,65 +13,47 @@ * @file Ntupler.h */ -#ifndef NTUPLER_H -#define NTUPLER_H +#ifndef NTUPLER_H +#define NTUPLER_H -#include -#include -#include +#include #include -#include #include -//#include -#include -#include -#include +#include + +#include +#include +#include #include #include #include -#ifdef __CINT__ -# define override -#endif - -class NTupler : public JPetUserTask{ +class NTupler : public JPetUserTask +{ public: - NTupler(const char * name); - virtual ~NTupler(){} + NTupler(const char* name); + virtual ~NTupler() {} virtual bool init() override; virtual bool exec() override; virtual bool terminate() override; -protected: - //double calculateTOTproportional(const JPetHit& hit) const; - bool isThreeHitCluster(std::vector hits); +protected: void resetRow(); - - bool fIsMC = false; - const double kSpeedOfLight = 29.9792458; // cm / ns - - //std::string fThresholdValuesKey = "Ntupler_ThresholdValues_std::vector"; - //std::vector fThresholdValues; - double kEventTimeWindow = 2500; //5000.0; //ps - const std::string fEventTimeParamKey = "EventFinder_EventTime_float"; - //const std::string fEventTimeParamKey = "Ntupler_FineEventTime_float"; - TFile* fOutFile; TTree* fOutTree; std::string fOutFileName; std::string fOutFilePath; - + // ntuple components std::vector fHitTimes; std::vector fHitPos; - std::vector fHitScinIDs; - std::vector fHitTOTsFlat; std::vector fHitTOTs; + std::vector fHitScinIDs; UChar_t fNumberOfHits; - }; + #endif /* !NTUPLER_H */ diff --git a/opsAnalysis/main.cpp b/opsAnalysis/main.cpp index 1a67bf7c..a7e96144 100644 --- a/opsAnalysis/main.cpp +++ b/opsAnalysis/main.cpp @@ -35,16 +35,16 @@ int main(int argc, const char* argv[]) manager.registerTask("SignalTransformer"); manager.registerTask("HitFinder"); manager.registerTask("EventFinder"); - // manager.registerTask("NTupler"); manager.registerTask("EventCategorizer"); + manager.registerTask("NTupler"); manager.useTask("TimeWindowCreator", "hld", "tslot.calib"); manager.useTask("SignalFinder", "tslot.calib", "raw.sig"); manager.useTask("SignalTransformer", "raw.sig", "phys.sig"); manager.useTask("HitFinder", "phys.sig", "hits"); manager.useTask("EventFinder", "hits", "unk.evt"); - // manager.useTask("NTupler", "unk.evt", "tupler"); manager.useTask("EventCategorizer", "unk.evt", "cat.evt"); + manager.useTask("NTupler", "cat.evt", "ntu"); manager.run(argc, argv); }