Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-07 09:25:18

0001 #include <iostream>
0002 #include <fstream>
0003 #include <vector>
0004 #include <map>
0005 #include <utility>
0006 #include <unistd.h> // Add for use on Mac OS -> Same goes for Analyses.cc
0007 #include <string>
0008 #include "TString.h"
0009 #include "TFile.h"
0010 #include "TTree.h"
0011 #include "TCanvas.h"
0012 #include "TF1.h"
0013 #include "TH1D.h"
0014 #include "TObjArray.h"
0015 #include "TObjString.h"
0016 
0017 #include "Setup.h"
0018 #include "Calib.h"
0019 #include "Event.h"
0020 #include "Tile.h"
0021 #include "HGCROC.h"
0022 #include "Caen.h"
0023 #include "CalibSampleParser.h"
0024 
0025 // read .csv files from H2GCROC calibration, and parse them into TTree
0026 
0027 void PrintHelp(char* exe){
0028   std::cout<<"Usage:"<<std::endl;
0029   std::cout<<exe<<" [-option (arguments)]"<<std::endl;
0030   std::cout<<"Options:"<<std::endl;
0031   std::cout<<"-d [0-n]  switch on debug info with debug level 0 to n"<<std::endl;
0032   std::cout<<"-i uuu    path to the input file: either .csv or config file with .json files for pedestal calib (mandatory)"<<std::endl;
0033   std::cout<<"-m        path to the mapping file (mandatory)"<<std::endl;
0034   std::cout<<"-r        path to the run list file (mandatory)"<<std::endl;
0035   std::cout<<"-n        run number to analyze (mandatory)"<<std::endl;
0036   std::cout<<"-p        setting the plot directory (for .csv file) (mandatory for plotting)"<<std::endl;
0037   std::cout<<"-o        output root filename, default same as input file"<<std::endl;
0038   std::cout<<"-c        path to .root file with calib object (mandatory for pedestal calib)"<<std::endl;
0039   std::cout<<"-h        print help"<<std::endl;
0040   std::cout<<"Examples:"<<std::endl;
0041   std::cout<<exe<<"-i input.csv -o output/"<<std::endl;
0042 }
0043 
0044 // inj_adc_samples_208_24_300.csv
0045 // channel, time, phase, ADC, TOT, ToA
0046 // time - 1.5625 increments, 0 - 248.4375, 160 steps
0047 // tree with tiles as branches, each tile - a different channel
0048 
0049 // two modes -
0050 //  1) read in .csv calib files, parse it into HGCROC tile; 
0051 //          required input: path to .csv file, mapping file, run list file and the run number, potentially plotting directory
0052 //  2) read in .json files and the pedestal values from HGCROC calibration, overwrite the pedestal values in existing calib object (preferably taken from pedestal calibration done with software)
0053 //          required input: mapping file, run list file and the run number, config file with "dead channels" (calib channels) and list of .json files with respective KCUs, .root file with calib object
0054 
0055 int main(int argc, char* argv[]){
0056     if(argc<1) {
0057         PrintHelp( argv[0] );
0058         return 0;
0059     }
0060 
0061     CalibSampleParser calibParser;
0062     int c;
0063     while( (c=getopt(argc,argv,"d:i:m:r:n:p:o:c:h:"))!=-1){
0064         switch(c){
0065             case 'd':
0066                 std::cout << "Enable debug " << optarg << std::endl;
0067                 calibParser.EnableDebug( atoi(optarg) );
0068                 break;
0069             case 'i':
0070                 std::cout << "Input file set to: " << optarg << std::endl;
0071                 calibParser.SetInputFile( Form("%s",optarg) );
0072                 break;
0073             case 'm':
0074                 std::cout << "Mapping file set to " << optarg << std::endl;
0075                 calibParser.SetMappingFile( Form("%s",optarg) );
0076                 break;
0077             case 'r':
0078                 std::cout << "Input list file set to " << optarg << std::endl;
0079                 calibParser.SetRunListInput( Form("%s",optarg) );
0080                 break;
0081             case 'n':
0082                 std::cout << "Run number set to " << optarg << std::endl;
0083                 calibParser.SetRunNumber ( atoi(optarg) );
0084                 break;
0085             case 'p':
0086                 std::cout << "Plotting directory set to " << optarg << std::endl;
0087                 calibParser.EnablePlotting();
0088                 calibParser.SetPlotDirectory( Form("%s",optarg) );
0089                 break;
0090             case 'o':
0091                 std::cout << "Output root filename set to: " << optarg << std::endl;
0092                 calibParser.SetOutputFilename( Form("%s", optarg) );
0093                 break;
0094             case 'c':
0095                 std::cout << "Reading in .csv file with pedestal values from H2GCalib"<<std::endl; // add path to the calib object from the other run
0096                 std::cout << "File with the calib object to switch the pedestal values: " << optarg << std::endl;
0097                 calibParser.SwitchPedestalCalib();
0098                 calibParser.SetInputCalibFile( Form("%s",optarg) );
0099                 break;
0100             case 'h':
0101                 PrintHelp( argv[0] );
0102                 return 0;
0103         }
0104     }
0105     if(!calibParser.CheckAndOpenIO()){
0106       std::cout<<"Check input and configurations, inconsistency or error with I/O detected"<<std::endl;
0107       PrintHelp(argv[0]);
0108       return -1;
0109     }
0110 
0111     calibParser.Process();
0112     std::cout<<"Exiting"<<std::endl;
0113     return 0;
0114 }
0115 
0116 
0117