File indexing completed on 2025-01-18 09:15:42
0001 #include <iostream>
0002 #include <fstream>
0003 #include <vector>
0004 #include <map>
0005 #include <utility>
0006
0007 #include "TString.h"
0008 #include "TFile.h"
0009 #include "TTree.h"
0010 #include "TCanvas.h"
0011 #include "TF1.h"
0012 #include "TH1D.h"
0013 #include "TObjArray.h"
0014 #include "TObjString.h"
0015
0016 #include "Setup.h"
0017 #include "Calib.h"
0018 #include "Event.h"
0019 #include "Tile.h"
0020 #include "HGCROC.h"
0021 #include "Caen.h"
0022 #include "Analyses.h"
0023
0024 Setup* Setup::instancePtr=nullptr;
0025
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<<"-c xxx Convert ASCII input file xxx into root format output"<<std::endl;
0032 std::cout<<"-C yyy Apply calibrations stored in yyy root file to the input uncalibrated file"<<std::endl;
0033 std::cout<<"-p Extract pedestal from input file and store it in output file"<<std::endl;
0034 std::cout<<"-y yyyy setting year externally to narrow parameters"<<std::endl;
0035 std::cout<<"-P zzz Correct pedestals stored in zzz root file and applied to input file"<<std::endl;
0036 std::cout<<"-i uuu Input file in root format"<<std::endl;
0037 std::cout<<"-o vvv Output file name (mandatory)"<<std::endl;
0038 std::cout<<"-O kkk Output directory name for plots (mandatory)"<<std::endl;
0039 std::cout<<"-b calculate bad channel map internally"<<std::endl;
0040 std::cout<<"-B lll apply external bad channel map during transfer of calibs"<<std::endl;
0041 std::cout<<"-s extract scaling constant from input data"<<std::endl;
0042 std::cout<<"-S extract scaling constant from input data in 2nd iteration based on pretriggered data"<<std::endl;
0043 std::cout<<"-N save noise triggered cells only"<<std::endl;
0044 std::cout<<"-M save mip triggered cells only"<<std::endl;
0045 std::cout<<"-f Force to write output if already exist"<<std::endl;
0046 std::cout<<"-m www Name of mapping file 2024 PS TB [../configs/mappingFile_202409_CAEN.txt] "<<std::endl;
0047 std::cout<<"-r rrr Name of run list file 2024 PS TB [../configs/DataTakingDB_202409_CAEN.csv] "<<std::endl;
0048 std::cout<<"-d [0-3] switch on debug info with debug level 0 to 3"<<std::endl;
0049 std::cout<<"-e extended plotting = 1"<<std::endl;
0050 std::cout<<"-E extended plotting = 2"<<std::endl;
0051 std::cout<<"-h this help"<<std::endl<<std::endl;
0052 std::cout<<"Examples:"<<std::endl;
0053 std::cout<<exe<<" -c input.txt -o output.root (Convert ASCII to root)"<<std::endl;
0054 std::cout<<exe<<" -p (-f) -o OutputWithExtractedPedestal.root -i input.root (-f to overwrite existing output)"<<std::endl;
0055 std::cout<<exe<<" -s (-f) -o OutputWithMIPscaling.root -i input.root (-f to overwrite existing output)"<<std::endl;
0056 std::cout<<exe<<" -S (-f) -o OutputWithMIPscaling.root -i input.root (-f to overwrite existing output)"<<std::endl;
0057 std::cout<<exe<<" -s (-f) -o OutputWithMIPscaling.root -P PedestalInput.root -i RawInput.root (-f to overwrite existing output)"<<std::endl;
0058 std::cout<<exe<<" -C Calibration.root (-f) -o CalibratedOutput.root -i Input.root (-f to overwrite existing output)"<<std::endl;
0059 }
0060
0061
0062 int main(int argc, char* argv[]){
0063 if(argc<4) {
0064 PrintHelp(argv[0]);
0065 return 0;
0066 }
0067 Analyses AnAnalysis;
0068 int c;
0069 while((c=getopt(argc,argv,"c:psP:SnbB:NMC:fo:O:aeEm:d:i:y:r:h"))!=-1){
0070 switch(c){
0071 case 'a':
0072 std::cout<<"printing calib object to file"<<std::endl;
0073 AnAnalysis.IsCalibSaveToFile(true);
0074 break;
0075 case 'c':
0076 std::cout<<"Convert ASCII input '"<<optarg<<"' to root format"<<std::endl;
0077 AnAnalysis.SetASCIIinput(Form("%s",optarg));
0078 AnAnalysis.IsToConvert(true);
0079 break;
0080 case 'p':
0081 std::cout<<"Extract pedestal from input data"<<std::endl;
0082 AnAnalysis.IsToExtractPedestal(true);
0083 break;
0084 case 's':
0085 std::cout<<"Extract scaling constant from input data"<<std::endl;
0086 AnAnalysis.IsToExtractScaling(true);
0087 break;
0088 case 'P':
0089 std::cout<<"Apply pedestal correction from: "<<optarg<<std::endl;
0090 AnAnalysis.SetRootPedestalInput(Form("%s",optarg));
0091 AnAnalysis.IsToApplyPedestalCorrection(true);
0092 break;
0093 case 'S':
0094 std::cout<<"Extract scaling improved from 2nd iteration"<<std::endl;
0095 AnAnalysis.IsToExtractScalingImproved(true);
0096 break;
0097 case 'n':
0098 std::cout<<"Extract noise after 1st mip fits and reevaluate pedestals"<<std::endl;
0099 AnAnalysis.IsToReextractNoise(true);
0100 break;
0101 case 'b':
0102 std::cout<<"run Bad channel determination"<<std::endl;
0103 AnAnalysis.SetCalcBadChannel(2);
0104 break;
0105 case 'B':
0106 std::cout<<"read bad channel map from external file: "<<optarg<<std::endl;
0107 AnAnalysis.SetExternalBadChannelMap(Form("%s",optarg));
0108 AnAnalysis.SetCalcBadChannel(1);
0109 break;
0110 case 'N':
0111 std::cout<<"Save noise only cells to create new pedestal"<<std::endl;
0112 AnAnalysis.IsToSaveNoiseOnly(true);
0113 break;
0114 case 'M':
0115 std::cout<<"Save mip triggered cells only to create minimal sample"<<std::endl;
0116 AnAnalysis.IsToSaveMipsOnly(true);
0117 break;
0118 case 'C':
0119 std::cout<<"Apply calibration (pedestal correction and scaling factor) from: "<<optarg<<std::endl;
0120 AnAnalysis.SetRootCalibInput(Form("%s",optarg));
0121 AnAnalysis.IsToApplyCalibration(true);
0122 break;
0123 case 'f':
0124 std::cout<<"If output already exists it will be overwritten"<<std::endl;
0125 AnAnalysis.CanOverWrite(true);
0126 break;
0127 case 'o':
0128 std::cout<<"Output to be saved in: "<<optarg<<std::endl;
0129 AnAnalysis.SetRootOutput(Form("%s",optarg));
0130 break;
0131 case 'O':
0132 std::cout<<"Outputdir plots to be saved in: "<<optarg<<std::endl;
0133 AnAnalysis.SetPlotOutputDir(Form("%s",optarg));
0134 break;
0135 case 'e':
0136 std::cout<<"enabling extended plotting"<<std::endl;
0137 AnAnalysis.SetExtPlotting(1);
0138 break;
0139 case 'E':
0140 std::cout<<"enabling more extended plotting"<<std::endl;
0141 AnAnalysis.SetExtPlotting(2);
0142 break;
0143 case 'm':
0144 std::cout<<"Mapping file from: "<<optarg<<std::endl;
0145 AnAnalysis.SetMapInput(Form("%s",optarg));
0146 break;
0147 case 'r':
0148 std::cout<<"run list file from: "<<optarg<<std::endl;
0149 AnAnalysis.SetRunListInput(Form("%s",optarg));
0150 break;
0151 case 'i':
0152 std::cout<<"Root input file is: "<<optarg<<std::endl;
0153 AnAnalysis.SetRootInput(Form("%s",optarg));
0154 break;
0155 case 'y':
0156 std::cout<<"Setting year externally: "<<optarg<<std::endl;
0157 AnAnalysis.SetYear(atoi(optarg));
0158 break;
0159 case 'd':
0160 std::cout<<"enable debug " << optarg <<std::endl;
0161 AnAnalysis.EnableDebug(atoi(optarg));
0162 break;
0163 case '?':
0164 std::cout<<"Option "<<optarg <<" not supported, will be ignored "<<std::endl;
0165 break;
0166 case 'h':
0167 PrintHelp(argv[0]);
0168 return 0;
0169 }
0170 }
0171 if(!AnAnalysis.CheckAndOpenIO()){
0172 std::cout<<"Check input and configurations, inconsistency or error with I/O detected"<<std::endl;
0173 PrintHelp(argv[0]);
0174 return -1;
0175 }
0176
0177 AnAnalysis.Process();
0178 std::cout<<"Exiting"<<std::endl;
0179 return 0;
0180 }