File indexing completed on 2026-09-17 08:28:55
0001 #ifndef ANALYSES_H
0002 #define ANALYSES_H
0003
0004 #include <iostream>
0005 #include <fstream>
0006 #include "TString.h"
0007 #include "TFile.h"
0008 #include "TTree.h"
0009 #include "TObjString.h"
0010
0011 #include "Setup.h"
0012 #include "RootSetupWrapper.h"
0013 #include "Calib.h"
0014 #include "Event.h"
0015 #include "Tile.h"
0016 #include "HGCROC.h"
0017 #include "Caen.h"
0018
0019 class Analyses{
0020
0021 public:
0022 Analyses(){
0023 eventptr=&event;
0024 rswptr=&rsw;
0025 calibptr=&calib;
0026 }
0027 ~Analyses(){}
0028
0029
0030 inline TString GetASCIIinputName() const {return ASCIIinputName;};
0031 inline TString GetMapInputName() const {return MapInputName;};
0032 inline TString GetRootCalibInputName() const {return RootCalibInputName;};
0033 inline TString GetRootCalibOutputName() const {return RootCalibOutputName;};
0034 inline TString GetRootInputName() const {return RootInputName;};
0035 inline TString GetRootPedestalInputName() const {return RootPedestalInputName;};
0036 inline TString GetRootOutputName() const {return RootOutputName;};
0037 inline TString GetPlotOutputDir() const {return OutputNameDirPlots;};
0038 inline TString GetExternalBadChannelMap() const {return ExternalBadChannelMap;};
0039 inline TString GetExternalCalibFile() const {return ExternalCalibFile;};
0040 inline TString GetExternalToACalibOffSetFile() const {return ExternalToACalibOffSetFile;};
0041
0042 inline std::fstream* GetASCIIinput() {return &ASCIIinput;};
0043 inline std::fstream* GetMapInput() {return &MapInput;};
0044
0045 inline TFile* GetRootCalibInput() {return RootCalibInput;}
0046 inline TFile* GetRootInput() {return RootInput;}
0047 inline TFile* GetRootPedestalInput() {return RootPedestalInput;}
0048 inline TFile* GetRootOutput() {return RootOutput;}
0049
0050 inline bool CanOverWrite(void) const {return Overwrite;};
0051 inline bool IsToTransferCalib(void) const {return ApplyTransferCalib;};
0052 inline bool IsToApplyCalibration(void) const {return ApplyCalibration;};
0053 inline bool IsToVisualizeWaveform(void) const {return IsVisualizeWaveform;};
0054 inline bool IsToConvert(void) const {return Convert;};
0055 inline bool IsToExtractPedestal(void) const {return ExtractPedestal;};
0056 inline bool IsToExtractToAPhase(void) const {return ExtractToAPhase;};
0057 inline bool IsToExtractScaling(void) const {return ExtractScaling;};
0058 inline bool IsToExtractScalingImproved(void) const {return ExtractScalingImproved;};
0059 inline bool IsHGCROC(void) const {return HGCROC;};
0060
0061 inline bool IsToReextractNoise(void) const {return ReextractNoise;};
0062 inline bool IsToSaveNoiseOnly(void) const {return SaveNoiseOnly;};
0063 inline bool IsToSaveMipsOnly(void) const {return SaveMipsOnly;};
0064 inline bool IsToEvalLocalTrigg(void) const {return EvalLocalTriggers;};
0065 inline bool UseLocTriggFromFile(void) const {return LocTriggFile;};
0066 inline bool IsToSaveCalibOnly(void) const {return SaveCalibOnly;};
0067 inline bool IsCalibSaveToFile(void) const {return SaveCalibToFile;};
0068 inline bool IsToSkimHGCROC(void) const {return SkimHGCROC;};
0069 inline short GetCalcBadChannel(void) const {return CalcBadChannel;};
0070 inline short GetExtPlotting(void) const {return ExtPlot;};
0071 inline bool GetOverWriteCalib(void) const {return OverWriteCalib;};
0072 inline bool GetOverWriteSetup(void) const {return OverWriteSetup;};
0073 inline int GetMaxEvents(void) const {return maxEvents;};
0074 inline bool GetHGCROCTrunctation(void) const {return truncateHGCROC;};
0075 inline int GetHGCROCNSampleInteg(void) const {return nSampleHGCROCInt;};
0076 inline int GetHGCROCOptInteg(void) const {return optHGCROCInt;};
0077
0078 inline bool CheckOutputWriteStatus(void){
0079 bool status = true;
0080 TFile* outputFiles[] = {RootOutput, RootOutputHist, RootCalibOutput};
0081 for (TFile* output : outputFiles){
0082 if (!output) continue;
0083 if (output->IsOpen()) output->Flush();
0084 if (output->TestBit(TFile::kWriteError)){
0085 std::cerr << "ROOT write error detected for " << output->GetName() << std::endl;
0086 status = false;
0087 }
0088 }
0089 return status;
0090 };
0091
0092
0093
0094 inline void CanOverWrite(bool b) {Overwrite=b;};
0095 inline void IsCalibSaveToFile(bool b) {SaveCalibToFile=b;};
0096 inline void IsToTransferCalib(bool b) {ApplyTransferCalib=b;};
0097 inline void IsToVisualizeWaveform(bool b) {IsVisualizeWaveform=b;};
0098 inline void IsToApplyCalibration(bool b) {ApplyCalibration=b;};
0099 inline void IsToConvert(bool b) {Convert=b;};
0100 inline void IsToExtractPedestal(bool b) {ExtractPedestal=b;};
0101 inline void IsToExtractToAPhase(bool b) {ExtractToAPhase=b;};
0102 inline void IsToExtractScaling(bool b) {ExtractScaling=b;};
0103 inline void IsToExtractScalingImproved(bool b) {ExtractScalingImproved=b;};
0104 inline void IsHGCROC(bool b) {HGCROC=b;};
0105 inline void IsToReextractNoise(bool b) {ReextractNoise=b;};
0106 inline void IsToReextractLGHGCorr(bool b) {ReextractLGHGCorr=b;};
0107 inline void IsNoEventTree(bool b) {NoEventTreeWrite=b;};
0108
0109 inline void IsToSaveNoiseOnly(bool b) {SaveNoiseOnly = b;};
0110 inline void IsToSaveMipsOnly(bool b) {SaveMipsOnly = b;};
0111 inline void IsToEvalLocalTrigg(bool b) {EvalLocalTriggers = b;};
0112 inline void DisableRecalcTriggPrimitives() {EvalTriggerPrimitives = false;};
0113 inline void IsToSaveCalibOnly(bool b) {SaveCalibOnly = b;};
0114 inline void IsToSkimHGCROC(bool b) {SkimHGCROC = b;};
0115 inline void UseLocTriggFromFile(bool b) {LocTriggFile = b;};
0116 inline void SetCalcBadChannel(short b) {CalcBadChannel = b;};
0117 inline void SetOverWriteCalib(bool b) {OverWriteCalib = b;};
0118 inline void SetOverWriteSetup(bool b) {OverWriteSetup = b;};
0119 inline void SetExtPlotting(short b) {ExtPlot = b;};
0120 inline void SetCleanupEvents(short b) {EventCleanup = b;};
0121 inline void EnableDebug(int i) {debug=i;};
0122 inline void SetHGCROCTruncation(bool b) {truncateHGCROC = b;};
0123 inline void SetHGCROCNSampleInteg(int n) {optHGCROCInt = 1;
0124 nSampleHGCROCInt = n;
0125 };
0126 inline void SetHGCROCNSampleIntegForced(int n) {optHGCROCInt = 101;
0127 nSampleHGCROCInt = n;
0128 };
0129
0130 inline void SetYear(int year) {yearData=year;};
0131 inline void SetASCIIinput(TString name) {ASCIIinputName=name;};
0132 inline void SetMapInput(TString name) {MapInputName=name;};
0133 inline void SetRunListInput(TString name) {RunListInputName=name;};
0134 inline void SetRootCalibInput(TString name) {RootCalibInputName=name;};
0135 inline void SetRootCalibOutput(TString name) {RootCalibOutputName=name;};
0136 inline void SetRootInput(TString name) {RootInputName=name;};
0137 inline void SetRootPedestalInput(TString name) {RootPedestalInputName=name;};
0138 inline void SetRootOutput(TString name) {RootOutputName =name;};
0139 inline void SetRootOutputHists(TString name) {RootOutputNameHist =name;};
0140 inline void SetPlotOutputDir(TString name) {OutputNameDirPlots =name;};
0141 inline void SetPlotSkipLayer(int skip) {skipPlotLayer =skip;};
0142 inline void SetPlotExtension(TString name) {plotSuffix = name;};
0143 inline void SetExternalBadChannelMap(TString name) {ExternalBadChannelMap =name;};
0144 inline void SetExternalCalibFile(TString name) {ExternalCalibFile =name;};
0145 inline void SetExternalToACalibOffSetFile(TString name) {ExternalToACalibOffSetFile =name;};
0146 inline void SetMaxEvents(int n) {maxEvents = n;};
0147 inline void OverwriteMinMipFrac(double min) {minMipFrac = min;};
0148 inline void OverwriteMinFracTriggThre(double min) {minFracTriggThre = min;};
0149
0150
0151 bool CreateOutputRootFile(void);
0152 bool CreateOutputRootHistFile(void);
0153 bool CheckAndOpenIO(void);
0154 bool Process(void);
0155
0156
0157 TString ASCIIinputName;
0158 TString RootOutputName;
0159 TString RootOutputNameHist;
0160 TString OutputNameDirPlots;
0161 TString RootInputName;
0162 TString RootCalibInputName;
0163 TString RootCalibOutputName;
0164 TString RootPedestalInputName;
0165 TString MapInputName;
0166 TString RunListInputName;
0167 TString ExternalBadChannelMap;
0168 TString ExternalCalibFile;
0169 TString ExternalToACalibOffSetFile ="";
0170 TString plotSuffix = "pdf";
0171 TFile* RootOutput =nullptr;
0172 TFile* RootOutputHist =nullptr;
0173 TFile* RootInput =nullptr;
0174 TFile* RootPedestalInput =nullptr;
0175 TFile* RootCalibInput =nullptr;
0176 TFile* RootCalibOutput =nullptr;
0177 std::fstream ASCIIinput;
0178 std::fstream MapInput;
0179 bool Convert =false;
0180 bool HGCROC =false;
0181 bool ExtractPedestal =false;
0182 bool ExtractScaling =false;
0183 bool ExtractScalingImproved =false;
0184 bool ReextractNoise =false;
0185 bool ReextractLGHGCorr =false;
0186 bool NoEventTreeWrite =false;
0187 bool ExtractToAPhase =false;
0188 bool ApplyTransferCalib =false;
0189 bool IsVisualizeWaveform =false;
0190 bool ApplyCalibration =false;
0191 bool SaveNoiseOnly =false;
0192 bool SaveMipsOnly =false;
0193 bool SaveCalibOnly =false;
0194 bool SaveCalibToFile =false;
0195 bool SkimHGCROC =false;
0196 bool EvalLocalTriggers =false;
0197 bool EvalTriggerPrimitives =true;
0198 bool LocTriggFile =false;
0199 short CalcBadChannel =0;
0200 bool OverWriteCalib =false;
0201 bool OverWriteSetup =false;
0202 short ExtPlot =0;
0203 bool Overwrite =false;
0204 int debug =0;
0205 int skipPlotLayer = 0;
0206 int yearData =-1;
0207 bool truncateHGCROC =false;
0208 short EventCleanup = 0;
0209 double cleanupLGTh = 20;
0210 double cleanupHGTh = 150;
0211 double minMipFrac = 0.3;
0212 double minFracTriggThre = 3.;
0213 int optHGCROCInt = 0;
0214 int nSampleHGCROCInt = 1;
0215
0216 RootSetupWrapper rsw;
0217 RootSetupWrapper* rswptr;
0218 Setup* setup;
0219 Calib calib;
0220 Calib* calibptr;
0221 Event event;
0222 Event* eventptr;
0223 int maxEvents = -1;
0224
0225 TTree* TsetupIn=nullptr;
0226 TTree* TsetupOut=nullptr;
0227 TTree* TdataIn=nullptr;
0228 TTree* TdataOut=nullptr;
0229 TTree* TcalibIn=nullptr;
0230 TTree* TcalibOut=nullptr;
0231
0232 protected:
0233
0234
0235 private:
0236 bool ConvertASCII2Root(void);
0237 bool ConvertOldRootFile2Root(void);
0238 bool GetPedestal(void);
0239 bool EvaluateHGCROCToAPhases(void);
0240 bool TransferCalib(void);
0241 bool ReevaluateLGHGCorr(void);
0242 bool VisualizeWaveform(void);
0243 bool GetScaling(void);
0244 bool GetImprovedScaling(void);
0245 bool GetNoiseSampleAndRefitPedestal(void);
0246 bool RunEvalLocalTriggers(void);
0247 bool Calibrate(void);
0248 bool SaveNoiseTriggersOnly(void);
0249 bool SaveMuonTriggersOnly(void);
0250 bool SaveCalibToOutputOnly(void);
0251 bool SkimHGCROCData(void);
0252 bool OverWriteSetupTree(void);
0253
0254
0255 std::map<int,short> ReadExternalBadChannelMap(void);
0256 };
0257
0258
0259 #endif