Browse Source

Added mcini optional support

ParfenovPeter 1 year ago
parent
commit
6ebf47cb62
5 changed files with 230 additions and 32 deletions
  1. 79 30
      CMakeLists.txt
  2. 17 2
      bin/main.cpp
  3. 3 0
      qaTools.LinkDef.h
  4. 84 0
      readers/qaReader_mcini.cxx
  5. 47 0
      readers/qaReader_mcini.h

+ 79 - 30
CMakeLists.txt

@@ -21,43 +21,92 @@ include(${ROOT_USE_FILE})
 
 add_definitions(${ROOT_CXX_FLAGS})
 
+#---Locate MCINI package
+find_library(MCINI NAMES McIniData PATHS $ENV{MCINI})
+IF(MCINI)
+  message(STATUS "mcini is found: ${MCINI}")
+  add_definitions("-D_MCINI_")
+endif()
+IF(NOT MCINI)
+  message(STATUS "mcini is not found. Building without it.")
+endif()
+
 set(CMAKE_BUILD_TYPE Debug)
 #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -Wall -pthread")
 # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -ffast-math")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall")
 
-set(QATOOLS_INCLUDE_DIRECTORIES
-  ${CMAKE_CURRENT_SOURCE_DIR}
-  ${CMAKE_CURRENT_SOURCE_DIR}/bin
-  ${CMAKE_CURRENT_SOURCE_DIR}/format
-  ${CMAKE_CURRENT_SOURCE_DIR}/readers
-  ${CMAKE_CURRENT_SOURCE_DIR}/utility
-  ${ROOT_INLCUDE_DIRS}
-)
-
-include_directories(${QATOOLS_INCLUDE_DIRECTORIES})
-
-set(QATOOLS_INCLUDE_LIBRARIES
-  ${ROOT_LIBRARIES}
-)
+if(NOT MCINI)
+  set(QATOOLS_INCLUDE_DIRECTORIES
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}/bin
+    ${CMAKE_CURRENT_SOURCE_DIR}/format
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers
+    ${CMAKE_CURRENT_SOURCE_DIR}/utility
+    ${ROOT_INLCUDE_DIRS}
+  )
+
+  set(QATOOLS_INCLUDE_LIBRARIES
+    ${ROOT_LIBRARIES}
+  )
+
+  set(QATOOLS_LIBRARY_h_files
+    ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticle.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/format/qaEvent.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_smash_root.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.h
+  )
+
+  set(QATOOLS_LIBRARY_cxx_files
+    ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticle.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/format/qaEvent.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_smash_root.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.cxx
+  )
+endif()
 
-set(QATOOLS_LIBRARY_h_files
-  ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticle.h
-  ${CMAKE_CURRENT_SOURCE_DIR}/format/qaEvent.h
-  ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_smash_root.h
-  ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.h
-  ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.h
-  ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.h
-)
+if(MCINI)
+  set(QATOOLS_INCLUDE_DIRECTORIES
+    ${CMAKE_CURRENT_SOURCE_DIR}
+    ${CMAKE_CURRENT_SOURCE_DIR}/bin
+    ${CMAKE_CURRENT_SOURCE_DIR}/format
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers
+    ${CMAKE_CURRENT_SOURCE_DIR}/utility
+    $ENV{MCINI}/include
+    ${ROOT_INLCUDE_DIRS}
+  )
+
+  set(QATOOLS_INCLUDE_LIBRARIES
+    ${ROOT_LIBRARIES}
+    ${MCINI}
+  )
+
+  set(QATOOLS_LIBRARY_h_files
+    ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticle.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/format/qaEvent.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_smash_root.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcini.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.h
+  )
+
+  set(QATOOLS_LIBRARY_cxx_files
+    ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticle.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/format/qaEvent.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_smash_root.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcini.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.cxx
+    ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.cxx
+  )
+endif()
 
-set(QATOOLS_LIBRARY_cxx_files
-  ${CMAKE_CURRENT_SOURCE_DIR}/format/qaParticle.cxx
-  ${CMAKE_CURRENT_SOURCE_DIR}/format/qaEvent.cxx
-  ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_smash_root.cxx
-  ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_mcpico.cxx
-  ${CMAKE_CURRENT_SOURCE_DIR}/readers/qaReader_manager.cxx
-  ${CMAKE_CURRENT_SOURCE_DIR}/utility/Utility.cxx
-)
+include_directories(${QATOOLS_INCLUDE_DIRECTORIES})
 
 set(QATOOLS_LinkDef
   ${CMAKE_CURRENT_SOURCE_DIR}/qaTools.LinkDef.h

+ 17 - 2
bin/main.cpp

@@ -15,13 +15,22 @@
 #include <qaReader_mcpico.h>
 #include <Utility.h>
 
+#ifdef _MCINI_
+#include <qaReader_mcini.h>
+#endif
+
 int main(int argc, char **argv)
 {
   TString iFileName, oFileName, configFileName = "";
 
   if (argc < 7)
   {
-    std::cerr << "./qaProcess -i input.list -o qa_output.root -format [mctree/particles] [OPTIONAL: -config qa.cfg]" << std::endl;
+    #ifndef _MCINI_
+    std::cerr << "./qaProcess -i input.list -o qa_output.root -format [mcpico/particles] [OPTIONAL: -config qa.cfg]" << std::endl;
+    #endif
+    #ifdef _MCINI_
+    std::cerr << "./qaProcess -i input.list -o qa_output.root -format [mcpico/mcini/particles] [OPTIONAL: -config qa.cfg]" << std::endl;
+    #endif
     return 1;
   }
   for (int i = 1; i < argc; i++)
@@ -186,10 +195,16 @@ int main(int argc, char **argv)
   }
 
   qaReader_manager *readerManager;
-  if (qaUtility::GetInstance()->format == "mctree")
+  if (qaUtility::GetInstance()->format == "mcpico")
   {
     readerManager = new qaReader_mcpico();
   }
+  #ifdef _MCINI_
+  if (qaUtility::GetInstance()->format == "mcini")
+  {
+    readerManager = new qaReader_mcini();
+  }
+  #endif
   if (qaUtility::GetInstance()->format == "particles")
   {
     readerManager = new qaReader_smash_root();

+ 3 - 0
qaTools.LinkDef.h

@@ -12,6 +12,9 @@
 #pragma link C++ class qaEvent+;
 #pragma link C++ class qaReader_smash_root+;
 #pragma link C++ class qaReader_mcpico+;
+#ifdef _MCINI_
+#pragma link C++ class qaReader_mcini+;
+#endif
 #pragma link C++ class qaReader_manager+;
 #pragma link C++ class qaUtility+;
 

+ 84 - 0
readers/qaReader_mcini.cxx

@@ -0,0 +1,84 @@
+#include <qaReader_mcini.h>
+
+ClassImp(qaReader_mcini);
+
+qaReader_mcini::qaReader_mcini(/* args */) : is_init(false), fCurrentEvent(-1), fEvent(nullptr), fParticle(nullptr)
+{
+}
+
+qaReader_mcini::~qaReader_mcini()
+{
+}
+
+Bool_t qaReader_mcini::ChainCheck()
+{
+  if (!is_init)
+  {
+    return false;
+  }
+
+  if (fCurrentEvent == -1)
+  {
+    return false;
+  }
+
+  if (!fChain->GetEntry(fCurrentEvent))
+  {
+    return false;
+  }
+
+  return true;
+}
+
+void qaReader_mcini::SetChain(const TString &inputFileName)
+{
+  fChain = (TChain *)qaUtility::GetInstance()->initChain(inputFileName, fChainName);
+
+  fChain->SetBranchAddress("event", &fEvent);
+
+  is_init = kTRUE;
+}
+
+qaEvent *qaReader_mcini::ReadEvent(Long64_t iev)
+{
+  fCurrentEvent = iev;
+
+  if (!ChainCheck())
+  {
+    return nullptr;
+  }
+
+  qaEvent *event = new qaEvent();
+
+  event->SetB(fEvent->GetB());
+  event->SetPhiRP(fEvent->GetPhi());
+  event->SetNparticles(fEvent->GetNpa());
+
+  return event;
+}
+
+qaParticle *qaReader_mcini::ReadParticle(Int_t ipart)
+{
+  if (!ChainCheck())
+  {
+    return nullptr;
+  }
+
+  if (ipart >= fEvent->GetNpa())
+  {
+    return nullptr;
+  }
+
+  fParticle = fEvent->GetParticle(ipart);
+  fMomentum = fParticle->GetMomentum();
+
+  qaParticle *particle = new qaParticle();
+
+  particle->SetEnergy(fMomentum.E());
+  particle->SetPdg(fParticle->GetPdg());
+  particle->SetPxPyPz(fMomentum.Px(), fMomentum.Py(), fMomentum.Pz());
+  particle->SetTime(0.);
+  particle->SetXYZ(0., 0., 0.);
+
+  return particle;
+}

+ 47 - 0
readers/qaReader_mcini.h

@@ -0,0 +1,47 @@
+#ifndef QATOOLS_READERS_MCINI_H
+#define QATOOLS_READERS_MCINI_H
+
+#include <Rtypes.h>
+#include <TChain.h>
+#include <TLorentzVector.h>
+
+#include <qaEvent.h>
+#include <qaParticle.h>
+#include <Utility.h>
+
+#include <qaReader_manager.h>
+
+#include <URun.h>
+#include <UEvent.h>
+#include <UParticle.h>
+#include <EventInitialState.h>
+
+class qaReader_mcini : virtual public qaReader_manager
+{
+private:
+  TChain *fChain;
+
+  const char *fChainName = "events";
+
+  bool is_init;
+  Long64_t fCurrentEvent;
+
+  UEvent *fEvent;
+  UParticle *fParticle;
+  TLorentzVector fMomentum;
+
+  Bool_t ChainCheck();
+
+public:
+  qaReader_mcini(/* args */);
+  virtual ~qaReader_mcini();
+
+  virtual void SetChain(const TString &inputFileName);
+  virtual Long64_t GetEntries() { return fChain->GetEntries(); }
+  virtual qaEvent *ReadEvent(Long64_t iev);
+  virtual qaParticle* ReadParticle(Int_t ipart);
+
+  ClassDef(qaReader_mcini, 0);
+};
+
+#endif