File indexing completed on 2025-12-16 09:28: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 "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 void PrintHelp(char* exe){
0025 std::cout<<"Usage:"<<std::endl;
0026 std::cout<<exe<<" [-option (arguments)]"<<std::endl;
0027 std::cout<<"Options:"<<std::endl;
0028 std::cout<<"-a printing calib object to file (using name of output root or calib root file ending in txt)"<<std::endl;
0029 std::cout<<"-A aaa stripping only calib and setup object to external file"<<std::endl;
0030 std::cout<<"-b calculate bad channel map internally"<<std::endl;
0031 std::cout<<"-B lll apply external bad channel map during transfer of calibs"<<std::endl;
0032 std::cout<<"-C yyy Apply calibrations stored in yyy root file to the input uncalibrated file"<<std::endl;
0033 std::cout<<"-d [0-n] switch on debug info with debug level 0 to n"<<std::endl;
0034 std::cout<<"-e extended plotting = 1"<<std::endl;
0035 std::cout<<"-E extended plotting = 2"<<std::endl;
0036 std::cout<<"-f Force to write output if already exist"<<std::endl;
0037 std::cout<<"-F fff set explicit plot extension explicitly, default is pdf "<<std::endl;
0038 std::cout<<"-i uuu Input file in root format"<<std::endl;
0039 std::cout<<"-k kkk enabling overwriting of calib file using external calib txt file"<<std::endl;
0040 std::cout<<"-L LLL enable testing with only limited number of events"<<std::endl;
0041 std::cout<<"-m www Name of mapping file 2024 PS TB [../configs/mappingFile_202409_CAEN.txt] "<<std::endl;
0042 std::cout<<"-M save mip triggered cells only"<<std::endl;
0043 std::cout<<"-n extract noise after first mip fits and reevaluate pedestals"<<std::endl;
0044 std::cout<<"-N save noise triggered cells only"<<std::endl;
0045 std::cout<<"-o vvv Output file name (mandatory)"<<std::endl;
0046 std::cout<<"-O kkk Output directory name for plots (mandatory)"<<std::endl;
0047 std::cout<<"-p Extract pedestal from input file and store it in output file"<<std::endl;
0048 std::cout<<"-P zzz Correct pedestals stored in zzz root file and applied to input file"<<std::endl;
0049 std::cout<<"-r rrr Name of run list file 2024 PS TB [../configs/DataTakingDB_202409_CAEN.csv] "<<std::endl;
0050 std::cout<<"-s extract scaling constant from input data"<<std::endl;
0051 std::cout<<"-S extract scaling constant from input data in 2nd iteration based on pretriggered data"<<std::endl;
0052 std::cout<<"-t use local trigger eval from existing input, don't redo in calibrate"<<std::endl;
0053 std::cout<<"-T ttt evaluate local triggers before calibrating, use external calib file ttt"<<std::endl;
0054 std::cout<<"-w www Analyse waveform of HGCROC data with www as pedestal file"<<std::endl;
0055 std::cout<<"-X skim HGCROC events to a new file where there is at least a signal in the TOA "<<std::endl;
0056 std::cout<<"-y yyyy setting year externally to narrow parameters"<<std::endl;
0057 std::cout<<"-h this help"<<std::endl<<std::endl;
0058 std::cout<<"Examples:"<<std::endl;
0059 std::cout<<exe<<" -p (-f) -o OutputWithExtractedPedestal.root -i input.root (-f to overwrite existing output)"<<std::endl;
0060 std::cout<<exe<<" -s (-f) -o OutputWithMIPscaling.root -i input.root (-f to overwrite existing output)"<<std::endl;
0061 std::cout<<exe<<" -S (-f) -o OutputWithMIPscaling.root -i input.root (-f to overwrite existing output)"<<std::endl;
0062 std::cout<<exe<<" -s (-f) -o OutputWithMIPscaling.root -P PedestalInput.root -i RawInput.root (-f to overwrite existing output)"<<std::endl;
0063 std::cout<<exe<<" -C Calibration.root (-f) -o CalibratedOutput.root -i Input.root (-f to overwrite existing output)"<<std::endl;
0064 }
0065
0066
0067 int main(int argc, char* argv[]){
0068 if(argc<4) {
0069 PrintHelp(argv[0]);
0070 return 0;
0071 }
0072 Analyses AnAnalysis;
0073 int c;
0074 while((c=getopt(argc,argv,"c:F:pT:sk:P:SnbB:L:NtMC:fo:O:aA:eEm:d:i:w:Xy:r:h"))!=-1){
0075 switch(c){
0076 case 'a':
0077 std::cout<<"DataPrep: printing calib object to file"<<std::endl;
0078 AnAnalysis.IsCalibSaveToFile(true);
0079 break;
0080 case 'A':
0081 std::cout<<"DataPrep: stripping calib object to file: " << optarg<<std::endl;
0082 AnAnalysis.IsToSaveCalibOnly(true);
0083 AnAnalysis.SetRootCalibOutput(optarg);
0084 break;
0085 case 'b':
0086 std::cout<<"DataPrep: run Bad channel determination"<<std::endl;
0087 AnAnalysis.SetCalcBadChannel(2);
0088 break;
0089 case 'B':
0090 std::cout<<"DataPrep: read bad channel map from external file: "<<optarg<<std::endl;
0091 AnAnalysis.SetExternalBadChannelMap(Form("%s",optarg));
0092 AnAnalysis.SetCalcBadChannel(1);
0093 break;
0094 case 'C':
0095 std::cout<<"DataPrep: Apply calibration (pedestal correction and scaling factor) from: "<<optarg<<std::endl;
0096 AnAnalysis.SetRootCalibInput(Form("%s",optarg));
0097 AnAnalysis.IsToApplyCalibration(true);
0098 break;
0099 case 'd':
0100 std::cout<<"DataPrep: enable debug " << optarg <<std::endl;
0101 AnAnalysis.EnableDebug(atoi(optarg));
0102 break;
0103 case 'e':
0104 std::cout<<"DataPrep: enabling extended plotting"<<std::endl;
0105 AnAnalysis.SetExtPlotting(1);
0106 break;
0107 case 'E':
0108 std::cout<<"DataPrep: enabling more extended plotting"<<std::endl;
0109 AnAnalysis.SetExtPlotting(2);
0110 break;
0111 case 'f':
0112 std::cout<<"DataPrep: If output already exists it will be overwritten"<<std::endl;
0113 AnAnalysis.CanOverWrite(true);
0114 break;
0115 case 'F':
0116 std::cout<<"DataPrep: Set Plot extension to: "<< optarg<<std::endl;
0117 AnAnalysis.SetPlotExtension(optarg);
0118 break;
0119 case 'i':
0120 std::cout<<"DataPrep: Root input file is: "<<optarg<<std::endl;
0121 AnAnalysis.SetRootInput(Form("%s",optarg));
0122 break;
0123 case 'k':
0124 std::cout<<"DataPrep: enable overwrite from external text file: "<< optarg <<std::endl;
0125 AnAnalysis.SetExternalCalibFile(optarg);
0126 AnAnalysis.SetOverWriteCalib(true);
0127 break;
0128 case 'L':
0129 std::cout<<"DataPrep: SetMaxEvents processed:"<<optarg<<std::endl;
0130 AnAnalysis.SetMaxEvents(atoi(optarg));
0131 break;
0132 case 'm':
0133 std::cout<<"DataPrep: Mapping file from: "<<optarg<<std::endl;
0134 AnAnalysis.SetMapInput(Form("%s",optarg));
0135 break;
0136 case 'M':
0137 std::cout<<"DataPrep: Save mip triggered cells only to create minimal sample"<<std::endl;
0138 AnAnalysis.IsToSaveMipsOnly(true);
0139 break;
0140 case 'n':
0141 std::cout<<"DataPrep: Extract noise after 1st mip fits and reevaluate pedestals"<<std::endl;
0142 AnAnalysis.IsToReextractNoise(true);
0143 break;
0144 case 'N':
0145 std::cout<<"DataPrep: Save noise only cells to create new pedestal"<<std::endl;
0146 AnAnalysis.IsToSaveNoiseOnly(true);
0147 break;
0148 case 'o':
0149 std::cout<<"DataPrep: Output to be saved in: "<<optarg<<std::endl;
0150 AnAnalysis.SetRootOutput(Form("%s",optarg));
0151 break;
0152 case 'O':
0153 std::cout<<"DataPrep: Outputdir plots to be saved in: "<<optarg<<std::endl;
0154 AnAnalysis.SetPlotOutputDir(Form("%s",optarg));
0155 break;
0156 case 'p':
0157 std::cout<<"DataPrep: Extract pedestal from input data"<<std::endl;
0158 AnAnalysis.IsToExtractPedestal(true);
0159 break;
0160 case 'P':
0161 std::cout<<"DataPrep: transfer calib object from: "<<optarg<<std::endl;
0162 AnAnalysis.SetRootPedestalInput(Form("%s",optarg));
0163 AnAnalysis.IsToTransferCalib(true);
0164 break;
0165 case 'r':
0166 std::cout<<"DataPrep: run list file from: "<<optarg<<std::endl;
0167 AnAnalysis.SetRunListInput(Form("%s",optarg));
0168 break;
0169 case 's':
0170 std::cout<<"DataPrep: Extract scaling constant from input data"<<std::endl;
0171 AnAnalysis.IsToExtractScaling(true);
0172 break;
0173 case 'S':
0174 std::cout<<"DataPrep: Extract scaling improved from 2nd iteration"<<std::endl;
0175 AnAnalysis.IsToExtractScalingImproved(true);
0176 break;
0177 case 't':
0178 std::cout<<"DataPrep: run without trigger eval, use from file" <<std::endl;
0179 AnAnalysis.UseLocTriggFromFile(true);
0180 break;
0181 case 'T':
0182 std::cout<<"DataPrep: run local trigger, with calib file:" << optarg<<std::endl;
0183 AnAnalysis.IsToEvalLocalTrigg(true);
0184 AnAnalysis.SetRootCalibInput(Form("%s",optarg));
0185 break;
0186 case 'w':
0187 std::cout<<"DataPrep: analyse HGCROC waveform and apply pedestal from: "<<optarg<<std::endl;
0188 AnAnalysis.SetRootPedestalInput(Form("%s",optarg));
0189 AnAnalysis.IsToTransferCalib(true);
0190 AnAnalysis.IsToAnalysisWaveForm(true);
0191 break;
0192 case 'X':
0193 std::cout<<"DataPrep: Skim HGCROC data: "<<std::endl;
0194 AnAnalysis.IsToSkimHGCROC(true);
0195 break;
0196 case 'y':
0197 std::cout<<"DataPrep: Setting year externally: "<<optarg<<std::endl;
0198 AnAnalysis.SetYear(atoi(optarg));
0199 break;
0200 case '?':
0201 std::cout<<"DataPrep: Option "<<optarg <<" not supported, will be ignored "<<std::endl;
0202 break;
0203 case 'h':
0204 PrintHelp(argv[0]);
0205 return 0;
0206 }
0207 }
0208 if(!AnAnalysis.CheckAndOpenIO()){
0209 std::cout<<"Check input and configurations, inconsistency or error with I/O detected"<<std::endl;
0210 PrintHelp(argv[0]);
0211 return -1;
0212 }
0213
0214 AnAnalysis.Process();
0215 std::cout<<"Exiting"<<std::endl;
0216 return 0;
0217 }