Browse Source

First commit

Parfenov_Petr_Evgen'evich 11 months ago
commit
d6a9de1830
8 changed files with 397 additions and 0 deletions
  1. 75 0
      README.md
  2. 59 0
      macro/CMakeLists.txt
  3. 133 0
      macro/FemtoDstAnalyzer.C
  4. 60 0
      macro/main.cpp
  5. 32 0
      scripts/GenerateLists.sh
  6. 12 0
      scripts/run.sh
  7. 22 0
      scripts/start.sh
  8. 4 0
      set_env.sh

+ 75 - 0
README.md

@@ -0,0 +1,75 @@
+# Quick informatio
+***
+
+It is a simple example of scripts/macros sets suitable for work on the MEPhI (basov) cluster.
+
+## Setting environment
+
+Copy from a git repo:
+
+        git clone https://devel.mephi.ru/PEParfenov/hpc_scripts.git
+
+Change paths accordingly:
+
+* 1 In `set_env.sh`: Change `ST_FEMTO_DST_INC_DIR` to standard one. It's the directory where `libStFemtoDst.so` is stored.
+* 2 In `scripts/run.sh`: change path to a last line to one where your build will be.
+* 3 In `scripts/start.sh`: change path to output directory (`OUTPUT_DIR`).
+
+## Installation
+
+Source required environment variables:
+
+        cd hpc_scripts/
+        . set_env.sh
+
+Make new build directory. For example:
+
+        mkdir build/
+        cd build/
+
+Generate makefile & install:
+
+        cmake ../macro/
+        make
+
+Keep in mind that one has to do `make` command after changing `FemtoDstAnalyzer.C` in order to compile new code.
+
+## Generate filelists
+
+Use `GenerateLists.sh` to make filelists:
+
+        . GenerateLists.sh FEMTODST_DIR N_FILES_IN_LIST
+
+where `FEMTODST_DIR` - path to the directory with `femtoDst.root` files.
+And `N_FILES_IN_LIST` denotes the maximum number of `femtoDst.root` files in each filelist.
+Basic example:
+
+          . GenerateLists.sh /mnt/pool/rhic/2/nigmatkulov/femtoDst/auau/200gev/12135/ 100
+
+Resulting filelists will be in the `hpc_scripts/lists/` directory.
+
+## Usage
+
+### Interactive mode
+
+To use `FemtoDstAnalyzer.C` in interactive mode:
+
+        cd build/
+        ./FemtoDstAnalyzer -i INPUTFILE -o OUTPUTFILE
+
+where `INPUTFILE` - is input file or filelist with `femtoDst.root`.
+`OUTPUTFILE` - is resulting root file.
+Basic example:
+
+        ./FemtoDstAnalyzer -i ../lists/StRuns1.list -o ./test.root
+
+### Batch mode
+
+To send jobs to basov cluster, use `scripts/start.sh`:
+
+        . start.sh INPUT_FILELIST_DIR
+
+where `INPUT_FILELIST_DIR` - is the directory where you store filelists.
+Basic example:
+
+        . start.sh /mnt/pool/rhic/4/parfenovpeter/STAR/Analysis/hpc_scripts/lists

+ 59 - 0
macro/CMakeLists.txt

@@ -0,0 +1,59 @@
+# CMakeLists.txt for FAS package. It creates a library with dictionary and a main program
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
+project(FemtoDstAnalyzer)
+
+# You need to tell CMake where to find the ROOT installation. This can be done
+# in a number of ways:
+#   - ROOT built with classic configure/make use the provided
+#   $ROOTSYS/etc/cmake/FindROOT.cmake
+#   - ROOT built with CMake. Add in CMAKE_PREFIX_PATH the installation prefix
+#   for ROOT
+if (ROOT_CMAKE)
+  list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
+else (ROOT_CMAKE)
+  set(ROOT_PREINSTALLED "/usr/lib64/Geant4-10.3.0/Modules")
+  list(APPEND CMAKE_MODULE_PATH ${ROOT_PREINSTALLED})
+endif (ROOT_CMAKE)
+
+#---Locate the ROOT package and defines a number of variables (e.g. ROOT_INCLUDE_DIRS)
+if (ROOT_CMAKE)
+  find_package(ROOT REQUIRED COMPONENTS MathCore RIO Hist Tree Net
+	  HINTS ENV{PATH})
+else (ROOT_CMAKE)
+  find_package(ROOT REQUIRED COMPONENTS MathCore RIO Hist Tree Net)
+endif (ROOT_CMAKE)
+
+#---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)
+if (ROOT_CMAKE)
+  include(${ROOT_USE_FILE})
+endif (ROOT_CMAKE)
+
+
+#---Define _VANILLA_ROOT_ variable needed for the project
+#add_definitions(-D_VANILLA_ROOT_)
+
+set(ST_FEMTO_DST_LIB libStFemtoDst.so)
+set(ST_FEMTO_DST_CUSTOM_DIR $ENV{ST_FEMTO_DST_BUILD_DIR})
+set(ST_FEMTO_DST_CUSTOM_INC_DIR $ENV{ST_FEMTO_DST_INC_DIR})
+
+find_library(ST_FEMTO_DST REQUIRED
+	NAMES ${ST_FEMTO_DST_LIB}
+	HINTS ${ST_FEMTO_DST_CUSTOM_DIR})
+
+set(INCLUDE_DIRECTORIES
+  ${CMAKE_SOURCE_DIR}
+  ${ST_FEMTO_DST_CUSTOM_INC_DIR}
+  ${ROOT_INCLUDE_DIRS}
+)
+
+include_directories(${INCLUDE_DIRECTORIES})
+set (CMAKE_CXX_STANDARD 11)
+add_definitions(${ROOT_CXX_FLAGS})
+
+set(CMAKE_BUILD_TYPE Debug)
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
+
+#---Make executable
+
+add_executable(FemtoDstAnalyzer main.cpp)
+target_link_libraries(FemtoDstAnalyzer ${ST_FEMTO_DST} ${ROOT_LIBRARIES})

+ 133 - 0
macro/FemtoDstAnalyzer.C

@@ -0,0 +1,133 @@
+/**
+ * \brief Example of how to read a file (list of files) using StFemtoEvent classes
+ *
+ * RunFemtoDstAnalyzer.C is an example of reading FemtoDst format.
+ * One can use either FemtoDst file or a list of femtoDst files (inFile.lis or
+ * inFile.list) as an input, and preform physics analysis
+ *
+ * \author Grigory Nigmatkulov
+ * \date May 29, 2018
+ */
+
+// This is needed for calling standalone classes
+#define _VANILLA_ROOT_
+
+// C++ headers
+#include <iostream>
+
+// ROOT headers
+#include "TROOT.h"
+#include "TFile.h"
+#include "TChain.h"
+#include "TTree.h"
+#include "TSystem.h"
+#include "TH1.h"
+#include "TH2.h"
+#include "TMath.h"
+
+// FemtoDst headers
+#include "/mnt/pool/rhic/1/nigmatkulov/soft/StFemtoEvent/StFemtoDstReader.h"
+#include "/mnt/pool/rhic/1/nigmatkulov/soft/StFemtoEvent/StFemtoDst.h"
+#include "/mnt/pool/rhic/1/nigmatkulov/soft/StFemtoEvent/StFemtoEvent.h"
+#include "/mnt/pool/rhic/1/nigmatkulov/soft/StFemtoEvent/StFemtoTrack.h"
+
+// Load libraries (for ROOT_VERSTION_CODE >= 393215)
+#if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
+R__LOAD_LIBRARY(/mnt/pool/rhic/1/nigmatkulov/soft/StFemtoEvent/libStFemtoDst)
+#endif
+
+// inFile - is a name of name.FemtoDst.root file or a name
+//          of a name.lis(t) files, that contains a list of
+//          name1.FemtoDst.root, name2.FemtoDst.root, ... files
+
+//_________________
+void FemtoDstAnalyzer(const Char_t *inFile = "st_physics_12150008_raw_4030001.femtoDst.root",const Char_t *oFileName = "oTest.root") {
+
+  std::cout << "Hi! Lets do some physics, Master!" << std::endl;
+
+  #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0)
+    gSystem->Load("/mnt/pool/rhic/1/nigmatkulov/soft/StFemtoEvent/libStFemtoDst.so");
+  #endif
+
+  StFemtoDstReader* femtoReader = new StFemtoDstReader(inFile);
+  femtoReader->Init();
+
+  // This is a way if you want to spead up IO
+  std::cout << "Explicit read status for some branches" << std::endl;
+  femtoReader->SetStatus("*",0);
+  femtoReader->SetStatus("Event",1);
+  femtoReader->SetStatus("Track",1);
+  std::cout << "Status has been set" << std::endl;
+
+  std::cout << "Now I know what to read, Master!" << std::endl;
+
+  if( !femtoReader->chain() ) {
+    std::cout << "No chain has been found." << std::endl;
+  }
+  Long64_t eventsInTree = femtoReader->tree()->GetEntries();
+  std::cout << "eventsInTree: "  << eventsInTree << std::endl;
+  Long64_t events2read = femtoReader->chain()->GetEntries();
+
+  std::cout << "Number of events to read: " << events2read << std::endl;
+
+  // Loop over events
+  for(Long64_t iEvent=0; iEvent<events2read; iEvent++) {
+
+    std::cout << "Working on event #[" << (iEvent+1)
+      	      << "/" << events2read << "]" << std::endl;
+
+    Bool_t readEvent = femtoReader->readFemtoEvent(iEvent);
+    if( !readEvent ) {
+      std::cout << "Something went wrong, Master! Nothing to analyze..." << std::endl;
+      break;
+    }
+
+    // Retrieve femtoDst
+    StFemtoDst *dst = femtoReader->femtoDst();
+
+    // Retrieve event information
+    StFemtoEvent *event = dst->event();
+    if( !event ) {
+      std::cout << "Something went wrong, Master! Event is hiding from me..." << std::endl;
+      break;
+    }
+
+    // Return primary vertex position
+    TVector3 pVtx = event->primaryVertex();
+
+    // Reject vertices that are far from the central membrane along the beam
+    if( TMath::Abs( pVtx.Z() ) > 200. ) continue;
+
+    // Track analysis
+    Int_t nTracks = dst->numberOfTracks();
+
+    // Track loop
+    for(Int_t iTrk=0; iTrk<nTracks; iTrk++) {
+
+      // Retrieve i-th femto track
+      StFemtoTrack *femtoTrack = dst->track(iTrk);
+
+      if (!femtoTrack) continue;
+
+      // Must be a primary track
+      if ( !femtoTrack->isPrimary() ) continue;
+
+      // Simple single-track cut
+      if( femtoTrack->gMom().Mag() < 0.1 || femtoTrack->gDCA(pVtx).Mag() > 3. ) {
+	       continue;
+      }
+
+      // Check if track has TOF signal
+      if ( femtoTrack->isTofTrack() ) {
+
+      } //if( isTofTrack() )
+
+    } //for(Int_t iTrk=0; iTrk<nTracks; iTrk++)
+
+  } //for(Long64_t iEvent=0; iEvent<events2read; iEvent++)
+
+  femtoReader->Finish();
+
+  std::cout << "I'm done with analysis. We'll have a Nobel Prize, Master!"
+	          << std::endl;
+}

+ 60 - 0
macro/main.cpp

@@ -0,0 +1,60 @@
+#include <iostream>
+
+#include <TROOT.h>
+#include <TStopwatch.h>
+#include <TFile.h>
+#include <TString.h>
+
+#include "FemtoDstAnalyzer.C"
+
+int main(int argc, char** argv)
+{
+  TString inFileName, outFileName;
+  TStopwatch timer;
+  if (argc < 5)
+  {
+    std::cerr << "./FemtoDstAnalyzer -i INPUTFILE -o OUTPUTFILE" << std::endl;
+    return 10;
+  }
+
+  for (int i=1;i<argc;i++)
+  {
+    if (std::string(argv[i]) != "-i" &&
+        std::string(argv[i]) != "-o")
+    {
+      std::cerr << "\nUnknown parameter: " << argv[i] << std::endl;
+      return 11;
+    }
+    else
+    {
+      if (std::string(argv[i]) == "-i" && i != argc-1)
+      {
+        inFileName = TString(argv[++i]);
+      }
+      if (std::string(argv[i]) == "-i" && i == argc-1)
+      {
+        std::cerr << "\nInput file was not specified!" << std::endl;
+	return 12;
+      }
+      if (std::string(argv[i]) == "-o" && i != argc-1)
+      {
+        outFileName = TString(argv[++i]);
+      }
+      if (std::string(argv[i]) == "-o" && i == argc-1)
+      {
+        std::cerr << "\nOutput file was not specified!" << std::endl;
+	return 13;
+      }
+    }
+  }
+  if (inFileName == "" || outFileName == "")
+  {
+    std::cerr << "\nInput/Output file has not been set properly!" << std::endl;
+    return 14;
+  }
+
+  FemtoDstAnalyzer(inFileName.Data(),outFileName.Data());
+
+  return 0;
+}
+

+ 32 - 0
scripts/GenerateLists.sh

@@ -0,0 +1,32 @@
+#!/bin/bash
+
+#-Set path to the femtoDst files
+INPUT_DIR=$1
+#-Set the maximum number of files in 1 list
+NUM_DIVIDES=$2
+
+#-Example usage
+# . GenerateLists.sh /mnt/pool/rhic/2/nigmatkulov/femtoDst/auau/200gev/12135/ 100
+
+CURRENT_DIR=${PWD}
+OUTPUT_DIR="../lists"
+
+TOTAL_NUM_FILES=`ls $INPUT_DIR/*.femtoDst.root | wc -l`
+echo "Total number of DST files: ${TOTAL_NUM_FILES}"
+
+MULT=$((TOTAL_NUM_FILES / NUM_DIVIDES))
+RESIDUE=$((TOTAL_NUM_FILES % NUM_DIVIDES))
+
+echo "Mult: $MULT, Residue: $RESIDUE"
+
+for i in `seq 1 $MULT`
+do
+  OUTPUT_FILE=$OUTPUT_DIR/StRuns${i}.list
+  echo $OUTPUT_FILE
+  ls $INPUT_DIR/*.femtoDst.root | head -n$((i*NUM_DIVIDES)) | tail -n$NUM_DIVIDES &> $OUTPUT_FILE
+done
+
+#-Generate last filelist for residual files
+OUTPUT_FILE=$OUTPUT_DIR/StRuns$((i+1)).list
+echo $OUTPUT_FILE
+ls $INPUT_DIR/*.femtoDst.root |  tail -n$RESIDUE &> $OUTPUT_FILE

+ 12 - 0
scripts/run.sh

@@ -0,0 +1,12 @@
+#!/bin/bash
+
+INPUT_FILE=$1
+OUTPUT_FILE=$2
+LOG_FILE=$3
+
+echo "Arguments:"
+echo "Input: $INPUT_FILE"
+echo "Output: $OUTPUT_FILE"
+echo "Log: $LOG_FILE"
+
+/mnt/pool/rhic/4/parfenovpeter/STAR/Analysis/hpc_scripts/build/FemtoDstAnalyzer -i $INPUT_FILE -o $OUTPUT_FILE &> $LOG_FILE

+ 22 - 0
scripts/start.sh

@@ -0,0 +1,22 @@
+#!/bin/bash
+
+INPUT_LIST_DIR=$1
+OUTPUT_DIR=/mnt/pool/rhic/4/parfenovpeter/STAR/Analysis/hpc_scripts/OUT/`date '+%Y%m%d_%H%M%S'`
+
+QUEUE=medium
+
+mkdir -p $OUTPUT_DIR/log
+mkdir -p $OUTPUT_DIR/root
+mkdir -p $OUTPUT_DIR/sge_error
+mkdir -p $OUTPUT_DIR/sge_output
+
+ls -1 $INPUT_LIST_DIR/* | while read line
+do
+  OUTPUT_ROOT=$OUTPUT_DIR/root/$RUNID/`basename ${line%.*t}`.root
+  OUTPUT_LOG=$OUTPUT_DIR/log/$RUNID/`basename ${line%.*t}`.log
+  OUTPUT_O_SGE=$OUTPUT_DIR/sge_output/$RUNID/`basename ${line%.*t}`.out
+  OUTPUT_E_SGE=$OUTPUT_DIR/sge_error/$RUNID/`basename ${line%.*t}`.err
+
+  qsub -q $QUEUE -o $OUTPUT_O_SGE -e $OUTPUT_E_SGE run.sh -F "$line $OUTPUT_ROOT $INPUT_RECENTERING $OUTPUT_LOG"
+
+done

+ 4 - 0
set_env.sh

@@ -0,0 +1,4 @@
+#!/bin/bash
+
+export ST_FEMTO_DST_INC_DIR=/mnt/pool/rhic/4/parfenovpeter/STAR/StFemtoEvent
+export ST_FEMTO_DST_BUILD_DIR=$ST_FEMTO_DST_INC_DIR