File indexing completed on 2026-04-22 07:51:13
0001 #include <iostream>
0002 #include <fstream>
0003 #include <vector>
0004 #include <map>
0005 #include <utility>
0006 #include <ctype.h>
0007 #include <stdio.h>
0008 #include <stdlib.h>
0009 #include <unistd.h> // Add for use on Mac OS -> Same goes for Analyses.cc
0010 #include "TString.h"
0011 #include "TFile.h"
0012 #include "TTree.h"
0013 #include "TCanvas.h"
0014 #include "TF1.h"
0015 #include "TH1D.h"
0016 #include "TObjArray.h"
0017 #include "TObjString.h"
0018
0019 #include "Setup.h"
0020 #include "Calib.h"
0021 #include "Event.h"
0022 #include "Tile.h"
0023 #include "HGCROC.h"
0024 #include "Caen.h"
0025 #include "Analyses.h"
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<<"-a printing calib object to file (using name of output root or calib root file ending in txt)"<<std::endl;
0032 std::cout<<"-c xxx Convert ASCII input file xxx into root format output"<<std::endl;
0033 std::cout<<"-d [0-n] switch on debug info with debug level 0 to n"<<std::endl;
0034 std::cout<<"-f Force to write output if already exist"<<std::endl;
0035 std::cout<<"-i uuu Input file in root format"<<std::endl;
0036 std::cout<<"-L LLL enable testing with only limited number of events (currently only works for HGCROC)"<<std::endl;
0037 std::cout<<"-m www Name of mapping file 2024 PS TB [../configs/mappingFile_202409_CAEN.txt] "<<std::endl;
0038 std::cout<<"-o vvv Output file name (mandatory)"<<std::endl;
0039 std::cout<<"-O kkk Output directory name for plots (mandatory)"<<std::endl;
0040 std::cout<<"-r rrr Name of run list file 2024 PS TB [../configs/DataTakingDB_202409_CAEN.csv] "<<std::endl;
0041 std::cout<<"-y yyyy setting year externally to narrow parameters"<<std::endl;
0042 std::cout<<"-w Run HGCROC data conversion."<<std::endl;
0043 std::cout<<"-h this help"<<std::endl<<std::endl;
0044 std::cout<<"Examples:"<<std::endl;
0045 std::cout<<exe<<" -c (-f) input.txt -o output.root (Convert ASCII to root) (-f to overwrite existing output)"<<std::endl;
0046 }
0047
0048 int main(int argc, char* argv[]){
0049 if(argc<4) {
0050 PrintHelp(argv[0]);
0051 return 0;
0052 }
0053 Analyses AnAnalysis;
0054 int c;
0055 while((c=getopt(argc,argv,"ac:d:fi:L:m:o:O:r:ty:wh"))!=-1){
0056 switch(c){
0057 case 'a':
0058 std::cout<<"Convert: printing calib object to file"<<std::endl;
0059 AnAnalysis.IsCalibSaveToFile(true);
0060 break;
0061 case 'c':
0062 std::cout<<"Convert: Convert ASCII input '"<<optarg<<"' to root format"<<std::endl;
0063 AnAnalysis.SetASCIIinput(Form("%s",optarg));
0064 AnAnalysis.IsToConvert(true);
0065 break;
0066 case 'd':
0067 std::cout<<"Convert: enable debug " << optarg <<std::endl;
0068 AnAnalysis.EnableDebug(atoi(optarg));
0069 break;
0070 case 'f':
0071 std::cout<<"Convert: If output already exists it will be overwritten"<<std::endl;
0072 AnAnalysis.CanOverWrite(true);
0073 break;
0074 case 'i':
0075 std::cout<<"Convert: Root input file is: "<<optarg<<std::endl;
0076 AnAnalysis.SetRootInput(Form("%s",optarg));
0077 break;
0078 case 'L':
0079 std::cout<<"Convert: SetMaxEvents processed:"<<optarg<<std::endl;
0080 AnAnalysis.SetMaxEvents(atoi(optarg));
0081 break;
0082 case 'm':
0083 std::cout<<"Convert: Mapping file from: "<<optarg<<std::endl;
0084 AnAnalysis.SetMapInput(Form("%s",optarg));
0085 break;
0086 case 'o':
0087 std::cout<<"Convert: Output to be saved in: "<<optarg<<std::endl;
0088 AnAnalysis.SetRootOutput(Form("%s",optarg));
0089 break;
0090 case 'O':
0091 std::cout<<"Convert: Outputdir plots to be saved in: "<<optarg<<std::endl;
0092 AnAnalysis.SetPlotOutputDir(Form("%s",optarg));
0093 break;
0094 case 'r':
0095 std::cout<<"Convert: run list file from: "<<optarg<<std::endl;
0096 AnAnalysis.SetRunListInput(Form("%s",optarg));
0097 break;
0098 case 't':
0099 std::cout<<"Convert: enable trunction of last 2 bits HGCROC readout."<<std::endl;
0100 AnAnalysis.SetHGCROCTruncation(true);
0101 break;
0102 case 'y':
0103 std::cout<<"Convert: Setting year externally: "<<optarg<<std::endl;
0104 AnAnalysis.SetYear(atoi(optarg));
0105 break;
0106 case 'w':
0107 std::cout<<"Convert HGCROC data"<<std::endl;
0108 AnAnalysis.IsHGCROC(true);
0109 break;
0110 case '?':
0111 std::cout<<"Convert: Option "<<optarg <<" not supported, will be ignored "<<std::endl;
0112 break;
0113 case 'h':
0114 PrintHelp(argv[0]);
0115 return 0;
0116 }
0117 }
0118 if(!AnAnalysis.CheckAndOpenIO()){
0119 std::cout<<"Check input and configurations, inconsistency or error with I/O detected"<<std::endl;
0120 PrintHelp(argv[0]);
0121 return -1;
0122 }
0123
0124 AnAnalysis.Process();
0125 std::cout<<"Exiting"<<std::endl;
0126 return 0;
0127 }