Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-20 07:39:04

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   //Getter methods
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   
0076   //setter methods
0077   //Overload method for boolean...or is it too dangerous?
0078   inline void CanOverWrite(bool b)               {Overwrite=b;};
0079   inline void IsCalibSaveToFile(bool b)          {SaveCalibToFile=b;};
0080   inline void IsToTransferCalib(bool b)          {ApplyTransferCalib=b;};
0081   inline void IsToVisualizeWaveform(bool b)      {IsVisualizeWaveform=b;};
0082   inline void IsToApplyCalibration(bool b)       {ApplyCalibration=b;};
0083   inline void IsToConvert(bool b)                {Convert=b;};
0084   inline void IsToExtractPedestal(bool b)        {ExtractPedestal=b;};
0085   inline void IsToExtractToAPhase(bool b)        {ExtractToAPhase=b;};
0086   inline void IsToExtractScaling(bool b)         {ExtractScaling=b;};
0087   inline void IsToExtractScalingImproved(bool b) {ExtractScalingImproved=b;};
0088   inline void IsHGCROC(bool b)                   {HGCROC=b;};
0089   inline void IsToReextractNoise(bool b)         {ReextractNoise=b;};
0090   inline void IsToSaveNoiseOnly(bool b)          {SaveNoiseOnly = b;};
0091   inline void IsToSaveMipsOnly(bool b)           {SaveMipsOnly = b;};
0092   inline void IsToEvalLocalTrigg(bool b)         {EvalLocalTriggers = b;};
0093   inline void DisableRecalcTriggPrimitives()     {EvalTriggerPrimitives = false;};
0094   inline void IsToSaveCalibOnly(bool b)          {SaveCalibOnly = b;};
0095   inline void IsToSkimHGCROC(bool b)             {SkimHGCROC = b;};
0096   inline void UseLocTriggFromFile(bool b)        {LocTriggFile = b;};
0097   inline void SetCalcBadChannel(short b)         {CalcBadChannel = b;};
0098   inline void SetOverWriteCalib(bool b)          {OverWriteCalib = b;};
0099   inline void SetOverWriteSetup(bool b)          {OverWriteSetup = b;};
0100   inline void SetExtPlotting(short b)            {ExtPlot = b;};
0101   inline void EnableDebug(int i)                 {debug=i;};
0102   inline void SetHGCROCTruncation(bool b)        {truncateHGCROC = b;};
0103   
0104   
0105   inline void SetYear(int year)                  {yearData=year;};
0106   inline void SetASCIIinput(TString name)        {ASCIIinputName=name;};
0107   inline void SetMapInput(TString name)          {MapInputName=name;};
0108   inline void SetRunListInput(TString name)      {RunListInputName=name;};
0109   inline void SetRootCalibInput(TString name)    {RootCalibInputName=name;};
0110   inline void SetRootCalibOutput(TString name)   {RootCalibOutputName=name;};
0111   inline void SetRootInput(TString name)         {RootInputName=name;};
0112   inline void SetRootPedestalInput(TString name) {RootPedestalInputName=name;};
0113   inline void SetRootOutput(TString name)        {RootOutputName =name;};
0114   inline void SetRootOutputHists(TString name)   {RootOutputNameHist =name;};
0115   inline void SetPlotOutputDir(TString name)     {OutputNameDirPlots =name;};
0116   inline void SetPlotExtension(TString name)     {plotSuffix = name;};
0117   inline void SetExternalBadChannelMap(TString name)     {ExternalBadChannelMap =name;};
0118   inline void SetExternalCalibFile(TString name)     {ExternalCalibFile =name;};
0119   inline void SetExternalToACalibOffSetFile(TString name)     {ExternalToACalibOffSetFile =name;};  
0120   inline void SetMaxEvents(int n)                 {maxEvents = n;};
0121   inline void OverwriteMinMipFrac(double min)    {minMipFrac = min;};
0122   
0123   //General methods
0124   bool CreateOutputRootFile(void);
0125   bool CreateOutputRootHistFile(void);
0126   bool CheckAndOpenIO(void);
0127   bool Process(void);
0128 
0129   //Variable members
0130   TString ASCIIinputName;                 // CAEN ASCII file input name (only needed for converting data)
0131   TString RootOutputName;                 // file name of root output with tree
0132   TString RootOutputNameHist;             // file name of root output with additional histograms & fits
0133   TString OutputNameDirPlots;             // directory name of output for plots
0134   TString RootInputName;                  // file name of input root file 
0135   TString RootCalibInputName;             // file name of calibration root file (mip calib)
0136   TString RootCalibOutputName;            // file name of calibration root file (mip calib) output
0137   TString RootPedestalInputName;          // file name of pedestal root file (pedestal values)
0138   TString MapInputName;                   // file name geometry mapping
0139   TString RunListInputName;               // file name run list 
0140   TString ExternalBadChannelMap;          // file name external bad channel map
0141   TString ExternalCalibFile;              // file name external calib file
0142   TString ExternalToACalibOffSetFile =""; // file name external ToA calib offsets file  
0143   TString plotSuffix        = "pdf";      // plot extension
0144   TFile* RootOutput         =nullptr;     // root file output tree
0145   TFile* RootOutputHist     =nullptr;     // root file output histos
0146   TFile* RootInput          =nullptr;     // root file input 
0147   TFile* RootPedestalInput  =nullptr;     // root file pedestal values
0148   TFile* RootCalibInput     =nullptr;     // root file calib values (mip)
0149   TFile* RootCalibOutput    =nullptr;     // root file calib values (mip) output
0150   std::fstream ASCIIinput;                // ASCII file streamer for CAEN data
0151   std::fstream MapInput;                  // file streamer for geometry mapping
0152   bool Convert                =false;     // Flag for data conversion 
0153   bool HGCROC                 =false;     // Flag for HGCROC data conversion
0154   bool ExtractPedestal        =false;     // Flag for pedestal extraction
0155   bool ExtractScaling         =false;     // Flag for mip scaling extraction
0156   bool ExtractScalingImproved =false;     // Flag for mip scaling extraction 2nd pass
0157   bool ReextractNoise         =false;     // Flag to enable noise trigger extraction and alternative pass for pedestals
0158   bool ExtractToAPhase        =false;     // Flag to enable the ToA Phase extraction
0159   bool ApplyTransferCalib     =false;     // Flag for application of pedestals
0160   bool IsVisualizeWaveform    =false;     // Flag for routine with waveform visualization
0161   bool ApplyCalibration       =false;     // Flag for aplication of calibration
0162   bool SaveNoiseOnly          =false;     // Flag to reduce file to noise/pedestal only
0163   bool SaveMipsOnly           =false;     // Flag to reduce file to mips only
0164   bool SaveCalibOnly          =false;     // Flag to reduce file to mips only
0165   bool SaveCalibToFile        =false;     // Flag to save calib objects to text file
0166   bool SkimHGCROC             =false;     // Flag to skim HGCROC data from pure noise events
0167   bool EvalLocalTriggers      =false;     // Flag to run local trigger eval
0168   bool EvalTriggerPrimitives  =true;      // Flag to evaluate trigger primitives
0169   bool LocTriggFile           =false;     // Flag to use already evaluated triggeres
0170   short CalcBadChannel        =0;         // Flag to create bad channel map
0171   bool OverWriteCalib         =false;     // Flag to overwrite calib from text file
0172   bool OverWriteSetup         =false;     // Flag to overwrite setup from new mapping file
0173   short ExtPlot               =0;         // Enable extended plotting
0174   bool Overwrite              =false;     // Flag to overwrite outputs
0175   int debug                   =0;         // debug level 
0176   int yearData                =-1;        // data taking year externally set
0177   bool truncateHGCROC         =false;     // flag to enable the truncation of the HGCROC data to 8 bit (masking the 2 least significant bits)
0178   double minMipFrac           = 0.3;
0179   RootSetupWrapper rsw;                   // Wrapper singleton class for setup
0180   RootSetupWrapper* rswptr;               // Pointer to wrapper for singleton class for setup
0181   Setup* setup;                           // geometry setup
0182   Calib calib;                            // calibration object
0183   Calib* calibptr;                        // pointer to calib object
0184   Event event;
0185   Event* eventptr;
0186   int maxEvents               = -1;
0187   
0188   TTree* TsetupIn=nullptr;
0189   TTree* TsetupOut=nullptr;
0190   TTree* TdataIn=nullptr;
0191   TTree* TdataOut=nullptr;
0192   TTree* TcalibIn=nullptr;
0193   TTree* TcalibOut=nullptr;
0194 
0195  protected:
0196 
0197 
0198  private:
0199   bool ConvertASCII2Root(void);
0200   bool ConvertOldRootFile2Root(void);
0201   bool GetPedestal(void);
0202   bool EvaluateHGCROCToAPhases(void);
0203   bool TransferCalib(void);
0204   bool VisualizeWaveform(void);
0205   bool GetScaling(void);
0206   bool GetImprovedScaling(void);
0207   bool GetNoiseSampleAndRefitPedestal(void);
0208   bool RunEvalLocalTriggers(void);
0209   bool Calibrate(void);
0210   bool SaveNoiseTriggersOnly(void);
0211   bool SaveMuonTriggersOnly(void);
0212   bool SaveCalibToOutputOnly(void);
0213   bool SkimHGCROCData(void);
0214   bool OverWriteSetupTree(void);
0215 
0216   std::map<int,short> ReadExternalBadChannelMap(void);
0217  };
0218 
0219 
0220 #endif