diff --git a/apps/TrappingCorrection.cxx b/apps/TrappingCorrection.cxx index 5c43d86e..d952e0d5 100644 --- a/apps/TrappingCorrection.cxx +++ b/apps/TrappingCorrection.cxx @@ -64,7 +64,7 @@ using namespace ROOT::Minuit2; #include "MModuleEventFilter.h" #include "MModuleStripPairingChiSquare.h" #include "MModuleStripPairingMultiRoundChiSquare.h" -#include "MModuleTACcut.h" +#include "MModuleTACCalibration.h" #include "MAssembly.h" @@ -153,7 +153,6 @@ class TrappingCorrection MString m_FileName; MString m_EcalFile; MString m_TACCalFile; - MString m_TACCutFile; MString m_StripMapFile; //! output file names MString m_OutFile; @@ -277,7 +276,6 @@ bool TrappingCorrection::ParseCommandLine(int argc, char** argv) Usage<<" --emax: maximum Event energy (default 5000 kev)"< i+1) && (argv[i+1][0] != '-' || isalpha(argv[i+1][1]) == 0))){ cout<<"Error: Option "<SetTACCalFileName(m_TACCalFile); - TACCalibrator->SetTACCutFileName(m_TACCutFile); S->SetModule(TACCalibrator, MNumber); ++MNumber; diff --git a/apps/TrappingCorrectionAm241.cxx b/apps/TrappingCorrectionAm241.cxx index dadf4894..a873307e 100644 --- a/apps/TrappingCorrectionAm241.cxx +++ b/apps/TrappingCorrectionAm241.cxx @@ -60,7 +60,7 @@ using namespace std; #include "MModuleEventFilter.h" #include "MModuleStripPairingChiSquare.h" #include "MModuleStripPairingMultiRoundChiSquare.h" -#include "MModuleTACcut.h" +#include "MModuleTACCalibration.h" #include "MAssembly.h" @@ -106,7 +106,6 @@ class TrappingCorrectionAm241 MString m_LVFileName; MString m_EcalFile; MString m_TACCalFile; - MString m_TACCutFile; MString m_StripMapFile; //! output file names MString m_OutFile; @@ -159,7 +158,6 @@ bool TrappingCorrectionAm241::ParseCommandLine(int argc, char** argv) Usage<<" --emax: maximum Event energy (default 70 kev)"<SetTACCalFileName(m_TACCalFile); - TACCalibrator->SetTACCutFileName(m_TACCutFile); S->SetModule(TACCalibrator, MNumber); ++MNumber; - + cout<<"Creating energy calibrator"<SetFileName(m_EcalFile); diff --git a/include/MAssembly.h b/include/MAssembly.h index 396f5b13..e16eba2c 100644 --- a/include/MAssembly.h +++ b/include/MAssembly.h @@ -53,8 +53,8 @@ class MAssembly static const uint64_t c_EventLoaderMeasurement = (1 << 2); // = 4 static const uint64_t c_EventOrdering = (1 << 3); // = 8 static const uint64_t c_Coincidence = (1 << 4); // = 16 - static const uint64_t c_TACcut = (1 << 5); // = 32 - static const uint64_t c_NearestNeighbor = (1 << 6); // = 32 + static const uint64_t c_TACCalibration = (1 << 5); // = 32 + static const uint64_t c_NearestNeighbor = (1 << 6); // = 64 static const uint64_t c_DetectorEffectsEngine = (1 << 7); static const uint64_t c_EventFilter = (1 << 8); static const uint64_t c_EnergyCalibration = (1 << 9); diff --git a/include/MGUIOptionsTACcut.h b/include/MGUIOptionsTACCalibration.h similarity index 69% rename from include/MGUIOptionsTACcut.h rename to include/MGUIOptionsTACCalibration.h index d83df4cd..7c5ba401 100644 --- a/include/MGUIOptionsTACcut.h +++ b/include/MGUIOptionsTACCalibration.h @@ -1,5 +1,5 @@ /* - * MGUIOptionsTACcut.h + * MGUIOptionsTACCalibration.h * * Copyright (C) 2008-2010 by Jau-Shian Liang. * All rights reserved. @@ -9,8 +9,8 @@ */ -#ifndef __MGUIOptionsTACcut__ -#define __MGUIOptionsTACcut__ +#ifndef __MGUIOptionsTACCalibration__ +#define __MGUIOptionsTACCalibration__ //////////////////////////////////////////////////////////////////////////////// @@ -43,14 +43,14 @@ class MGUIEEntry; //////////////////////////////////////////////////////////////////////////////// -class MGUIOptionsTACcut : public MGUIOptions +class MGUIOptionsTACCalibration : public MGUIOptions { // public Session: public: //! Default constructor - MGUIOptionsTACcut(MModule* Module); + MGUIOptionsTACCalibration(MModule* Module); //! Default destructor - virtual ~MGUIOptionsTACcut(); + virtual ~MGUIOptionsTACCalibration(); //! Process all button, etc. messages virtual bool ProcessMessage(long Message, long Parameter1, long Parameter2); @@ -58,13 +58,22 @@ class MGUIOptionsTACcut : public MGUIOptions //! The creation part which gets overwritten virtual void Create(); + // protected methods: protected: //! Actions after the Apply or OK button has been pressed virtual bool OnApply(); + //! Toggle TAC cut radio buttons and coincidence window entry + void ToggleRadioButtons(int WidgetID); + //! Widget IDs + enum { + c_TACCutIgnore = 120, + c_TACCutApply = 121 + }; + // protected members: protected: //! The detector IDs as a string @@ -73,9 +82,14 @@ class MGUIOptionsTACcut : public MGUIOptions //! Select TAC Calibration file to load, converts readout timing to nanoseconds MGUIEFileSelector* m_TACCalFileSelector; - //! Select TAC Cut file to load, which specifies the parameters for removing strip hits - MGUIEFileSelector* m_TACCutFileSelector; + //! Do not apply TAC cuts + TGRadioButton* m_TACCutRBIgnore; + + //! Apply TAC cuts + TGRadioButton* m_TACCutRBApply; + //! TAC coincidence window in ns + MGUIEEntry* m_CoincidenceWindow; // private members: private: @@ -83,7 +97,7 @@ class MGUIOptionsTACcut : public MGUIOptions #ifdef ___CLING___ public: - ClassDef(MGUIOptionsTACcut, 1) // basic class for dialog windows + ClassDef(MGUIOptionsTACCalibration, 1) // basic class for dialog windows #endif }; diff --git a/include/MModuleTACcut.h b/include/MModuleTACCalibration.h similarity index 62% rename from include/MModuleTACcut.h rename to include/MModuleTACCalibration.h index 5dcd29ac..a56602d5 100644 --- a/include/MModuleTACcut.h +++ b/include/MModuleTACCalibration.h @@ -1,5 +1,5 @@ /* - * MModuleTACcut.h + * MModuleTACCalibration.h * * Copyright (C) by Andreas Zoglauer. * All rights reserved. @@ -9,90 +9,88 @@ */ -#ifndef __MModuleTACcut__ -#define __MModuleTACcut__ +#ifndef __MModuleTACCalibration__ +#define __MModuleTACCalibration__ //////////////////////////////////////////////////////////////////////////////// // Standard libs: -#include - -// ROOT libs: -#include "TGClient.h" -#include "TH1.h" // MEGAlib libs: #include "MGlobal.h" #include "MModule.h" -#include "MGUIExpoTACcut.h" -#include "MGUIExpoPlotSpectrum.h" // Forward declarations: +class MGUIExpoTACcut; +class MGUIExpoPlotSpectrum; //////////////////////////////////////////////////////////////////////////////// -class MModuleTACcut : public MModule +class MModuleTACCalibration : public MModule { // public interface: public: //! Default constructor - MModuleTACcut(); + MModuleTACCalibration(); //! Default destructor - virtual ~MModuleTACcut(); + virtual ~MModuleTACCalibration(); //! Create a new object of this class - virtual MModuleTACcut* Clone() { return new MModuleTACcut(); } + virtual MModuleTACCalibration* Clone() { return new MModuleTACCalibration(); } //! Initialize the module virtual bool Initialize(); - //! Create expos - virtual void CreateExpos(); - //! Finalize the module virtual void Finalize(); - //! Main data analysis routine, which updates the event to a new level - virtual bool AnalyzeEvent(MReadOutAssembly* Event); + //! Create Expos + virtual void CreateExpos(); //! Show the options GUI virtual void ShowOptionsGUI(); + //! Main data analysis routine, which updates the event to a new level + virtual bool AnalyzeEvent(MReadOutAssembly* Event); //! Read the configuration data from an XML node virtual bool ReadXmlConfiguration(MXmlNode* Node); + //! Create an XML node tree from the configuration virtual MXmlNode* CreateXmlConfiguration(); - ///////////// Creating functions that will update and get the min/max TAC values ////////////////////////// - //! Set filename for TAC calibration - void SetTACCalFileName( const MString& FileName) {m_TACCalFile = FileName;} + void SetTACCalFileName( const MString& FileName) { m_TACCalFile = FileName; } + //! Get filename for TAC calibration MString GetTACCalFileName() const {return m_TACCalFile;} - //! Set filename for TAC cut - void SetTACCutFileName( const MString& FileName) {m_TACCutFile = FileName;} - //! Get filename for TAC cut - MString GetTACCutFileName() const {return m_TACCutFile;} - //! Load the TAC calibration file bool LoadTACCalFile(MString FName); - //! Load the TAC cut file - bool LoadTACCutFile(MString FName); - //! Set the TAC calibration parameters void SetTACCalParameters(unordered_map>>> TACCal) { m_TACCal = TACCal; } //! Get the TAC calibration parameters unordered_map>>> GetTACCalParameters() { return m_TACCal; } + //! Enable or disable TAC cuts + void SetApplyTACCuts(bool ApplyTACCuts) { m_ApplyTACCuts = ApplyTACCuts; } + + //! Return whether TAC cuts are enabled + bool GetApplyTACCuts() const { return m_ApplyTACCuts; } + + //! Set TAC coincidence window in ns + void SetCoincidenceWindow(double CoincidenceWindow) { m_CoincidenceWindow = CoincidenceWindow; } + + //! Get TAC coincidence window in ns + double GetCoincidenceWindow() const { return m_CoincidenceWindow; } + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -104,6 +102,12 @@ class MModuleTACcut : public MModule // private methods: private: + //! Apply TAC calibration to strip hits + bool ApplyTACCal(MReadOutAssembly* Event); + + //! Apply TAC cuts to calibrated strip hits + //! Assumes ApplyTACCal() has already been called for this event + bool ApplyTACCuts(MReadOutAssembly* Event); // protected members: @@ -115,29 +119,29 @@ class MModuleTACcut : public MModule //! TAC calibration parameter file name MString m_TACCalFile; - //! TAC cut parameter files - MString m_TACCutFile; - //! Map DetID -> Side (LV=0, HV=1) -> Strip ID -> TAC calibration parameters unordered_map>>> m_TACCal; - //! Map DetID -> Side (LV=0, HV=1) -> Strip ID -> TAC cut parameters - unordered_map>>> m_TACCut; - - //! Map characters representing sides of the detectors indices to avoid mistakes + //! Map characters representing detector sides to LV/HV indices unordered_map m_SideToIndex; //! Vector of Detector IDs vector m_DetectorIDs; - MGUIExpoTACcut* m_ExpoTACcut; + //! TAC coincidence window in ns + double m_CoincidenceWindow; + //! Option to apply TAC cuts after TAC calibration + bool m_ApplyTACCuts; + + //! TAC distribution and energy spectra + MGUIExpoTACcut* m_ExpoTACcut; MGUIExpoPlotSpectrum* m_ExpoEnergySpectrum; #ifdef ___CLING___ public: - ClassDef(MModuleTACcut, 0) // no description + ClassDef(MModuleTACCalibration, 0) // no description #endif }; diff --git a/resource/unittestdata/406-1/hdf5-to-tra.nuclearizer.cfg b/resource/unittestdata/406-1/hdf5-to-tra.nuclearizer.cfg index f26a70d2..cec6db4d 100644 --- a/resource/unittestdata/406-1/hdf5-to-tra.nuclearizer.cfg +++ b/resource/unittestdata/406-1/hdf5-to-tra.nuclearizer.cfg @@ -3,7 +3,7 @@ XmlTagMeasurementLoaderHDF EnergyCalibration - XmlTagTACcut + XmlTagTACCalibration XmlTagStripPairingMultiRoundChiSquare DepthCalibration XmlTagRevan @@ -52,9 +52,14 @@ $(NUCLEARIZER)/resource/unittestdata/406-1/hp52406-1.revan.cfg - + $(NUCLEARIZER)/resource/unittestdata/406-1/hp52406-1.taccal.csv - $(NUCLEARIZER)/resource/unittestdata/406-1/hp52406-1.taccut.csv - + true + + 600 + + + + diff --git a/resource/unittestdata/406-1/hp52406-1.taccut.csv b/resource/unittestdata/406-1/hp52406-1.taccut.csv deleted file mode 100644 index 8a92b7cb..00000000 --- a/resource/unittestdata/406-1/hp52406-1.taccut.csv +++ /dev/null @@ -1,131 +0,0 @@ -# DetID,Strip voltage, StripID, Shaping Offset, Coincidence Window, Disable Time, Flag-to-enable Delay, FL noise cut, Flag delay -0,l,0,2255,500,1400,100,200,200 -0,l,1,2255,500,1400,100,200,200 -0,l,2,2255,500,1400,100,200,200 -0,l,3,2255,500,1400,100,200,200 -0,l,4,2255,500,1400,100,200,200 -0,l,5,2255,500,1400,100,200,200 -0,l,6,2255,500,1400,100,200,200 -0,l,7,2255,500,1400,100,200,200 -0,l,8,2255,500,1400,100,200,200 -0,l,9,2255,500,1400,100,200,200 -0,l,10,2255,500,1400,100,200,200 -0,l,11,2255,500,1400,100,200,200 -0,l,12,2255,500,1400,100,200,200 -0,l,13,2255,500,1400,100,200,200 -0,l,14,2255,500,1400,100,200,200 -0,l,15,2255,500,1400,100,200,200 -0,l,16,2255,500,1400,100,200,200 -0,l,17,2255,500,1400,100,200,200 -0,l,18,2255,500,1400,100,200,200 -0,l,19,2255,500,1400,100,200,200 -0,l,20,2255,500,1400,100,200,200 -0,l,21,2255,500,1400,100,200,200 -0,l,22,2255,500,1400,100,200,200 -0,l,23,2255,500,1400,100,200,200 -0,l,24,2255,500,1400,100,200,200 -0,l,25,2255,500,1400,100,200,200 -0,l,26,2255,500,1400,100,200,200 -0,l,27,2255,500,1400,100,200,200 -0,l,28,2255,500,1400,100,200,200 -0,l,29,2255,500,1400,100,200,200 -0,l,30,2255,500,1400,100,200,200 -0,l,31,2255,500,1400,100,200,200 -0,l,32,2255,500,1400,100,200,200 -0,l,33,2255,500,1400,100,200,200 -0,l,34,2255,500,1400,100,200,200 -0,l,35,2255,500,1400,100,200,200 -0,l,36,2255,500,1400,100,200,200 -0,l,37,2255,500,1400,100,200,200 -0,l,38,2255,500,1400,100,200,200 -0,l,39,2255,500,1400,100,200,200 -0,l,40,2255,500,1400,100,200,200 -0,l,41,2255,500,1400,100,200,200 -0,l,42,2255,500,1400,100,200,200 -0,l,43,2255,500,1400,100,200,200 -0,l,44,2255,500,1400,100,200,200 -0,l,45,2255,500,1400,100,200,200 -0,l,46,2255,500,1400,100,200,200 -0,l,47,2255,500,1400,100,200,200 -0,l,48,2255,500,1400,100,200,200 -0,l,49,2255,500,1400,100,200,200 -0,l,50,2255,500,1400,100,200,200 -0,l,51,2255,500,1400,100,200,200 -0,l,52,2255,500,1400,100,200,200 -0,l,53,2255,500,1400,100,200,200 -0,l,54,2255,500,1400,100,200,200 -0,l,55,2255,500,1400,100,200,200 -0,l,56,2255,500,1400,100,200,200 -0,l,57,2255,500,1400,100,200,200 -0,l,58,2255,500,1400,100,200,200 -0,l,59,2255,500,1400,100,200,200 -0,l,60,2255,500,1400,100,200,200 -0,l,61,2255,500,1400,100,200,200 -0,l,62,2255,500,1400,100,200,200 -0,l,63,2255,500,1400,100,200,200 -0,l,64,2255,500,1400,100,200,200 -0,h,65,2255,500,1400,100,200,200 -0,h,0,2255,500,1400,100,200,200 -0,h,1,2255,500,1400,100,200,200 -0,h,2,2255,500,1400,100,200,200 -0,h,3,2255,500,1400,100,200,200 -0,h,4,2255,500,1400,100,200,200 -0,h,5,2255,500,1400,100,200,200 -0,h,6,2255,500,1400,100,200,200 -0,h,7,2255,500,1400,100,200,200 -0,h,8,2255,500,1400,100,200,200 -0,h,9,2255,500,1400,100,200,200 -0,h,10,2255,500,1400,100,200,200 -0,h,11,2255,500,1400,100,200,200 -0,h,12,2255,500,1400,100,200,200 -0,h,13,2255,500,1400,100,200,200 -0,h,14,2255,500,1400,100,200,200 -0,h,15,2255,500,1400,100,200,200 -0,h,16,2255,500,1400,100,200,200 -0,h,17,2255,500,1400,100,200,200 -0,h,18,2255,500,1400,100,200,200 -0,h,19,2255,500,1400,100,200,200 -0,h,20,2255,500,1400,100,200,200 -0,h,21,2255,500,1400,100,200,200 -0,h,22,2255,500,1400,100,200,200 -0,h,23,2255,500,1400,100,200,200 -0,h,24,2255,500,1400,100,200,200 -0,h,25,2255,500,1400,100,200,200 -0,h,26,2255,500,1400,100,200,200 -0,h,27,2255,500,1400,100,200,200 -0,h,28,2255,500,1400,100,200,200 -0,h,29,2255,500,1400,100,200,200 -0,h,30,2255,500,1400,100,200,200 -0,h,31,2255,500,1400,100,200,200 -0,h,32,2255,500,1400,100,200,200 -0,h,33,2255,500,1400,100,200,200 -0,h,34,2255,500,1400,100,200,200 -0,h,35,2255,500,1400,100,200,200 -0,h,36,2255,500,1400,100,200,200 -0,h,37,2255,500,1400,100,200,200 -0,h,38,2255,500,1400,100,200,200 -0,h,39,2255,500,1400,100,200,200 -0,h,40,2255,500,1400,100,200,200 -0,h,41,2255,500,1400,100,200,200 -0,h,42,2255,500,1400,100,200,200 -0,h,43,2255,500,1400,100,200,200 -0,h,44,2255,500,1400,100,200,200 -0,h,45,2255,500,1400,100,200,200 -0,h,46,2255,500,1400,100,200,200 -0,h,47,2255,500,1400,100,200,200 -0,h,48,2255,500,1400,100,200,200 -0,h,49,2255,500,1400,100,200,200 -0,h,50,2255,500,1400,100,200,200 -0,h,51,2255,500,1400,100,200,200 -0,h,52,2255,500,1400,100,200,200 -0,h,53,2255,500,1400,100,200,200 -0,h,54,2255,500,1400,100,200,200 -0,h,55,2255,500,1400,100,200,200 -0,h,56,2255,500,1400,100,200,200 -0,h,57,2255,500,1400,100,200,200 -0,h,58,2255,500,1400,100,200,200 -0,h,59,2255,500,1400,100,200,200 -0,h,60,2255,500,1400,100,200,200 -0,h,61,2255,500,1400,100,200,200 -0,h,62,2255,500,1400,100,200,200 -0,h,63,2255,500,1400,100,200,200 diff --git a/resource/unittestdata/542-1/hdf5-to-tra.nuclearizer.cfg b/resource/unittestdata/542-1/hdf5-to-tra.nuclearizer.cfg index c7e75bdd..4ce9a804 100644 --- a/resource/unittestdata/542-1/hdf5-to-tra.nuclearizer.cfg +++ b/resource/unittestdata/542-1/hdf5-to-tra.nuclearizer.cfg @@ -3,7 +3,7 @@ XmlTagMeasurementLoaderHDF EnergyCalibration - XmlTagTACcut + XmlTagTACCalibration XmlTagStripPairingMultiRoundChiSquare DepthCalibration XmlTagRevan @@ -52,9 +52,14 @@ $(NUCLEARIZER)/resource/unittestdata/542-1/hp52542-1.revan.cfg - + $(NUCLEARIZER)/resource/unittestdata/542-1/hp52542-1.taccal.csv - $(NUCLEARIZER)/resource/unittestdata/542-1/hp52542-1.taccut.csv - + true + + 600 + + + + diff --git a/resource/unittestdata/542-1/hp52542-1.taccut.csv b/resource/unittestdata/542-1/hp52542-1.taccut.csv deleted file mode 100644 index 8a92b7cb..00000000 --- a/resource/unittestdata/542-1/hp52542-1.taccut.csv +++ /dev/null @@ -1,131 +0,0 @@ -# DetID,Strip voltage, StripID, Shaping Offset, Coincidence Window, Disable Time, Flag-to-enable Delay, FL noise cut, Flag delay -0,l,0,2255,500,1400,100,200,200 -0,l,1,2255,500,1400,100,200,200 -0,l,2,2255,500,1400,100,200,200 -0,l,3,2255,500,1400,100,200,200 -0,l,4,2255,500,1400,100,200,200 -0,l,5,2255,500,1400,100,200,200 -0,l,6,2255,500,1400,100,200,200 -0,l,7,2255,500,1400,100,200,200 -0,l,8,2255,500,1400,100,200,200 -0,l,9,2255,500,1400,100,200,200 -0,l,10,2255,500,1400,100,200,200 -0,l,11,2255,500,1400,100,200,200 -0,l,12,2255,500,1400,100,200,200 -0,l,13,2255,500,1400,100,200,200 -0,l,14,2255,500,1400,100,200,200 -0,l,15,2255,500,1400,100,200,200 -0,l,16,2255,500,1400,100,200,200 -0,l,17,2255,500,1400,100,200,200 -0,l,18,2255,500,1400,100,200,200 -0,l,19,2255,500,1400,100,200,200 -0,l,20,2255,500,1400,100,200,200 -0,l,21,2255,500,1400,100,200,200 -0,l,22,2255,500,1400,100,200,200 -0,l,23,2255,500,1400,100,200,200 -0,l,24,2255,500,1400,100,200,200 -0,l,25,2255,500,1400,100,200,200 -0,l,26,2255,500,1400,100,200,200 -0,l,27,2255,500,1400,100,200,200 -0,l,28,2255,500,1400,100,200,200 -0,l,29,2255,500,1400,100,200,200 -0,l,30,2255,500,1400,100,200,200 -0,l,31,2255,500,1400,100,200,200 -0,l,32,2255,500,1400,100,200,200 -0,l,33,2255,500,1400,100,200,200 -0,l,34,2255,500,1400,100,200,200 -0,l,35,2255,500,1400,100,200,200 -0,l,36,2255,500,1400,100,200,200 -0,l,37,2255,500,1400,100,200,200 -0,l,38,2255,500,1400,100,200,200 -0,l,39,2255,500,1400,100,200,200 -0,l,40,2255,500,1400,100,200,200 -0,l,41,2255,500,1400,100,200,200 -0,l,42,2255,500,1400,100,200,200 -0,l,43,2255,500,1400,100,200,200 -0,l,44,2255,500,1400,100,200,200 -0,l,45,2255,500,1400,100,200,200 -0,l,46,2255,500,1400,100,200,200 -0,l,47,2255,500,1400,100,200,200 -0,l,48,2255,500,1400,100,200,200 -0,l,49,2255,500,1400,100,200,200 -0,l,50,2255,500,1400,100,200,200 -0,l,51,2255,500,1400,100,200,200 -0,l,52,2255,500,1400,100,200,200 -0,l,53,2255,500,1400,100,200,200 -0,l,54,2255,500,1400,100,200,200 -0,l,55,2255,500,1400,100,200,200 -0,l,56,2255,500,1400,100,200,200 -0,l,57,2255,500,1400,100,200,200 -0,l,58,2255,500,1400,100,200,200 -0,l,59,2255,500,1400,100,200,200 -0,l,60,2255,500,1400,100,200,200 -0,l,61,2255,500,1400,100,200,200 -0,l,62,2255,500,1400,100,200,200 -0,l,63,2255,500,1400,100,200,200 -0,l,64,2255,500,1400,100,200,200 -0,h,65,2255,500,1400,100,200,200 -0,h,0,2255,500,1400,100,200,200 -0,h,1,2255,500,1400,100,200,200 -0,h,2,2255,500,1400,100,200,200 -0,h,3,2255,500,1400,100,200,200 -0,h,4,2255,500,1400,100,200,200 -0,h,5,2255,500,1400,100,200,200 -0,h,6,2255,500,1400,100,200,200 -0,h,7,2255,500,1400,100,200,200 -0,h,8,2255,500,1400,100,200,200 -0,h,9,2255,500,1400,100,200,200 -0,h,10,2255,500,1400,100,200,200 -0,h,11,2255,500,1400,100,200,200 -0,h,12,2255,500,1400,100,200,200 -0,h,13,2255,500,1400,100,200,200 -0,h,14,2255,500,1400,100,200,200 -0,h,15,2255,500,1400,100,200,200 -0,h,16,2255,500,1400,100,200,200 -0,h,17,2255,500,1400,100,200,200 -0,h,18,2255,500,1400,100,200,200 -0,h,19,2255,500,1400,100,200,200 -0,h,20,2255,500,1400,100,200,200 -0,h,21,2255,500,1400,100,200,200 -0,h,22,2255,500,1400,100,200,200 -0,h,23,2255,500,1400,100,200,200 -0,h,24,2255,500,1400,100,200,200 -0,h,25,2255,500,1400,100,200,200 -0,h,26,2255,500,1400,100,200,200 -0,h,27,2255,500,1400,100,200,200 -0,h,28,2255,500,1400,100,200,200 -0,h,29,2255,500,1400,100,200,200 -0,h,30,2255,500,1400,100,200,200 -0,h,31,2255,500,1400,100,200,200 -0,h,32,2255,500,1400,100,200,200 -0,h,33,2255,500,1400,100,200,200 -0,h,34,2255,500,1400,100,200,200 -0,h,35,2255,500,1400,100,200,200 -0,h,36,2255,500,1400,100,200,200 -0,h,37,2255,500,1400,100,200,200 -0,h,38,2255,500,1400,100,200,200 -0,h,39,2255,500,1400,100,200,200 -0,h,40,2255,500,1400,100,200,200 -0,h,41,2255,500,1400,100,200,200 -0,h,42,2255,500,1400,100,200,200 -0,h,43,2255,500,1400,100,200,200 -0,h,44,2255,500,1400,100,200,200 -0,h,45,2255,500,1400,100,200,200 -0,h,46,2255,500,1400,100,200,200 -0,h,47,2255,500,1400,100,200,200 -0,h,48,2255,500,1400,100,200,200 -0,h,49,2255,500,1400,100,200,200 -0,h,50,2255,500,1400,100,200,200 -0,h,51,2255,500,1400,100,200,200 -0,h,52,2255,500,1400,100,200,200 -0,h,53,2255,500,1400,100,200,200 -0,h,54,2255,500,1400,100,200,200 -0,h,55,2255,500,1400,100,200,200 -0,h,56,2255,500,1400,100,200,200 -0,h,57,2255,500,1400,100,200,200 -0,h,58,2255,500,1400,100,200,200 -0,h,59,2255,500,1400,100,200,200 -0,h,60,2255,500,1400,100,200,200 -0,h,61,2255,500,1400,100,200,200 -0,h,62,2255,500,1400,100,200,200 -0,h,63,2255,500,1400,100,200,200 diff --git a/src/MAssembly.cxx b/src/MAssembly.cxx index eb778940..2f3ae4cd 100644 --- a/src/MAssembly.cxx +++ b/src/MAssembly.cxx @@ -74,7 +74,7 @@ using namespace std; #include "MModuleSaverMeasurementsFITS.h" #include "MModuleResponseGenerator.h" #include "MModuleRevan.h" -#include "MModuleTACcut.h" +#include "MModuleTACCalibration.h" // #include "MModuleNearestNeighbor.h" #include "MModuleDiagnostics.h" #include "MModuleDiagnosticsEnergyPerStrip.h" @@ -145,7 +145,7 @@ MAssembly::MAssembly() m_Supervisor->AddAvailableModule(new MModuleTransmitterRealta()); m_Supervisor->AddAvailableModule(new MModuleResponseGenerator()); m_Supervisor->AddAvailableModule(new MModuleRevan()); - m_Supervisor->AddAvailableModule(new MModuleTACcut()); + m_Supervisor->AddAvailableModule(new MModuleTACCalibration()); // m_Supervisor->AddAvailableModule(new MModuleNearestNeighbor()); m_Supervisor->AddAvailableModule(new MModuleDiagnostics()); diff --git a/src/MGUIExpoPlotSpectrum.cxx b/src/MGUIExpoPlotSpectrum.cxx index 35ba3acc..ec3b052d 100644 --- a/src/MGUIExpoPlotSpectrum.cxx +++ b/src/MGUIExpoPlotSpectrum.cxx @@ -62,7 +62,11 @@ MGUIExpoPlotSpectrum::MGUIExpoPlotSpectrum(MModule* Module) : MGUIExpo(Module) // Set the new title of the tab here: if (Module != nullptr) { + if (Module->GetName() == "TAC Calibration") { + m_TabTitle = "Energy Spectrum (TAC cuts)"; + } else { m_TabTitle = "Energy Spectrum (" + Module->GetName() + ")"; + } } else { m_TabTitle = "Energy Spectrum"; } diff --git a/src/MGUIExpoTACcut.cxx b/src/MGUIExpoTACcut.cxx index ee6cf47b..66a491fb 100644 --- a/src/MGUIExpoTACcut.cxx +++ b/src/MGUIExpoTACcut.cxx @@ -2,7 +2,7 @@ * MGUIExpoTACcut.cxx * * - * Copyright (C) by Andreas Zoglauer, Nicole Rodriquez Cavero. + * Copyright (C) by Andreas Zoglauer, Nicole Rodriguez Cavero. * All rights reserved. * * @@ -49,7 +49,7 @@ MGUIExpoTACcut::MGUIExpoTACcut(MModule* Module) : MGUIExpo(Module) // standard constructor // Set the new title of the tab here: - m_TabTitle = "TAC Calibration"; + m_TabTitle = "TAC Cuts"; // Set the histogram arrangment // SetTACHistogramArrangement(1, 1); diff --git a/src/MGUIOptionsTACCalibration.cxx b/src/MGUIOptionsTACCalibration.cxx new file mode 100644 index 00000000..a3cbfba4 --- /dev/null +++ b/src/MGUIOptionsTACCalibration.cxx @@ -0,0 +1,251 @@ +/* + * MGUIOptionsTACCalibration.cxx + * + * + * Copyright (C) by Andreas Zoglauer, Nicole Rodriguez Cavero + * Sean Pike + * All rights reserved. + * + * + * This code implementation is the intellectual property of + * Sean Pike, Andreas Zoglauer, Nicole Rodriguez Cavero. + * + * By copying, distributing or modifying the Program (or any work + * based on the Program) you indicate your acceptance of this statement, + * and all its terms. + * + */ + + +// Include the header: +#include "MGUIOptionsTACCalibration.h" + +// Standard libs: + +// ROOT libs: +#include +#include +#include +#include +#include + +// MEGAlib libs: +#include "MStreams.h" +#include "MString.h" +#include "MGUIEFileSelector.h" +#include "MGUIEMinMaxEntry.h" +#include "MGUIEEntry.h" + +// Nuclearizer libs: +#include "MModuleTACCalibration.h" + + +//////////////////////////////////////////////////////////////////////////////// + + +#ifdef ___CLING___ +ClassImp(MGUIOptionsTACCalibration +) +#endif + + +//////////////////////////////////////////////////////////////////////////////// + + +MGUIOptionsTACCalibration::MGUIOptionsTACCalibration(MModule* Module) + : MGUIOptions(Module) +{ + // standard constructor +} + + +//////////////////////////////////////////////////////////////////////////////// + + +MGUIOptionsTACCalibration::~MGUIOptionsTACCalibration() +{ + // kDeepCleanup is activated +} + + +//////////////////////////////////////////////////////////////////////////////// + + +void MGUIOptionsTACCalibration::Create() +{ + PreCreate(); + + m_TACCalFileSelector = new MGUIEFileSelector( + m_OptionsFrame, + "Select a TAC Calibration file:", + dynamic_cast(m_Module)->GetTACCalFileName() + ); + + m_TACCalFileSelector->SetFileType("TAC", "*.csv"); + + TGLayoutHints* TACCalLayout = + new TGLayoutHints( + kLHintsTop | kLHintsCenterX | kLHintsExpandX, + 10, 10, 10, 10 + ); + + m_OptionsFrame->AddFrame(m_TACCalFileSelector, TACCalLayout); + + TGLayoutHints* LabelLayout = + new TGLayoutHints( + kLHintsTop | kLHintsLeft, + 10, 10, 10, 5 + ); + + TGLayoutHints* RBLayout = + new TGLayoutHints( + kLHintsTop | kLHintsLeft, + 20, 10, 5, 5 + ); + + TGLayoutHints* RBOptionLayout = + new TGLayoutHints( + kLHintsTop | kLHintsLeft | kLHintsExpandX, + 40, 10, 5, 10 + ); + + TGLabel* TACCutLabel = + new TGLabel(m_OptionsFrame, + "Please choose how to handle TAC cuts:"); + + m_OptionsFrame->AddFrame(TACCutLabel, LabelLayout); + + m_TACCutRBIgnore = + new TGRadioButton( + m_OptionsFrame, + "Do not apply TAC cuts", + c_TACCutIgnore + ); + + m_TACCutRBIgnore->Associate(this); + m_OptionsFrame->AddFrame(m_TACCutRBIgnore, RBLayout); + + m_TACCutRBApply = + new TGRadioButton( + m_OptionsFrame, + "Apply TAC cuts", + c_TACCutApply + ); + + m_TACCutRBApply->Associate(this); + m_OptionsFrame->AddFrame(m_TACCutRBApply, RBLayout); + + m_CoincidenceWindow = + new MGUIEEntry( + m_OptionsFrame, + "Set coincidence window [ns]:", + false, + dynamic_cast(m_Module)->GetCoincidenceWindow(), + true, + 0.0 + ); + + m_OptionsFrame->AddFrame( + m_CoincidenceWindow, + RBOptionLayout + ); + + bool ApplyTACCuts = dynamic_cast(m_Module)->GetApplyTACCuts(); + + if (ApplyTACCuts == true) { + ToggleRadioButtons(c_TACCutApply); + } else { + ToggleRadioButtons(c_TACCutIgnore); + } + + PostCreate(); +} + + +//////////////////////////////////////////////////////////////////////////////// + + +bool MGUIOptionsTACCalibration::ProcessMessage(long Message, long Parameter1, long Parameter2) +{ + // Modify here if you have more buttons + + bool Status = true; + + switch (GET_MSG(Message)) { + case kC_COMMAND: + switch (GET_SUBMSG(Message)) { + case kCM_BUTTON: + break; + + case kCM_RADIOBUTTON: + ToggleRadioButtons(Parameter1); + break; + + case kCM_CHECKBUTTON: + break; + + default: + break; + } + break; + default: + break; + } + + if (Status == false) { + return false; + } + + // Call also base class + return MGUIOptions::ProcessMessage(Message, Parameter1, Parameter2); +} + + +//////////////////////////////////////////////////////////////////////////////// + + +bool MGUIOptionsTACCalibration::OnApply() +{ + // Store the data in the module + dynamic_cast(m_Module)->SetTACCalFileName(m_TACCalFileSelector->GetFileName()); + + // Apply TAC cuts or not + if (m_TACCutRBIgnore->GetState() == kButtonDown) { + dynamic_cast(m_Module)-> + SetApplyTACCuts(false); + } else if (m_TACCutRBApply->GetState() == kButtonDown) { + dynamic_cast(m_Module)-> + SetApplyTACCuts(true); + } + + // Coincidence window + dynamic_cast(m_Module)-> + SetCoincidenceWindow( + m_CoincidenceWindow->GetAsDouble() + ); + return true; +} + +//////////////////////////////////////////////////////////////////////////////// + +void MGUIOptionsTACCalibration::ToggleRadioButtons(int WidgetID) +{ + if (WidgetID == c_TACCutIgnore) { + + m_TACCutRBIgnore->SetState(kButtonDown); + m_TACCutRBApply->SetState(kButtonUp); + + m_CoincidenceWindow->SetEnabled(false); + + } else if (WidgetID == c_TACCutApply) { + + m_TACCutRBIgnore->SetState(kButtonUp); + m_TACCutRBApply->SetState(kButtonDown); + + m_CoincidenceWindow->SetEnabled(true); + } +} + + +// MGUIOptionsTACCalibration: the end... +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/MGUIOptionsTACcut.cxx b/src/MGUIOptionsTACcut.cxx deleted file mode 100644 index 3b953acf..00000000 --- a/src/MGUIOptionsTACcut.cxx +++ /dev/null @@ -1,138 +0,0 @@ -/* - * MGUIOptionsTACcut -.cxx - * - * - * Copyright (C) by Andreas Zoglauer, Nicole Rodriguez Cavero - * Sean Pike - * All rights reserved. - * - * - * This code implementation is the intellectual property of - * Sean Pike, Andreas Zoglauer, Nicole Rodriguez Cavero. - * - * By copying, distributing or modifying the Program (or any work - * based on the Program) you indicate your acceptance of this statement, - * and all its terms. - * - */ - - -// Include the header: -#include "MGUIOptionsTACcut.h" - -// Standard libs: - -// ROOT libs: -#include -#include -#include -#include -#include - -// MEGAlib libs: -#include "MStreams.h" -#include "MString.h" -#include "MGUIEFileSelector.h" -#include "MGUIEMinMaxEntry.h" -#include "MGUIEEntry.h" - -// Nuclearizer libs: -#include "MModuleTACcut.h" - - -//////////////////////////////////////////////////////////////////////////////// - - -#ifdef ___CLING___ -ClassImp(MGUIOptionsTACcut -) -#endif - - -//////////////////////////////////////////////////////////////////////////////// - - -MGUIOptionsTACcut::MGUIOptionsTACcut(MModule* Module) - : MGUIOptions(Module) -{ - // standard constructor -} - - -//////////////////////////////////////////////////////////////////////////////// - - -MGUIOptionsTACcut::~MGUIOptionsTACcut() -{ - // kDeepCleanup is activated -} - - -//////////////////////////////////////////////////////////////////////////////// - - -void MGUIOptionsTACcut::Create() -{ - PreCreate(); - - m_TACCalFileSelector = new MGUIEFileSelector(m_OptionsFrame, "Select a TAC Calibration file:", dynamic_cast(m_Module)->GetTACCalFileName()); - m_TACCalFileSelector->SetFileType("TAC", "*.csv"); - TGLayoutHints* TACCalLayout = new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 10, 10, 10, 10); - m_OptionsFrame->AddFrame(m_TACCalFileSelector, TACCalLayout); - - m_TACCutFileSelector = new MGUIEFileSelector(m_OptionsFrame, "Select a TAC Cut file:", dynamic_cast(m_Module)->GetTACCutFileName()); - m_TACCutFileSelector->SetFileType("TAC", "*.csv"); - TGLayoutHints* TACCutLayout = new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 10, 10, 10, 10); - m_OptionsFrame->AddFrame(m_TACCutFileSelector, TACCutLayout); - - PostCreate(); -} - - -//////////////////////////////////////////////////////////////////////////////// - - -bool MGUIOptionsTACcut::ProcessMessage(long Message, long Parameter1, long Parameter2) -{ - // Modify here if you have more buttons - - bool Status = true; - - switch (GET_MSG(Message)) { - case kC_COMMAND: - switch (GET_SUBMSG(Message)) { - case kCM_BUTTON: - break; - default: - break; - } - break; - default: - break; - } - - if (Status == false) { - return false; - } - - // Call also base class - return MGUIOptions::ProcessMessage(Message, Parameter1, Parameter2); -} - - -//////////////////////////////////////////////////////////////////////////////// - - -bool MGUIOptionsTACcut::OnApply() -{ - // Store the data in the module - dynamic_cast(m_Module)->SetTACCalFileName(m_TACCalFileSelector->GetFileName()); - dynamic_cast(m_Module)->SetTACCutFileName(m_TACCutFileSelector->GetFileName()); - - return true; -} - - -// MGUIOptionsTACcut: the end... -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/MModuleDepthCalibration.cxx b/src/MModuleDepthCalibration.cxx index 3d5d3874..78662c0a 100644 --- a/src/MModuleDepthCalibration.cxx +++ b/src/MModuleDepthCalibration.cxx @@ -64,7 +64,7 @@ MModuleDepthCalibration::MModuleDepthCalibration() : MModule() // Set all modules, which have to be done before this module AddPreceedingModuleType(MAssembly::c_EnergyCalibration, true); AddPreceedingModuleType(MAssembly::c_StripPairing, true); - AddPreceedingModuleType(MAssembly::c_TACcut, true); + AddPreceedingModuleType(MAssembly::c_TACCalibration, true); // AddPreceedingModuleType(MAssembly::c_CrosstalkCorrection, false); // Soft requirement // Set all types this modules handles diff --git a/src/MModuleEnergyCalibration.cxx b/src/MModuleEnergyCalibration.cxx index c35817d0..449eb1f4 100644 --- a/src/MModuleEnergyCalibration.cxx +++ b/src/MModuleEnergyCalibration.cxx @@ -74,13 +74,13 @@ MModuleEnergyCalibration::MModuleEnergyCalibration() : MModule() // Set all modules, which have to be done before this module AddPreceedingModuleType(MAssembly::c_EventLoader); - // AddPreceedingModuleType(MAssembly::c_TACcut); + // AddPreceedingModuleType(MAssembly::c_TACCalibration); // Set all types this modules handles AddModuleType(MAssembly::c_EnergyCalibration); // Set all modules, which can follow this module - AddSucceedingModuleType(MAssembly::c_TACcut); + AddSucceedingModuleType(MAssembly::c_TACCalibration); // Set if this module has an options GUI m_HasOptionsGUI = true; diff --git a/src/MModuleStripPairingChiSquare.cxx b/src/MModuleStripPairingChiSquare.cxx index f11fe4bd..d74dced2 100644 --- a/src/MModuleStripPairingChiSquare.cxx +++ b/src/MModuleStripPairingChiSquare.cxx @@ -62,7 +62,7 @@ MModuleStripPairingChiSquare::MModuleStripPairingChiSquare() : MModule() // Set all modules, which have to be done before this module AddPreceedingModuleType(MAssembly::c_EventLoader); AddPreceedingModuleType(MAssembly::c_EnergyCalibration); - AddPreceedingModuleType(MAssembly::c_TACcut); + AddPreceedingModuleType(MAssembly::c_TACCalibration); // Set all types this modules handles AddModuleType(MAssembly::c_StripPairing); diff --git a/src/MModuleStripPairingMultiRoundChiSquare.cxx b/src/MModuleStripPairingMultiRoundChiSquare.cxx index 3b6b00c4..d5ca248d 100644 --- a/src/MModuleStripPairingMultiRoundChiSquare.cxx +++ b/src/MModuleStripPairingMultiRoundChiSquare.cxx @@ -74,7 +74,7 @@ MModuleStripPairingMultiRoundChiSquare::MModuleStripPairingMultiRoundChiSquare() // Set all modules, which have to be done before this module AddPreceedingModuleType(MAssembly::c_EventLoader); AddPreceedingModuleType(MAssembly::c_EnergyCalibration); - AddPreceedingModuleType(MAssembly::c_TACcut); + AddPreceedingModuleType(MAssembly::c_TACCalibration); // Set all types this modules handles AddModuleType(MAssembly::c_StripPairing); diff --git a/src/MModuleTACCalibration.cxx b/src/MModuleTACCalibration.cxx new file mode 100644 index 00000000..c8f9bb44 --- /dev/null +++ b/src/MModuleTACCalibration.cxx @@ -0,0 +1,498 @@ +/* + * MModuleTACCalibration.cxx + * + * + * Copyright (C) by Andreas Zoglauer, Nicole Rodriguez Cavero + * Sean Pike + * All rights reserved. + * + * + * This code implementation is the intellectual property of + * Andreas Zoglauer, Nicole Rodriguez Cavero, Sean Pike. + * + * By copying, distributing or modifying the Program (or any work + * based on the Program) you indicate your acceptance of this statement, + * and all its terms. + * + */ + + +//////////////////////////////////////////////////////////////////////////////// +// +// MModuleTACCalibration +// +//////////////////////////////////////////////////////////////////////////////// + + +// Include the header: +#include "MModuleTACCalibration.h" +#include "MGUIExpoTACcut.h" +#include "MGUIExpoPlotSpectrum.h" +#include "MGUIOptionsTACCalibration.h" + +// Standard libs: +#include +#include + +// ROOT libs: + + +// MEGAlib libs: +#include "MModule.h" + + +//////////////////////////////////////////////////////////////////////////////// + + +#ifdef ___CLING___ +ClassImp(MModuleTACCalibration) +#endif + + +//////////////////////////////////////////////////////////////////////////////// + + +MModuleTACCalibration::MModuleTACCalibration() : MModule() +{ + // Construct an instance of MModuleTACCalibration + + // Set all module relevant information + + // Set the module name --- has to be unique + m_Name = "TAC Calibration"; + + // Set the XML tag --- has to be unique --- no spaces allowed + m_XmlTag = "XmlTagTACCalibration"; + + // Set all modules, which have to be done before this module + AddPreceedingModuleType(MAssembly::c_EventLoader); + AddPreceedingModuleType(MAssembly::c_EnergyCalibration); + + // Set all types this modules handles + AddModuleType(MAssembly::c_TACCalibration); + + // Set all modules, which can follow this module + AddSucceedingModuleType(MAssembly::c_StripPairing); + AddSucceedingModuleType(MAssembly::c_DepthCorrection); + + // Set if this module has an options GUI + // Overwrite ShowOptionsGUI() with the call to the GUI! + m_HasOptionsGUI = true; + // If true, you have to derive a class from MGUIOptions (use MGUIOptionsTACCalibration) + // and implement all your GUI options + + // Can the program be run multi-threaded + m_AllowMultiThreading = true; + + // Can we use multiple instances of this class + m_AllowMultipleInstances = true; + + // Applying taccuts by default + m_ApplyTACCuts = true; + + // Default coincidence window in ns + m_CoincidenceWindow = 600.0; + + m_SideToIndex = {{'l', 0}, {'h', 1}, {'0', 0}, {'1', 1}, {'p', 0}, {'n', 1}}; + +} + + +//////////////////////////////////////////////////////////////////////////////// + + +MModuleTACCalibration::~MModuleTACCalibration() +{ + // Delete this instance of MModuleTACCalibration +} + + +//////////////////////////////////////////////////////////////////////////////// + + +bool MModuleTACCalibration::Initialize() +{ + // Initialize the module + + if (LoadTACCalFile(m_TACCalFile) == false) { + cout<SetTACHistogramArrangement(m_DetectorIDs); + + for (unsigned int i = 0; i < m_DetectorIDs.size(); ++i) { + unsigned int DetID = m_DetectorIDs[i]; + m_ExpoTACcut->SetTACHistogramParameters(DetID, 200, 0, 6000); + } + + m_Expos.push_back(m_ExpoTACcut); + + m_ExpoEnergySpectrum = new MGUIExpoPlotSpectrum(this); + m_Expos.push_back(m_ExpoEnergySpectrum); +} + +//////////////////////////////////////////////////////////////////////////////// + +void MModuleTACCalibration::ShowOptionsGUI() +{ + MGUIOptionsTACCalibration* Options = + new MGUIOptionsTACCalibration(this); + + Options->Create(); + gClient->WaitForUnmap(Options); +} + +//////////////////////////////////////////////////////////////////////////////// + +bool MModuleTACCalibration::AnalyzeEvent(MReadOutAssembly* Event) +{ + if (HasExpos()) { + for (unsigned int i = 0; i < Event->GetNStripHits(); ++i) { + + MStripHit* SH = Event->GetStripHit(i); + + m_ExpoEnergySpectrum->AddEnergyInitial( + SH->GetEnergy(), + SH->IsNearestNeighbor(), + SH->IsLowVoltageStrip() + ); + } + } + + // Always apply TAC calibration + if (ApplyTACCal(Event) == false){ + return false; + } + + // Optionally apply TAC cuts + if (m_ApplyTACCuts == true) { + if (ApplyTACCuts(Event) == false) { + return false; + } + } + + if (HasExpos()) { + for (unsigned int i = 0; i < Event->GetNStripHits(); ++i) { + + MStripHit* SH = Event->GetStripHit(i); + + m_ExpoEnergySpectrum->AddEnergyFinal( + SH->GetEnergy(), + SH->IsNearestNeighbor(), + SH->IsLowVoltageStrip() + ); + + if ((SH->IsGuardRing() == false) && + (SH->HasFastTiming() == true)) { + + m_ExpoTACcut->AddTAC( + SH->GetDetectorID(), + SH->GetTiming() + ); + } + } + } + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// + +bool MModuleTACCalibration::ApplyTACCal(MReadOutAssembly* Event) +{ + // Loop through all strip hits in the event + for (unsigned int i = 0; i < Event->GetNStripHits(); ++i) { + // Get the current strip hit + MStripHit* SH = Event->GetStripHit(i); + + // Guard rings are intentionally not TAC calibrated + if (SH->IsGuardRing() == false) { + + int DetID = SH->GetDetectorID(); + int StripID = SH->GetStripID(); + char Side = SH->IsLowVoltageStrip() ? 'l' : 'h'; + + // Check that this detector exists in the TAC calibration + if (m_TACCal.find(DetID) == m_TACCal.end()) { + cout<GetTAC(); + + // Convert TAC value into timing in ns + double ns_timing = + TAC_timing*m_TACCal[DetID][SideIndex][StripID][0] + + m_TACCal[DetID][SideIndex][StripID][1]; + + // Store calibrated timing + SH->SetTiming(ns_timing); + } + } + + // Mark TAC calibration as completed for this event + Event->SetAnalysisProgress(MAssembly::c_TACCalibration); + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// + +bool MModuleTACCalibration::ApplyTACCuts(MReadOutAssembly* Event) +{ + // Find the max timing value for non-NN hits of an event + // This will be used for the coincidence window + double MaxTAC = -numeric_limits::max(); + + for (unsigned int i = 0; i < Event->GetNStripHits(); ++i) { + MStripHit* SH = Event->GetStripHit(i); + + if ((SH->IsGuardRing() == false) && (SH->HasFastTiming() == true) && (SH ->IsNearestNeighbor()==false)){ + double ns_timing = SH->GetTiming(); + + if (ns_timing> MaxTAC) { + MaxTAC = ns_timing; + } + } + } + + // 200ns appears to be the minimum acceptable timing value for all hits + constexpr double c_FLNoiseCut = 200.0; + + // TotalOffset: Earliest time (in ns) after which valid timing hits can appear, start of the allowed timing window + constexpr double TotalOffset = 3000.0; + + // Apply TAC cuts + + for (unsigned int i = 0; i < Event->GetNStripHits();) { + MStripHit* SH = Event->GetStripHit(i); + bool Passed = true; + + if (SH->IsGuardRing()==false) { + double SHTiming = SH->GetTiming(); + + // Nearest neighbor and direct hit with slow timing + if (SH->HasFastTiming() == false) { + if (SHTiming <= c_FLNoiseCut) { + Passed = false; + } + + //Fast-timing hits must satisfy true and chance coincidence cuts + } else { + if ((SHTiming < TotalOffset) || (SHTiming < MaxTAC - m_CoincidenceWindow)) { + Passed = false; + } + } + } + + if (Passed == true) { + ++i; + } else { + Event->RemoveStripHit(i); + delete SH; + } + } + + Event->SetAnalysisProgress(MAssembly::c_TACCalibration); + + return true; +} + +//////////////////////////////////////////////////////////////////////////////// + + +void MModuleTACCalibration::Finalize() +{ + m_TACCal.clear(); + m_DetectorIDs.clear(); + + MModule::Finalize(); +} + +//////////////////////////////////////////////////////////////////////////////// + + +bool MModuleTACCalibration::ReadXmlConfiguration(MXmlNode* Node) +{ + //! Read the configuration data from an XML node + + MXmlNode* TACCalFileNameNode = Node->GetNode("TACCalFileName"); + if (TACCalFileNameNode != nullptr) { + SetTACCalFileName(TACCalFileNameNode->GetValue()); + } + + MXmlNode* ApplyTACCutsNode = Node->GetNode("ApplyTACCuts"); + if (ApplyTACCutsNode != nullptr) { + SetApplyTACCuts(ApplyTACCutsNode->GetValueAsBoolean()); + } + + MXmlNode* TACCutNode = Node->GetNode("TACCut"); + if (TACCutNode != nullptr) { + + MXmlNode* CoincidenceWindowNode = + TACCutNode->GetNode("CoincidenceWindow"); + + if (CoincidenceWindowNode != nullptr) { + SetCoincidenceWindow( + CoincidenceWindowNode->GetValueAsDouble() + ); + } + } + + return true; +} + + +//////////////////////////////////////////////////////////////////////////////// + + +MXmlNode* MModuleTACCalibration::CreateXmlConfiguration() +{ + //! Create an XML node tree from the configuration + + MXmlNode* Node = new MXmlNode(0, m_XmlTag); + + new MXmlNode(Node, "TACCalFileName", m_TACCalFile); + + new MXmlNode(Node, "ApplyTACCuts", m_ApplyTACCuts); + + MXmlNode* TACCutNode = + new MXmlNode(Node, "TACCut"); + + new MXmlNode( + TACCutNode, + "CoincidenceWindow", + m_CoincidenceWindow + ); + + return Node; +} + + +//////////////////////////////////////////////////////////////////////////////// + + +bool MModuleTACCalibration::LoadTACCalFile(MString FName) +{ + // Read in the TAC Calibration file, which should contain for each strip: + // DetID, Side (h or l for high or low voltage), TAC cal, TAC cal error, TAC cal offset, TAC offset error + // OR: + // ReadOutID, Detector, Side, Strip, TAC cal, TAC cal error, TAC offset, TAC offset error + MFile F; + if (F.Open(FName) == false) { + cout< Tokens = Line.Tokenize(","); + if ((Tokens.size() == 7) || (Tokens.size() == 8)) { + int IndexOffset = Tokens.size() % 7; + int DetID = Tokens[0+IndexOffset].ToInt(); + MString SideString = Tokens[1+IndexOffset].Trim(); + char Side; + if (SideString.Length()!=1) { + cout< CalValues; + CalValues.push_back(TACCal); CalValues.push_back(Offset); CalValues.push_back(TACCalError); CalValues.push_back(OffsetError); + + // If this detector has not been encountered yet, create LV and HV calibration maps for it + if (m_TACCal.find(DetID) == m_TACCal.end()) { + vector>> TempVector; + unordered_map> TempMapLV; + unordered_map> TempMapHV; + m_TACCal[DetID] = TempVector; + m_TACCal[DetID].push_back(TempMapLV); + m_TACCal[DetID].push_back(TempMapHV); + } + + // Keep track of detector IDs contained in the calibration + if (find(m_DetectorIDs.begin(), m_DetectorIDs.end(), DetID) == m_DetectorIDs.end()) { + m_DetectorIDs.push_back(DetID); + } + + // Store the calibration parameters + if (m_SideToIndex.find(Side) != m_SideToIndex.end()) { + m_TACCal[DetID][m_SideToIndex[Side]][StripID] = CalValues; + } else { + cout<SetTACHistogramArrangement(m_DetectorIDs); - for (unsigned int i = 0; i < m_DetectorIDs.size(); ++i) { - unsigned int DetID = m_DetectorIDs[i]; - m_ExpoTACcut->SetTACHistogramParameters(DetID, 200, 0, 6000); - } - m_Expos.push_back(m_ExpoTACcut); - - // Set the energy histogram display - m_ExpoEnergySpectrum = new MGUIExpoPlotSpectrum(this); - m_Expos.push_back(m_ExpoEnergySpectrum); -} - -//////////////////////////////////////////////////////////////////////////////// - - -bool MModuleTACcut::AnalyzeEvent(MReadOutAssembly* Event) -{ - // Start with sanity checks: - for (unsigned int i = 0; i < Event->GetNStripHits(); ++i) { - MStripHit* SH = Event->GetStripHit(i); - - int DetID = SH->GetDetectorID(); - int StripID = SH->GetStripID(); - char Side = SH->IsLowVoltageStrip() ? 'l' : 'h'; - - // This captures every single hit before we delete any of them. - if (HasExpos()) { - m_ExpoEnergySpectrum->AddEnergyInitial(SH->GetEnergy(), SH->IsNearestNeighbor(), SH->IsLowVoltageStrip()); - } - - if (DetID >= m_TACCal.size()) { - cout<IsGuardRing() == false) { - cout<= m_TACCal[DetID][m_SideToIndex[Side]].size()) && (SH->IsGuardRing()==false)) { - cout<= m_TACCut.size()) { - cout<IsGuardRing()==false) { - cout<= m_TACCut[DetID][m_SideToIndex[Side]].size()) && (SH->IsGuardRing()==false)) { - cout<::max(); - for (unsigned int i = 0; i < Event->GetNStripHits(); ++i) { - MStripHit* SH = Event->GetStripHit(i); - double TAC_timing = SH->GetTAC(); - double ns_timing = 0; - int DetID = SH->GetDetectorID(); - int StripID = SH->GetStripID(); - char Side = SH->IsLowVoltageStrip() ? 'l' : 'h'; - if ((TAC_timing == 0) || (SH->IsGuardRing() == true)) { - SH->HasCalibratedTiming(false); - } else { - ns_timing = TAC_timing*m_TACCal[DetID][m_SideToIndex[Side]][StripID][0] + m_TACCal[DetID][m_SideToIndex[Side]][StripID][1]; - SH->HasCalibratedTiming(true); - } - SH->SetTiming(ns_timing); - if ((SH->HasCalibratedTiming()==true) && (ns_timing > MaxTAC) && (SH->HasFastTiming()==true) && (SH->IsNearestNeighbor()==false)) { - MaxTAC = ns_timing; - } - } - - // 200ns appears to be the minimum acceptable timing value for Nearest Neighbor hits - constexpr double c_MinNearestNeighborTiming = 200.0; - - for (unsigned int i = 0; i < Event->GetNStripHits();) { - MStripHit* SH = Event->GetStripHit(i); - bool Passed = true; - if ((SH->IsNearestNeighbor() == true) && (SH->HasCalibratedTiming() == false)) { // Nearest neighbor with slow timing - double SHTiming = SH->GetTiming(); - if (SHTiming <= c_MinNearestNeighborTiming) { - Passed = false; - } - } else if ((SH->HasCalibratedTiming() == true) && (SH->IsGuardRing()==false)) { - double SHTiming = SH->GetTiming(); - int DetID = SH->GetDetectorID(); - int StripID = SH->GetStripID(); - char Side = SH->IsLowVoltageStrip() ? 'l' : 'h'; - double FLNoiseCut = m_TACCut[DetID][m_SideToIndex[Side]][StripID][4]; - if ((SHTiming < FLNoiseCut)) { - Passed = false; - } else if (SH->HasFastTiming()==true) { - double ShapingOffset = m_TACCut[DetID][m_SideToIndex[Side]][StripID][0]; - double CoincidenceWindow = m_TACCut[DetID][m_SideToIndex[Side]][StripID][1]; - double DisableTime = m_TACCut[DetID][m_SideToIndex[Side]][StripID][2]; - double FlagToEnDelay = m_TACCut[DetID][m_SideToIndex[Side]][StripID][3]; - double FlagDelay = m_TACCut[DetID][m_SideToIndex[Side]][StripID][5]; - // double TotalOffset = ShapingOffset + DisableTime + FlagToEnDelay + FlagDelay; // Changing the total Offset based on data instead - // TotalOffset: Earliest time (in ns) after which valid timing hits can appear, start of the allowed timing window - constexpr double TotalOffset = 3000.0; - // TODO(@NicoleRodriguezCavero): Match TotalOffset with timing contributions from electronics, temporary number is a rough estimate - // HardCoincidenceWindow: Width of the valid coincidence region (after TotalOffset) during which multiple strip hits are considered part of the same event - constexpr double HardCoincidenceWindow = 600.0; - // TODO(@NicoleRodriguezCavero): Coincidence window subject to change pending more analysis - // if ((SHTiming > TotalOffset + CoincidenceWindow) || (SHTiming < TotalOffset) || (SHTiming < MaxTAC - CoincidenceWindow)) { - // Passed = false; - // } else if (HasExpos()==true) { - // m_ExpoTACcut->AddTAC(DetID, SHTiming); - // } - if ((SHTiming < TotalOffset) || (SHTiming < MaxTAC - HardCoincidenceWindow)) { //Eliminating the upper boundary condition and just using one cut based on the coincidence window - Passed = false; - } else if (HasExpos()==true) { - m_ExpoTACcut->AddTAC(DetID, SHTiming); - m_ExpoEnergySpectrum->AddEnergyFinal(SH->GetEnergy(), SH->IsNearestNeighbor(), SH->IsLowVoltageStrip()); - } - } - } - if (Passed == true) { - ++i; - } else { - Event->RemoveStripHit(i); - delete SH; - } - } - - Event->SetAnalysisProgress(MAssembly::c_TACcut); - - return true; -} - - -//////////////////////////////////////////////////////////////////////////////// - - -void MModuleTACcut::Finalize() -{ - MModule::Finalize(); -} - - -//////////////////////////////////////////////////////////////////////////////// - - -void MModuleTACcut::ShowOptionsGUI() -{ - //! Show the options GUI --- has to be overwritten! - - MGUIOptionsTACcut* Options = new MGUIOptionsTACcut(this); - Options->Create(); - gClient->WaitForUnmap(Options); -} - - -//////////////////////////////////////////////////////////////////////////////// - - -bool MModuleTACcut::ReadXmlConfiguration(MXmlNode* Node) -{ - //! Read the configuration data from an XML node - - MXmlNode* TACCalFileNameNode = Node->GetNode("TACCalFileName"); - if (TACCalFileNameNode != nullptr) { - SetTACCalFileName(TACCalFileNameNode->GetValue()); - } - - MXmlNode* TACCutFileNameNode = Node->GetNode("TACCutFileName"); - if (TACCutFileNameNode != nullptr) { - SetTACCutFileName(TACCutFileNameNode->GetValue()); - } - - return true; -} - - -//////////////////////////////////////////////////////////////////////////////// - - -MXmlNode* MModuleTACcut::CreateXmlConfiguration() -{ - //! Create an XML node tree from the configuration - - MXmlNode* Node = new MXmlNode(0, m_XmlTag); - - new MXmlNode(Node, "TACCalFileName", m_TACCalFile); - new MXmlNode(Node, "TACCutFileName", m_TACCutFile); - - return Node; -} - - -//////////////////////////////////////////////////////////////////////////////// - - -bool MModuleTACcut::LoadTACCalFile(MString FName) -{ - // Read in the TAC Calibration file, which should contain for each strip: - // DetID, Side (h or l for high or low voltage), TAC cal, TAC cal error, TAC cal offset, TAC offset error - // OR: - // ReadOutID, Detector, Side, Strip, TAC cal, TAC cal error, TAC offset, TAC offset error - MFile F; - if (F.Open(FName) == false) { - cout< Tokens = Line.Tokenize(","); - if ((Tokens.size() == 7) || (Tokens.size() == 8)) { - int IndexOffset = Tokens.size() % 7; - int DetID = Tokens[0+IndexOffset].ToInt(); - MString SideString = Tokens[1+IndexOffset].Trim(); - char Side; - if (SideString.Length()!=1) { - cout< CalValues; - CalValues.push_back(TACCal); CalValues.push_back(Offset); CalValues.push_back(TACCalError); CalValues.push_back(OffsetError); - - if (m_TACCal.find(DetID) == m_TACCal.end()) { - vector>> TempVector; - unordered_map> TempMapLV; - unordered_map> TempMapHV; - m_TACCal[DetID] = TempVector; - m_TACCal[DetID].push_back(TempMapLV); - m_TACCal[DetID].push_back(TempMapHV); - } - - if (find(m_DetectorIDs.begin(), m_DetectorIDs.end(), DetID) == m_DetectorIDs.end()) { - m_DetectorIDs.push_back(DetID); - } - - if (m_SideToIndex.find(Side) != m_SideToIndex.end()) { - m_TACCal[DetID][m_SideToIndex[Side]][StripID] = CalValues; - } else { - cout< Tokens = Line.Tokenize(","); - if (Tokens.size() >= 5) { - int DetID = Tokens[0].ToInt(); - MString SideString = Tokens[1]; - char Side; - if (SideString.Length()!=1) { - cout< CutParams; - CutParams.push_back(ShapingOffset); CutParams.push_back(CoincidenceWindow); CutParams.push_back(DisableTime); CutParams.push_back(FlagToEnDelay); CutParams.push_back(FLNoiseCut); CutParams.push_back(FlagDelay); - - if (m_TACCut.find(DetID) == m_TACCut.end()) { - vector>> TempVector; - unordered_map> TempMapLV; - unordered_map> TempMapHV; - m_TACCut[DetID] = TempVector; - m_TACCut[DetID].push_back(TempMapLV); - m_TACCut[DetID].push_back(TempMapHV); - } - - if (find(m_DetectorIDs.begin(), m_DetectorIDs.end(), DetID) == m_DetectorIDs.end()) { - m_DetectorIDs.push_back(DetID); - } - - if (m_SideToIndex.find(Side) != m_SideToIndex.end()) { - m_TACCut[DetID][m_SideToIndex[Side]][StripID] = CutParams; - } else { - cout<