From 3cccb44c728f1edaa9eda70f0e5d8453cac2d49b Mon Sep 17 00:00:00 2001 From: Viktor Date: Thu, 11 Jun 2020 11:04:15 +0200 Subject: [PATCH 01/20] add files --- AnalysisTreeInterface/CMakeLists.txt | 41 +++++ AnalysisTreeInterface/InConverter.cxx | 231 +++++++++++++++++++++++++ AnalysisTreeInterface/InConverter.h | 76 ++++++++ AnalysisTreeInterface/KFManLinkDef.h | 10 ++ AnalysisTreeInterface/KFPS_manager.cxx | 33 ++++ AnalysisTreeInterface/KFPS_manager.h | 35 ++++ AnalysisTreeInterface/OutConverter.cxx | 116 +++++++++++++ AnalysisTreeInterface/OutConverter.h | 70 ++++++++ AnalysisTreeInterface/main.cxx | 29 ++++ CMakeLists.txt | 16 +- 10 files changed, 651 insertions(+), 6 deletions(-) create mode 100644 AnalysisTreeInterface/CMakeLists.txt create mode 100644 AnalysisTreeInterface/InConverter.cxx create mode 100644 AnalysisTreeInterface/InConverter.h create mode 100644 AnalysisTreeInterface/KFManLinkDef.h create mode 100644 AnalysisTreeInterface/KFPS_manager.cxx create mode 100644 AnalysisTreeInterface/KFPS_manager.h create mode 100644 AnalysisTreeInterface/OutConverter.cxx create mode 100644 AnalysisTreeInterface/OutConverter.h create mode 100644 AnalysisTreeInterface/main.cxx diff --git a/AnalysisTreeInterface/CMakeLists.txt b/AnalysisTreeInterface/CMakeLists.txt new file mode 100644 index 0000000..34d7bf4 --- /dev/null +++ b/AnalysisTreeInterface/CMakeLists.txt @@ -0,0 +1,41 @@ +set(SOURCES + KFPS_manager.cxx + InConverter.cxx + OutConverter.cxx + ) + +string(REPLACE ".cxx" ".h" HEADERS "${SOURCES}") + +add_library(KFMan SHARED ${SOURCES} G__KFMan.cxx) + +ROOT_GENERATE_DICTIONARY(G__KFMan ${HEADERS} LINKDEF KFManLinkDef.h OPTIONS "-DDO_TPCCATRACKER_EFF_PERFORMANCE" "-DNonhomogeneousField" "-DCBM" "-DUSE_TIMERS") +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(KFMan ${ROOT_LIBRARIES} AnalysisTreeBase AnalysisTreeInfra KFParticle KFParticleInterface KFParticleSimple) + +add_target_property(KFMan COMPILE_FLAGS "-DDO_TPCCATRACKER_EFF_PERFORMANCE -DNonhomogeneousField -DCBM -DUSE_TIMERS") + +install(TARGETS KFMan EXPORT KFManTargets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include + ) + +install( + FILES + ${HEADERS} + DESTINATION + include + COMPONENT + Devel +) + +set(PCM_FILE_NAME libKFMan) + +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PCM_FILE_NAME}_rdict.pcm" + DESTINATION + lib + OPTIONAL +) diff --git a/AnalysisTreeInterface/InConverter.cxx b/AnalysisTreeInterface/InConverter.cxx new file mode 100644 index 0000000..646905e --- /dev/null +++ b/AnalysisTreeInterface/InConverter.cxx @@ -0,0 +1,231 @@ +#include "InConverter.h" + +//KF Particle headers +#include "KFParticle.h" +#include "KFPTrackVector.h" + +//KF Simple headers +#include "SimpleFinder.h" +#include "Constants.h" + +//c++ and std headers +#include +#include +#include + +void InConverter::InitAnalysisTree(const std::string& file_name, const std::string& tree_name) +{ + in_file_ = TFile::Open(file_name.c_str(), "read"); + config_ = (AnalysisTree::Configuration*) in_file_->Get("Configuration"); + + in_chain_ = new TChain(tree_name.c_str()); + in_chain_ -> Add(file_name.c_str()); + in_chain_ -> SetBranchAddress("KfpfTracks", &kf_tracks_); + in_chain_ -> SetBranchAddress("SimTracks", &sim_tracks_); + in_chain_ -> SetBranchAddress("RecEventHeader", &rec_event_header_); + in_chain_ -> SetBranchAddress("SimEventHeader", &sim_event_header_); + in_chain_ -> SetBranchAddress(config_->GetMatchName("KfpfTracks", "SimTracks").c_str(), &kf2sim_tracks_); + + auto branch_conf_kftr = config_->GetBranchConfig( "KfpfTracks" ); + q_field_id_ = branch_conf_kftr.GetFieldId("q"); + + par_field_id_ = branch_conf_kftr.GetFieldId("x"); // par0 + mf_field_id_ = branch_conf_kftr.GetFieldId("cx0"); // magnetic field par0 + cov_field_id_ = branch_conf_kftr.GetFieldId("cov1"); // cov matrix 0 + + passcuts_field_id_ = branch_conf_kftr.GetFieldId("pass_cuts"); + pdg_field_id_ = branch_conf_kftr.GetFieldId("mc_pdg"); + + auto branch_conf_simtr = config_->GetBranchConfig( "SimTracks" ); + mother_id_field_id_ = branch_conf_simtr.GetFieldId("mother_id"); + sim_pdg_field_id_ = branch_conf_simtr.GetFieldId("pdg"); + + if (track_cuts_ != nullptr) + track_cuts_->Init(*config_); +} + +int InConverter::GetTrackPid(const AnalysisTree::Track& rec_track) +{ + int pdg = -1; + if(is_shine_) { + pdg = rec_track.GetField(q_field_id_) > 0 ? 2212 : -211; + } + else { + pdg = rec_track.GetField(pdg_field_id_); + } + return pdg; +} + +void InConverter::FillTrack(const AnalysisTree::Track& rec_track, InputContainer& input_info) +{ + std::vector mf(kNumberOfFieldPars, 0.f); + for(int iF=0; iF(mf_field_id_+iF); + + auto cov_matrix = is_shine_ ? GetCovMatrixShine(rec_track) : GetCovMatrixCbm(rec_track); + std::vector par(kNumberOfTrackPars,0.f); + + par[kX] = rec_track.GetField(par_field_id_); + par[kY] = rec_track.GetField(par_field_id_ + 1); + par[kZ] = rec_track.GetField(par_field_id_ + 2); + par[kPx] = rec_track.GetPx(); + par[kPy] = rec_track.GetPy(); + par[kPz] = rec_track.GetPz(); + + const int pdg = GetTrackPid(rec_track); + + input_info.AddTrack(par, cov_matrix, mf, rec_track.GetField(q_field_id_), pdg, rec_track.GetId(), rec_track.GetField(passcuts_field_id_)); +} + + +InputContainer InConverter::CreateInputContainer(int iEvent) +{ + in_chain_->GetEntry(iEvent); + const int n_tracks = kf_tracks_->GetNumberOfChannels(); + std::cout << "Event # " << iEvent << " with Ntracks = " << n_tracks << std::endl; + + InputContainer input_info; + input_info.SetCuts(cuts_); + input_info.SetPV(rec_event_header_->GetVertexX(), rec_event_header_->GetVertexY(), rec_event_header_->GetVertexZ()); + + int n_good_tracks{0}; + for(int i_track=0; i_trackGetChannel(i_track); + if(!IsGoodTrack(rec_track)) continue; + FillTrack(rec_track, input_info); + n_good_tracks++; +// ======= +// const AnalysisTree::Track& rec_track = kf_tracks_->GetChannel(i_track); +// +// if (track_cuts_ != nullptr) +// if(!track_cuts_->Apply(rec_track)) +// continue; +// +// std::vector par; +// for(int iP=0; iP<3; iP++) +// par.push_back(rec_track.GetField(par_field_id_ + iP)); +// par.push_back(rec_track.GetPx()); +// par.push_back(rec_track.GetPy()); +// par.push_back(rec_track.GetPz()); +// +// std::vector mf; +// for(int iF=0; iF<10; iF++) +// mf.push_back(rec_track.GetField(mf_field_id_+iF)); +// +// int pdg = -1; +// if(is_shine_) { +// pdg = rec_track.GetField(q_field_id_) > 0 ? 2212 : -211; +// } +// else { +// pdg = rec_track.GetField(pdg_field_id_); +// } +// auto cov_matrix = is_shine_ ? GetCovMatrixShine(rec_track) : GetCovMatrixCbm(rec_track); +// +// // if(ststrack.GetField(m_pdg_field_id_)!=3122) continue; +// inputInfo.AddTrack( par, +// cov_matrix, +// mf, +// rec_track.GetField(q_field_id_), +// pdg, +// rec_track.GetId(), +// rec_track.GetField(passcuts_field_id_)); +// // ststrack.GetField(nhits_field_id_), +// // ststrack.GetField(passcuts_field_id_)); +// >>>>>>> lubynets-order + } + + std::cout << "Good tracks = " << n_good_tracks << std::endl; + return input_info; +} + +bool InConverter::IsGoodTrack(const AnalysisTree::Track& rec_track) +{ + return true; + bool is_good{false}; + + const int sim_id = kf2sim_tracks_->GetMatch(rec_track.GetId()); +// std::cout<< "sim " << sim_id << std::endl; + if (sim_id >= 0 && sim_id < sim_tracks_->GetNumberOfChannels()) { + const AnalysisTree::Track& sim_track = sim_tracks_->GetChannel(sim_id); + const int mother_id = sim_track.GetField(mother_id_field_id_); +// std::cout << "mother " << mother_id << std::endl; + + if (mother_id >= 0 && mother_id < sim_tracks_->GetNumberOfChannels() ) + { + const AnalysisTree::Track& mother_track = sim_tracks_->GetChannel(mother_id); + const int mother_pdg = mother_track.GetField(sim_pdg_field_id_); + std::cout << "mother pdg " << mother_pdg << std::endl; + + if(mother_pdg == 3122) + is_good = true; + } + } + return is_good; +} + +std::vector InConverter::GetCovMatrixCbm(const AnalysisTree::Track& track) const +{ + const double tx = track.GetField(par_field_id_+3); + const double ty = track.GetField(par_field_id_+4); + const double qp = track.GetField(par_field_id_+5); + const Int_t q = track.GetField(q_field_id_); + + //calculate covariance matrix + const double t = sqrt(1.f + tx*tx + ty*ty); + const double t3 = t*t*t; + const double dpxdtx = q/qp*(1.f+ty*ty)/t3; + const double dpxdty = -q/qp*tx*ty/t3; + const double dpxdqp = -q/(qp*qp)*tx/t; + const double dpydtx = -q/qp*tx*ty/t3; + const double dpydty = q/qp*(1.f+tx*tx)/t3; + const double dpydqp = -q/(qp*qp)*ty/t; + const double dpzdtx = -q/qp*tx/t3; + const double dpzdty = -q/qp*ty/t3; + const double dpzdqp = -q/(qp*qp*t3); + + const double F[6][5] = { {1.f, 0.f, 0.f, 0.f, 0.f}, + {0.f, 1.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, dpxdtx, dpxdty, dpxdqp}, + {0.f, 0.f, dpydtx, dpydty, dpydqp}, + {0.f, 0.f, dpzdtx, dpzdty, dpzdqp} }; + + double VFT[5][6]; + for(int i=0; i<5; i++) + for(int j=0; j<6; j++) + { + VFT[i][j] = 0; + for(int k=0; k<5; k++) + { + if (k<=i) + VFT[i][j] += track.GetField(cov_field_id_ + k + i*(i+1)/2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; + else + VFT[i][j] += track.GetField(cov_field_id_ + i + k*(k+1)/2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; + } + } + + + std::vector cov(21, 0); + for(int i=0, l=0; i<6; i++) + for(int j=0; j<=i; j++, l++) + { + cov[l] = 0; + for(int k=0; k<5; k++) + { + cov[l] += F[i][k] * VFT[k][j]; + } + } + return cov; +} + +std::vector InConverter::GetCovMatrixShine(const AnalysisTree::Track& track) const +{ + std::vector cov(21, 0.); + + for (int iCov=0; iCov<21; ++iCov) + cov[iCov] = track.GetField(cov_field_id_+iCov); + + return cov; +} diff --git a/AnalysisTreeInterface/InConverter.h b/AnalysisTreeInterface/InConverter.h new file mode 100644 index 0000000..6ceb729 --- /dev/null +++ b/AnalysisTreeInterface/InConverter.h @@ -0,0 +1,76 @@ +#ifndef AT_KFC_in_HH +#define AT_KFC_in_HH + +#include "TFile.h" +#include "TTree.h" +#include "TChain.h" + +#include "AnalysisTree/Track.h" +#include "AnalysisTree/Hit.h" +#include "AnalysisTree/Detector.h" +#include "AnalysisTree/Configuration.h" +#include "AnalysisTree/EventHeader.h" +#include "AnalysisTree/Matching.h" +#include "AnalysisTree/Cuts.h" + +#include "InputContainer.h" + +class InConverter +{ +public: + + // Constructors/Destructors --------- + InConverter() = default; + virtual ~InConverter() = default; + + void InitAnalysisTree(const std::string& file_name, const std::string& tree_name); + InputContainer CreateInputContainer(int iEvent); + + void SetIsShine(bool is=true) { is_shine_ = is; } + int GetNEvents(){return in_chain_ -> GetEntries();}; + + void SetCuts(const CutsContainer& cuts) { cuts_ = cuts; }; + void SetTrackCuts(AnalysisTree::Cuts* const cuts) { track_cuts_ = cuts; }; + +protected: + std::vector GetCovMatrixCbm(const AnalysisTree::Track& track) const; + std::vector GetCovMatrixShine(const AnalysisTree::Track& track) const; + bool IsGoodTrack(const AnalysisTree::Track& rec_track); + void FillTrack(const AnalysisTree::Track& rec_track, InputContainer& input_info); + int GetTrackPid(const AnalysisTree::Track& rec_track); + + TFile* in_file_{nullptr}; + TChain* in_chain_{nullptr}; + + AnalysisTree::TrackDetector* kf_tracks_{nullptr}; + AnalysisTree::TrackDetector* sim_tracks_{nullptr}; + AnalysisTree::Matching* kf2sim_tracks_{nullptr}; + AnalysisTree::EventHeader* rec_event_header_{nullptr}; + AnalysisTree::EventHeader* sim_event_header_{nullptr}; + AnalysisTree::Configuration* config_{nullptr}; +// <<<<<<< HEAD + +// ======= +// + AnalysisTree::Cuts* track_cuts_{nullptr}; +// +// const int nParametersKF{6}; +// >>>>>>> lubynets-order + CutsContainer cuts_; + + // field ids for input parameters + int q_field_id_{AnalysisTree::UndefValueInt}; + int pdg_field_id_{AnalysisTree::UndefValueInt}; + int par_field_id_ {AnalysisTree::UndefValueInt}; + int mf_field_id_ {AnalysisTree::UndefValueInt}; + int cov_field_id_{AnalysisTree::UndefValueInt}; + int mother_id_field_id_{AnalysisTree::UndefValueInt}; + int sim_pdg_field_id_{AnalysisTree::UndefValueInt}; + int passcuts_field_id_{AnalysisTree::UndefValueInt}; + + bool is_shine_{false}; + + +}; + +#endif diff --git a/AnalysisTreeInterface/KFManLinkDef.h b/AnalysisTreeInterface/KFManLinkDef.h new file mode 100644 index 0000000..f2d1ed9 --- /dev/null +++ b/AnalysisTreeInterface/KFManLinkDef.h @@ -0,0 +1,10 @@ +#ifdef __MAKECINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +//KFParticle +#pragma link C++ class KFPS_manager+; + +#endif diff --git a/AnalysisTreeInterface/KFPS_manager.cxx b/AnalysisTreeInterface/KFPS_manager.cxx new file mode 100644 index 0000000..17c1768 --- /dev/null +++ b/AnalysisTreeInterface/KFPS_manager.cxx @@ -0,0 +1,33 @@ +#include "KFPS_manager.h" + +void KFPS_manager::Run(int n_events) +{ + InConverter converter_in; + converter_in.SetTrackCuts(track_cuts_); + converter_in.InitAnalysisTree(in_file_name_, in_tree_name_); + converter_in.SetIsShine(is_shine_); + + OutConverter converter_out; + converter_out.SetOutFileName("KFPS_output.root"); + converter_out.InitAT(); + + std::cout << converter_in.GetNEvents() << std::endl; + + if(n_events<0 || n_events>converter_in.GetNEvents()) + n_events = converter_in.GetNEvents(); + + for(int iEvent=0; iEvent +#include + +#include "InConverter.h" +#include "OutConverter.h" +#include "SimpleFinder.h" + +class KFPS_manager +{ +public: + + void Init() {}; + void Run(int n_events=-1); + void Finish(){}; + + void SetInFileName(const std::string& name){in_file_name_ = name;}; + void SetInTreeName(const std::string& name){in_tree_name_ = name;}; + void SetIsShine(bool is=true) { is_shine_ = is; } + + void SetCuts(const CutsContainer& cuts) { cuts_ = cuts; }; + void SetTrackCuts(AnalysisTree::Cuts* const cuts) { track_cuts_ = cuts; }; + + protected: + std::string in_file_name_; + std::string in_tree_name_; + CutsContainer cuts_; + AnalysisTree::Cuts* track_cuts_{nullptr}; + + bool is_shine_{false}; + +}; +#endif \ No newline at end of file diff --git a/AnalysisTreeInterface/OutConverter.cxx b/AnalysisTreeInterface/OutConverter.cxx new file mode 100644 index 0000000..da1fbfd --- /dev/null +++ b/AnalysisTreeInterface/OutConverter.cxx @@ -0,0 +1,116 @@ +#include "OutConverter.h" + +void OutConverter::InitAT() +{ + out_file_ = TFile::Open(out_file_name_.c_str(), "recreate"); + +// ***** Lambda Candidates ******* + + AnalysisTree::BranchConfig LambdaRecoBranch("LambdaCandidates", AnalysisTree::DetType::kParticle); + + LambdaRecoBranch.AddField("chi2primpos"); + LambdaRecoBranch.AddField("chi2primneg"); + LambdaRecoBranch.AddField("distance"); + LambdaRecoBranch.AddField("cosinepos"); + LambdaRecoBranch.AddField("cosineneg"); + LambdaRecoBranch.AddField("chi2geo"); + LambdaRecoBranch.AddField("l"); + LambdaRecoBranch.AddField("ldl"); + LambdaRecoBranch.AddField ("isfrompv"); + LambdaRecoBranch.AddField("cosinetopo"); + LambdaRecoBranch.AddField("chi2topo"); + + LambdaRecoBranch.AddField("x"); + LambdaRecoBranch.AddField("y"); + LambdaRecoBranch.AddField("z"); + LambdaRecoBranch.AddField("invmass"); + LambdaRecoBranch.AddField("rapidity_lab"); + LambdaRecoBranch.AddField("rapidity_cm"); + LambdaRecoBranch.AddField("pdg"); + LambdaRecoBranch.AddField("daughter1id"); + LambdaRecoBranch.AddField("daughter2id"); + + out_config_.AddBranchConfig( LambdaRecoBranch ); + lambda_reco_ = new AnalysisTree::Particles(out_config_.GetLastId()); + + out_tree_ = new TTree("aTree", "AnalysisTree Lambda"); + out_tree_ -> Branch("LambdaCandidates", "AnalysisTree::Particles", &lambda_reco_); + out_config_.Write("Configuration"); + + x_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("x"); + y_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("y"); + z_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("z"); + mass_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("invmass"); + rap_lab_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("rapidity_lab"); + rap_cm_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("rapidity_cm"); + pdg_field_id_w_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("pdg"); + daughter1_id_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("daughter1id"); + daughter2_id_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("daughter2id"); + + chi2primpos_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("chi2primpos"); + chi2primneg_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("chi2primneg"); + distance_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("distance"); + cosinepos_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("cosinepos"); + cosineneg_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("cosineneg"); + chi2geo_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("chi2geo"); + l_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("l"); + ldl_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("ldl"); + isfrompv_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("isfrompv"); + cosinetopo_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("cosinetopo"); + chi2topo_field_id_ = out_config_.GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("chi2topo"); +} + +void OutConverter::WriteCandidates(const std::vector& canditates) +{ + lambda_reco_->ClearChannels(); + + for(const auto& candidate : canditates) + { + auto* lambdarec = lambda_reco_->AddChannel(); + lambdarec->Init(out_config_.GetBranchConfig(lambda_reco_->GetId())); + + const KFParticle& particle = candidate.GetParticle(); + float mass, masserr; + particle.GetMass(mass, masserr); + lambdarec->SetField(mass, mass_field_id_); + lambdarec->SetField(particle.DaughterIds()[0], daughter1_id_field_id_); + lambdarec->SetField(particle.DaughterIds()[1], daughter2_id_field_id_); +// std::cout << "FC\t" << particle.DaughterIds()[0] << "\t" << particle.DaughterIds()[1] << "\n"; + + lambdarec->SetField(particle.X(), x_field_id_); + lambdarec->SetField(particle.Y(), y_field_id_); + lambdarec->SetField(particle.Z(), z_field_id_); + lambdarec->SetMomentum(particle.GetPx(), particle.GetPy(), particle.GetPz()); + lambdarec->SetField( particle.GetRapidity(), rap_lab_field_id_); + lambdarec->SetField( particle.GetRapidity() - RapidityShift(12.), rap_cm_field_id_); + lambdarec->SetField( particle.GetPDG(), pdg_field_id_w_ ); + + lambdarec->SetPid( particle.GetPDG()); + lambdarec->SetMass(mass); + + lambdarec->SetField( candidate.GetChi2PrimPos(), chi2primpos_field_id_); + lambdarec->SetField( candidate.GetChi2PrimNeg(), chi2primneg_field_id_); + lambdarec->SetField( candidate.GetDistance(), distance_field_id_); + lambdarec->SetField( candidate.GetCosineDaughterPos(), cosinepos_field_id_); + lambdarec->SetField( candidate.GetCosineDaughterNeg(), cosineneg_field_id_); + lambdarec->SetField( candidate.GetChi2Geo(), chi2geo_field_id_); + lambdarec->SetField( candidate.GetL(), l_field_id_); + lambdarec->SetField( candidate.GetLdL(), ldl_field_id_); + lambdarec->SetField( candidate.GetIsFromPV(), isfrompv_field_id_); + lambdarec->SetField( candidate.GetCosineTopo(), cosinetopo_field_id_); + lambdarec->SetField( candidate.GetChi2Topo(), chi2topo_field_id_); + } + out_tree_->Fill(); +} + +void OutConverter::Finish() +{ + out_tree_->Write(); + out_file_->Close(); +} + +float OutConverter::RapidityShift(float pbeam) +{ + const float nucleonmass = 0.939; + return TMath::Log(((sqrt(nucleonmass*nucleonmass + pbeam*pbeam) + pbeam) / (sqrt(nucleonmass*nucleonmass + pbeam*pbeam) - pbeam)))/4.; +} \ No newline at end of file diff --git a/AnalysisTreeInterface/OutConverter.h b/AnalysisTreeInterface/OutConverter.h new file mode 100644 index 0000000..479ca49 --- /dev/null +++ b/AnalysisTreeInterface/OutConverter.h @@ -0,0 +1,70 @@ +#ifndef KFC_out_AT_HH +#define KFC_out_AT_HH + +#include + +#include "TFile.h" +#include "TTree.h" +#include "TChain.h" + +#include "AnalysisTree/Track.h" +#include "AnalysisTree/Hit.h" +#include "AnalysisTree/Detector.h" +#include "AnalysisTree/Configuration.h" +#include "AnalysisTree/EventHeader.h" +#include "AnalysisTree/Matching.h" + +#include "OutputContainer.h" + +class OutConverter +{ +public: + + // Constructors/Destructors --------- + OutConverter() = default; + virtual ~OutConverter() = default; + + void InitAT(); + void SetOutFileName(std::string name){out_file_name_ = name;}; + + void WriteCandidates(const std::vector& canditates); + + void Finish(); + +protected: + + float RapidityShift(float pbeam); + + std::string out_file_name_{"KFPS_output.root"}; + TFile* out_file_{nullptr}; + TTree* out_tree_{nullptr}; + + AnalysisTree::Configuration out_config_; + AnalysisTree::Particles* lambda_reco_{nullptr}; + + // field ids for selected lambda candidates kinematic parameters + int x_field_id_{-1}; + int y_field_id_{-1}; + int z_field_id_{-1}; + int mass_field_id_{-1}; + int rap_lab_field_id_{-1}; + int rap_cm_field_id_{-1}; + int pdg_field_id_w_{-1}; + int daughter1_id_field_id_{-1}; + int daughter2_id_field_id_{-1}; + + // field ids for lambda candidate cutting parameters + int chi2primpos_field_id_{-1}; + int chi2primneg_field_id_{-1}; + int distance_field_id_{-1}; + int cosinepos_field_id_{-1}; + int cosineneg_field_id_{-1}; + int chi2geo_field_id_{-1}; + int l_field_id_{-1}; + int ldl_field_id_{-1}; + int isfrompv_field_id_{-1}; + int cosinetopo_field_id_{-1}; + int chi2topo_field_id_{-1}; + +}; +#endif \ No newline at end of file diff --git a/AnalysisTreeInterface/main.cxx b/AnalysisTreeInterface/main.cxx new file mode 100644 index 0000000..2ed386a --- /dev/null +++ b/AnalysisTreeInterface/main.cxx @@ -0,0 +1,29 @@ +#include "KFPS_manager.h" + +int main(int argc, char** argv) +{ + if(argc < 2) + return 0; + + CutsContainer cuts; + cuts.CancelCuts(); + cuts.SetCutChi2PrimPos(100.); + cuts.SetCutChi2PrimNeg(100.); + cuts.SetCutDistance(0.7); + cuts.SetCutCosineDaughterPos(0.95); + cuts.SetCutCosineDaughterNeg(0.9); + cuts.SetCutChi2Geo(3.); + cuts.SetCutLDown(3.); + cuts.SetCutLdL(7.); + + std::string filename = argv[1]; + KFPS_manager man; + man.SetInFileName(filename); + man.SetInTreeName("aTree"); + man.SetIsShine(true); + man.SetCuts(cuts); + + man.Run(100); + + return 0; +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 92ccf4c..7800d61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ set(FIXTARGET TRUE CACHE BOOL "Compile for fix target geometry.") find_package(ROOT REQUIRED RIO) find_package(KFParticle QUIET) find_package(Vc QUIET) +find_package(AnalysisTree QUIET) set(EXTERNAL_DIR ${CMAKE_BINARY_DIR}/external) set(EXTERNAL_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/external) @@ -57,13 +58,16 @@ Else() include(cmake_modules/KFParticle.cmake) EndIf() -if (ROOT_FOUND) - message(STATUS "Using ROOT: ${ROOT_VERSION} <${ROOT_CONFIG}>") - include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIR} ${ROOT_INCLUDE_DIRS}) - include(${ROOT_USE_FILE}) -endif (ROOT_FOUND) +message(STATUS "Using ROOT: ${ROOT_VERSION} <${ROOT_CONFIG}>") +include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS} ${KFParticle_INCLUDE_DIR} ${Vc_INCLUDE_DIR}) +include(${ROOT_USE_FILE}) -include_directories(${CMAKE_SOURCE_DIR} ${KFParticle_INCLUDE_DIR} ${Vc_INCLUDE_DIR}) +if(AnalysisTree_FOUND) + Message("AnalysisTree found. Corresponding interface will be compiled") + add_subdirectory(AnalysisTreeInterface) +Else() + Message("AnalysisTree is not found. Corresponding interface will be compiled") +EndIf() add_subdirectory(KFSimple) add_subdirectory(Interface) -- GitLab From 121022d18ab6b84c3fcfcf4956ae983be7801e56 Mon Sep 17 00:00:00 2001 From: Viktor Date: Thu, 11 Jun 2020 16:26:33 +0200 Subject: [PATCH 02/20] refactor ConverterIn --- AnalysisTreeInterface/CMakeLists.txt | 22 ++-- AnalysisTreeInterface/ConverterIn.cpp | 117 ++++++++++++++++++ AnalysisTreeInterface/ConverterIn.h | 89 +++++++++++++ AnalysisTreeInterface/KFManLinkDef.h | 3 +- .../{KFPS_manager.cxx => Manager.cxx} | 4 +- .../{KFPS_manager.h => Manager.h} | 2 +- AnalysisTreeInterface/OutConverter.h | 4 +- AnalysisTreeInterface/main.cxx | 2 +- CMakeLists.txt | 15 +-- Interface/CMakeLists.txt | 12 +- KFSimple/CMakeLists.txt | 8 +- cmake_modules/KFParticle.cmake | 1 + cmake_modules/Vc.cmake | 21 ---- 13 files changed, 246 insertions(+), 54 deletions(-) create mode 100644 AnalysisTreeInterface/ConverterIn.cpp create mode 100644 AnalysisTreeInterface/ConverterIn.h rename AnalysisTreeInterface/{KFPS_manager.cxx => Manager.cxx} (92%) rename AnalysisTreeInterface/{KFPS_manager.h => Manager.h} (96%) delete mode 100644 cmake_modules/Vc.cmake diff --git a/AnalysisTreeInterface/CMakeLists.txt b/AnalysisTreeInterface/CMakeLists.txt index 34d7bf4..42adc9a 100644 --- a/AnalysisTreeInterface/CMakeLists.txt +++ b/AnalysisTreeInterface/CMakeLists.txt @@ -1,17 +1,25 @@ set(SOURCES - KFPS_manager.cxx - InConverter.cxx - OutConverter.cxx +# Manager.cxx +# InConverter.cxx +# OutConverter.cxx + ConverterIn.cpp ) -string(REPLACE ".cxx" ".h" HEADERS "${SOURCES}") +string(REPLACE ".cpp" ".h" HEADERS "${SOURCES}") + +include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/Interface ${CMAKE_SOURCE_DIR}/KFSimple ${AnalysisTree_INCLUDE_DIR}) + +if(PROJECT_LINK_DIRECTORIES) + include_directories(${PROJECT_INCLUDE_DIRECTORIES}) + link_directories(${PROJECT_LINK_DIRECTORIES}) +endif() add_library(KFMan SHARED ${SOURCES} G__KFMan.cxx) - + ROOT_GENERATE_DICTIONARY(G__KFMan ${HEADERS} LINKDEF KFManLinkDef.h OPTIONS "-DDO_TPCCATRACKER_EFF_PERFORMANCE" "-DNonhomogeneousField" "-DCBM" "-DUSE_TIMERS") -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(KFMan ${ROOT_LIBRARIES} AnalysisTreeBase AnalysisTreeInfra KFParticle KFParticleInterface KFParticleSimple) +target_link_libraries(KFMan ${ROOT_LIBRARIES} AnalysisTreeBase AnalysisTreeInfra KFParticleInterface KFParticleSimple KFParticle) +add_dependencies(KFMan KFParticleSimple) add_target_property(KFMan COMPILE_FLAGS "-DDO_TPCCATRACKER_EFF_PERFORMANCE -DNonhomogeneousField -DCBM -DUSE_TIMERS") install(TARGETS KFMan EXPORT KFManTargets diff --git a/AnalysisTreeInterface/ConverterIn.cpp b/AnalysisTreeInterface/ConverterIn.cpp new file mode 100644 index 0000000..6c9312f --- /dev/null +++ b/AnalysisTreeInterface/ConverterIn.cpp @@ -0,0 +1,117 @@ +// +// Created by vklochkov on 6/11/20. +// + +#include +#include +#include "ConverterIn.h" + + +InputContainer ConverterIn::CreateInputContainer() +{ + const int n_tracks = kf_tracks_->GetNumberOfChannels(); + std::cout << " Ntracks = " << n_tracks << std::endl; + + InputContainer input_info; + input_info.SetCuts(cuts_); + input_info.SetPV(rec_event_header_->GetVertexX(), rec_event_header_->GetVertexY(), rec_event_header_->GetVertexZ()); + + int n_good_tracks{0}; + for(int i_track=0; i_trackGetChannel(i_track); +// if(!IsGoodTrack(rec_track)) continue; + FillParticle(rec_track, input_info); + n_good_tracks++; + } + + std::cout << "Good tracks = " << n_good_tracks << std::endl; + return input_info; +} + + +void ConverterIn::FillParticle(const AnalysisTree::Particle& rec_particle, InputContainer& input_info) +{ + std::vector mf(kNumberOfFieldPars, 0.f); + for(int iF=0; iF(mf_field_id_+iF); + + auto cov_matrix = is_shine_ ? GetCovMatrixShine(rec_particle) : GetCovMatrixCbm(rec_particle); + std::vector par(kNumberOfTrackPars,0.f); + + par[kX] = rec_particle.GetField(par_field_id_); + par[kY] = rec_particle.GetField(par_field_id_ + 1); + par[kZ] = rec_particle.GetField(par_field_id_ + 2); + par[kPx] = rec_particle.GetPx(); + par[kPy] = rec_particle.GetPy(); + par[kPz] = rec_particle.GetPz(); + + const int pdg = rec_particle.GetPid(); + + input_info.AddTrack(par, cov_matrix, mf, rec_particle.GetField(q_field_id_), pdg, rec_particle.GetId(), rec_particle.GetField(passcuts_field_id_)); +} + +std::vector ConverterIn::GetCovMatrixCbm(const AnalysisTree::Particle& particle) const +{ + const auto tx = particle.GetField(par_field_id_+3); + const auto ty = particle.GetField(par_field_id_+4); + const auto qp = particle.GetField(par_field_id_+5); + const auto q = particle.GetField(q_field_id_); + + //calculate covariance matrix + const auto t = sqrt(1.f + tx*tx + ty*ty); + const auto t3 = t*t*t; + const auto dpxdtx = q/qp*(1.f+ty*ty)/t3; + const auto dpxdty = -q/qp*tx*ty/t3; + const auto dpxdqp = -q/(qp*qp)*tx/t; + const auto dpydtx = -q/qp*tx*ty/t3; + const auto dpydty = q/qp*(1.f+tx*tx)/t3; + const auto dpydqp = -q/(qp*qp)*ty/t; + const auto dpzdtx = -q/qp*tx/t3; + const auto dpzdty = -q/qp*ty/t3; + const auto dpzdqp = -q/(qp*qp*t3); + + const auto F[6][5] = { {1.f, 0.f, 0.f, 0.f, 0.f}, + {0.f, 1.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, dpxdtx, dpxdty, dpxdqp}, + {0.f, 0.f, dpydtx, dpydty, dpydqp}, + {0.f, 0.f, dpzdtx, dpzdty, dpzdqp} }; + + float VFT[5][6]; + for(int i=0; i<5; i++) + for(int j=0; j<6; j++) + { + VFT[i][j] = 0; + for(int k=0; k<5; k++) + { + if (k<=i) + VFT[i][j] += particle.GetField(cov_field_id_ + k + i*(i+1)/2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; + else + VFT[i][j] += particle.GetField(cov_field_id_ + i + k*(k+1)/2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; + } + } + + + std::vector cov(21, 0); + for(int i=0, l=0; i<6; i++) + for(int j=0; j<=i; j++, l++) + { + cov[l] = 0; + for(int k=0; k<5; k++) + { + cov[l] += F[i][k] * VFT[k][j]; + } + } + return cov; +} + +std::vector ConverterIn::GetCovMatrixShine(const AnalysisTree::Particle& particle) const +{ + std::vector cov(21, 0.); + + for (int iCov=0; iCov<21; ++iCov) + cov[iCov] = particle.GetField(cov_field_id_+iCov); + + return cov; +} \ No newline at end of file diff --git a/AnalysisTreeInterface/ConverterIn.h b/AnalysisTreeInterface/ConverterIn.h new file mode 100644 index 0000000..13a008b --- /dev/null +++ b/AnalysisTreeInterface/ConverterIn.h @@ -0,0 +1,89 @@ +#ifndef KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTERIN_H_ +#define KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTERIN_H_ + +#include +#include +#include "AnalysisTree/FillTask.h" + +class ConverterIn : public AnalysisTree::FillTask { + + enum eInputBranches { + kRecEventHeader = 0, + kSimEventHeader, + kKfpfTracks, + kSimTracks, + kNumberOfInputBranches + }; + + public: + ConverterIn(){ // Use default names for the input branches + in_branches_.resize(kNumberOfInputBranches); + in_branches_[kRecEventHeader] = "RecEventHeader"; + in_branches_[kSimEventHeader] = "RecEventHeader"; + in_branches_[kKfpfTracks] = "KfpfTracks"; + in_branches_[kSimTracks] = "SimTracks"; + } + ~ConverterIn() = default; + + void Init(std::map& branches) override { + rec_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kRecEventHeader])->second; + sim_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kSimEventHeader])->second; + kf_tracks_ = (AnalysisTree::Particles*) branches.find(in_branches_[kKfpfTracks])->second; + sim_tracks_ = (AnalysisTree::Particles*) branches.find(in_branches_[kSimTracks])->second; + kf2sim_tracks_ = (AnalysisTree::Matching*) branches.find( + config_->GetMatchName(in_branches_[kKfpfTracks], in_branches_[kSimTracks]))->second; + + auto branch_conf_kftr = config_->GetBranchConfig(in_branches_[kKfpfTracks]); + + q_field_id_ = branch_conf_kftr.GetFieldId("q"); + par_field_id_ = branch_conf_kftr.GetFieldId("x"); // par0 + mf_field_id_ = branch_conf_kftr.GetFieldId("cx0"); // magnetic field par0 + cov_field_id_ = branch_conf_kftr.GetFieldId("cov1"); // cov matrix 0 + passcuts_field_id_ = branch_conf_kftr.GetFieldId("pass_cuts"); + pdg_field_id_ = branch_conf_kftr.GetFieldId("mc_pdg"); + + auto branch_conf_simtr = config_->GetBranchConfig(in_branches_[kSimTracks]); + mother_id_field_id_ = branch_conf_simtr.GetFieldId("mother_id"); + sim_pdg_field_id_ = branch_conf_simtr.GetFieldId("pdg"); + + if (track_cuts_ != nullptr) + track_cuts_->Init(*config_); + } + + void Exec() override { + + } + + void Finish() override {}; + + protected: + + std::vector GetCovMatrixCbm(const AnalysisTree::Particle&) const; + std::vector GetCovMatrixShine(const AnalysisTree::Particle&) const; + void FillParticle(const AnalysisTree::Particle&, InputContainer&); + InputContainer CreateInputContainer(); + + AnalysisTree::Particles* kf_tracks_{nullptr}; + AnalysisTree::Particles* sim_tracks_{nullptr}; + AnalysisTree::Matching* kf2sim_tracks_{nullptr}; + AnalysisTree::EventHeader* rec_event_header_{nullptr}; + AnalysisTree::EventHeader* sim_event_header_{nullptr}; + AnalysisTree::Cuts* track_cuts_{nullptr}; + + CutsContainer cuts_; + + // field ids for input parameters + int q_field_id_{AnalysisTree::UndefValueInt}; + int pdg_field_id_{AnalysisTree::UndefValueInt}; + int par_field_id_ {AnalysisTree::UndefValueInt}; + int mf_field_id_ {AnalysisTree::UndefValueInt}; + int cov_field_id_{AnalysisTree::UndefValueInt}; + int mother_id_field_id_{AnalysisTree::UndefValueInt}; + int sim_pdg_field_id_{AnalysisTree::UndefValueInt}; + int passcuts_field_id_{AnalysisTree::UndefValueInt}; + + bool is_shine_{false}; + +}; + +#endif //KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTERIN_H_ diff --git a/AnalysisTreeInterface/KFManLinkDef.h b/AnalysisTreeInterface/KFManLinkDef.h index f2d1ed9..483ed69 100644 --- a/AnalysisTreeInterface/KFManLinkDef.h +++ b/AnalysisTreeInterface/KFManLinkDef.h @@ -4,7 +4,8 @@ #pragma link off all classes; #pragma link off all functions; -//KFParticle #pragma link C++ class KFPS_manager+; +#pragma link C++ class InConverter+; +#pragma link C++ class OutConverter+; #endif diff --git a/AnalysisTreeInterface/KFPS_manager.cxx b/AnalysisTreeInterface/Manager.cxx similarity index 92% rename from AnalysisTreeInterface/KFPS_manager.cxx rename to AnalysisTreeInterface/Manager.cxx index 17c1768..3a8ea0b 100644 --- a/AnalysisTreeInterface/KFPS_manager.cxx +++ b/AnalysisTreeInterface/Manager.cxx @@ -1,6 +1,6 @@ -#include "KFPS_manager.h" +#include "Manager.h" -void KFPS_manager::Run(int n_events) +void Manager::Run(int n_events) { InConverter converter_in; converter_in.SetTrackCuts(track_cuts_); diff --git a/AnalysisTreeInterface/KFPS_manager.h b/AnalysisTreeInterface/Manager.h similarity index 96% rename from AnalysisTreeInterface/KFPS_manager.h rename to AnalysisTreeInterface/Manager.h index a7516ba..fd02521 100644 --- a/AnalysisTreeInterface/KFPS_manager.h +++ b/AnalysisTreeInterface/Manager.h @@ -8,7 +8,7 @@ #include "OutConverter.h" #include "SimpleFinder.h" -class KFPS_manager +class Manager { public: diff --git a/AnalysisTreeInterface/OutConverter.h b/AnalysisTreeInterface/OutConverter.h index 479ca49..a3257c7 100644 --- a/AnalysisTreeInterface/OutConverter.h +++ b/AnalysisTreeInterface/OutConverter.h @@ -2,6 +2,7 @@ #define KFC_out_AT_HH #include +#include #include "TFile.h" #include "TTree.h" @@ -25,8 +26,7 @@ public: virtual ~OutConverter() = default; void InitAT(); - void SetOutFileName(std::string name){out_file_name_ = name;}; - + void SetOutFileName(std::string name){out_file_name_ = std::move(name);}; void WriteCandidates(const std::vector& canditates); void Finish(); diff --git a/AnalysisTreeInterface/main.cxx b/AnalysisTreeInterface/main.cxx index 2ed386a..3745f4a 100644 --- a/AnalysisTreeInterface/main.cxx +++ b/AnalysisTreeInterface/main.cxx @@ -1,4 +1,4 @@ -#include "KFPS_manager.h" +#include "Manager.h" int main(int argc, char** argv) { diff --git a/CMakeLists.txt b/CMakeLists.txt index 7800d61..0d406d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,28 +38,25 @@ set(FIXTARGET TRUE CACHE BOOL "Compile for fix target geometry.") find_package(ROOT REQUIRED RIO) find_package(KFParticle QUIET) -find_package(Vc QUIET) find_package(AnalysisTree QUIET) set(EXTERNAL_DIR ${CMAKE_BINARY_DIR}/external) set(EXTERNAL_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/external) -if(Vc_FOUND) - Message("Vc found") -Else() - Message("Vc is not found. It will be installed as external package") - include(cmake_modules/Vc.cmake) -EndIf() - if(KFParticle_FOUND) Message("KFParticle found") + find_package(Vc REQUIRED) + include_directories(${KFParticle_INCLUDE_DIR} ${Vc_INCLUDE_DIR}) Else() Message("KFParticle is not found. It will be installed as external package") include(cmake_modules/KFParticle.cmake) + include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS} ${PROJECT_INCLUDE_DIRECTORIES}) EndIf() +message(STATUS "ROJECT_INCLUDE_DIRECTORIES ${PROJECT_INCLUDE_DIRECTORIES}") + message(STATUS "Using ROOT: ${ROOT_VERSION} <${ROOT_CONFIG}>") -include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS} ${KFParticle_INCLUDE_DIR} ${Vc_INCLUDE_DIR}) +include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS}) include(${ROOT_USE_FILE}) if(AnalysisTree_FOUND) diff --git a/Interface/CMakeLists.txt b/Interface/CMakeLists.txt index 0a856ed..d86161e 100644 --- a/Interface/CMakeLists.txt +++ b/Interface/CMakeLists.txt @@ -6,15 +6,17 @@ set(SOURCES string(REPLACE ".cxx" ".h" HEADERS "${SOURCES}") include_directories(${CMAKE_SOURCE_DIR}/Interface ) -link_directories(${PROJECT_LINK_DIRECTORIES}) +include_directories(${PROJECT_INCLUDE_DIRECTORIES}) +link_directories(${PROJECT_LINK_DIRECTORIES}) add_library(KFParticleInterface SHARED ${SOURCES} G__KFParticleInterface.cxx) -if(ROOT_FOUND) - ROOT_GENERATE_DICTIONARY(G__KFParticleInterface ${HEADERS} LINKDEF KFParticleInterfaceLinkDef.h OPTIONS "-DDO_TPCCATRACKER_EFF_PERFORMANCE" "-DNonhomogeneousField" "-DCBM" "-DUSE_TIMERS") +if(PROJECT_DEPENDENCIES) add_dependencies(KFParticleInterface ${PROJECT_DEPENDENCIES}) - target_link_libraries(KFParticleInterface ${ROOT_LIBRARIES} KFParticle ${Vc_LIBRARIES}) -endif(ROOT_FOUND) +endif() + +ROOT_GENERATE_DICTIONARY(G__KFParticleInterface ${HEADERS} LINKDEF KFParticleInterfaceLinkDef.h OPTIONS "-DDO_TPCCATRACKER_EFF_PERFORMANCE" "-DNonhomogeneousField" "-DCBM" "-DUSE_TIMERS") +target_link_libraries(KFParticleInterface ${ROOT_LIBRARIES} KFParticle ${Vc_LIBRARIES}) add_target_property(KFParticleInterface COMPILE_FLAGS "-DDO_TPCCATRACKER_EFF_PERFORMANCE -DNonhomogeneousField -DCBM -DUSE_TIMERS") diff --git a/KFSimple/CMakeLists.txt b/KFSimple/CMakeLists.txt index f89a245..1b944f5 100644 --- a/KFSimple/CMakeLists.txt +++ b/KFSimple/CMakeLists.txt @@ -10,11 +10,9 @@ link_directories(${PROJECT_LINK_DIRECTORIES}) add_library(KFParticleSimple SHARED ${SOURCES} G__KFParticleSimple.cxx) -if(ROOT_FOUND) - ROOT_GENERATE_DICTIONARY(G__KFParticleSimple ${HEADERS} LINKDEF KFSimpleLinkDef.h OPTIONS "-DDO_TPCCATRACKER_EFF_PERFORMANCE" "-DNonhomogeneousField" "-DCBM" "-DUSE_TIMERS") - add_dependencies(KFParticleSimple KFParticleInterface) - target_link_libraries(KFParticleSimple ${ROOT_LIBRARIES} KFParticle ${Vc_LIBRARIES} KFParticleInterface) -endif(ROOT_FOUND) +ROOT_GENERATE_DICTIONARY(G__KFParticleSimple ${HEADERS} LINKDEF KFSimpleLinkDef.h OPTIONS "-DDO_TPCCATRACKER_EFF_PERFORMANCE" "-DNonhomogeneousField" "-DCBM" "-DUSE_TIMERS") +add_dependencies(KFParticleSimple KFParticleInterface) +target_link_libraries(KFParticleSimple ${ROOT_LIBRARIES} KFParticle KFParticleInterface) add_target_property(KFParticleSimple COMPILE_FLAGS "-DDO_TPCCATRACKER_EFF_PERFORMANCE -DNonhomogeneousField -DCBM -DUSE_TIMERS") diff --git a/cmake_modules/KFParticle.cmake b/cmake_modules/KFParticle.cmake index ae4dc04..b3039c3 100644 --- a/cmake_modules/KFParticle.cmake +++ b/cmake_modules/KFParticle.cmake @@ -10,6 +10,7 @@ ExternalProject_Add(KFParticle_Ext BINARY_DIR "${EXTERNAL_DIR}/KFParticle_build" INSTALL_DIR "${KFParticle_INSTALL_DIR}" CMAKE_ARGS + "-DEXTERNAL_INSTALL_DIR=${KFParticle_INSTALL_DIR}" "-DCMAKE_INSTALL_PREFIX=${KFParticle_INSTALL_DIR}" "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" diff --git a/cmake_modules/Vc.cmake b/cmake_modules/Vc.cmake deleted file mode 100644 index 0e74b70..0000000 --- a/cmake_modules/Vc.cmake +++ /dev/null @@ -1,21 +0,0 @@ -set(Vc_INSTALL_DIR ${EXTERNAL_INSTALL_DIR}) -set(Vc_INCLUDE_DIR ${Vc_INSTALL_DIR}/include) -set(Vc_LIBRARY_DIR ${Vc_INSTALL_DIR}/lib) - -ExternalProject_Add(Vc_Ext - GIT_REPOSITORY "https://github.com/VcDevel/Vc" - GIT_TAG "1.4.1" - UPDATE_DISCONNECTED ${UPDATE_DISCONNECTED} - SOURCE_DIR "${EXTERNAL_DIR}/Vc_src" - BINARY_DIR "${EXTERNAL_DIR}/Vc_build" - INSTALL_DIR "${Vc_INSTALL_DIR}" - CMAKE_ARGS - "-DCMAKE_INSTALL_PREFIX=${Vc_INSTALL_DIR}" - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" - "-DBUILD_TESTING=OFF" - ) - -list(APPEND PROJECT_DEPENDENCIES Vc_Ext) -list(APPEND PROJECT_LINK_DIRECTORIES ${Vc_LIBRARY_DIR}) -list(APPEND PROJECT_INCLUDE_DIRECTORIES ${Vc_INCLUDE_DIR}) \ No newline at end of file -- GitLab From 2229b9277977e8a0c733ec966ea25b4d0046766a Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 15 Jun 2020 15:35:34 +0200 Subject: [PATCH 03/20] use AnalysisTree base classes --- AnalysisTreeInterface/CMakeLists.txt | 7 +- AnalysisTreeInterface/ConverterIn.cpp | 101 +++++++++++------------- AnalysisTreeInterface/ConverterIn.h | 16 ++-- AnalysisTreeInterface/ConverterOut.cpp | 99 +++++++++++++++++++++++ AnalysisTreeInterface/ConverterOut.h | 48 +++++++++++ AnalysisTreeInterface/KFManLinkDef.h | 6 +- AnalysisTreeInterface/PFTaskManager.cpp | 29 +++++++ AnalysisTreeInterface/PFTaskManager.h | 33 ++++++++ 8 files changed, 272 insertions(+), 67 deletions(-) create mode 100644 AnalysisTreeInterface/ConverterOut.cpp create mode 100644 AnalysisTreeInterface/ConverterOut.h create mode 100644 AnalysisTreeInterface/PFTaskManager.cpp create mode 100644 AnalysisTreeInterface/PFTaskManager.h diff --git a/AnalysisTreeInterface/CMakeLists.txt b/AnalysisTreeInterface/CMakeLists.txt index 42adc9a..4a68c54 100644 --- a/AnalysisTreeInterface/CMakeLists.txt +++ b/AnalysisTreeInterface/CMakeLists.txt @@ -1,8 +1,7 @@ set(SOURCES -# Manager.cxx -# InConverter.cxx -# OutConverter.cxx - ConverterIn.cpp + ConverterIn.cpp + ConverterOut.cpp + PFTaskManager.cpp ) string(REPLACE ".cpp" ".h" HEADERS "${SOURCES}") diff --git a/AnalysisTreeInterface/ConverterIn.cpp b/AnalysisTreeInterface/ConverterIn.cpp index 6c9312f..d799337 100644 --- a/AnalysisTreeInterface/ConverterIn.cpp +++ b/AnalysisTreeInterface/ConverterIn.cpp @@ -6,36 +6,30 @@ #include #include "ConverterIn.h" - -InputContainer ConverterIn::CreateInputContainer() -{ +void ConverterIn::Exec() { const int n_tracks = kf_tracks_->GetNumberOfChannels(); std::cout << " Ntracks = " << n_tracks << std::endl; - InputContainer input_info; - input_info.SetCuts(cuts_); - input_info.SetPV(rec_event_header_->GetVertexX(), rec_event_header_->GetVertexY(), rec_event_header_->GetVertexZ()); + input_container_.SetCuts(cuts_); + input_container_.SetPV(rec_event_header_->GetVertexX(), rec_event_header_->GetVertexY(), rec_event_header_->GetVertexZ()); int n_good_tracks{0}; - for(int i_track=0; i_trackGetChannel(i_track); // if(!IsGoodTrack(rec_track)) continue; - FillParticle(rec_track, input_info); + FillParticle(rec_track, input_container_); n_good_tracks++; } std::cout << "Good tracks = " << n_good_tracks << std::endl; - return input_info; } - void ConverterIn::FillParticle(const AnalysisTree::Particle& rec_particle, InputContainer& input_info) { std::vector mf(kNumberOfFieldPars, 0.f); - for(int iF=0; iF(mf_field_id_+iF); - + } auto cov_matrix = is_shine_ ? GetCovMatrixShine(rec_particle) : GetCovMatrixCbm(rec_particle); std::vector par(kNumberOfTrackPars,0.f); @@ -51,58 +45,55 @@ void ConverterIn::FillParticle(const AnalysisTree::Particle& rec_particle, Input input_info.AddTrack(par, cov_matrix, mf, rec_particle.GetField(q_field_id_), pdg, rec_particle.GetId(), rec_particle.GetField(passcuts_field_id_)); } -std::vector ConverterIn::GetCovMatrixCbm(const AnalysisTree::Particle& particle) const -{ - const auto tx = particle.GetField(par_field_id_+3); - const auto ty = particle.GetField(par_field_id_+4); - const auto qp = particle.GetField(par_field_id_+5); +std::vector ConverterIn::GetCovMatrixCbm(const AnalysisTree::Particle& particle) const { + const auto tx = particle.GetField(par_field_id_ + 3); + const auto ty = particle.GetField(par_field_id_ + 4); + const auto qp = particle.GetField(par_field_id_ + 5); const auto q = particle.GetField(q_field_id_); //calculate covariance matrix - const auto t = sqrt(1.f + tx*tx + ty*ty); - const auto t3 = t*t*t; - const auto dpxdtx = q/qp*(1.f+ty*ty)/t3; - const auto dpxdty = -q/qp*tx*ty/t3; - const auto dpxdqp = -q/(qp*qp)*tx/t; - const auto dpydtx = -q/qp*tx*ty/t3; - const auto dpydty = q/qp*(1.f+tx*tx)/t3; - const auto dpydqp = -q/(qp*qp)*ty/t; - const auto dpzdtx = -q/qp*tx/t3; - const auto dpzdty = -q/qp*ty/t3; - const auto dpzdqp = -q/(qp*qp*t3); - - const auto F[6][5] = { {1.f, 0.f, 0.f, 0.f, 0.f}, - {0.f, 1.f, 0.f, 0.f, 0.f}, - {0.f, 0.f, 0.f, 0.f, 0.f}, - {0.f, 0.f, dpxdtx, dpxdty, dpxdqp}, - {0.f, 0.f, dpydtx, dpydty, dpydqp}, - {0.f, 0.f, dpzdtx, dpzdty, dpzdqp} }; - - float VFT[5][6]; - for(int i=0; i<5; i++) - for(int j=0; j<6; j++) - { + const auto t = sqrt(1.f + tx * tx + ty * ty); + const auto t3 = t * t * t; + const auto dpxdtx = q / qp * (1.f + ty * ty) / t3; + const auto dpxdty = -q / qp * tx * ty / t3; + const auto dpxdqp = -q / (qp * qp) * tx / t; + const auto dpydtx = -q / qp * tx * ty / t3; + const auto dpydty = q / qp * (1.f + tx * tx) / t3; + const auto dpydqp = -q / (qp * qp) * ty / t; + const auto dpzdtx = -q / qp * tx / t3; + const auto dpzdty = -q / qp * ty / t3; + const auto dpzdqp = -q / (qp * qp * t3); + + const float F[kNumberOfTrackPars][5] = {{1.f, 0.f, 0.f, 0.f, 0.f}, + {0.f, 1.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, 0.f, 0.f, 0.f}, + {0.f, 0.f, dpxdtx, dpxdty, dpxdqp}, + {0.f, 0.f, dpydtx, dpydty, dpydqp}, + {0.f, 0.f, dpzdtx, dpzdty, dpzdqp}}; + + float VFT[5][kNumberOfTrackPars]; + for(int i = 0; i < 5; i++){ + for(int j = 0; j < kNumberOfTrackPars; j++) { VFT[i][j] = 0; - for(int k=0; k<5; k++) - { - if (k<=i) - VFT[i][j] += particle.GetField(cov_field_id_ + k + i*(i+1)/2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; - else - VFT[i][j] += particle.GetField(cov_field_id_ + i + k*(k+1)/2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; + for(int k = 0; k < 5; k++) { + VFT[i][j] += particle.GetField(cov_field_id_ + k + i * (std::max(i, k) + 1) / 2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; +// if(k <= i) +// VFT[i][j] += particle.GetField(cov_field_id_ + k + i * (i + 1) / 2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; +// else +// VFT[i][j] += particle.GetField(cov_field_id_ + i + k * (k + 1) / 2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; } } - + } std::vector cov(21, 0); - for(int i=0, l=0; i<6; i++) - for(int j=0; j<=i; j++, l++) - { + for(int i=0, l=0; i ConverterIn::GetCovMatrixShine(const AnalysisTree::Particle& cov[iCov] = particle.GetField(cov_field_id_+iCov); return cov; -} \ No newline at end of file +} + + diff --git a/AnalysisTreeInterface/ConverterIn.h b/AnalysisTreeInterface/ConverterIn.h index 13a008b..4e5301b 100644 --- a/AnalysisTreeInterface/ConverterIn.h +++ b/AnalysisTreeInterface/ConverterIn.h @@ -5,6 +5,8 @@ #include #include "AnalysisTree/FillTask.h" +#include "Interface/InputContainer.h" + class ConverterIn : public AnalysisTree::FillTask { enum eInputBranches { @@ -23,7 +25,7 @@ class ConverterIn : public AnalysisTree::FillTask { in_branches_[kKfpfTracks] = "KfpfTracks"; in_branches_[kSimTracks] = "SimTracks"; } - ~ConverterIn() = default; + virtual ~ConverterIn() = default; void Init(std::map& branches) override { rec_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kRecEventHeader])->second; @@ -46,22 +48,23 @@ class ConverterIn : public AnalysisTree::FillTask { mother_id_field_id_ = branch_conf_simtr.GetFieldId("mother_id"); sim_pdg_field_id_ = branch_conf_simtr.GetFieldId("pdg"); - if (track_cuts_ != nullptr) + if (track_cuts_){ track_cuts_->Init(*config_); + } } - void Exec() override { - - } + void Exec() override; void Finish() override {}; + const CutsContainer& GetCuts() const { return cuts_; } + const InputContainer& GetInputContainer() const { return input_container_; } + protected: std::vector GetCovMatrixCbm(const AnalysisTree::Particle&) const; std::vector GetCovMatrixShine(const AnalysisTree::Particle&) const; void FillParticle(const AnalysisTree::Particle&, InputContainer&); - InputContainer CreateInputContainer(); AnalysisTree::Particles* kf_tracks_{nullptr}; AnalysisTree::Particles* sim_tracks_{nullptr}; @@ -71,6 +74,7 @@ class ConverterIn : public AnalysisTree::FillTask { AnalysisTree::Cuts* track_cuts_{nullptr}; CutsContainer cuts_; + InputContainer input_container_; // field ids for input parameters int q_field_id_{AnalysisTree::UndefValueInt}; diff --git a/AnalysisTreeInterface/ConverterOut.cpp b/AnalysisTreeInterface/ConverterOut.cpp new file mode 100644 index 0000000..d1564f0 --- /dev/null +++ b/AnalysisTreeInterface/ConverterOut.cpp @@ -0,0 +1,99 @@ +#include "ConverterOut.h" + + +void ConverterOut::Exec() +{ + lambda_reco_->ClearChannels(); + + for(const auto& candidate : canditates_) + { + auto* lambdarec = lambda_reco_->AddChannel(); + lambdarec->Init(out_config_->GetBranchConfig(lambda_reco_->GetId())); + + const KFParticle& particle = candidate.GetParticle(); + float mass, masserr; + particle.GetMass(mass, masserr); + lambdarec->SetField(mass, mass_field_id_); + lambdarec->SetField(particle.DaughterIds()[0], daughter1_id_field_id_); + lambdarec->SetField(particle.DaughterIds()[1], daughter2_id_field_id_); +// std::cout << "FC\t" << particle.DaughterIds()[0] << "\t" << particle.DaughterIds()[1] << "\n"; + + lambdarec->SetField(particle.X(), x_field_id_); + lambdarec->SetField(particle.Y(), y_field_id_); + lambdarec->SetField(particle.Z(), z_field_id_); + lambdarec->SetMomentum(particle.GetPx(), particle.GetPy(), particle.GetPz()); + lambdarec->SetField( particle.GetRapidity(), rap_lab_field_id_); + lambdarec->SetField( particle.GetRapidity() - data_header_->GetBeamRapidity(), rap_cm_field_id_); + lambdarec->SetField( particle.GetPDG(), pdg_field_id_w_ ); + + lambdarec->SetPid( particle.GetPDG()); + lambdarec->SetMass(mass); + + lambdarec->SetField( candidate.GetChi2PrimPos(), chi2primpos_field_id_); + lambdarec->SetField( candidate.GetChi2PrimNeg(), chi2primneg_field_id_); + lambdarec->SetField( candidate.GetDistance(), distance_field_id_); + lambdarec->SetField( candidate.GetCosineDaughterPos(), cosinepos_field_id_); + lambdarec->SetField( candidate.GetCosineDaughterNeg(), cosineneg_field_id_); + lambdarec->SetField( candidate.GetChi2Geo(), chi2geo_field_id_); + lambdarec->SetField( candidate.GetL(), l_field_id_); + lambdarec->SetField( candidate.GetLdL(), ldl_field_id_); + lambdarec->SetField( candidate.GetIsFromPV(), isfrompv_field_id_); + lambdarec->SetField( candidate.GetCosineTopo(), cosinetopo_field_id_); + lambdarec->SetField( candidate.GetChi2Topo(), chi2topo_field_id_); + } + out_tree_->Fill(); +} + + +void ConverterOut::Init(std::map& branches) +{ + AnalysisTree::BranchConfig LambdaRecoBranch("LambdaCandidates", AnalysisTree::DetType::kParticle); + + LambdaRecoBranch.AddField("chi2primpos"); + LambdaRecoBranch.AddField("chi2primneg"); + LambdaRecoBranch.AddField("distance"); + LambdaRecoBranch.AddField("cosinepos"); + LambdaRecoBranch.AddField("cosineneg"); + LambdaRecoBranch.AddField("chi2geo"); + LambdaRecoBranch.AddField("l"); + LambdaRecoBranch.AddField("ldl"); + LambdaRecoBranch.AddField ("isfrompv"); + LambdaRecoBranch.AddField("cosinetopo"); + LambdaRecoBranch.AddField("chi2topo"); + + LambdaRecoBranch.AddField("x"); + LambdaRecoBranch.AddField("y"); + LambdaRecoBranch.AddField("z"); + LambdaRecoBranch.AddField("invmass"); + LambdaRecoBranch.AddField("rapidity_lab"); + LambdaRecoBranch.AddField("rapidity_cm"); + LambdaRecoBranch.AddField("pdg"); + LambdaRecoBranch.AddField("daughter1id"); + LambdaRecoBranch.AddField("daughter2id"); + + out_config_->AddBranchConfig( LambdaRecoBranch ); + lambda_reco_ = new AnalysisTree::Particles(out_config_->GetLastId()); + out_tree_ -> Branch("LambdaCandidates", "AnalysisTree::Particles", &lambda_reco_); + + x_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("x"); + y_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("y"); + z_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("z"); + mass_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("invmass"); + rap_lab_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("rapidity_lab"); + rap_cm_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("rapidity_cm"); + pdg_field_id_w_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("pdg"); + daughter1_id_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("daughter1id"); + daughter2_id_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("daughter2id"); + + chi2primpos_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("chi2primpos"); + chi2primneg_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("chi2primneg"); + distance_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("distance"); + cosinepos_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("cosinepos"); + cosineneg_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("cosineneg"); + chi2geo_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("chi2geo"); + l_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("l"); + ldl_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("ldl"); + isfrompv_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("isfrompv"); + cosinetopo_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("cosinetopo"); + chi2topo_field_id_ = out_config_->GetBranchConfig( lambda_reco_->GetId() ).GetFieldId("chi2topo"); +} diff --git a/AnalysisTreeInterface/ConverterOut.h b/AnalysisTreeInterface/ConverterOut.h new file mode 100644 index 0000000..29ff68c --- /dev/null +++ b/AnalysisTreeInterface/ConverterOut.h @@ -0,0 +1,48 @@ +#ifndef KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTEROUT_H_ +#define KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTEROUT_H_ + +#include +#include "AnalysisTree/FillTask.h" + +class ConverterOut : public AnalysisTree::FillTask { + public: + ConverterOut() = default; + virtual ~ConverterOut() = default; + + void Init(std::map& branches) override; + void Exec() override; + void Finish() override {} + + void SetCandidates(const std::vector& canditates) { canditates_ = canditates; } + + protected: + + AnalysisTree::Particles* lambda_reco_{nullptr}; + std::vector canditates_; + + // field ids for selected lambda candidates kinematic parameters + int x_field_id_{-1}; + int y_field_id_{-1}; + int z_field_id_{-1}; + int mass_field_id_{-1}; + int rap_lab_field_id_{-1}; + int rap_cm_field_id_{-1}; + int pdg_field_id_w_{-1}; + int daughter1_id_field_id_{-1}; + int daughter2_id_field_id_{-1}; + + // field ids for lambda candidate cutting parameters + int chi2primpos_field_id_{-1}; + int chi2primneg_field_id_{-1}; + int distance_field_id_{-1}; + int cosinepos_field_id_{-1}; + int cosineneg_field_id_{-1}; + int chi2geo_field_id_{-1}; + int l_field_id_{-1}; + int ldl_field_id_{-1}; + int isfrompv_field_id_{-1}; + int cosinetopo_field_id_{-1}; + int chi2topo_field_id_{-1}; +}; + +#endif //KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTEROUT_H_ diff --git a/AnalysisTreeInterface/KFManLinkDef.h b/AnalysisTreeInterface/KFManLinkDef.h index 483ed69..306dd62 100644 --- a/AnalysisTreeInterface/KFManLinkDef.h +++ b/AnalysisTreeInterface/KFManLinkDef.h @@ -4,8 +4,8 @@ #pragma link off all classes; #pragma link off all functions; -#pragma link C++ class KFPS_manager+; -#pragma link C++ class InConverter+; -#pragma link C++ class OutConverter+; +#pragma link C++ class PFTaskManager+; +#pragma link C++ class ConverterIn+; +#pragma link C++ class ConverterOut+; #endif diff --git a/AnalysisTreeInterface/PFTaskManager.cpp b/AnalysisTreeInterface/PFTaskManager.cpp new file mode 100644 index 0000000..5c764cc --- /dev/null +++ b/AnalysisTreeInterface/PFTaskManager.cpp @@ -0,0 +1,29 @@ +#include +#include "PFTaskManager.h" + +void PFTaskManager::Run(long long int nEvents) { + std::cout << "PFTaskManager::Run" << std::endl; + nEvents = nEvents < 0 ? in_tree_->GetEntries() : nEvents; + + for (long long iEvent = 0; iEvent < nEvents; ++iEvent) { + in_tree_->GetEntry(iEvent); + if(( iEvent+1) % 100 == 0) { + std::cout << "Event # " << iEvent+1 << " out of " << nEvents << "\r" << std::flush; + } + + tasks_.at(kInConverter)->Exec(); + const auto* converter_in = ((ConverterIn*)tasks_.at(kInConverter)); + + SimpleFinder FCFinder; + FCFinder.Init(converter_in->GetInputContainer()); + FCFinder.SetCuts(converter_in->GetCuts()); + FCFinder.SortTracks(); + FCFinder.FindParticles(); + + auto* converter_out = ((ConverterOut*)tasks_.at(kOutConverter)); + converter_out->SetCandidates(FCFinder.GetLambdas()); + converter_out->Exec(); + + out_tree_->Fill(); + } // Event loop +} diff --git a/AnalysisTreeInterface/PFTaskManager.h b/AnalysisTreeInterface/PFTaskManager.h new file mode 100644 index 0000000..47b597f --- /dev/null +++ b/AnalysisTreeInterface/PFTaskManager.h @@ -0,0 +1,33 @@ +#ifndef KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_PFTASKMANAGER_H_ +#define KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_PFTASKMANAGER_H_ + +#include "AnalysisTree/TaskManager.h" +#include "ConverterOut.h" +#include "ConverterIn.h" + +class PFTaskManager : public AnalysisTree::TaskManager { + + enum eTasks{ + kInConverter = 0, + kOutConverter + }; + + public: + PFTaskManager(const std::string& filelist, const std::string& in_tree) : + AnalysisTree::TaskManager(filelist, in_tree) {} + + void Run(long long nEvents) final; + + void AddTasks(ConverterIn* in_task, ConverterOut* out_task){ + assert(tasks_.empty()); + tasks_.emplace_back(in_task); + tasks_.emplace_back(out_task); + } + + void AddTask() = delete; + + protected: + +}; + +#endif //KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_PFTASKMANAGER_H_ -- GitLab From 27978cfb2fcdbb938afada574ad37419bbbcd194 Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 15 Jun 2020 15:36:32 +0200 Subject: [PATCH 04/20] fix name --- AnalysisTreeInterface/ConverterIn.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnalysisTreeInterface/ConverterIn.h b/AnalysisTreeInterface/ConverterIn.h index 4e5301b..94e97a9 100644 --- a/AnalysisTreeInterface/ConverterIn.h +++ b/AnalysisTreeInterface/ConverterIn.h @@ -21,7 +21,7 @@ class ConverterIn : public AnalysisTree::FillTask { ConverterIn(){ // Use default names for the input branches in_branches_.resize(kNumberOfInputBranches); in_branches_[kRecEventHeader] = "RecEventHeader"; - in_branches_[kSimEventHeader] = "RecEventHeader"; + in_branches_[kSimEventHeader] = "SimEventHeader"; in_branches_[kKfpfTracks] = "KfpfTracks"; in_branches_[kSimTracks] = "SimTracks"; } -- GitLab From 932797f58548aaca4e95956e733cfbc4fc630927 Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 15 Jun 2020 15:41:12 +0200 Subject: [PATCH 05/20] go back to Tracks to test --- AnalysisTreeInterface/ConverterIn.cpp | 35 ++++++++++++++++++++++++--- AnalysisTreeInterface/ConverterIn.h | 34 ++++---------------------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/AnalysisTreeInterface/ConverterIn.cpp b/AnalysisTreeInterface/ConverterIn.cpp index d799337..8971bd5 100644 --- a/AnalysisTreeInterface/ConverterIn.cpp +++ b/AnalysisTreeInterface/ConverterIn.cpp @@ -24,7 +24,7 @@ void ConverterIn::Exec() { std::cout << "Good tracks = " << n_good_tracks << std::endl; } -void ConverterIn::FillParticle(const AnalysisTree::Particle& rec_particle, InputContainer& input_info) +void ConverterIn::FillParticle(const AnalysisTree::Track& rec_particle, InputContainer& input_info) { std::vector mf(kNumberOfFieldPars, 0.f); for(int iF=0; iF(pdg_field_id_); +// const int pdg = rec_particle.GetPid(); input_info.AddTrack(par, cov_matrix, mf, rec_particle.GetField(q_field_id_), pdg, rec_particle.GetId(), rec_particle.GetField(passcuts_field_id_)); } -std::vector ConverterIn::GetCovMatrixCbm(const AnalysisTree::Particle& particle) const { +std::vector ConverterIn::GetCovMatrixCbm(const AnalysisTree::Track& particle) const { const auto tx = particle.GetField(par_field_id_ + 3); const auto ty = particle.GetField(par_field_id_ + 4); const auto qp = particle.GetField(par_field_id_ + 5); @@ -97,7 +98,7 @@ std::vector ConverterIn::GetCovMatrixCbm(const AnalysisTree::Particle& pa return cov; } -std::vector ConverterIn::GetCovMatrixShine(const AnalysisTree::Particle& particle) const +std::vector ConverterIn::GetCovMatrixShine(const AnalysisTree::Track& particle) const { std::vector cov(21, 0.); @@ -107,4 +108,30 @@ std::vector ConverterIn::GetCovMatrixShine(const AnalysisTree::Particle& return cov; } +void ConverterIn::Init(std::map& branches) { + rec_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kRecEventHeader])->second; + sim_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kSimEventHeader])->second; + kf_tracks_ = (AnalysisTree::TrackDetector*) branches.find(in_branches_[kKfpfTracks])->second; + sim_tracks_ = (AnalysisTree::Particles*) branches.find(in_branches_[kSimTracks])->second; + kf2sim_tracks_ = (AnalysisTree::Matching*) branches.find( + config_->GetMatchName(in_branches_[kKfpfTracks], in_branches_[kSimTracks]))->second; + + auto branch_conf_kftr = config_->GetBranchConfig(in_branches_[kKfpfTracks]); + + q_field_id_ = branch_conf_kftr.GetFieldId("q"); + par_field_id_ = branch_conf_kftr.GetFieldId("x"); // par0 + mf_field_id_ = branch_conf_kftr.GetFieldId("cx0"); // magnetic field par0 + cov_field_id_ = branch_conf_kftr.GetFieldId("cov1"); // cov matrix 0 + passcuts_field_id_ = branch_conf_kftr.GetFieldId("pass_cuts"); + pdg_field_id_ = branch_conf_kftr.GetFieldId("mc_pdg"); + + auto branch_conf_simtr = config_->GetBranchConfig(in_branches_[kSimTracks]); + mother_id_field_id_ = branch_conf_simtr.GetFieldId("mother_id"); + sim_pdg_field_id_ = branch_conf_simtr.GetFieldId("pdg"); + + if (track_cuts_){ + track_cuts_->Init(*config_); + } +} + diff --git a/AnalysisTreeInterface/ConverterIn.h b/AnalysisTreeInterface/ConverterIn.h index 94e97a9..6cb5354 100644 --- a/AnalysisTreeInterface/ConverterIn.h +++ b/AnalysisTreeInterface/ConverterIn.h @@ -27,31 +27,7 @@ class ConverterIn : public AnalysisTree::FillTask { } virtual ~ConverterIn() = default; - void Init(std::map& branches) override { - rec_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kRecEventHeader])->second; - sim_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kSimEventHeader])->second; - kf_tracks_ = (AnalysisTree::Particles*) branches.find(in_branches_[kKfpfTracks])->second; - sim_tracks_ = (AnalysisTree::Particles*) branches.find(in_branches_[kSimTracks])->second; - kf2sim_tracks_ = (AnalysisTree::Matching*) branches.find( - config_->GetMatchName(in_branches_[kKfpfTracks], in_branches_[kSimTracks]))->second; - - auto branch_conf_kftr = config_->GetBranchConfig(in_branches_[kKfpfTracks]); - - q_field_id_ = branch_conf_kftr.GetFieldId("q"); - par_field_id_ = branch_conf_kftr.GetFieldId("x"); // par0 - mf_field_id_ = branch_conf_kftr.GetFieldId("cx0"); // magnetic field par0 - cov_field_id_ = branch_conf_kftr.GetFieldId("cov1"); // cov matrix 0 - passcuts_field_id_ = branch_conf_kftr.GetFieldId("pass_cuts"); - pdg_field_id_ = branch_conf_kftr.GetFieldId("mc_pdg"); - - auto branch_conf_simtr = config_->GetBranchConfig(in_branches_[kSimTracks]); - mother_id_field_id_ = branch_conf_simtr.GetFieldId("mother_id"); - sim_pdg_field_id_ = branch_conf_simtr.GetFieldId("pdg"); - - if (track_cuts_){ - track_cuts_->Init(*config_); - } - } + void Init(std::map& branches) override; void Exec() override; @@ -62,11 +38,11 @@ class ConverterIn : public AnalysisTree::FillTask { protected: - std::vector GetCovMatrixCbm(const AnalysisTree::Particle&) const; - std::vector GetCovMatrixShine(const AnalysisTree::Particle&) const; - void FillParticle(const AnalysisTree::Particle&, InputContainer&); + std::vector GetCovMatrixCbm(const AnalysisTree::Track&) const; + std::vector GetCovMatrixShine(const AnalysisTree::Track&) const; + void FillParticle(const AnalysisTree::Track&, InputContainer&); - AnalysisTree::Particles* kf_tracks_{nullptr}; + AnalysisTree::TrackDetector* kf_tracks_{nullptr}; AnalysisTree::Particles* sim_tracks_{nullptr}; AnalysisTree::Matching* kf2sim_tracks_{nullptr}; AnalysisTree::EventHeader* rec_event_header_{nullptr}; -- GitLab From e3e39ae5e06111cab7658a14d50069fb311e185f Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 15 Jun 2020 16:15:45 +0200 Subject: [PATCH 06/20] add exe --- AnalysisTreeInterface/CMakeLists.txt | 4 ++++ AnalysisTreeInterface/ConverterIn.cpp | 3 +++ AnalysisTreeInterface/ConverterIn.h | 3 ++- AnalysisTreeInterface/main.cxx | 22 ++++++++++++---------- Interface/InputContainer.h | 7 ++++++- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/AnalysisTreeInterface/CMakeLists.txt b/AnalysisTreeInterface/CMakeLists.txt index 4a68c54..2611bbf 100644 --- a/AnalysisTreeInterface/CMakeLists.txt +++ b/AnalysisTreeInterface/CMakeLists.txt @@ -21,6 +21,10 @@ target_link_libraries(KFMan ${ROOT_LIBRARIES} AnalysisTreeBase AnalysisTreeInfra add_dependencies(KFMan KFParticleSimple) add_target_property(KFMan COMPILE_FLAGS "-DDO_TPCCATRACKER_EFF_PERFORMANCE -DNonhomogeneousField -DCBM -DUSE_TIMERS") +add_executable(main main.cxx) +add_dependencies(main KFMan) +target_link_libraries(main KFMan KFParticleSimple KFParticleInterface) + install(TARGETS KFMan EXPORT KFManTargets LIBRARY DESTINATION lib ARCHIVE DESTINATION lib diff --git a/AnalysisTreeInterface/ConverterIn.cpp b/AnalysisTreeInterface/ConverterIn.cpp index 8971bd5..cf584de 100644 --- a/AnalysisTreeInterface/ConverterIn.cpp +++ b/AnalysisTreeInterface/ConverterIn.cpp @@ -7,6 +7,9 @@ #include "ConverterIn.h" void ConverterIn::Exec() { + + input_container_.Clear(); + const int n_tracks = kf_tracks_->GetNumberOfChannels(); std::cout << " Ntracks = " << n_tracks << std::endl; diff --git a/AnalysisTreeInterface/ConverterIn.h b/AnalysisTreeInterface/ConverterIn.h index 6cb5354..6e6de7c 100644 --- a/AnalysisTreeInterface/ConverterIn.h +++ b/AnalysisTreeInterface/ConverterIn.h @@ -18,7 +18,8 @@ class ConverterIn : public AnalysisTree::FillTask { }; public: - ConverterIn(){ // Use default names for the input branches + ConverterIn(CutsContainer cuts) : cuts_(cuts) + { // Use default names for the input branches in_branches_.resize(kNumberOfInputBranches); in_branches_[kRecEventHeader] = "RecEventHeader"; in_branches_[kSimEventHeader] = "SimEventHeader"; diff --git a/AnalysisTreeInterface/main.cxx b/AnalysisTreeInterface/main.cxx index 3745f4a..6cc3559 100644 --- a/AnalysisTreeInterface/main.cxx +++ b/AnalysisTreeInterface/main.cxx @@ -1,9 +1,11 @@ -#include "Manager.h" +#include "PFTaskManager.h" int main(int argc, char** argv) { - if(argc < 2) - return 0; + if(argc < 2){ + std::cout << "Wrong number of arguments! Please use:\n ./main filename\n"; + return EXIT_FAILURE; + } CutsContainer cuts; cuts.CancelCuts(); @@ -16,14 +18,14 @@ int main(int argc, char** argv) cuts.SetCutLDown(3.); cuts.SetCutLdL(7.); - std::string filename = argv[1]; - KFPS_manager man; - man.SetInFileName(filename); - man.SetInTreeName("aTree"); - man.SetIsShine(true); - man.SetCuts(cuts); + const std::string& filename = argv[1]; - man.Run(100); + PFTaskManager man(filename, "aTree"); + man.AddTasks(new ConverterIn(cuts), new ConverterOut); + man.SetOutFileName("PFSimpleOutput.root"); + man.Init(); + man.Run(10); + man.Finish(); return 0; } \ No newline at end of file diff --git a/Interface/InputContainer.h b/Interface/InputContainer.h index 5e053ad..104e431 100644 --- a/Interface/InputContainer.h +++ b/Interface/InputContainer.h @@ -51,7 +51,12 @@ class InputContainer{ const KFVertex& GetVertex() const {return vtx_;}; const std::vector& GetTracks() const {return tracks_;}; const CutsContainer& GetCuts() const {return cuts_;}; - + + void Clear() { + if(!tracks_.empty()){ + tracks_.clear(); + } + } protected: -- GitLab From 6162bb3c52ef7d6926e5f7dcd4eae196b6cd3311 Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 15 Jun 2020 16:50:16 +0200 Subject: [PATCH 07/20] WTF is going on here? --- AnalysisTreeInterface/ConverterIn.cpp | 6 +++--- AnalysisTreeInterface/ConverterIn.h | 2 ++ Interface/InputContainer.h | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/AnalysisTreeInterface/ConverterIn.cpp b/AnalysisTreeInterface/ConverterIn.cpp index cf584de..15e439c 100644 --- a/AnalysisTreeInterface/ConverterIn.cpp +++ b/AnalysisTreeInterface/ConverterIn.cpp @@ -8,6 +8,8 @@ void ConverterIn::Exec() { + std::cout << "WTF? " << input_container_.GetTracks().size() << std::endl; + input_container_.Clear(); const int n_tracks = kf_tracks_->GetNumberOfChannels(); @@ -135,6 +137,4 @@ void ConverterIn::Init(std::map& branches) { if (track_cuts_){ track_cuts_->Init(*config_); } -} - - +} \ No newline at end of file diff --git a/AnalysisTreeInterface/ConverterIn.h b/AnalysisTreeInterface/ConverterIn.h index 6e6de7c..216c5f8 100644 --- a/AnalysisTreeInterface/ConverterIn.h +++ b/AnalysisTreeInterface/ConverterIn.h @@ -25,6 +25,8 @@ class ConverterIn : public AnalysisTree::FillTask { in_branches_[kSimEventHeader] = "SimEventHeader"; in_branches_[kKfpfTracks] = "KfpfTracks"; in_branches_[kSimTracks] = "SimTracks"; + + std::cout << "WTF! " << input_container_.GetTracks().size() << std::endl; } virtual ~ConverterIn() = default; diff --git a/Interface/InputContainer.h b/Interface/InputContainer.h index 104e431..b4fcf45 100644 --- a/Interface/InputContainer.h +++ b/Interface/InputContainer.h @@ -45,7 +45,6 @@ class InputContainer{ void AddTrack(const std::vector& par, const std::vector& cov, const std::vector& field, int charge, int pdg, int id, int passcuts=1); // KFParticleTopoReconstructor* CreateTopoReconstructor(); //^ not good - void SetCuts(const CutsContainer& cuts) { cuts_ = cuts; }; const KFVertex& GetVertex() const {return vtx_;}; @@ -53,7 +52,9 @@ class InputContainer{ const CutsContainer& GetCuts() const {return cuts_;}; void Clear() { + std::cout << "Clear " << tracks_.size(); if(!tracks_.empty()){ + std::cout << "Clear non-empty" << tracks_.size(); tracks_.clear(); } } @@ -63,7 +64,7 @@ class InputContainer{ double InversedChi2Prob(double p, int ndf) const; KFVertex vtx_; - std::vector tracks_; + std::vector tracks_{0}; CutsContainer cuts_; }; -- GitLab From e4f4c5b261acd104034e26e6db3f176d36387045 Mon Sep 17 00:00:00 2001 From: Viktor Date: Tue, 14 Jul 2020 18:39:26 +0200 Subject: [PATCH 08/20] switch to new AT --- AnalysisTreeInterface/ConverterIn.cpp | 3 +++ AnalysisTreeInterface/ConverterIn.h | 12 +++++++----- AnalysisTreeInterface/ConverterOut.cpp | 5 +++++ AnalysisTreeInterface/ConverterOut.h | 5 +++-- AnalysisTreeInterface/PFTaskManager.h | 4 ++-- AnalysisTreeInterface/main.cxx | 1 + CMakeLists.txt | 2 +- Interface/InputContainer.cxx | 3 +++ Interface/InputContainer.h | 4 ++-- 9 files changed, 27 insertions(+), 12 deletions(-) diff --git a/AnalysisTreeInterface/ConverterIn.cpp b/AnalysisTreeInterface/ConverterIn.cpp index 15e439c..01f5039 100644 --- a/AnalysisTreeInterface/ConverterIn.cpp +++ b/AnalysisTreeInterface/ConverterIn.cpp @@ -19,6 +19,9 @@ void ConverterIn::Exec() { input_container_.SetPV(rec_event_header_->GetVertexX(), rec_event_header_->GetVertexY(), rec_event_header_->GetVertexZ()); int n_good_tracks{0}; + + input_container_.Reserve(n_tracks); + for(int i_track=0; i_trackGetChannel(i_track); // if(!IsGoodTrack(rec_track)) continue; diff --git a/AnalysisTreeInterface/ConverterIn.h b/AnalysisTreeInterface/ConverterIn.h index 216c5f8..7028aac 100644 --- a/AnalysisTreeInterface/ConverterIn.h +++ b/AnalysisTreeInterface/ConverterIn.h @@ -1,9 +1,11 @@ #ifndef KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTERIN_H_ #define KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTERIN_H_ -#include -#include -#include "AnalysisTree/FillTask.h" +#include +#include +#include +#include +#include "AnalysisTree/FillTask.hpp" #include "Interface/InputContainer.h" @@ -18,7 +20,7 @@ class ConverterIn : public AnalysisTree::FillTask { }; public: - ConverterIn(CutsContainer cuts) : cuts_(cuts) + explicit ConverterIn(const CutsContainer& cuts) : cuts_(cuts) { // Use default names for the input branches in_branches_.resize(kNumberOfInputBranches); in_branches_[kRecEventHeader] = "RecEventHeader"; @@ -28,7 +30,7 @@ class ConverterIn : public AnalysisTree::FillTask { std::cout << "WTF! " << input_container_.GetTracks().size() << std::endl; } - virtual ~ConverterIn() = default; + ~ConverterIn() override = default; void Init(std::map& branches) override; diff --git a/AnalysisTreeInterface/ConverterOut.cpp b/AnalysisTreeInterface/ConverterOut.cpp index d1564f0..d1ff091 100644 --- a/AnalysisTreeInterface/ConverterOut.cpp +++ b/AnalysisTreeInterface/ConverterOut.cpp @@ -1,5 +1,8 @@ #include "ConverterOut.h" +#include "TTree.h" + +#include "AnalysisTree/DataHeader.hpp" void ConverterOut::Exec() { @@ -47,6 +50,8 @@ void ConverterOut::Exec() void ConverterOut::Init(std::map& branches) { + assert(out_config_ && out_tree_); + AnalysisTree::BranchConfig LambdaRecoBranch("LambdaCandidates", AnalysisTree::DetType::kParticle); LambdaRecoBranch.AddField("chi2primpos"); diff --git a/AnalysisTreeInterface/ConverterOut.h b/AnalysisTreeInterface/ConverterOut.h index 29ff68c..bb3f5a5 100644 --- a/AnalysisTreeInterface/ConverterOut.h +++ b/AnalysisTreeInterface/ConverterOut.h @@ -2,12 +2,13 @@ #define KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTEROUT_H_ #include -#include "AnalysisTree/FillTask.h" +#include +#include "AnalysisTree/FillTask.hpp" class ConverterOut : public AnalysisTree::FillTask { public: ConverterOut() = default; - virtual ~ConverterOut() = default; + ~ConverterOut() override = default; void Init(std::map& branches) override; void Exec() override; diff --git a/AnalysisTreeInterface/PFTaskManager.h b/AnalysisTreeInterface/PFTaskManager.h index 47b597f..afd04b7 100644 --- a/AnalysisTreeInterface/PFTaskManager.h +++ b/AnalysisTreeInterface/PFTaskManager.h @@ -1,7 +1,7 @@ #ifndef KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_PFTASKMANAGER_H_ #define KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_PFTASKMANAGER_H_ -#include "AnalysisTree/TaskManager.h" +#include "AnalysisTree/TaskManager.hpp" #include "ConverterOut.h" #include "ConverterIn.h" @@ -14,7 +14,7 @@ class PFTaskManager : public AnalysisTree::TaskManager { public: PFTaskManager(const std::string& filelist, const std::string& in_tree) : - AnalysisTree::TaskManager(filelist, in_tree) {} + AnalysisTree::TaskManager({filelist}, {in_tree}) {} void Run(long long nEvents) final; diff --git a/AnalysisTreeInterface/main.cxx b/AnalysisTreeInterface/main.cxx index 6cc3559..e374e15 100644 --- a/AnalysisTreeInterface/main.cxx +++ b/AnalysisTreeInterface/main.cxx @@ -23,6 +23,7 @@ int main(int argc, char** argv) PFTaskManager man(filename, "aTree"); man.AddTasks(new ConverterIn(cuts), new ConverterOut); man.SetOutFileName("PFSimpleOutput.root"); + man.SetOutTreeName("sTree"); man.Init(); man.Run(10); man.Finish(); diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d406d9..c5e6a76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ if(AnalysisTree_FOUND) Message("AnalysisTree found. Corresponding interface will be compiled") add_subdirectory(AnalysisTreeInterface) Else() - Message("AnalysisTree is not found. Corresponding interface will be compiled") + Message("AnalysisTree is not found. Corresponding interface will not be compiled") EndIf() add_subdirectory(KFSimple) diff --git a/Interface/InputContainer.cxx b/Interface/InputContainer.cxx index aff0079..7f2e2d7 100644 --- a/Interface/InputContainer.cxx +++ b/Interface/InputContainer.cxx @@ -152,3 +152,6 @@ double InputContainer::InversedChi2Prob(double p, int ndf) const return chi2Centr; } +void InputContainer::Reserve(size_t n) { + tracks_.reserve(n); +} diff --git a/Interface/InputContainer.h b/Interface/InputContainer.h index b4fcf45..7e2f095 100644 --- a/Interface/InputContainer.h +++ b/Interface/InputContainer.h @@ -54,17 +54,17 @@ class InputContainer{ void Clear() { std::cout << "Clear " << tracks_.size(); if(!tracks_.empty()){ - std::cout << "Clear non-empty" << tracks_.size(); tracks_.clear(); } } + void Reserve(size_t n); protected: double InversedChi2Prob(double p, int ndf) const; KFVertex vtx_; - std::vector tracks_{0}; + std::vector tracks_{}; CutsContainer cuts_; }; -- GitLab From 5a5982e4528444cf148c534da96b7b0d0ce0ff9e Mon Sep 17 00:00:00 2001 From: Viktor Date: Thu, 16 Jul 2020 09:28:14 +0200 Subject: [PATCH 09/20] switch to new AT --- AnalysisTreeInterface/ConverterIn.cpp | 128 ++++++++++-------- AnalysisTreeInterface/ConverterIn.h | 12 +- AnalysisTreeInterface/ConverterOut.h | 3 +- AnalysisTreeInterface/PFTaskManager.cpp | 3 +- AnalysisTreeInterface/PFTaskManager.h | 3 +- .../{ => old}/InConverter.cxx | 0 AnalysisTreeInterface/{ => old}/InConverter.h | 0 AnalysisTreeInterface/{ => old}/Manager.cxx | 0 AnalysisTreeInterface/{ => old}/Manager.h | 4 +- .../{ => old}/OutConverter.cxx | 0 .../{ => old}/OutConverter.h | 0 Interface/InputContainer.cxx | 97 +++++++------ Interface/InputContainer.h | 3 +- KFSimple/SimpleFinder.cxx | 8 +- 14 files changed, 137 insertions(+), 124 deletions(-) rename AnalysisTreeInterface/{ => old}/InConverter.cxx (100%) rename AnalysisTreeInterface/{ => old}/InConverter.h (100%) rename AnalysisTreeInterface/{ => old}/Manager.cxx (100%) rename AnalysisTreeInterface/{ => old}/Manager.h (86%) rename AnalysisTreeInterface/{ => old}/OutConverter.cxx (100%) rename AnalysisTreeInterface/{ => old}/OutConverter.h (100%) diff --git a/AnalysisTreeInterface/ConverterIn.cpp b/AnalysisTreeInterface/ConverterIn.cpp index 01f5039..994c1d4 100644 --- a/AnalysisTreeInterface/ConverterIn.cpp +++ b/AnalysisTreeInterface/ConverterIn.cpp @@ -1,38 +1,8 @@ -// -// Created by vklochkov on 6/11/20. -// - #include #include #include "ConverterIn.h" -void ConverterIn::Exec() { - - std::cout << "WTF? " << input_container_.GetTracks().size() << std::endl; - - input_container_.Clear(); - - const int n_tracks = kf_tracks_->GetNumberOfChannels(); - std::cout << " Ntracks = " << n_tracks << std::endl; - - input_container_.SetCuts(cuts_); - input_container_.SetPV(rec_event_header_->GetVertexX(), rec_event_header_->GetVertexY(), rec_event_header_->GetVertexZ()); - - int n_good_tracks{0}; - - input_container_.Reserve(n_tracks); - - for(int i_track=0; i_trackGetChannel(i_track); -// if(!IsGoodTrack(rec_track)) continue; - FillParticle(rec_track, input_container_); - n_good_tracks++; - } - - std::cout << "Good tracks = " << n_good_tracks << std::endl; -} - -void ConverterIn::FillParticle(const AnalysisTree::Track& rec_particle, InputContainer& input_info) +void ConverterIn::FillParticle(const AnalysisTree::Track& rec_particle, InputContainer& input_info) const { std::vector mf(kNumberOfFieldPars, 0.f); for(int iF=0; iF(pdg_field_id_); + const int pdg = rec_particle.GetField(pdg_field_id_); //TODO // const int pdg = rec_particle.GetPid(); input_info.AddTrack(par, cov_matrix, mf, rec_particle.GetField(q_field_id_), pdg, rec_particle.GetId(), rec_particle.GetField(passcuts_field_id_)); } + +void ConverterIn::Init(std::map& branches) { + rec_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kRecEventHeader])->second; + sim_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kSimEventHeader])->second; + kf_tracks_ = (AnalysisTree::TrackDetector*) branches.find(in_branches_[kKfpfTracks])->second; + sim_tracks_ = (AnalysisTree::Particles*) branches.find(in_branches_[kSimTracks])->second; + kf2sim_tracks_ = (AnalysisTree::Matching*) branches.find( + config_->GetMatchName(in_branches_[kKfpfTracks], in_branches_[kSimTracks]))->second; + + auto branch_conf_kftr = config_->GetBranchConfig(in_branches_[kKfpfTracks]); + + q_field_id_ = branch_conf_kftr.GetFieldId("q"); + par_field_id_ = branch_conf_kftr.GetFieldId("x"); // par0 + mf_field_id_ = branch_conf_kftr.GetFieldId("cx0"); // magnetic field par0 + cov_field_id_ = branch_conf_kftr.GetFieldId("cov1"); // cov matrix 0 + passcuts_field_id_ = branch_conf_kftr.GetFieldId("pass_cuts"); + pdg_field_id_ = branch_conf_kftr.GetFieldId("mc_pdg"); + + auto branch_conf_simtr = config_->GetBranchConfig(in_branches_[kSimTracks]); + mother_id_field_id_ = branch_conf_simtr.GetFieldId("mother_id"); + sim_pdg_field_id_ = branch_conf_simtr.GetFieldId("pdg"); + + if (track_cuts_){ + track_cuts_->Init(*config_); + } +} + +InputContainer ConverterIn::CreateInputContainer() const { + + InputContainer input_container; + const int n_tracks = kf_tracks_->GetNumberOfChannels(); + std::cout << " Ntracks = " << n_tracks << std::endl; + input_container.SetCuts(cuts_); + input_container.SetPV(rec_event_header_->GetVertexX(), rec_event_header_->GetVertexY(), rec_event_header_->GetVertexZ()); + + int n_good_tracks{0}; + input_container.Reserve(n_tracks); + for(int i_track=0; i_trackGetChannel(i_track); + if(!IsGoodTrack(rec_track)) continue; + FillParticle(rec_track, input_container); + n_good_tracks++; + } + std::cout << "Good tracks = " << n_good_tracks << std::endl; + return input_container; +} + std::vector ConverterIn::GetCovMatrixCbm(const AnalysisTree::Track& particle) const { const auto tx = particle.GetField(par_field_id_ + 3); const auto ty = particle.GetField(par_field_id_ + 4); @@ -116,28 +133,27 @@ std::vector ConverterIn::GetCovMatrixShine(const AnalysisTree::Track& par return cov; } -void ConverterIn::Init(std::map& branches) { - rec_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kRecEventHeader])->second; - sim_event_header_ = (AnalysisTree::EventHeader*) branches.find(in_branches_[kSimEventHeader])->second; - kf_tracks_ = (AnalysisTree::TrackDetector*) branches.find(in_branches_[kKfpfTracks])->second; - sim_tracks_ = (AnalysisTree::Particles*) branches.find(in_branches_[kSimTracks])->second; - kf2sim_tracks_ = (AnalysisTree::Matching*) branches.find( - config_->GetMatchName(in_branches_[kKfpfTracks], in_branches_[kSimTracks]))->second; - - auto branch_conf_kftr = config_->GetBranchConfig(in_branches_[kKfpfTracks]); - - q_field_id_ = branch_conf_kftr.GetFieldId("q"); - par_field_id_ = branch_conf_kftr.GetFieldId("x"); // par0 - mf_field_id_ = branch_conf_kftr.GetFieldId("cx0"); // magnetic field par0 - cov_field_id_ = branch_conf_kftr.GetFieldId("cov1"); // cov matrix 0 - passcuts_field_id_ = branch_conf_kftr.GetFieldId("pass_cuts"); - pdg_field_id_ = branch_conf_kftr.GetFieldId("mc_pdg"); - - auto branch_conf_simtr = config_->GetBranchConfig(in_branches_[kSimTracks]); - mother_id_field_id_ = branch_conf_simtr.GetFieldId("mother_id"); - sim_pdg_field_id_ = branch_conf_simtr.GetFieldId("pdg"); - - if (track_cuts_){ - track_cuts_->Init(*config_); +bool ConverterIn::IsGoodTrack(const AnalysisTree::Track& rec_track) const +{ + return true; + bool is_good{false}; + + const int sim_id = kf2sim_tracks_->GetMatch(rec_track.GetId()); +// std::cout<< "sim " << sim_id << std::endl; + if (sim_id >= 0 && sim_id < sim_tracks_->GetNumberOfChannels()) { + const AnalysisTree::Track& sim_track = sim_tracks_->GetChannel(sim_id); + const int mother_id = sim_track.GetField(mother_id_field_id_); +// std::cout << "mother " << mother_id << std::endl; + + if (mother_id >= 0 && mother_id < sim_tracks_->GetNumberOfChannels() ) + { + const AnalysisTree::Track& mother_track = sim_tracks_->GetChannel(mother_id); + const int mother_pdg = mother_track.GetField(sim_pdg_field_id_); + std::cout << "mother pdg " << mother_pdg << std::endl; + + if(mother_pdg == 3122) + is_good = true; + } } -} \ No newline at end of file + return is_good; +} diff --git a/AnalysisTreeInterface/ConverterIn.h b/AnalysisTreeInterface/ConverterIn.h index 7028aac..3639e1e 100644 --- a/AnalysisTreeInterface/ConverterIn.h +++ b/AnalysisTreeInterface/ConverterIn.h @@ -27,25 +27,25 @@ class ConverterIn : public AnalysisTree::FillTask { in_branches_[kSimEventHeader] = "SimEventHeader"; in_branches_[kKfpfTracks] = "KfpfTracks"; in_branches_[kSimTracks] = "SimTracks"; - - std::cout << "WTF! " << input_container_.GetTracks().size() << std::endl; } ~ConverterIn() override = default; void Init(std::map& branches) override; - void Exec() override; + void Exec() override {}; void Finish() override {}; const CutsContainer& GetCuts() const { return cuts_; } - const InputContainer& GetInputContainer() const { return input_container_; } +// const InputContainer& GetInputContainer() const { return input_container_; } + InputContainer CreateInputContainer() const; protected: std::vector GetCovMatrixCbm(const AnalysisTree::Track&) const; std::vector GetCovMatrixShine(const AnalysisTree::Track&) const; - void FillParticle(const AnalysisTree::Track&, InputContainer&); + void FillParticle(const AnalysisTree::Track&, InputContainer&) const; + bool IsGoodTrack(const AnalysisTree::Track& rec_track) const; AnalysisTree::TrackDetector* kf_tracks_{nullptr}; AnalysisTree::Particles* sim_tracks_{nullptr}; @@ -55,7 +55,7 @@ class ConverterIn : public AnalysisTree::FillTask { AnalysisTree::Cuts* track_cuts_{nullptr}; CutsContainer cuts_; - InputContainer input_container_; +// InputContainer input_container_; // field ids for input parameters int q_field_id_{AnalysisTree::UndefValueInt}; diff --git a/AnalysisTreeInterface/ConverterOut.h b/AnalysisTreeInterface/ConverterOut.h index bb3f5a5..1e5eda3 100644 --- a/AnalysisTreeInterface/ConverterOut.h +++ b/AnalysisTreeInterface/ConverterOut.h @@ -2,8 +2,9 @@ #define KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_CONVERTEROUT_H_ #include -#include + #include "AnalysisTree/FillTask.hpp" +#include "AnalysisTree/Detector.hpp" class ConverterOut : public AnalysisTree::FillTask { public: diff --git a/AnalysisTreeInterface/PFTaskManager.cpp b/AnalysisTreeInterface/PFTaskManager.cpp index 5c764cc..95d0f28 100644 --- a/AnalysisTreeInterface/PFTaskManager.cpp +++ b/AnalysisTreeInterface/PFTaskManager.cpp @@ -11,11 +11,10 @@ void PFTaskManager::Run(long long int nEvents) { std::cout << "Event # " << iEvent+1 << " out of " << nEvents << "\r" << std::flush; } - tasks_.at(kInConverter)->Exec(); const auto* converter_in = ((ConverterIn*)tasks_.at(kInConverter)); SimpleFinder FCFinder; - FCFinder.Init(converter_in->GetInputContainer()); + FCFinder.Init(converter_in->CreateInputContainer()); FCFinder.SetCuts(converter_in->GetCuts()); FCFinder.SortTracks(); FCFinder.FindParticles(); diff --git a/AnalysisTreeInterface/PFTaskManager.h b/AnalysisTreeInterface/PFTaskManager.h index afd04b7..5b737f2 100644 --- a/AnalysisTreeInterface/PFTaskManager.h +++ b/AnalysisTreeInterface/PFTaskManager.h @@ -2,6 +2,7 @@ #define KFPARTICLESIMPLE_ANALYSISTREEINTERFACE_PFTASKMANAGER_H_ #include "AnalysisTree/TaskManager.hpp" + #include "ConverterOut.h" #include "ConverterIn.h" @@ -24,7 +25,7 @@ class PFTaskManager : public AnalysisTree::TaskManager { tasks_.emplace_back(out_task); } - void AddTask() = delete; + void AddTask(AnalysisTree::FillTask *task) = delete; //TODO make it virtual in AT protected: diff --git a/AnalysisTreeInterface/InConverter.cxx b/AnalysisTreeInterface/old/InConverter.cxx similarity index 100% rename from AnalysisTreeInterface/InConverter.cxx rename to AnalysisTreeInterface/old/InConverter.cxx diff --git a/AnalysisTreeInterface/InConverter.h b/AnalysisTreeInterface/old/InConverter.h similarity index 100% rename from AnalysisTreeInterface/InConverter.h rename to AnalysisTreeInterface/old/InConverter.h diff --git a/AnalysisTreeInterface/Manager.cxx b/AnalysisTreeInterface/old/Manager.cxx similarity index 100% rename from AnalysisTreeInterface/Manager.cxx rename to AnalysisTreeInterface/old/Manager.cxx diff --git a/AnalysisTreeInterface/Manager.h b/AnalysisTreeInterface/old/Manager.h similarity index 86% rename from AnalysisTreeInterface/Manager.h rename to AnalysisTreeInterface/old/Manager.h index fd02521..36db7d6 100644 --- a/AnalysisTreeInterface/Manager.h +++ b/AnalysisTreeInterface/old/Manager.h @@ -4,8 +4,8 @@ #include #include -#include "InConverter.h" -#include "OutConverter.h" +#include "AnalysisTreeInterface/old/InConverter.h" +#include "AnalysisTreeInterface/old/OutConverter.h" #include "SimpleFinder.h" class Manager diff --git a/AnalysisTreeInterface/OutConverter.cxx b/AnalysisTreeInterface/old/OutConverter.cxx similarity index 100% rename from AnalysisTreeInterface/OutConverter.cxx rename to AnalysisTreeInterface/old/OutConverter.cxx diff --git a/AnalysisTreeInterface/OutConverter.h b/AnalysisTreeInterface/old/OutConverter.h similarity index 100% rename from AnalysisTreeInterface/OutConverter.h rename to AnalysisTreeInterface/old/OutConverter.h diff --git a/Interface/InputContainer.cxx b/Interface/InputContainer.cxx index 7f2e2d7..3412d90 100644 --- a/Interface/InputContainer.cxx +++ b/Interface/InputContainer.cxx @@ -14,7 +14,7 @@ void InputContainer::SetPV(float x, float y, float z) primVtx_tmp.SetNContributors( 0 ); primVtx_tmp.SetChi2( -100 ); - vtx_ = KFVertex(primVtx_tmp); + vtx_ = KFVertex(primVtx_tmp); } void InputContainer::AddTrack(const std::vector& par, @@ -27,10 +27,9 @@ void InputContainer::AddTrack(const std::vector& par, { if (passcuts==0 || pdg==0 || pdg==-2) return; - + if( par.size() != kNumberOfTrackPars || cov.size() != NumberOfCovElements || field.size() != kNumberOfFieldPars){ - std::cout << "InputContainer::AddTrack - Wrong size of input vector!!" << std::endl; - exit(kError); + throw std::runtime_error("Wrong size of input vector!"); } KFParticle particle; @@ -50,8 +49,39 @@ void InputContainer::AddTrack(const std::vector& par, particle.Q() = char(charge); //NOTE: is not safe particle.SetPDG(pdg); particle.SetId(id); + + tracks_.push_back(particle); +} + +double InputContainer::InversedChi2Prob(double p, int ndf) +{ + const double epsilon = 1.e-14; + double chi2Left = 0.f; + double chi2Right = 10000.f; + + double probLeft = p - TMath::Prob(chi2Left, ndf); + + double chi2Centr = (chi2Left+chi2Right)/2.f; + double probCentr = p - TMath::Prob( chi2Centr, ndf); - tracks_.emplace_back(particle); + while( TMath::Abs(chi2Right-chi2Centr)/chi2Centr > epsilon ) { + if(probCentr * probLeft > 0.f) { + chi2Left = chi2Centr; + probLeft = probCentr; + } + else { + chi2Right = chi2Centr; + } + + chi2Centr = (chi2Left+chi2Right)/2.f; + probCentr = p - TMath::Prob( chi2Centr, ndf); + } + + return chi2Centr; +} + +void InputContainer::Reserve(size_t n) { + tracks_.reserve(n); } // KFParticleTopoReconstructor* InputContainer::CreateTopoReconstructor() @@ -59,17 +89,17 @@ void InputContainer::AddTrack(const std::vector& par, // /* // * Creates the pointer on the KFParticleTopoReconstructor object // * with all necessary input information in order to perform particle selection using -// * non-simplified "standard" KFParticle algorithm. +// * non-simplified "standard" KFParticle algorithm. // */ // auto* TR = new KFParticleTopoReconstructor; -// +// // // cuts setting // TR -> GetKFParticleFinder() -> SetChiPrimaryCut2D(cuts_.GetCutChi2PrimPos()); // TR -> GetKFParticleFinder() -> SetMaxDistanceBetweenParticlesCut(cuts_.GetCutDistance()); // TR -> GetKFParticleFinder() -> SetChi2Cut2D(cuts_.GetCutChi2Geo()); // TR -> GetKFParticleFinder() -> SetLCut(cuts_.GetCutLDown()); // TR -> GetKFParticleFinder() -> SetLdLCut2D(cuts_.GetCutLdL()); -// +// // KFPTrackVector track_tmp, track_empty; // track_tmp.Resize(tracks_.size()); // for(int iTr=0; iTr& par, // track_tmp.SetFieldCoefficient(tracks_[iTr].GetFieldCoeff()[iF], iF, iTr); // track_tmp.SetPDG(tracks_[iTr].GetPDG(), iTr); // track_tmp.SetQ(tracks_[iTr].GetQ(), iTr); -// track_tmp.SetPVIndex(-1, iTr); +// track_tmp.SetPVIndex(-1, iTr); // track_tmp.SetId(tracks_[iTr].Id(), iTr); // } // TR->Init(track_tmp, track_empty); -// +// // TR->AddPV(vtx_); -// +// // return TR; // } @@ -98,12 +128,12 @@ void InputContainer::AddTrack(const std::vector& par, // * Creates the SimpleFinder object with all necessary input information in order to // * perform particle selection using KFSimple algorithm. // */ -// +// // SimpleFinder FCF; -// +// // KFPTrackVector track_tmp; // track_tmp.Resize(tracks_.size()); -// +// // for(int iTr=0; iTr& par, // track_tmp.SetFieldCoefficient(tracks_[iTr].GetFieldCoeff()[iF], iF, iTr); // track_tmp.SetPDG(tracks_[iTr].GetPDG(), iTr); // track_tmp.SetQ(tracks_[iTr].GetQ(), iTr); -// track_tmp.SetPVIndex(-1, iTr); +// track_tmp.SetPVIndex(-1, iTr); // track_tmp.SetId(tracks_[iTr].Id(), iTr); // } // FCF.Init(track_tmp, vtx_); // FCF.SetCuts(cuts_); -// -// return FCF; +// +// return FCF; // } - -double InputContainer::InversedChi2Prob(double p, int ndf) const -{ - const double epsilon = 1.e-14; - double chi2Left = 0.f; - double chi2Right = 10000.f; - - double probLeft = p - TMath::Prob(chi2Left, ndf); - - double chi2Centr = (chi2Left+chi2Right)/2.f; - double probCentr = p - TMath::Prob( chi2Centr, ndf); - - while( TMath::Abs(chi2Right-chi2Centr)/chi2Centr > epsilon ) - { - if(probCentr * probLeft > 0.f) - { - chi2Left = chi2Centr; - probLeft = probCentr; - } - else - { - chi2Right = chi2Centr; - } - - chi2Centr = (chi2Left+chi2Right)/2.f; - probCentr = p - TMath::Prob( chi2Centr, ndf); - } - - return chi2Centr; -} -void InputContainer::Reserve(size_t n) { - tracks_.reserve(n); -} diff --git a/Interface/InputContainer.h b/Interface/InputContainer.h index 7e2f095..77d00fd 100644 --- a/Interface/InputContainer.h +++ b/Interface/InputContainer.h @@ -52,7 +52,6 @@ class InputContainer{ const CutsContainer& GetCuts() const {return cuts_;}; void Clear() { - std::cout << "Clear " << tracks_.size(); if(!tracks_.empty()){ tracks_.clear(); } @@ -61,7 +60,7 @@ class InputContainer{ void Reserve(size_t n); protected: - double InversedChi2Prob(double p, int ndf) const; + static double InversedChi2Prob(double p, int ndf) ; KFVertex vtx_; std::vector tracks_{}; diff --git a/KFSimple/SimpleFinder.cxx b/KFSimple/SimpleFinder.cxx index 5083800..53fece7 100644 --- a/KFSimple/SimpleFinder.cxx +++ b/KFSimple/SimpleFinder.cxx @@ -14,7 +14,7 @@ void SimpleFinder::Init(const InputContainer& input) KFPTrackVector track_tmp; const std::vector& tracks = input.GetTracks(); track_tmp.Resize(tracks.size()); - + for(int iTr=0; iTr Date: Fri, 17 Jul 2020 14:30:48 +0200 Subject: [PATCH 10/20] rm unused code --- AnalysisTreeInterface/ConverterIn.cpp | 9 +++++++-- AnalysisTreeInterface/ConverterIn.h | 5 +++++ AnalysisTreeInterface/PFTaskManager.cpp | 3 ++- AnalysisTreeInterface/PFTaskManager.h | 5 +++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/AnalysisTreeInterface/ConverterIn.cpp b/AnalysisTreeInterface/ConverterIn.cpp index 994c1d4..6feb829 100644 --- a/AnalysisTreeInterface/ConverterIn.cpp +++ b/AnalysisTreeInterface/ConverterIn.cpp @@ -21,7 +21,7 @@ void ConverterIn::FillParticle(const AnalysisTree::Track& rec_particle, InputCon const int pdg = rec_particle.GetField(pdg_field_id_); //TODO // const int pdg = rec_particle.GetPid(); - input_info.AddTrack(par, cov_matrix, mf, rec_particle.GetField(q_field_id_), pdg, rec_particle.GetId(), rec_particle.GetField(passcuts_field_id_)); + input_info.AddTrack(par, cov_matrix, mf, rec_particle.GetField(q_field_id_), pdg, rec_particle.GetId()); } @@ -135,7 +135,12 @@ std::vector ConverterIn::GetCovMatrixShine(const AnalysisTree::Track& par bool ConverterIn::IsGoodTrack(const AnalysisTree::Track& rec_track) const { - return true; + if(!track_cuts_){ + return true; + } + return track_cuts_->Apply(rec_track); + +// return true; bool is_good{false}; const int sim_id = kf2sim_tracks_->GetMatch(rec_track.GetId()); diff --git a/AnalysisTreeInterface/ConverterIn.h b/AnalysisTreeInterface/ConverterIn.h index 3639e1e..aef4ebc 100644 --- a/AnalysisTreeInterface/ConverterIn.h +++ b/AnalysisTreeInterface/ConverterIn.h @@ -39,6 +39,11 @@ class ConverterIn : public AnalysisTree::FillTask { const CutsContainer& GetCuts() const { return cuts_; } // const InputContainer& GetInputContainer() const { return input_container_; } + void SetIsShine(bool is=true) { is_shine_ = is; } + + void SetCuts(const CutsContainer& cuts) { cuts_ = cuts; }; + void SetTrackCuts(AnalysisTree::Cuts* const cuts) { track_cuts_ = cuts; }; + InputContainer CreateInputContainer() const; protected: diff --git a/AnalysisTreeInterface/PFTaskManager.cpp b/AnalysisTreeInterface/PFTaskManager.cpp index 95d0f28..82fccb2 100644 --- a/AnalysisTreeInterface/PFTaskManager.cpp +++ b/AnalysisTreeInterface/PFTaskManager.cpp @@ -11,7 +11,8 @@ void PFTaskManager::Run(long long int nEvents) { std::cout << "Event # " << iEvent+1 << " out of " << nEvents << "\r" << std::flush; } - const auto* converter_in = ((ConverterIn*)tasks_.at(kInConverter)); + auto* converter_in = ((ConverterIn*)tasks_.at(kInConverter)); + converter_in->SetCuts(cuts_); SimpleFinder FCFinder; FCFinder.Init(converter_in->CreateInputContainer()); diff --git a/AnalysisTreeInterface/PFTaskManager.h b/AnalysisTreeInterface/PFTaskManager.h index 5b737f2..efcc197 100644 --- a/AnalysisTreeInterface/PFTaskManager.h +++ b/AnalysisTreeInterface/PFTaskManager.h @@ -25,9 +25,14 @@ class PFTaskManager : public AnalysisTree::TaskManager { tasks_.emplace_back(out_task); } + void SetCuts(const CutsContainer& cuts) { cuts_ = cuts; }; + + void AddTask(AnalysisTree::FillTask *task) = delete; //TODO make it virtual in AT protected: + CutsContainer cuts_; + }; -- GitLab From 42de7f228c218e037593fa47680e8a49c618576e Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 17 Jul 2020 14:31:20 +0200 Subject: [PATCH 11/20] configuration --- AnalysisTreeInterface/main.cxx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/AnalysisTreeInterface/main.cxx b/AnalysisTreeInterface/main.cxx index e374e15..299cdfb 100644 --- a/AnalysisTreeInterface/main.cxx +++ b/AnalysisTreeInterface/main.cxx @@ -21,12 +21,17 @@ int main(int argc, char** argv) const std::string& filename = argv[1]; PFTaskManager man(filename, "aTree"); - man.AddTasks(new ConverterIn(cuts), new ConverterOut); man.SetOutFileName("PFSimpleOutput.root"); man.SetOutTreeName("sTree"); + + auto* in_converter = new ConverterIn(cuts); + in_converter->SetTrackCuts(new AnalysisTree::Cuts("Cut to reproduce KFPF", {{{"KfpfTracks", "pass_cuts"}, 1}})); + in_converter->SetIsShine(false); //TODO maybe change name + + man.AddTasks(in_converter, new ConverterOut); man.Init(); - man.Run(10); + man.Run(10); // -1 = all events man.Finish(); - return 0; + return EXIT_SUCCESS; } \ No newline at end of file -- GitLab From 36565f9f3bcc76158be135063c3c4677f9735bb5 Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 17 Jul 2020 14:31:50 +0200 Subject: [PATCH 12/20] is_passed now set with AT::Cuts --- Interface/InputContainer.cxx | 5 ++--- Interface/InputContainer.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Interface/InputContainer.cxx b/Interface/InputContainer.cxx index 3412d90..7d77f6e 100644 --- a/Interface/InputContainer.cxx +++ b/Interface/InputContainer.cxx @@ -22,10 +22,9 @@ void InputContainer::AddTrack(const std::vector& par, const std::vector& field, int charge, int pdg, - int id, - int passcuts) + int id) { - if (passcuts==0 || pdg==0 || pdg==-2) + if (pdg==0 || pdg==-2) return; if( par.size() != kNumberOfTrackPars || cov.size() != NumberOfCovElements || field.size() != kNumberOfFieldPars){ diff --git a/Interface/InputContainer.h b/Interface/InputContainer.h index 77d00fd..97fbd38 100644 --- a/Interface/InputContainer.h +++ b/Interface/InputContainer.h @@ -42,7 +42,7 @@ class InputContainer{ void SetPV(float x, float y, float z); void SetPV(KFVertex vertex); void SetPV(KFPVertex vertex); - void AddTrack(const std::vector& par, const std::vector& cov, const std::vector& field, int charge, int pdg, int id, int passcuts=1); + void AddTrack(const std::vector& par, const std::vector& cov, const std::vector& field, int charge, int pdg, int id); // KFParticleTopoReconstructor* CreateTopoReconstructor(); //^ not good void SetCuts(const CutsContainer& cuts) { cuts_ = cuts; }; -- GitLab From 6efd18f19a27bf35464d3eaa171e66cb61412708 Mon Sep 17 00:00:00 2001 From: Viktor Date: Fri, 17 Jul 2020 14:32:32 +0200 Subject: [PATCH 13/20] std::sqrt -> templated -> no double-float conversion --- CMakeLists.txt | 4 ++-- KFSimple/SimpleFinder.cxx | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5e6a76..9fb620c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ message(STATUS "Using C++${CMAKE_CXX_STANDARD}") # by default build optimized code with debug symbols if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - set(CMAKE_BUILD_TYPE RELWITHDEBINFO) + set(CMAKE_BUILD_TYPE RELEASE) endif () # in DEBUG mode make verbose Makefile @@ -53,7 +53,7 @@ Else() include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS} ${PROJECT_INCLUDE_DIRECTORIES}) EndIf() -message(STATUS "ROJECT_INCLUDE_DIRECTORIES ${PROJECT_INCLUDE_DIRECTORIES}") +#message(STATUS "PROJECT_INCLUDE_DIRECTORIES ${PROJECT_INCLUDE_DIRECTORIES}") message(STATUS "Using ROOT: ${ROOT_VERSION} <${ROOT_CONFIG}>") include_directories(${CMAKE_SOURCE_DIR} ${ROOT_INCLUDE_DIRS}) diff --git a/KFSimple/SimpleFinder.cxx b/KFSimple/SimpleFinder.cxx index 53fece7..901871a 100644 --- a/KFSimple/SimpleFinder.cxx +++ b/KFSimple/SimpleFinder.cxx @@ -117,7 +117,7 @@ float SimpleFinder::CalculateDistanceBetweenParticles(const std::array const float dx = pars1.at(0) - pars2.at(0); const float dy = pars1.at(1) - pars2.at(1); const float dz = pars1.at(2) - pars2.at(2); - const float dr = sqrt(dx*dx+dy*dy+dz*dz); + const float dr = std::sqrt(dx*dx+dy*dy+dz*dz); return dr; } @@ -132,7 +132,7 @@ float SimpleFinder::CalculateCosMomentumSum(const std::array &pars1, c const std::array PSum = {P1.at(0)+P2.at(0), P1.at(1)+P2.at(1), P1.at(2)+P2.at(2)}; return (P1.at(0)*PSum.at(0) + P1.at(1)*PSum.at(1) + P1.at(2)*PSum.at(2)) / - (sqrt(P1.at(0)*P1.at(0) + P1.at(1)*P1.at(1) + P1.at(2)*P1.at(2)) * sqrt(PSum.at(0)*PSum.at(0) + PSum.at(1)*PSum.at(1) + PSum.at(2)*PSum.at(2))); + (sqrt(P1.at(0)*P1.at(0) + P1.at(1)*P1.at(1) + P1.at(2)*P1.at(2)) * std::sqrt(PSum.at(0)*PSum.at(0) + PSum.at(1)*PSum.at(1) + PSum.at(2)*PSum.at(2))); } KFParticleSIMD SimpleFinder::ConstructMother(const KFPTrack &track1, const int pid1, const KFPTrack &track2, const int pid2) const @@ -202,7 +202,7 @@ float SimpleFinder::CalculateCosTopo(const KFParticleSIMD& mother) const const float delta_z = z_mother - prim_vx_.GetZ(); const float sp = delta_x*px_mother + delta_y*py_mother + delta_z*pz_mother; - const float norm = sqrt(delta_x*delta_x + delta_y*delta_y + delta_z*delta_z) * sqrt(px_mother*px_mother + py_mother*py_mother + pz_mother*pz_mother); + const float norm = std::sqrt(delta_x*delta_x + delta_y*delta_y + delta_z*delta_z) * std::sqrt(px_mother*px_mother + py_mother*py_mother + pz_mother*pz_mother); return sp/norm; } @@ -291,7 +291,7 @@ void SimpleFinder::FindParticles() if((cuts_.GetIsApplyCutLDown())&&(lambda.GetL() <= cuts_.GetCutLDown())) continue; lambda.SetChi2Topo(CalculateChi2Topo(mother)); - if((cuts_.GetIsApplyCutChi2Topo())&&(lambda.GetChi2Topo() > cuts_.GetCutChi2Topo()) || lambda.GetChi2Topo()!=lambda.GetChi2Topo()) continue; + if((cuts_.GetIsApplyCutChi2Topo() && lambda.GetChi2Topo() > cuts_.GetCutChi2Topo()) || lambda.GetChi2Topo()!=lambda.GetChi2Topo()) continue; KFParticle particle; mother.GetKFParticle(particle, 0); -- GitLab From 6fbb96ad1b457eddc30cae26b4bc91cc725826a9 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Tue, 21 Jul 2020 01:46:56 +0200 Subject: [PATCH 14/20] main exe properly linking --- AnalysisTreeInterface/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnalysisTreeInterface/CMakeLists.txt b/AnalysisTreeInterface/CMakeLists.txt index 2611bbf..a9f1c26 100644 --- a/AnalysisTreeInterface/CMakeLists.txt +++ b/AnalysisTreeInterface/CMakeLists.txt @@ -23,7 +23,7 @@ add_target_property(KFMan COMPILE_FLAGS "-DDO_TPCCATRACKER_EFF_PERFORMANCE -DNon add_executable(main main.cxx) add_dependencies(main KFMan) -target_link_libraries(main KFMan KFParticleSimple KFParticleInterface) +target_link_libraries(main KFMan KFParticleSimple KFParticleInterface KFParticleSimple Vc) install(TARGETS KFMan EXPORT KFManTargets LIBRARY DESTINATION lib -- GitLab From a0d9f339d7d5a852a80a9cf201d34c4c5c0adac7 Mon Sep 17 00:00:00 2001 From: Oleksii Lubynets Date: Tue, 21 Jul 2020 01:50:47 +0200 Subject: [PATCH 15/20] correct typo --- AnalysisTreeInterface/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnalysisTreeInterface/CMakeLists.txt b/AnalysisTreeInterface/CMakeLists.txt index a9f1c26..1919db2 100644 --- a/AnalysisTreeInterface/CMakeLists.txt +++ b/AnalysisTreeInterface/CMakeLists.txt @@ -23,7 +23,7 @@ add_target_property(KFMan COMPILE_FLAGS "-DDO_TPCCATRACKER_EFF_PERFORMANCE -DNon add_executable(main main.cxx) add_dependencies(main KFMan) -target_link_libraries(main KFMan KFParticleSimple KFParticleInterface KFParticleSimple Vc) +target_link_libraries(main KFMan KFParticleSimple KFParticleInterface KFParticle Vc) install(TARGETS KFMan EXPORT KFManTargets LIBRARY DESTINATION lib -- GitLab From 027d0399aa034b8eb51b6f564fa3aec28252feb7 Mon Sep 17 00:00:00 2001 From: Viktor Klochkov Date: Wed, 22 Jul 2020 16:12:50 +0200 Subject: [PATCH 16/20] rm flag -march=native due to problem with compilation on Kronos --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fb620c..5c1c75c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,8 @@ endif () # set(CMAKE_CXX_FLAGS_DEBUG "-O0 -ggdb -g -DDEBUG -D__DEBUG -Wall") set(CMAKE_CXX_FLAGS_DEBUG "-O0 -ggdb -DDEBUG -D__DEBUG -Wall") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} -ggdb") -set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -ftree-vectorize -ffast-math -DNODEBUG") +# set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -ftree-vectorize -ffast-math -DNODEBUG") +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ftree-vectorize -ffast-math -DNODEBUG") message(STATUS "Using CXX flags for ${CMAKE_BUILD_TYPE}: ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}") list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS}) -- GitLab From 90f406c9baf4bf275171a396c8ea00ac4f85bbda Mon Sep 17 00:00:00 2001 From: Lubynets Date: Thu, 23 Jul 2020 14:33:01 +0200 Subject: [PATCH 17/20] add executable installation --- AnalysisTreeInterface/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AnalysisTreeInterface/CMakeLists.txt b/AnalysisTreeInterface/CMakeLists.txt index 1919db2..a73aaa0 100644 --- a/AnalysisTreeInterface/CMakeLists.txt +++ b/AnalysisTreeInterface/CMakeLists.txt @@ -50,3 +50,4 @@ install( lib OPTIONAL ) +install (TARGETS main RUNTIME DESTINATION bin) \ No newline at end of file -- GitLab From 0c23ffdcd54d786e47d07be64582b9c668b191e9 Mon Sep 17 00:00:00 2001 From: Lubynets Date: Thu, 23 Jul 2020 14:33:49 +0200 Subject: [PATCH 18/20] fix error with covmatrix calculation --- AnalysisTreeInterface/ConverterIn.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AnalysisTreeInterface/ConverterIn.cpp b/AnalysisTreeInterface/ConverterIn.cpp index 6feb829..a04d33a 100644 --- a/AnalysisTreeInterface/ConverterIn.cpp +++ b/AnalysisTreeInterface/ConverterIn.cpp @@ -67,7 +67,7 @@ InputContainer ConverterIn::CreateInputContainer() const { FillParticle(rec_track, input_container); n_good_tracks++; } - std::cout << "Good tracks = " << n_good_tracks << std::endl; + std::cout << "Good tracks = " << n_good_tracks << "\n" << std::endl; return input_container; } @@ -102,7 +102,7 @@ std::vector ConverterIn::GetCovMatrixCbm(const AnalysisTree::Track& parti for(int j = 0; j < kNumberOfTrackPars; j++) { VFT[i][j] = 0; for(int k = 0; k < 5; k++) { - VFT[i][j] += particle.GetField(cov_field_id_ + k + i * (std::max(i, k) + 1) / 2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; + VFT[i][j] += particle.GetField(cov_field_id_ + std::min(i, k) + std::max(i, k) * (std::max(i, k) + 1) / 2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; // if(k <= i) // VFT[i][j] += particle.GetField(cov_field_id_ + k + i * (i + 1) / 2) * F[j][k]; //parameters->GetCovariance(i,k) * F[j][k]; // else -- GitLab From 8f083dd2716bdda6ed4b47648b22eb9e1b7c6455 Mon Sep 17 00:00:00 2001 From: Lubynets Date: Thu, 23 Jul 2020 14:34:48 +0200 Subject: [PATCH 19/20] fix error with cuts transfer, rm extra tree fill --- AnalysisTreeInterface/PFTaskManager.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/AnalysisTreeInterface/PFTaskManager.cpp b/AnalysisTreeInterface/PFTaskManager.cpp index 82fccb2..6dd7f14 100644 --- a/AnalysisTreeInterface/PFTaskManager.cpp +++ b/AnalysisTreeInterface/PFTaskManager.cpp @@ -7,12 +7,10 @@ void PFTaskManager::Run(long long int nEvents) { for (long long iEvent = 0; iEvent < nEvents; ++iEvent) { in_tree_->GetEntry(iEvent); - if(( iEvent+1) % 100 == 0) { - std::cout << "Event # " << iEvent+1 << " out of " << nEvents << "\r" << std::flush; - } + std::cout << "Event # " << iEvent << " out of " << nEvents << std::endl; auto* converter_in = ((ConverterIn*)tasks_.at(kInConverter)); - converter_in->SetCuts(cuts_); + SetCuts(converter_in->GetCuts()); SimpleFinder FCFinder; FCFinder.Init(converter_in->CreateInputContainer()); @@ -24,6 +22,6 @@ void PFTaskManager::Run(long long int nEvents) { converter_out->SetCandidates(FCFinder.GetLambdas()); converter_out->Exec(); - out_tree_->Fill(); +// out_tree_->Fill(); } // Event loop } -- GitLab From 8547519b87b8fa9b7fde2e51981905944ddac48a Mon Sep 17 00:00:00 2001 From: Lubynets Date: Thu, 23 Jul 2020 14:35:57 +0200 Subject: [PATCH 20/20] set default KFPF cuts (as example) --- AnalysisTreeInterface/main.cxx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/AnalysisTreeInterface/main.cxx b/AnalysisTreeInterface/main.cxx index 299cdfb..6daa673 100644 --- a/AnalysisTreeInterface/main.cxx +++ b/AnalysisTreeInterface/main.cxx @@ -9,14 +9,11 @@ int main(int argc, char** argv) CutsContainer cuts; cuts.CancelCuts(); - cuts.SetCutChi2PrimPos(100.); - cuts.SetCutChi2PrimNeg(100.); - cuts.SetCutDistance(0.7); - cuts.SetCutCosineDaughterPos(0.95); - cuts.SetCutCosineDaughterNeg(0.9); + cuts.SetCutChi2PrimPos(3.); + cuts.SetCutChi2PrimNeg(3.); + cuts.SetCutDistance(1.); cuts.SetCutChi2Geo(3.); - cuts.SetCutLDown(3.); - cuts.SetCutLdL(7.); + cuts.SetCutLdL(5.); const std::string& filename = argv[1]; @@ -30,7 +27,7 @@ int main(int argc, char** argv) man.AddTasks(in_converter, new ConverterOut); man.Init(); - man.Run(10); // -1 = all events + man.Run(-1); // -1 = all events man.Finish(); return EXIT_SUCCESS; -- GitLab